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
5f544507a89d8890327fa2f6658e917e
none
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
[ "\"\"\"\r\n author: Newplayers12\r\n created: Friday 06-08-2021 08:24:19\r\n\"\"\"\r\nimport queue\r\nimport math\r\n\r\ndef findSet(x):\r\n if (parent[x] != x):\r\n parent[x] = findSet(parent[x])\r\n return parent[x]\r\n\r\ndef unionSet(a, b):\r\n pa = findSet(a)\r\n pb = findSet(b)\...
{"inputs": ["6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2", "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8", "5 4\n1 5\n1 3\n1 4\n3 2", "12 12\n4 12\n4 7\n4 9\n7 2\n5 12\n2 1\n5 9\n8 6\n10 12\n2 5\n10 9\n12 3", "12 15\n3 2\n11 12\n1 9\n2 1\n1 8\n9 6\n11 5\n9 5\n9 10\n11 3\n7 11\n5 6\n1...
UNKNOWN
PYTHON3
CODEFORCES
56
5f55ca8af46f5d6579c10f09189e234d
24 Game
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit...
[ "n=int(input())\r\nif n>=4:\r\n print(\"YES\")\r\n if n==4:\r\n print(\"4 * 3 = 12\")\r\n print(\"12 * 2 = 24\")\r\n print(\"24 * 1 = 24\")\r\n elif n==5:\r\n print(\"5 * 4 = 20\")\r\n print(\"20 + 3 = 23\")\r\n print(\"23 + 2 = 25\")\r\n print(\"25 - 1 = 24...
{"inputs": ["1", "8", "12", "100", "1000", "987", "2", "3", "4", "5", "6", "7", "100000", "99999", "99998", "99997", "580", "422", "116", "447", "62052", "25770", "56118", "86351", "48108", "33373", "9782", "19082", "4", "7", "3"], "outputs": ["NO", "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56...
UNKNOWN
PYTHON3
CODEFORCES
42
5f78c17e3e077560c33137901ccbd807
Simple Subset
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=&lt;<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime. You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You wan...
[ "import math\n\nN = 2000001\nsq = math.floor(N ** 0.5)\nisprime = [True] * N\nfor p in range(2, N):\n if isprime[p]:\n for i in range(p**2, N, p):\n isprime[i] = False\n\ndef solve():\n n = int(input())\n A = [int(x) for x in input().split()]\n odd = list(filter(lambda x: x%2, A))\n ...
{"inputs": ["2\n2 3", "2\n2 2", "3\n2 1 1", "2\n83 14", "10\n10 10 1 2 3 3 1 2 1 5", "100\n314 905 555 526 981 360 424 104 920 814 143 872 741 592 105 573 837 962 220 692 560 493 889 824 145 491 828 960 889 87 375 486 609 423 386 323 124 830 206 446 899 522 514 696 786 783 268 483 318 261 675 445 1000 896 812 277 131 2...
UNKNOWN
PYTHON3
CODEFORCES
5
5f7f173ec7b8e0e45134a0c4d3a65ec4
Winter Is Coming
The winter in Berland lasts *n* days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tires which allows him to drive safely no more than *k* days at any average air temperature. After *k* days of using it (regardless of the temperature of these days) the set ...
[ "_, k = map(int, input().split())\nval = [0] + list(map(int, input().split()))\nn = len(val)\npls = []\n\ncur, i, sm = 0, 0, 0\nwhile i < n:\n if val[i] >= 0:\n cur += 1\n else:\n if cur > 0:\n pls.append(cur)\n cur = 0\n i += 1\n\nsm = sum(p for p in pls)\npls = pls[1:]\n\...
{"inputs": ["4 3\n-5 20 -3 0", "4 2\n-5 20 -3 0", "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "4 4\n-5 20 -3 0", "4 1\n-5 20 -3 0", "1 0\n-13", "2 0\n-12 -13", "3 1\n9 -16 -7", "5 5\n-15 -10 -20 -19 -14", "7 3\n-2 -14 3 -17 -20 -13 -17", "10 10\n-9 4 -3 16 -15 12 -12 8 -14 15", "30 9\n12 8 -20 0 11 -17 -11 -6 -2 -18 -19 -19 -18 -1...
UNKNOWN
PYTHON3
CODEFORCES
7
5faca9bc5d53ce1b6775356223a21f65
Bicycle Chain
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<...
[ "import math\r\nn=int(input())\r\narr=[int(x) for x in input().split()]\r\nm=int(input())\r\nbrr=[int(x) for x in input().split()]\r\nmx=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if int(math.ceil(brr[j]/arr[i]))==brr[j]//arr[i]:\r\n if brr[j]//arr[i]>mx:\r\n mx=brr[j]//a...
{"inputs": ["2\n4 5\n3\n12 13 15", "4\n1 2 3 4\n5\n10 11 12 13 14", "1\n1\n1\n1", "2\n1 2\n1\n1", "1\n1\n2\n1 2", "4\n3 7 11 13\n4\n51 119 187 221", "4\n2 3 4 5\n3\n1 2 3", "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97", "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28", "10\n24 ...
UNKNOWN
PYTHON3
CODEFORCES
414
5fb2747ed83e4c02b1581533dd4e7d2c
Mice
Modern researches has shown that a flock of hungry mice searching for a piece of cheese acts as follows: if there are several pieces of cheese then each mouse chooses the closest one. After that all mice start moving towards the chosen piece of cheese. When a mouse or several mice achieve the destination point and ther...
[ "def distance(x, y):\r\n return abs(x - y)\r\n\r\nn, m, y0, y1 = map(int, input().split())\r\nmouse = list(map(int, input().split()))\r\ncheeses = list(map(int, input().split()))\r\n\r\ni = 0 \r\nj = 0\r\nres = 0\r\nmouse.append(float(\"inf\"))\r\ncheeses.append(float(\"inf\"))\r\nprevJ = -1\r\n\r\nfor i in rang...
{"inputs": ["3 2 0 2\n0 1 3\n2 5", "7 11 10 20\n6 18 32 63 66 68 87\n6 8 15 23 25 41 53 59 60 75 90", "13 17 14 1\n6 9 10 12 17 25 91 100 118 136 145 163 172\n0 1 2 3 4 10 12 13 16 17 19 22 26 27 28 109 154", "19 23 13 11\n3 6 7 15 21 22 23 33 35 37 40 44 79 86 100 114 121 135 142\n2 3 5 6 7 14 15 17 18 19 20 22 25 27 ...
UNKNOWN
PYTHON3
CODEFORCES
4
5fca268576815fab64c58a47fbb928cc
Two Sets
Little X has *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n*. He wants to divide all of them into two sets *A* and *B*. The following two conditions must be satisfied: - If number *x* belongs to set *A*, then number *a*<=-<=*x* must also belong to set *A*. - If number *x* belongs to set *B*, then number *b*<=-<=*x...
[ "import sys\r\nfrom collections import defaultdict as dd\r\ninput = sys.stdin.readline\r\nI = lambda : list(map(int,input().split()))\r\n\r\nn,a,b=I()\r\nl=I()\r\ndic=dd(int)\r\nfor i in range(n):\r\n\tdic[l[i]]=1\r\nbs=[]\r\npa=dd(int)\r\nfor i in range(n):\r\n\tif dic[a-l[i]]==0:\r\n\t\tbs.append(l[i])\r\n\telse:...
{"inputs": ["4 5 9\n2 3 4 5", "3 3 4\n1 2 4", "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 2420 3361 3035 956 253...
UNKNOWN
PYTHON3
CODEFORCES
6
60122b5a7d52bc435984453c4c38584a
Mahmoud and Ehab and the bipartiteness
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *...
[ "import math\r\nimport sys\r\nfrom collections import defaultdict\r\nfrom collections import Counter\r\nfrom collections import deque\r\nimport bisect\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split())...
{"inputs": ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5", "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8", "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9", "2\n1 2"], "outputs": ["0", "2", "16", "16", "16", "0", "0...
UNKNOWN
PYTHON3
CODEFORCES
124
6014b9478d7f57ed59cdafd03fe47e3e
none
Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point *d*. Johnny's truck has a gas tank that holds exactly *n* liters, and his tank is initially full. As he drives, the truck consu...
[ "#!/usr/bin/env python3\n\nfrom heapq import heappop, heappush\n# from collections import defaultdict\n\n\ndef pprint(*args):\n print(*args)\n\n\ndef discard_earlier(h, pos):\n while h and h[0][1] <= pos:\n heappop(h)\n\n\nend, max_fuel, num_stations = map(int, input().strip().split(' '))\n# pprint('...
{"inputs": ["10 4 4\n3 5\n5 8\n6 3\n8 4", "16 5 2\n8 2\n5 1", "400000000 400000000 3\n1 139613\n19426 13509\n246298622 343529", "229 123 2\n170 270968\n76 734741", "153 105 1\n96 83995", "281 12 23\n178 650197\n129 288456\n34 924882\n43 472160\n207 957083\n103 724815\n167 308008\n135 906958\n74 242828\n229 146026\n85 2...
UNKNOWN
PYTHON3
CODEFORCES
1
601619bbc1a70e0f37eec361a968484a
Rebus
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive integer from 1 to *n*, such that equality holds. The only line of the input contains a rebus....
[ "s = input().split()\nt = s[::]\nreq = int(s[-1])\nlim = req\nS = 0\nfor i in range(len(s)):\n\tif s[i] == '?':\n\t\ts[i] = '1'\n\t\tS += 1 if i == 0 or s[i - 1] == '+' else -1\n\nif S < req:\n\tfor i in range(len(s)):\n\t\tif t[i] == '?':\n\t\t\tsign = 1 if i == 0 or s[i - 1] == '+' else -1\n\t\t\tif sign == 1:\n\...
{"inputs": ["? + ? - ? + ? + ? = 42", "? - ? = 1", "? = 1000000", "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 9", "? - ? + ? + ? + ? + ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? + ? + ? + ? - ? + ? + ? + ? - ? + ? + ? - ? + ? - ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? - ...
UNKNOWN
PYTHON3
CODEFORCES
22
602b71ae265c6a9862d03253d3a2378a
Wizards and Minimal Spell
Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells. Each spell consists of several lines. The line, whose first non-space chara...
[ "import sys\r\nres = ''\r\nhas_endl = True\r\nfor line in sys.stdin:\r\n if '#' in line:\r\n i = line.index('#')\r\n if list(line[:i]) == [' '] * i:\r\n if not has_endl:\r\n res += '\\n'\r\n res += line\r\n has_endl = True\r\n continue\r\n ...
{"inputs": [" # include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#", "#\n \n#", "#a\n#a\n\n#a\n\n\n#a\n \n#a\n \n\n#a\n\n \n#a\n \n \n#a", " # a \n # a \n\n # a \n\n\n # a ...
UNKNOWN
PYTHON3
CODEFORCES
3
604fde0d7c396166ca579aaf2833553f
Hiking
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the *i*-th rest point the distance from the start equals *x**i*, and its picturesque...
[ "#from sys import stdin\r\n#input=lambda :stdin.readline()[:-1]\r\nimport math\r\nn,l=map(int,input().split())\r\nd=[0]\r\nb=[0]\r\n#data=[0]*n\r\n#data1=[0]*n\r\n#data2=[-1]*n\r\nfor i in range(0,n):\r\n t,tt=map(int,input().split())\r\n d.append(t)\r\n b.append(tt)\r\ndata=[]\r\nfor i in range(0,n):\r\n ...
{"inputs": ["5 9\n10 10\n20 10\n30 1\n31 5\n40 10", "1 20\n9 1", "2 7\n1 9\n5 6", "3 2\n2 6\n3 9\n6 8", "4 3\n1 6\n5 10\n9 9\n10 6", "5 1\n2 3\n5 4\n7 9\n8 10\n10 7", "10 6\n1 16\n8 27\n23 2\n26 21\n32 50\n38 53\n51 79\n62 97\n77 18\n100 5", "11 6\n9 50\n10 56\n14 39\n17 91\n22 1\n25 65\n38 15\n39 93\n54 62\n62 31\n90 ...
UNKNOWN
PYTHON3
CODEFORCES
1
606225754191071a59ac3caab457cd3b
Jzzhu and Apples
Jzzhu has picked *n* apples from his big apple tree. All the apples are numbered from 1 to *n*. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be gre...
[ "apples=int(input())\n\nif apples<=3:\n\n print(0)\n\nelse:\n\n halfpr=int(apples/2)\n\n def primes(n):\n\n isPrime = [True for i in range(n + 1)]\n\n isPrime[0] = isPrime[1] = False\n\n \n\n idx = 2\n\n while idx * idx <= n:\n\n if isPrime[idx]:\n\n ...
{"inputs": ["6", "9", "2", "10", "100", "99998", "100000", "1", "3", "5", "98765", "52999", "99524", "99994", "5249", "99999", "10007", "30011", "60013", "99991"], "outputs": ["2\n6 3\n2 4", "3\n9 3\n2 4\n6 8", "0", "4\n2 4\n6 8\n10 5\n9 3", "44\n33 27\n22 11\n25 5\n64 66\n42 44\n31 62\n58 29\n43 86\n15 21\n6 99\n8 12\...
UNKNOWN
PYTHON3
CODEFORCES
3
60697373d2b5fcb2993cba287677c38d
The Values You Can Make
Pari wants to buy an expensive chocolate from Arya. She has *n* coins, the value of the *i*-th coin is *c**i*. The price of the chocolate is *k*, so Pari will take a subset of her coins with sum equal to *k* and give it to Arya. Looking at her coins, a question came to her mind: after giving the coins to Arya, what va...
[ "from heapq import heappush, heappop\r\nfrom collections import defaultdict, Counter, deque\r\nimport threading\r\nimport sys\r\nimport bisect\r\ninput = sys.stdin.readline\r\ndef ri(): return int(input())\r\ndef rs(): return input()\r\ndef rl(): return list(map(int, input().split()))\r\ndef rls(): return list(inpu...
{"inputs": ["6 18\n5 6 1 10 12 2", "3 50\n25 25 50", "1 79\n79", "1 114\n114", "5 1\n1 500 205 6 355", "8 42\n7 24 22 25 31 12 17 26", "8 91\n74 25 66 50 62 30 50 50", "8 15\n13 3 5 5 6 14 5 5", "8 39\n38 17 25 33 7 29 15 22", "15 185\n69 61 185 127 169 42 140 93 12 115 36 46 19 80 123", "15 109\n92 60 14 9 22 99 17 22...
UNKNOWN
PYTHON3
CODEFORCES
16
60834fd7364cc020a919b4ea17ddf492
Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t...
[ "try:\r\n t=int(input())\r\n a=[int(i) for i in input().split()]\r\n c=0\r\n j=[]\r\n for i in range(t):\r\n c=(a[i]-1)*(i+1)+1\r\n j.append(c)\r\n \r\n print(sum(j)) \r\nexcept:\r\n pass", "n = int(input())\r\na = list(map(int,input().split()))\r\ns = 0\r\n\r\nfor i i...
{"inputs": ["2\n1 1", "2\n2 2", "1\n10", "3\n2 4 1", "4\n5 5 3 1", "2\n1000000000 1000000000", "10\n5 7 8 1 10 3 6 4 10 6", "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 ...
UNKNOWN
PYTHON3
CODEFORCES
104
60c6fd01f2a44cd778910c3d04369750
Two Friends
Two neighbours, Alan and Bob, live in the city, where there are three buildings only: a cinema, a shop and the house, where they live. The rest is a big asphalt square. Once they went to the cinema, and the film impressed them so deeply, that when they left the cinema, they did not want to stop discussing it. Bob wa...
[ "#!/usr/bin/env python\n'''\n' Author: Cheng-Shih Wong\n' Email: [email protected]\n' Date: 2017-08-26\n'''\n\ndef main():\n\n import math\n from itertools import combinations, chain\n EPS = 1e-12\n\n def fcomp(x):\n return -1 if x < -EPS else int(x>EPS)\n\n def dist(A, B):\n r...
{"inputs": ["0 2\n0 0\n4 0\n-3 0", "0 0\n0 0\n2 0\n1 0", "0 2\n0 0\n40 0\n-31 1", "100 2\n0 0\n4 0\n-3 0", "2 100\n0 0\n4 0\n-3 0", "0 0\n0 0\n5 0\n10 0", "2 0\n0 0\n5 0\n10 0", "0 2\n0 0\n5 0\n10 0", "0 0\n0 0\n4 0\n4 3", "0 4\n0 0\n4 0\n4 3", "0 3\n0 0\n4 0\n4 3", "1 4\n0 0\n4 0\n4 3", "0 0\n0 0\n100 100\n100 0", "1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
60d12ffdce709d46156de6423c7c6ee1
Intercepted Message
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred...
[ "n, m = map(int, input().split(' '))\r\nx = list(map(int, input().split(' ')))\r\ny = list(map(int, input().split(' ')))\r\n\r\nsumx, sumy = x[0], y[0]\r\nix, iy = 0, 0\r\n\r\nans = 0\r\n\r\nwhile 1:\r\n if sumx == sumy and ix < n - 1 and iy < m - 1:\r\n ix += 1\r\n iy += 1\r\n sumxnew = x[i...
{"inputs": ["7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8", "3 3\n1 10 100\n1 100 10", "1 4\n4\n1 1 1 1", "1 1\n1000000\n1000000", "3 5\n2 2 9\n2 1 4 2 4", "5 3\n1 1 4 1 2\n1 4 4", "30 50\n3 3 1 3 1 2 4 3 4 1 3 2 3 3 2 3 2 1 3 4 2 1 1 3 2 2 1 3 1 60\n4 4 1 2 2 2 3 1 3 2 1 2 4 4 2 1 2 3 1 3 4 4 3 3 4 4 4 1 2 1 3 3 1 1 3 3 4 3 2 3 2...
UNKNOWN
PYTHON3
CODEFORCES
83
6100c1c63131367d738e0408b5f12c9d
Little Elephant and Numbers
The Little Elephant loves numbers. He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations. Help the Little Elephant to find the described num...
[ "x = int(input())\r\nhash = []\r\nfor i in range(10):\r\n hash.append(0)\r\nt = x\r\nwhile t > 0:\r\n hash[t % 10] = 1\r\n t //= 10\r\nans = 0\r\ni = 1\r\nwhile i * i <= x:\r\n if x % i == 0:\r\n t = i\r\n while t > 0 and hash[t % 10] == 0:\r\n t //= 10\r\n if t > 0:\r\n ...
{"inputs": ["1", "10", "47", "100", "128", "2", "17", "1000000", "1000000000", "4584725", "999999999", "9", "3", "4", "20", "24", "48", "2458450", "97648850", "96488450", "879541", "111111111", "222222222", "777777777", "211768200", "536870912", "654885000", "223092870", "901800900", "101871000", "49", "999999993", "99...
UNKNOWN
PYTHON3
CODEFORCES
53
61084951b3b6e5a68f9fc621f812352a
Fake News (easy)
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... The...
[ "def main():\n s = input()\n heidi = \"heidi\"\n\n j = 0\n hasHeidi = 0\n\n for i in s:\n if(i == heidi[j]):\n if(j < 4):\n j += 1\n else:\n hasHeidi = 1\n\n if(hasHeidi == 0):\n print(\"NO\")\n else:\n print(\"YES\")\n\n\...
{"inputs": ["abcheaibcdi", "hiedi", "ihied", "diehi", "deiih", "iheid", "eihdi", "ehdii", "edhii", "deiih", "ehdii", "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswg...
UNKNOWN
PYTHON3
CODEFORCES
330
611d5edf1fac73722d75e675883f655e
Laboratory Work
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value *n* times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: *x*1, *x*2, ..., *x**n*. It is important that the values are clo...
[ "n = int(input())\narr = list(map(int, input().split()))\nmina = min(arr)\nmaxa = max(arr)\nif maxa - mina < 2:\n print(n)\n print(*arr)\n exit()\na, b, c = 0, 0, 0\nfor i in arr:\n if i == mina:\n a += 1\n elif i == maxa:\n c += 1\n else:\n b += 1\nm = max(2 * min(a, c), b //...
{"inputs": ["6\n-1 1 1 0 0 -1", "3\n100 100 101", "7\n-10 -9 -10 -8 -10 -9 -9", "60\n-8536 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8535 -8536 -8536 -8535 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -8536 -...
UNKNOWN
PYTHON3
CODEFORCES
28
61210c098c09d3189bc978f2beecaf95
Hexagons!
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might &amp; Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every...
[ "n=int(input())\r\nc=1+n*(n+1)//2*6\r\nprint(c)\r\n", "n=int(input())\r\nprint((3*n*n)+(3*n)+1)", "n=int(input())\r\nprint((((n+1)*3)*n)+1)", "a=int(input())\r\nprint(1+a*(a+1)//2*6)", "n = int(input())\r\nprint(1 + n * (n + 1) * 3)\n# Sat Aug 05 2023 13:29:16 GMT+0300 (Moscow Standard Time)\n", "a=int(in...
{"inputs": ["2", "0", "1", "3", "749431", "748629743", "945234000", "900000000", "999999999", "1000000000"], "outputs": ["19", "1", "7", "37", "1684942719577", "1681339478558627377", "2680401947103702001", "2430000002700000001", "2999999997000000001", "3000000003000000001"]}
UNKNOWN
PYTHON3
CODEFORCES
21
61331892fdd37295b2e464408bc46a91
Bear and Finding Criminals
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
[ "n, a = map(int, input().split())\r\n\r\na -= 1\r\nl = list(map(int, input().split()))\r\n\r\nans = l[a]\r\n\r\ni, j = a-1, a+1\r\n\r\nwhile i >= 0 and j < n:\r\n if l[i] == 1 and l[j] == 1:\r\n ans += l[i] + l[j]\r\n i -= 1\r\n j += 1\r\nwhile i >= 0:\r\n ans += l[i]\r\n i -= 1\r\nwhile j < n...
{"inputs": ["6 3\n1 1 1 0 1 0", "5 2\n0 0 0 1 0", "1 1\n1", "1 1\n0", "9 3\n1 1 1 1 1 1 1 1 0", "9 5\n1 0 1 0 1 0 1 0 1", "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0", "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1...
UNKNOWN
PYTHON3
CODEFORCES
292
6188ca22b8da96766b5b984e5b443947
Effective Approach
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
[ "# direct access array\r\nn = int(input())\r\nA = tuple(map(int,input().split()))\r\nm = int(input())\r\nB = tuple(map(int,input().split()))\r\n\r\nD_array = [None] * 100001\r\nfor i in range(0, n):\r\n D_array[A[i]] = i + 1\r\n\r\nV, P = 0, 0\r\nfor i in B:\r\n V += D_array[i]\r\n P += n + 1 - D_array[i...
{"inputs": ["2\n1 2\n1\n1", "2\n2 1\n1\n1", "3\n3 1 2\n3\n1 2 3", "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "4\n1 3 2 4\n4\n3 1 2 3", "3\n1 2 3\n8\n3 2 1 1 2 3 1 ...
UNKNOWN
PYTHON3
CODEFORCES
344
618e02f7384cdd19508ebd84ad809d18
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme...
[ "import sys\nimport math\n\ndata = sys.stdin.read().split()\ndata_ptr = 0\n\ndef data_next():\n global data_ptr, data\n data_ptr += 1\n return data[data_ptr - 1]\n\nN = int(data_next())\npre = [0] + list(map(int, data[1::2]))\nnxt = [0] + list(map(int, data[2::2]))\nvis = [False] * (N + 1)\n\ndef find_last...
{"inputs": ["7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "2\n2 0\n0 1", "1\n0 0", "4\n0 2\n1 0\n0 4\n3 0", "5\n0 0\n0 0\n0 0\n0 0\n0 0", "2\n0 0\n0 0", "2\n0 2\n1 0", "5\n5 3\n4 0\n1 4\n3 2\n0 1", "5\n2 0\n0 1\n0 4\n3 5\n4 0", "5\n3 4\n0 0\n0 1\n1 0\n0 0", "5\n3 0\n0 0\n0 1\n0 0\n0 0", "10\n7 5\n5 0\n4 7\n10 3\n1 2\n0 9\n3 ...
UNKNOWN
PYTHON3
CODEFORCES
19
6199397c95c09acba408fadef4aae0c7
Chips
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The pre...
[ "m,n=map(int,input().split())\r\nt=False\r\nwhile not t:\r\n for x in range(m):\r\n if n>=x+1:\r\n n-=x+1\r\n else:\r\n t=True\r\n break\r\nprint(n)", "s = list(map(int, input().split()))\r\nind = 0\r\nwhile(s[1] > 0):\r\n\tif(s[1] < ind+1):\r\n\t\tbreak\r\n\ts[1]...
{"inputs": ["4 11", "17 107", "3 8", "46 7262", "32 6864", "36 6218", "25 9712", "9 7601", "1 9058", "29 7772", "45 9465", "46 866", "29 1241", "17 4248", "20 8082", "50 9555", "4 7455", "36 880", "24 7440", "44 7888", "1 1", "50 10000", "1 10000", "50 1", "50 50"], "outputs": ["0", "2", "1", "35", "0", "14", "11", "5"...
UNKNOWN
PYTHON3
CODEFORCES
517
61f4b3564579a1f7b930cb0ef135aa17
Ilya and Bank Account
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow...
[ "n=str(input())\r\nm = n\r\nif n[0] == '-':\r\n if int(n[-2]) <= int(n[-1]):\r\n m=n[:-1]\r\n else:\r\n m=n[:-2]+n[-1]\r\n m=int(m)\r\nprint(m)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\nx=str(n)\r\nif n<0:\r\...
{"inputs": ["2230", "-10", "-100003", "544883178", "-847251738", "423654797", "-623563697", "645894116", "-384381709", "437587210", "-297534606", "891773002", "-56712976", "963662765", "-272656295", "383441522", "-477665112", "791725034", "-812168727", "528894922", "-479977172", "568044564", "-392784794", "925596634", ...
UNKNOWN
PYTHON3
CODEFORCES
234
620529f2264406c5758083e8026c0720
World Football Cup
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features *n* teams (*n* is always even) - the first *n*<=/<=2 t...
[ "class Info:\r\n def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals):\r\n self.teamName = newTeamName\r\n self.points = newPoints\r\n self.goalDiff = newGoalDiff\r\n self.scoredGoals = newScoredGoals\r\n\r\n def __str__(self):\r\n return f'teamName: \\'{s...
{"inputs": ["4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "2\na\nA\na-A 2:1", "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92", "4\nTeMnHVvWKpwlpubwyhzqvc\nAWJwc\nbhbxErlydiwtoxy\nEVASMeLpfqwjkke\nAWJwc-TeMnHVvWKpwlpubwyhzqvc 37:34\nbhbxErlydiwtoxy-Te...
UNKNOWN
PYTHON3
CODEFORCES
49
622f88a1bbe0ffe4c3d7e4698161b0f0
Magic Matrix
You're given a matrix *A* of size *n*<=×<=*n*. Let's call the matrix with nonnegative elements magic if it is symmetric (so *a**ij*<==<=*a**ji*), *a**ii*<==<=0 and *a**ij*<=≤<=*max*(*a**ik*,<=*a**jk*) for all triples *i*,<=*j*,<=*k*. Note that *i*,<=*j*,<=*k* do not need to be distinct. Determine if the matrix is mag...
[ "from collections import defaultdict, deque\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef get_root(s):\r\n v = []\r\n while not s == root[s]:\r\n v.append(s)\r\n s = root[s]\r\n for i in v:\r\n root[i] = s\r\n return s\r\n\r\ndef un...
{"inputs": ["3\n0 1 2\n1 0 2\n2 2 0", "2\n0 1\n2 3", "4\n0 1 2 3\n1 0 3 4\n2 3 0 5\n3 4 5 0", "5\n0 2 5 9 5\n2 0 5 9 5\n5 5 0 9 4\n9 9 9 0 9\n5 5 4 9 0", "10\n0 16 5 14 14 17 14 14 9 14\n16 0 16 16 16 17 16 16 16 16\n5 16 0 14 14 17 14 14 9 14\n14 16 14 0 7 17 3 8 14 12\n14 16 14 7 0 17 7 8 14 12\n17 17 17 17 17 0 17 1...
UNKNOWN
PYTHON3
CODEFORCES
1
6252b2f7bbb9c359601f5f67e3a97eee
Artsem and Saunders
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*. Now then, you are ...
[ "n = int(input())\nf = [y for y in map(int, input().split())]\n\nim_f = list(set(f))\nok = True\nfor y in im_f:\n index = y - 1\n ok &= f[index] == y\n\nif ok:\n m = len(im_f)\n ind = {}\n for i, y in enumerate(im_f):\n ind[y] = i + 1\n print(m)\n values = []\n for y in f:\n va...
{"inputs": ["3\n1 2 3", "3\n2 2 2", "2\n2 1", "1\n1", "2\n2 1", "2\n2 2", "5\n5 5 5 3 5", "10\n4 4 4 4 4 4 4 4 4 4", "2\n1 2", "3\n3 2 3", "3\n1 2 1", "4\n4 2 4 4", "5\n1 4 5 4 5", "4\n1 2 1 2", "5\n1 3 3 4 4", "4\n4 2 2 4", "7\n7 3 3 5 5 7 7", "6\n1 1 1 3 3 3", "4\n2 2 3 2", "6\n1 2 3 4 5 5", "3\n1 1 2", "4\n3 4 3 4",...
UNKNOWN
PYTHON3
CODEFORCES
20
6254108ea889c419d9f8e2afba6f5ada
Babaei and Birthday Cake
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake. Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has *n* simple cakes and he is going to make a special ...
[ "# [https://codeforces.com/contest/629/submission/32426374]\r\nimport math\r\n\r\nn = int(input())\r\np = [0] * n\r\nfor i in range(n):\r\n (r, h) = map(int, input().split())\r\n p[i] = r**2 * h\r\nk = {v: j for j, v in enumerate(sorted(set(p)))}\r\nd = [0] * (len(k) + 1)\r\nfor v in p: \r\n j = k[v]\r\n ...
{"inputs": ["2\n100 30\n40 10", "4\n1 1\n9 7\n1 4\n10 7", "3\n2 2\n1 1\n3 3", "3\n2 2\n3 3\n1 1", "3\n3 3\n1 1\n2 2", "3\n1 1\n2 2\n3 3", "3\n1 1\n3 3\n2 2", "3\n3 3\n2 2\n1 1", "1\n1 1", "2\n1 1\n2 2", "2\n2 2\n1 1", "4\n1 1\n2 2\n3 3\n4 4", "4\n1 1\n2 2\n4 4\n3 3", "4\n1 1\n3 3\n2 2\n4 4", "4\n1 1\n3 3\n4 4\n2 2", "4...
UNKNOWN
PYTHON3
CODEFORCES
2
626718e6c98f6f2994a519cc90bf888d
Suit and Tie
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the pic...
[ "n=int(input())\r\nlst = list(map(int, input().strip().split(' ')))\r\nc=0\r\nwhile(len(lst)!=0):\r\n p=lst[0]\r\n del lst[0]\r\n i=lst.index(p)\r\n c+=i\r\n del lst[i]\r\nprint(c)\r\n ", "n=int(input())\r\na=list(map(int, input().split()))\r\nans=0\r\nwhile len(a) > 0:\r\n x=a.pop(0)\r\n ...
{"inputs": ["4\n1 1 2 3 3 2 4 4", "3\n1 1 2 2 3 3", "3\n3 1 2 3 1 2", "8\n7 6 2 1 4 3 3 7 2 6 5 1 8 5 8 4", "2\n1 2 1 2", "3\n1 2 3 3 1 2", "38\n26 28 23 34 33 14 38 15 35 36 30 1 19 17 18 28 22 15 9 27 11 16 17 32 7 21 6 8 32 26 33 23 18 4 2 25 29 3 35 8 38 37 31 37 12 25 3 27 16 24 5 20 12 13 29 11 30 22 9 19 2 24 7 ...
UNKNOWN
PYTHON3
CODEFORCES
75
62701aa73b10e5e72bb53185e0b68677
Desk Disorder
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,...
[ "import sys\ninput = sys.stdin.readline\n\nclass DisjointSetUnion:\n def __init__(self, n):\n self.parent = list(range(n))\n self.size = [1] * n\n self.num_sets = n\n\n def find(self, a):\n acopy = a\n while a != self.parent[a]:\n a = self.parent[a]\n while...
{"inputs": ["4\n1 5\n5 2\n3 7\n7 3", "5\n1 10\n2 10\n3 10\n4 10\n5 5", "1\n1 2", "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\n52 55\n55 33\n36 9\n10 9\n9 33\n33 19\n5 23\n47 23\n23 32\n50 44\n26 44\n44 32\n32 19\n19 48", "50\n73 1\n65 73\n16 65\n57 65\...
UNKNOWN
PYTHON3
CODEFORCES
1
6286823ddf5df5be20a2e19ef19da4f1
War of the Corporations
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine...
[ "# Description of the problem can be found at http://codeforces.com/problemset/problem/625/B\r\n\r\nx = input()\r\ns = input()\r\n\r\nprint(x.count(s))", "a = str(input())\r\nb = str(input())\r\nprint(a.count(b))\r\n", "# this is from codeforces problem\r\n\r\nimport re\r\n\r\nstring = input().strip()\r\nsub = ...
{"inputs": ["intellect\ntell", "google\napple", "sirisiri\nsir", "sirisiri\nsiri", "aaaaaaa\naaaa", "bbbbbb\nbb", "abc\nabcabc", "kek\nkekekek", "aaaaa\naaa", "abcdabcv\nabcd", "abcabcabczabcabcabcz\ncab", "aatopotopotopotaa\ntopot", "abcabcabcabcabcabcabcabcabcabc\nabcabcabcabcabcabcabcabcabcabc", "sosossosos\nsos", "...
UNKNOWN
PYTHON3
CODEFORCES
221
629153c9b94fe4c0e94ab1c77e4ac45d
Mad Joe
Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path. Joe's house has *n* floors, each floor is a segment of *m* cells. Each cell either contains nothing (it is an empty cell), or has a brick or a concrete wall (always something one of three). It is believed that ea...
[ "n, m = [int(i) for i in input().split()]\r\ncurrent_floor = list(input())\r\n\r\nx, t, direction = 0, 0, 1\r\n\r\nfor i in range(n-1):\r\n floor = list(input())\r\n l, r = x, x\r\n wall = 0\r\n while True:\r\n t += 1\r\n if floor[x] == '.':\r\n break\r\n if (x + directio...
{"inputs": ["3 5\n..+.#\n#+..+\n+.#+.", "4 10\n...+.##+.+\n+#++..+++#\n++.#++++..\n.+##.++#.+", "2 2\n..\n++", "5 1\n.\n.\n.\n.\n.", "20 20\n..+#+.+++.+++#+..#++\n..####+++#..++#+.+.+\n+.+..+++..#.++++++++\n+##++..+.##..#+++.++\n++.+.+.+.++++.+++.++\n.+++++.+#+++++...+#+\n.+++#+++++++.+.++.++\n...+.++++++.++#...++\n+++...
UNKNOWN
PYTHON3
CODEFORCES
1
629ace22bf13e54cf3019369032e4a31
Buy a Ticket
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well. There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go ...
[ "from sys import stdin, stdout\r\nfrom heapq import heapify,heappop,heappush,heappushpop\r\n \r\nn, m = map(int, stdin.readline().split())\r\n \r\nady = [[] for i in range(n)]\r\n \r\nfor i in range(m):\r\n u,v,w = map(int,stdin.readline().split())\r\n ady[u-1].append((v-1,2*w))\r\n ady[v-1].append((u-1,2*...
{"inputs": ["4 2\n1 2 4\n2 3 7\n6 20 1 25", "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20", "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393"], "outputs": ["6 14 1 25 ", "12 10 12 ", "1 335807 7498159 335769 53373 21385 663675 "]...
UNKNOWN
PYTHON3
CODEFORCES
1
62ca0fdbd9cd503199fb21ff45877182
Day at the Beach
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were *n* castles built by friends. Castles are numbered from 1 to *n*, and the ...
[ "from collections import Counter\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\np=sorted(arr)\r\nans=0\r\nc=Counter()\r\nseen=set()\r\nfor a,b in zip(arr,p):\r\n c[a]+=1\r\n c[b]-=1\r\n if c[a]>0:\r\n seen.add(a)\r\n if c[a]==0 and a in seen:\r\n seen.remove(a)\r\n if c[b]>0...
{"inputs": ["3\n1 2 3", "4\n2 1 3 2", "17\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005", "101\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257 145 199 235 102 146 119 60 109 134 209 260 210 191 180 271 236 195 155 169 166 143 246 102 208 137 278 269 15...
UNKNOWN
PYTHON3
CODEFORCES
16
62fe0ebe0c4ab67b71ccafaf12746b83
The Maths Lecture
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't. First he gave Amr two positive integers *n* and *k*. Then he asked Amr, how many integer numbers *x*<=&gt;<=0 exist such t...
[ "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nimport heapq\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\n \n# M = mod = 998244353\ndef factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in...
{"inputs": ["1 2 1000", "2 2 1000", "5 3 1103", "2 17 10000", "3 9 10000", "6 64 941761822", "183 3 46847167", "472 44 364550669", "510 76 811693420", "783 30 602209107", "863 47 840397713", "422 22 411212542", "370 9 385481464", "312 41 915197716", "261 32 49719977", "434 6 56571287", "355 3 945669623", "905 71 999142...
UNKNOWN
PYTHON3
CODEFORCES
1
6329ead462cbeae7d091ee0822fdf649
Minimum Binary Number
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"...
[ "def solve():\r\n size = input()\r\n s = input()\r\n \r\n print('1' * ('1' in s) + '0' * s.count('0'))\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ", "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\ndef process(S):\r\n if S=='0':\r\n sys.stdout.write('0')\r\...
{"inputs": ["4\n1001", "1\n1", "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "100\n11111111111111111111111111111111111111111111111111111111111111111...
UNKNOWN
PYTHON3
CODEFORCES
260
6345b9b6db25c4c6c108cbbca4514fab
Cheese Board
Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have. The next *N* lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its ty...
[ "from math import *\r\nt = input\r\nn = int(t())\r\na = sum(t()[-4] == 'h' for i in 'i' * n)\r\nprint(ceil(max(max(n - a, a) * 2 - 1, n) ** .5))\r\n", "# LUOGU_RID: 101738955\nfrom math import ceil\r\nn = int(input())\r\na = sum(input()[-4] == 'h' for _ in range(n))\r\nprint(ceil(max(max(n - a, a) * 2 - 1, n) ** ...
{"inputs": ["9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "9\ngorgonzola soft\ncambozola soft\nmascarpone soft\nricotta soft\nmozzarella soft\nbryndza soft\njarl...
UNKNOWN
PYTHON3
CODEFORCES
6
6359aabb4e475d8930450b9c7b8a244e
Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n* in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. ...
[ "# LUOGU_RID: 102443681\nn = int(input())\r\nif n < 3:\r\n print(-1)\r\nelse:\r\n print(*range(n, 0, -1))", "def main_function():\r\n a = int(input())\r\n if a > 2:\r\n return \" \".join([str(a - i) for i in range(a)])\r\n return -1\r\n\r\n\r\n\r\n\r\nprint(main_function())\r\n\r\n", "n=in...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "50", "22", "34", "50", "12", "26", "38", "4", "18", "30", "46", "32"], "outputs": ["-1", "-1", "3 2 1 ", "4 3 2 1 ", "5 4 3 2 1 ", "6 5 4 3 2 1 ", "7 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 ", "9 8 7 6 5 4 3 2 1 ", "50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 ...
UNKNOWN
PYTHON3
CODEFORCES
104
6373123f7aa31b6ad05e108d392f4525
cAPS lOCK
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
[ "inp = input()\r\n\r\nif inp[0]==inp[0].lower() and inp[1:]==inp[1:].upper():\r\n print(inp.title())\r\n\r\nelif inp==inp.upper():\r\n print(inp.lower())\r\n\r\nelse:\r\n print(inp)", "a=str(input())\r\nif a==a.upper() or (a[:1]==a[:1].lower() and a[1:]==a[1:].upper()):\r\n s=\"\"\r\n for i in range(len(...
{"inputs": ["cAPS", "Lock", "cAPSlOCK", "CAPs", "LoCK", "OOPS", "oops", "a", "A", "aA", "Zz", "Az", "zA", "AAA", "AAa", "AaR", "Tdr", "aTF", "fYd", "dsA", "fru", "hYBKF", "XweAR", "mogqx", "eOhEi", "nkdku", "zcnko", "lcccd", "vwmvg", "lvchf", "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVU...
UNKNOWN
PYTHON3
CODEFORCES
185
63797f23a28c31697c3a4221a9c9de1d
LionAge II
Vasya plays the LionAge II. He was bored of playing with a stupid computer, so he installed this popular MMORPG, to fight with his friends. Vasya came up with the name of his character — non-empty string *s*, consisting of a lowercase Latin letters. However, in order not to put up a front of friends, Vasya has decided ...
[ "from math import inf\r\n\r\ns,k= input().split()\r\nk=int(k)\r\ndict=[[0]*26 for i in range(26)]\r\nfor i in range(int(input())):\r\n\r\n\r\n x=input().split()\r\n # print(ord(x[0])-97,ord(x[1])-97)\r\n dict[ord(x[0])-97][ord(x[1])-97]=int(x[2])\r\ndp=[[[-inf]*26 for j in range(k+2)]for i in range(len(s))]...
{"inputs": ["winner 4\n4\ns e 7\no s 8\nl o 13\no o 8", "abcdef 1\n5\na b -10\nb c 5\nc d 5\nd e 5\ne f 5", "akcbd 2\n3\na d 55\nb z 100\nb c 50", "adcbd 1\n3\na d 55\nb z 100\nb c 50", "abcbd 1\n3\na b 55\nb z 100\nb c 50", "vswlx 1\n3\nz l 509\nb i 287\na o 952", "srtlmx 2\n2\ne a -167\nc v -932", "dlcmexn 3\n3\no k ...
UNKNOWN
PYTHON3
CODEFORCES
4
638c7aa6d07a25b3a8293cfb624a5cc6
The Fibonacci Segment
You have array *a*1,<=*a*2,<=...,<=*a**n*. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) is good if *a**i*<==<=*a**i*<=-<=1<=+<=*a**i*<=-<=2, for all *i* (*l*<=+<=2<=≤<=*i*<=≤<=*r*). Let's define *len*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1, *len*([*l*,<=*r*]) is the length of the segment [*l*,<=*r*]. Segment [*l*1,<=*r...
[ "n=int(input())\r\na=list(map(int, input().split()))\r\nm=min(2, n)\r\nk=m\r\nfor i in range(2,n):\r\n if a[i] == a[i-1] + a[i-2]:\r\n k += 1\r\n else:\r\n k = 2\r\n m=max(k,m)\r\nprint(m) ", "n = int(input())\r\nA = [*map(int, input().split())]\r\nk = x = min(n,2)\r\n\r\nfor i in range(n-2...
{"inputs": ["10\n1 2 3 5 8 13 21 34 55 89", "5\n1 1 1 1 1", "1\n1000", "51\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1\n0", "2\n0 0", "3\n0 0 0", "4\n0 0 0 0", "5\n0 0 0 0 0", "6\n10 20 30 10 40 50", "5\n8 9 17 26 43", "12\n1 2 3 5 8 13 0 1 1 2 3 5", "13\n...
UNKNOWN
PYTHON3
CODEFORCES
36
63a39518a14342d2da52a6a26177fe6d
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
[ "n = int(input())\r\nhome = input()\r\nflights = []\r\nbe_in_home = 0\r\nnot_in_home = 0\r\nfor i in range(n):\r\n airport_from, airport_to = map(str, input().split('->'))\r\n flights.append([airport_from, airport_to])\r\n\r\n\r\nfor x in flights:\r\n if x[1] == home:\r\n be_in_home += 1\r\n else:\r\n not...
{"inputs": ["4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "1\nESJ\nESJ->TSJ", "2\nXMR\nFAJ->XMR\nXMR->FAJ", "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ", "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO", "11\nIAU\nIAU->RU...
UNKNOWN
PYTHON3
CODEFORCES
199
63a615e529c016233a0a40824ea99d38
Letter A
Little Petya learns how to write. The teacher gave pupils the task to write the letter *A* on the sheet of paper. It is required to check whether Petya really had written the letter *A*. You are given three segments on the plane. They form the letter *A* if the following conditions hold: - Two segments have common e...
[ "__author__ = 'Darren'\r\n\r\n\r\ndef solve():\r\n t = int(input())\r\n while t:\r\n run()\r\n t -= 1\r\n\r\n\r\ndef run():\r\n def check_condition_1():\r\n record = {}\r\n common, first, second = None, -1, -1\r\n found = False\r\n for i in range(3):\r\n ...
{"inputs": ["3\n4 4 6 0\n4 1 5 2\n4 0 4 4\n0 0 0 6\n0 6 2 -4\n1 1 0 1\n0 0 0 5\n0 5 2 -1\n1 2 0 1"], "outputs": ["YES\nNO\nYES"]}
UNKNOWN
PYTHON3
CODEFORCES
5
63a9cea7d9db70b77cff7f58c487ccdf
Number of Parallelograms
You are given *n* points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of points. Each of the next *n* lines contains two inte...
[ "n = int(input())\na = []\nfor _ in range(n):\n xy = list(map(int, input().split()))\n a.append(xy)\nmidpoint = {}\nfor i in range(n):\n for j in range(i + 1, n):\n x1, y1 = a[i][0], a[i][1]\n x2, y2 = a[j][0], a[j][1]\n dx = x2 + x1\n dy = y2 + y1\n midpoint[(dx / 2, dy ...
{"inputs": ["4\n0 1\n1 0\n1 1\n2 0", "1\n0 0", "1\n6 6", "5\n1 5\n4 2\n4 4\n8 1\n8 2", "10\n1 7\n2 14\n3 7\n3 13\n5 13\n13 10\n15 12\n17 1\n18 8\n19 0", "20\n0 17\n1 8\n1 9\n2 5\n2 11\n3 0\n5 10\n5 13\n6 7\n7 3\n12 13\n13 7\n14 16\n15 10\n15 18\n17 2\n17 12\n18 14\n19 18\n20 17", "2\n2 5\n10 7", "4\n7 9\n10 2\n12 20\n1...
UNKNOWN
PYTHON3
CODEFORCES
14
63b11bb3bcf044f70a1065e2688186d4
Phone Number
Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppos...
[ "import os\r\nimport sys\r\nfrom math import floor, ceil\r\n\r\nif os.getenv('LOCALCFTEST'):\r\n sys.stdin = open('cfinput.txt')\r\nMOD = 998244353\r\n\r\n\r\ndef solve(s):\r\n s = list(map(int, s))\r\n n = len(s)\r\n dp = [[0] * 10 for _ in range(n)]\r\n dp[0] = [1] * 10\r\n flag = True\r\n fo...
{"inputs": ["12345", "09", "3", "55", "737", "21583", "33408349", "0180990956", "433488906230138", "00046142930690780976", "317579445234107659439645596", "95066916647678224147260013920", "36460576924876475371008334246121610", "429622625617508557672595893160462042433748844995", "17601120900014764776764048700928872725171...
UNKNOWN
PYTHON3
CODEFORCES
16
63b7d41690ec122f4af9a2a294f9cc0b
Protect Sheep
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or...
[ "R,C=map(int, input().split())\r\nm=[[str(j) for j in input()] for i in range(R)]\r\nrow=0\r\nfor i in range(R):\r\n if row == 1:\r\n break\r\n for j in range(C):\r\n if m[i][j] == \".\":\r\n m[i][j] = \"D\"\r\n elif m[i][j] == \"S\":\r\n if j > 0 and m[i][j-1] == \"...
{"inputs": ["1 2\nSW", "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S", "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S", "1 50\nW...S..............W.....S..S......
UNKNOWN
PYTHON3
CODEFORCES
268
63bda1d48d73e74b0fb2315f69ff2346
Watering System
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After...
[ "cnt=lambda s,i:s.count(i)\r\nii=lambda:int(input())\r\nsi=lambda:input()\r\nf=lambda:map(int,input().split())\r\nil=lambda:list(map(int,input().split()))\r\nn,a,b=f()\r\nl=il()\r\nsm=sum(l)\r\nk=l.pop(0)\r\nc=0\r\nl.sort(reverse=True)\r\nfor i in range(0,n-1):\r\n if (k*a)/sm<b:\r\n c+=1\r\n sm-=l...
{"inputs": ["4 10 3\n2 2 2 2", "4 80 20\n3 2 1 4", "5 10 10\n1000 1 1 1 1", "10 300 100\n20 1 3 10 8 5 3 6 4 3", "10 300 100\n20 25 68 40 60 37 44 85 23 96", "1 1 1\n1", "1 2 1\n1", "2 2 2\n1 10000", "2 10000 1\n1 9999"], "outputs": ["1", "0", "4", "1", "8", "0", "0", "1", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
183
63cefaf85dc9a9057a96f4a4b3cf46b4
Sereja and Coat Rack
Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one person can hang clothes on one hook. Tonight Sereja expects *m* guests in the restaurant. Naturally, each gu...
[ "n,d=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=int(input())\r\na.sort()\r\nif m==n:\r\n print(sum(a))\r\nif m<n:\r\n print(sum(a[0:m]))\r\nif m>n:\r\n print(sum(a)-d*(m-n))", "n, d = map(int, input().split())\r\nhooks = list(map(int, input().split()))\r\nm = int(input())\r\n\r\nho...
{"inputs": ["2 1\n2 1\n2", "2 1\n2 1\n10", "1 1\n1\n2", "3 96\n83 22 17\n19", "8 4\n27 72 39 70 13 68 100 36\n95", "2 65\n23 34\n74", "2 48\n12 54\n69", "5 30\n63 58 38 60 24\n42", "9 47\n17 36 91 43 89 7 41 43 65\n49", "6 49\n91 30 71 51 7 2\n94", "57 27\n73 51 24 86 57 17 27 58 27 58 38 72 70 62 97 23 18 13 18 97 86 ...
UNKNOWN
PYTHON3
CODEFORCES
15
63fdf4925ed3ccbb06620158f797a41d
Photo to Remember
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangl...
[ "\r\n\r\nn = int(input())\r\n\r\nW = 0\r\npers = []\r\nH1 = 0; H2 = 0\r\nI = 0\r\nfor i in range(n):\r\n w, h = map(int, input().split())\r\n pers.append([w,h])\r\n W += w\r\n\r\n if h > H2:\r\n H2 = h\r\n I = i\r\n\r\nfor i in range(n):\r\n if i == I:\r\n continue\r\n w, h = ...
{"inputs": ["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1", "2\n1 5\n2 3", "2\n2 3\n1 1", "3\n1 10\n2 10\n3 10", "3\n2 10\n1 9\n3 7", "3\n1 1\n3 2\n2 3", "3\n3 123\n1 456\n2 789", "3\n2 987\n3 654\n1 321", "3\n3 143\n2 543\n1 893", "2\n1 1\n1 2", "3\n2 22\n1 11\n2 22", "3\n1 11\n1 12\n1 13", "3\n1 11\n1 12\n2 10", "10\n6 20\...
UNKNOWN
PYTHON3
CODEFORCES
137
641a649f2f8006ce2ac9c06d92bc9009
Vasya and Robot
Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by hi...
[ "#!/usr/bin/python3\n\nimport sys\n\nn, l, r, ql, qr = map(int, sys.stdin.readline().strip().split())\nw = [int(x) for x in sys.stdin.readline().strip().split()]\n\ns = [0]\nfor i in range(0, n):\n s.append(s[-1] + w[i])\n\ndef cost(left):\n right = n - left\n diff = left - right\n bonus = 0\n if dif...
{"inputs": ["3 4 4 19 1\n42 3 99", "4 7 2 3 9\n1 2 3 4", "2 100 100 10000 10000\n100 100", "2 3 4 5 6\n1 2", "1 78 94 369 10000\n93", "1 94 78 369 10000\n93", "5 1 100 1 10000\n1 2 3 4 5", "5 100 1 10000 1\n1 2 3 4 5", "5 1 100 10000 1\n1 2 3 4 5", "5 100 1 1 10000\n1 2 3 4 5", "6 32 47 965 897\n7 4 1 3 5 4", "7 3 13 3...
UNKNOWN
PYTHON3
CODEFORCES
29
643c6163ecab0b811b51f719c5fe56c7
Walking in the Rain
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number *n*. During the walk it is allowed to move...
[ "n=int(input())\nL=list(map(int,input().split()))\ni=0\nsol=[L[0]]\nwhile i+2<len(L)-1:\n if L[i+1]>L[i+2]:\n sol.append(L[i+1])\n i+=1\n else:\n sol.append(L[i+2])\n i+=2\nsol.append(L[len(L)-1])\nprint(min(sol))\n\t\t \t \t \t\t\t \t \t \t\t \t \t \t", "n=int(input())\n...
{"inputs": ["4\n10 3 5 10", "5\n10 2 8 3 5", "10\n10 3 1 6 7 1 3 3 8 1", "10\n26 72 10 52 2 5 61 2 39 64", "100\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 1 5 10 7 6 8 10 2 6 4 4 2 2 10 7 2 7 3 2 6 3 6 4 7 6 2 5 5 8 6 9 5 2 7 5 8 6 5 8 10 6 10 8 5 3 1 10 6 1 7 5 1 8 10 5 1 3 10 7 10 5 7 1 4 3 8 6 3 ...
UNKNOWN
PYTHON3
CODEFORCES
75
646829dd4da9ab53be8b2b48c5fd1b6d
Perfectionist Arkadiy
Arkadiy has lots square photos with size *a*<=×<=*a*. He wants to put some of them on a rectangular wall with size *h*<=×<=*w*. The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside row...
[ "def gcd(n,m):\n if m==0:return n\n else:return gcd(m,n%m)\na,h,w=map(int,input().split())\ng=gcd(a+h,a+w)\ns=(a+w)//g\nt=((w//a+1)//s)*s-1\nif t<=0:print(-1)\nelse:print(\"%.10lf\"%((w-t*a)/(t+1)))", "def gcd(a,b):\n if(b==0):return a;\n else: return gcd(b,a%b);\ndef main():\n a,h,w=map(int,input(...
{"inputs": ["2 18 13", "4 4 4", "3 4 3", "9 81 23", "11 21 21", "55 178 996", "8 81 60", "3 1000000000 1000000000", "1000000000 1000000000 1000000000", "1 1000000000 1000000000", "6 1000000000 1000000000", "6 1000000000 956431324", "546 182989 371991", "45 654489 357075", "97259 999895180 999895180", "453145 999531525 ...
UNKNOWN
PYTHON3
CODEFORCES
7
64708c20e20886405273495cf8cb8aa5
Marco and GCD Sequence
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length *n*, but forgot the exact sequence. Let the elements of the sequence ...
[ "n=int(input());\r\ns=list(map(int,input().split()));\r\np=s[0];\r\nfor i in s:\r\n if(i%p): \r\n print(-1);\r\n exit(0);\r\nans=[];\r\nfor i in s:\r\n ans+=[i,p];\r\nprint(len(ans));\r\nprint(*ans);", "n=int(input())\na=list(map(int,input().split()))\nfor i in range(1,n):\n if a[i]%a[0]:ex...
{"inputs": ["4\n2 4 6 12", "2\n2 3", "2\n1 6", "3\n1 2 7", "1\n1", "2\n1 10", "3\n1 2 6", "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "14\n1 2 3 4 5 6 7 8 9 10 11 12 13 14", "5\n2 5 6 7 11", "11\n3 4 5 6 7 8 9 10 11 12 13", "3\n4 9 11", "6\n5 6 9 11 14 16", "12\n8 9 10 11 12 13 14 15 16 17 18 19", "3\n1007 397765 414884...
UNKNOWN
PYTHON3
CODEFORCES
10
6489c934b00a49add0189bfd59b6168f
Bear and Company
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string *s*...
[ "# http://codeforces.com/contest/771/problem/D\n\"\"\"\nDP-solution.\n\nFor each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x\naxes and check that\ndp[future_state] = min(dp[future_state], dp[state] + cost_of_move)\nHence this implicitly reults in the one with least cost.\n\nV, K, X are ar...
{"inputs": ["4\nVKVK", "5\nBVVKV", "7\nVVKEVKK", "20\nVKVKVVVKVOVKVQKKKVVK", "5\nLIMAK", "1\nV", "1\nK", "1\nZ", "17\nVAKVAKLIMAKVVVKKK", "10\nVVKAVZVAAZ", "17\nQZVRZKDKMZZAKKZVA", "51\nAVVVVVVVVVVKKKKKKKKKKVVVVVVVVVVVVVVVKKKKKKKKKKKKKKK", "75\nVFZVZRVZAZJAKAZKAVVKZKVHZZZZAVAAKKAADKNAKRFKAAAZKZVAKAAAJAVKYAAZAKAVKASZAAK...
UNKNOWN
PYTHON3
CODEFORCES
2
648ebdda98e828fc28e38a9a29ff5be5
QAQ
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
[ "t = list(input())\n\nq_inds = [i for i, x in enumerate(t) if x == \"Q\"]\na_inds = [i for i, x in enumerate(t) if x == \"A\"]\n\nans = 0\nfor i, qi in enumerate(q_inds):\n for ai in a_inds:\n if qi < ai:\n for qi_2 in q_inds[i+1:]:\n if ai < qi_2:\n ans += 1\n...
{"inputs": ["QAQAQYSYIOIWIN", "QAQQQZZYNOIWIN", "QA", "IAQVAQZLQBQVQFTQQQADAQJA", "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",...
UNKNOWN
PYTHON3
CODEFORCES
821
649a7547be14ae924e629e397bbeab07
Polo the Penguin and XOR operation
Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to *n*, inclusive. For permutation *p*<==<=*p*0,<=*p*1,<=...,<=*p**n*, Polo has defined its beauty — number . Expression means applying the operation of bitwise excluding "OR" to numbers *x* and *y*. This operation exist...
[ "import sys\r\nfrom collections import defaultdict\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nl = []\r\nfor i in range(21):\r\n l.append((1 << i)-1)\r\n\r\n\r\ndef up(key):\r\n for i in range(21):\r\n if (key <= l[i]):\r\n return l[i]\r\n\r\n\r\nans = []\r\nd = defaultdict(int)\r\n...
{"inputs": ["4", "7", "1", "2", "3", "8", "10", "47", "74", "99", "128", "257", "1000000", "77845", "100000", "100001", "999999", "777777", "687500", "17", "18", "19", "20", "4587", "15475", "68450", "6100", "1047", "670041", "875495", "687548", "154781", "684501", "754810", "987548", "348754", "20", "11", "12", "13", ...
UNKNOWN
PYTHON3
CODEFORCES
6
649aa1e191c627b051eaf6aa75a8fc29
Buy a Shovel
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
[ "inp = input().split()\r\ninp = [int(x) for x in inp]\r\na=0\r\nfor i in range(15):\r\n if(i>0):\r\n if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# :\r\n a=i\r\n break\r\nprint(a)", "l = input()\r\nlist1 = l.split(\" \...
{"inputs": ["117 3", "237 7", "15 2", "1 1", "1 9", "1000 3", "1000 1", "1000 9", "1 2", "999 9", "999 8", "105 6", "403 9", "546 4", "228 9", "57 2", "437 9", "997 6", "109 1", "998 9", "4 2", "9 3", "8 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "100 3", "1000 2", "1000 4", "1000 5", "1000 6", "1000 7", "1000 8", "...
UNKNOWN
PYTHON3
CODEFORCES
657
64ae99b2640743d28b6f1af4965bdc8b
Petya and Divisors
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given *n* queries in the form "*x**i* *y**i*". For each query Petya should count how many divisors of number *x**i* divide none of the numbers *x**i*<=-<=*y**i*,<=*x**i*<=-<=*y**i*<=+<=1,<=...,<=*x**i*<=-<=1. Hel...
[ "def R(): return map(int, input().split())\r\ndef I(): return int(input())\r\ndef S(): return str(input())\r\n\r\ndef L(): return list(R())\r\n\r\nfrom collections import Counter \r\n\r\nimport math\r\nimport sys\r\n\r\nfrom itertools import permutations\r\n\r\n\r\nimport bisect\r\n\r\ndiv=[[] for i in range(10**5+...
{"inputs": ["6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3", "5\n10 0\n10 0\n10 0\n10 0\n10 0", "12\n41684 0\n95210 1\n60053 1\n32438 3\n97956 1\n21785 2\n14594 6\n17170 4\n93937 6\n70764 5\n13695 4\n14552 6", "10\n54972 0\n48015 1\n7114 1\n68273 2\n53650 4\n1716 1\n16165 2\n96062 5\n57750 1\n21071 5", "20\n68260 0\n819 1\n5417...
UNKNOWN
PYTHON3
CODEFORCES
8
64af1d01e5de4d00253448efa8270fac
Round Table Knights
There are *n* knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knight...
[ "import sys\nimport math\n\nN = int(sys.stdin.readline().strip())\nmoods = sys.stdin.readline().strip().split()\n\ndef check(N, moods):\n regular = False\n for k in range(3,(N+1)):\n if N%k==0:\n regular = True\n for start in range(0,int(N/k)):\n regular = True\n ...
{"inputs": ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1", "10\n1 0 1 1 1 0 1 0 1 0", "15\n0 0 0 1 0 1 1 0 1 0 0 1 0 1 0", "29\n0 1 0 0 0 1 1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 0 0 1 1 1", "77\n0 1 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 ...
UNKNOWN
PYTHON3
CODEFORCES
4
653c4a2ac6666e63908c505220e30beb
Making a String
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ...
[ "#!/usr/bin/env python3\n\nif __name__ == '__main__':\n N = int(input())\n a = list(map(int, input().split()))\n\n res = 0\n used = set()\n for c in sorted(a, reverse=True):\n while c and c in used:\n c -= 1\n if c:\n used.add(c)\n res += c\n print(re...
{"inputs": ["3\n2 5 5", "3\n1 1 2", "2\n1 1", "3\n1 1000000000 2", "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000...
UNKNOWN
PYTHON3
CODEFORCES
109
6541177a52b00070ad9dd4343e4db7c8
An impassioned circulation of affection
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* fro...
[ "import sys, functools, bisect, collections, string, math\r\nfrom math import gcd\r\ninput = sys.stdin.readline\r\n\r\nrs = lambda: input().strip()\r\nri = lambda: int(input())\r\nrmi = lambda: map(int, input().split())\r\nra = lambda: [int(x) for x in input().split()]\r\n\r\nINF = 10**18\r\nMOD = 10**9+7\r\nN =...
{"inputs": ["6\nkoyomi\n3\n1 o\n4 o\n4 m", "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b", "10\naaaaaaaaaa\n2\n10 b\n10 z", "1\nc\n4\n1 x\n1 a\n1 e\n1 t", "20\naaaaaaaaaaaaaaaaaaaa\n1\n11 a", "4\ncbcc\n12\n4 b\n4 c\n1 b\n2 a\n3 b\n2 c\n4 a\n1 a\n2 b\n3 a\n1 c\n3 c", "4\nddbb\n16\n3 c\n3 b\n...
UNKNOWN
PYTHON3
CODEFORCES
16
65412f3683283e2c511a4c7a01346395
Memory and Trident
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move...
[ "def main():\r\n s = input()\r\n if len(s) % 2 == 1:\r\n print('-1')\r\n return\r\n\r\n cnt = {'L':0,'R':0,'U':0,'D':0}\r\n for c in s:\r\n cnt[c] += 1\r\n \r\n reduce1 = abs(cnt['L'] - cnt['R'])\r\n reduce2 = abs(cnt['U'] - cnt['D'])\r\n print((reduce1 + reduce2) // 2)\...
{"inputs": ["RRU", "UDUR", "RUUR", "DDDD", "RRRR", "RRRUUD", "UDURLRDURLRD", "RLRU", "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDULRURRDDDLLUDRLUDDLDDDRRDDDULLLLDLDRLRRLRRDDRLULURRUDRDUUUULDURUDRDLDDUDUDRRURDULRRUDRLRRDL...
UNKNOWN
PYTHON3
CODEFORCES
164
6558f3871d816257c05bb8862dc490d2
Nastya and a Wardrobe
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with ...
[ "MOD = 10**9 + 7\n\ndef fast_power(b, k):\n if k == 1:\n return b\n if k == 0:\n return 1\n\n hk = k // 2\n half = fast_power(b, hk)\n\n if k % 2 == 0:\n return (half * half) % MOD\n else:\n return (half * half * b) % MOD\n\ndef mod_inv(a, m):\n return fast_power(a, ...
{"inputs": ["2 0", "2 1", "3 2", "1 411", "1 692", "16 8", "18 12", "1 1000000000000000000", "0 24", "24 0", "1000000000000000000 1", "348612312017571993 87570063840727716", "314647997243943415 107188213956410843", "375000003 2", "451 938", "4 1669", "24 347", "1619 1813", "280 472", "1271 237", "626 560", "167 887", "...
UNKNOWN
PYTHON3
CODEFORCES
29
65627e8c97269b0e4c8570613a86125c
Large Bouquets
A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a lar...
[ "n = int(input())\r\narr = (map(int, input().split()))\r\nres = 0\r\nfor x in arr:\r\n res = res + x % 2\r\n \r\nfinalres = min(n - res, res)\r\nres = res - finalres\r\nfinalres = finalres + res // 3\r\nprint(finalres)", "n = int(input())\r\ns = list(map(int, input().split()))\r\n\r\noddd = 0\r\nevend = 0\r...
{"inputs": ["5\n2 3 4 2 7", "6\n2 2 6 8 6 12", "3\n11 4 10", "1\n1", "1\n2", "1\n999999", "1\n1000000", "4\n943543 151729 379602 589828", "2\n468463 62253", "3\n352987 849349 967007", "20\n274039 899325 798709 157662 963297 276599 529230 80095 252956 980560 358150 82383 29856 901568 123794 275349 512273 508369 120076 1...
UNKNOWN
PYTHON3
CODEFORCES
61
6591fe9909df35ca605beeb5672d0d91
Symmetric and Transitive
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation. A set ρ of pairs (*a*,<=*b*) of elem...
[ "sym_trans = [1, 3, 10, 37, 151, 674, 3263, 17007, 94828, 562595, 3535027, 23430840, 163254885, 192059216, 97183539, 384727153, 211932162, 665362848, 415709078, 654959364, 894067657, 839120000, 627072923, 586774033, 440165789, 840647542, 118441546, 505992682, 607243387, 93527420, 378847836, 948139661, 770183251, 36...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "42", "2000", "4000", "2345", "2500", "2780", "2999", "3000", "20", "76", "133", "345", "555", "666", "777", "999", "1234", "1730", "3333", "3555", "3789", "3999"], "outputs": ["1", "3", "10", "37", "151", "674", "3263", "17007", "94828", "562595", "7381865...
UNKNOWN
PYTHON3
CODEFORCES
6
65a515ded91844bec4018832113063e5
Video Cards
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are *n* video cards in the shop, the power of the *i*-th video card is equal t...
[ "from bisect import bisect_left\r\n\r\nn = int(input())\r\na = sorted(list(map(int, input().split())))\r\nans = 0\r\nfor k in set(a):\r\n r = sum(n - bisect_left(a, j) for j in range(k, a[-1] + 1, k))\r\n ans = max(ans, k * r)\r\nprint(ans)", "import sys\r\nfrom itertools import accumulate\r\n\r\ndef main():\r\...
{"inputs": ["4\n3 2 15 9", "4\n8 2 2 7", "1\n1", "1\n123819", "10\n9 6 8 5 5 2 8 9 2 2", "100\n17 23 71 25 50 71 85 46 78 72 89 26 23 70 40 59 23 43 86 81 70 89 92 98 85 88 16 10 26 91 61 58 23 13 75 39 48 15 73 79 59 29 48 32 45 44 25 37 58 54 45 67 27 77 20 64 95 41 80 53 69 24 38 97 59 94 50 88 92 47 95 31 66 48 48 ...
UNKNOWN
PYTHON3
CODEFORCES
2
65e7b8d199c55a9034c457643be6e021
Help Kingdom of Far Far Away 2
For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operatio...
[ "s=input().rstrip()\r\nif '.' in s:\r\n neg=0\r\n if '-' in s:\r\n neg=1\r\n s=[s[i] for i in range(1,len(s))]\r\n s=''.join(s)\r\n b=s.split('.')\r\n \r\n if len(b[1])==1:\r\n postfix=b[1]+'0'\r\n else:\r\n postfix=b[1][0:2]\r\n prefix=''\r\n y=0\r\n\r\n ...
{"inputs": ["2012", "0.000", "-0.00987654321", "-12345678.9", "0.99999999999999999999", "-999999999.9999999999", "4.30", "-3136", "47.849", "0", "-1", "5.3944", "-359789", "-999999", "50117.75", "-2717.859", "446900763", "-92.04295", "1000000000", "-4097961.5", "-83348637.91", "741968647.01", "8590210736.2", "-33732263...
UNKNOWN
PYTHON3
CODEFORCES
55
65f128e7e76e33b5ae2e810771d106aa
Alice, Bob, Two Teams
Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are *n* pieces, and the *i*-th piece has a strength *p**i*. The way to split up game pieces is split into several steps: 1. First, Alice will split the pieces into two different groups *A* and *B*. This can be seen as ...
[ "n, p = int( input() ) + 1, [0] + list( map( int, input().split() ) )\ns = '_' + input()\nans = sum( p[i] for i in range(n) if s[i] == 'B' )\nf1 = [0]\nfor i in range(1, n):\n f1.append(f1[-1] + ( 0 if s[i] == 'A' else p[i] ))\nf1 += [0]\nf2 = [0]\nfor i in reversed(range(1, n)):\n f2.append(f2[-1] + ( 0 if s...
{"inputs": ["5\n1 2 3 4 5\nABABA", "5\n1 2 3 4 5\nAAAAA", "1\n1\nB", "10\n1 9 7 6 2 4 7 8 1 3\nABBABAABBB", "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 43...
UNKNOWN
PYTHON3
CODEFORCES
68
6647d15d8b35c41ac84591549e47957e
Guess the Tree
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that - each i...
[ "def DFS(x):\n\n for i in range(x):\n\n if(Seen[i][x]):\n\n continue\n\n if(Rem[i]>=C[x]):\n\n if(Rem[i]==C[x] and len(Children[i])==0):\n\n continue\n\n Rem[i]-=C[x]\n\n Parent[x]=i\n\n Children[i].append(x)\n\n retur...
{"inputs": ["4\n1 1 1 4", "5\n1 1 5 2 1", "13\n1 1 1 1 1 1 1 1 1 4 4 4 13", "4\n1 1 1 3", "24\n1 1 1 1 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 1", "24\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24", "10\n1 1 1 1 7 1 1 1 4 10", "24\n1 1 3 1 1 10 2 9 13 1 8 1 4 1 3 24 1 1 1 1 4 1 3 1", "24\n2 3 20 1 4 9 ...
UNKNOWN
PYTHON3
CODEFORCES
1
6672c1b44ded24c3820de2d7af58959a
Read Time
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In t...
[ "# Read Time\r\nimport sys\r\ninput = sys.stdin.buffer.readline\r\n\r\nn, m = map(int, input().split())\r\n\r\nh = list(map(int, input().split()))\r\n\r\np = list(map(int, input().split()))\r\n\r\n# minimmum time for h_i to cover all p_s...p_e\r\ndef min_t(h_i, p_s, p_e):\r\n return min(abs(h[h_i]-p[p_s]),abs(h[...
{"inputs": ["3 4\n2 5 6\n1 3 6 8", "3 3\n1 2 3\n1 2 3", "1 2\n165\n142 200", "1 2\n5000000000\n1 10000000000", "2 4\n3 12\n1 7 8 14", "3 3\n1 2 3\n2 3 4", "2 1\n1 10\n9", "3 19\n7 10 13\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19", "3 3\n2 3 4\n1 3 5", "10 11\n1 909090909 1818181817 2727272725 3636363633 454545454...
UNKNOWN
PYTHON3
CODEFORCES
4
669ea39a865cf70eb2919884abde7dbd
Capture Valerian
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran. Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu...
[ "numbers = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17,'I':18,'J':19,'K':20,'L':21,'M':22,'N':23,'O':24,'P':25,'Q':26,'R':27,'S':28,'T':29,'U':30,'V':31,'W':32,'X':33,'Y':34,'Z':35}\r\ncharacters = {0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:...
{"inputs": ["10 2\n1", "16 R\n5", "5 R\n4", "2 2\n1111001", "12 13\nA", "6 7\n12345", "25 12\nABG", "17 10\nABACG", "18 R\nGH", "20 25\n4E32BB21D812", "15 11\n760595A635B24", "10 22\n956512026633000", "5 9\n1102101401441324123301", "23 4\nDL5K6H78CAH", "18 R\n36E", "13 2\n1B579528314B30", "8 13\n20043013541570572", "19...
UNKNOWN
PYTHON3
CODEFORCES
6
66a7f66baf08ce934bace8df2aaf42ee
Convenient For Everybody
In distant future on Earth day lasts for *n* hours and that's why there are *n* timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to *n* are used, i.e. there is no time "0 hours", instead of it "*n* hours" is used. When local time in the 1-st timezone is 1 ...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\na+=a\r\ns,f=map(int,input().split())\r\nd=f-s\r\nx=sum(a[:d])\r\nMAX=x\r\nans_time=s\r\ntime=s\r\nfor i in range(d,2*n):\r\n if i-d>=n:\r\n break\r\n x+=a[i]\r\n x-=a[i-d]\r\n time=(time+n-1)%n or n\r\n if MAX<x or (MAX==x and time<ans_time):\r\n MAX...
{"inputs": ["3\n1 2 3\n1 3", "5\n1 2 3 4 1\n1 3", "2\n5072 8422\n1 2", "10\n7171 2280 6982 9126 9490 2598 569 6744 5754 1855\n7 9", "10\n5827 8450 8288 5592 6627 8234 3557 7568 4607 6949\n2 10", "50\n2847 339 1433 128 5933 4805 4277 5697 2574 9638 6992 5045 2254 7675 7503 3802 4012 1388 5307 3652 4764 214 9507 1832 118...
UNKNOWN
PYTHON3
CODEFORCES
6
66b208b49de57d1fc0d9b8aaf388e993
Mishka and Game
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined....
[ "n=int(input())\r\nx=0\r\ny=0\r\nz=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if(a>b):\r\n x=x+1\r\n elif(a<b):\r\n y=y+1\r\n elif(a==b):\r\n z=z+1\r\nif(x>y):\r\n print(\"Mishka\")\r\nelif(x<y):\r\n print(\"Chris\")\r\nelif(x==y or z>0):\r\n print(\"Frien...
{"inputs": ["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2", "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5", "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5", "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3", "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6", "9\n1 2\n1 2\n1 2\n1 2\n1 2\...
UNKNOWN
PYTHON3
CODEFORCES
584
66cf8d18e9b93800181475f578cb87e7
Chord
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft...
[ "lt = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A' ,'B', 'H']\r\nmajor = [[4,3], [3,5], [5,4]]\r\nminor = [[3,4], [4,5], [5,3]]\r\n\r\nx,y,z = input().split()\r\nind = [lt.index(p) for p in (x,y,z)]\r\nind.sort()\r\ndiff = [ind[1]-ind[0], ind[2]-ind[1]]\r\nif diff in major:\r\n print('major')\r\nelif di...
{"inputs": ["C E G", "C# B F", "A B H", "G H E", "D# B G", "D# B F#", "F H E", "B F# G", "F# H C", "C# F C", "G# C# E", "D# H G#", "C F A", "H E G#", "G D# B", "E C G", "G# C# F", "D# C G#", "C# F B", "D# C G", "A D F", "F# H D", "D A F", "D A F#", "C# B F", "A C F", "D F# H", "H G# D#", "A D F#", "H E G#", "D# B F#", ...
UNKNOWN
PYTHON3
CODEFORCES
67
66de36ca55f972fc8a934ebd5e9c909e
Least Cost Bracket Sequence
This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequenc...
[ "s=[]\r\ncost,pre,pq=0,0,[]\r\nfrom heapq import heappop, heappush\r\nfor i, c in enumerate(input()):\r\n\tif c=='?':\r\n\t\tc=')'\r\n\t\tx,y=map(int,input().split())\r\n\t\tcost+=y\r\n\t\theappush(pq, (x-y,i))\r\n\ts.append(c)\r\n\tif c=='(': pre+=1\r\n\telse:\r\n\t\tif pre==0:\r\n\t\t\tif not pq:\r\n\t\t\t\tpre=-...
{"inputs": ["(??)\n1 2\n2 8", "??\n1 1\n1 1", "(???\n1 1\n1 1\n1 1", "(??)\n2 1\n1 1", "(???)?\n3 3\n3 1\n3 3\n2 3", "((????\n3 2\n3 2\n1 1\n2 3", "???())\n2 4\n3 3\n4 1", "((????\n3 5\n4 1\n2 2\n1 5", "?(?)(???\n2 3\n2 2\n3 2\n3 1\n3 1", "(??????)\n1 1\n3 3\n3 3\n3 2\n1 3\n3 3", "?????)??\n2 3\n2 1\n1 3\n5 1\n3 3\n1 3...
UNKNOWN
PYTHON3
CODEFORCES
9
6723baca5db7b202f4866cca6b94ad57
Cubes
Let's imagine that you're playing the following simple computer game. The screen displays *n* lined-up cubes. Each cube is painted one of *m* colors. You are allowed to delete not more than *k* cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are clos...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nx = [[] for _ in range(m + 1)]\r\nfor i in range(n):\r\n x[a[i]].append(i)\r\nans = 0\r\nfor y in x:\r\n if not y:\r\n continue\r\n ...
{"inputs": ["10 3 2\n1 2 1 1 3 2 1 1 2 2", "10 2 2\n1 2 1 2 1 1 2 1 1 2", "3 1 2\n1 1 1", "10 2 2\n1 1 1 2 1 2 1 2 1 1", "1 1 0\n1", "20 3 5\n2 2 3 1 2 2 3 3 3 2 1 2 3 1 1 3 3 3 2 3", "20 2 5\n2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1", "20 6 3\n4 1 2 6 3 3 2 5 2 5 2 1 1 4 1 2 2 1 1 4", "30 5 8\n1 4 1 5 3 4 4 1 1 4 1 3 5...
UNKNOWN
PYTHON3
CODEFORCES
6
672869e84817a94bff50a4be90966cd2
Continued Fractions
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator ...
[ "from fractions import gcd\np,q=map(int,input().split())\ngc=gcd(p,q)\np//=gc\nq//=gc\nn=int(input())\na=list(map(int,input().split()))\ndef add(a,b):\n res=[]\n a[0]*=b[1]\n b[0]*=a[1]\n temp=b[1]*a[1]\n top=a[0]+b[0]\n gc=gcd(top,temp)\n temp//=gc\n top//=gc;\n res.append(top)\n res....
{"inputs": ["9 4\n2\n2 4", "9 4\n3\n2 3 1", "9 4\n3\n1 2 4", "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4", "61305790721611591 37889062373143906\n80\n1 1 1 1 1 1 1 1 1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
65
67347f3321f7532c4e1985451bfacafe
Boredom
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
[ "n = int(input())\r\nread = list(map(int, input().split()))\r\nread.sort()\r\ncount = {}\r\nexist = set()\r\npoints = [[0] * 100001 for i in range(0, 2)]\r\nfor i in range(0, n):\r\n if not read[i] in count:\r\n count[read[i]] = 1\r\n exist.add(read[i])\r\n else:\r\n count[read[i]] += 1\r...
{"inputs": ["2\n1 2", "3\n1 2 3", "9\n1 2 1 3 2 2 2 2 3", "5\n3 3 4 5 4", "5\n5 3 5 3 4", "5\n4 2 3 2 5", "10\n10 5 8 9 5 6 8 7 2 8", "10\n1 1 1 1 1 1 2 3 4 4", "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 ...
UNKNOWN
PYTHON3
CODEFORCES
359
6735696886855248ebfe10fd886b0fa1
Draw Brackets!
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular. Draw the given sequence using a minimalistic pseud...
[ "input()\r\ns = input()\r\n\r\nh, y = [], 0\r\nfor q in s:\r\n h.append(y)\r\n y += 2 * (q == '[') - 1\r\nm = 1 + 2 * max(h)\r\n\r\nf = lambda y: '+'.join((' ' * y, '|' * (m - 2 * y - 2), ' ' * y))\r\ng = lambda i, y: [f(y)] if s[i] == '[' else ([' ' * m] * 3 if s[i - 1] == '[' else []) + [f(y - 1)]\r\n\r\nfo...
{"inputs": ["8\n[[][]][]", "6\n[[[]]]", "6\n[[][]]", "2\n[]", "4\n[][]", "4\n[[]]", "6\n[][][]", "6\n[][[]]", "6\n[[]][]", "100\n[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "100\n[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]...
UNKNOWN
PYTHON3
CODEFORCES
3
673feee697cb87c2999a30d43e4b7045
Naming Company
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor ...
[ "a = sorted(input())\r\nb = sorted(input(), reverse=True)\r\nn = len(a)\r\na = ''.join(a[:(n+1)//2])\r\nb = ''.join(b[:n//2])\r\nname = ['']*(len(a)+len(b))\r\n\r\nia = ib = ic = 0\r\nja = len(a)-1\r\njb = len(b)-1\r\njc = len(name)-1\r\nturn = 1\r\nwhile ic <= jc:\r\n if turn == 1:\r\n if ib > jb: name[i...
{"inputs": ["tinkoff\nzscoder", "xxxxxx\nxxxxxx", "ioi\nimo", "abc\naaa", "reddit\nabcdef", "cbxz\naaaa", "bcdef\nabbbc", "z\ny", "y\nz"], "outputs": ["fzfsirk", "xxxxxx", "ioi", "aab", "dfdeed", "abac", "bccdb", "z", "y"]}
UNKNOWN
PYTHON3
CODEFORCES
15
6747cd9adcb28234b54adeac8c2d3729
Corporation Mail
The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows: - *employee* ::= *name*. | *name*:*employee*1,*employee*2, ... ,*employee**k*. - *name* ::= name of an employee That is, the description of each employee consists o...
[ "#!/usr/bin/env python3 \r\n\r\ntree = input().strip()\r\n\r\ndef get_answer(tree, start_index = 0, prev = []):\r\n colon_index = tree.find(':', start_index)\r\n period_index = tree.find('.', start_index)\r\n name_end_index = colon_index if ((colon_index != -1) and (colon_index < period_index)) else period_index...
{"inputs": ["A:A..", "CK:CK.,CK.,CK..", "RHLGWEVBJ:KAWUINWEI:KAWUINWEI..,ZQATMW.,KAWUINWEI.,RSWN..", "GIRRY.", "XGB:QJNGARRAZV:DWGDCCU:ARDKJV:P:MXBLZKLPYI:FKSBDQVXH:FKSBDQVXH:MXBLZKLPYI..,DWGDCCU..,P...,FKSBDQVXH....,ARDKJV..", "BZSBQVEUZK:GW:IJXBZZR:Q:TTTUZKB:IJXBZZR..,KPMRUKBRJ.,DJJTU..,DJJTU..,SFMVKQPXS.,TTTUZKB:AE....
UNKNOWN
PYTHON3
CODEFORCES
8
674b04517890642f598b058b223c1c1c
A Problem about Polyline
There is a polyline going through points (0,<=0)<=–<=(*x*,<=*x*)<=–<=(2*x*,<=0)<=–<=(3*x*,<=*x*)<=–<=(4*x*,<=0)<=–<=...<=-<=(2*kx*,<=0)<=–<=(2*kx*<=+<=*x*,<=*x*)<=–<=.... We know that the polyline passes through the point (*a*,<=*b*). Find minimum positive value *x* such that it is true or determine that there is no ...
[ "from sys import stdin, stdout\r\n\r\nint_in = lambda: int(stdin.readline())\r\narr_in = lambda: [int(x) for x in stdin.readline().split()]\r\nmat_in = lambda rows: [arr_in() for _ in range(rows)]\r\nstr_in = lambda: stdin.readline().strip()\r\nout = lambda o: stdout.write(\"{}\\n\".format(o))\r\narr_out = lambda o...
{"inputs": ["3 1", "1 3", "4 1", "1000000000 1000000000", "1000000000 1", "991691248 43166756", "973970808 679365826", "404878182 80324806", "405262931 391908625", "758323881 37209930", "405647680 36668977", "750322953 61458580", "406032429 31993512", "1000000000 111111111", "999999999 111111111", "999999998 111111111"...
UNKNOWN
PYTHON3
CODEFORCES
31
6757acaebc046655e71b78e491135cbb
Olympiad
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least *x* points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances....
[ "from sys import stdin,stdout\r\nimport bisect as bs\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor _ in range(1):#nmbr()):\r\n n,sm=lst()\r\n a=sorted(lst(),reverse=1)\r\n b=sorted(lst())\r\n used=-1\r\n rank=1\r\n # print(a)\r\n # print...
{"inputs": ["5 2\n1 1 1 1 1\n1 1 1 1 1", "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4", "1 100\n56\n44", "5 1\n1 2 3 4 5\n1 2 3 4 5", "5 5\n2 2 2 2 2\n3 3 3 3 3", "4 100\n98 98 99 100\n1 1 2 2", "5 45\n1 2 3 4 5\n10 20 30 40 50", "10 5\n3 1 1 2 1 3 1 1 2 3\n2 1 3 2 1 3 3 3 3 1", "10 0\n3 3 1 1 1 2 3 0 0 3\n1 3 0 1 2 0 3 3 0 0", "10 ...
UNKNOWN
PYTHON3
CODEFORCES
3
6758ce3610d53f6a3784f8efd8e06410
Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the *m* Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by *n* Berland students. There were at least two schoolboys participating from each of th...
[ "import operator\r\n\r\nclass Participant:\r\n\tdef __init__(self,name,point):\r\n\t\tself.name=name\r\n\t\tself.point=point\r\n\r\nn,m=map(int,input().split())\r\ndes=[None]*m\r\nfor i in range(m):\r\n\tdes[i]=[]\r\nfor i in range(n):\r\n\tname,region,point=input().split()\r\n\tdes[int(region)-1].append(Participan...
{"inputs": ["5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503", "5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503", "10 2\nSHiBIEz 2 628\nXxwaAxB 1 190\nXwR 2 290\nRKjOf 2 551\nTUP 1 333\nFarsFvyH 1 208\nCGDYnq 1 482\nqaM 2 267\nVfiLunRz 1 416\nuVMHLk 2 754", "10 ...
UNKNOWN
PYTHON3
CODEFORCES
17
675f42df09900c5ecbac9bbbc4961e7a
Merge Sort
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=&lt;<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+...
[ "n, m = list(map(int, input().split()))\n \nsolucao = []\n \ndef merge(inicio, fim, rem):\n\tif rem < 2:\n\t\tsolucao.extend(range(inicio, fim))\n\t\treturn rem\n\tif fim - inicio == 1:\n\t\tsolucao.append(inicio)\n\t\treturn rem\n\trem -= 2\n\tmid = (inicio + fim + 1)//2\n\trem = merge(mid, fim, rem)\n\trem = merg...
{"inputs": ["3 3", "4 1", "5 6", "100 100", "10000 10001", "10000 20001", "10000 30001", "20000 10001", "20000 20001", "20000 30001", "30000 10001", "30000 20001", "30000 30001", "40000 10001", "40000 20001", "40000 30001", "50000 10001", "50000 20001", "50000 30001", "60000 10001", "60000 20001", "60000 30001", "70000...
UNKNOWN
PYTHON3
CODEFORCES
40
676d7d8ba8d2e382fd2b536381577b77
Almost Prime
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). Output the amount of almo...
[ "\r\ndef count_primes(num):\r\n #does not consider num as a prime number\r\n count = 0\r\n\r\n for divisor in range(2, int(num**0.5)+1):\r\n if num % divisor == 0: count += 1\r\n\r\n while num % divisor == 0:\r\n num /= divisor\r\n \r\n if num > 1: count += 1 #num itself is p...
{"inputs": ["10", "21", "1", "2", "4", "3", "8", "19", "40", "77", "222", "987", "1000", "2000", "3000", "2999", "2998", "2997", "1429", "1673", "1500", "500", "856"], "outputs": ["2", "8", "0", "0", "0", "0", "1", "6", "19", "41", "125", "501", "508", "958", "1375", "1375", "1375", "1374", "706", "808", "732", "266", ...
UNKNOWN
PYTHON3
CODEFORCES
586
6770639456b30696194d24f4aff1cfe0
Board Game
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (*x*,<=*y*) to (*x*<=-<=1,<=*y*) or (*x*,<=*y*<=-<=1). Vasiliy can move his pawn from (*x*,...
[ "# LUOGU_RID: 132709855\n# pypy3\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nimport sys\r\n\r\nfrom math import gcd\r\n\r\nIN = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nPN = lambda x: sys.stdout.write(x)\r\nI = lambda...
{"inputs": ["2 1 2 2", "4 7 7 4", "20 0 7 22", "80 100 83 97", "80 100 77 103", "55000 60000 55003 60100", "100000 100000 100000 99999", "100000 99999 100000 100000", "0 100000 100000 99999", "0 100000 99999 100000", "0 90000 89999 89999", "0 1 0 2", "0 1 1 0", "0 1 1 1", "0 1 1 2", "0 1 2 0", "0 1 2 1", "0 1 2 2", "0 ...
UNKNOWN
PYTHON3
CODEFORCES
13
6770d28df371e4b6ceb7802e0142726f
Grasshopper And the String
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
[ "l=['A','U','O','I','E','Y']\r\ns=input()\r\nc=0\r\nm=0\r\nfor i in s:\r\n if(i in l):\r\n m=max(m,c)\r\n c=0\r\n else:\r\n c=c+1\r\nm=max(c,m)\r\nprint(m+1)", "s=input()\r\nm=1\r\nl=0\r\nd={'A','E','I','O','U','Y'}\r\nfor i in range(len(s)):\r\n\tif s[i] in d:\r\n\t\tl=max(l,m)\r\n\t\t...
{"inputs": ["ABABBBACFEYUKOTT", "AAA", "A", "B", "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI", "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNH...
UNKNOWN
PYTHON3
CODEFORCES
203
6779a84accbc036b36a7f8384cba5fae
Game on Paper
One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered white square piece of paper, consisting of *n*<=×<=*n* cells. After that, he started to paint the white cells black one after the other. In total he painted *m* different cells ...
[ "import math\r\nfrom sys import stdin\r\nfrom math import ceil\r\nimport sys\r\n\r\nif __name__ == '__main__':\r\n numbers = list(map(int, input().split()))\r\n n = numbers[0]\r\n m = numbers[1]\r\n moves = [[0] * (n + 4) for _ in range(n + 4)]\r\n for i in range(m):\r\n listOfMoves = list(map...
{"inputs": ["4 11\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n3 3\n4 1", "4 12\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n4 2\n4 1\n3 1", "3 1\n1 3", "3 8\n1 3\n3 3\n2 2\n3 2\n1 1\n1 2\n2 3\n3 1", "3 9\n2 3\n1 3\n3 1\n1 1\n3 3\n2 1\n2 2\n1 2\n3 2", "4 16\n1 3\n4 4\n4 1\n2 3\n3 1\n3 2\n1 4\n2 2\n1 2\n3 3\n2 1\n1 1\...
UNKNOWN
PYTHON3
CODEFORCES
14
67881ae428f6a4036f08f27aa010df48
Appleman and Card Game
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette...
[ "firstLine = input();\nn, k = firstLine.split();\nn = int(n);\nk = int(k);\n\ns = input();\n\nresult = 0;\ncount = [0] * 26\n\nfor i in range(0, len(s)):\n index = ord(s[i]) - 65;\n count[index] = count[index] + 1;\n \ncount.sort(reverse=True)\n\n\n\nfor j in range(0, len(count)):\n\n if(count[j] <= k):...
{"inputs": ["15 10\nDZFDFZDFDDDDDDF", "6 4\nYJSNPI", "5 3\nAOWBY", "1 1\nV", "2 1\nWT", "2 2\nBL", "5 1\nFACJT", "5 5\nMJDIJ", "15 5\nAZBIPTOFTJCJJIK", "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH", "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKI...
UNKNOWN
PYTHON3
CODEFORCES
292
67adc0bad471876d638897386ff0ab58
Obsession with Robots
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ...
[ "def main():\r\n #get the input string \r\n path = input()\r\n #initialise coordinates with 0\r\n coordinate = [[0 for i in range(2)] for j in range(len(path)+1)]\r\n #here we will store the number of moves left, right, up and down\r\n left = 0\r\n right = 0\r\n up = 0\r\n down = 0\r\n #get the number of ...
{"inputs": ["LLUUUR", "RRUULLDD", "L", "R", "R", "RR", "DL", "LD", "RUL", "ULD", "DDR", "RRDD", "RRLR", "RRDL", "LRUD", "RDRLL", "DRDRD", "ULURL", "LUUDU", "RDLUR", "DLDLDDRR", "RDRDDD", "UULLDLUR", "LULU", "LLDDLDLLDDDLLLDLLLLLUU", "LLDDLDLLDDDLLLDLLLLLUU", "LLDDLDLLDDDLLLDLLLLLUU", "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLD...
UNKNOWN
PYTHON3
CODEFORCES
48
67b8c70d7eeee85ba2167799826eef08
Fafa and his Company
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em...
[ "# A. Fafa and his Company\r\n \r\nn = int(input())\r\ni = 1\r\ncont = 0\r\nwhile i <= n/2:\r\n e = n - i\r\n if e % i == 0:\r\n cont += 1\r\n i += 1\r\nprint(cont)", "no_of_employees=int(input())\r\ni=1\r\nways=0\r\nwhile(i<=no_of_employees/2):\r\n if(no_of_employees%i==0):\r\n ways+=1\r\n i+=...
{"inputs": ["2", "10", "3", "4", "6", "13", "100000", "1024", "99999", "10007", "4096", "65536", "40320", "30030", "161", "1000", "10000", "777", "121", "25", "40000", "99990", "98765", "56789", "13579", "97531", "12345", "54321", "83160", "9", "21", "11", "15"], "outputs": ["1", "3", "1", "2", "3", "1", "35", "10", "1...
UNKNOWN
PYTHON3
CODEFORCES
649
67c7db44ad516d4d9637eea2d9ffa9ef
Cards
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja...
[ "# In this template you are not required to write code in main\r\n\r\nimport sys\r\ninf = float(\"inf\")\r\n\r\n#from collections import deque, Counter, OrderedDict,defaultdict\r\n#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace\r\n#from math import ceil,floor,log,sqrt,factorial,pow,...
{"inputs": ["2\nRB", "3\nGRG", "5\nBBBBB", "1\nR", "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB", "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
UNKNOWN
PYTHON3
CODEFORCES
62
67d44d56308d1ed231216c9f73dde7c5
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
[ "s = []\r\nfor i in range(int(input())):\r\n s.append(input())\r\ns = \"<3\" + '<3'.join(s) + \"<3\"\r\ncur = 0\r\nt = input()\r\nfor i in t:\r\n if i == s[cur]: cur += 1\r\n if cur == len(s): break\r\n\r\nprint('yes' if cur == len(s) else 'no')", "n=int(input())\r\ntext=\"\"\r\n\r\nfor _ in range(n):\r\...
{"inputs": ["3\ni\nlove\nyou\n<3i<3love<23you<3", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "4\na\nb\nc\nd\n<3a<3b<3c<3d", "4\na\nb\nc\nd\na<3b<3c<3d<3", "3\ni\nlove\nyou\n<3i<3love<3you<3", "1\na\na", "1\na\n<3a<3b", "1\naa\n<3a<3...
UNKNOWN
PYTHON3
CODEFORCES
34
6811358b57ceb6396694af8cc77a194d
Buttons
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the seque...
[ "n = int(input())\r\nresult = 0\r\nfor i in range(1, n + 1):\r\n result += i * (n - i) + 1\r\nprint(result)\r\n", "n=int(input())\r\nprint(int((n*(n-1)*(n+1))/6+n))", "# t = int(input())\r\n# while t>0:\r\nn = int(input())\r\nres = n\r\nc = 1\r\nfor i in range((n-1),0,-1):\r\n res+=(i*c)\r\n c+=1\r\n\r...
{"inputs": ["2", "3", "4", "1", "10", "2000", "1747", "889", "1999", "914", "996", "17", "50", "91", "92", "256", "512", "666", "667", "314", "1241", "1500", "1837", "1000"], "outputs": ["3", "7", "14", "1", "175", "1333335000", "888644743", "117099969", "1331335999", "127259419", "164675486", "833", "20875", "125671",...
UNKNOWN
PYTHON3
CODEFORCES
130
6817ec8c524a6cdd6f48f850c1a03b5b
Modular Equations
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and...
[ "arr = [int(x) for x in input().split()]\na = arr[0]\nb = arr[1]\nresp = 0\nif a == b:\n resp = 'infinity'\nif resp != 'infinity':\n x = a - b\n i = 1\n c = 0\n while i**2 < x:\n c += 1\n if x % i == 0:\n if i > b:\n resp += 1\n if x/i > b:\n resp += 1\n i += 1\n if i**2 == x ...
{"inputs": ["21 5", "9435152 272", "10 10", "0 1000000000", "11 2", "1 0", "0 0", "121 0", "772930485 686893955", "257424 24", "295138437 589952171", "223093836 966", "233758336 10665466", "223092887 17", "223094728 1858", "223092899 29", "997920 0", "887043 3", "124 24", "982901 101", "357987 35", "954374 1030", "4910...
UNKNOWN
PYTHON3
CODEFORCES
89
683c27dac16cdfe6eaa07b2cd1c495d6
GukiZ hates Boxes
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are *n* piles of boxes, arranged in a line, from left to right, *i*-th pile (1<=≤<=*i*<=≤<=*n*) containing *a**i* boxes. Luckily, *m* students are willing to help GukiZ by removing all the ...
[ "f = lambda: map(int, input().split())\r\nn, m = f()\r\nh = list(f())[::-1]\r\ndef g(t, m):\r\n t -= n\r\n d = 0\r\n for u in h:\r\n t+=1\r\n if u>d:\r\n if t<1: \r\n return 1\r\n u-=d\r\n d=-u % t\r\n m-=(u + d) // t\r\n i...
{"inputs": ["2 1\n1 1", "3 2\n1 0 2", "4 100\n3 4 5 4", "5 8\n121351 0 13513 0 165454", "6 6\n0 10 0 0 10 0", "1 1\n1", "1 100000\n1", "1 100000\n1000000000", "1 1\n1000000000", "20 20\n0 0 0 0 0 0 154 0 0 0 0 0 0 0 0 0 0 0 0 0", "10 10\n0 0 0 100 0 0 0 0 0 0", "15 20\n0 0 0 500 0 0 0 0 400 0 0 0 0 0 0", "5 3\n0 0 14 0...
UNKNOWN
PYTHON3
CODEFORCES
4
685766372374c5357654ecb9e8d5a092
Fight Against Traffic
Little town Nsk consists of *n* junctions connected by *m* bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible...
[ "import sys\r\nfrom collections import defaultdict,deque\r\ninp=sys.stdin.readline\r\nn,m,s,t=map(int,inp().split())\r\ns-=1\r\nt-=1\r\ngraph=defaultdict(list)\r\nedges=set()\r\nfor _ in range(m):\r\n u,v=map(int,inp().split())\r\n u-=1\r\n v-=1\r\n graph[u].append(v)\r\n graph[v].append(u)\r\n u,...
{"inputs": ["5 4 1 5\n1 2\n2 3\n3 4\n4 5", "5 4 3 5\n1 2\n2 3\n3 4\n4 5", "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5", "2 1 2 1\n1 2", "3 2 2 3\n1 2\n2 3", "3 2 1 3\n1 2\n2 3", "3 3 2 3\n1 2\n2 3\n1 3"], "outputs": ["0", "5", "3", "0", "1", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
19