problem_id stringlengths 32 32 | name stringlengths 2 54 | problem stringlengths 204 5.28k | solutions listlengths 1 5.17k | test_cases stringlengths 38 86.7k | difficulty stringclasses 1
value | language stringclasses 1
value | source stringclasses 1
value | num_solutions int64 1 5.17k | starter_code stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|
4e2f2585b450362d7e2a53f3e8966fe1 | none | It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly *S* slices.
It is known that the *i*-th contestant will eat *s**i* slices of pizza, and ... | [
"def solve(arr):\r\n arr.sort(key=lambda q: q[1] - q[0])\r\n m = sum(si for a, b, si in arr)\r\n k = s * (m // s)\r\n n = m - k\r\n x, y, z = 0, 0, 0\r\n for a, b, si in arr:\r\n if k >= si:\r\n k -= si\r\n z += si * a\r\n elif k > 0:\r\n z += k * a\r... | {"inputs": ["3 12\n3 5 7\n4 6 7\n5 9 5", "6 10\n7 4 7\n5 8 8\n12 5 8\n6 11 6\n3 3 7\n5 9 6", "1 100\n97065 97644 98402", "1 100000\n1 82372 5587", "25 6\n1 10 5\n1 8 4\n1 8 2\n4 8 9\n3 2 8\n1 9 5\n2 10 10\n3 9 6\n3 5 4\n2 7 8\n2 3 2\n2 6 8\n3 7 8\n4 3 7\n1 8 1\n3 6 4\n3 2 8\n2 2 1\n4 8 8\n4 8 4\n3 10 2\n3 6 6\n2 2 5\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
4e6946d661b5320cd47b3c77431ea1bd | Food on the Plane | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | [
"c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1}\r\nx=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n\r\nprint(x-1 if (n-1)%4<2 else x-3)",
"s=input()\r\na=int(s[:-1])-1\r\nprint(a//4*16+(a%2)*7+' fedabc'.index(s[-1]))",
"given = input()\nrow = int(given[:-1])\naisle = given[-1]\n\nresult = 16 * ((... | {"inputs": ["1f", "2d", "4a", "5e", "2c", "1b", "1000000000000000000d", "999999999999999997a", "1c", "1d", "1e", "1a", "2a", "2b", "2e", "2f", "3a", "3b", "3c", "3d", "3e", "3f", "4b", "4c", "4d", "4e", "4f", "999999997a", "999999997b", "999999997c", "999999997d", "999999997e", "999999997f", "999999998a", "999999998b",... | UNKNOWN | PYTHON3 | CODEFORCES | 101 | |
4e6f6cbabbc99f8cca4697f102ddcb4a | Kyoya and Photobooks | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | [
"s=input()\r\nn=len(s)\r\nprint((n+1)*26-n)",
"\na = input()\n\nprint((len(a)+1) * 25 + 1)\n\n\n",
"s = input()\r\nn = len(s)\r\nans = n * 25 + 26\r\nprint(ans)",
"def main():\n st = input()\n print(solve(st))\n\ndef solve(st):\n return len(st)*25 + 26\n\nmain()\n \t \t \t \t \t\t \t\t\t \t\t ... | {"inputs": ["a", "hi", "y", "kgan", "zoabkyuvus", "spyemhyznjieyhhbk", "xulsyfkuizjauadjjopu", "e", "zv", "jgv", "zsfo", "jselr", "dwemig", "mddoxsf", "jgirkrmi", "spkxurcum", "fykkiubdkt", "fznbcxsxygs", "qcrvrdqcbtou", "qktrbjzrqgmlr", "foamodbvptlxxg", "ydzpjhsidipricw", "lpfpndmjfvqejdgf", "ofkvparuvjtggnmab", "xxn... | UNKNOWN | PYTHON3 | CODEFORCES | 398 | |
4e7689d6c8eafdd03fd8c880eb071bcf | Enemy is weak | The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | [
"def getSum(BiTree, i, n):\n sum = 0\n while i > 0:\n sum += BiTree[i]\n i -= i & (-i)\n return sum\nfrom sys import stdin, stdout\n \ndef update(BiTree, i, n, val):\n while i <n:\n BiTree[i] += val\n i += i & (-i)\n \n \n \n \ndef construct(a, BiTree, a2, a3, n):\n lcount... | {"inputs": ["3\n3 2 1", "3\n2 3 1", "4\n10 8 3 1", "4\n1 5 4 3", "9\n10 9 5 6 8 3 4 7 11", "7\n11 3 8 4 2 9 6", "6\n2 1 10 7 3 5", "4\n1 5 3 10", "3\n2 7 11", "5\n4 11 7 5 10", "72\n685 154 298 660 716 963 692 257 397 974 92 191 519 838 828 957 687 776 636 997 101 800 579 181 691 256 95 531 333 347 803 682 252 655 297 ... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
4e7ef17cfdabf27d2d245b8f76ac89d4 | Tetrahedron | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | [
"b,power,mod = 0,3,10**9+7\r\nfor i in range(int(input())-1): b=(power-b)%mod; power=(power*3)%mod\r\nprint(b)",
"n=int(input())\r\nMOD=int(1e9+7)\r\nprint(int(((pow(3, n, 4*MOD)+3*pow(-1,n))/4))%MOD)",
"\nmod = 10**9+7\nn = int(input())\n\n# A, B, C, D = 0, 0, 0, 1\n# for i in range(1, n+1):\n# new_A = (B ... | {"inputs": ["2", "4", "1", "3", "5", "6", "7", "8", "9", "10", "15", "30", "10000000", "100", "300", "900", "1500", "3000", "5000", "10000", "50000", "90000", "99999", "100000", "300000", "800000", "1000000", "4000000", "9000000", "9999999", "1000000", "9999999", "10000000", "9999998", "30", "31"], "outputs": ["3", "21... | UNKNOWN | PYTHON3 | CODEFORCES | 129 | |
4e93562b61be1dc35e16228296a50a7a | Jumping Ball | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | [
"n = int(input() )\r\ns = input()\r\n\r\npos = s.find(\"><\")\r\nif pos == -1 :\r\n print(n)\r\nelse :\r\n ans = 0\r\n for i in s :\r\n if i == '>' :\r\n break;\r\n else :\r\n ans += 1;\r\n for i in range(n-1,-1,-1) :\r\n t = s[i]\r\n if t==\"<\" :\r\n ... | {"inputs": ["4\n<<><", "5\n>>>>>", "4\n>><<", "3\n<<>", "3\n<<<", "3\n><<", "1\n<", "2\n<>", "3\n<>>", "3\n><>", "2\n><", "2\n>>", "2\n<<", "1\n>", "3\n>><", "3\n>>>", "3\n<><", "10\n<<<><<<>>>", "20\n><><<><<<>>>>>>>>>>>", "20\n<<<<<<<<<<><<<<>>>>>", "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>", "100\n<<<<... | UNKNOWN | PYTHON3 | CODEFORCES | 163 | |
4e9884823cc182d8bcd7b08538d77a54 | MUH and Sticks | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | [
"\nsticks = input().split()\n\nfour = False\ntwo = False\n\nfor stick in sticks:\n\tif sticks.count(stick) >= 4:\n\t\tfour = True \n\tif sticks.count(stick) == 2 or sticks.count(stick) == 6:\n\t\ttwo = True\n\nif four:\n\tif two:\n\t\tprint(\"Elephant\")\n\telse:\n\t\tprint(\"Bear\")\nelse:\n\tprint(\"Alien\")",
... | {"inputs": ["4 2 5 4 4 4", "4 4 5 4 4 5", "1 2 3 4 5 6", "5 5 5 5 5 5", "1 1 1 2 3 5", "1 1 1 1 1 1", "9 9 9 9 9 9", "1 8 9 1 1 1", "9 9 9 1 9 9", "1 2 3 8 9 7", "5 5 5 6 6 6", "1 1 2 2 3 4", "4 4 4 4 4 2", "2 2 3 3 4 4", "4 4 4 4 4 5", "1 1 2 2 2 2", "1 2 5 5 5 5", "4 4 2 2 2 2", "1 1 1 1 1 2", "2 2 4 4 4 4", "4 4 4 4... | UNKNOWN | PYTHON3 | CODEFORCES | 200 | |
4eb717ee9cf01551ebb483e88ba4b9f5 | Vladik and Entertaining Flags | In his spare time Vladik estimates beauty of the flags.
Every flag could be represented as the matrix *n*<=×<=*m* which consists of positive integers.
Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that s... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u * n + v\r\n\r\ndef get_root(s):\r\n v = []\r\n while not s == root[s]:\r\n v.append(s)\r\n s = root[s]\r\n for i in v:\r\n root[i] = s\r\n return s\r\n\r\ndef unit... | {"inputs": ["4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5", "5 2 9\n6 1\n6 6\n6 6\n6 6\n5 6\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 2\n1 1", "5 4 10\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n2 4\n2 2\n1 2\n1 4\n1 1\n1 3\n2 4\n2 3\n1 3\n3 3", "8 4 12\n7 20 20 29\n29 7 29 29\n29 20 20 29\n29 20... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
4ec79af96774776f3541a3c3c00f4d6a | Mike and Foam | Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are *n* kinds of beer at Rico's numbered from 1 to *n*. *i*-th kind of beer has *a**i* milliliters of foam on it.
Maxim is Mike's boss. Today he told Mike to perform *q* queries. Initially the shelf is empty. In each request,... | [
"import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heapp... | {"inputs": ["5 6\n1 2 3 4 6\n1\n2\n3\n4\n5\n1", "3 3\n151790 360570 1\n2\n3\n3", "1 1\n1\n1", "5 10\n1 1 1 1 1\n1\n2\n3\n4\n5\n5\n4\n3\n2\n1", "1 2\n499590\n1\n1"], "outputs": ["0\n1\n3\n5\n6\n2", "0\n1\n0", "0", "0\n1\n3\n6\n10\n6\n3\n1\n0\n0", "0\n0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
4ecaefff8877a36ffd6fb1febd12369d | The Untended Antiquity | Adieu l'ami.
Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence.
The space is represented by a rectangular grid of *n*<=×<=*m* cells, arranged into *n* rows and *m* columns. The *c*-th cell in the *r*-th row is ... | [
"import random\r\ng = {}\r\nn, m, q = map(int, input().split())\r\nc = [[0] * 2520 for _ in range(2520)]\r\ndef R(x, y, z):\r\n i = x\r\n while i <= n:\r\n j = y\r\n while j <= m:\r\n c[i][j] += z\r\n j += j & -j\r\n i += i & -i\r\ndef G(x, y):\r\n re = 0\r\n i... | {"inputs": ["5 6 5\n1 2 2 4 5\n1 3 3 3 3\n3 4 4 1 1\n2 2 2 4 5\n3 1 1 4 4", "2500 2500 8\n1 549 1279 1263 2189\n1 303 795 1888 2432\n1 2227 622 2418 1161\n3 771 2492 1335 1433\n1 2017 2100 2408 2160\n3 48 60 798 729\n1 347 708 1868 792\n3 1940 2080 377 1546", "3 3 5\n3 1 3 1 3\n3 1 1 3 1\n1 2 2 2 2\n3 2 3 2 2\n3 1 1 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
4ed5cab6a6a8f2e20270f96bf0b11ab9 | You're Given a String... | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Lat... | [
"def main():\r\n s = input()\r\n\r\n l = len(s)\r\n for i in range(l, 0, -1):\r\n substring_dict = {}\r\n for j in range(l - i + 1):\r\n substring = s[j: j + i]\r\n if substring in substring_dict:\r\n print(i)\r\n return\r\n subst... | {"inputs": ["abcd", "ababa", "zzz", "kmmm", "wzznz", "qlzazaaqll", "lzggglgpep", "iegdlraaidefgegiagrdfhihe", "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg", "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw", "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbk... | UNKNOWN | PYTHON3 | CODEFORCES | 147 | |
4eddd3363623be37a94dbf0b2b374a00 | Cowslip Collections | In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has *n* diffe... | [
"from sys import stdin #Bibliotecas para optimizar la entrada/salida\r\nfrom sys import stdout\r\n\r\nMOD = 1000000007 #Modulo\r\nMAXA = 1000007 #Maximo valor posible en A\r\nMAXN = 200007 #Suma de maximos valores posibles de n y q\r\n\r\np = [0 for i in range(MAXA)] #Para cada i me guarda 0 si i es primo o 1... | {"inputs": ["3 3 2\n4\n6\n9\n8\n6", "4 1 2\n6\n5\n4\n3\n2\n1", "3 3 3\n6\n8\n10\n12\n14\n16", "1 1 1\n1\n1", "10 10 10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10", "7 1 9\n3\n6\n7\n2\n10\n8\n1\n3\n9\n2\n9\n10\n2\n4\n5\n2", "5 1 7\n10\n8\n4\n5\n8\n3\n9\n3\n9\n3\n10\n1", "7 2 8\n2\n5\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
4ee030eb81b88d70cace434a5be31ced | Multipliers | Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the password to the secret data base. Now he wants to calculate this value.
The first line of the input... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nfrom collections import Counter\r\n\r\nmod = 10**9 + 7\r\n\r\ndef fpow(a, p):\r\n if p == 0:\r\n return 1\r\n t = fpow(a, p // 2)\r\n res = t * t % mod\r\n if p & 1:\r\n res = res * a % mod\r\n return res\r\n\r\n\r\nm = int(input())\r\ncn... | {"inputs": ["2\n2 3", "3\n2 3 2", "1\n2017", "2\n63997 63997", "5\n11 7 11 7 11", "5\n2 2 2 2 2", "4\n3 3 3 5", "6\n101 103 107 109 101 103", "10\n3 3 3 3 3 3 3 3 3 3", "5\n7 5 2 3 13", "23\n190979 191627 93263 72367 52561 188317 198397 24979 70313 105239 86263 78697 6163 7673 84137 199967 14657 84391 101009 16231 1751... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
4efe90f9fc3fbf649ac705ac3ad803c1 | Multitasking | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort *n* arrays simultaneously, each array consisting of *m* integers.
Iahub can choose a pair of distinct indices *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*). Then in each array the values at positions *i* and *j* are swapped ... | [
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(n, m, k, A):\r\n if k==0:\r\n sys.stdout.write(f'{m*(m-1)//2}\\n')\r\n for smaller in range(1, m+1):\r\n for larger in range(smaller+1, m+1):\r\n sys.stdout.write(f'{smaller} {larger}\\n')\r\n retu... | {"inputs": ["2 5 0\n1 3 2 5 4\n1 4 3 2 5", "3 2 1\n1 2\n2 3\n3 4", "2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591", "2 5 1\n331081 525217 574775 753333 840639\n225591 347017 538639 620341 994088", "1 1 0\n1", "1 1 1\n1", "2 1 0\n1\n2", "1 2 1\n2 1", "2 2 0\n2 1\n3 1", "2 2 0\n2 1\n1 3", "... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
4f3f1b3886bf8084ebd7c68cecda1017 | Ring road | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly tw... | [
"n = int(input())\r\n\r\nroad = [map(int,input().split()) for i in range(n)]\r\n\r\ngraf = [[] for i in range(n + 1)]\r\n\r\ns = 0\r\nfor a,b,c in road:\r\n\tgraf[a].append((b,0))\r\n\tgraf[b].append((a,c))\r\n\ts += c\r\n\r\nvis = [0] * (n + 1)\r\n\r\ndef dfs(u,p):\r\n\td = 0\r\n\tfor v,c in graf[u]:\r\n\t\tif v !... | {"inputs": ["3\n1 3 1\n1 2 1\n3 2 1", "3\n1 3 1\n1 2 5\n3 2 1", "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54", "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90", "17\n8 12 43\n13 12 70\n7 13 68\n11 7 1... | UNKNOWN | PYTHON3 | CODEFORCES | 90 | |
4f57807abc657d81814ba2545baf08e5 | Race | Today *s* kilometer long auto race takes place in Berland. The track is represented by a straight line as long as *s* kilometers. There are *n* cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which... | [
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, s = map(int, input().split())\r\ndata = [dict() for _ in range(n)]\r\n\r\nfor i in range(n):\r\n k, *a = map(int, input().split())\r\n cur = 0\r\n for j in ra... | {"inputs": ["2 33\n2 5 1 2 14\n1 3 11", "2 33\n2 1 3 10 3\n1 11 3", "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5", "2 166755\n2 733 187 362 82\n3 813 147 565 57 557 27", "3 228385\n2 307 733 43 78\n2 252 801 157 169\n3 86 346 133 886 467 173", "4 773663\n9 277 398 57 73 62 736 625 393 186 761 129 716 329... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
4f681d465ce8905f9eebe024d288c041 | Laser | Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of *n*<=×<=*m* cells and a robotic arm. Each cell of the field is a 1<=×<=1 square. The robotic arm has two l... | [
"def main():\r\n t = int(input())\r\n for _ in range(t):\r\n n, m, x1, y1, x2, y2 = map(int, input().split())\r\n rect_x, rect_y = n - abs(x2 - x1), m - abs(y2 - y1)\r\n area = n * m - 2 * rect_x * rect_y + max(0, rect_x * 2 - n) * max(0, rect_y * 2 - m)\r\n print(area)\r\n\r\n\r\n... | {"inputs": ["2\n4 4 1 1 3 3\n4 3 1 1 2 2", "1\n2 2 1 2 2 1", "1\n2 2 1 2 2 1", "1\n3 3 3 2 1 1", "1\n3 4 1 1 1 2", "1\n4 3 3 1 4 1", "1\n3 5 2 4 3 5", "1\n4 5 2 2 4 2", "1\n2 5 1 5 2 2", "1\n2 6 2 6 2 3", "1\n3 6 3 5 2 4", "1\n4 6 2 1 2 3", "1\n5 6 3 4 4 2", "1\n7 3 6 2 5 2", "1\n8 2 6 1 7 2", "1\n9 6 6 5 3 1", "20\n10... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
4f6d771773c09a28a6671135a970f49c | Death Stars (easy) | The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.
Tw... | [
"def rotate_90(a):\r\n b=[]\r\n for x in range(len(a)):\r\n l=[]\r\n for y in range(len(a)-1,-1,-1):\r\n l.append(a[y][x])\r\n b.append(l)\r\n return b\r\ndef flip(a):\r\n b=[]\r\n for x in range(len(a)):\r\n l=[]\r\n for y in range(len(a)-1,-1,-1):\r\n ... | {"inputs": ["4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX", "2\nXX\nOO\nXO\nOX", "1\nO\nO", "1\nX\nO", "2\nOX\nXX\nOX\nXX", "2\nOX\nXO\nXO\nOX", "2\nOX\nOX\nXX\nOX", "2\nOO\nOO\nOO\nOO", "2\nOX\nOX\nXO\nXO", "10\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOX... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
4f84f706f58aeadbed87aac8b2b1859c | Multiplication Table | 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* ... | [
"import sys, threading\ninput = sys.stdin.readline\nfrom collections import defaultdict\ninput = sys.stdin.readline\n\n# returns the first number where key becomes true for a given delegate type key\ndef bs(low=1, high=1, key = lambda x: True):\n\n while low <= high:\n mid = (low + high)//2\n if ke... | {"inputs": ["2 2 2", "2 3 4", "1 10 5", "1 1 1", "10 1 7", "10 10 33", "500000 500000 1", "500000 500000 250000000000", "3 3 1", "3 3 2", "3 3 3", "3 3 5", "3 3 8", "3 3 9", "1 500000 74747", "500000 1 47474", "499975 499981 12345", "499997 499989 248758432143", "5 1 2", "2 2 4", "1 2 1", "2 44 36", "2 28 49", "3 48 30... | UNKNOWN | PYTHON3 | CODEFORCES | 34 | |
4f926e59c7bf0478b3b3f334a6fa879a | Shell Game | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | [
"print(\"012102120210201021\"[int(input())%6*3+int(input())])\n\t\t \t\t\t \t \t\t \t\t \t\t \t \t \t\t\t\t",
"n = int(input())\nx = int(input())\na = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]\n\nprint(a[n % 6][x])\n",
"n=int(input())\r\nn%=6\r\na=[0,1,2]\r\nfor i in range(n):\r\n ... | {"inputs": ["4\n2", "1\n1", "2\n2", "3\n1", "3\n2", "3\n0", "2000000000\n0", "2\n0", "2\n1", "4\n0", "4\n1", "5\n0", "5\n1", "5\n2", "6\n0", "6\n1", "6\n2", "7\n0", "7\n1", "7\n2", "100000\n0", "100000\n1", "100000\n2", "99999\n1", "99998\n1", "99997\n1", "99996\n1", "99995\n1", "1999999995\n0", "1999999995\n1", "19999... | UNKNOWN | PYTHON3 | CODEFORCES | 172 | |
4f96c364ed54ea97246ce9afac3b7d1b | Closest Equals | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that:
- both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nclass FenwickTreeMinMax:\r\n def __init__(self, n, func, ini):\r\n self.size = n\r\n self.a = [ini] * (n + 1)\r\n self.b = self.a[:]\r\n self.func = func\r\n self.ini = ini\r\n\r\n def _lowbit(self, index):\r\n return i... | {"inputs": ["5 3\n1 1 2 3 2\n1 5\n2 4\n3 5", "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6", "10 6\n2 2 1 5 6 4 9 8 5 4\n1 2\n1 10\n2 10\n2 9\n5 5\n2 8", "1 1\n1\n1 1", "1 3\n1\n1 1\n1 1\n1 1", "2 1\n1 1\n1 2", "2 1\n1 1\n1 1", "2 5\n1 1\n1 1\n1 2\n2 2\n1 2\n1 1", "2 4\n1 2\n1 1\n1 2\n2 2\n1 2"], "outputs": ["1\n-1\n2", "... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
4faaadd1d15296e368288dbc1e242dd8 | Coins | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | [
"n = int(input())\n\ncont = 0\nfor i in range(n, 0, -1):\n if n%i == 0:\n n = i\n \n if cont == 0:\n cont = 1\n else:\n print(' ', end = '')\n \n print(n, end = '')\nprint()\n \t \t \t\t\t\t\t\t \t\t \t\t\t \t \t\t\t",
"n = int(input())... | {"inputs": ["10", "4", "3", "2", "5", "6", "7", "1", "8", "12", "100", "1000", "10000", "100000", "1000000", "509149", "572877", "152956", "733035", "313114", "893193", "473273", "537000", "117079", "784653", "627251", "9", "999999", "120", "720", "648", "2430", "119070", "15", "21", "25", "100", "524287", "1000000", "... | UNKNOWN | PYTHON3 | CODEFORCES | 86 | |
4fb8a4af89091c7d09f011d25922a148 | Crossword solving | Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta... | [
"n, m = map(int, input().split())\r\ns = input()\r\nt = input()\r\n\r\nres = [0] * 10000\r\nfor i in range(m - n + 1):\r\n asd = []\r\n for j in range(n):\r\n if t[i + j] != s[j]:\r\n asd.append(j + 1) \r\n if len(asd) < len(res):\r\n res = asd\r\nprint(len(res))\r\nprint(*res)\r... | {"inputs": ["3 5\nabc\nxaybz", "4 10\nabcd\nebceabazcd", "1 1\na\na", "1 1\na\nz", "3 5\naaa\naaaaa", "3 5\naaa\naabaa", "5 5\ncoder\ncored", "1 1\nz\nz", "1 2\nf\nrt", "1 2\nf\nfg", "1 2\nf\ngf", "2 5\naa\naabaa", "2 5\naa\navaca", "3 5\naaa\nbbbbb", "3 5\naba\ncbcbc", "3 5\naba\nbbbbb", "3 5\naaa\naabvd", "3 5\nvvv\n... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
4fcfeab57c0f51c448943dcc7cb20eb1 | Knights of a Polygonal Table | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | [
"from heapq import heappush, heappushpop\n\nn, k = map(int, input().split())\npp = list(map(int, input().split()))\nid = sorted(range(n), key=pp.__getitem__)\ncc = list(map(int, input().split()))\nrr, hh, s, t = cc[:], [], 0, 0\nfor i in id:\n p = pp[i]\n while pp[id[t]] < p:\n c = cc[id[t]]\n i... | {"inputs": ["4 2\n4 5 9 7\n1 2 11 33", "5 1\n1 2 3 4 5\n1 2 3 4 5", "1 0\n2\n3", "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9", "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "2 0\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 73 | |
4fe0252045164e7628be3435258cb5a1 | Alice and Bob | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | [
"from math import gcd\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ng = a[0]\r\nmax = a[0]\r\nfor i in a:\r\n if i > max:\r\n max = i\r\n g = gcd(g, i)\r\n\r\nans = (max // g) - n\r\n\r\nif ans % 2 == 0:\r\n print(\"Bob\")\r\nelse:\r\n print(\"Alice\")",
"import functools\r\... | {"inputs": ["2\n2 3", "2\n5 3", "3\n5 6 7", "10\n72 96 24 66 6 18 12 30 60 48", "10\n78 66 6 60 18 84 36 96 72 48", "10\n98 63 42 56 14 77 70 35 84 21", "2\n1 1000000000", "2\n1000000000 999999999", "3\n2 4 6", "2\n4 6", "2\n2 6", "2\n6 2", "10\n100000000 200000000 300000000 400000000 500000000 600000000 700000000 8000... | UNKNOWN | PYTHON3 | CODEFORCES | 98 | |
4fe552649d99fa72c49afc64c9577426 | Lucky Division | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | [
"n=int(input(\"\"))\r\nwhile not(1<=n<=1000):\r\n n=int(input(\"\"))\r\nl=[4,7,47,74,477,447,444,44,77,777,774,744,474]\r\np=len(l)\r\ni=0\r\ntest=False\r\nwhile not test and i<p:\r\n if n%l[i]==0:\r\n test=True\r\n else:\r\n i+=1\r\nif test:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\"... | {"inputs": ["47", "16", "78", "48", "100", "107", "77", "477", "480", "1", "3", "4", "49", "56", "124", "1000", "999", "298", "274", "998", "42", "788", "70", "444", "777", "799", "25", "882", "88", "11", "2", "7", "8", "94", "477", "141"], "outputs": ["YES", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "NO", ... | UNKNOWN | PYTHON3 | CODEFORCES | 451 | |
4ff1d09db6f2d9a2ebec4be3201d5014 | Squats | Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe... | [
"def main():\n input()\n s = input()\n ta = t = (s.count('x') - s.count('X')) // 2\n res = []\n if t > 0:\n for c in s:\n if t and c == 'x':\n c = 'X'\n t -= 1\n res.append(c)\n else:\n for c in s:\n if t and c == 'X':\n ... | {"inputs": ["4\nxxXx", "2\nXX", "6\nxXXxXx", "4\nxXXX", "2\nXx", "22\nXXxXXxxXxXxXXXXXXXXXxx", "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx", "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX", "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXx... | UNKNOWN | PYTHON3 | CODEFORCES | 177 | |
50193bc9e697c53d3b8f630d05729da8 | Elections | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | [
"m, n = input().split()\ncand = []\nfor i in range (int(m)):\n\tcand.append(0)\n\t\nfor i in range (int(n)):\n\ta = [int(x) for x in input().split()]\n\tcand[a.index(max(a))] += 1\n\t\nprint(cand.index(max(cand)) + 1)\n\t\n\t\n",
"n, m = list(map(int,input().split()))\na = [0]*n\nfor i in range(m):\n\tb = list(ma... | {"inputs": ["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "1 3\n5\n3\n2", "3 1\n1 2 3", "3 1\n100 100 100", "2 2\n1 2\n2 1", "2 2\n2 1\n2 1", "2 2\n1 2\n1 2", "3 3\n0 0 0\n1 1 1\n2 2 2", "1 1\n1000000000", "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9", "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 180 | |
5027834466ec82df4cc3c1242f683414 | none | A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell... | [
"def print_line(base, start, end):\n if start > end:\n return\n print_vertex(base, start)\n current = start\n while current != end:\n print_vertex(current, current + 1)\n current += 1\n\n\ndef print_branch(base, start, end):\n if start > end:\n return\n current = start\... | {"inputs": ["5 3 2", "8 5 2", "8 4 2", "2 1 1", "10 3 3", "15 6 4", "16 15 14", "1000 51 25", "100000 10 7", "3 1 1", "3 2 1", "3 2 2", "4 1 1", "4 2 1", "4 2 2", "4 3 1", "4 3 2", "4 3 3", "8 5 3", "20 19 19", "30 14 14", "33 5 3", "5432 200 100", "5433 200 99", "99999 1 1", "99999 2 1", "99999 7 4", "9999 7 3", "1000... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
50337a54eefe8cc0b248d33a7c217796 | Spelling Check | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d... | [
"s1=input()\r\ns2=input()\r\nraz=len(s1)-1\r\nfor i in range(len(s2)):\r\n if s1[i]!=s2[i]: raz=i;break\r\nfor i in range(raz+1, len(s1)):\r\n if s1[i]!=s2[i-1]: print(0);exit()\r\ni=raz\r\nwhile i>0 and s1[raz]==s1[i-1]: i-=1\r\nprint(raz-i+1)\r\nprint(' '.join(map(str, range(i+1,raz+2))))\r\n",
"import sy... | {"inputs": ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces", "ab\na", "bb\nb", "aab\nab", "aabb\nabb", "babaacaacaa\nbbaacaacaa", "bccaabbcccc\nbccaabcccc", "ababcaabaaa\nabacaabaaa", "cccacaccacb\ncccacaccac", "aaaaaaaaaaa\naaaaaaaaaa", "lcaaxcbcjca\nccaaacccca", "babbbtaamba\nbabbbaabba", "xdfxmcnzpch... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
503aa9522a8ac3af4f5e2355c3273d17 | Sereja and Contest | During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants.
Let's assume that *n* people took part in the contest. Let's assume that the participant who got the first place has rating *a*1, the second place participant has rating *a*2, ..... | [
"from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\ndef fn(a):\r\n print('a',a)\r\n n=len(a)\r\n pos1=[0]\r\n for i in range(1,n):\r\n pos1+=[pos1[-1]+a[i]*i]\r\n print('pos1',pos1)\r\n neg=[]\r\n for i in rang... | {"inputs": ["5 0\n5 3 4 1 2", "10 -10\n5 5 1 7 5 1 2 4 9 2"], "outputs": ["2\n3\n4", "2\n4\n5\n7\n8\n9"]} | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
50551a5504711861b7c6daf400d98f68 | Sleepy Game | Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of *n* vertices and *m* edges. One of the vertices contains a chip. Initially the chip is located at vertex *s*. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who c... | [
"import sys\r\ninput=sys.stdin.readline\r\nn,m=map(int,input().split())#10w,20w\r\ng=[set()]\r\nvisited={}\r\nend=set()\r\nans=[]\r\ncycle=[]\r\nfor i in range(n):\r\n inp=list(map(int, input().split()))\r\n if inp[0]==0:\r\n end.add(i+1)\r\n g.append(set(inp[1:]))\r\ns=int(input())\r\npath={s}\r\nwh... | {"inputs": ["5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1", "3 2\n1 3\n1 1\n0\n2", "2 2\n1 2\n1 1\n1", "92 69\n1 76\n1 14\n1 9\n0\n1 46\n1 80\n0\n0\n1 77\n0\n1 53\n1 81\n1 61\n1 40\n0\n1 20\n1 71\n1 24\n1 54\n1 82\n1 23\n0\n1 63\n1 25\n1 38\n1 68\n0\n1 65\n0\n1 76\n1 55\n1 87\n1 1\n1 37\n1 68\n1 30\n1 17\n1 19\n0\n1 16\n1 69\n0\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
50791db071f3edbf0b1751f2239c954b | Coin Troubles | In the Isle of Guernsey there are *n* different types of coins. For each *i* (1<=≤<=*i*<=≤<=*n*), coin of type *i* is worth *a**i* cents. It is possible that *a**i*<==<=*a**j* for some *i* and *j* (*i*<=≠<=*j*).
Bessie has some set of these coins totaling *t* cents. She tells Jessie *q* pairs of integers. For each *i... | [
"'''\r\n有n种价值为a[i]的硬币,某人拥有总值为t的硬币,已知q对数字(b,c)中,所有的b之间不同、\r\n所有的c之间不同,其拥有的第b种币数量>第c种。求所有可能的方案数,并取模。\r\n\r\n方案数为0的情况:数对表示的大小关系形成环(dfs检测环)\r\n进行预处理之后使用完全背包\r\n'''\r\nR,P,G=lambda:map(int,input().split()),print,range;n,q,t=R();n+=1;a=[0]+[*R()]\r\n# 图的预处理这块没看明白\r\ng,d=[0]*n,[0]*n\r\nfor _ in G(q):u,v=R();g[u]=v;d[v]+=1... | {"inputs": ["4 2 17\n3 1 2 5\n4 2\n3 4", "3 2 6\n3 1 1\n1 2\n2 3", "3 2 10\n1 2 3\n1 2\n2 1", "10 0 97\n7 2 10 5 10 5 8 9 6 2", "10 2 11\n4 9 3 1 4 10 2 6 10 8\n3 6\n6 4", "10 4 18\n9 2 8 2 7 4 9 5 10 9\n7 9\n9 2\n2 5\n5 10", "10 0 96374\n9 4 9 8 4 1 10 1 6 6", "10 5 857\n3 9 8 10 10 5 3 3 8 1\n6 9\n9 2\n2 7\n4 3\n8 10... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
508e636f3924d8df0d7fac38849e57da | none | Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, *A* and *B*. Each of them has certain number of rows which are distributed on different number of partitions. Table *A* is distributed on the first cluster cons... | [
"n,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nb = sorted(list(map(int,input().split())))\r\n\r\ndef solve(a, b):\r\n s = sum(b)\r\n l = len(a)\r\n ans = len(a) * sum(b)\r\n temp = 0\r\n for i in range(l-1):\r\n temp += a[i]\r\n ans = min(ans, (l - i - ... | {"inputs": ["2 2\n2 6\n3 100", "2 3\n10 10\n1 1 1", "2 2\n888381664 866366630\n170399907 404233949", "3 4\n337369924 278848730 654933675\n866361693 732544605 890800310 350303294", "10 10\n510955240 684852706 455356451 284505713 595775142 646334608 563116339 941123613 818750895 516673753\n382626402 204542396 341363992 2... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
50deaa2fdf386fcdaf44f03cf4706b8e | A rectangle | Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will... | [
"x1,y1,x2,y2 = map(int,input().split())\r\nprint((x2-x1)//2*(y2-y1+1)+(y2-x1)//2-(y1-x1)//2+1)"
] | {"inputs": ["1 1 5 5", "-1 -3 1 3", "-2 -2 2 2", "0 0 2 2", "0 0 2 0", "0 0 0 0", "0 -2 0 2", "-2 -2 -2 0", "-1000000000 -1000000000 1000000000 1000000000", "-999999999 -999999999 999999999 999999999", "-999999999 -999999999 -1 -1", "-411495869 33834653 -234317741 925065545", "-946749893 -687257665 -539044455 -44356867... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
50e08cf44bddd6a4b194ec1f594526c0 | Black Square | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum pos... | [
"def main():\r\n\t(n, m) = (int(x) for x in input().split())\r\n\tL = [None] * n\r\n\tfor i in range(n):\r\n\t\tL[i] = input()\r\n\tprint(solver(n, m, L))\r\n\r\ndef solver(n, m, L):\r\n\ttr = topRow(n, m, L)\r\n\tif tr == -1:\r\n\t\treturn 1\r\n\tbr = bottomRow(n, m, L)\r\n\tlc = leftCol(n, m, L)\r\n\trc = rightCo... | {"inputs": ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW", "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\... | UNKNOWN | PYTHON3 | CODEFORCES | 73 | |
50e3de91cc5521bb0c2850880e212a5f | Commentary Boxes | 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 = [int(x) for x in input().split(' ')]\r\nif n % m == 0:\r\n print(0)\r\nelse:\r\n rem = n % m\r\n add_amt = (m - rem) * a\r\n sub_amt = rem * b\r\n print(add_amt if add_amt < sub_amt else sub_amt)",
"n, m, a, b = [int(i) for i in input().split()]\r\rif n % m != 0:\r print(min((m - n... | {"inputs": ["9 7 3 8", "2 7 3 7", "30 6 17 19", "500000000001 1000000000000 100 100", "1000000000000 750000000001 10 100", "1000000000000 750000000001 100 10", "42 1 1 1", "1 1000000000000 1 100", "7 2 3 7", "999999999 2 1 1", "999999999999 10000000007 100 100", "10000000001 2 1 1", "29 6 1 2", "99999999999 6 100 100",... | UNKNOWN | PYTHON3 | CODEFORCES | 269 | |
510995f0772298cdcea496ca8e30b37f | Jamie and Alarm Snooze | 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 ... | [
"import datetime\r\n\r\nn = int(input())\r\na , b = input().split()\r\n\r\nx = datetime.timedelta(hours= int(a) , minutes=int(b))\r\nc = 0\r\nwhile '7' not in str(x):\r\n x -= datetime.timedelta(hours= 0 , minutes=n)\r\n c +=1\r\n\r\nprint(c)",
"x = int(input())\r\n\r\nh, m = [int(x) for x in input().split(... | {"inputs": ["3\n11 23", "5\n01 07", "34\n09 24", "2\n14 37", "14\n19 54", "42\n15 44", "46\n02 43", "14\n06 41", "26\n04 58", "54\n16 47", "38\n20 01", "11\n02 05", "55\n22 10", "23\n10 08", "23\n23 14", "51\n03 27", "35\n15 25", "3\n12 15", "47\n00 28", "31\n13 34", "59\n17 32", "25\n11 03", "9\n16 53", "53\n04 06", "... | UNKNOWN | PYTHON3 | CODEFORCES | 221 | |
510c8b6e384edf5cc7c5ebc9f24ffc8d | Die Roll | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | [
"y,w=map(int,input().split())\r\nprobability=[\"\", \"1/1\", \"5/6\", \"2/3\", \"1/2\", \"1/3\", \"1/6\"]\r\nprint(probability[max(y,w)])",
"a,b = map(int,input().split())\nv = max(a,b)\nv = (6-v)+1\nif(v==1):\n print(\"1/6\")\nelif(v==2):\n print(\"1/3\")\nelif(v==3):\n print(\"1/2\")\nelif(v==4):\n ... | {"inputs": ["4 2", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "2 1", "2 2", "2 3", "2 4", "2 5", "2 6", "3 1", "3 2", "3 3", "3 4", "3 5", "3 6", "4 1", "4 3", "4 4", "4 5", "4 6", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6"], "outputs": ["1/2", "1/1", "5/6", "2/3", "1/2", "1/3", "... | UNKNOWN | PYTHON3 | CODEFORCES | 1,289 | |
51541df11a68a266455ed6830f33bb89 | 3-cycles | During a recent research Berland scientists found out that there were *n* cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose thr... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict,deque\r\ndef I(): return int(input())\r\ndef II(): return list(map(int, input().split()))\r\ndef S(): return input()[:-1]\r\ndef M(n): return [list(map(int, input().split())) for ___ in range(n)]\r\ndef pb(b): print('YES' if b else 'NO... | {"inputs": ["3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "11", "13", "16", "18", "19", "12", "22", "23", "15", "29", "31", "33", "36", "40", "42", "47", "50", "52", "59", "63", "64", "68", "75", "77", "81", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"], "outputs": ["2\... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
5178b46518ed8b00d8287e9a143991df | New Year Tree | The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.
The New Year tree is an undirected tree with *n* vertices and root in the vertex 1.
You should process the queries of the two types:
1. Cha... | [
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\ndef popcount(n):\r\n c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555)\r\n c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333)\r\n c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f)\r\n c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff... | {"inputs": ["7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3", "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
517c2823ba28b9c195cdcd650d4db4fb | 2 + 2 != 4 | One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution...
The only line of input data contains the arithmetic ex... | [
"# LUOGU_RID: 101738980\ns = input()\r\nans = eval(s)\r\nfor i in range(len(s)):\r\n if s[i] == '+':\r\n x = -5\r\n j = i + 1\r\n while j < len(s) and s[j] not in '+-':\r\n x *= 10\r\n j += 1\r\n ans += x\r\n if s[i] == '-':\r\n x = 3\r\n j = i +... | {"inputs": ["8-7+6-5+4-3+2-1-0", "2+2", "112-37", "255+255+255+255+255+255+255+255+255+255", "0-255-255-255-255-255-255-255-255-255", "0+0+0+0+0+0+0+0+0+0", "0-0-0-0-0-0-0-0-0-0", "0+100+100+100+100+100+100+100+100+100", "255-100-100-100-100-100-100-100-100-100", "45+5", "23+6-9", "123+234-56-78-90", "97+67+12+9+42+45+... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
51871bcfc6ef6119fe456069494bd418 | Tricky Alchemy | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | [
"a, b = map(int, input().split())\nx, y, z = map(int, input().split())\n\nneed_yellow = x * 2 + y\nneed_blue = y + z * 3\n\nyellow_diff = max(0, need_yellow - a)\nblue_diff = max(0, need_blue - b)\n\ntotal_diff = yellow_diff + blue_diff\n\nprint(total_diff)\n\n\t \t\t\t \t\t \t \t \t\t \t\t \t\t\t\t",
"Y ,... | {"inputs": ["4 3\n2 1 1", "3 9\n1 1 3", "12345678 87654321\n43043751 1000000000 53798715", "12 12\n3 5 2", "770 1390\n170 442 311", "3555165 6693472\n1499112 556941 3075290", "0 0\n1000000000 1000000000 1000000000", "1 1\n0 1 0", "117708228 562858833\n118004008 360437130 154015822", "999998118 700178721\n822106746 8298... | UNKNOWN | PYTHON3 | CODEFORCES | 401 | |
519044032d5415fdfdd43cc483036c0a | Test | Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop... | [
"import sys\r\nimport random\r\nimport sys\r\nfrom itertools import permutations\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def read_int():\r\n return int(sys.stdin.readline().strip())\r\n\r\n @staticmethod\r\n def read_float():\r\n retu... | {"inputs": ["ab\nbc\ncd", "abacaba\nabaaba\nx", "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls", "jwdezvgfm\nmdoqvylpuvyk\nqylldbziva", "ujgquqxdlowuwnqkmbd\nwdwkhkdgsujgqu\njlxqvcuivagmw", "rdtevvmiqmfgvafkdypxjthzhfsbavmhgkavkfonscaokdxoscenpxrc\nijbvueenz... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
519062580288920390ab5b9c5f1e5dd1 | Divisible by Seven | You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resu... | [
"N=input()\r\ncnt=[0,0,0,0,0,0,0,0,0,0]\r\nfor c in N:\r\n cnt[ord(c)-48]+=1\r\ncnt[1]-=1\r\ncnt[6]-=1\r\ncnt[8]-=1\r\ncnt[9]-=1\r\nans=[1869,1968,1689,6198,1698,1986,1896]\r\nres=\"\"\r\nmod=0\r\nfor i in range(9,0,-1):\r\n for j in range(cnt[i]):\r\n res+=str(i)\r\n mod=(mod*3+i)%7\r\nres+=str... | {"inputs": ["1689", "18906", "2419323689", "8589157262", "2717172350336955863014903670481525170997949309274087058935108848979319747543008692128164875210350026", "9825995656040286793128006047268547610068699214477842995873286607346639816314908021369221299622234988", "100000000689", "16891", "16892", "16893", "16894", "16... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
51911583dab871f5ea0ac52588a84b8b | Antimatter | Iahub accidentally discovered a secret lab. He found there *n* devices ordered in a line, numbered from 1 to *n* from left to right. Each device *i* (1<=≤<=*i*<=≤<=*n*) can create either *a**i* units of matter or *a**i* units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify... | [
"n = int(input())\r\nnums = list(map(int, input().split()))\r\nmod = 10 ** 9 + 7\r\n\r\ndp = [0] * 20001\r\n\r\nans = 0\r\nfor num in nums:\r\n new_dp = [0] * 20001\r\n for i in range(20001):\r\n if dp[i]:\r\n new_dp[i+num] += dp[i]\r\n new_dp[i+num] %= mod\r\n new_dp[i... | {"inputs": ["4\n1 1 1 1", "10\n16 9 9 11 10 12 9 6 10 8", "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3", "100\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 3 4 2 3 5 3 6 5 3 6 5 6 6 2 6 4 5 5 4 6 4 3 2 8 5 6 6 7 4 4 9 5 6 6 3 7 1 6 2 6 5 9 3 8 6 2 6 3 2 4 4 3 5 4 7 6 5 4 6 3... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
51b23f121a010950ffd4756d31d02d4a | Fafa and Ancient Alphabet | Ancient Egyptians are known to have used a large set of symbols to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words *S*1 and *S*2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the words w... | [
"'''\r\n Python3(PyPy3) Template for Programming-Contest.\r\n'''\r\n\r\nimport sys\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().rstrip()\r\n\r\n\r\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\r\nmod = int(1e9 + 7)\r\ninf = 1 << 64\r\n\r\n\r\ndef main():\r\n n,M = map(int,input().split())\r\... | {"inputs": ["1 2\n0\n1", "1 2\n1\n0", "7 26\n0 15 12 9 13 0 14\n11 1 0 13 15 12 0", "6 26\n14 5 19 18 9 14\n0 0 0 0 0 0", "4 26\n0 0 0 0\n13 15 18 1", "5 100\n0 0 0 0 0\n0 0 0 0 0", "7 30\n11 1 0 13 15 12 0\n0 15 12 9 13 0 14", "4 50\n19 1 19 1\n19 1 19 15", "4 50\n19 1 19 15\n19 1 19 1", "107 100000\n0 0 0 0 0 0 0 0 0... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
51cf8476c1c8c68b031ab3f1f1625c98 | Points on the line | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | [
"n,d = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nj = ans = 0\r\nfor i in range(n):\r\n while j<n and arr[j]-arr[i]<=d: j += 1\r\n ans = max(ans,j-i)\r\nprint(n-ans)",
"n, d = map(int, input().split())\narr = list(map(int, input().split()))\narr.sort()\n\n# finding lar... | {"inputs": ["3 1\n2 1 4", "3 0\n7 7 7", "6 3\n1 3 4 6 9 10", "11 5\n10 11 12 13 14 15 16 17 18 19 20", "1 100\n1", "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 5... | UNKNOWN | PYTHON3 | CODEFORCES | 121 | |
51dcd299d4c1375028194acc6f588742 | Vitaly and Strings | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | [
"from bisect import bisect_left, bisect_right\r\nfrom collections import Counter, deque\r\nfrom functools import lru_cache\r\nfrom math import factorial, comb, sqrt, gcd, lcm\r\nfrom copy import deepcopy\r\nimport heapq\r\n\r\ndef num_to_str(n):\r\n chushu = (n - 1) // 26\r\n yushu = (n - 1) % 26\r\n if ch... | {"inputs": ["a\nc", "aaa\nzzz", "abcdefg\nabcdefh", "abcdefg\nabcfefg", "frt\nfru", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz... | UNKNOWN | PYTHON3 | CODEFORCES | 118 | |
51ea43be131b02c7ef7343fe9f2b02c0 | Secret Combination | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | [
"def main():\n input()\n digits = list(map(int, input()))\n l = [digits]\n for a in range(1, 10):\n l.append([(a + b) % 10 for b in digits])\n for digits in l[:]:\n a = digits[-1]\n for i, b in enumerate(digits):\n if a and not b:\n l.append(digits[i:] +... | {"inputs": ["3\n579", "4\n2014", "1\n1", "3\n039", "4\n4444", "5\n46802", "10\n4447444444", "10\n5810438174", "30\n027027027027027027027027027027", "50\n41012516454101251645410125164541012516454101251645", "72\n464553044645330446455304464553064645530445455304464553044645530446455304", "100\n2144315253572020279108092911... | UNKNOWN | PYTHON3 | CODEFORCES | 89 | |
525529e7c4f14a1e5c41a441db482ecb | Mister B and Flight to the Moon | In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with *n* vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
We are sure that Mister B will solve the problem soon and will fly to the ... | [
"import sys\r\n\r\n\r\ndef solve(n):\r\n if n == 3:\r\n return [(1, 2, 3)]*2\r\n if n == 4:\r\n return [(1, 2, 3, 4), (1, 2, 4, 3), (1, 4, 2, 3)]\r\n else:\r\n return [*solve(n-2), (n, n - 1, 1), (n, n - 1, n - 2), *[(n, i, n - 1, i + 1) for i in range(1, n - 2)]]\r\n\r\n\r\nanswer = s... | {"inputs": ["3", "5", "299", "300", "4", "5", "6", "7", "8", "9", "10", "298", "297", "11", "14", "21", "28", "35", "42", "49", "56", "63", "70", "77", "84", "91", "98", "105", "112", "119", "126", "133", "140", "147", "154", "161", "168", "175", "182", "189", "196", "203", "210", "217", "224", "231", "238", "245", "25... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
528e74abdd6f1a9f497825c446f2ef2b | Chewbaсca and Number | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | [
"s=input()\r\nss=\"\"\r\nfor i in range(len(s)):\r\n if i==0 and s[i]=='9':\r\n ss+=s[i]\r\n continue\r\n if int(s[i])>9-int(s[i]):\r\n ss+=str(9-int(s[i]))\r\n else:\r\n ss+=s[i]\r\nprint(ss)\r\n ",
"a = int(input())\nt = 0\nb = a\nc = 1\nr = 0\n\nwhile a > 0:\n t =... | {"inputs": ["27", "4545", "1", "9", "8772", "81", "71723447", "91730629", "420062703497", "332711047202", "3395184971407775", "8464062628894325", "164324828731963982", "384979173822804784", "41312150450968417", "2156", "1932", "5902", "5728", "8537", "55403857", "270739", "28746918", "10279211", "40289679", "5452032385... | UNKNOWN | PYTHON3 | CODEFORCES | 346 | |
5292b9c42c14e162f4ce34076de89ae1 | none | Little Elephant loves Furik and Rubik, who he met in a small city Kremenchug.
The Little Elephant has two strings of equal length *a* and *b*, consisting only of uppercase English letters. The Little Elephant selects a pair of substrings of equal length — the first one from string *a*, the second one from string *b*. ... | [
"total = 0\n\ndef solve(A, B, next):\n global s\n global t\n\n total = 0\n\n for iord in range(ord('A'), ord('Z') + 1):\n i = chr(iord)\n\n if (i not in A) or (i not in B):\n continue\n\n SP = [0 for _ in range(len(s) + 5)]\n\n for j in B[i]:\n SP[j] += len(t) - j\n\n ... | {"inputs": ["2\nAB\nBA", "3\nAAB\nCAA", "7\nAAAAAAA\nBBBBBBB", "4\nAAAA\nAAAB", "10\nSATYFFJYBA\nBGFOBFBVAV", "1\nA\nA", "1\nA\nZ", "14\nBABBABABABABAA\nBABABAABAAABAB", "10\nQUDLGGRJEG\nMIZIEZRCJU", "47\nGMQXICWAZQNJFYHHAFWXZOLNEZGUIPEKMWPWXLXUBDFONZF\nXSGRAAAFYJBCJYECMTWRTZNKVWMSVYJOFDNZFEFYLWGUGYX", "25\nYWORWQKEMDA... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
5298cee5f0c18b0718c0ec3fe8bd388a | Wet Shark and Flowers | There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too.
Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equipro... | [
"import os, sys\r\nfrom io import BytesIO, IOBase\r\nmod=10**9+7\r\nfrom math import gcd\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n#n,a,b,p,q=map(int,input().split())\r\nn,p=map(int,input().split())\r\na=[0]*n\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n l-=1\r\n a[i]=... | {"inputs": ["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14", "3 3\n3 3\n2 4\n1 1", "5 5\n5 204\n420 469\n417 480\n442 443\n44 46", "3 2\n2 2\n3 3\n4 4", "6 7\n8 13\n14 14\n8 13\n14 14\n8 13\n14 14", "3 7\n7 14\n700000000 700000007\n420 4200", "5 999999937\n999999935 999999936\n999999937 999999938\n999999939 ... | UNKNOWN | PYTHON3 | CODEFORCES | 52 | |
52bb700295732c2b5c9555abba470fd8 | Kids' Riddle | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
The input contains a single integer *n* (0<=≤<=*n*<=≤<=2000000000).
Output a single integer.
Sample Input
11
14
61441
571576
2128506
Sample Output
2
0
2
10
3
| [
"n=int(input())\r\nsumx=0\r\nif(n==0):\r\n\tprint(1)\r\nelse:\r\n\twhile(n>0):\r\n\t\ta=n%16\r\n\t\tif(a<10):\r\n\t\t\tif(a==0 or a==4 or a==6 or a==9):\r\n\t\t\t\tsumx+=1\r\n\t\t\telif(a==8):\r\n\t\t\t\tsumx+=2\r\n\t\telif(a==10 or a==13):\r\n\t\t\tsumx+=1\r\n\t\telif(a==11):\r\n\t\t\tsumx+=2\r\n\t\tn=n//16\r\n\tp... | {"inputs": ["11", "14", "61441", "571576", "2128506", "0", "2000000000", "143165576", "1741", "1919020031", "1795248373", "1818960378", "1285316221", "1309028227", "1304312649", "1180540990", "1204252996", "1199537418", "1075765759", "724264821", "747976826", "624205168", "619489590", "643201595", "638486017", "5147143... | UNKNOWN | PYTHON3 | CODEFORCES | 33 | |
52bdea90e6852a13d360805c66942d58 | Finite or not? | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | [
"input()\nprint('\\n'.join(['Infinite' if p * pow(b, 99, q) % q else 'Finite' for p, q, b in map(lambda l: map(int, l.split()), __import__('sys').stdin.readlines())]))\n",
"from sys import stdin\n\n_, *l = stdin.read().splitlines()\nfor i, s in enumerate(l):\n p, q, b = map(int, s.split())\n l[i] = 'Infinit... | {"inputs": ["2\n6 12 10\n4 3 10", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4", "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2", "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10", "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4", "10\n5 8 2\n0 ... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
52c301e110c218203ec5f2e7b16fdaef | k-substrings | You are given a string *s* consisting of *n* lowercase Latin letters.
Let's denote *k*-substring of *s* as a string *subs**k*<==<=*s**k**s**k*<=+<=1..*s**n*<=+<=1<=-<=*k*. Obviously, *subs*1<==<=*s*, and there are exactly such substrings.
Let's call some string *t* an odd proper suprefix of a string *T* iff the foll... | [
"import random\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef is_Prime(n):\r\n if n == 1:\r\n return False\r\n for i in range(2, min(int(n ** (1 / 2)) + 2, n)):\r\n if n % i == 0:\r\n return False\r\n return True\r\n\r\ndef random_m... | {"inputs": ["15\nbcabcabcabcabca", "24\nabaaabaaaabaaabaaaabaaab", "19\ncabcabbcabcabbcabca", "2\nza", "20\nbbbaaabbbbbbbbaaabbb", "2\nzz", "3\ndad", "4\naccd", "5\naabcd", "6\nbcabbd", "7\nbaaaadd"], "outputs": ["9 7 5 3 1 -1 -1 -1", "15 13 11 9 7 5 3 1 1 -1 -1 1", "5 3 1 -1 -1 1 1 -1 -1 -1", "-1", "9 7 5 3 1 1 7 5 3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
52f5dd7190e4ec2cbb522191d7d08ee6 | Robot Sequence | Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s... | [
"n=int(input())\na=input()\nans=0\nfor i in range(n+1):\n for j in range(i):\n l=a[j:i].count(\"L\") \n r=a[j:i].count(\"R\") \n u=a[j:i].count(\"U\") \n d=a[j:i].count(\"D\") \n if l==r and u==d:\n ans+=1\n \nprint(ans)\n",
"n = int(input())\n\ncode = i... | {"inputs": ["6\nURLLDR", "4\nDLUU", "7\nRLRLRLR", "1\nR", "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL", "200\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... | UNKNOWN | PYTHON3 | CODEFORCES | 166 | |
533ae5b3b2eae7d179cdcdabdab45238 | Little Elephant and Chess | The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d... | [
"ans = 'YES'\r\n\r\nfor _ in range(8):\r\n line = input()\r\n \r\n for i in range(7):\r\n if line[i] == line[i+1]:\r\n ans = 'NO'\r\n break\r\n\r\nprint(ans) ",
"ans = True\r\n\r\nfor i in range(8):\r\n s = input()\r\n for i in range(7):\r\n if s[i] == s[i+1]:\r\... | {"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nW... | UNKNOWN | PYTHON3 | CODEFORCES | 204 | |
53591cfe13dfca10ed3fe3da3e03db20 | Little Artem and Random Variable | Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to *n* inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and d... | [
"n = int(input())\r\nmaxs = list(map(float, input().split()))\r\nmins = list(map(float, input().split()))\r\n\r\nd1s, d2s = [], []\r\ncd1sum, cd2sum = 0, 0\r\n\r\nfor i in range(n):\r\n z = mins[i]+maxs[i]\r\n c = cd2sum\r\n d = cd1sum\r\n s = mins[i]\r\n b = d-z-c\r\n c = z-d*z-s\r\n disc = ma... | {"inputs": ["2\n0.25 0.75\n0.75 0.25", "3\n0.125 0.25 0.625\n0.625 0.25 0.125", "10\n0.01 0.01 0.01 0.01 0.01 0.1 0.2 0.2 0.4 0.05\n1.0 0 0 0 0 0 0 0 0 0", "10\n0 0 0 0 0 0 0 0 0 1.0\n1.0 0 0 0 0 0 0 0 0 0", "1\n1.0\n1.0", "2\n0.00001 0.99999\n0.5 0.5", "3\n0.1 0.1 0.8\n0.6 0.2 0.2", "8\n0.09597231 0.11315755 0.3207711... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
535ff148f11b5e0f05a3efd56473da55 | Ilya and Roads | Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as *n* holes in a row. We will consider the holes numbered from 1 to *n*, from left to right.
Ilya is really keep on helping his city. So, he wants to fix at least *k* holes (perharps he can fix more) on a sing... | [
"INF = 10**18\r\n\r\nn, m, k = map(int, input().split())\r\n\r\ncost = [[INF]*(n+1) for i in range(n+1)]\r\ndp = [[INF]*(n+1) for i in range(n+1)]\r\n\r\nfor i in range(m):\r\n l, r, c = map(int, input().split())\r\n for j in range(l, r+1):\r\n cost[j][r] = min(cost[j][r], c)\r\n\r\ndp[0][0] = 0\r\n\r\... | {"inputs": ["10 4 6\n7 9 11\n6 9 13\n7 7 7\n3 5 6", "10 7 1\n3 4 15\n8 9 8\n5 6 8\n9 10 6\n1 4 2\n1 4 10\n8 10 13", "10 1 9\n5 10 14", "10 6 9\n6 8 7\n2 8 11\n2 6 10\n8 10 9\n2 5 8\n2 3 8", "10 6 8\n3 6 7\n1 4 3\n2 7 10\n4 7 4\n7 10 15\n4 7 7", "10 4 10\n1 1 11\n7 7 15\n2 3 11\n2 8 6", "10 3 7\n4 6 6\n5 7 1\n2 10 15", ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
538e5a259bf9609053b62f07a3684521 | The Child and Toy | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | [
"n, m = map(int, input().split())\r\nx = list(map(int, input().split()))\r\nnum = 0\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n a, b = a - 1, b - 1\r\n num += min(x[a], x[b])\r\n\r\n\r\nprint(num)\r\n",
"from collections import defaultdict\r\nn,m = map(int,input().split())\r\nA = list(... | {"inputs": ["4 3\n10 20 30 40\n1 4\n1 2\n2 3", "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "1 0\n23333", "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5", "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n... | UNKNOWN | PYTHON3 | CODEFORCES | 224 | |
53bf4c704b2a544a0f1fb3c16762f47a | Lineland Mail | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | [
"n=int(input())\r\na=list(map(int, input().split()))\r\nfor i in range(n):\r\n if i==0:\r\n print(abs(a[i+1]-a[i]),end=\" \")\r\n elif i==n-1:\r\n print(abs(a[n-1]-a[n-2]),end=\" \")\r\n else:\r\n print(min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])),end=\" \")\r\n print(max(abs(a[i]-a[0]),a... | {"inputs": ["4\n-5 -2 2 7", "2\n-1 1", "3\n-1 0 1", "4\n-1 0 1 3", "3\n-1000000000 0 1000000000", "2\n-1000000000 1000000000", "10\n1 10 12 15 59 68 130 912 1239 9123", "5\n-2 -1 0 1 2", "5\n-2 -1 0 1 3", "3\n-10000 1 10000", "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "10\n-857422304 -529223472 82412... | UNKNOWN | PYTHON3 | CODEFORCES | 608 | |
53c54a45f7b49ca7ba7f34ca352c10d6 | Dog Show | A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as poss... | [
"# using the min-heap \r\nfrom heapq import heappush,heappop\r\nbowels,Time = map(int,input().split())\r\nmyLine = [-int(b) for b in input().split()]\r\ngulp = []; eat = 0\r\nfor i in range(1,min(bowels+1,Time)):\r\n while gulp and -gulp[0] >= Time - i:\r\n # remove the bowel with the highest time penalty... | {"inputs": ["3 5\n1 5 3", "1 2\n1", "1 1\n1", "1 1\n2", "2 2\n2 3", "2 3\n2 1", "3 3\n2 3 2", "3 2\n2 3 4", "3 4\n2 1 2", "4 4\n2 1 2 3", "4 3\n2 1 2 3", "4 6\n2 3 4 5", "5 5\n2 1 2 3 4", "5 3\n2 3 2 1 2", "5 7\n2 1 2 3 4", "6 6\n2 3 2 3 4 3", "6 4\n2 3 2 3 4 3", "6 9\n2 1 2 1 2 3", "7 7\n2 3 4 5 6 5 6", "7 4\n2 1 2 3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
53de648b0565d1a3703a8ca27e960722 | Nikita and string | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make... | [
"inp = str(input())\r\na = [0] * 3\r\nfor i in inp:\r\n\tif i == 'a':\r\n\t\ta[2] = max(a) + 1\r\n\t\ta[0] += 1\r\n\telse:\r\n\t\ta[1] = max(a[:2]) + 1\r\nprint(max(a))",
"s = input()\r\nn = len(s)\r\na = s.count('a')\r\nb = s.count('b')\r\nans = max(n - a, n - b)\r\npref = [0] * (n + 1)\r\nfor i in range(1, n + ... | {"inputs": ["abba", "bab", "bbabbbaabbbb", "bbabbbbbaaba", "bbabbbababaa", "aabbaababbab", "a", "b", "ab", "ba", "bb", "aa", "babbbaab", "abaaaa", "aaa"], "outputs": ["4", "2", "9", "10", "9", "8", "1", "1", "2", "2", "2", "2", "6", "6", "3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 72 | |
53fa4bd5bc566062e8f1db038d8f15de | Pattern | Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.
In this task, a pattern will be a string con... | [
"for s in zip(*(input()for p in range(int(input())))):\r\n l=set(s)-{'?'}\r\n print('?'if len(l)>1 else l.pop()if l else 'a',end='')",
"def main():\n l = []\n for col in map(set, zip(*[input() for _ in range(int(input()))])):\n col.discard('?')\n l.append(col.pop() if len(col) == 1 else ... | {"inputs": ["2\n?ab\n??b", "2\na\nb", "1\n?a?b", "1\n?", "3\nabacaba\nabacaba\nabacaba", "3\nabc?t\n?bc?z\nab??t", "4\nabc\ndef\n???\nxyz", "2\n?????\n?????", "2\na\na", "3\nabc\n???\naxc", "1\n?m??x?xxexxx?xxmxx??", "2\nhszhh?zszs\nhhzhz?zzhs", "3\neddzde\needded\nzdde?z", "4\nff?o?\nfk?of\nk?kof\nfk?oo", "5\nyigi\ne?... | UNKNOWN | PYTHON3 | CODEFORCES | 74 | |
5400ae66fbdd291d560caf981f43e7e0 | Petya and Staircases | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | [
"n,k=map(int,input().split())\r\nif(k>0):\r\n l=list(map(int,input().split()))\r\n l.sort()\r\nc=0\r\nif(k==0):\r\n print(\"YES\")\r\nelif(l[0]==1 or l[-1]==n):\r\n print(\"NO\")\r\nelse:\r\n for i in range(2,k):\r\n if (l[i]-l[i-1]==1 and l[i-1]-l[i-2]==1):\r\n c=1\r\n b... | {"inputs": ["10 5\n2 4 8 3 6", "10 5\n2 4 5 7 9", "10 9\n2 3 4 5 6 7 8 9 10", "5 2\n4 5", "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "10 10\n7 6 4 2 5 10 8 3 9 1", "12312 0", "9817239 1\n6323187", "1 1\n1", "5 4\n4 2 5 1", "5 3\n4 3 5", "500 3\n18 62 445", "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 4... | UNKNOWN | PYTHON3 | CODEFORCES | 44 | |
5403d9edc0e697bd7a0b0ef11150d83c | Gleb And Pizza | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | [
"r , d = map(int, input().split())\r\nn = int(input())\r\nk = 0\r\nfor i in range(n):\r\n x, y, w = map(int, input().split())\r\n l = (x**2 + y**2)**(1/2)\r\n if l-w >= r-d and l+w <= r:\r\n k += 1\r\nprint(k)",
"#i don't even wanna solve this problem. Just to get out of this.\r\nr,d=map(int,in... | {"inputs": ["8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1", "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2", "1 0\n1\n1 1 0", "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1", "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0", "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1", "... | UNKNOWN | PYTHON3 | CODEFORCES | 190 | |
540cb1fd4a6870c7db9c8333423e798f | Cows and Poker Game | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | [
"\na = int(input())\ns = input()\n\nb = {'A':0, 'I':0, 'F':0}\n\n\nfor i in s:\n b[i] += 1\nif b['I'] > 1:\n print(0)\nelif b['I'] == 1:\n print(1)\nelse:\n print(b['A'])\n\t\n",
"def main():\n n = int(input())\n cows = input()\n \n i_cont = cows.count(\"I\")\n\n if i_cont == 0:\n ... | {"inputs": ["6\nAFFAAA", "3\nAFI", "3\nFFF", "3\nFIF", "3\nAAA", "3\nIII", "3\nIIA", "3\nAFF", "5\nFAFFF", "3\nIAA", "3\nIIF", "2\nFA", "2\nFF", "2\nIF", "5\nAAAAI", "5\nIIIIF", "10\nAAAAAAAAAA", "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "5\nFAIAF", "5\... | UNKNOWN | PYTHON3 | CODEFORCES | 126 | |
549053419f14efeb49ea7377628d5a2d | Mashmokh and Numbers | It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r... | [
"# 414A\r\n\r\nfrom sys import stdin\r\n\r\n__author__ = 'artyom'\r\n\r\nn, k = list(map(int, stdin.readline().strip().split()))\r\n\r\nif n == 1:\r\n if k == 0:\r\n print(1)\r\n else:\r\n print(-1)\r\n exit()\r\n\r\npairs = n // 2\r\nif k < pairs:\r\n print(-1)\r\n exit()\r\n\r\nx, y = 1, 2\r\nif k > pa... | {"inputs": ["5 2", "5 3", "7 2", "1 1", "2 0", "1 10", "1 0", "7 3", "7 6", "7 7", "100000 100000000", "3455 2792393", "74086 16504611", "28515 44887064", "21324 73830196", "90212 5921828", "25095 2372924", "92977 95851971", "39095 77350428", "785 70908164", "28051 5506872", "74077 37498088", "58284 12998910", "28768 3... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
54a78b545ae5ffb4e728231eb0a098e9 | Surrounded | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround... | [
"x1,y1,r1=list(map(float,input().split()))\r\nx2,y2,r2=list(map(float,input().split()))\r\nif r1>r2:\r\n r2,r1=r1,r2\r\nd=((x2-x1)**2 + (y2-y1)**2)**(0.5)\r\nif d>r1+r2:\r\n print((d-(r1+r2))/2)\r\nelif r2>d+r1:\r\n print((r2-(r1+d))/2)\r\nelse:\r\n print(0)",
"import math\r\n\r\nx1,y1,r1=map(int,inpu... | {"inputs": ["0 0 1\n6 0 3", "-10 10 3\n10 -10 3", "2 1 3\n8 9 5", "0 0 1\n-10 -10 9", "10000 -9268 1\n-9898 9000 10", "10000 10000 1\n-10000 -10000 1", "123 21 50\n10 100 1000", "0 3278 2382\n2312 1 1111", "3 4 5\n5 12 13", "-2 7 5\n4 0 6", "4 0 2\n6 -1 10", "41 17 3\n71 -86 10", "761 641 6\n506 -293 5", "-5051 -7339 9... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
54ae528218897038012509ab2051c563 | Broken robot | You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of *N* rows and *M* columns of cells. The robot is initially at some cell on the *i*-th row and the *j*-th column. Then at every step the... | [
"from functools import cache\n\n\nN, M = [int(w) for w in input().split()]\nr, c = [int(w) for w in input().split()]\n# print(N, M, r, c)\n\n# @cache\ndef calc(r: int, c: int) -> float:\n if r == N:\n return 0\n e, a, b = [0.] * M, [0.] * M, [0.] * M\n for l in range(N - 1, r - 1, -1):\n a[0]... | {"inputs": ["10 10\n10 4", "10 14\n5 14", "126 125\n115 22", "755 51\n205 12", "385 978\n344 18", "663 904\n192 518", "293 183\n279 21", "922 109\n431 55", "552 36\n199 35", "182 314\n54 201", "812 240\n561 19", "595 881\n417 120", "694 685\n278 653", "793 840\n534 276", "892 996\n288 751", "990 800\n801 66", "89 955\n... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
54b9ba5fab7b748e49429697be63d53e | Present from Lena | Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to *n* as the pattern. The digits will form a rhombus. The largest digit *n* should be located in the centre. The digits should decrease as they approach the edges. For example, for *n*<==<=5 t... | [
"x=int(input())\r\nl=x\r\nm=2*x+1\r\narr = [[\" \" for _ in range(m)] for _ in range(m)]\r\nleft=right=l\r\nwhile(x>=0):\r\n up=down=l\r\n y=x\r\n while(y>=0):\r\n arr[up][left]=str(y)\r\n arr[up][right]=str(y)\r\n arr[down][left]=str(y)\r\n arr[down][right]=str(y)\r\n y-... | {"inputs": ["2", "3", "4", "5", "6", "7", "8", "9"], "outputs": [" 0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0", " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n0 1 2 3 4 3 2 1 0\n 0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n ... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
54eabc2821352e7e3a39754857af9e14 | A Game With Numbers | Imagine that Alice is playing a card game with her friend Bob. They both have exactly $8$ cards and there is an integer on each card, ranging from $0$ to $4$. In each round, Alice or Bob in turns choose two cards from different players, let them be $a$ and $b$, where $a$ is the number on the player's card, and $b$ is t... | [
"# My Solution for CF 919/F.\r\nimport sys\r\nimport itertools\r\nfrom collections import deque\r\n\r\nt = int(input())\r\n\r\nhand_size = 8\r\nnum_values = 5\r\nres = 1\r\nfor x in range(hand_size + 1, hand_size + num_values):\r\n res *= x\r\nfor x in range(1, num_values):\r\n res //= x\r\n# res = (handsize ... | {"inputs": ["4\n1\n0 0 0 0 0 0 0 0\n1 2 3 4 1 2 3 4\n1\n0 0 0 1 0 0 0 0\n0 0 0 0 4 0 0 0\n0\n1 0 0 0 0 0 0 0\n0 0 0 4 0 0 2 0\n1\n1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1", "1\n0\n0 2 2 0 1 2 1 2\n1 2 4 3 2 1 1 0"], "outputs": ["Alice\nBob\nAlice\nDeal", "Alice"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
54ef95eac742c7cf136cec111b8e7b83 | Borya's Diagnosis | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | [
"n = int(input())\r\nres = 0\r\n\r\nwhile n > 0:\r\n n -= 1\r\n x, y = input().split()\r\n x = int(x)\r\n y = int(y)\r\n while x <= res:\r\n x += y\r\n res = x\r\n\r\nprint(res)",
"n=int(input())\r\nx=int(input().split()[0])\r\nfor i in range(n-1):\r\n c,d=map(int,input().split())\r\n if c<=x:x=c+(... | {"inputs": ["3\n2 2\n1 2\n2 2", "2\n10 1\n6 5", "3\n6 10\n3 3\n8 2", "4\n4 8\n10 10\n4 2\n8 2", "5\n7 1\n5 1\n6 1\n1 6\n6 8", "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8", "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9", "1\n1 1", "1\n1000 1000", "42\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 67 | |
54f2b0eb96295a35dd0ba51561306f0a | none | Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, w... | [
"AND = \"AND\"\r\nOR = \"OR\"\r\nXOR = \"XOR\"\r\nNOT = \"NOT\"\r\nIN = \"IN\"\r\n\r\nOPS = {\r\n AND: AND,\r\n OR: OR,\r\n XOR: XOR,\r\n NOT: NOT,\r\n}\r\n\r\n\r\nclass Node:\r\n def __init__(self, num):\r\n self.num = num\r\n self.op = None\r\n self.parent = None\r\n sel... | {"inputs": ["10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8", "3\nAND 2 3\nIN 0\nIN 0", "3\nAND 2 3\nIN 1\nIN 0", "3\nAND 2 3\nIN 0\nIN 1", "3\nAND 2 3\nIN 1\nIN 1", "3\nOR 2 3\nIN 0\nIN 0", "3\nOR 2 3\nIN 1\nIN 0", "3\nOR 2 3\nIN 0\nIN 1", "3\nOR 2 3\nIN 1\nIN 1", "3\nXOR 2 3\nIN 0\nIN 0"... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
54f654755a3f3b43fcc1e4463c5ec344 | K-Periodic Array | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it... | [
"n, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(k):\r\n s1, s2 = 0, 0\r\n for j in range(i, n, k):\r\n if A[j] == 1:\r\n s1+=1\r\n else:\r\n s2+=1\r\n ans = ans + min(s1, s2)\r\nprint(ans)",
"I=lambda:map(int,input... | {"inputs": ["6 2\n2 1 2 2 2 1", "8 4\n1 1 2 1 1 1 2 1", "9 3\n2 1 1 1 2 1 1 1 2", "1 1\n2", "2 1\n1 1", "2 2\n2 2", "100 1\n1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 81 | |
5593c830d71188d6cb7298d1414d88e3 | Python Indentation | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | [
"n = int(input())\r\ndp = [[0 for _ in range(n)] for _ in range(n)]\r\ndp[0][0] = 1\r\nMOD = 10**9 + 7\r\nlast = input()\r\nfor i in range(1, n):\r\n x = input()\r\n if x == 'f' and last == 'f':\r\n for j in range(n-1):\r\n dp[i][j+1] = dp[i-1][j] % MOD\r\n elif x == 'f':\r\n res =... | {"inputs": ["4\ns\nf\nf\ns", "4\nf\ns\nf\ns", "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
55ae3df199bb9e610ef7dd2ba38b3fe1 | Shooting Gallery | One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.
The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ... | [
"n = int(input())\nts = sorted((list(map(float,input().strip().split())) for _ in range(n)), key=lambda x:x[2])\nd = [0]*n\nans = 0\nfor i in range(n):\n d[i] = ts[i][3]\n for j in range(i):\n if (ts[i][0]-ts[j][0])**2 + (ts[i][1]-ts[j][1])**2 <= (ts[i][2]-ts[j][2])**2:\n d[i] = max(d[i], d[... | {"inputs": ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7", "1\n-5 2 3 0.886986", "4\n10 -7 14 0.926305\n-7 -8 12 0.121809\n-7 7 14 0.413446\n3 -8 6 0.859061", "5\n-2 -2 34 0.127276\n5 -5 4 0.459998\n10 3 15 0.293766\n1 -3 7 0.089869\n-4 -7 11 0.772515", "5\n2 5 1 0.955925\n9 -9 14 0.299977\n0 1 97 0.114582\n-4 -2 66 0.5610... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
55bd32dabd659fa4145edf5cace46d7e | Maximal Area Quadrilateral | Iahub has drawn a set of *n* points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is o... | [
"import sys\r\ns, n = 0, int(input())\r\nt = list(map(int, sys.stdin.read().split()))\r\np = [(t[2 * i], t[2 * i + 1]) for i in range(n)]\r\nfor x, i in enumerate(p, 1):\r\n for j in p[x:]:\r\n a = b = 0\r\n for k in p:\r\n d = (i[0] - k[0]) * (j[1] - k[1]) - (i[1] - k[1]) * (j[0] - k[0]... | {"inputs": ["5\n0 0\n0 4\n4 0\n4 4\n2 3", "10\n-6 -4\n-7 5\n-7 -7\n5 -7\n4 -9\n-6 7\n2 9\n-4 -6\n2 10\n-10 -4", "4\n-3 3\n0 3\n-2 -1\n2 2", "5\n-4 -3\n-3 -2\n3 3\n-1 2\n3 -3", "6\n-4 -3\n-1 3\n0 0\n2 2\n2 1\n-3 1", "7\n-2 -1\n4 3\n2 2\n-4 0\n-2 4\n0 0\n1 -3", "4\n-874 606\n-996 -207\n897 847\n775 191", "10\n156 -415\n8... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
55d0b2a7f663cfde27c5fb8e3f1bdcd8 | Schedule | At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, beca... | [
"class Event:\n def __init__(self, span_id, point, open=False, close=False):\n self.span_id, self.point = span_id, point\n self.open, self.close = open, close\n self.sort_key = 2 * point + (1 if open else 0)\n self.count = 0\n\nclass Span:\n def __init__(self, left, right):\n ... | {"inputs": ["3\n3 10\n20 30\n1 3", "4\n3 10\n20 30\n1 3\n1 39", "3\n1 5\n2 6\n3 7", "4\n1 5\n5 7\n6 9\n9 10", "11\n717170 795210\n866429 970764\n163324 322182\n677099 717170\n241684 393937\n50433 114594\n970764 997956\n393937 664883\n235698 241684\n795210 832346\n114594 232438", "16\n203671 381501\n58867 59732\n817520 ... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
55e0f5d579ec5fa6ede167fd6433cad2 | Gifts by the List | Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are *n* men in Sasha's family, so let's number them with integers from 1 to *n*.
Each man has at most one father but may have arbitrary number of sons.
Man number *A* is considere... | [
"# [https://codeforces.com/contest/681/submission/37694242 <- https://codeforces.com/contest/681/status/D <- https://codeforces.com/contest/681 <- https://codeforces.com/blog/entry/45425 <- https://codeforces.com/problemset/problem/681/D <- https://algoprog.ru/material/pc681pD]\r\n\r\n(n, m) = map(int, input().spli... | {"inputs": ["3 2\n1 2\n2 3\n1 2 1", "4 2\n1 2\n3 4\n1 2 3 3", "1 0\n1", "2 1\n2 1\n2 2", "2 1\n2 1\n1 2", "4 3\n1 2\n2 3\n3 4\n1 1 3 2", "4 3\n4 3\n3 2\n2 1\n3 4 4 4", "4 3\n1 2\n2 3\n3 4\n1 1 1 2"], "outputs": ["-1", "3\n2\n1\n3", "1\n1", "1\n2", "2\n1\n2", "-1", "-1", "-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
55e2de5ea4444a213d58a4e0107ee79d | none | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is *t*1, and the hot water's temperature is *t*2. The cold water tap can transmit any integer number of water units per second from 0 to *x*1, inclusive. Similarly, the hot water ta... | [
"t1,t2,x1,x2,t0=map(int,input().split())\r\ny1,y2,a1,a2,m=x1,x2,0,0,10000000\r\nwhile True:\r\n t=(t1*y1+t2*y2)/(y1+y2)\r\n if t>=t0:\r\n if t-t0<m:a1,a2,m=y1,y2,t-t0\r\n if y1==0 or y2==0 or t==t0:break\r\n if t>t0:\r\n y2-=1\r\n else:\r\n y1-=1\r\nprint(a1,a2)\r\n",
"from fra... | {"inputs": ["10 70 100 100 25", "300 500 1000 1000 300", "143 456 110 117 273", "10 20 5 5 13", "1 3 1999 3444 2", "100 110 2 2 109", "3746 3797 485 485 3747", "900000 1000000 50000 50000 960000", "1 3 100 100 2", "1 3 100 100 3", "1 1 100 100 1", "1 1 1 1 1", "10 14 1 1 12", "10 14 1 1 13", "10 14 1 1 14", "10 14 1 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
55e557b14d1dcc88b6b22982f8316a5d | Verse Pattern | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel... | [
"vowels = ['a','e','i','o','u','y']\r\nN = int(input())\r\nP = list(map(int, input().split()))\r\nans = True\r\nfor n in range(N):\r\n\ts = input()\r\n\tvc = len(list(True for c in s if c in vowels))\r\n\tif vc != P[n]:\r\n\t\tans = False\r\nprint(\"YES\" if ans else \"NO\")",
"n = int(input())\nno = list(map(int... | {"inputs": ["3\n2 2 3\nintel\ncode\nch allenge", "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles", "5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\... | UNKNOWN | PYTHON3 | CODEFORCES | 170 | |
5614f76a9a106b37d45a3d86e6f37cd2 | Pixels | Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors *x* and *y* (*x*<=≠<=*y*) meet in a violent fight, then t... | [
"import sys\r\ninput=sys.stdin.readline\r\nl=input().split()\r\nli=[int(i) for i in l]\r\nmaxa=10**18\r\nli.sort()\r\nif((li[2]-li[1])%2==0):\r\n maxa=min(maxa,li[2])\r\nif((li[2]-li[0])%2==0):\r\n maxa=min(maxa,li[2])\r\nif((li[1]-li[0])%2==0):\r\n maxa=min(maxa,li[1])\r\nif(maxa==10**18):\r\n print(-1... | {"inputs": ["1 1 1", "3 1 0", "1 4 4", "5 10 6", "6 8 10", "1 10 2", "10 6 8", "18 67 5", "67 81 1", "51 10 91", "48 6 7", "8 97 83", "2 7 95", "772486757 1747374885 377299255", "1358352906 27037371 1947040615", "1944219055 454183506 1369298327", "382601556 881329640 791556039", "246543403 71853598 1504509195", "506063... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
561ea8f650301bad39b3ab5015b8b0dd | Space Voyage | The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit *n* planets. For planet *i* *a**i* is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and *b**i* is the number of citizens on the planet.
The Smart Beaver is going ... | [
"a=[]\nb=[]\nn=0\ndef cal(x):\n\tp=0\n\tglobal n,a,b\n\tfor i in range(n):\n\t\tp+=((a[i]*x)//b[i])\n\treturn p\n\nn,c=map(int,input().split())\nc-=n\nif c < 0:\n\tprint(0)\n\texit(0)\na=[0]*n\nb=[0]*n\nfor i in range(n):\n\ta[i],b[i]=map(int,input().split())\nL=1\nR=10**18\nlower=R+1\nwhile L<=R :\n\tm=(L+R)>>1\n\... | {"inputs": ["2 5\n1 5\n2 4", "1 97\n1 91", "2 79\n1 91\n1 77", "3 100\n8 46\n8 56\n77 98", "71 100\n1 92\n1 94\n1 97\n1 95\n1 100\n1 100\n1 98\n1 99\n1 98\n1 96\n1 97\n1 93\n1 97\n1 92\n1 91\n1 96\n1 97\n1 96\n1 92\n1 99\n1 92\n1 95\n1 93\n1 99\n1 99\n1 99\n1 97\n1 99\n1 95\n1 95\n1 95\n1 96\n1 95\n1 97\n1 93\n1 93\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
56451bdd43f18cd529603f3281b1328a | Vanya and Brackets | Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
The firs... | [
"s = str(input())\r\nval = eval(s)\r\nn = len(s)\r\nfor i in range(-1, n):\r\n\tif i == -1 or s[i] == '*':\r\n\t\tfor j in range(i + 1, n + 1):\r\n\t\t\tif j == n or s[j] == '*':\r\n\t\t\t\tnew = s[0 : i + 1] + '(' + s[i + 1 : j] + ')' + s[j : n]\r\n\t\t\t\tval = max(val, eval(new))\r\nprint(val)",
"s = \"1*\" + ... | {"inputs": ["3+5*7+8*4", "2+3*5", "3*4*5", "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5", "2*2+2*2", "1+1+1+1+1+1+1", "1+5*6+7*8", "9*8+7*6+5*4+3*2+1", "3*3*9+4+6+8*4+5+1*4*6", "4*9+4+5+8*4+6+9+8+2+5+2+5*7+6+8", "9+9+9*9*9*9+9+9", "9+9+9+9+9*9*9*9", "1*1*1*1*1*1*1*1+1*1*1*1*1*1*1*1", "4+2*7+8+9*6+6*9+8+7*2+4", "5", "4+6*7+4", "2+7... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
56463ac6ae649470f5a322be850540a6 | Codecraft III | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | [
"l=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']\r\nn=input()\r\np=int(input())\r\npp=l.index(n)\r\nprint(l[(pp+p)%12])",
"s=input()\r\nn=int(input())\r\nl=['January','February','March','April','May','June', 'July', 'August', 'September'... | {"inputs": ["November\n3", "May\n24", "April\n0", "September\n0", "August\n0", "June\n1", "July\n2", "September\n3", "July\n4", "August\n24", "May\n48", "November\n47", "December\n49", "June\n99", "March\n100", "December\n1", "January\n11", "December\n0", "January\n0", "July\n77", "February\n11", "February\n22", "July\... | UNKNOWN | PYTHON3 | CODEFORCES | 227 | |
565ba3eb6d9564437c2cdd828875b47c | Kefa and Watch | One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money.
The pawnbroker said that each watch contains a serial number ... | [
"if True:\r\n from io import BytesIO, IOBase\r\n import math\r\n\r\n import random\r\n import sys\r\n import os\r\n\r\n import bisect\r\n import typing\r\n from collections import Counter, defaultdict, deque\r\n from copy import deepcopy\r\n from functools import cmp_to_key, lru_cache,... | {"inputs": ["3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1", "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1", "1 0 1\n5\n2 1 1 1", "20 1 2\n34075930750342906718\n2 1 20 20\n1 1 20 6\n2 1 20 1", "10 1 4\n4545454545\n2 1 10 2\n2 2 4 2\n2 2 9 4\n1 2 9 6\n2 3 8 3", "15 1 5\n234072305423089\n2 1 15 1\n2 5 6 1\n2 8 11 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
56792a031cc15f8d2f78b3cbe37979f4 | Funky Numbers | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | [
"import sys, os.path\r\nfrom collections import*\r\nfrom copy import*\r\nimport math\r\nmod=10**9+7\r\nif(os.path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\")\r\n\r\ndef bs(left,right,x):\r\n while(left<=right):\r\n mid=left+(right-left)... | {"inputs": ["256", "512", "80", "828", "6035", "39210", "79712", "190492", "5722367", "816761542", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "18", "19", "20", "41", "11", "69", "82", "85", "736", "895", "934", "6213", "7405", "9919", "40942", "41992", "68535", "405718", "104... | UNKNOWN | PYTHON3 | CODEFORCES | 116 | |
5691be4e6291720f4fc740dc091f5666 | Working out | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column.
Ia... | [
"from collections import defaultdict as dd, deque as dq, Counter as ctr\r\nfrom itertools import accumulate\r\nfrom re import findall\r\nimport re\r\nimport sys\r\n\r\n\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\\r\\n')\r\n \r\nfrom bisect import bisect_left as bl\r\nfrom bisect imp... | {"inputs": ["3 3\n100 100 100\n100 1 100\n100 100 100", "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280", "3 3\n3 1 2\n3 2 0\n2 3 2", "3 3\n1 10 1\n1 10 1\n1 10 1", "3 3\n0 0 0\n0 10000 0\n0 0 0", "3 3\n1 1 1\n0 10000 0\n1 1 1", "3 3\n9 0 9\n0... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
569f266d1ef3cadb019f0bea338062a5 | none | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | [
"n = int(input())\r\nanw = False\r\nans = 0\r\nimport string\r\nvs = set(list(string.ascii_lowercase))\r\nfor i in range(n):\r\n act, w = input().split()\r\n if not anw:\r\n if act == '.':\r\n for l in w:\r\n if l in vs:\r\n vs.remove(l)\r\n if act ==... | {"inputs": ["5\n! abc\n. ad\n. b\n! cd\n? c", "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "4\n! abcd\n! cdef\n? d\n? c", "1\n? q", "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q", "3\n. abcdefghijklmnopqrs... | UNKNOWN | PYTHON3 | CODEFORCES | 82 | |
56c299caf0c2946a94e66bc57bd96b66 | Tom Riddle's Diary | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | [
"n=int(input())\r\na=[]\r\nfor i in range(n):\r\n\tc=0\r\n\ta.append(input())\r\n\tfor j in range(0,i):\r\n\t\tif j!=i:\r\n\t\t\tif a[i]==a[j]:\r\n\t\t\t\tc+=1\r\n\tif c>0:\r\n\t\tprint(\"YES\")\t\r\n\telse:\r\n\t\tprint(\"NO\")",
"#all those moments will be lost in time , like tears in rain \"D\r\na=[]\r\nn=int(... | {"inputs": ["6\ntom\nlucius\nginny\nharry\nginny\nharry", "3\na\na\na", "1\nzn", "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdf... | UNKNOWN | PYTHON3 | CODEFORCES | 591 | |
56c6f54cc6eef938ce3755bc6b36a16d | Banana | Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly *n* stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length *n*. Piegirl wants to create a string *s* using stickers. She may buy as many s... | [
"s,n,q,a=input(),int(input()),{},\"\"\r\nfor i in s:q[i]=[q[i][0]+1,1]if i in q else [1,1]\r\nif len(q)>n:print(-1)\r\nelse:\r\n for i in range(n-len(q)):\r\n o=0\r\n for j in q:\r\n m=(q[j][0]+q[j][1]-1)//q[j][1]\r\n if m>o:o,w=m,j\r\n q[w][1]=q[w][1]+1\r\n for i in... | {"inputs": ["banana\n4", "banana\n3", "banana\n2", "p\n1000", "b\n1", "aba\n2", "aaa\n2", "aa\n3", "aaaaaaaabbbbbccccccccccccccccccccccccccccccc\n7", "aaaaa\n10", "baba\n3", "a\n1000", "aan\n5", "banana\n5", "a\n5", "aaaaaaa\n5", "abc\n100", "zzz\n4", "aaabbb\n3", "abc\n5", "abc\n10", "aaaaa\n100", "abc\n1000", "a\n10"... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
56dd00818d60b0d068df5b0ca0550b87 | Perfect Pair | Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of th... | [
"def Solve():\n x,y,m=map(int,input().split())\n\n if(x>=m or y>=m):\n return 0\n\n if(x<=0 and y<=0):\n return -1\n ans=0\n if(y<=0):\n ans=abs(y)//x+1\n y+=ans*x\n\n elif(x<=0):\n ans=abs(x)//y+1\n x+=ans*y\n\n while(x<m and y<m):\n if(x<y):\n ... | {"inputs": ["1 2 5", "-1 4 15", "0 -1 5", "0 1 8", "-134 -345 -134", "-134 -345 -133", "999999999 -1000000000 1000000000", "0 0 0", "0 0 1", "-1000000000000000000 1 1000000000000000000", "-3 26 -1", "-25 4 -8", "12 30 -8", "-12 17 3", "4 -11 28", "38 174 957147453", "154 30 763391461", "3 193 648520002", "139 82 923851... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
570f9c7077215c141fdea3f969d947e8 | Pineapple Incident | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | [
"t,s,x=map(int,input().split())\r\na=x-t\r\nb=x-t-1\r\nif(t==x):\r\n print(\"YES\")\r\nelse:\r\n if(a>=s)or(b>=s):\r\n if(a>=s)and(a%s==0):\r\n print(\"YES\")\r\n elif((b%s==0)and(b>=s)):\r\n print(\"YES\")\r\n else:\r\n pr... | {"inputs": ["3 10 4", "3 10 3", "3 8 51", "3 8 52", "456947336 740144 45", "33 232603 599417964", "4363010 696782227 701145238", "9295078 2 6", "76079 281367 119938421", "93647 7 451664565", "5 18553 10908", "6 52 30", "6431 855039 352662", "749399100 103031711 761562532", "21 65767 55245", "4796601 66897 4860613", "8 ... | UNKNOWN | PYTHON3 | CODEFORCES | 205 | |
571267a70a8005908ca90f309f896f28 | Constants in the language of Shakespeare | Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespeare, and numbers are given by combinations of ornate epithets. In this problem we will have a closer look at the way the numbers are described in Shakespeare.
Each constant in Shakespeare is created from non-negati... | [
"s=('00'+input())[::-1];pre=c=0;z=[]\r\nfor i in range(len(s)-1):\r\n if pre^int(s[i]):c+=1;pre=int(s[i+1]);z+=[['+','-'][pre]+'2^'+str(i)]\r\nP=print;P(c);P('\\n'.join(z))"
] | {"inputs": ["1111", "1010011", "1", "10110111", "10101110", "1011001", "10001", "10", "11", "100", "100", "111", "1000000000", "1011000000", "1100010000", "1000111001", "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "1000000000000000000000000000000000000000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
571ae45c10d438fc84e131b6b6598e6f | Subsequence Counting | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_su... | [
"from math import *\r\nfrom collections import *\r\nimport sys\r\nsys.setrecursionlimit(10**9)\r\nl = [2**i-1 for i in range(40)]\r\nx,d = map(int,input().split())\r\na = []\r\nct = 1\r\nwhile(x != 0):\r\n\tfor i in range(39):\r\n\t\tif l[i+1] > x:\r\n\t\t\tind = i\r\n\t\t\tbreak\r\n\tx -= l[ind]\r\n\tfor i in rang... | {"inputs": ["10 5", "4 2", "4 1", "1 1", "63 1", "98 88", "746 173", "890 553", "883 1000", "1 1000", "695 188", "2060 697", "70 3321", "6358 1646", "167959139 481199252", "641009859 54748096", "524125987 923264237", "702209411 496813081", "585325539 365329221", "58376259 643910770", "941492387 72235422", "824608515 94... | UNKNOWN | PYTHON3 | CODEFORCES | 30 | |
571fcb9db60f838e9e04086862d0e748 | Energy exchange | It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the *i*-th accumulator has *a**i* units of energy. Energy ... | [
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nsumEn = sum(a)\r\n\r\nleft = 0\r\nright = 1000\r\n\r\neps = 1e-7\r\n\r\nwhile right - left > eps:\r\n mid = (left + right)/2\r\n sumLoss = 0\r\n for i in a:\r\n if i > mid:\r\n sumLoss += i - mid\r\n sumLos... | {"inputs": ["3 50\n4 2 1", "2 90\n1 11", "5 26\n42 65 23 43 64", "5 45\n964 515 454 623 594", "1 20\n784", "10 20\n812 896 36 596 709 641 679 778 738 302", "10 83\n689 759 779 927 15 231 976 943 604 917", "11 1\n235 280 196 670 495 379 391 280 847 875 506", "12 71\n472 111 924 103 975 527 807 618 400 523 607 424", "13 ... | UNKNOWN | PYTHON3 | CODEFORCES | 47 | |
573dc1b93b6aae1166255b4af7c1e03a | k-Multiple Free Set | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | [
"n, k = [int(e) for e in input().split()]\r\na = sorted([int(e) for e in input().split()])\r\ns = set()\r\nfor i in range(n):\r\n if a[i] % k != 0:\r\n s.add(a[i])\r\n elif a[i] / k not in s:\r\n s.add(a[i])\r\nprint(len(s))",
"n,k = map(int,input().split())\r\narr = list(map(int,input().split... | {"inputs": ["6 2\n2 3 6 5 4 10", "10 2\n1 2 3 4 5 6 7 8 9 10", "1 1\n1", "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 1... | UNKNOWN | PYTHON3 | CODEFORCES | 77 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.