problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
1f691431dd0731837a0707821314632e
UNKNOWN
You are given four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$). Find any such rectangular matrix of size $n \times m$ that satisfies all of the following conditions: each row of the matrix contains exactly $a$ ones; each column of the matrix contains exactly $b$ ones; all ...
["for _ in range(int(input())):\n n, m, a, b = list(map(int, input().split()))\n if a * n != b * m:\n print('NO')\n else:\n ar = []\n for i in range(n):\n ar.append([0] * m)\n x, y = 0, a\n for i in range(n):\n if x < y:\n for j in range(x...
{ "inputs": [ "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n" ], "outputs": [ "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0110\n0011\n1001\nYES\n1\n1\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
21,001
92b46bb582523ce85bebf0ff6f4a4f05
UNKNOWN
The principal of a school likes to put challenges to the students related with finding words of certain features. One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first stud...
["def wanted_words(vowels, consonants, forbidden):\n return [w for w in WORD_LIST\n if len(w) == vowels + consonants\n and sum(map(w.count, 'aeiou')) == vowels\n and not any(c in w for c in forbidden)]", "from collections import defaultdict\nWORD_INDEX = defaultdict(list)...
{"fn_name": "wanted_words", "inputs": [[1, 7, ["m", "y"]], [3, 7, ["m", "y"]], [3, 7, ["a", "s", "m", "y"]]], "outputs": [[["strength"]], [["afterwards", "background", "photograph", "successful", "understand"]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,528
def wanted_words(n, m, forbid_let):
4b1e479a1c8fb3f6fa0e4734ec2a7f3c
UNKNOWN
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, ...
["s = input()\nn = len(s)\nind = -1\nf = False\nfor i in range(n):\n if s[i] == '[':\n f = True\n elif s[i] == ':':\n if f:\n ind = i\n break\nbind = -1\nf = False\nfor i in range(n-1,-1,-1):\n if s[i] == ']':\n f = True\n elif s[i] == ':':\n if f:\n ...
{ "inputs": [ "|[a:b:|]\n", "|]:[|:]\n", ":][:\n", ":[]:\n", "[[:]]\n", "[::]\n", "]:|:[\n", ":::::]\n", "::::]\n", "::[]\n", "[]\n", "[a|[::]\n", "dsfdsfds\n", ":[||]:\n", "::]\n", ":::]\n", "[||]\n", ":[[[:]]]:\n", "::]::[:]::[::\n", "[...
INTERVIEW
PYTHON3
CODEFORCES
12,277
07494ffcbf5b8e84e1540cd11b0cffe3
UNKNOWN
Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. -----Input----- The first line contains the positive inte...
["num = list(map(int, input()))\nbest = num[:]\nfor i in range(-1, -len(num) - 1, -1):\n if num[i] == 0:\n continue\n num[i] -= 1\n for j in range(i + 1, 0):\n num[j] = 9\n if sum(num) > sum(best):\n best = num[:]\ns = ''.join(map(str, best)).lstrip('0')\nprint(s)\n", "s_num = input()\n...
{ "inputs": [ "100\n", "48\n", "521\n", "1\n", "2\n", "3\n", "39188\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "59999154\n", "1000\n", "10000\n", "100000\n", "1000000\n", "10000000\n", "100000000\n", "1000000000\n", "100000000...
INTERVIEW
PYTHON3
CODEFORCES
14,891
f0b16dd16f404d3776df62839613c538
UNKNOWN
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
["def main():\n s = input()\n n = len(s)\n t = int(str(int(s[0]) + 1) + '0' * (n - 1))\n\n print(t - int(s))\n\nmain()\n", "s = input()\nx = int(s)\ny = int(str(int(s[0]) + 1) + '0' * (len(s) - 1))\nprint(y - x)", "n = int(input())\n\nfor i in range(0,11):\n for j in range(1,10):\n m = j*10**i\n ...
{ "inputs": [ "4\n", "201\n", "4000\n", "9\n", "10\n", "1\n", "100000000\n", "900000000\n", "999999999\n", "1000000000\n", "9999999\n", "100000001\n", "3660\n", "21\n", "900000001\n", "62911\n", "11\n", "940302010\n", "91\n", "101\n", ...
INTERVIEW
PYTHON3
CODEFORCES
3,594
48a74ba91321f0298629870fdc9970ee
UNKNOWN
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$. Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters yo...
["from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\nn, q=mi()\n\nints=[]\n\n\nfor _ in range(q):\n\tst, end=mi()\n\tints.append((...
{ "inputs": [ "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n", "4 3\n1 1\n2 2\n3 4\n", "4 4\n1 1\n2 2\n2 3\n3 4\n", "3 3\n1 3\n1 1\n2 2\n", "6 3\n1 6\n1 3\n4 6\n", "3 3\n1 1\n2 3\n2 3\n", "3 4\n1 3\n1 1\n2 2\n3 3\n", "233 3\n1 2\n2 3\n3 4\n", "5 3\n5 5\n1 3\n3 5\n", "4 5\n1 4\n1 1\n2 2\n3 3\n...
INTERVIEW
PYTHON3
CODEFORCES
24,440
30fbc3c6241377aa6cf258d254d405db
UNKNOWN
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to kno...
["x=int(input())\nh,m=list(map(int,input().split()))\ndef ok(mm):\n while mm<0: mm+=1440\n hh=mm//60\n mm=mm%60\n return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7\nfor y in range(999):\n if ok(h*60+m-y*x):\n print(y)\n return\n", "def lucky(x):\n return (x % 10 == 7)\nx = int(input())\nh, m = list(ma...
{ "inputs": [ "3\n11 23\n", "5\n01 07\n", "34\n09 24\n", "2\n14 37\n", "14\n19 54\n", "42\n15 44\n", "46\n02 43\n", "14\n06 41\n", "26\n04 58\n", "54\n16 47\n", "38\n20 01\n", "11\n02 05\n", "55\n22 10\n", "23\n10 08\n", "23\n23 14\n", "51\n03 27\n", ...
INTERVIEW
PYTHON3
CODEFORCES
7,816
dd70941a66f0d5ee3df46e2dd6ef1214
UNKNOWN
Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this se...
["n, pos, l, r = map(int, input().split())\n\nif l > 1 and r < n:\n if l <= pos and pos <= r:\n if pos - l < r - pos:\n print(pos - l + 1 + r - l + 1)\n else:\n print(r - pos + 1 + r - l + 1)\n elif pos > r:\n print(pos - r + 1 + r - l + 1)\n else:\n print(l - ...
{ "inputs": [ "6 3 2 4\n", "6 3 1 3\n", "5 2 1 5\n", "100 1 1 99\n", "100 50 1 99\n", "100 99 1 99\n", "100 100 1 99\n", "100 50 2 100\n", "100 1 100 100\n", "100 50 50 50\n", "6 4 2 5\n", "100 5 2 50\n", "10 7 3 9\n", "7 4 2 5\n", "43 16 2 18\n", "100 5...
INTERVIEW
PYTHON3
CODEFORCES
9,401
c3443c89d019eea9bdacaf171be8f1d2
UNKNOWN
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $cur...
["for _ in range(int(input())):\n n, x = list(map(int, input().split()))\n A = []\n for _1 in range(n):\n d, h = list(map(int, input().split()))\n A.append([d, h])\n A.sort(reverse=True)\n if A[0][0] >= x:\n print(1)\n else:\n x -= A[0][0]\n mz = 0\n for d, h in...
{ "inputs": [ "3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n", "7\n5 1000000000\n2 1\n1 10\n1 1\n4 1000000000\n3 3\n1 1000000000\n5 1\n2 999999999\n3 1\n2 10000000\n4 10000000\n10000000 999999999\n9999900 12\n9999999 55\n9999999 1\n2 1000000\n1000000 1000000\n999999 1\n3 999999911\...
INTERVIEW
PYTHON3
CODEFORCES
13,270
fdee575bf5cb14e9e71937ab797027f0
UNKNOWN
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba...
["n, m = map(int, input().split())\nif (m >= n): print(n)\nelse:\n c = n - m\n l = 0\n r = 10 ** 18\n while r - l > 1:\n md = (r + l) // 2\n if (1 + md) * md // 2 < c:\n l = md\n else:\n r = md\n print(r + m)", "n, m = map(int, input().split())\n\ndef calc(n):\n...
{ "inputs": [ "5 2\n", "8 1\n", "32 5\n", "1024 1024\n", "58044 52909\n", "996478063 658866858\n", "570441179141911871 511467058318039545\n", "1 1\n", "1000000000000000000 1000000000000000000\n", "1000000000000000000 999999999999997145\n", "1 1000000000000000000\n", "10...
INTERVIEW
PYTHON3
CODEFORCES
9,743
3e38cb0e22c2ed60a403562a4a55b0ef
UNKNOWN
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the fir...
["cards=list(input().split())\nlm=[0]*9\nlp=[0]*9\nls=[0]*9\nfor item in cards:\n if item[1]=='m':\n lm[int(item[0])-1]+=1\n elif item[1]=='p':\n lp[int(item[0])-1]+=1\n else :\n ls[int(item[0])-1]+=1\nif max(lm)==3 or max(lp)==3 or max(ls)==3:\n print(0)\nelse :\n flag=0\n def se...
{ "inputs": [ "1s 2s 3s\n", "9m 9m 9m\n", "3p 9m 2p\n", "8p 2s 9m\n", "5s 8m 5s\n", "9s 4s 3m\n", "4p 8m 9s\n", "8s 5s 7p\n", "4p 7p 2p\n", "3p 2p 3p\n", "5s 9p 5s\n", "9m 6s 1p\n", "4m 2p 8m\n", "8p 6s 4p\n", "9s 6m 7p\n", "4m 1p 3m\n", "8s 8m 1p\n"...
INTERVIEW
PYTHON3
CODEFORCES
22,594
6bfbbb14a9ad27afe9c89cef4e2541b5
UNKNOWN
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ...
["from sys import stdin, stdout\n\nk = int(stdin.readline())\nn, m = map(int, stdin.readline().split())\nleft, right, down, up = [], [], [], []\ncoordinates = []\n\nfor i in range(k):\n x1, y1, x2, y2 = map(int, stdin.readline().split())\n \n if x1 == x2:\n if y1 < y2:\n coordinates.append((x...
{ "inputs": [ "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n", "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n", "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n", "1\n1 2\n1 1 1 2\n0 0 0 0\n", "1\n2 1\n2 1 1 1\n0 0 0 0\n", "1\n1000 1000\n63 902 63 901\n0 0 0 0\n", "6\n10 10\n3 6 3 7\n4 9 5 9\n5 4 5 3\n7 1 8 1\...
INTERVIEW
PYTHON3
CODEFORCES
9,940
bbdd58734667b3eef9988120510b83cd
UNKNOWN
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. -----Input----- The first line of the input ...
["n=int(input())\nr=n%7\nd=n//7\nprint(2*d+max(0,r-5),2*d+min(r,2))\n", "minday = maxday = 0\n\nfor i in range(int(input())) :\n k = i % 7\n if k == 0 or k == 1 : maxday += 1\n if k == 5 or k == 6 : minday += 1\n\nprint(minday, maxday)", "__author__ = 'Andrey'\nn = int(input())\nk = n // 7\nc = n % 7\nprint(2 ...
{ "inputs": [ "14\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "1000000\n", "16\n", "17\n", "18\n", "19\n", "20\n", "21\n", "22\n", "23\n", "24\n", "25\n", "26\...
INTERVIEW
PYTHON3
CODEFORCES
4,446
aa16a0c77557756dce56c2bc2cca3f3c
UNKNOWN
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a a...
["from fractions import gcd\ndef lcm(a, b):\n return a*b//gcd(a, b)\nn, a, b, p, q = list(map(int, input().split(' ')))\nred = n//a\nblue = n//b\nif (p<q):\n red -= n//lcm(a, b)\nelse:\n blue -= n//lcm(a, b)\n\nprint(p*red+q*blue)\n", "3\n# Copyright (C) 2016 Sayutin Dmitry.\n#\n# This program is free software...
{ "inputs": [ "5 2 3 12 15\n", "20 2 3 3 5\n", "1 1 1 1 1\n", "1 2 2 2 2\n", "2 1 3 3 3\n", "3 1 1 3 3\n", "4 1 5 4 3\n", "8 8 1 1 1\n", "15 14 32 65 28\n", "894 197 325 232 902\n", "8581 6058 3019 2151 4140\n", "41764 97259 54586 18013 75415\n", "333625 453145 8008...
INTERVIEW
PYTHON3
CODEFORCES
6,226
4b268bdda3a0afebdf511d26664080d8
UNKNOWN
Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement a...
["n = int(input())\nA = input()\nx = A.count('G')\nnum_1 = 0\nnum_2 = 0\nmax_num = 0\nflag = 0\nfor i in range(n):\n if A[i] == 'G' and flag == 0:\n num_1 += 1\n elif A[i] == 'G' and flag == 1:\n num_2 += 1\n elif A[i] == 'S' and flag == 0:\n flag = 1\n else:\n if num_1 + num_2 +...
{ "inputs": [ "10\nGGGSGGGSGG\n", "4\nGGGG\n", "3\nSSS\n", "11\nSGGGGSGGGGS\n", "300\nSSGSGSSSGSGSSSSGGSGSSGGSGSGGSSSGSSGSGGSSGGSGSSGGSGGSSGSSSGSGSGSSGSGGSSSGSSGSSGGGGSSGSSGSSGSGGSSSSGGGGSSGSSSSSSSSGSSSSGSGSSSSSSSSGSGSSSSGSSGGSSGSGSSSSSSGSGSSSGGSSGSGSSGSSSSSSGGGSSSGSGSGSGGSGGGSSGSGSSSGSSGGSSGSSGGG...
INTERVIEW
PYTHON3
CODEFORCES
15,259
66f4027a6255527d56ce7d5dc575a37d
UNKNOWN
Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage. The situation is complicated by the dependence of online courses, for each course there is a list of those that must be pas...
["#This code is dedicated to Vlada S.\n\nclass Course:\n\tdef __init__(self, reqs, number):\n\t\tself.reqs = list(map(int, reqs.split()[1:]))\n\t\tself.available = False\n\t\tself.in_stack = False\n\t\tself.number = number\n\nn, k = list(map(int, input().split()))\nrequirements = list(map(int, input().split()))\ncourse...
{ "inputs": [ "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n", "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n", "3 3\n1 2 3\n1 2\n1 3\n1 1\n", "5 3\n2 1 4\n0\n0\n1 5\n0\n0\n", "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2\n", "5 2\n4 5\n2 3 4\n1 4\n1 4\n0\n0\n", "6 6\n5 4 3 2 6 1\n1 4\n0\n2 2 6\n2 3 6...
INTERVIEW
PYTHON3
CODEFORCES
18,713
496e8f80db87f87cdb4a40e783cbe01c
UNKNOWN
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty). You may perform the following operations until both a and s are empty: Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, append it to the end of arr...
["import sys\n\n#f = open('input', 'r')\nf = sys.stdin\nn,k = list(map(int, f.readline().split()))\na = list(map(int, f.readline().split()))\naset = set(a)\nst = []\nfailed = False\nai = 0\napp = []\nfor p in range(1, n+1):\n if p in aset:\n while ai < k and (len(st)==0 or st[-1]!=p):\n st.append(a[ai])\n ...
{"inputs": ["5 3\n3 2 1\n", "5 3\n2 3 1\n", "5 1\n3\n", "5 2\n3 4\n", "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3\n", "10 1\n6\n", "20 18\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16\n", "10 2\n3 7\n", "100000 3\n43791 91790 34124\n", "20 17\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 17 7 5\n", "10 3\n2 10 3\n"...
INTERVIEW
PYTHON3
CODEFORCES
7,048
f04173741258e3a1ce52ee49a1b8f8d4
UNKNOWN
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that ...
["import sys\na,b,c=map(int,input().split())\nif c==0:\n if a==b:\n print('YES')\n else:\n print('NO')\n return\nif (b-a)%c==0 and (b-a)//c>=0:\n print('YES')\nelse:\n print('NO')", "a, b, c = list(map(int, input().split()))\nif c != 0:\n if c * (b - a) >= 0 and (b - a) % c == 0:\n ...
{ "inputs": [ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n", "1 -4 -5\n", "0 1 0\n", "10 10 42\n", "-1000000000 1000000000 -1\n", "10 16 4\n", "-1000000000 1000000000 5\n", "1000000000 -1000000000 5\n", "1000000000 -1000000000 0\n", "1000000000 1000000000 0\n", ...
INTERVIEW
PYTHON3
CODEFORCES
5,945
ea0c7c97191ca88f5e3d1404042dcd90
UNKNOWN
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; ")...
["cnt1 = int(input())\ncnt2 = int(input())\ncnt3 = int(input())\ncnt4 = int(input())\nif cnt1 != cnt4:\n\tprint(0)\n\treturn\n\nif (cnt3 != 0 and cnt1 == 0):\n\tprint(0)\n\treturn\n\nprint(1)", "cnt = [int(input()) for _ in range(4)]\n\nif cnt[0] != cnt[3]:\n\tprint(0)\nelif cnt[2] > 0 and cnt[0] == 0:\n\tprint(0)\nels...
{ "inputs": [ "3\n1\n4\n3\n", "0\n0\n0\n0\n", "1\n2\n3\n4\n", "1000000000\n1000000000\n1000000000\n1000000000\n", "1000000000\n1000000000\n1000000000\n999999999\n", "1000000000\n999999999\n1000000000\n1000000000\n", "0\n1000000000\n0\n0\n", "0\n0\n1\n0\n", "4\n3\n2\n1\n", "1\n2...
INTERVIEW
PYTHON3
CODEFORCES
6,703
82aa680a3778f90edb47b98c02e9d82a
UNKNOWN
Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k + 1, the (k + 1)-th spectator stands and th...
["def read_ints():\n\treturn [int(i) for i in input().split()]\n\nn, k, t = read_ints()\nif t <= k:\n\tprint(t)\nelif t > n:\n\tprint(k + n - t)\nelse:\n\tprint(k)", "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input(...
{ "inputs": [ "10 5 3\n", "10 5 7\n", "10 5 12\n", "840585600 770678331 788528791\n", "25462281 23343504 8024619\n", "723717988 205757169 291917494\n", "27462087 20831796 15492397\n", "966696824 346707476 1196846860\n", "290274403 41153108 327683325\n", "170963478 151220598 222...
INTERVIEW
PYTHON3
CODEFORCES
3,413
b78369ef00805ba6c21858579dc8b2a8
UNKNOWN
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this charact...
["from collections import deque\nS = input()\nmn = [ 300 for i in range( len( S ) ) ]\nfor i in range( len( S ) - 1, -1, -1 ):\n if i == len( S ) - 1:\n mn[ i ] = ord( S[ i ] )\n else:\n mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) )\nans = \"\"\ndq = deque()\nfor i in range( len( S ) ):\n dq.append( ord( S[ i ] ...
{ "inputs": [ "cab\n", "acdb\n", "a\n", "ab\n", "ba\n", "dijee\n", "bhrmc\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaab...
INTERVIEW
PYTHON3
CODEFORCES
17,026
a8ea706adf8ad661a00ced9cc142dbb4
UNKNOWN
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases...
["import sys\ninput = sys.stdin.readline\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n lastP = 0\n lastC = 0\n works = True\n for _ in range(n):\n p, c = list(map(int, input().split()))\n pDiff = p-lastP\n cDiff = c-lastC\n if 0 <= cDiff <= pDiff:\n p...
{ "inputs": [ "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "1\n2\n10 1\n11 3\n", "1\n2\n5 2\n8 6\n", "1\n2\n43 34\n44 35\n", "1\n2\n4 1\n5 3\n", "1\n2\n100 0\n101 2\n", "1\n3\n2 1\n4 1\n5 3\n", "1\n4\n0 0\n0 0\...
INTERVIEW
PYTHON3
CODEFORCES
4,056
93e2f93db1400b529095dcc596df7472
UNKNOWN
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance...
["read = lambda: list(map(int, input().split()))\nn = int(input())\na = list(read())\nx, y = a.index(1), a.index(n)\nans = max(x, y, n - x - 1, n - y - 1)\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\ni, j = sorted([a.index(1), a.index(n)])\nprint(max(j, n - i - 1))\n", "n = int(input())\nL = ...
{ "inputs": [ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 3 1\n", "4\n4 1 3 2\n", "5\n1 4 5 2 3\n", "6\n4 6 3 5 2 1\n", "7\n1 5 3 6 2 4 7\n", "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56...
INTERVIEW
PYTHON3
CODEFORCES
5,737
20e0ecd27d8a0f5c101bba17237b3343
UNKNOWN
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
["a = list(input())\nb = int(input())\na.sort()\na = a[::-1]\nprefix = \"\"\nwhile(len(a) > 0):\n\tfor i in range(len(a)):\n\t\tnum = prefix + a[i] + \"\".join(sorted(a[:i] + a[i + 1:]))\n\t\tif (int(num) <= b):\n\t\t\tprefix += a[i]\n\t\t\ta = a[:i] + a[i+1:]\n\t\t\tbreak\nprint(prefix)\n", "fact_ = [1] * 50\n\n\ndef ...
{ "inputs": [ "123\n222\n", "3921\n10000\n", "4940\n5000\n", "23923472834\n23589234723\n", "102391019\n491010301\n", "123456789123456789\n276193619183618162\n", "1000000000000000000\n1000000000000000000\n", "1\n1000000000000000000\n", "999999999999999999\n1000000000000000000\n", ...
INTERVIEW
PYTHON3
CODEFORCES
26,313
29633ba64ca97d6588338256f8d6ebdb
UNKNOWN
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins imm...
["s = [ [ c for c in input() ] for i in range(10) ]\ndef win():\n for i in range(10):\n for j in range(10):\n ok = True\n for k in range(5):\n if j+k>9: ok = False\n elif s[i][j+k] != 'X': ok = False\n if ok: return True\n ok = True\n for k in range(5):\n if i+k>9: ok =...
{ "inputs": [ "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XO........\n.XO.......\n..XO......\n....O.....
INTERVIEW
PYTHON3
CODEFORCES
38,698
42b046f5467d667d5fa6605d356d5dbc
UNKNOWN
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically...
["#!/usr/bin/env python3\n\ndef main():\n import sys\n\n readln = sys.stdin.readline\n try:\n while True:\n n, k = list(map(int, input().split()))\n a = [['0'] * n for i in range(n)]\n i = j = 0\n while k > 0:\n if i == j:\n a...
{"inputs": ["2 1\n", "3 2\n", "2 5\n", "1 0\n", "1 1\n", "20 401\n", "100 10001\n", "2 3\n", "4 5\n", "5 6\n", "5 24\n", "2 0\n", "3 5\n", "3 3\n", "5 10\n", "3 4\n", "4 3\n", "1 1000000\n", "3 6\n", "1 2\n", "1 0\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n", "1 8\n", "1 9\n", "1 10\n", "1 11\n", "...
INTERVIEW
PYTHON3
CODEFORCES
17,450
73df745ec11e1e98ea60132d52b24227
UNKNOWN
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ...
["from math import log\nfrom decimal import Decimal\n\ns = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y']\n\nx, y, z = list(map(Decimal, input().split()))\n\nf = []\nf += [(Decimal(log(x)) * (y ** z), 0)]\nf += [(Decimal(log(x)) * (z ** y), -1)]\nf += [(Decimal(log(x)) * (y * ...
{ "inputs": [ "1.1 3.4 2.5\n", "2.0 2.0 2.0\n", "1.9 1.8 1.7\n", "2.0 2.1 2.2\n", "1.5 1.7 2.5\n", "1.1 1.1 1.1\n", "4.2 1.1 1.2\n", "113.9 125.2 88.8\n", "185.9 9.6 163.4\n", "198.7 23.7 89.1\n", "141.1 108.1 14.9\n", "153.9 122.1 89.5\n", "25.9 77.0 144.8\n", ...
INTERVIEW
PYTHON3
CODEFORCES
23,748
d90b42222bbae5ae64c77ae320bd453d
UNKNOWN
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string. Besides, at most once you may perform one addit...
["n = int(input())\nst = input()\nans = n\nnow = ''\nma = 0\nfor i in range(n // 2):\n now += st[i]\n t = ''\n for j in range(i + 1, 2 * i + 2):\n t += st[j]\n if t == now:\n ma = i\nprint(ans - ma)\n", "n = int(input())\nstrng = input().strip()\nres = len(strng)\nst = len(strng)//2\nwhile st>...
{ "inputs": [ "7\nabcabca\n", "8\nabcdefgh\n", "100\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxc\n", "99\ntrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjhhkqmlzuhrplrtrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjhhkqmlzuhrplrm\n", "100\nyeywsnxcwslfyiqbbeoaawtmi...
INTERVIEW
PYTHON3
CODEFORCES
5,797
99742b3625488a94166ab5853fd25e86
UNKNOWN
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to re...
["n = int(input())\nt = [1] + [0] * n\nb, a = d = [], []\nh, s = [], []\n\nfor i in range(n):\n f, k = input().split()\n d[int(k)].append(f)\n\nm = len(a)\nfor i in a:\n if i.isdigit() and i[0] != '0':\n j = int(i)\n if 0 < j <= m:\n t[j] = 1\n elif m < j <= n:\n t[j]...
{ "inputs": [ "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "2\n1 0\n2 1\n", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n", "4\nir7oz8 1\nvj4v5t 1\nkwkahb 1\nj5s8o1 0\n", "4\n3 1\n1o0bp2 0\n9tn379 0\nv04v6j 1\n", "4\n1 0\nsc7czx 0\nfr4033 1\n3 0\n", "4\n4 0\n1 0\n2 0\nizfotg 1\n", "4\n2 0\n3 0\n1 ...
INTERVIEW
PYTHON3
CODEFORCES
5,852
8bc11b55285124f35e0f08af98537086
UNKNOWN
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
["x=int(input())\ndef s(a):\n r=0\n while a>0:\n r+=a%10\n a//=10\n return r\ndef d(a,b):\n r=0\n for i in range(6):\n if a%10!=b%10:\n r += 1\n a//=10\n b//=10\n return r\nc=6\nfor i in range(1000000):\n if s(i%1000)==s(i//1000):\n c=min(c,d(x,i))\nprint(c)\n", "s = input()\n\nans = 6\n\n...
{ "inputs": [ "000000\n", "123456\n", "111000\n", "120111\n", "999999\n", "199880\n", "899889\n", "899888\n", "505777\n", "999000\n", "989010\n", "651894\n", "858022\n", "103452\n", "999801\n", "999990\n", "697742\n", "242367\n", "099999\n", ...
INTERVIEW
PYTHON3
CODEFORCES
15,974
b09fcdb0ebd39f3c8a790fc83a31cb3c
UNKNOWN
The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of ...
["from math import gcd\ndef powmod(a,b,m):\n a%=m\n r=1\n while b:\n if b&1:r=r*a%m\n a=a*a%m\n b>>=1\n return r\n\ndef f(n):\n r=[]\n if (n&1)==0:\n e=0\n while (n&1)==0:n>>=1;e+=1\n yield (2,e)\n p=3\n while n>1:\n if p*p>n:p=n\n if n%p:\n p+=2\n continue\n e=1;n//=p\n while n%p==0:n//=p;e+=1\n yield (...
{ "inputs": [ "4 3\n", "5 2\n", "7 2\n", "2 1\n", "100000000000000 1\n", "100000000000000 99999999999999\n", "12 1\n", "12 5\n", "12 7\n", "12 11\n", "1117 1\n", "1117 2\n", "1117 3\n", "1117 4\n", "1117 5\n", "1117 6\n", "1117 7\n", "1117 8\n", ...
INTERVIEW
PYTHON3
CODEFORCES
788
3f0d36e680f0074b6ca6c5f108e03b53
UNKNOWN
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland. In Udayland,...
["m = 10** 6 + 3\n\nn, k = list(map(int, input().split()))\np = 1\nfor i in range(n):\n p *= 2\n if p > k:\n break\nif p < k:\n print('1 1')\n return\n\ngcd = tmp = k - 1\nwhile tmp:\n gcd -= tmp % 2\n tmp //= 2\nb = pow(2, (k - 1) * n - gcd, m)\na = 1\nmem = [-1]*100\nfor i in range(1, k):\n ...
{ "inputs": [ "3 2\n", "1 3\n", "4 3\n", "1000000000000000000 1000000000000000000\n", "59 576460752303423489\n", "1234567891234 100005\n", "2 4\n", "59 576460752303423488\n", "2016 2016\n", "2016 2017\n", "468804735183774830 244864585447548924\n", "172714899512474455 41...
INTERVIEW
PYTHON3
CODEFORCES
7,354
5eea2c499378acc73602c546b249e9e1
UNKNOWN
You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0. -----Input----- The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 ≤ 2·10^9, - 2·10^9 ≤ b_1, b_2, L, R ≤ 2·...
["import sys, collections\n\ndef gcd(a, b):\n if b == 0: return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\ndef extgcd(a, b):\n if b == 0: return 1, 0\n x, y = extgcd(b, a % b)\n return y, x - a // b * y\n\ndef prime_factor(n):\n res = collections.defaultdict(int)\n\n ...
{ "inputs": [ "2 0 3 3 5 21\n", "2 4 3 0 6 17\n", "2 0 4 2 -39 -37\n", "1 9 3 11 49 109\n", "3 81 5 72 -1761 501\n", "8 -89 20 67 8771 35222\n", "1 -221 894 86403 -687111 141371\n", "1 -1074 271 17741 -2062230 1866217\n", "3 2408 819 119198 -8585197 7878219\n", "1 341 8581 3946...
INTERVIEW
PYTHON3
CODEFORCES
18,952
0aef0fdb087c1f6d103db1b857749c97
UNKNOWN
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
["n, a, b = map(int, input().split())\nans = 0\nfor i in range(1, n):\n ans = max(ans, min(a // i, b // (n - i)))\nprint(ans)", "n,a,b = [int(x) for x in input().split()]\nmxmn = max(min(a//i,b//(n-i)) for i in range(1,n))\nprint(mxmn)\n", "n, a, b = map(int, input().split())\n\nans = -1\nfor x in range(1, min(n, a)...
{ "inputs": [ "5 2 3\n", "4 7 10\n", "100 100 100\n", "10 100 3\n", "2 9 29\n", "4 6 10\n", "3 70 58\n", "5 7 10\n", "5 30 22\n", "5 5 6\n", "2 4 3\n", "10 10 31\n", "2 1 1\n", "10 98 99\n", "4 10 16\n", "11 4 8\n", "5 10 14\n", "6 7 35\n", "...
INTERVIEW
PYTHON3
CODEFORCES
4,469
ce43c28725a7aadbef676ab8ea310a5b
UNKNOWN
The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each col...
["n,m=list(map(int,input().split()))\nf=[input() for _ in range(n)]\ndef clr(ss):\n cc = None\n for s in ss:\n for c in s:\n if cc is None:\n cc = c\n elif cc != c:\n return None\n return cc\nif n%3 == 0:\n s = set()\n for i in range(0,n,n//3):\n...
{ "inputs": [ "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n", "4 3\nBRG\nBRG\nBRG\nBRG\n", "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n", "4 4\nRRRR\nRRRR\nBBBB\nGGGG\n", "1 3\nGRB\n", "3 1\nR\nG\nB\n", "4 3\nRGB\nGRB\nGRB\nGRB\n", "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGB...
INTERVIEW
PYTHON3
CODEFORCES
27,515
4745b4079af52073ca0a3b46fb0d192f
UNKNOWN
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
["a, b, c = list(map(int, input().split()))\np = [0] * 100000\np[0] = 1\np[a] = 1\np[b] = 1\nfor i in range(c + 1):\n if p[i]:\n p[i + a] = 1\n p[i + b] = 1\nif p[c]:\n print('Yes')\nelse:\n print('No')\n", "# You lost the game.\na,b,c = list(map(int, input().split()))\n\nT = [not((c-a*k)%b) for ...
{ "inputs": [ "4 6 15\n", "3 2 7\n", "6 11 6\n", "3 12 15\n", "5 5 10\n", "6 6 7\n", "1 1 20\n", "12 14 19\n", "15 12 26\n", "2 4 8\n", "4 5 30\n", "4 5 48\n", "2 17 105\n", "10 25 282\n", "6 34 323\n", "2 47 464\n", "4 53 113\n", "6 64 546\n", ...
INTERVIEW
PYTHON3
CODEFORCES
5,457
ec05af925c97fb244107e892e7dda8a8
UNKNOWN
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1 \leq l \leq r \leq |s|$) of a string $s = s_{1}s_{2} \ldots ...
["s = input()\nmx = 0\nn = len(s)\nfor l in range(n):\n for r in range(l, n):\n if s[l:r+1] != s[l:r+1][::-1]:\n mx = max(mx, r - l + 1)\nprint(mx)", "ans = 0\ns = input()\nn = len(s)\nfor i in range(n):\n for j in range(i + 1, n + 1):\n t = s[i:j]\n if t != t[::-1]:\n a...
{ "inputs": [ "mew\n", "wuffuw\n", "qqqqqqqq\n", "ijvji\n", "iiiiiii\n", "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow\n", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy\n", "ijvxljt\n", "fyhcncnchyf\n", "ff...
INTERVIEW
PYTHON3
CODEFORCES
5,387
77d07269f679f5e6eea9a9ced4ba97da
UNKNOWN
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
["'''input\n5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'''\nn = int(input())\nx = []\nf = 0\nfor _ in range(n):\n\ta, b = list(map(int, input().split()))\n\tif a != b:\n\t\tf = 1\n\tx.append(a)\nif f == 1:\n\tprint(\"rated\")\nelif sorted(x)[::-1] == x:\n\tprint(\"maybe\")\nelse:\n\tprint(\"unrated\")\n\...
{ "inputs": [ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n", "2\n1 1\n1 1\n", "2\n4126 4126\n4126 4126\n", "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n9...
INTERVIEW
PYTHON3
CODEFORCES
9,695
2f0e357bc7e76baa6ed4fb20a22983a2
UNKNOWN
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. -----Input----- The first line contains integer n (1 ≤ n ≤ 2·10^5) — length of the array a. The sec...
["inf = 10 ** 6\nn = int(input())\na = list(map(int, input().split()))\ndist = [inf] * n\nfor i in range(len(a)):\n if not a[i]:\n dist[i] = 0\n cur = 1\n i1 = i\n while i1 - 1 > - 1 and a[i1 - 1] != 0:\n dist[i1 - 1] = min(dist[i1 - 1], cur)\n i1 -= 1\n c...
{ "inputs": [ "9\n2 1 0 3 0 0 3 2 4\n", "5\n0 1 2 3 4\n", "7\n5 6 0 1 -2 3 4\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "5\n0 1000000000 1000000000 1000000000 1000000000\n", "5\n-1000000000 -1000000000 0 1000000000 1000000000\n", "5\n-1000000000 1000000000 1000000000 100...
INTERVIEW
PYTHON3
CODEFORCES
16,581
407da1540056fc473d26129a3a826db9
UNKNOWN
You are given a binary string $s$. Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring. The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$. For example, the cyclic...
["n=int(input())\ns=[c=='1' for c in input()]\nm=len(s)\nz=[[0,0]]\nfor c in s:\n ind = z[-1][c]\n z[-1][c] = len(z)\n z.append(z[ind][:])\nassert(len(z) == m+1)\nz[m][0] = z[m][1] = m # make it sticky\n\n# how many things match directly\ndp = [0 for _ in range(m+1)]\ndp[0] = 1\nfor i in range(n):\n ndp = [0 for _ in r...
{ "inputs": [ "2\n0\n", "4\n1010\n", "20\n10101010101010\n", "2\n11\n", "5\n00101\n", "10\n100101\n", "4\n0011\n", "7\n1100\n", "8\n01010001\n", "6\n10\n", "17\n011100101100110\n", "22\n1110011010100111\n", "17\n1110110111010101\n", "11\n10100000100\n", "20\...
INTERVIEW
PYTHON3
CODEFORCES
830
ee6b6c405286570028bbae5d72950a2b
UNKNOWN
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ...
["from math import *\n# stores counterclockwise angle between vector (1,0) and each vector in a\na = []\nn = int(input())\nfor i in range(n):\n x,y = list(map(int,input().split()))\n # calculate counterclockwise angle between (1,0) and this vector\n t = acos(x/sqrt(x**2+y**2))\n a.append((i+1,[2*pi-t,t][y>=...
{ "inputs": [ "4\n-1 0\n0 -1\n1 0\n1 1\n", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n", "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7\n", "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2\n", "2\n351 -4175\...
INTERVIEW
PYTHON3
CODEFORCES
20,683
562ee9372bc59d9da5615925b024908e
UNKNOWN
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers. Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will ...
["d, k, a, b, t = list(map(int, input().split()))\n\nt1 = d * b\nt2 = d * a + ((d - 1) // k) * t\nt3 = max(0, d - k) * b + min(k, d) * a\ndd = d % k\nd1 = d - dd\nt4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b\n\nprint(min([t1, t2, t3, t4]))\n", "from random import randint\nd, k, a, b, t = list(map(int, input().split...
{ "inputs": [ "5 2 1 4 10\n", "5 2 1 4 5\n", "1 1 1 2 1\n", "1000000000000 1000000 999999 1000000 1000000\n", "997167959139 199252 232602 952690 802746\n", "244641009859 748096 689016 889744 927808\n", "483524125987 264237 209883 668942 244358\n", "726702209411 813081 730750 893907 593...
INTERVIEW
PYTHON3
CODEFORCES
10,092
7ecc9ed40010985002e3ed6f20e3271d
UNKNOWN
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by the...
["n, k = map(int, input().split())\ndiv = []\ni = 1\nn1 = n\nwhile i * i <= n:\n if n % i == 0:\n div.append(i)\n div.append(n // i)\n i += 1\ndiv.sort()\nmx = -1\nfor i in range(len(div)):\n a = div[i] * k * (k + 1) // 2\n if a <= n:\n mx = div[i]\nif mx == -1:\n print(-1)\nelse:\n ...
{"inputs": ["6 3\n", "8 2\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "2 10000000000\n", "5 1\n", "6 2\n", "24 2\n", "24 3\n", "24 4\n", "24 5\n", "479001600 2\n", "479001600 3\n", "479001600 4\n", "479001600 5\n", "479001600 6\n", "3000000021 1\n", "3000000021 2\n", "3000000021 3\n", "3000000021 4\n", "3000000021 100000\n...
INTERVIEW
PYTHON3
CODEFORCES
15,782
7c4525b4e10a86b02129c3ee5e58964a
UNKNOWN
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ...
["ct=0\na, b = list(map(int, input().split(' ')))\nx=[0]*5\nfor i in range(1, b+1):\n x[i%5]+=1\nfor i in range(1, a+1):\n ct+=x[(0-i)%5]\nprint(ct)\n", "#!/usr/bin/env python3\n\ntry:\n while True:\n n, m = list(map(int, input().split()))\n a = [0] * 5\n b = [0] * 5\n for i in rang...
{ "inputs": [ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n", "10 15\n", "1 1\n", "1 1000000\n", "1000000 1\n", "1000000 1000000\n", "944 844\n", "368 984\n", "792 828\n", "920 969\n", "640 325\n", "768 170\n", "896 310\n", "320 15...
INTERVIEW
PYTHON3
CODEFORCES
7,324
d30588acc0dd3bbc4acc8dd7f3b2fa88
UNKNOWN
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
["N, X = list(map(int, input().split()))\nA = [int(a) for a in input().split()]\n\ndp = [[0]*4 for _ in range(N+1)]\n\nfor i in range(1, N+1):\n dp[i][0] = max(dp[i-1][0] + A[i-1], 0)\n dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0])\n dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1])\n dp[i][3] = max(dp[i-1]...
{ "inputs": [ "5 -2\n-3 8 -2 1 -6\n", "12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n", "5 10\n-1 -2 -3 -4 -5\n", "10 100\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "3 0\n1 -10 2\n", "5 0\n5 -10 -10 -10 6\n", "5 0\n-12 10 -9 10 -12\...
INTERVIEW
PYTHON3
CODEFORCES
12,497
ffe2f49b50d16c940b801a137654dc53
UNKNOWN
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
["def main():\n from math import sqrt\n m, n, k = list(map(int, input().split()))\n if n < m:\n n, m = m, n\n lo, hi = 1, k + 1\n while lo + 1 < hi:\n mid = (lo + hi) // 2\n t = mid - 1\n v = min(int(sqrt(t)), m)\n tn, tm = (t - 1) // m, t // n\n vv = [t // i for...
{ "inputs": [ "2 2 2\n", "2 3 4\n", "1 10 5\n", "1 1 1\n", "10 1 7\n", "10 10 33\n", "500000 500000 1\n", "500000 500000 250000000000\n", "3 3 1\n", "3 3 2\n", "3 3 3\n", "3 3 5\n", "3 3 8\n", "3 3 9\n", "1 500000 74747\n", "500000 1 47474\n", "49997...
INTERVIEW
PYTHON3
CODEFORCES
1,765
54613c7e01cce088b347e375833c1553
UNKNOWN
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The fir...
["k = int(input())\n\nif k<=9:\n print(k)\nelse:\n num_arr = [9*(i+1)* 10**i for i in range(11)]\n\n index = 0\n\n while True:\n if k<=num_arr[index]:\n break\n else:\n k -= num_arr[index]\n index += 1\n\n digit = index+1\n k += digit-1\n\n\n num = k//...
{ "inputs": [ "7\n", "21\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n", "10\n", "12\n", "188\n", "189\n", "190\n", "191\n", "192\n", "193\n", "194\n", "195\n", "196\n", "197\n", "198\n", "199\n", "200\n", ...
INTERVIEW
PYTHON3
CODEFORCES
9,705
06883cdd47a503495a5ab7af05af8a62
UNKNOWN
Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are $n$ opportunities to buy shares. The $i$-th of them allows to buy as many shares as you want, each at the pri...
["n, m, r = map(int, input().split())\nS = list(map(int, input().split()))\nB = list(map(int, input().split()))\nx = min(S)\ny = max(B)\ncnt = r % x\nact = r // x\ncnt += act * y\nprint(max(r, cnt))", "n, m, r = map(int, input().split())\nA = min(list(map(int, input().split())))\nB = max(list(map(int, input().split()))...
{ "inputs": [ "3 4 11\n4 2 5\n4 4 5 4\n", "2 2 50\n5 7\n4 2\n", "1 1 1\n1\n1\n", "1 1 35\n5\n7\n", "1 1 36\n5\n7\n", "3 5 20\n1000 4 6\n1 2 7 6 5\n", "5 3 20\n5 4 3 2 1\n6 7 1000\n", "30 30 987\n413 937 166 77 749 925 792 353 773 88 218 863 71 186 753 306 952 966 236 501 84 163 767 99 ...
INTERVIEW
PYTHON3
CODEFORCES
6,831
fd8eebf200d204e3b5286f33eb620c68
UNKNOWN
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение мо...
["s = input()\nt = 0\nif len(s)%2==0:\n n = (len(s)-1)//2+1\nelse:\n n = (len(s)-1)//2\nfor i in range(n, len(s)-1):\n a = i\n b = len(s)-i-1\n if s[:a+1]==s[b:]:\n print('YES')\n print(s[:a+1])\n t = 1\n break\nif t==0:\n print('NO')", "a = input()\nif len(a)//2*2 == len(a...
{ "inputs": [ "abrakadabrabrakadabra\n", "acacacaca\n", "abcabc\n", "abababab\n", "tatbt\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "r\n", "zaz\n", "zaza\n", "gg\n", "gagaga\n", "hhhh\n", "sssss\n", ...
INTERVIEW
PYTHON3
CODEFORCES
3,859
c68f06ac81e016bf8fc5490f335871a5
UNKNOWN
Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are...
["n = int(input())\nres = set()\nfor r in range(100):\n a = 1\n b = 2**(r + 1) - 3\n c = -2 * n\n d = b * b - 4 * a * c\n if d < 0:\n continue\n le = 0\n ri = d\n while le < ri:\n c = (le + ri) // 2\n if c * c < d:\n le = c + 1\n else:\n ri = c\n...
{ "inputs": [ "3\n", "25\n", "2\n", "1\n", "15\n", "314\n", "524800\n", "5149487579894806\n", "249999998807430810\n", "1000000000000000000\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "21\n...
INTERVIEW
PYTHON3
CODEFORCES
8,789
8f36f14fc1e7206eb48ef9a2d506f354
UNKNOWN
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}...
["from collections import Counter\n\nr = lambda: list(map(int, input().split()))\n\ndef main():\n\tn, = r()\n\ts = input()\n\tcost = list(r())\n\n\tans = 0\n\n\tcnt = Counter()\n\n\tfor i in range(n // 2):\n\t\tif s[i] == s[n - 1 - i]:\n\t\t\tans += min(cost[i], cost[n - 1 - i])\n\t\t\tcnt[s[i]] += 1\n\ttotal = sum(cnt...
{ "inputs": [ "8\nabacabac\n1 1 1 1 1 1 1 1\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabca\n1 2 3 4 4 3 2 1\n", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 5...
INTERVIEW
PYTHON3
CODEFORCES
3,716
bbb031c2e3cf9b886f5101b5d3b71a66
UNKNOWN
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
["w,m=map(int,input().split())\n\nbb=True\n\nwhile(m>0 and bb):\n\tx=m%w\n\tif x==1:m-=1\n\telif x==w-1:m+=1\n\telif x!=0:bb=False\n\tm//=w\n\t\nif bb:print(\"YES\")\nelse:print(\"NO\")", "def f(w, m):\n\tif m == 0:\n\t\treturn True\n\tif m % w == 0:\n\t\treturn f(w, m // w)\n\tif (m - 1) % w == 0:\n\t\treturn f(w, (m ...
{ "inputs": [ "3 7\n", "100 99\n", "100 50\n", "1000000000 1\n", "100 10002\n", "4 7\n", "4 11\n", "5 781\n", "7 9\n", "5077 5988\n", "2 9596\n", "4 1069\n", "4 7134\n", "4 9083\n", "4 7927\n", "4 6772\n", "5 782\n", "4 1000000000\n", "4 3579...
INTERVIEW
PYTHON3
CODEFORCES
20,956
1958077a81e650451c1779a53a2b2510
UNKNOWN
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As t...
["from collections import defaultdict\n\ndef solve(n, k):\n as_bin = bin(n)[2:]\n cnt = defaultdict(int)\n cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'})\n curr_len = len(cnt)\n curr_pow = len(as_bin) - 1\n\n if curr_len > k:\n return None\n\n while True:\n ne...
{"inputs": ["23 5\n", "13 2\n", "1 2\n", "1 1\n", "7 2\n", "7 3\n", "7 4\n", "521325125150442808 10\n", "1 4\n", "9 4\n", "3 4\n", "144 4\n", "59 4\n", "78 4\n", "192 4\n", "107 4\n", "552 5\n", "680 5\n", "808 5\n", "1528 5\n", "1656 5\n", "26972 8\n", "23100 8\n", "19228 8\n", "22652 8\n", "26076 8\n", "329438 10\n",...
INTERVIEW
PYTHON3
CODEFORCES
20,465
f6d9b2e30b48cf4d14f62f2a1825bca4
UNKNOWN
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
["n = int(input())\npoints = [[int(x) for x in input().split()] for _ in range(n)]\nif n <= 1:\n\tprint(-1)\n\treturn\ndx = [1e9, -1e9]\ndy = [1e9, -1e9]\nfor x, y in points:\n\tdx[0] = min(dx[0], x)\n\tdx[1] = max(dx[1], x)\n\tdy[0] = min(dy[0], y)\n\tdy[1] = max(dy[1], y)\narea = (dx[1] - dx[0]) * (dy[1] - dy[0])\nif...
{ "inputs": [ "2\n0 0\n1 1\n", "1\n1 1\n", "1\n-188 17\n", "1\n71 -740\n", "4\n-56 -858\n-56 -174\n778 -858\n778 -174\n", "2\n14 153\n566 -13\n", "2\n-559 894\n314 127\n", "1\n-227 -825\n", "2\n-187 583\n25 13\n", "2\n-337 451\n32 -395\n", "4\n-64 -509\n-64 960\n634 -509\n6...
INTERVIEW
PYTHON3
CODEFORCES
11,697
0f2ce3ccad7a2683f788a66712567cc8
UNKNOWN
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side. Determine a minimal number of wooden bars which are needed t...
["'''input\n6\n4\n2\n'''\n\ndef list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \ndef f(n,a,b,left,cnta = 4,cntb = 2):\n\tif(cnta == 0 and cntb == 0): return 0\n\tif(cnta < 0 or cntb < 0): return 10000000000...
{ "inputs": [ "8\n1\n2\n", "5\n3\n4\n", "6\n4\n2\n", "20\n5\n6\n", "1\n1\n1\n", "3\n1\n2\n", "3\n2\n1\n", "1000\n1\n1\n", "1000\n1000\n1000\n", "1000\n1\n999\n", "1000\n1\n498\n", "1000\n1\n998\n", "31\n5\n6\n", "400\n100\n2\n", "399\n100\n2\n", "800\n40...
INTERVIEW
PYTHON3
CODEFORCES
14,516
549864d2a29367de769c0f80b4e7e10f
UNKNOWN
You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the ...
["n = int(input())\na = list(map(int,input().split()))\np = input()\nm = 0\nsuc = True\nfor i in range(n-1):\n m = max(m,a[i])\n if p[i] == '0' and m>(i+1):\n suc = False\n break\nif suc:\n print('YES')\nelse:\n print('NO')\n", "import getpass\nimport sys\nimport math\n\n\ndef ria():\n retu...
{ "inputs": [ "6\n1 2 5 3 4 6\n01110\n", "6\n1 2 5 3 4 6\n01010\n", "6\n1 6 3 4 5 2\n01101\n", "6\n2 3 1 4 5 6\n01111\n", "4\n2 3 1 4\n011\n", "2\n2 1\n0\n", "5\n1 2 4 5 3\n0101\n", "5\n1 2 4 5 3\n0001\n", "5\n1 4 5 2 3\n0110\n", "5\n4 5 1 2 3\n0111\n", "3\n3 1 2\n10\n", ...
INTERVIEW
PYTHON3
CODEFORCES
16,088
de9cd0651925f6f23ae6271edcb9ce72
UNKNOWN
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers. -----Input----- The first line...
["n, bx = list(map(int, input().split()))\nx1 = list(map(int, input().split()))\nx = 0\nfor i in range(n):\n\tx *= bx\n\tx += x1[i]\n\nn, by = list(map(int, input().split()))\ny1 = list(map(int, input().split()))\ny = 0\nfor i in range(n):\n\ty *= by\n\ty += y1[i]\n\nif x == y:\n\tprint('=')\nelif x < y:\n\tprint('<')\...
{ "inputs": [ "6 2\n1 0 1 1 1 1\n2 10\n4 7\n", "3 3\n1 0 2\n2 5\n2 4\n", "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n", "2 2\n1 0\n2 3\n1 0\n", "2 2\n1 0\n1 3\n1\n", "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2\n", "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0\n", "5 5\n...
INTERVIEW
PYTHON3
CODEFORCES
10,519
d20dd61c8ebb9969acf7f5d65787316f
UNKNOWN
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games. BitLGM and Bi...
["from math import *\nn=int(input())\nif n==3:\n li=list(map(int,input().split()))\n ans=0\n flag=0\n for i in li:\n ans^=i\n if ans==0:\n print(\"BitAryo\")\n else:\n print(\"BitLGM\")\nelif n==2:\n li=list(map(int,input().split()))\n li.sort()\n phi=(1+sqrt(5))/2\n c...
{ "inputs": [ "2\n1 1\n", "2\n1 2\n", "3\n1 2 1\n", "2\n1 3\n", "2\n3 5\n", "2\n9 10\n", "2\n6 8\n", "3\n0 0 0\n", "2\n223 58\n", "2\n106 227\n", "2\n125 123\n", "3\n31 132 7\n", "2\n41 29\n", "3\n103 286 100\n", "3\n9 183 275\n", "3\n19 88 202\n", "...
INTERVIEW
PYTHON3
CODEFORCES
649
6659f0f78b7afbe11afe533944ce9b50
UNKNOWN
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck. After receiving...
["n,k=map(int,input().split())\nl=list(map(int,input().split()))\npf=[]\nneeded=[]\nfor i in range(2,40000):\n\tif k%i==0:\n\t\tpf.append(i)\n\t\tc=0\n\t\twhile k%i==0:\n\t\t\tk//=i\n\t\t\tc+=1\n\t\tneeded.append(c)\nif k>1:\n\tpf.append(k)\n\tneeded.append(1)\npfl=len(pf)\ncnt=[[0]*n for i in range(pfl)]\nfor i in ran...
{ "inputs": [ "3 4\n6 2 8\n", "3 6\n9 1 14\n", "5 1\n1 3 1 3 1\n", "5 1\n5 5 5 5 5\n", "5 1\n5 4 4 4 4\n", "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
INTERVIEW
PYTHON3
CODEFORCES
2,970
50c95b0c8133e861e7abc4b9c2fac3e5
UNKNOWN
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloon...
["alpha = [chr(ord('a')+i) for i in range(26)]\nn,k = list(map(int,input().split()))\ns = input()\narr = [s.count(alpha[i]) for i in range(26)]\n\nprint('YES' if max(arr) <= k else 'NO')\n", "n, k = map(int, input().split())\ns = input()\nd = {}\n\nfor el in s:\n if el in d:\n d[el] += 1\n else:\n d...
{ "inputs": [ "4 2\naabb\n", "6 3\naacaab\n", "2 2\nlu\n", "5 3\novvoo\n", "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf\n", "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv\n", "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
INTERVIEW
PYTHON3
CODEFORCES
5,845
638f204f48b1759dc9af46c2ffd08e7c
UNKNOWN
You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line contains positive integer n (2 ≤ n ≤ 10^5) — size of the given array. The second...
["n = int(input())\nA = [int(x) for x in input().split()]\nmn = min(A)\n\nI = [i for i in range(len(A)) if A[i] == mn]\nmindiff = min(I[i]-I[i-1] for i in range(1,len(I)))\nprint(mindiff)\n", "n = int(input())\nz = list(map(int, input().split()))\nfor i in range(n):\n z[i] = [z[i], i]\nz.sort()\nans = 1e9\nfor i in ...
{ "inputs": [ "2\n3 3\n", "3\n5 6 5\n", "9\n2 1 3 5 4 1 2 3 1\n", "6\n4 6 7 8 6 4\n", "2\n1000000000 1000000000\n", "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "2\n10000000 10000000\n", "5\n100000000 100000001 100000000 100000001 1000000...
INTERVIEW
PYTHON3
CODEFORCES
6,323
701b1faf3053991b5ab08e40cbb1d4ee
UNKNOWN
Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also another $z$ persons who would vote, but you don't know whether the...
["x, y, z = map(int, input().split())\nif z == 0:\n if x == y:\n print('0')\n elif x > y:\n print('+')\n else:\n print('-')\nelse:\n if x > y + z:\n print('+') \n elif x + z < y:\n print('-')\n else:\n print('?')", "x, y, z = map(int, input().split())\nbest = ...
{ "inputs": [ "3 7 0\n", "2 0 1\n", "1 1 0\n", "0 0 1\n", "12 1 11\n", "22 99 77\n", "28 99 70\n", "73 29 43\n", "100 100 100\n", "1 0 1\n", "5 7 1\n", "13 6 8\n", "94 37 25\n", "45 0 44\n", "62 56 5\n", "88 88 0\n", "1 1 1\n", "0 0 0\n", "0 ...
INTERVIEW
PYTHON3
CODEFORCES
6,994
cdaf9457996202399755f1a930c04997
UNKNOWN
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1...
["# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\ntry :\n #raise ModuleNotFoundError\n import numpy\n def dprint(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n dprint('debug ...
{ "inputs": [ "5\nRURUU\n-2 3\n", "4\nRULR\n1 1\n", "3\nUUU\n100 100\n", "6\nUDUDUD\n0 1\n", "100\nURDLDDLLDDLDDDRRLLRRRLULLRRLUDUUDUULURRRDRRLLDRLLUUDLDRDLDDLDLLLULRURRUUDDLDRULRDRUDDDDDDULRDDRLRDDL\n-59 -1\n", "8\nUUULLLUU\n-3 0\n", "9\nUULUURRUU\n6379095 -4\n", "5\nDUUUD\n2 3\n", ...
INTERVIEW
PYTHON3
CODEFORCES
33,718
1356528246712ba38783b8e4f6b31eaf
UNKNOWN
You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010... Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of so...
["t=int(input())\nfor i in ' '*t:\n n,x=map(int,input().split())\n s=input()\n L=[0]\n for i in s:\n if i=='0':L.append(L[-1]+1)\n else:L.append(L[-1]-1)\n L.pop(0)\n k=L[-1]\n c=0\n if x==0:c+=1\n if k>0:\n for i in L:\n if i%k==x%k and i<=x:c+=1\n prin...
{ "inputs": [ "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n", "2\n1 -548706795\n0\n1 -735838406\n1\n", "1\n5 5\n00000\n", "19\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n", "1\n3 0\n011\n...
INTERVIEW
PYTHON3
CODEFORCES
6,458
2989081fa01d52055d9bf422b886ddb6
UNKNOWN
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the r...
["s = input().split()\nk = int(s[1])\ns = s[0]\nif s.count('0') < k:\n if s.count('0') > 0:\n print(len(s) - 1)\n else:\n print(len(s))\n return\nhave = 0\nits = 0\nfor i in range(len(s) - 1, -1, -1):\n its += 1\n if s[i] == '0':\n have += 1\n if have == k:\n print(its - ha...
{ "inputs": [ "30020 3\n", "100 9\n", "10203049 2\n", "0 1\n", "0 9\n", "100 2\n", "102030404 2\n", "1000999999 3\n", "12000000 4\n", "1090090090 5\n", "10 1\n", "10 2\n", "10 9\n", "100 1\n", "100 3\n", "101010110 3\n", "101010110 1\n", "1010101...
INTERVIEW
PYTHON3
CODEFORCES
8,527
ede915df0815c8717c94b05539e313d0
UNKNOWN
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of t...
["n, m, k, x, y = list(map(int, input().split()))\n\nans = [[0] * m for x in range(n)]\n\nonebig = (2*n-2)*m or m\n\noo = k // onebig\n\nfor i in range(n):\n for j in range(m):\n if i == 0 or i == n-1:\n ans[i][j] += oo\n k -= oo\n else:\n ans[i][j] += 2*oo\n ...
{ "inputs": [ "1 3 8 1 1\n", "4 2 9 4 2\n", "5 5 25 4 3\n", "100 100 1000000000000000000 100 100\n", "3 2 15 2 2\n", "4 1 8 3 1\n", "3 2 8 2 1\n", "4 2 9 4 1\n", "1 3 7 1 1\n", "2 2 8 2 1\n", "3 1 6 2 1\n", "5 6 30 5 4\n", "3 8 134010 3 4\n", "10 10 25 5 1\n", ...
INTERVIEW
PYTHON3
CODEFORCES
24,872
82170f55128efc3e6ee4faed8d630d54
UNKNOWN
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
["turns = int(input())\ns0 = input()\ns1 = input()\ns2 = input()\n\nd0 = dict()\nd1 = dict()\nd2 = dict()\n\nalphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'\nfor char in alphabet:\n\td0[char] = 0\n\td1[char] = 0\n\td2[char] = 0\n\nfor char in s0:\n\td0[char] += 1\nfor char in s1:\n\td1[char] += 1\nfor...
{ "inputs": [ "3\nKuroo\nShiro\nKatie\n", "7\ntreasurehunt\nthreefriends\nhiCodeforces\n", "1\nabcabc\ncbabac\nababca\n", "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n", "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb\n", "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYda...
INTERVIEW
PYTHON3
CODEFORCES
21,102
b3e2a73977435fb3dd9a27e0f13ef17b
UNKNOWN
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_0 pages, at second...
["read = lambda: map(int, input().split())\nc, v0, v1, a, l = read()\ncur = 0\ncnt = 0\nwhile cur < c:\n cur = max(0, cur - l)\n cur += min(v1, v0 + a * cnt)\n cnt += 1\nprint(cnt)", "c,v0,v1,a,l = map(int,input().split())\ncnt = 0\nans = 0\nv = v0\nwhile(cnt < c):\n\tcnt += v\n\tif(ans != 0):\n\t\tcnt -= l\n\...
{ "inputs": [ "5 5 10 5 4\n", "12 4 12 4 1\n", "15 1 100 0 0\n", "1 1 1 0 0\n", "1000 999 1000 1000 998\n", "1000 2 2 5 1\n", "1000 1 1 1000 0\n", "737 41 74 12 11\n", "1000 1000 1000 0 999\n", "765 12 105 5 7\n", "15 2 2 1000 0\n", "1000 1 1000 1000 0\n", "20 3 7 1...
INTERVIEW
PYTHON3
CODEFORCES
5,840
012d54a20c3bc8416aea0a9ce7b6fffe
UNKNOWN
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 ≤ i ≤ k), such that 1 ≤ k ≤ 3 p_...
["import math\n\nn=int(input())\n\ndef prime(p):\n if p == 1:\n return False\n fl=True\n for i in range(2,math.ceil(p**0.5) + 1):\n if p % i == 0:\n fl=False\n return fl\n\ndef sum_of_primes(k):\n fl=True\n for i in range((k // 2) + 1):\n if prime(i) and prime(k-i):\n ...
{ "inputs": [ "27\n", "3\n", "25\n", "9\n", "91\n", "57\n", "31\n", "555\n", "700000001\n", "5\n", "7\n", "11\n", "13\n", "15\n", "17\n", "19\n", "21\n", "23\n", "29\n", "79\n", "99\n", "27\n", "55\n", "79\n", "585\n",...
INTERVIEW
PYTHON3
CODEFORCES
15,539
72e498b19c661268f8b4bf0d1ae2a824
UNKNOWN
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column...
["n, m = list(map(int, input().split()))\np = []\nans = 0\nfor i in range(n):\n s = input()\n ans += s.count('*')\n p.append(s)\ndp = []\nfor i in range(n):\n dp.append([0] * m)\nfor i in range(n):\n col = p[i].count('*')\n for t in range(m):\n dp[i][t] = col\nfor i in range(m):\n col = 0\n ...
{ "inputs": [ "3 4\n.*..\n....\n.*..\n", "3 3\n..*\n.*.\n*..\n", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "1 10\n**********\n", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n...
INTERVIEW
PYTHON3
CODEFORCES
14,392
e7ec84b40c5fa958de3e7ea3e31c1e5a
UNKNOWN
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil...
["n, m, a, b = list(map(int, input().split()))\n\nk = n%m\nprint(min(k*b, (m - k)*a))\n", "n,m,a,b=list(map(int,input().split()))\nprint(min((n%m)*b,(m-(n%m))*a))\n", "(n, m, a, b) = list(map(int, input().split()))\n\nif n % m == 0:\n print(0)\nelse:\n k1 = n % m\n k2 = m - k1\n print(min(k1 * b, k2 * a))\n...
{ "inputs": [ "9 7 3 8\n", "2 7 3 7\n", "30 6 17 19\n", "500000000001 1000000000000 100 100\n", "1000000000000 750000000001 10 100\n", "1000000000000 750000000001 100 10\n", "42 1 1 1\n", "1 1000000000000 1 100\n", "7 2 3 7\n", "999999999 2 1 1\n", "999999999999 10000000007...
INTERVIEW
PYTHON3
CODEFORCES
4,486
03ed48d7cd9470c9012c4452051e80fb
UNKNOWN
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by de...
["n = int(input())\na = list(map(int, input().split()))\nres = 0\nnew_a = []\nfor i in range(n):\n if a[i] % 2 == 0:\n if a[i] > 0:\n res += a[i]\n else:\n new_a.append(a[i])\na = new_a\na.sort()\nres += a[-1]\na.pop()\nwhile len(a) > 1:\n if a[-1] + a[-2] > 0:\n res += a[-1] + ...
{ "inputs": [ "4\n-2 2 -3 1\n", "3\n2 -5 -3\n", "1\n1\n", "1\n-1\n", "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\n", "2\n-5439 -6705\n", "2\n2850 6843\n", "2\n144 9001\n", "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757\n", "10\n-...
INTERVIEW
PYTHON3
CODEFORCES
11,915
c53c5bd7a34ae851383afe0c6ee93883
UNKNOWN
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
["from math import factorial\n\n\ndef lol(n):\n if n == 1:\n yield [0]\n yield [1]\n else:\n for p in lol(n - 1):\n p.append(0)\n yield p\n p[-1] = 1\n yield p\n p.pop()\n\n\ndef sp(g1, g2, g3, f):\n if g1 == 0:\n if g2 == g3:\n...
{ "inputs": [ "3 3\n1 1\n1 2\n1 3\n", "3 3\n1 1\n1 1\n1 3\n", "4 10\n5 3\n2 1\n3 2\n5 1\n", "1 1\n1 1\n", "1 1\n1 3\n", "1 2\n1 2\n", "1 15\n15 1\n", "1 225\n15 1\n", "2 1\n1 2\n1 2\n", "2 1\n1 1\n1 1\n", "2 1\n3 1\n2 2\n", "2 2\n1 3\n1 3\n", "2 2\n1 3\n1 1\n", ...
INTERVIEW
PYTHON3
CODEFORCES
7,606
d47bf72c4fda876a17cbe93daa7e80b9
UNKNOWN
Vivek initially has an empty array $a$ and some integer constant $m$. He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of integers in $a$. In case it equals to $1$, break Otherwise, return to ste...
["big = 100010\ndef gen_mu():\n mu = [1]*big\n mu[0] = 0\n P = [True]*big\n P[0] = P[1] = False\n for i in range(2,big):\n if P[i]:\n j = i\n while j<big:\n P[j] = False\n mu[j] *= -1\n j += i\n j = i*i\n whil...
{ "inputs": [ "1\n", "2\n", "4\n", "3\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "100000\n", "99991\n", "30030\n", "99594\n", "91402\n", "93493\n", "96917\n", "80555\n", "30238\n", "5447\n", "5714\n", "...
INTERVIEW
PYTHON3
CODEFORCES
5,894
6f3e020a04db3a0e5f65fd9fcf21cd1f
UNKNOWN
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common...
["from math import sqrt\nfrom fractions import gcd\nl, r, x, y = list(map(int, input().split()))\nif y % x != 0:\n print(0)\n return\nlo = (l + x - 1) // x\nhi = r // x\np = y // x\ns = 0\n\nk1 = 1\nwhile k1 * k1 <= p:\n k2 = p // k1\n if lo <= k1 <= hi and lo <= k2 <= hi and gcd(k1, k2) == 1 and k1 * k2 ==...
{ "inputs": [ "1 2 1 2\n", "1 12 1 12\n", "50 100 3 30\n", "1 1000000000 1 1000000000\n", "1 1000000000 158260522 200224287\n", "1 1000000000 2 755829150\n", "1 1000000000 158260522 158260522\n", "1 1000000000 877914575 877914575\n", "232 380232688 116 760465376\n", "47259 3393...
INTERVIEW
PYTHON3
CODEFORCES
34,202
313d30ef183c1a30246ba934a5a58891
UNKNOWN
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
["from math import gcd\na, b = list(map(int, input().split()))\nif b < a:\n a, b = b, a\nif a == b:\n print(0)\n return\nc = b - a\ni = 1\nans = a * b // gcd(a, b)\n\ndef get(x):\n A = (a + x - 1) // x * x\n B = A - a + b\n return A * B // gcd(A, B), A\n\nr = 0\nwhile i * i <= c:\n if c % i == 0:\n...
{ "inputs": [ "6 10\n", "21 31\n", "5 10\n", "1924 5834\n", "9911 666013\n", "1 1\n", "69 4295\n", "948248258 533435433\n", "953 1349\n", "999999973 800000007\n", "112342324 524224233\n", "1021211 59555555\n", "1000000000 1000000000\n", "199999943 999999973\n", ...
INTERVIEW
PYTHON3
CODEFORCES
21,272
895afd2e1776738223c4f89675c1bc9a
UNKNOWN
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
["n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = sum(a)\nans = 0\nc = k - 0.5\nwhile s / n < c:\n s += k\n n += 1\n ans += 1\nprint(ans)\n", "n, k = list(map(int, input().split(' ')))\nl = list(map(int, input().split(' ')))\n\ns = sum(l)\ntotal = len(l)\nres = 0\nwhile s < tot...
{ "inputs": [ "2 10\n8 9\n", "3 5\n4 4 4\n", "3 10\n10 8 9\n", "2 23\n21 23\n", "5 10\n5 10 10 9 10\n", "12 50\n18 10 26 22 22 23 14 21 27 18 25 12\n", "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6\n", "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 3...
INTERVIEW
PYTHON3
CODEFORCES
6,649
af4ddb694ba476ddbb51ab026c8f5ac0
UNKNOWN
You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e.,...
["n=int(input())\nar=list(map(int,input().split()))\npos=0\nneg=0\nfor a in ar:\n if(a>0):pos+=1\n elif a<0:neg+=1\nif(pos*2>=n):\n print(1)\nelif neg*2>=n:\n print(-1)\nelse:\n print(0)\n", "n = int(input())\na = list(map(int, input().split()))\np = o = 0\nfor i in a:\n if i > 0:\n p += 1\n ...
{ "inputs": [ "5\n10 0 -7 2 6\n", "7\n0 0 1 -1 0 0 2\n", "5\n0 0 0 1 1\n", "1\n777\n", "2\n1 0\n", "100\n39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 ...
INTERVIEW
PYTHON3
CODEFORCES
6,401
9d66f634d055b4999d793d8bddd7b110
UNKNOWN
There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with severa...
["from sys import stdin as cin\nfrom sys import stdout as cout\n\ndef main():\n n = int(cin.readline())\n o = 0\n for x in range(9, 0, -1):\n if 10 ** x // 2 <= n:\n ##print(x)\n for i in range(9):\n q = 10 ** x * (i + 1) // 2 - 1\n if q <= n:\n ...
{ "inputs": [ "7\n", "14\n", "50\n", "999999999\n", "15\n", "3\n", "6500\n", "4\n", "13\n", "10\n", "499999\n", "6\n", "8\n", "9\n", "11\n", "12\n", "5\n", "16\n", "17\n", "18\n", "19\n", "20\n", "21\n", "22\n", "23\n"...
INTERVIEW
PYTHON3
CODEFORCES
13,451
6ac3d3a751204ca028c32f1021e7a049
UNKNOWN
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one him...
["a,b=list(map(int,input().split()))\nc,d=list(map(int,input().split()))\ne=a*b\nf=c*d\nn=0\nwhile e%2==0:e=e//2\nwhile e%3==0:e=e//3\nwhile f%2==0:f=f//2\nwhile f%3==0:f=f//3\nif e!=f:print(\"-1\")\nelse:\n i=0\n j=0\n e=a*b\n f=c*d\n while e%3==0:\n e=e//3\n i+=1\n while f%3==0:\n f=f//3\n ...
{ "inputs": [ "2 6\n2 3\n", "36 5\n10 16\n", "3 5\n2 1\n", "36 5\n10 12\n", "1 1\n1 1\n", "2 1\n1 2\n", "3 6\n2 1\n", "1 27\n1 1\n", "2 5\n20 2\n", "40 5\n150 36\n", "60 1080\n60 45\n", "2160 3240\n7200 384\n", "51840 900\n48 27000\n", "100 200\n7200 25\n", ...
INTERVIEW
PYTHON3
CODEFORCES
33,966
bf376fdf503e02bc039eb0f767987447
UNKNOWN
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: ...
["a, b, x, y = map(int, input().split())\nif a >= x:\n if b >= y:\n print('Vasiliy')\n else:\n z = y - b\n t = max(x - z, 0)\n if a - z <= t:\n print('Polycarp')\n else:\n print('Vasiliy')\nelse:\n if b <= y:\n print('Polycarp')\n else:\n ...
{ "inputs": [ "2 1 2 2\n", "4 7 7 4\n", "20 0 7 22\n", "80 100 83 97\n", "80 100 77 103\n", "55000 60000 55003 60100\n", "100000 100000 100000 99999\n", "100000 99999 100000 100000\n", "0 100000 100000 99999\n", "0 100000 99999 100000\n", "0 90000 89999 89999\n", "0 1 0...
INTERVIEW
PYTHON3
CODEFORCES
2,532
89a7e7f743a21695496f4774acc2ae05
UNKNOWN
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: $\left. \begin{...
["import sys\narr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\na, b = list(map(int, input().split()))\na -= 1\nb -= 1\nctr = 1\nfor i in range(arr[a] - 1):\n b += 1\n if (b == 7):\n b = 0\n ctr += 1\nprint(ctr)\n \n", "def main():\n\tm, d = map(int, input().split())\n\ta = [31, 28,...
{ "inputs": [ "1 7\n", "1 1\n", "11 6\n", "2 7\n", "2 1\n", "8 6\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n", "2 1\n", "2 2\n", "2 3\n", "2 4\n", "2 5\n", "2 6\n", "2 7\n", "3 1\n", "3 2\n", "3 3\n", ...
INTERVIEW
PYTHON3
CODEFORCES
4,955
2a8b2e79e2670e60517bc07b0dfe9e17
UNKNOWN
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
["def zero(strx):\n k = []\n str2 = list(strx)\n for i in range(1, len(str2)):\n str3 = str2[:]\n str3[i] = '0'\n k.append(''.join(str3))\n return k\na = []\nfor i in range(1, 64):\n a += zero('1'*i)\n\nct = 0\nx, y = list(map(int, input().split(' ')))\nfor i in a:\n if x <= int(i...
{ "inputs": [ "5 10\n", "2015 2015\n", "100 105\n", "72057594000000000 72057595000000000\n", "1 100\n", "1000000000000000000 1000000000000000000\n", "1 1000000000000000000\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n", "2 2\n", "2 3\n...
INTERVIEW
PYTHON3
CODEFORCES
7,655
f5ab2d03703b951f142213a2033e2f9d
UNKNOWN
Anya loves to fold and stick. Today she decided to do just that. Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes. Anya can stick a...
["fact = [ 1 ]\nfor i in range( 1, 20, 1 ):\n fact.append( fact[ i - 1 ] * i )\n\nfrom collections import defaultdict\n\nN, K, S = list(map( int, input().split() ))\nA = list( map( int, input().split() ) )\n\nldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]\nldp[ 0 ][ 0 ][ 0 ] = 1\nfor i in...
{ "inputs": [ "2 2 30\n4 3\n", "2 2 7\n4 3\n", "3 1 1\n1 1 1\n", "25 25 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "13 1 60\n3 6 3 4 3 5 1 4 4 4 3 4 3\n", "10 10 1002\n5 6 5 3 4 3 3 2 6 4\n", "7 6 14\n1 3 2 4 1 1 6\n", "8 7 169\n4 3 4 3 5 5 2 5\n", "1 0 384338286\n38...
INTERVIEW
PYTHON3
CODEFORCES
1,518
5658d462f80357a0e0aba8cb45c6f6dd
UNKNOWN
Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can: either choose position $pos$ ($1 \le pos \le n$) and increase $v_{pos}$ by $k^i$; or not choo...
["t = int(input())\nfor _ in range(t):\n n,k = list(map(int,input().split()))\n a = list(map(int,input().split()))\n for i in range(60, -1, -1):\n m = k ** i\n for j in range(n):\n if a[j] >= m:\n a[j] -= m\n break\n if all(i == 0 for i in a):\n ...
{ "inputs": [ "5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n", "3\n5 2\n1 2 4 8 17\n2 3\n1 2\n4 3\n10 4 13 12\n", "1\n1 10\n10000000000000000\n", "1\n1 100\n10000000000000000\n", "1\n2 2\n2251799813685248 2251799813685248\n", "1\n2 2\n9007199254740992 9007199254740992\n...
INTERVIEW
PYTHON3
CODEFORCES
3,439
6140519c98786afe747ae06870b2cd91
UNKNOWN
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: $\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$ Find the sum modulo 1073741824 (2^30). -----Input----- The first line contains three s...
["a, b, c = map(int, input().split())\nd = 1073741824\np = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\nt = [{} for i in range(101)]\nans = {}\nfor i in p:\n j = i\n m = 1\n while j < 101:\n for k in range(j, 101, j):\n t[k][i] = m\n ...
{ "inputs": [ "2 2 2\n", "5 6 7\n", "91 42 25\n", "38 47 5\n", "82 29 45\n", "40 15 33\n", "35 5 21\n", "71 2 1\n", "22 44 41\n", "73 19 29\n", "76 12 17\n", "16 10 49\n", "59 99 33\n", "17 34 25\n", "21 16 9\n", "31 51 29\n", "26 41 17\n", "85 1...
INTERVIEW
PYTHON3
CODEFORCES
17,612
883dcca1ec02a32895e4292192ef771e
UNKNOWN
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the em...
["a, b, c, d = input(), input(), input(), input()\na = a + b[::-1]\nx = \"X\"\nfor i in range(4):\n if a[i] == x:\n a = a[:i] + a[i + 1:]\n break\nc = c + d[::-1]\n\nfor i in range(4):\n if c[i] == x:\n c = c[:i] + c[i + 1:]\n break\nflag = False\nfor i in range(4):\n if a == c:\n ...
{ "inputs": [ "AB\nXC\nXB\nAC\n", "AB\nXC\nAC\nBX\n", "XC\nBA\nCB\nAX\n", "AB\nXC\nAX\nCB\n", "CB\nAX\nXA\nBC\n", "BC\nXA\nBA\nXC\n", "CA\nXB\nBA\nCX\n", "CA\nXB\nAC\nBX\n", "CB\nAX\nCX\nAB\n", "AX\nCB\nBC\nXA\n", "CA\nXB\nBA\nXC\n", "CX\nAB\nAX\nCB\n", "AB\nXC\nAB\...
INTERVIEW
PYTHON3
CODEFORCES
10,342
0e336060ed343fd0368ff65c1dcf2325
UNKNOWN
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets...
["n=int(input())\ns=input()\npw=[1]\nlast=1\nfor i in range(70):\n if (last>1e19):\n break\n pw.append(last*n)\n last=last*n\ndp=[1e19]*100\nfor i in range(100):\n dp[i]=[1e19]*100\ndp[len(s)][0]=0\nfor i in range(len(s),-1,-1):\n for power in range(0,len(pw)):\n cur=''\n for j in ra...
{ "inputs": [ "13\n12\n", "16\n11311\n", "20\n999\n", "17\n2016\n", "1000\n1001\n", "1000\n1000\n", "2\n110111100000101101101011001110100111011001000000000000000000\n", "500\n29460456244280453288\n", "1000000000\n17289468142098080\n", "123\n7719\n", "25\n2172214240\n", ...
INTERVIEW
PYTHON3
CODEFORCES
12,439
49f3f5ee24a6cf54b0e1b529a18a7057
UNKNOWN
Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays a...
["n = int(input())\nL = list(map(int, input().split()))\ni = 0\na = 0\nwhile i < n and L[i] > a:\n a = L[i]\n i += 1\nwhile i < n and L[i] == a:\n i += 1\nwhile i < n and L[i] < a:\n a = L[i]\n i += 1\nif i == n:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n = int(input())\na = list(map(int, input...
{ "inputs": [ "6\n1 5 5 5 4 2\n", "5\n10 20 30 20 10\n", "4\n1 2 1 2\n", "7\n3 3 3 3 3 3 3\n", "6\n5 7 11 11 2 1\n", "1\n7\n", "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 5...
INTERVIEW
PYTHON3
CODEFORCES
9,123
e16766b2b56f3aa4f90b0c6f17cfc78b
UNKNOWN
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$ We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, an...
["def gg(n,lol):\n\tans = 0\n\tcur = 1\n\tlol2 = lol\n\twhile(2*lol+1<=n):\n\t\tcur *= 2\n\t\tans += cur\n\t\tlol = 2*lol+1\n\t\tlol2 *= 2\n\tif lol2*2 <= n:\n\t\tans += n-lol2*2+1\t\n\treturn ans\n\nn,k = list(map(int,input().split()))\nlow = 1\nhigh = n//2\nres = 1\nwhile low <= high:\n\tmid = (low+high)//2\n\tif gg(...
{ "inputs": [ "11 3\n", "11 6\n", "20 20\n", "14 5\n", "1000000 100\n", "1 1\n", "2 1\n", "100 4\n", "502333439 2047\n", "773014587697599 31\n", "946338791423 262143\n", "1000000000 4\n", "13 2\n", "1073741821 2\n", "1000000000 100\n", "1000000000 100000...
INTERVIEW
PYTHON3
CODEFORCES
7,512
6482a7bc84dae655ab4d0ab44f538ca2
UNKNOWN
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b...
["def main():\n (b1, q, l, m) = list(map(int, input().split()))\n a = set(map(int, input().split()))\n if abs(b1) > l:\n print(0)\n else:\n if b1 == 0:\n if 0 in a:\n print(0)\n else:\n print(\"inf\")\n elif q == 0:\n if 0 n...
{ "inputs": [ "3 2 30 4\n6 14 25 48\n", "123 1 2143435 4\n123 11 -5453 141245\n", "123 1 2143435 4\n54343 -13 6 124\n", "3 2 25 2\n379195692 -69874783\n", "3 2 30 3\n-691070108 -934106649 -220744807\n", "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981...
INTERVIEW
PYTHON3
CODEFORCES
16,719
5238aea76916fc4879c770598953804a
UNKNOWN
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that pain...
["3\n\ndef readln(): return list(map(int, input().split()))\nimport sys\ndef return:\n print(-1)\n return\n\nn, m = readln()\nmon = [list(input()) for _ in range(n)]\nhor = [i for i in range(n) if mon[i] != ['.'] * m]\nrmon = list(zip(*mon))\nver = [j for j in range(m) if rmon[j] != ('.',) * n]\nmini = hor[0]\nma...
{ "inputs": [ "4 8\n..w..w..\n........\n........\n..w..w..\n", "5 6\n......\n.w....\n......\n..w...\n......\n", "2 4\n....\n.w..\n", "2 6\nw..w.w\n...w..\n", "9 4\n....\n....\n....\n....\n....\n..w.\n....\n....\n.w..\n", "10 4\n....\n.w..\n....\n....\n.w..\n....\n....\n....\n....\n....\n", ...
INTERVIEW
PYTHON3
CODEFORCES
9,649
29c36a19a3d3a8aad2ce838df479d9cd
UNKNOWN
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles. I...
["def egcd(a, b):\n x,y, u,v = 0,1, 1,0\n while a != 0:\n q, r = b//a, b%a\n m, n = x-u*q, y-v*q\n b,a, x,y, u,v = a,r, u,v, m,n\n gcd = b\n return gcd, x, y\n\n\nimport math\nn=int(input())\na=int(input())\nb=int(input())\ngcd,x,y=(egcd(a,b))\n\n\nstatus=0\nif((n%gcd)!=0):\n print(\...
{ "inputs": [ "7\n2\n3\n", "100\n25\n10\n", "15\n4\n8\n", "9960594\n2551\n2557\n", "10000000\n1\n1\n", "9999999\n9999\n9999\n", "9963629\n2591\n2593\n", "1\n7\n8\n", "9963630\n2591\n2593\n", "7516066\n1601\n4793\n", "6509546\n1607\n6221\n", "2756250\n8783\n29\n", "7...
INTERVIEW
PYTHON3
CODEFORCES
2,324
217dd1a3326dce4429eff122e16cf2f7
UNKNOWN
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom. JATC decided to prank his friend by erasing some consecutive elements in th...
["n = int(input())\na = [0] + list(map(int, input().split())) + [1001]\nmx = 1\np = 1\nfor i in range(1, n + 2):\n if a[i] == a[i - 1] + 1:\n p += 1\n mx = max(p, mx)\n else:\n p = 1\nprint(max(0, mx - 2))", "n = int(input())\narr = [0] + list(map(int, input().split()))\narr.append(1001)\nmax...
{ "inputs": [ "6\n1 3 4 5 6 9\n", "3\n998 999 1000\n", "5\n1 2 3 4 5\n", "1\n1\n", "2\n1 2\n", "2\n999 1000\n", "9\n1 4 5 6 7 100 101 102 103\n", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48...
INTERVIEW
PYTHON3
CODEFORCES
9,358
bae9d0e43b383daca9d002828940fccd
UNKNOWN
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
["def main():\n n = int(input())\n a = list(int(x) for x in input().split())\n s = sum(a)\n t = 0\n for i in range(n):\n t += a[i]\n if 2 * t >= s:\n print(i + 1)\n return\n\nmain()\n", "#!/bin/python\n\nn = int(input())\nl = list(map(int, input().split()))\ns = sum(l)...
{ "inputs": [ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n", "1\n10000\n", "3\n2 1 1\n", "2\n1 3\n", "4\n2 1 1 3\n", "3\n1 1 3\n", "3\n1 1 1\n", "2\n1 2\n", "3\n2 1 2\n", "5\n1 2 4 3 5\n", "5\n2 2 2 4 3\n", "4\n1 2 3 1\n", "6\n7 3 10 7 3 11\n", "2\n3 4\n", "5\n1 1 ...
INTERVIEW
PYTHON3
CODEFORCES
5,292
c8281996d73535331229c3ae9a2030ee
UNKNOWN
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$-th square in the $i$-th row has a number $A_{ij}$...
["n=int(input())\ngraph=[{},{},{}]\nfor i in range(n):\n for j in range(n):\n graph[0][(i,j)]=[(k,j) for k in range(n)]+[(i,k) for k in range(n)]\n graph[0][(i,j)].remove((i,j))\n graph[0][(i,j)].remove((i,j))\n graph[1][(i,j)]=[]\n for k in range(n):\n for l in range(n)...
{ "inputs": [ "3\n1 9 3\n8 6 7\n4 2 5\n", "3\n1 5 8\n9 2 4\n3 6 7\n", "4\n5 4 1 13\n8 3 6 16\n15 9 14 12\n11 2 7 10\n", "5\n21 14 2 3 12\n19 8 16 18 7\n9 17 10 15 4\n24 5 1 23 11\n25 13 22 6 20\n", "6\n8 3 15 14 29 17\n27 11 16 21 18 28\n34 23 36 12 10 5\n30 31 25 6 9 2\n7 24 13 1 35 4\n19 26 33 3...
INTERVIEW
PYTHON3
CODEFORCES
5,010
66045cea075e3895343a003accedb914
UNKNOWN
Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором этаже первого подъ...
["n, m, k = map(int, input().split())\na, b = map(int, input().split())\na -= 1\nb -= 1\ndef p(x):\n\treturn x // (m * k)\ndef e(x):\n\treturn (x - p(x) * m * k) // k\ndef lift(x):\n\treturn min(5 * x, 10 + x)\n\t\nif p(a) == p(b):\n\tdif = abs(e(a) - e(b))\n\tprint(lift(dif))\nelse:\n\tprint(lift(e(a)) + 15 * min((p(a...
{ "inputs": [ "4 10 5\n200 6\n", "3 1 5\n7 2\n", "100 100 100\n1 1000000\n", "1000 1000 1000\n1 1000000000\n", "125 577 124\n7716799 6501425\n", "624 919 789\n436620192 451753897\n", "314 156 453\n9938757 14172410\n", "301 497 118\n11874825 13582548\n", "491 980 907\n253658701 4211...
INTERVIEW
PYTHON3
CODEFORCES
8,080
3561f2330c36fd7f82cc966eccb25dc6
UNKNOWN
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
["s = input()\ni = 0\nwhile i < len(s) and s[i] == '0':\n i += 1\ncnt = 0\nwhile i < len(s):\n if s[i] == '0':\n cnt += 1\n i += 1\n\nif cnt >= 6:\n print('yes')\nelse:\n print('no')\n", "s=input()\none=False\nzero=0\nfor x in s:\n if not one:\n if x=='1':\n one=True\n else...
{ "inputs": [ "100010001\n", "100\n", "0000001000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111\n", "011111110111111111111111...
INTERVIEW
PYTHON3
CODEFORCES
4,614
9b4498aa81930e683bb48d000c1c283f
UNKNOWN
You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of ...
["s = list(input())\ntarget = 'abcdefghijklmnopqrstuvwxyz'\nind_t = 0\nind_s = 0\nwhile ind_s < len(s) and ind_t < 26:\n if ord(s[ind_s]) <= ord(target[ind_t]):\n s[ind_s] = target[ind_t]\n ind_t += 1\n ind_s += 1\n else:\n ind_s += 1\nif ind_t == 26:\n print(''.join(s))\nelse:\n print(-1)", "\na = list...
{ "inputs": [ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n", "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs\n", "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "abcdefghijklmnopqrstuvwxxx\n", "abc...
INTERVIEW
PYTHON3
CODEFORCES
6,295
e109c81e14b7a3625edaaeae9688baa7
UNKNOWN
Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $a_1 \cdot a_2 \cdot \dots a_n$ of its elements seemed to him not large enoug...
["n = int(input())\nA = list(map(int, input().split()))\nif n == 1:\n if A[0] >= 0:\n print(A[0])\n else:\n print(-A[0]-1)\n return\nfor i in range(n):\n if A[i] < 0:\n pass\n else:\n A[i] = -A[i]-1\nif n % 2 == 0:\n print(*A)\n return\nmim = 0\nindmim = 0\nfor i in rang...
{ "inputs": [ "4\n2 2 2 2\n", "1\n0\n", "3\n-3 -3 2\n", "10\n2 10 6 8 -4 -11 -10 3 -3 8\n", "10\n8 6 3 9 8 7 7 7 7 6\n", "8\n-3 -11 -4 -8 -4 -5 -3 -2\n", "10\n6 1 -11 -10 -9 -8 8 -1 -10 1\n", "6\n10 -11 -8 -11 -11 10\n", "3\n-2 -3 -4\n", "5\n0 0 0 -4 -3\n", "1\n-3\n", "...
INTERVIEW
PYTHON3
CODEFORCES
10,488