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 |
|---|---|---|---|---|---|---|---|---|---|
3cfec1b69fe2adf1d00ee6f434777a8c | Blood Cousins | Polycarpus got hold of a family relationship tree. The tree describes family relationships of *n* people, numbered 1 through *n*. Each person in the tree has no more than one parent.
Let's call person *a* a 1-ancestor of person *b*, if *a* is the parent of *b*.
Let's call person *a* a *k*-ancestor (*k*<=><=1) of p... | [
"import sys\r\nimport random\r\nfrom math import gcd, lcm, sqrt, isqrt, perm, comb, factorial, log2, ceil, floor\r\nfrom collections import Counter, defaultdict, deque\r\nfrom functools import lru_cache, reduce, cmp_to_key\r\nfrom itertools import accumulate, combinations, permutations\r\nfrom heapq import nsmalles... | {"inputs": ["6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "1\n0\n20\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "2\n0 1\n20\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 1\n1 1\n1 1\n2 1\n1 1\n2 1\n2 1\n2 1\n1 1\n2 1\n2 1\n1 1\n1 1\n2 1", "3\n0 0 2\n20\n2 1\n1 1\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
3cffef1fee59b03bd6899de7b943aa9b | Key races | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | [
"s,v1,v2,t1,t2=map(int,input().split())\r\nfirst=s*v1+2*t1\r\nsecond=s*v2+2*t2\r\nif first > second:\r\n print (\"Second\")\r\nif first < second:\r\n print(\"First\")\r\nif first ==second:\r\n print(\"Friendship\")\r\n \r\n ",
"s, v1, v2, t1, t2 = [int(x) for x in input().split()]\r\nif(s*v1+2*t1)<... | {"inputs": ["5 1 2 1 2", "3 3 1 1 1", "4 5 3 1 5", "1000 1000 1000 1000 1000", "1 1 1 1 1", "8 8 1 1 1", "15 14 32 65 28", "894 197 325 232 902", "1 2 8 8 5", "37 261 207 1 1000", "29 344 406 900 1", "1 2 8 9 8", "2 9 8 8 9", "213 480 811 134 745", "2 313 856 964 421", "1 10 2 6 10", "2 7 6 2 3", "637 324 69 612 998", ... | UNKNOWN | PYTHON3 | CODEFORCES | 613 | |
3d2a87f340c6112637ca5c250096c894 | Worms | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | [
"n=int(input())#numero de montones\r\na=[int(x) for x in input().split(' ')]#cantidad por monton\r\nm=int(input())#gusanos sabrosos\r\nq=[int(x) for x in input().split(' ')]#etiquetas de los gusanos sabrosos\r\nmonton={}\r\ncontador=1\r\nfor i in range(n):\r\n for j in range(a[i]):\r\n monton[contador]=i+... | {"inputs": ["5\n2 7 3 4 9\n3\n1 25 11"], "outputs": ["1\n5\n3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 207 | |
3d44911c778a334eb3c3c200eb0958dc | Mysterious Present | Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes *A*<==<={*a*1,<=<=*a*2,<=<=...,<=<=*a**n*}, where the width and the height of the *i*-th envelope is strictly higher than the... | [
"\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn, w, h = map(int, input().split())\r\nd = [(w, h, 0)]\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n if a > w and b > h:\r\n d.append((a, b, i+1))\r\nd.sort()\r\nm = len(d)\r\nx = [(1, 0) for i in range(m)]\r\nif len(d) == 1:\r\n ... | {"inputs": ["2 1 1\n2 2\n2 2", "3 3 3\n5 4\n12 11\n9 8", "5 10 10\n22 23\n17 19\n13 17\n8 12\n2 6", "5 13 13\n4 4\n10 10\n7 7\n1 1\n13 13", "4 12 140\n172 60\n71 95\n125 149\n53 82", "3 500 789\n56 32\n64 42\n74 55", "4 100 100\n332 350\n232 250\n32 50\n132 150", "2 10 10\n15 15\n16 16", "6 1 1\n900000 900000\n902400 9... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
3d5dfedec0811ef539a5f2b64322feb4 | Restore a Number | Vasya decided to pass a very large integer *n* to Kate. First, he wrote that number as a string, then he appended to the right integer *k* — the number of digits in *n*.
Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty ... | [
"def main():\n s = input()\n if s in (\"01\", \"10\"):\n print(0)\n return\n cnt = [0] * 58\n for j in map(ord, s):\n cnt[j] += 1\n n, s1 = sum(cnt), input()\n for le in range(n - 1, 0, -1):\n if len(str(le)) + le == n:\n break\n for s in s1, str(le):\n ... | {"inputs": ["003512\n021", "199966633300\n63", "01\n0", "0000454312911\n9213544", "13\n3", "00010454312921\n9213544", "11317110\n01", "1516532320120301262110112013012410838210025280432402042406224604110031740090203024020012\n0126064", "233121122272652143504001162131110307236110231414093112213120271312010423132181004\n0... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3d7a918b546bcb1f8edc711f260f83e9 | Numbers | One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ... | [
"import math\ndef prime(x):\n for i in range(2, int(math.sqrt(x))+1):\n if x % i == 0:\n return 0\n return 1\n\n\ndef cal(n, k):\n if not prime(k):\n return 0\n elif k >= n:\n return k == n\n res = n // k\n for i in range(2, min(k, n // k +1)):\n res -= cal(n... | {"inputs": ["1 10 2", "12 23 3", "6 19 5", "1 80 7", "100 1000 1009", "11 124 11", "1000 10000 19", "2020 6300 29", "213 1758 41", "201 522 233", "97 10403 101", "1 340431 3", "3500 100000 1009", "300 300000 5003", "100000 100000 5", "300 700 41", "7000 43000 61", "12 20000000 11", "35000 100000000 50021", "1 20000000 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3d88853ec11a6f22622d7af3d8efba50 | Pseudorandom Sequence Period | Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are constants, fixed for the given realization of the pseudorandom numbers generator, *r*0 is the so-called *randseed* (t... | [
"import poplib\r\nimport string\r\nimport math\r\n\r\ndef main_function():\r\n a, b, m, r_0 = [int(i) for i in input().split(\" \")]\r\n current_index = 1\r\n hash_ = {r_0: 0}\r\n while True:\r\n r_0 = (a * r_0 + b) % m\r\n if r_0 in hash_:\r\n print(current_index - hash_[r_0])\... | {"inputs": ["2 6 12 11", "2 3 5 1", "3 6 81 9", "10 11 12 3", "4 4 5 4", "0 1 6 5", "1 0 7 3", "25 154 200 68", "0 0 1 0", "1 1 100000 0", "73 778 36193 20163", "65 101 43738 16242", "177 329 83469 5951", "452 53 51476 50033", "900 209 34129 21607", "137 936 79151 3907", "687 509 56521 48466", "977 461 14937 9343", "54... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
3d9e1596deea889723ff8b12ffa03c48 | Spider's Web | Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.
There are *n* main threads going from the center of the web. All main threads are located in one plane and divide it into *n* equal infinite sectors. The sectors are indexed... | [
"\r\nimport math \r\nimport sys\r\ndef search(arr,l,r,p1,p2):\r\n\r\n\r\n \r\n i1=-1\r\n i2=-1\r\n copy_l=l \r\n copy_r=r\r\n while l<=r:\r\n m=(l+r)//2 \r\n val=arr[m]\r\n if p1<=val and val<=p2:\r\n i1=m\r\n r=m-1 \r\n elif val>p2:\r\n \r\n r=m-1 \r\n else:\r\n l=m+1\r... | {"inputs": ["7\n3 1 6 7\n4 3 5 2 9\n2 8 1\n4 3 7 6 4\n3 2 5 9\n3 6 3 8\n3 4 2 9", "3\n1 1\n1 2\n1 3", "3\n2 1 2\n2 3 4\n2 5 6", "5\n3 2 4 10\n2 1 6\n2 8 7\n3 2 4 10\n2 1 6", "3\n5 2 7 6 9 8\n4 10 1 5 4\n1 3", "4\n5 2 6 10 8 3\n1 7\n2 10 4\n2 9 5", "5\n3 12 10 19\n5 1 4 18 11 13\n4 17 15 2 6\n4 3 12 18 10\n4 2 8 5 9", "... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
3dab8c5075e0332c36e38519909f1c65 | Japanese Crosswords Strike Back | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | [
"n,x=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nif sum(a) + n - 1 == x:\r\n print('Yes')\r\nelse:\r\n print('No')\r\n",
"n,x=map(int,input().split(' '))\nval=[int(i) for i in input().split(' ') ]\ns=len(val)-1\nfor i in val:\n s+=i\nif s==x:\n print('YES')\nelse:\n print(... | {"inputs": ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3", "1 1\n1", "1 10\n10", "1 10000\n10000", "10 1\n5 78 3 87 4 9 5 8 9 1235", "3 12\n3 3 3", "3 9\n2 2 2", "2 5\n1 1", "1 2\n1", "3 13\n3 3 3", "3 6\n1 1 1", "1 6\n5", "3 11\n3 3 2", "2 6\n1 3", "3 10\n2 2 2", "3 8\n2 1 1", "1 5\n2", "1 3\n1", "5 5\n1 1 1 1 1", "2 10\n4 4... | UNKNOWN | PYTHON3 | CODEFORCES | 211 | |
3dbee8c53095be15c54fd95fa1d23783 | Lucky Interval | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya came across an interval of numbers [*a*,<=*a*<=+<=*l*<=-<=1]. Let *F*(*x*) be the numb... | [
"import sys\r\nclass HappyNumbers:\r\n def solve(self):\r\n a, l = map(int, input().split())\r\n print(self.doit(a, l))\r\n def doit(self, a, l):\r\n if l >= 10:\r\n first = a\r\n last = a + l - 1\r\n return self.doit(first // 10, last // 10 - first // 10 ... | {"inputs": ["7 4", "4 7", "10 10", "47 74", "469 1", "47 74", "100 1", "104 1", "477 7", "777 10", "100 100", "1 1000", "47 9454", "458 10000", "9548 748", "10000 10000", "46999 100000", "548454 845445", "459544 48587874", "1000000000 1000000000", "779999 1000000000", "4699999 1000000000", "9999 107545", "954 71", "974... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3dc2dd5bf116a1f0df0313bb38a1a3d8 | Traffic Lights | A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light ... | [
"def fmod(x, m):\r\n while x >= m:\r\n x = x - m\r\n return x\r\n\r\nl, d, v, g, r = map(int, input().split(' '))\r\n\r\nx = fmod(float(d / v), g + r)\r\n\r\nans = (d / v) + (l - d) / v\r\n\r\nif x >= g:\r\n ans = ans + g + r - x \r\n\r\nprint(\"%.10f\" % (ans))\r\n\r\n",
"[l,d,v,g,r] = map(int... | {"inputs": ["2 1 3 4 5", "5 4 3 1 1", "862 33 604 888 704", "458 251 49 622 472", "772 467 142 356 889", "86 64 587 89 657", "400 333 31 823 74", "714 474 124 205 491", "29 12 569 939 259", "65 24 832 159 171", "2 1 1 1 1", "2 1 1 1 1000", "2 1 1 1000 1", "2 1 1 1000 1000", "2 1 1000 1 1", "2 1 1000 1 1000", "2 1 1000 ... | UNKNOWN | PYTHON3 | CODEFORCES | 53 | |
3ddf6953a9633fbc02a19ac2d84f63d3 | Красивая команда | Завтра у хоккейной команды, которой руководит Евгений, важный матч. Евгению нужно выбрать шесть игроков, которые выйдут на лед в стартовом составе: один вратарь, два защитника и три нападающих.
Так как это стартовый состав, Евгения больше волнует, насколько красива будет команда на льду, чем способности игроков. А име... | [
"import bisect\r\nfrom functools import lru_cache\r\n\r\ng, d, f = tuple(map(int, input().split()))\r\n\r\ngoals = list(map(int, input().split()))\r\ndefs = list(map(int, input().split()))\r\nforwards = list(map(int, input().split()))\r\n\r\ngoals.sort()\r\ndefs.sort()\r\nforwards.sort()\r\n\r\nforwards.append(1000... | {"inputs": ["1 2 3\n15\n10 19\n20 11 13", "2 3 4\n16 40\n20 12 19\n13 21 11 10", "4 4 5\n15 16 19 6\n8 11 9 18\n5 3 1 12 14", "6 7 7\n32 35 26 33 16 23\n4 40 36 12 28 24 3\n39 11 31 37 1 25 6", "9 10 7\n935 433 848 137 548 958 758 576 592\n780 129 631 991 575 421 245 944 487 771\n430 34 276 8 165 188 727", "17 15 17\n5... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
3de5d2ad422d9650f7b7c73ff464e988 | A Simple Task | This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*<==<=1 or in non-increasing order if *k*<==<=0.
Output the final string after applying the queries... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef binary_trie():\r\n G0, G1, cnt = [-1], [-1], [0]\r\n return G0, G1, cnt\r\n\r\ndef insert(x, l):\r\n j = 0\r\n for i in range(l, -1, -1):\r\n cnt[j] += 1\r\n if x & pow2[i]:\r\n if G1[... | {"inputs": ["10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1", "10 1\nagjucbvdfk\n1 10 1", "10 6\nrmaahmdmuo\n1 3 1\n4 6 0\n5 6 1\n7 8 0\n8 10 0\n8 9 1", "10 5\nhbtngdflmj\n1 10 1\n2 9 0\n3 8 1\n4 7 0\n5 6 1", "13 0\nokaywearedone"], "outputs": ["cbcaaaabdd", "abcdfgjkuv", "amrmahmoud", "bnflhjgmdt", "okaywearedo... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3df03802b37da8b768eedaa9b38bc34c | T-decomposition | You've got a undirected tree *s*, consisting of *n* nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.
Let's denote the set of all nodes *s* as *v*. Let's consider an undirected tree *t*, whose nodes are some non-empty subsets of *v*, we'll call them *x**i* . The... | [
"from bisect import bisect_right\r\nfrom collections import defaultdict\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nfrom types import GeneratorType\r\nfrom collections import defaultdict\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file... | {"inputs": ["2\n1 2", "3\n1 2\n2 3", "4\n2 1\n3 1\n4 1", "6\n2 5\n4 3\n4 2\n4 6\n3 1", "6\n3 6\n4 2\n3 4\n3 1\n6 5", "6\n3 2\n6 5\n1 3\n1 4\n6 1", "6\n5 3\n4 2\n5 6\n6 1\n5 4", "5\n1 2\n1 3\n4 5\n4 1", "5\n1 5\n5 3\n2 4\n4 1", "5\n1 5\n5 2\n1 4\n1 3", "4\n1 4\n3 1\n3 2", "20\n19 2\n19 18\n20 9\n20 10\n18 4\n17 5\n17 13... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3e0305ad00a8ce7041ada4c908f96a24 | none | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | [
"n=int(input())\r\nl=list(map(int,input().split()))\r\nf=0\r\nfor i in range(n):\r\n #print(l[i],l[i+1])\r\n if l[i]>1 and l[i+1]>1:\r\n ind=i\r\n f+=1\r\n break\r\nif f==0:\r\n print(\"perfect\")\r\nelse:\r\n print(\"ambiguous\")\r\n l1,l2=[],[]\r\n cnt=0\r\n for i in rang... | {"inputs": ["2\n1 1 1", "2\n1 2 2", "10\n1 1 1 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 2 1 1 1 1 1", "10\n1 1 1 1 2 2 1 1 1 1 1", "10\n1 1 1 1 1 1 1 2 1 1 2", "10\n1 1 1 3 2 1 2 4 1 3 1", "10\n1 1 1 4 1 1 2 1 5 1 2", "10\n1 1 11 12 12 11 15 13 8 8 8", "10\n1 1 21 1 20 1 14 1 19 1 20", "10\n1 1 93 121 112 103 114 112 112 122 1... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
3e1d040318b5b2ff2bff5feb4d9fa67a | Lovely Palindromes | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | [
"from sys import stdin,stdout\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,factorial\r\n# setrecursionlimi... | {"inputs": ["1", "10", "11", "12", "100", "1321", "2", "3", "4", "5", "6", "7", "8", "9", "13", "14", "15", "16", "17", "18", "19", "20", "26550", "16137", "91471", "41242", "30866", "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "78065260847320107428504709029792... | UNKNOWN | PYTHON3 | CODEFORCES | 477 | |
3e50d65928f72db74df1ec21ab597cd8 | none | Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,<=*a**n* требуется найти *r* — максимальную степень числа 2, на которую делится хотя бы од... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nans = 1\r\nansc = 0\r\n\r\nfor x in a:\r\n i = 0\r\n while (x % (2 ** i) == 0):\r\n i += 1\r\n i -= 1\r\n if (2 ** i == ans):\r\n ansc += 1\r\n if (2 ** i > ans):\r\n ans = 2 ** i\r\n ansc = 1\r\n\r\nprint(str(ans) + ' ' +... | {"inputs": ["5\n80 7 16 4 48", "4\n21 5 3 33", "10\n8 112 52 86 93 102 24 24 100 826791168", "3\n458297759 18 104", "7\n12 14 40 8 74 104 11", "11\n35 16 664311776 46 48 52 63 82 84 80 23", "7\n67 68 58 24 96 73 72", "8\n48 112 40 8 112 14 80 36", "10\n14 6 68 8 84 949689614 91 26 80 56", "4\n39 56 939117699 56", "5\n9... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
3e647b09d39c70908a6b850df8244f27 | none | Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!
Of course, there is a code lock is installed on the safe. The lock... | [
"n, s, t = int(input()), input(), input()\nans = []\nfor i in range(n):\n cur = 0\n for j in range(n - i):\n if s[j] == t[i]:\n cur = j\n break\n else:\n print(-1)\n raise SystemExit\n ans.extend([n - 1 - cur, 1, n])\n #print('s[%d:0:-1]:' % (cur - 1), s[cur... | {"inputs": ["6\nabacbb\nbabcba", "3\naba\nbba", "1\nw\nw", "2\nvb\nvb", "7\nvhypflg\nvprhfly", "8\nzyzxzyzw\nzzyzxywz", "8\nvnidcatu\nuiacnvdt", "3\nxhh\nxhh", "4\nwnsc\nnwcs", "5\nutvrb\nvbtru", "8\nvnidcatu\nvnidcatu", "8\nabbabaab\nbaababba", "8\nabaababa\nabaaabab", "49\nssizfrtawiuefcgtrrapgoivdxmmipwvdtqggsczdipn... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
3e78ba92ef883d1b1e8971722951af9d | Numbers | Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer *n* and array *a*, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positi... | [
"p = int(1e9+7)\r\nN = 100\r\nfact= [1]*(N+1)\r\nfor i in range(2,N+1):\r\n fact[i]=(fact[i-1]*i)%p\r\n\r\ndef bpow(a,b,p):\r\n c = 1\r\n while b>0:\r\n if b&1: c=(c*a)%p\r\n a = (a*a)%p\r\n b = b>>1\r\n return c\r\n\r\ndef inv(a,p):\r\n return bpow(a,p-2,p)\r\n\r\ndef bino(n... | {"inputs": ["1\n0 0 0 0 0 0 0 0 0 1", "2\n1 1 0 0 0 0 0 0 0 0", "3\n1 1 0 0 0 0 0 0 0 0", "4\n0 1 0 1 2 0 0 0 0 0", "5\n2 1 2 0 0 0 0 0 0 0", "6\n1 1 0 1 2 1 0 0 0 0", "7\n0 0 2 2 1 0 1 0 0 0", "8\n1 0 1 0 1 1 2 2 0 0", "9\n1 1 1 2 1 0 0 2 0 1", "10\n2 0 0 1 0 2 0 1 1 0", "100\n10 11 14 16 12 17 10 10 0 0", "100\n0 0 0... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
3e9a4ebf95b6b8fe90488c34ac94b6b2 | Cardiogram | In this problem, your task is to use ASCII graphics to paint a cardiogram.
A cardiogram is a polyline with the following corners:
That is, a cardiogram is fully defined by a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
Your task is to paint a cardiogram by given sequence *a**i*.
The first line contains... | [
"import operator\n\nn = int(input())\npoints = list(map(int, input().split()))\n\ndef praf(g):\n for i in g[1:]:\n print(''.join(i))\n\ndef calc(n):\n global points\n a = b = 0\n step = 1\n for i in range(n):\n a += points[i]\n b += points[i] * step\n step = -step\n ret... | {"inputs": ["5\n3 1 2 5 1", "3\n1 5 1", "2\n1 1", "2\n2 1", "2\n1 2", "2\n2 2", "3\n1 1 1", "100\n14 6 10 12 11 12 6 19 12 7 10 17 8 10 10 5 9 6 9 14 15 5 9 11 8 12 14 15 9 9 9 11 13 15 11 10 4 10 8 7 13 11 17 10 14 14 15 8 10 7 12 8 7 15 13 8 7 13 5 11 12 8 9 8 7 16 11 10 10 15 9 11 2 12 12 9 9 13 7 6 9 7 8 7 4 6 15 6... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
3eba397c78e7876c6f513acead37b714 | The Intriguing Obsession | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three... | [
"mod = 998244353\r\n\r\ndef binpow(num, p):\r\n if(p == 0):\r\n return 1\r\n if(p % 2 == 0):\r\n return binpow((num * num) % mod, p // 2)\r\n return (num * binpow(num, p - 1)) % mod\r\n\r\ndef rev(num):\r\n return binpow(num, mod - 2)\r\n\r\ndef solve(a, b):\r\n result = 1\r\n prev =... | {"inputs": ["1 1 1", "1 2 2", "1 3 5", "6 2 9", "7 3 7", "135 14 39", "5000 5000 5000", "2 1 1", "1 1 3", "1 2 3", "4 1 2", "5 9 4", "4 2 5", "9 4 10", "16 8 29", "17 46 45", "28 47 1", "94 87 10", "84 29 61", "179 856 377", "1925 1009 273", "1171 2989 2853", "3238 2923 4661", "1158 506 4676", "4539 2805 2702", "4756 7... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
3ec537dbbb4d9020531b843e0d184b4d | Chris and Magic Square | ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling ... | [
"n = int(input())\r\nmat=[]\r\na=-1\r\nb=-1\r\nans=True\r\nfor i in range(n):\r\n l = list(map(int,input().split()))\r\n mat.append(l)\r\ns =set()\r\n\r\nfor i in range(n):\r\n sum=0\r\n flag = False\r\n for j in range(n):\r\n if mat[i][j]==0:\r\n flag = True\r\n sum+=mat[i][... | {"inputs": ["3\n4 0 2\n3 5 7\n8 1 6", "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "1\n0", "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 0 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
3ee91e91636c5ffb1ea55d1b76d482a0 | Good Sequences | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increas... | [
"#iterate through numbers\r\n#find prime factorization for each number\r\n#compute max value among each prime factor\r\n#increment each by 1\r\n\r\nfrom collections import defaultdict\r\nimport math\r\n\r\ndef primeFactors(n): \r\n prime = set()\r\n while n % 2 == 0: \r\n prime.add(2)\r\n n = n/... | {"inputs": ["5\n2 3 4 6 9", "9\n1 2 3 5 6 7 8 9 10", "4\n1 2 4 6", "7\n1 2 3 4 7 9 10", "1\n1", "8\n3 4 5 6 7 8 9 10", "5\n2 3 7 9 10", "3\n1 4 7", "1\n4", "9\n1 2 3 4 5 6 7 9 10", "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 64... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
3ef2760c88ad3bfbe9fc232ac88a8cf4 | Code For 1 | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | [
"mp = {0: 1, 1: 1}\nvec = []\n\n\ndef getLen(n):\n if n == 0 or n == 1:\n return 1\n m = n // 2\n mp[m] = getLen(m)\n mp[n] = 2 * mp[m] + 1\n return mp[n]\n\n\ndef getAns(n, interval):\n if n == 1:\n return len(interval)\n elif n == 0:\n return 0\n else:\n length ... | {"inputs": ["7 2 5", "10 3 10", "56 18 40", "203 40 124", "903316762502 354723010040 354723105411", "33534354842198 32529564319236 32529564342569", "62518534961045 50734311240112 50734311287877", "95173251245550 106288351347530 106288351372022", "542 321 956", "3621 237 2637", "9056 336 896", "36007 368 24490", "244269... | UNKNOWN | PYTHON3 | CODEFORCES | 67 | |
3f39c6661843648becc971efaa0a76e1 | Merge Equal Elements | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both a... | [
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nstack = []\r\ni = 0\r\nx = a[i]\r\nwhile True:\r\n if len(stack) == 0:\r\n stack.append(x)\r\n i += 1\r\n if i == n:\r\n break\r\n x = a[i]\r\n else:\r\n if x == stack[-1]:\r\n del stack[-1]\... | {"inputs": ["6\n5 2 1 1 2 2", "4\n1000000000 1000000000 1000000000 1000000000", "7\n4 10 22 11 12 5 6", "2\n1 1", "3\n2 1 1", "4\n3 2 1 1", "7\n5 5 4 4 5 6 7"], "outputs": ["2\n5 4 ", "1\n1000000002 ", "7\n4 10 22 11 12 5 6 ", "1\n2 ", "1\n3 ", "1\n4 ", "3\n7 6 7 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
3fa3ff835903925f73dff6b30ce57d8d | 000001 | The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output a single integer.
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64).
Output a single integer.
Sample Input
2
4
27
42
Sample Output
1
2
5
6
| [
"from sys import stdin,stdout\r\n# from os import _exit\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,facto... | {"inputs": ["2", "4", "27", "42", "1", "3", "64", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52",... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
3fa63a22428f9feb1c46ac8c4c844904 | Bark to Unlock | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | [
"p =input()\nn =int(input())\narr =[]\nfor i in range(n):\n\tarr.append(input())\nfor i in range(n):\n\tfor j in range(n):\n\t\tif p in str(arr[i]+arr[j]):\n\t\t\tprint (\"YES\")\n\t\t\texit()\nprint (\"NO\")",
"password = input('')\r\n\r\nvocablen = input()\r\nvocablen = int(vocablen)\r\n\r\nvocab = []\r\nfor i ... | {"inputs": ["ya\n4\nah\noy\nto\nha", "hp\n2\nht\ntp", "ah\n1\nha", "bb\n4\nba\nab\naa\nbb", "bc\n4\nca\nba\nbb\ncc", "ba\n4\ncd\nad\ncc\ncb", "pg\n4\nzl\nxs\ndi\nxn", "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\... | UNKNOWN | PYTHON3 | CODEFORCES | 237 | |
3fa9b04e87068a56cf8b8d30f96c8e17 | Marlin | The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the ... | [
"n , k = [int(i) for i in input().strip().split()]\r\nl=[]\r\nfor i in range(4):\r\n l.append([])\r\n for j in range(n):\r\n l[-1].append('.')\r\nif (n==3 or k%2==0):\r\n print ('YES')\r\n x=k//2\r\n for i in range(1,x+1):\r\n for j in range(1,3):\r\n l[j][i]='#'\r\n if (k... | {"inputs": ["7 2", "5 3", "3 2", "3 0", "49 1", "9 4", "9 5", "99 193", "99 14", "57 15", "99 3", "3 1", "9 9", "67 9", "99 99", "31 32", "5 1", "5 2", "5 4", "5 6", "5 5", "7 9", "7 10", "19 12", "19 3", "37 14", "37 15", "37 37", "37 36", "37 35", "37 34", "37 38", "37 39", "37 40", "5 0", "67 1", "37 19", "77 7", "3... | UNKNOWN | PYTHON3 | CODEFORCES | 51 | |
3fc3f99751dce181d2a4d87285222ec8 | Colorful Field | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | [
"n,m,k,t=map(int,input().split())\r\nwaste=[]\r\n\r\nval=['Carrots','Kiwis','Grapes']\r\nfor i in range(k):\r\n a=list(map(int,input().split()))\r\n waste.append(a)\r\n\r\nfor i in range(t):\r\n q=list(map(int,input().split()))\r\n if q in waste:\r\n print('Waste')\r\n \r\n else:\r\n ... | {"inputs": ["4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "2 3 2 2\n1 1\n2 2\n2 1\n2 2", "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 3... | UNKNOWN | PYTHON3 | CODEFORCES | 97 | |
3fc90abc9145be915e2ce28bbd6e8bb7 | Towers | As you know, all the kids in Berland love playing with cubes. Little Petya has *n* towers consisting of cubes of the same size. Tower with number *i* consists of *a**i* cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the h... | [
"n_k = list(map(int, input().split()))\r\nn = n_k[0]\r\nk = n_k[1]\r\na = list(map(int, input().split()))\r\nmoves = []\r\nfor i in range(k):\r\n minimum = min(a)\r\n maximum = max(a)\r\n instability = maximum - minimum\r\n if instability > 1:\r\n moves.append(f\"{a.index(maximum)+1} {a.index(min... | {"inputs": ["3 2\n5 8 5", "3 4\n2 2 4", "5 3\n8 3 2 6 3", "4 6\n1 10 8 2", "5 3\n2 2 2 2 2", "95 720\n9119 7480 7245 2431 7986 4088 3498 7724 9291 3853 9733 4018 1109 6476 6915 6456 8956 2877 8090 7557 1886 5944 9952 6275 2877 6488 2688 319 4635 8618 2724 7047 3261 8750 971 9114 6552 7749 4356 6059 1495 5713 2625 7230 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
3fd31c857915f9f288689eeab0d1ed96 | Paper Airplanes | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | [
"import math\r\nk,n,s,p=map(int,input().split())\r\nprint(math.ceil(k*math.ceil(n/s)/p))\r\n",
"from math import ceil\r\n\r\nX = list(map(int, input().split()))\r\nMath = ceil(X[1] / X[2])\r\nMath = ceil(Math * X[0])\r\nprint(ceil(Math / X[3]))\r\n",
"# A. Paper Airplanes\n\nk, n, s, p = map(int, input().split(... | {"inputs": ["5 3 2 3", "5 3 100 1", "10000 10000 1 1", "1 1 10000 10000", "300 300 21 23", "300 2 37 51", "2 400 23 57", "1 1 1 1", "10000 10000 3 2", "1 2 1 2", "1 1 2 2", "1 1 10 10", "5324 5439 32 13", "9000 1 2432 1", "230 1234 9124 23", "11 1 1 1", "6246 8489 1227 9", "9 20 5 7"], "outputs": ["4", "5", "100000000"... | UNKNOWN | PYTHON3 | CODEFORCES | 414 | |
3fd6411c52c2bb52d854c5fde1244ac1 | Da Vinci Powers | The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
The input contains a single integer *a* (0<=≤<=*a*<=≤<=35).
Output a single integer.
Sample Input
3
10
Sample Output
8
1024
| [
"if __name__ == \"__main__\":\r\n\ta = [1,\r\n\t2,\r\n\t4,\r\n\t8,\r\n\t16,\r\n\t32,\r\n\t64,\r\n\t128,\r\n\t256,\r\n\t512,\r\n\t1024,\r\n\t2048,\r\n\t4096,\r\n\t8092,\r\n\t16184,\r\n\t32368,\r\n\t64736,\r\n\t129472,\r\n\t258944,\r\n\t517888,\r\n\t1035776,\r\n\t2071552,\r\n\t4143104,\r\n\t8286208,\r\n\t16572416,\r\... | {"inputs": ["3", "10", "35", "0", "1", "2", "4", "5", "6", "7", "8", "9", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34"], "outputs": ["8", "1024", "33940307968", "1", "2", "4", "16", "32", "64", "128", "256", "512", "2048",... | UNKNOWN | PYTHON3 | CODEFORCES | 71 | |
3fd6afa7e65bd757f1d253da0506bad2 | none | The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ... | [
"from operator import itemgetter\n\n\nclass CodeforcesTask528BSolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.points = []\n\n def read_input(self):\n self.n = int(input())\n for _ in range(self.n):\n self.points.append([int(x) for x in input... | {"inputs": ["4\n2 3\n3 1\n6 1\n0 2", "1\n42 23", "2\n1 5\n2 6", "2\n1 5\n12 6", "1\n0 1", "1\n1000000000 1000000000", "2\n4 4\n12 5", "2\n4 4\n12 4", "2\n4 4\n12 3", "3\n0 1\n2 1\n4 1", "3\n0 1\n2 2\n4 1", "2\n0 1\n1000000000 1", "2\n0 1000000000\n1000000000 1000000000", "1\n76438 10", "10\n6 15\n4 5\n1 4\n2 4\n0 6\n9 ... | UNKNOWN | PYTHON3 | CODEFORCES | 38 | |
3ff2cbe65f52ba8911e911d0182c829d | Spotlights | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | [
"n, m = [int(x) for x in input().split()]\n\nplan = []\nfor line in range(n):\n\tplan.append([int(x) for x in input().split(\" \")])\n\ntotal_positions = 0\nfor i in range(n):\n\tactor_before = False\n\tfree_spot_counter = 0\n\tfor j in range(m):\n\t\tif(plan[i][j] == 1):\n\t\t\tactor_before = True\n\t\t\ttotal_pos... | {"inputs": ["2 4\n0 1 0 0\n1 0 1 0", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "1 5\n1 1 0 0 0", "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "3 1\n1\n0\n0", "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 83 | |
3ff91f444ea82f0d659a0cee9eab7199 | University Classes | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the ... | [
"import sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\r\ninput = sys.stdin.readline\r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \... | {"inputs": ["2\n0101010\n1010101", "3\n0101011\n0011001\n0110111", "1\n0111000", "1\n0000000", "1\n1111111", "2\n1000000\n0101000", "3\n0101111\n1101011\n1010011", "5\n0100101\n0000001\n0110000\n0010000\n0011110", "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100", "10\n0000000\n0010000\n0000000\n0000010\n000000... | UNKNOWN | PYTHON3 | CODEFORCES | 205 | |
400f7e05f6be90746148a4be088b9c36 | Cards and Joy | There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning... | [
"\r\ndef Solucion(n,k,c,f,h):\r\n # La alegría de no tener cartas favoritas es0\r\n h = [0]+h\r\n \r\n # Contamos la cantidad de veces que una carta es favorita por los jugadores\r\n count_fav = {}\r\n # Guardamos el máximo número de veces que se repite un número en los favoritos\r\n max_count_... | {"inputs": ["4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7", "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3", "1 1\n1\n2\n1", "1 1\n1\n1\n1", "1 1\n1\n1\n100000", "50 1\n52 96 99 37 143 148 10 140 131 29 82 134 56 73 121 57 98 101 134 4 103 10 86 70 4 98 102 35 149 47 136 87 4 127 142 105 78 10 123 75 67 149 81 78 34 79 62 12 43... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
402e655a9681a4ba53d28cd08cebe137 | Dot | Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
- On the checkered paper ... | [
"from sys import stdin\r\n\r\nx,y,n,d = [int(x) for x in stdin.readline().split()]\r\nd = d**2\r\n\r\n\r\nv = []\r\n\r\nfor vec in range(n):\r\n v.append([int(x) for x in stdin.readline().split()])\r\n\r\nfound = {}\r\n\r\ndef winner(x,y,v,d):\r\n if x**2 + y**2 > d:\r\n return 1\r\n if (x,y) in fou... | {"inputs": ["0 0 2 3\n1 1\n1 2", "0 0 2 4\n1 1\n1 2", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76", "0 0 5 100\n16 24\n29 6\n44 24\n66 37\n102 19", "0 0 5 100\n4 108\n5 170\n7 30\n7 101\n21 117", "0 0 5 100\n30 9\n53 14\n84 7\n94 18\n121 16", "0 0 5 100\n52 144\n55 58\n56 103\n98 65\n134 16", "0 0 5 100\n17 3\n42 24\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
404367fb62cada8206433e740328e249 | Trees in a Row | The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a... | [
"n,k = map(int,input().split())\r\nalist = [int(x) for x in input().split()]\r\n\r\nminchange=n\r\nmina=1000\r\n\r\nfor a in range(1,1001):\r\n blist=[x*k+a for x in range(0,n)]\r\n change=0\r\n\r\n for i in range(0,n):\r\n if alist[i]!=blist[i]:\r\n change+=1\r\n\r\n if change>=mi... | {"inputs": ["4 1\n1 2 1 5", "4 1\n1 2 3 4", "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50", "10 1\n1 2 3 4 5 6 7 8 9 10", "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 13... | UNKNOWN | PYTHON3 | CODEFORCES | 25 | |
404b200d427f3ddb6485f4203e91fecd | Weird Chess | Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size *n*<=×<=*n* cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of... | [
"import math\r\nfrom sys import stdin\r\nfrom math import ceil\r\nimport sys\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n table = list()\r\n # newT = list()\r\n for i in range(n):\r\n table.append(input())\r\n # for i in range(2 * n):\r\n # newT.append(1)\r\n # table = [... | {"inputs": ["5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "3\no.x\noxx\no.x", "1\no", "2\nox\n.o", "5\n.xxo.\n..oxo\nx.oxo\no..xo\noooox", "8\n..x.xxx.\nx.x.xxxx\nxxxxxxox\nxxoxxxxx\n.xxxx.x.\nx.xxx.x.\n..x..xx.\n.xx...x.", "8\noxxxxxxx\nxoxxxoxx\nxx...x..\nxx...x..\nxx...... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
405b8caa86e7814d1e817ab826b49213 | The Useless Toy | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s... | [
"# Description of the problem can be found at http://codeforces.com/problemset/problem/834/A\r\n\r\nd = {\"v\": 0, \"<\": 1, \"^\": 2, \">\": 3}\r\nf1, f2 = input().split()\r\ns = int(input())\r\n\r\nx1 = (d[f1] + s) % 4 == d[f2]\r\nx2 = (d[f1] - s) % 4 == d[f2]\r\nif x1 and x2:\r\n print(\"undefined\")\r\nelif... | {"inputs": ["^ >\n1", "< ^\n3", "^ v\n6", "^ >\n999999999", "> v\n1", "v <\n1", "< ^\n1", "v <\n422435957", "v >\n139018901", "v ^\n571728018", "^ ^\n0", "< >\n2", "> >\n1000000000", "v v\n8", "< <\n1568", "^ v\n2", "^ <\n1", "< v\n1", "v >\n1", "> ^\n1", "v <\n422435957", "v v\n927162384", "v ^\n571728018", "^ <\n4674... | UNKNOWN | PYTHON3 | CODEFORCES | 170 | |
40717239356b32937395da93d2c71397 | TCMCF+++ | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of po... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\npos = []\r\nneg = []\r\nz = 0\r\n\r\nfor i in range(n):\r\n if a[i] > 0:\r\n pos.append(a[i])\r\n elif a[i] < 0:\r\n neg.append(a[i])\r\n else:\r\n z += 1\r\n\r\nm = len(neg)\r\nneg.sort()\r\n\r\nif m % 2:\r\n m -= 1\r\... | {"inputs": ["5\n1 2 -3 3 3", "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "4\n-2 -2 -2 -2", "1\n1", "1\n-1", "1\n0", "2\n1 1", "2\n1 -1", "2\n-1 1", "2\n-1 -1", "2\n1 0", "2\n0 1", "2\n0 0", "2\n-1 0", "2\n0 -1", "1\n13", "1\n-13", "1\n100", "1\n-100", "2\n100 100", "2\n100 -100", "2\n-100 100", "2\n100 0... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
408f82f624583dec0966eee9d774fe37 | Valera and Fruits | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec... | [
"from collections import*\r\nfrom heapq import*\r\nn,k=map(int,input().split())\r\nans=0\r\ng=defaultdict(list)\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n g[a].append(b)\r\nh=[]\r\nfor day in range(1,3002):\r\n if day in g:\r\n for i in g[day]:heappush(h,[day,i])\r\n sobr=k\r\n ... | {"inputs": ["2 3\n1 5\n2 3", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "2 1500\n2 575\n1 2522", "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\... | UNKNOWN | PYTHON3 | CODEFORCES | 49 | |
409dccf3516d83f62b976456af9790aa | Train | A stowaway and a controller play the following game.
The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or ... | [
"from sys import stdin, stdout, exit\r\n \r\nn, m, k = map(int, stdin.readline().split())\r\nd = 1 if stdin.readline()[6] == 'l' else -1\r\nm = 1 if m < k else n\r\n \r\nfor i, c in enumerate(stdin.readline(), 1):\r\n if c == '0':\r\n if k == 1: k, d = 2, 1\r\n elif k == n: k, d = n - 1, -1\r\n ... | {"inputs": ["5 3 2\nto head\n0001001", "3 2 1\nto tail\n0001", "4 2 1\nto tail\n1000001", "2 1 2\nto head\n111111", "4 1 4\nto head\n010001", "10 2 1\nto tail\n000000001", "5 5 3\nto tail\n01010000000001", "4 3 1\nto tail\n1000001001101", "4 1 3\nto head\n011000011000001", "20 13 9\nto head\n111111111111111111111111111... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
40c9ef84c365e270b4156155cd48a810 | Forbidden Indices | You are given a string *s* consisting of *n* lowercase Latin letters. Some indices in this string are marked as forbidden.
You want to find a string *a* such that the value of |*a*|·*f*(*a*) is maximum possible, where *f*(*a*) is the number of occurences of *a* in *s* such that these occurences end in non-forbidden in... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef suffix_array(s):\r\n l = len(s)\r\n x = [[] for _ in range(222)]\r\n for i in range(l):\r\n x[s[i]].append(i)\r\n y = []\r\n z = [0]\r\n for x0 in x:\r\n for i in x0:\r\n y.appen... | {"inputs": ["5\nababa\n00100", "5\nababa\n00000", "5\nababa\n11111", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\n1101101101110110001000001101001000100001010111001001111000111011000111111010110100000111001100100000", "100\nabbbafdcebdafbfdbbcfbdbeaceccccaaa... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
40cca99cdf0629447b7e56038528c854 | Common ancestor | The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are *... | [
"#!/usr/bin/env python3\r\n\r\nimport itertools\r\nimport collections\r\n\r\n# Read input strings\r\ns1 = input()\r\ns2 = input()\r\n\r\n# Read evolution rules, use a mapping from the 2 target characters to the source character\r\nrules = collections.defaultdict(set)\r\nn = int(input())\r\nfor i in range(n):\r\n r... | {"inputs": ["ababa\naba\n2\nc->ba\nc->cc", "ababa\naba\n7\nc->ba\nc->cc\ne->ab\nz->ea\nb->ba\nd->dd\nd->ab", "ababa\naba\n1\nc->ba", "mvo\nmx\n5\nu->dl\nt->fb\nx->vo\nn->kq\na->ca", "bxr\nbxr\n5\nw->jk\nm->ie\nh->ab\nu->sy\nj->gj", "oaujn\noaemvsbb\n50\ny->zr\nw->qg\nf->ep\nw->pd\nq->gf\ng->sn\nw->ug\ne->yj\nn->bb\nd->... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
40ce2b9ba56732ac93bbdb9bc82a216d | Color the Fence | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | [
"from copy import deepcopy\r\n\r\n\r\nclass Digit(object):\r\n def __init__(self, _cost, _value):\r\n self.cost = _cost\r\n self.value = _value\r\n\r\n\r\ndef main():\r\n v = int(input())\r\n a = list(map(int, input().split()))\r\n a = tuple(Digit(cost, digit+1) for digit, cost in enumerat... | {"inputs": ["5\n5 4 3 2 1 2 3 4 5", "2\n9 11 1 12 5 8 9 10 6", "0\n1 1 1 1 1 1 1 1 1", "50\n5 3 10 2 2 4 3 6 5", "22\n405 343 489 474 385 23 100 94 276", "62800\n867 936 2 888 474 530 287 822 220", "27\n836 637 966 929 82 678 213 465 688", "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "8982... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
40eb40e325de8be7bfeb81c76388a9d4 | Amr and Chemistry | Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.
Amr has *n* different types of chemicals. Each chemical *i* has an initial volume of *a**i* liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. ... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nba = list(map(lambda x: str(bin(x))[2:], a))\r\nbcom = ba[0]\r\nl = len(bcom)\r\nfor bnum in ba:\r\n # i + 1\r\n j = 0\r\n while j < l and bnum[j] == bcom[j]:\r\n j += 1\r\n l = j\r\n\r\nbcom = bcom[:l]\r\n\r\n# print(com)\r\... | {"inputs": ["3\n4 8 2", "3\n3 5 6", "2\n50000 100000", "2\n99999 99998", "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "19\n1 2 3 4 6 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6 8 16 20 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
40f2e176a6abf8dae6b38e3250395111 | Four Segments | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr... | [
"s = {0:0,1:0}\r\nfor i in range(4):\r\n a,b,c,d = input().split()\r\n if a==c and b!=d:\r\n s[0]+=1\r\n if b==d and a!=c:\r\n s[1]+=1\r\n for q in [(a,b),(c,d)]:\r\n s[q] = s.get(q,0) + 1\r\nprint(\"YES\" if all(i==2 for i in s.values())else \"NO\")",
"def slope(seg):\r\n\tif seg... | {"inputs": ["1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0", "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5", "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0", "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0", "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1", "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0", "... | UNKNOWN | PYTHON3 | CODEFORCES | 32 | |
40f403a46246b12aacc68b00452a2120 | Crash | During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive i... | [
"data = {}\r\nfor _ in range(int(input())):\r\n x, k = map(int, input().split())\r\n if k in data:\r\n data[k].append(x)\r\n else:\r\n data[k] = [x]\r\nflag = True\r\nfor counts in data.values():\r\n allowed = 0\r\n for count in counts:\r\n if count > allowed:\r\n flag... | {"inputs": ["2\n0 1\n1 1", "4\n0 1\n1 2\n1 1\n0 2", "4\n0 1\n1 1\n0 1\n0 2", "4\n7 1\n4 2\n8 2\n1 8", "2\n0 8\n0 5", "3\n7 9\n5 8\n8 2", "1\n0 8", "5\n8 10\n7 9\n5 6\n5 2\n10 7", "7\n0 2\n0 3\n0 2\n0 1\n0 10\n1 10\n0 5", "6\n0 1\n1 1\n2 1\n1 1\n2 1\n4 1", "4\n0 1\n1 1\n0 1\n2 1", "6\n0 1\n1 1\n2 1\n3 1\n4 1\n2 1", "3\n... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
4104e11d5fa7683657dfb3c6de1bb921 | Opponents | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | [
"n,d=map(int,input().split())\r\nm=[]\r\na=0\r\nfor i in range(d):\r\n l=input()[:n]\r\n if \"0\" in l:\r\n a=a+1\r\n else:\r\n m.append(a)\r\n a=0\r\n if i==d-1:\r\n m.append(a)\r\nprint(max(m))\r\n",
"n,d=map(int,input().split())\r\nm=0\r\ncount=0\r\nf=1\r\nfor i in range... | {"inputs": ["2 2\n10\n00", "4 1\n0100", "4 5\n1101\n1111\n0110\n1011\n1111", "3 2\n110\n110", "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111", "10 10\n000010001... | UNKNOWN | PYTHON3 | CODEFORCES | 201 | |
411cf6d0e6f1f53b7fb05afd40bdfab6 | New Year and Old Property | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Lim... | [
"l, r = map(int, input().split())\r\nb = ['1'] \r\nans = 0 \r\nc = 1 \r\nwhile(c <= 60):\r\n for i in range(len(b) - 1, 0, -1):\r\n b[i] = '0'\r\n a = int(''.join(b), 2)\r\n if(a >= l and a <= r):\r\n ans += 1 \r\n b[i] = '1' \r\n b.append('1')\r\n c += 1 \r\n \r\... | {"inputs": ["5 10", "2015 2015", "100 105", "72057594000000000 72057595000000000", "1 100", "1000000000000000000 1000000000000000000", "1 1000000000000000000", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "3 3", "3 4", "3 5", "3 6", "3 7", "4 4", "4 5", "4 6", "4 7", "5 5",... | UNKNOWN | PYTHON3 | CODEFORCES | 148 | |
413a2efed103298f61dbbdaba82b5d29 | Trains and Statistic | Vasya commutes by train every day. There are *n* train stations in the city, and at the *i*-th station it's possible to buy only tickets to stations from *i*<=+<=1 to *a**i* inclusive. No tickets are sold at the last station.
Let ρ*i*,<=*j* be the minimum number of tickets one needs to buy in order to get from station... | [
"n=int(input())\r\na=list(map(int, input().split()))\r\na=[ai-1 for ai in a]\r\na[n:n] = [n - 1]\r\n\r\ndp=[0]*n\r\nans=0\r\ni=n-2\r\n\r\nnmax=2**17\r\ntree=[[0,0]]*2*nmax;\r\n\r\n#Build Segment tree\r\nj=0\r\nwhile j<n:\r\n tree[nmax + j] = [a[j], j]\r\n j=j+1\r\nj=nmax-1\r\nwhile j>0:\r\n tree[j]=max(tre... | {"inputs": ["4\n4 4 4", "5\n2 3 5 5", "2\n2", "10\n2 10 8 7 8 8 10 9 10", "3\n3 3", "4\n3 3 4", "5\n4 4 4 5", "6\n3 3 6 6 6", "7\n7 3 4 6 6 7", "8\n3 7 7 8 8 7 8", "9\n2 9 7 6 9 7 8 9"], "outputs": ["6", "17", "1", "63", "3", "8", "13", "21", "35", "37", "52"]} | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
413ca22062394aad71eddbd8f0a7027b | Tea Party | Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that:
- Every cup... | [
"n, w = (int(i) for i in input().split())\r\nmas = [int(i) for i in input().split()]\r\n \r\ndef qer():\r\n global w\r\n for i, size in enumerate(mas):\r\n q = round(size / 2 + 0.1)\r\n rer[size,i] = q\r\n w -= q\r\n if w < 0:\r\n return {1:-1}\r\n \r\n for size,i in ... | {"inputs": ["2 10\n8 7", "4 4\n1 1 1 1", "3 10\n9 8 10", "1 1\n1", "1 1\n2", "1 10\n20", "3 10\n8 4 8", "3 100\n37 26 37", "3 60\n43 23 24", "20 14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 8\n1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2", "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
417ce5067c4e2e68d756c82c73b1dd87 | none | Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t... | [
"n = int(input())\r\ninf = 10 ** 9 + 7\r\na = list(map(int, input().split()))\r\nst = [0 for i in range(n)]\r\nst[0] = 1\r\nfor i in range(1, n):\r\n st[i] = (st[i - 1] * 2) % inf\r\na.sort()\r\nres = 0\r\nfor i in range(n - 1):\r\n res += (a[i + 1] - a[i]) * (st[i + 1] - 1) * (st[n - i - 1] - 1)\r\n res %... | {"inputs": ["2\n4 7", "3\n4 3 1", "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97", "1\n78091781", "2\n1000000000 1", "3\n999999998 999999999 999999992", "3\n465343471 465343474... | UNKNOWN | PYTHON3 | CODEFORCES | 38 | |
419ffe04367daa7d7a7fa8fd0572d3b8 | Cracking the Code | The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.
A young hacker Vasya disassembled the program and foun... | [
"num = input()\r\nansw = int(\"\".join((num[i] for i in [0,2,4,3,1])))\r\nansw = str(answ**5)\r\nprint(answ[-5:])# 1698156355.2098389",
"n=str(input())\r\ns=n[0]+n[2]+n[4]+n[3]+n[1]\r\ni=int(s)\r\ni=i**5\r\na=str(i)\r\nprint(a[-5:])\r\n",
"so=input(); print(str(int(so[0] + so[2] + so[4] + so[3] + so[1])**5)[-5:... | {"inputs": ["12345", "13542", "71232", "11111", "10000", "99999", "91537", "70809", "41675", "32036"], "outputs": ["71232", "84443", "10151", "36551", "00000", "99999", "27651", "00000", "61851", "82432"]} | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
41a166ab295ee669618ba2141ea4821c | Expensive Strings | You are given *n* strings *t**i*. Each string has cost *c**i*.
Let's define the function of string , where *p**s*,<=*i* is the number of occurrences of *s* in *t**i*, |*s*| is the length of the string *s*. Find the maximal value of function *f*(*s*) over all strings.
Note that the string *s* is not necessarily some s... | [
"def SA_IS(S):\r\n S += [0]\r\n k = max(S) + 1\r\n n = len(S)\r\n\r\n def induce_l(sa, a, n, k, stype):\r\n bucket = get_buckets(a, k, 1)\r\n for i in range(n):\r\n j = sa[i] - 1\r\n if j >= 0 and (not stype[j]):\r\n sa[bucket[a[j]]] = j\r\n ... | {"inputs": ["2\naa\nbb\n2 1", "2\naa\nab\n2 1", "1\naaa\n2", "3\na\naa\naaa\n1 2 3", "3\na\naaa\naa\n2 1 3", "1\nabcde\n-1", "1\na\n1", "5\nbbbb\nbaaa\nbbba\naaba\nbbaa\n17 -17 -82 47 -85", "10\nckxyxnoyqw\nlwvjsygwrc\nhretftiphn\nrqqncjnggb\ntxvnxgkynk\nbukntrryio\ncinrjaobxu\nxqvurzhxth\nkmvrlhpqdk\ndsdubnyoun\n-78 8... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
41ab7444d442dab8d3d66fbf569ee337 | Interestring graph and Apples | Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f... | [
"class DisjointSet:\r\n\r\n def __init__(self, n):\r\n self.array = [-1] * n\r\n\r\n def union(self, x, y):\r\n rx, ry = self.find(x), self.find(y)\r\n if rx == ry:\r\n return False\r\n if self.array[rx] < self.array[ry]:\r\n self.array[ry] = rx\r\n eli... | {"inputs": ["3 2\n1 2\n2 3", "1 1\n1 1", "1 2\n1 1\n1 1", "1 3\n1 1\n1 1\n1 1", "2 0", "2 1\n1 1", "2 1\n2 2", "2 1\n2 1", "2 2\n1 1\n2 2", "2 2\n1 2\n2 1", "2 3\n1 1\n1 2\n2 1", "3 2\n1 2\n1 2", "1 0", "4 3\n1 2\n1 3\n1 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1", "49 0", "50 0", "50 1\n2 3", "3 2\n1 2\n2 3", "5 3\n3 5\n4... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
41c39b952ce670cd8ffe912e78607de7 | A Blend of Springtime | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | [
"s=input()\r\nn=len(s)\r\nf=0\r\nfor i in range(n-2):\r\n if(ord(s[i])+ord(s[i+1])+ord(s[i+2])==198 and s[i]!=s[i+1]):\r\n f=1\r\n break\r\nif(f==0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")",
"s=input()\r\nl=['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']\r\ndef f(l,s):\r\n\tfor i in l:\r\... | {"inputs": [".BAC.", "AA..CB", ".", "ACB.AAAAAA", "B.BC.BBBCA", "BA..CAB..B", "CACCBAA.BC", ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.", "A", "..", "BC", "CAB", "A.CB", "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB", "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.... | UNKNOWN | PYTHON3 | CODEFORCES | 358 | |
41ca8fb7f117ce4485016a95203706a3 | Crazy Town | Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ... | [
"x1,y1=map(int,input().split())\r\nx2,y2=map(int,input().split())\r\na1=y1-y2\r\nb1=x2-x1\r\nc1=x2*(y2-y1)-y2*(x2-x1)\r\ndef intersect(a2,b2,c2):\r\n global a1,b1,c1,x1,y1,x2,y2\r\n if(a1*b2==a2*b1):\r\n return False\r\n x=(b1*c2-b2*c1)/(a1*b2-b1*a2)\r\n y=(a1*c2-c1*... | {"inputs": ["1 1\n-1 -1\n2\n0 1 0\n1 0 0", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 854898\n-846967 -749453 -341866\n-622388 434663 264157\n-638453 625357 344195\n-255265 -6763... | UNKNOWN | PYTHON3 | CODEFORCES | 72 | |
41d636d593d8694e8ec12e3e434c3a50 | none | A tree is a graph with *n* vertices and exactly *n*<=-<=1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.
A subtree of a tree *T* is a tree with both vertices and edges as subsets of vertices and edges of *T*.
You're ... | [
"import os, sys\r\nfrom io import BytesIO, IOBase\r\nfrom collections import *\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n ... | {"inputs": ["3\n1 2\n1 3\n1 -1 1", "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3", "10\n5 6\n8 2\n9 3\n4 1\n6 10\n9 8\n7 10\n7 4\n5 2\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3", "5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4", "12\n1 6\n10 1\n4 1\n7 1\n1 2\n5 1\n1 8\n1 11\n3 1\n12 1\n9 1\n580660007 861441526 -264928594 488291045 253254575 -974301934 709... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
41eb93137fa630da03ff834ead54d33f | Running Student | And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*.
Poor Student knows the following:
- during one run the minibus makes ... | [
"n,vb,vs=map(int,input().split())\r\nl=[int(i) for i in input().split()]\r\nget=[None]*n \r\nt=0 \r\ndx,dy=map(int,input().split())\r\nget[0]=10**9 \r\nfrom math import sqrt as S \r\ndef dist(x1,y1,x2,y2):\r\n return S((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))\r\ndef time(d,v):\r\n return d/v\r\nprev=0 \r\nfor i in ... | {"inputs": ["4 5 2\n0 2 4 6\n4 1", "2 1 1\n0 100000\n100000 100000", "6 5 1\n0 1 2 3 4 5\n0 0", "4 100 10\n0 118 121 178\n220 220", "4 3 3\n0 6 8 10\n7 -4", "5 900 1\n0 37474 80030 85359 97616\n-1 -1", "5 200 400\n0 8068 28563 51720 66113\n5423 -34", "6 10 3\n0 12 14 16 19 20\n14 0", "6 13 11\n0 16 27 31 39 42\n54 3", ... | UNKNOWN | PYTHON3 | CODEFORCES | 62 | |
41ebdff11474320eb192b62f53bee417 | Duff and Meat | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | [
"from math import inf\n\nmin_p = inf\nans = 0\nfor _ in range(int(input())):\n ai, pi = map(int, input().split())\n min_p = min(min_p, pi)\n ans += ai * min_p\nprint(ans)\n",
"n = int(input())\r\na = [0]*(n+3)\r\np = [0]*(n+3)\r\nfor i in range(n):\r\n t1, t2 = map(int,input().split())\r\n a[i] = t... | {"inputs": ["3\n1 3\n2 2\n3 1", "3\n1 3\n2 1\n3 2", "1\n39 52", "2\n25 56\n94 17", "5\n39 21\n95 89\n73 90\n9 55\n85 32", "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88", "2\n100 68\n38 80"], "outputs": ["10", "8", "2028", "2998", "6321", "6742", "9384"]} | UNKNOWN | PYTHON3 | CODEFORCES | 576 | |
42091aac2a6cdab50a22dada380bd1cb | Moore's Law | The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev... | [
"i = input().split()\nn = int(i[0])\nt = int(i[1])\nprint(n * 1.0 *(1.000000011 ** t))\n",
"n, t = [int(x) for x in input().split()]\r\n\r\ntasa = 1.000000011\r\n\r\nincremento = tasa**t\r\n\r\nprint(n*incremento)",
"n,t1=map(int,input().split())\r\nprint(((1.000000011**t1))*n)\r\n",
"n, t = map(int, input().... | {"inputs": ["1000 1000000", "1000 0", "1000 1", "1000 2", "10000 3", "10000 2000000000", "4907 244618708", "9030 982505993", "4054 287739817", "1587 1941728048"], "outputs": ["1011.060722383550382782399454922040", "1000", "1000.000011000", "1000.000022000000121000", "10000.000330000003630000013310000", "35849124123571.... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
4218b321e26d2ddfec1d7e89ce1f3bca | none | Santa Claus likes palindromes very much. There was his birthday recently. *k* of his friends came to him to congratulate him, and each of them presented to him a string *s**i* having the same length *n*. We denote the beauty of the *i*-th string by *a**i*. It can happen that *a**i* is negative — that means that Santa d... | [
"from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nk, n = map(int, input().split())\r\nd1 = defaultdict(lambda : [])\r\nd2 = defaultdict(lambda : [])\r\nfor _ in range(k):\r\n s, a = input().rstrip().decode().split()\r\n f = 1\r\n ... | {"inputs": ["7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4", "3 1\na 1\na 2\na 3", "2 5\nabcde 10000\nabcde 10000", "10 10\nnjxbzflaka -1\nfelbvvtkja 6\ngxiuztqkcw 5\naomvscmtti 6\njsqmkoyuca -2\nwckqtzuixg 5\najktvvblef -5\nittmcsvmoa -1\nakalfzbxjn 10\nacuyokmqsj 8", "10 20\njvyxocgomfmrtllgmagp 13\ngvtjnya... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
421b45ffdfe79c9f1edcd8d6002e3e6b | Beautiful Function | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | [
"def canonise(t):\r\n\tif t < 0:\r\n\t\treturn \"(0-\" + canonise(-t) + \")\"\r\n\tans = \"\"\r\n\twhile t > 50:\r\n\t\tans += \"(50+\"\r\n\t\tt -= 50\r\n\treturn ans + str(t) + \")\" * (len(ans)//4)\r\n\r\nn = int(input())\r\n\r\ncxes = []\r\ncyes = []\r\nfor i in range(n):\r\n\tx, y, r = map(int, input().split())... | {"inputs": ["3\n0 10 4\n10 0 4\n20 10 4", "3\n0 0 2\n5 7 5\n20 25 10", "1\n0 0 2", "4\n0 0 2\n50 50 2\n50 0 2\n0 50 2", "1\n50 50 50", "50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
422bf825badd0a5368d73f8ba0f21a26 | Brevity is Soul of Wit | As we communicate, we learn much new information. However, the process of communication takes too much time. It becomes clear if we look at the words we use in our everyday speech.
We can list many simple words consisting of many letters: "information", "technologies", "university", "construction", "conservatoire", "r... | [
"import sys\r\nfrom itertools import combinations\r\n\r\nin_file = open(\"input.txt\", \"r\") #\r\nout_file = open(\"output.txt\", \"w\")\r\n\r\nn = int(in_file.readline().strip())\r\n\r\nU = []\r\nfor i in range(n):\r\n U.append(in_file.readline().strip())\r\n \r\nA = [set() for u in U]\r\nl = len(U)\r\nV_in... | {"inputs": ["6\nprivet\nspasibo\ncodeforces\njava\nmarmelad\nnormalno", "5\naaa\naa\na\naaaa\naaaaa", "26\naaaaa\naaaab\naaaac\naaaad\naaaae\naaaaf\naaaag\naaaah\naaaai\naaaaj\naaaak\naaaal\naaaam\naaaan\naaaao\naaaap\naaaaq\naaaar\naaaas\naaaat\naaaau\naaaav\naaaaw\naaaax\naaaay\naaaaz", "26\naaaa\naaab\naaac\naaad\na... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
4232ec75dc18ac6e0a61e3e5a668e21d | Amr and The Large Array | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | [
"def bin_search(n,a):\r\n l = 0\r\n r = len(a)-1\r\n while l<=r:\r\n m = (l+r)//2\r\n if n>a[m][0]:\r\n l = m+1\r\n if n<a[m][0]:\r\n r = m-1\r\n if n == a[m][0]:\r\n return m\r\n return -1\r\nn = int(input())\r\na = input().split()\r\ndef ke(... | {"inputs": ["5\n1 1 2 2 1", "5\n1 2 2 3 1", "6\n1 2 2 1 1 2", "10\n1 1000000 2 1000000 3 2 1000000 1 2 1", "10\n1 2 3 4 5 5 1 2 3 4", "10\n1 1 2 1 1 2 2 1 2 3", "10\n5 4 3 2 1 1 2 3 4 5", "10\n1 10 100 1000 10000 1 10 100 1000 10000", "10\n9 9 9 9 8 9 8 8 8 8", "10\n1 11 111 1111 1 11 11 1 1111 1111"], "outputs": ["1 5... | UNKNOWN | PYTHON3 | CODEFORCES | 77 | |
426b5a365833606c53c083fcc15d7f14 | Presents | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c... | [
"n, k = list(map(int,input().strip().split(' ')))\r\nholidays = list(map(int,input().strip().split(' ')))[1:]\r\nprev = 0\r\ni = 0\r\ninc = 0\r\npres = 0\r\nwhile i < n:\r\n i += 1\r\n inc += 1\r\n if inc == k or i in holidays:\r\n prev = i\r\n inc = 0\r\n pres += 1\r\nprint(pres)",
"def findNext(curs... | {"inputs": ["5 2\n1 3", "10 1\n3 6 7 8", "5 5\n1 3", "10 3\n3 3 6 9", "5 2\n0", "1 1\n0", "5 1\n0", "5 1\n1 2", "5 2\n0", "10 3\n2 4 8", "10 1\n0", "10 2\n1 5", "10 1\n0", "10 1\n0", "15 5\n0", "15 1\n1 3", "15 2\n1 10", "15 1\n0", "15 3\n1 11", "20 1\n3 7 9 20", "20 3\n1 11", "20 2\n6 6 9 10 15 19 20", "20 1\n0", "20 ... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
426be2cfde0ba66b5780e3542f125b5d | Two Bases | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers.
The first line of the i... | [
"# import sys\r\n# sys.stdin = open('cf602a.in')\r\n\r\nn, bx = map(int, input().split())\r\nx = list(map(int, input().split()))\r\n\r\nm, by = map(int, input().split())\r\ny = list(map(int, input().split()))\r\n\r\nxx = sum(v * bx**(len(x) - i - 1) for i, v in enumerate(x))\r\nyy = sum(v * by**(len(y) - i - 1) for... | {"inputs": ["6 2\n1 0 1 1 1 1\n2 10\n4 7", "3 3\n1 0 2\n2 5\n2 4", "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0", "2 2\n1 0\n2 3\n1 0", "2 2\n1 0\n1 3\n1", "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2", "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0", "5 5\n4 4 4 4 4\n4 6\n5 5 5 5", "2 8\n1 0\n4 2\n1 0 0 0"... | UNKNOWN | PYTHON3 | CODEFORCES | 221 | |
4290dd7eebb98be6552ad447c1d68e45 | Haar Features | The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represent... | [
"n, m = [int(x) for x in input().split()]\nM = [[1 if k == 'B' else -1 for k in input()] for i in range(n)]\nP = [[0 for j in range(m+1)] for i in range(n+1)]\nfor i in range(n):\n for j in range(m):\n P[i][j] += M[i][j]\n P[i+1][j+1] += M[i][j]\n P[i+1][j] -= M[i][j]\n P[i][j+1] -= M... | {"inputs": ["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "10 9\nBWWWBWWBB\nBBWWBWBBW\nBBWBWBWBB\nBWBWBBBBB\nBBWBWBWBW\nBWWBWWBBW\nWBWWWBWWW\nWBBWBWBWW\nBBWWBWWBB\nBBWWBWWBW", "4 1\nW\nW\nB\nB", "2 10\nBBWBWWBWBB\nB... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
4297a8089e219ee6655d445c9c6e9503 | Circular RMQ | You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (in... | [
"import math,sys,bisect,heapq,os\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\nfrom functools import lru_cache\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\ndef input(): return sys.stdin.readline().rstrip('\\r\\n')\r\n#input = iter(sys.s... | {"inputs": ["4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1", "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1", "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1"], "outputs": ["1\n0\n0", "-2\n-1\n0\n0", "-1\n-1\n0\n-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
42ad930ecd13a48ee6b60a077599f993 | Sequence | Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of s... | [
"import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nq = []\r\nans = 0\r\nimport heapq\r\nfor i in range(n):\r\n heapq.heappush(q,-a[i])\r\n if -q[0] > a[i]:\r\n T = heapq.heappop(q)\r\n heapq.heappush(q,-a[i])\r\n ans += -T - a[i]\r\npri... | {"inputs": ["5\n3 2 -1 2 11", "5\n2 1 1 1 1", "5\n0 0 0 0 0", "1\n11", "2\n10 2", "6\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "7\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000", "10\n3 0 5 10 10 9 10 8 8 1", "20\n5 5 6 5 10 9 4 0 0 0 7 7 7 5 6 7 5 6 5 6",... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
42c6a5a548dc05112d0702ad7a0913f6 | The table | Harry Potter has a difficult homework. Given a rectangular table, consisting of *n*<=×<=*m* cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negativ... | [
"import math\r\nimport sys\r\ninput = sys.stdin.readline\r\nn, m = map(int, input().split())\r\na = [[] for _ in range(n)]\r\nfor i in range(n):\r\n a[i] = [int(_) for _ in input().split()]\r\nrow = []\r\ncol = []\r\nrowStat = [1] * n\r\ncolStat = [1] * m\r\nwhile True:\r\n bad = False\r\n for i in range(n... | {"inputs": ["4 1\n-1\n-1\n-1\n-1", "2 4\n-1 -1 -1 2\n1 1 1 1", "10 5\n1 7 1 6 -3\n8 -8 0 -7 -8\n7 -10 -8 -3 6\n-3 0 -9 0 -3\n-1 5 -2 -9 10\n-2 9 2 0 7\n5 0 -1 -10 6\n7 -8 -3 -9 1\n-5 10 -10 5 9\n-7 4 -8 0 -4", "5 10\n-2 -7 -10 -9 5 -9 -3 8 -8 5\n3 0 9 8 -4 -3 -8 1 8 1\n2 3 7 5 -8 -3 0 -9 -7 -2\n-6 -7 0 0 6 9 -8 6 -8 3\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
42c910c4a6919aef7498053ae7f7b086 | Cubical Planet | You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the mom... | [
"a,b,c=map(int,input().split())\r\nx,y,z=map(int,input().split())\r\n\r\nx=a-x\r\ny=b-y\r\nz=c-z\r\n\r\ndist=x**2+y**2+z**2\r\nif dist==3:\r\n print('NO')\r\n\r\nelse:\r\n print('YES')",
"x1,y1,z1=map(int,input().split())\r\nx2,y2,z2=map(int,input().split())\r\nif x1==x2 or y1==y2 or z1==z2:\r\n print(\"... | {"inputs": ["0 0 0\n0 1 0", "1 1 0\n0 1 0", "0 0 0\n1 1 1", "0 0 0\n1 0 0", "0 0 0\n0 1 0", "0 0 0\n1 1 0", "0 0 0\n0 0 1", "0 0 0\n1 0 1", "0 0 0\n0 1 1", "0 0 0\n1 1 1", "1 0 0\n0 0 0", "1 0 0\n0 1 0", "1 0 0\n1 1 0", "1 0 0\n0 0 1", "1 0 0\n1 0 1", "1 0 0\n0 1 1", "1 0 0\n1 1 1", "0 1 0\n0 0 0", "0 1 0\n1 0 0", "0 1... | UNKNOWN | PYTHON3 | CODEFORCES | 135 | |
42db725c4f43301d5b259580e315cf37 | Sereja and Algorithm | Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as *q*<==<=*q*1*q*2... *q**k*. The algorithm consists of two steps:
1. Find any continuous subsequence (substring) of three characters of string *q... | [
"s=input()\r\nhs=[[0]*3 for i in range(len(s)+1)]\r\nfor i in range(len(s)):\r\n for j in range(3):\r\n hs[i+1][j]=hs[i][j]\r\n if s[i]=='x':\r\n hs[i+1][0]+=1\r\n if s[i]=='y':\r\n hs[i+1][1]+=1\r\n if s[i]=='z':\r\n hs[i+1][2]+=1\r\nn=int(input())\r\nres=[]\r\nfor i in rang... | {"inputs": ["zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6", "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\n10\n17 67\n6 35\n12 45\n56 56\n14 30\n25 54\n1 1\n46 54\n3 33\n19 40", "xxxxyyxyyzzyxyxzxyzyxzyyyzyzzxxxxzyyzzzzyxxxxzzyzzyzx\n5\n4 4\n3 3\n1 24\n3 28\n18 39", "yzxyzxyzxzxzyzxyzyzzzyxzyz\n9\n4... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
42df25d03c42a9281bb42d57dea8b11c | Vladik and Complicated Book | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
So... | [
"n,m=map(int,input().split())\r\np=list(map(int,input().split()))\r\nfor _ in range(m):\r\n l,r,x=map(int,input().split())\r\n l2=p[l-1:r]\r\n k=l2[x-l]\r\n c=0\r\n for y in l2:\r\n if y<l2[x-l]:\r\n c+=1\r\n if c==x-l:\r\n print(\"Yes\")\r\n else:\r\n print(\"No... | {"inputs": ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3", "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3", "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4", "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11... | UNKNOWN | PYTHON3 | CODEFORCES | 30 | |
4322bd062e78cfb6f7bdbdb6c2d4dea5 | Vasya and Types | Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's descripti... | [
"#!/usr/bin/env python3 \r\n\r\nn = int(input())\r\n\r\ndata = dict()\r\ndata['void'] = 0\r\n\r\ndef parse(definition):\r\n ampersands = definition.count('&')\r\n asterisks = definition.count('*')\r\n name = definition[ampersands:len(definition)-asterisks]\r\n return (name, asterisks - ampersands)\r\n\r... | {"inputs": ["5\ntypedef void* ptv\ntypeof ptv\ntypedef &&ptv node\ntypeof node\ntypeof &ptv", "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &b b\ntypeof b\ntypeof c\ntypedef &&b* c\ntypeof c\ntypedef &b* c\ntypeof c\ntypedef &void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &&b* c\ntypeof c", "... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
43235ed4d2e5609de3c8d6267989703b | SwapSort | In this problem your goal is to sort an array consisting of *n* integers in at most *n* swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.
Note that in this problem you do not have to minimize the number o... | [
"# Generated by powerful Codeforces Tool\n# You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)\n# Author: djjzz\n# Time: 2023-05-01 17:13:46\n\nn = int(input())\ns = list(map(int, input().split()))\na = [] \nm = len(s)\n\nfor i in range(m):\n min_idx = i\n for j... | {"inputs": ["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100", "1\n1000", "2\n1000000000 -1000000000", "8\n5 2 6 8 3 1 6 8", "2\n200000000 199999999", "3\n100000000 100000002 100000001", "5\n1000000000 -10000000 0 8888888 7777777", "5\n10 30 20 50 40"], "outputs": ["2\n0 3\n4 2", "0", "1\n0 1", "0", "1\n0 1", "4\n0 ... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
436124fdf51dc694d298b358c9c52de6 | Short Code | Arkady's code contains $n$ variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide wi... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef trie():\r\n G, cnt = [[-1] * 26], [0]\r\n return G, cnt\r\n\r\ndef insert(s):\r\n j = 0\r\n for i in s:\r\n if not G[j][i - 97] ^ -1:\r\n G[j][i - 97] = len(cnt)\r\n G.append([-1] ... | {"inputs": ["3\ncodeforces\ncodehorses\ncode", "5\nabba\nabb\nab\naa\naacada", "3\ntelegram\ndigital\nresistance", "1\na", "10\naaaba\nbabba\nbbba\naaabb\nabba\na\nbbb\nbaa\naaba\naa", "10\naaaaaaaaaaaaaaa\naaaaaaaaaaaaaa\naaaaaaaa\naaa\naaaaaaaaaaaa\naa\naaaaaaa\naaaaaaaaa\naaaaaaaaaaaaa\naaaaaaaaaa", "26\ni\nm\nz\na\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
43679e980bde9e7eb4cadb169cffb376 | Try and Catch | Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.
The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks:
1. The try oper... | [
"n = (int)(input())\r\nstack = []\r\nfound = False\r\nfor _ in range(n) :\r\n line = input()\r\n operator = \"\"\r\n index = 0\r\n ln = len(line)\r\n while index < ln and line[index] == ' ' : index += 1\r\n if index == ln : continue\r\n while index < ln :\r\n operator += line[index]\r\n ... | {"inputs": ["8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")", "8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch(BE, \"BE in line 5\") \ncatch(AE,\"AE somewhere\")", "8\ntry\... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
43742a6b0a3bfdc144e535cc28eadd52 | Mike and Chocolate Thieves | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous... | [
"# import sys\r\n# sys.stdout = open('editor/output.txt', 'w')\r\n# sys.stdin = open('editor/input.txt', 'r')\r\n\r\n# Add custom packages imports here\r\n\r\n# Write solution here\r\ndef solution(m):\r\n def check(mid):\r\n ans = 0\r\n i = 2\r\n while i * i * i <= mid:\r\n ans +=... | {"inputs": ["1", "8", "10", "27", "28206", "32", "115", "81258", "116003", "149344197", "57857854", "999999999999999", "181023403153", "196071196742", "49729446417673", "14821870173923", "29031595887308", "195980601490039", "181076658641313", "166173583620704", "151269640772354", "136366565751970", "121463490731834", "... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
438d09394374feed263199efaf7d6f1d | Dima and Sequence | Dima got into number sequences. Now he's got sequence *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Also, Dima has got a function *f*(*x*), which can be defined with the following recurrence:
- *f*(0)<==<=0; - *f*(2·*x*)<==<=*f*(*x*); - *f*(2·*x*<=+<=1)<==<=*f*(*x*)<=+<=1.
Dima wonders, how many... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\nw = Counter(map(lambda x:(bin(int(x))[2:]).count('1'), input().split()))\r\nc = 0\r\nfor i in w:\r\n c += (w[i]*(w[i]-1))//2\r\n\r\nprint(c)",
"n = int(input())\r\nlis=list(map(int,input().split()))\r\nans=[... | {"inputs": ["3\n1 2 4", "3\n5 3 1", "2\n469264357 996569493", "6\n396640239 62005863 473635171 329666981 510631133 207643327", "8\n851991424 32517099 310793856 776130403 342626527 58796623 49544509 517126753", "7\n481003311 553247971 728349004 258700257 916143165 398096105 412826266", "4\n363034183 741262741 657823174 ... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
43ad1fbd0312da59aa03d4cd429e18f2 | Jzzhu and Children | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | [
"n,m = map(int,input().split())\r\narr = [i for i in range(n)]\r\nv = list(map(int,input().split()))\r\nwhile len(arr)>1:\r\n # print(arr)\r\n v[arr[0]]-=m\r\n if v[arr[0]]<=0:\r\n arr.pop(0)\r\n else:\r\n n = arr.pop(0)\r\n arr.append(n)\r\nprint(arr[0]+1)\r\n",
"import collectio... | {"inputs": ["5 2\n1 3 1 4 2", "6 4\n1 1 2 2 3 3", "7 3\n6 1 5 4 2 3 1", "10 5\n2 7 3 6 2 5 1 3 4 5", "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 7... | UNKNOWN | PYTHON3 | CODEFORCES | 355 | |
43b813e4082830bfb6b515f350e10621 | Big Segment | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | [
"n=int(input())\r\nL=[]\r\naG=0;\r\nmini = 1000000000\r\nmaxi = -1000000000;\r\nfor i in range(0,n):\r\n a=input().rstrip().split(' ')\r\n L.append(a)\r\n if int(a[0])<=mini and int(a[1])>=maxi:\r\n G=int(a[0]);\r\n H=int(a[1]);\r\n S=i;\r\n mini = int(a[0])\r\n maxi = in... | {"inputs": ["3\n1 1\n2 2\n3 3", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "4\n1 5\n2 2\n2 4\n2 5", "5\n3 3\n1 3\n2 2\n2 3\n1 2", "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8", "3\n2 5\n3 4\n2 3", "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19", "9\n1 10\n7 8\n6 7\n1 4\n5 9\n... | UNKNOWN | PYTHON3 | CODEFORCES | 403 | |
43c46bb04031f2be203158f0103de1b3 | Segments Removal | Vasya has an array of integers of length *n*.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after o... | [
"import heapq\r\nclass Node:\r\n\r\n def __init__(self,idx,freq,val) -> None:\r\n self.value=val \r\n self.index=idx \r\n self.occ=freq \r\n self.front=None \r\n self.back=None \r\nclass LinkedList:\r\n\r\n def __init__(self) -> None:\r\n self.head=None\r\n self.h=[]\r\n se... | {"inputs": ["4\n2 5 5 2", "5\n6 3 4 1 5", "8\n4 4 4 2 2 100 100 100", "6\n10 10 50 10 50 50", "1\n1", "100\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
442026842a6080e105907e188fe8446f | Travelling Salesman and Special Numbers | The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer *x* and reduce it to the number of bits set to 1 in the binary representation of *x*. For example for number 13 it's true that 1310<... | [
"MX = 1030\r\nM = 1000 * 1000 * 1000 + 7\r\nc = [[0] * MX for i in range(MX)]\r\nfor i in range(MX):\r\n c[i][0] = 1\r\nfor i in range(1, MX):\r\n for j in range(1, MX):\r\n c[i][j] = c[i - 1][j] + c[i - 1][j - 1]\r\n c[i][j] %= M\r\n \r\nnum = list(map(int, list(input())))\r\ncnt = int(input())... | {"inputs": ["110\n2", "111111011\n2", "100011110011110110100\n7", "110100110\n0", "10000000000000000000000000000000000000000000\n2", "100000000000000000000100000000000010100100001001000010011101010\n3", "101010110000\n3", "11010110000\n3", "100\n6", "100100100100\n5", "10000000000\n4", "10\n868", "1\n0", "1\n1", "10\n0... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
444bae627ba01124383dbebb45960ea7 | Semifinals | Two semifinals have just been in the running tournament. Each semifinal had *n* participants. There are *n* participants advancing to the finals, they are chosen as follows: from each semifinal, we choose *k* people (0<=≤<=2*k*<=≤<=*n*) who showed the best result in their semifinals and all other places in the finals g... | [
"from heapq import *\r\nfrom queue import *\r\nimport sys, math, bisect\r\nfrom collections import Counter, defaultdict\r\nfrom math import *\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\n# print = sys.stdout.write\r\ninl = lambda: list(map(int, input().split()))\r\nintp = lambda: tuple(map... | {"inputs": ["4\n9840 9920\n9860 9980\n9930 10020\n10040 10090", "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110", "1\n1 2", "1\n2 1", "2\n1 2\n3 4", "2\n3 1\n4 2", "3\n1 3\n2 5\n4 6", "3\n2 1\n4 3\n5 6", "3\n1 4\n2 5\n3 6", "4\n5 1\n6 2\n7 3\n8 4", "2\n1 2\n4 3", "3\n1 2\n3 5\n4 6", "3\n1 2\n3 4\n5 6", "3\n1 3\n2 4\... | UNKNOWN | PYTHON3 | CODEFORCES | 38 | |
445d9481502b5c3e25f57cafd9bf8b5a | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | [
"import math\r\nn = int(input())\r\nsticks = list(map(int,input().split()))\r\n\r\nsticks.sort()\r\n \r\npair = 0\r\ncount = 1\r\n\r\nfor index in range(len(sticks)-1):\r\n if sticks[index] == sticks[index+1]:\r\n count = count + 1\r\n if index == len(sticks)-2:\r\n pair = pair + math.fl... | {"inputs": ["5\n2 4 3 2 3", "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "4\n3 3 3 5", "2\n3 5", "9\n1 2 3 4 5 6 7 8 9", "14\n2 4 2 6 2 3 4 1 4 5 4 3 4 1", "33\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36", "1\n1", "1\n10", "2\n1 1", "3\n1 1 1", "3\n1 2 2", "3\n3 2 1", "4\n1 1 1 1", "4... | UNKNOWN | PYTHON3 | CODEFORCES | 125 | |
4473ff9e4adbc9cb1817d454202ff6d3 | Magic Powder - 1 | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | [
"class Solution:\r\n def getList(self):\r\n return list(map(int,input().split()))\r\n def solve(self):\r\n n,k = input().split()\r\n n = int(n)\r\n k = int(k)\r\n a = self.getList()\r\n b = self.getList()\r\n c = [b[i]//a[i] for i in range(n)]\r\n total ... | {"inputs": ["3 1\n2 1 4\n11 3 16", "4 3\n4 3 5 6\n11 12 14 20", "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779", "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 91 | |
449f1c28e0986a00b861c10185315278 | Pouring Rain | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | [
"from math import pi\r\nX = list(map(int, input().split()))\r\nRainPouring = X[-1] * (X[0] / 2) ** 2 * pi\r\nif RainPouring >= X[-2]: print(\"NO\");exit()\r\nX[-2] -= RainPouring\r\nVolume = X[1] * (X[0] / 2) ** 2 * pi\r\nprint(\"YES\", Volume / X[-2], sep='\\n')\r\n# Caption: With the help of ARPA\r\n",
"from ma... | {"inputs": ["1 2 3 100", "1 1 1 1", "48 7946 7992 72", "72 6791 8546 46", "100 5635 9099 23", "20 287 3845 5", "48 6428 9807 83", "72 5272 4552 64", "100 4117 5106 34", "20 2961 9852 15", "48 1805 3109 93", "72 8534 7042 65", "1 47 80 68", "4 495 8813 1", "5 2797 5925 9", "1 8324 4362 23", "6 1976 8455 3", "7 2644 8080... | UNKNOWN | PYTHON3 | CODEFORCES | 216 | |
44c0f23b8d8ca722aa4895215030b6d0 | PolandBall and Hypothesis | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | [
"from math import sqrt\r\nn=int(input())\r\nm=1\r\nwhile True:\r\n x=(n*m)+1\r\n flag=0\r\n for _ in range(2,int(sqrt(x))+1):\r\n if x%_==0:\r\n flag=1\r\n break\r\n if flag==1:\r\n print(m)\r\n break \r\n m+=1 \r\n ",
"n = int(input())\r\n\r\nde... | {"inputs": ["3", "4", "10", "153", "1000", "1", "2", "5", "6", "7", "8", "9", "11", "998", "996", "36", "210", "270", "306", "330", "336", "600", "726", "988", "12", "987", "13", "986", "14", "985", "15", "984", "16", "983", "17", "982", "18", "981", "19", "980", "20", "979", "21", "978", "22", "977", "23", "976", "24"... | UNKNOWN | PYTHON3 | CODEFORCES | 283 | |
44ca45f51b5c4a41c257d86927f120ff | Misha and XOR | After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number *x* to the basket, Misha should answer the que... | [
"m = int(input())\r\nbasis = []\r\nfor i in range(m):\r\n a = int(input())\r\n need=0\r\n for v,bitset in basis:\r\n if a^v<a:\r\n need^=bitset\r\n a^=v\r\n if a:\r\n basis.append((a,need^(1<<i)))\r\n print(0)\r\n else:\r\n res = [d for d in range(i) ... | {"inputs": ["7\n7\n6\n5\n4\n3\n2\n1", "2\n5\n5", "10\n81\n97\n12\n2\n16\n96\n80\n99\n6\n83", "10\n15106\n13599\n69319\n33224\n26930\n94490\n85089\n60931\n23137\n62868", "10\n5059464500\n8210395556\n3004213265\n248593357\n5644084048\n9359824793\n8120649160\n4288978422\n183848555\n8135845959", "10\n4\n12\n28\n29\n31\n31\... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
44dfc44778d571919af6c6951a9cfbd9 | Permutations | Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.
One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through *n* and is asked to convert the first one to the second. In one move he can remove the last number from the pe... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\nB = list(map(int, input().split()))\r\n\r\npre = -1\r\nj = 0\r\nfor i in range(N):\r\n while j<N and A[i]!=B[j]:\r\n j+=1\r\n if j<N and A[i]==B[j]:\r\n pre = i+1\r\n ... | {"inputs": ["3\n3 2 1\n1 2 3", "5\n1 2 3 4 5\n1 5 2 3 4", "5\n1 5 2 3 4\n1 2 3 4 5", "1\n1\n1", "7\n6 1 7 3 4 5 2\n6 1 7 3 4 5 2", "10\n5 8 1 10 3 6 2 9 7 4\n4 2 6 3 1 9 10 5 8 7", "10\n1 6 10 3 4 9 2 5 8 7\n7 5 1 6 10 3 4 8 9 2", "10\n2 1 10 3 7 8 5 6 9 4\n6 9 2 4 1 10 3 7 8 5", "10\n8 2 10 3 4 6 1 7 9 5\n8 2 10 3 4 6... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
44f8b44da74a30906d6c591697c555e4 | Green and Black Tea | Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black.
Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order ... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nchars=['G','B']\r\nN,K,a,b = map(int, input().split())\r\nif a<b:\r\n a,b = b,a\r\n chars=['B','G']\r\n \r\nans = ['']\r\nwhile a>0:\r\n if a>b:\r\n if len(ans[-1])>=K:break\r\n ans[-1]+=chars[0]\r\n a-=1\r\n ... | {"inputs": ["5 1 3 2", "7 2 2 5", "4 3 4 0", "2 2 0 2", "3 2 0 3", "1 1 0 1", "1 1 1 0", "11 2 3 8", "100000 39 24855 75145", "2 2 2 0", "2 2 1 1", "3 2 2 1", "3 2 1 2", "5 1 4 1", "10 1 7 3", "20 1 5 15", "1000 123 447 553", "3000 70 2946 54", "10000 590 4020 5980", "10001 1841 1052 8949", "50000 104 31045 18955", "59... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
45282fa05e4b8c2d025dd8d93e75065b | Palindrome pairs | You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=<<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*.... | [
"s = input()\r\nn = len(s)\r\n\r\nbeg = [0] * n\r\nend = [0] * n\r\n\r\nfor i in range(n):\r\n for j in range(n):\r\n if i-j < 0 or i+j >= n: break\r\n if s[i-j] != s[i+j]: break\r\n beg[i-j] += 1\r\n end[i+j] += 1\r\n\r\n for j in range(n):\r\n if i-j < 0 or i+j+1 >= n: bre... | {"inputs": ["aa", "aaa", "abacaba", "aaaaaaaaaa", "aabbb", "abbaa", "bbbbb", "bbaab", "aabba", "aaaaa", "abicabacka", "aiajadabaa", "abacabauabagabaeabacabadabacabbfabacamadabacabaeabacabadabacababcdggdefxeceadaffhecbgpdbeffecdcbfagcbbfgegaggcaffdfiafaeaab", "abacabadabacabaeabacabadabacabafabacabadabqcabaeoqacabagabac... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
45481b7f95028e4feb5463900ff4ae43 | Kefa and Company | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has *n* friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend... | [
"def fun(l,val):\r\n b=0\r\n e=len(l)-1\r\n ans=-1\r\n while(b<=e):\r\n mid=(b+e)//2\r\n if l[mid]>=val:\r\n e=mid-1\r\n else:\r\n ans=mid\r\n b=mid+1\r\n return ans\r\n \r\nn,d=map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n... | {"inputs": ["4 5\n75 5\n0 100\n150 20\n75 1", "5 100\n0 7\n11 32\n99 10\n46 8\n87 54", "1 1000000000\n15 12", "5 1\n5 9\n2 10\n8 5\n18 12\n1 1", "3 3\n4 15\n0 17\n9 11", "5 10\n8 90\n1009 1000000\n9 121\n10 298\n0 109092", "5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989", "4 2\n10909234 9\n10909236 8\n... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
4563ded09df778b09bd7288d019e0de1 | Perfect Permutation | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | [
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 14 12:45:15 2022\r\n\r\n@author: dehon\r\n\"\"\"\r\n\r\nn = int(input())\r\nif(n%2 == 1):\r\n print(-1)\r\nelse:\r\n for i in range(1,n+1):\r\n if(i%2 == 1):\r\n print(i+1, end=' ')\r\n else:\r\n print(i-1, end=' ')",... | {"inputs": ["1", "2", "4", "3", "5", "6", "7", "20", "8", "9", "10", "11", "21", "50", "51", "52", "84", "86", "100", "98", "96", "33", "34", "36", "38", "40", "42", "44", "46", "48"], "outputs": ["-1", "2 1 ", "2 1 4 3 ", "-1", "-1", "2 1 4 3 6 5 ", "-1", "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 ", "2 1 4 3... | UNKNOWN | PYTHON3 | CODEFORCES | 464 | |
4588cbcd745d482105ef033b27b0a596 | Shaass and Lights | There are *n* lights aligned in a row. These lights are numbered 1 to *n* from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is a... | [
"MOD = int(1e9+7)\r\nn, m = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\n\r\nfact = [1]\r\nfor i in range(1, 1000):\r\n fact.append((fact[-1] * i) % MOD)\r\n\r\ndef fast_power(b, e):\r\n res = 1\r\n while e > 0:\r\n if e % 2 == 1:\r\n res = res * b % MOD\r... | {"inputs": ["3 1\n1", "4 2\n1 4", "11 2\n4 8", "4 2\n1 3", "4 4\n1 2 3 4", "4 2\n1 3", "4 4\n1 2 3 4", "1000 3\n100 900 10", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74 13\n6 14 19 20 21 24 30 43 58 61 69 70 73", "74... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
45986d9ec9e10c4ae93d52ad9184357c | Uncowed Forces | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | [
"def score(x,m,w):\r\n t=(1-(m/250))*x - (50*w)\r\n return max(0.3*x,t)\r\n\r\nsl=[500,1000,1500,2000,2500]\r\nm=list(map(int, input().split()))\r\nw=list(map(int, input().split()))\r\ns,u=map(int,input().split())\r\n\r\nres=0\r\n\r\nfor i in range(5):\r\n res+=score(sl[i],m[i],w[i])\r\nres+=(100*s)\r\nres... | {"inputs": ["20 40 60 80 100\n0 1 2 3 4\n1 0", "119 119 119 119 119\n0 0 0 0 0\n10 0", "3 6 13 38 60\n6 10 10 3 8\n9 9", "21 44 11 68 75\n6 2 4 8 4\n2 8", "16 112 50 114 68\n1 4 8 4 9\n19 11", "55 66 75 44 47\n6 0 6 6 10\n19 0", "47 11 88 5 110\n6 10 4 2 3\n10 6", "5 44 61 103 92\n9 0 10 4 8\n15 7", "115 53 96 62 110\n... | UNKNOWN | PYTHON3 | CODEFORCES | 213 | |
45cdd77b341010af99c45274268020a2 | Decoding | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf... | [
"n = int(input())\r\na=input()\r\nif (n-1)%2==0:\r\n c = ''\r\n i = n - 2\r\n while i % 2 != 0 and i > 0:\r\n c = c + a[i]\r\n i = i - 2\r\n i = 0\r\n while i % 2 == 0 and i < n:\r\n c = c + a[i]\r\n i = i + 2\r\nelse:\r\n c = ''\r\n i = n - 2\r\n while i % 2 == 0... | {"inputs": ["5\nlogva", "2\nno", "4\nabba", "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "1\nw", "2\ncb", "3\nqok", "4\naegi", "5\noqquy", "6\nulhpnm", "7\nijvxljt", "8\nwwmiwkeo", "9\ngmwqmpfow", "10\nhncmexsslh", "20\nrtcjbjlbtjfmvzdqutuw", "21\ngjyiqoebcnpsdegxnsauh", "30\nudotcwvcwxajkadxqvxvwgmwmnqrb... | UNKNOWN | PYTHON3 | CODEFORCES | 427 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.