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
000226c6000c597d60e93105ad1571c8
Restoring Password
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ...
[ "s = input()\na = []\nfor i in range(10):\n a.append(input())\n\np = 0\nwhile(p < 80):\n for i in range(10):\n if a[i] == s[p:p+10]:\n print(i, end='')\n p += 10\n break\n\n", "password = input()\r\nnum = []\r\npas = []\r\nfor i in range(10): num.append(input())\r\n\r...
{"inputs": ["01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n110111100...
UNKNOWN
PYTHON3
CODEFORCES
254
0009291163ba4c4519b618bd57707c1b
Math Show
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order. ...
[ "n,k,M = [int(i) for i in input().split(' ')]\ntasks = [int(i) for i in input().split(' ')]\ntasks = sorted(tasks)\nans = 0\nfor i in range(n+1):\n remaining_time = M - i*sum(tasks)\n if(remaining_time < 0):\n break\n value = (k+1)*i\n for j in range(k):\n for take in range(n-i):\n ...
{"inputs": ["3 4 11\n1 2 3 4", "5 5 10\n1 2 4 8 16", "1 1 0\n2", "1 1 1\n1", "2 1 0\n2", "2 2 2\n2 3", "4 2 15\n1 4", "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 ...
UNKNOWN
PYTHON3
CODEFORCES
37
00116124170d507613516798746290b0
A Lot of Games
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of *n* non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the ...
[ "max_alpha = 26\r\n\r\nclass TrieNode:\r\n def __init__(self):\r\n self.children = [0] * max_alpha\r\n\r\ndef add_trie(root, word):\r\n v = root\r\n for char in word:\r\n c = ord(char) - ord('a')\r\n if not v.children[c]:\r\n v.children[c] = TrieNode()\r\n v = v.child...
{"inputs": ["2 3\na\nb", "3 1\na\nb\nc", "1 2\nab", "5 6\nabas\ndsfdf\nabacaba\ndartsidius\nkolobok", "4 2\naaaa\nbbbb\nccccc\ndumbavumba", "3 8\nso\nbad\ntest", "5 2\nwelcome\nto\nthe\nmatrix\nneo", "6 4\ndog\ncat\ncow\nhot\nice\nlol", "4 8\nla\na\nz\nka", "3 2\nop\nhop\ncop", "3 3\nabasdfabab\nabaaasdfdsf\nasdfaba", ...
UNKNOWN
PYTHON3
CODEFORCES
2
0016836ae943bbac4c1846a047051d30
Perfect Number
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). A single number, denoting the $k$-th smallest perfect intege...
[ "k=int(input())\r\na=10\r\nwhile k!=0:\r\n a+=9\r\n s=sum(list(map(int,str(a))))\r\n # print(s)\r\n if s==10:\r\n k=k-1\r\nprint(a)", "import sys\r\ndef input(): return sys.stdin.readline().strip()\r\ndef getints(): return map(int,sys.stdin.readline().strip().split())\r\n\r\nn = int(input())\r\...
{"inputs": ["1", "2", "13", "101", "1023", "9999", "10000", "2333", "9139", "9859", "5987", "3", "4", "5", "7", "9", "10", "15", "51", "99", "138", "233", "666", "1234", "3567", "4445", "5689", "6666", "7777", "8888", "9411", "5539", "6259", "2387", "8515"], "outputs": ["19", "28", "136", "1432", "100270", "10800010", ...
UNKNOWN
PYTHON3
CODEFORCES
159
0019608f1af8cd1d0015e58a30bead95
Wrong Floyd
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it. Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from *n* vertexes and *m* edges, co...
[ "n,m,k=map(int,input().split())\r\nif k==n or m>(n-1)*(n-2)//2+n-k:print(-1)\r\nelse:\r\n\tbn=[int(i)-1 for i in input().split()]\r\n\tmkd,edg=[False]*n,[]\r\n\tfor i in bn:mkd[i]=True\r\n\tnbn=[i for i in range(n) if not mkd[i]]\r\n\tfor i in nbn:edg.append((bn[0],i))\r\n\tfor i in range(1,len(bn)):edg.append((nbn...
{"inputs": ["3 2 2\n1 2", "3 3 2\n1 2", "300 43056 2\n5 6", "300 44849 2\n1 300", "300 44850 2\n3 9", "58 702 19\n14 29 47 15 31 5 26 57 55 16 17 24 46 58 11 28 20 56 43", "43 76 6\n24 11 30 21 35 1", "6 13 6\n2 6 5 4 1 3", "139 8017 8\n18 108 117 80 99 74 36 52", "144 1175 121\n141 124 23 85 142 59 25 84 32 43 35 101 ...
UNKNOWN
PYTHON3
CODEFORCES
2
003925cb042a4e23c8a1ae7ed2d3c676
Golden System
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a n...
[ "def clean(d):\n ans = ['0']\n for c in list(d):\n ans.append(c)\n i = len(ans) - 1 #find last index\n while i > 1 and ans[i-2]== '0' and ans[i - 1] == '1' and ans[i] == '1':\n ans[i - 2] = '1'\n ans[i - 1] = '0'\n ans[i] = '0'\n i -= 2\n ret...
{"inputs": ["1000\n111", "00100\n11", "110\n101", "0\n0", "1\n10", "11\n10", "00111\n10100", "00\n1", "01\n010", "111\n00", "1100\n11", "0110\n001", "1111\n0110", "01010\n0011", "0\n1", "1\n0", "1\n1", "010000100010100000100010001000001100100010110000101010000010010011001111101101001\n0010111000011101011110011001100010...
UNKNOWN
PYTHON3
CODEFORCES
4
004052b4221db9fe863f7c0c314178ad
Simple Cycles Edges
You are given an undirected graph, consisting of $n$ vertices and $m$ edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself). A cycle in a graph is called a simple, if it conta...
[ "import sys\r\n\r\ndef solve():\r\n\tn, m = map(int, input().split())\r\n\tg = [[] for i in range(n+1)]\r\n\tE = [None]*m\r\n\tfor i in range(m):\r\n\t\tu, v = map(int, input().split())\r\n\t\tE[i] = (u, v)\r\n\t\tg[u].append([v,i])\r\n\t\tg[v].append([u,i])\r\n\tP = [-1]*(n+1)\r\n\tI = [0]*(n+1)\r\n\tst = []\r\n\t...
{"inputs": ["3 3\n1 2\n2 3\n3 1", "6 7\n2 3\n3 4\n4 2\n1 2\n1 5\n5 6\n6 1", "5 6\n1 2\n2 3\n2 4\n4 3\n2 5\n5 3", "4 5\n1 2\n2 3\n3 4\n4 1\n1 3", "7 8\n1 2\n2 3\n3 4\n4 1\n3 5\n5 6\n6 7\n7 3", "7 9\n1 2\n2 4\n4 3\n3 1\n2 3\n4 5\n5 6\n6 7\n7 4", "6 9\n1 2\n2 3\n1 4\n4 2\n5 2\n5 3\n4 5\n6 4\n6 5", "6 7\n1 2\n2 3\n3 1\n3 4...
UNKNOWN
PYTHON3
CODEFORCES
1
00a6789db72f25421f52cf4aa40e1f80
Vitya and Strange Lesson
Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, *mex*([4,<=33,<=0,<=1,<=1,<=5])<==<=2 and *mex*([1,<=2,<=3])<==<=0. Vitya quickly understood all tasks of the teacher, but ca...
[ "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\...
{"inputs": ["2 2\n1 3\n1\n3", "4 3\n0 1 5 6\n1\n2\n4", "5 4\n0 1 5 6 7\n1\n1\n4\n5", "5 5\n1 2 3 4 5\n1\n2\n3\n4\n5", "9 3\n2 3 4 5 6 7 8 9 10\n1\n2\n3", "10 30\n0 0 0 0 0 0 0 0 0 0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "17 30\n4194 1990 2257 1363 2798 386 3311 3152...
UNKNOWN
PYTHON3
CODEFORCES
2
00aa51e739d4197c4766ec0104225460
Laptops
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ...
[ "def solve():\r\n x = int(input())\r\n l = []\r\n for i in range(x):\r\n a, b = map(int, input().split())\r\n l.append((a, b))\r\n l.sort(key=lambda p: p[0])\r\n for i in range(1, x):\r\n if l[i][1]-l[i-1][1] < 0:\r\n print('Happy Alex')\r\n return\r\n pr...
{"inputs": ["2\n1 2\n2 1", "2\n1 1\n2 2", "3\n2 2\n3 3\n1 1", "3\n3 3\n1 2\n2 1", "1\n1 1", "3\n2 3\n1 1\n3 2", "4\n4 1\n3 2\n2 3\n1 4", "2\n2 1\n1 2", "3\n3 2\n1 1\n2 3", "3\n1 2\n2 3\n3 1", "3\n1 2\n2 1\n3 3", "3\n1 2\n2 3\n3 1"], "outputs": ["Happy Alex", "Poor Alex", "Poor Alex", "Happy Alex", "Poor Alex", "Happy A...
UNKNOWN
PYTHON3
CODEFORCES
300
00d009aca003c86e98034a2626d72d5a
Increase and Decrease
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i...
[ "n = int(input())\r\narr = [int(i) for i in input().split()]\r\nif sum(arr)%n ==0: print(n)\r\nelse: print(n-1)", "n = int(input())\r\nlst = map(int, input().split())\r\nanes = sum(lst)\r\nif anes % n:\r\n n -= 1\r\nprint(n)\r\n", "n = int(input())\nnumbers = input().split()\nlst = [int(x) for x in numbers]\...
{"inputs": ["2\n2 1", "3\n1 4 1", "4\n2 -7 -2 -6", "4\n2 0 -2 -1", "6\n-1 1 0 0 -1 -1", "5\n0 0 0 0 0", "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56...
UNKNOWN
PYTHON3
CODEFORCES
196
00d61208f82188a7c0d0ea2dc89d4d5e
Stripe 2
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
[ "n,num,ways,q = int(input()),0,0,0\r\ns = list(map(int,input().split()))\r\nsums = sum(s)\r\nfor i in range(n):\r\n num += s[i]\r\n if num * 3 == sums * 2 and 0 < i < n - 1:\r\n ways += q\r\n if num * 3 == sums:\r\n q += 1\r\nprint(ways)", "from collections import Counter\r\n\r\nn = int(inp...
{"inputs": ["1\n-3", "2\n0 0", "3\n0 0 0", "4\n-2 3 3 2", "5\n-6 3 -1 2 -7", "6\n2 3 -3 0 -3 1", "7\n-1 1 -3 4 3 0 2", "8\n2 0 0 2 -1 3 4 5", "9\n-5 -2 1 1 5 0 -4 4 0", "10\n-1 5 2 3 1 5 0 2 2 5", "100\n3 0 -5 2 -3 -1 -1 0 -2 -5 -4 2 1 2 -2 -1 -1 -4 3 -1 -3 -1 5 0 -4 -4 -1 0 -2 -2 0 1 -1 -2 -1 -5 -4 -2 3 1 -3 0 -1 1 0 ...
UNKNOWN
PYTHON3
CODEFORCES
20
00d8b668cd014571f31e0eab59f83480
Ring Road 2
It is well known that Berland has *n* cities, which form the Silver ring — cities *i* and *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are connected by a road, as well as the cities *n* and 1. The goverment have decided to build *m* new roads. The list of the roads to build was prepared. Each road will connect two cities. Each roa...
[ "n,m=map(int,input().split())\r\n\r\nX=[tuple(map(int,input().split())) for i in range(m)]\r\n\r\nE=[[] for i in range(m)]\r\n\r\nfor i in range(m):\r\n a,b=X[i]\r\n if a>b:\r\n a,b=b,a\r\n for j in range(i+1,m):\r\n c,d=X[j]\r\n if c>d:\r\n c,d=d,c\r\n\r\n if a<c<b<d...
{"inputs": ["4 1\n4 2", "4 2\n1 3\n2 4", "5 1\n3 5", "5 2\n2 4\n4 1", "5 3\n4 2\n1 3\n5 2", "5 4\n1 3\n3 5\n1 4\n2 4", "6 1\n6 2", "6 2\n3 5\n2 4", "6 3\n5 1\n4 6\n3 1", "6 4\n6 3\n1 3\n6 4\n5 3", "6 5\n5 3\n4 1\n2 6\n5 1\n5 2", "6 6\n1 4\n4 6\n2 6\n2 4\n5 3\n6 3", "7 1\n4 7", "7 3\n2 7\n1 5\n5 7", "7 5\n3 7\n5 7\n6 4\...
UNKNOWN
PYTHON3
CODEFORCES
5
00e6fd1ffd43552c1eec62ca3a83edc1
Frodo and pillows
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
[ "n,m,k = list(map(int, input().split(' ')))\n\nextra = m - n\nmaxi = 1\n\nif n == 1:\n print(m)\nelif n == 2:\n if m%2 == 0:\n print(m//2)\n else:\n print(m//2 +1)\nelse:\n for i in range(extra):\n stepPillows = 1 + min(k-1,i) + min(n-k,i)\n if extra >= stepPillows:\n ...
{"inputs": ["4 6 2", "3 10 3", "3 6 1", "3 3 3", "1 1 1", "1 1000000000 1", "100 1000000000 20", "1000 1000 994", "100000000 200000000 54345", "1000000000 1000000000 1", "1000000000 1000000000 1000000000", "1000000000 1000000000 500000000", "1000 1000 3", "100000000 200020000 54345", "100 108037 18", "100000000 2000200...
UNKNOWN
PYTHON3
CODEFORCES
72
00fbc945b80faddc1a7886d351cd17ec
Cut 'em all!
You're given a tree with $n$ vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree. The next $n - 1$ lines co...
[ "# Time Complexity: O(n)\n# Space Complexity: O(n)\n# The solution iterates through every node and edge using DFS in O(n + m)\n# Then, it iterates through every node and assume it is the root of a forest\n# to check if it has even number of nodes in O(n).\nn = int(input())\nif n % 2 == 1:\n print(-1)\n exit()...
{"inputs": ["4\n2 4\n4 1\n3 1", "3\n1 2\n1 3", "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "2\n1 2", "1", "4\n1 2\n1 3\n1 4"], "outputs": ["1", "-1", "4", "0", "-1", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
29
00ff2211b9d4f140a5b66f07f703e31e
Prefix Product Sequence
Consider a sequence [*a*1,<=*a*2,<=... ,<=*a**n*]. Define its prefix product sequence . Now given *n*, find a permutation of [1,<=2,<=...,<=*n*], such that its prefix product sequence is a permutation of [0,<=1,<=...,<=*n*<=-<=1]. The only input line contains an integer *n* (1<=≤<=*n*<=≤<=105). In the first output lin...
[ "def comp(x):\r\n for i in range(2, x):\r\n if x % i == 0:\r\n return True\r\n return False\r\n\r\nN = int(input())\r\n\r\nif N == 4:\r\n print('YES', '1', '3', '2', '4', sep = '\\n')\r\nelif comp(N):\r\n print('NO')\r\nelse:\r\n print('YES', '1', sep = '\\n')\r\n if N > 1:\r\n ...
{"inputs": ["7", "6", "7137", "10529", "34211", "1941", "55004", "21341", "61333", "77617", "44633", "18047", "78137", "2647", "6577", "87511", "87299", "49069", "16553", "19333", "8677", "83203", "31513", "60811", "71821", "1", "2", "3", "4", "5", "99989"], "outputs": ["YES\n1\n2\n5\n6\n3\n4\n7", "NO", "NO", "YES\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
4
011ffafc12a39435e3be0ababc151355
Train and Peter
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy start...
[ "f = input()\r\nb = f[::-1]\r\n\r\ns1 = input()\r\ns2 = input()\r\n\r\ni = -1\r\nj = -1\r\ntry:\r\n i = f.index(s1)\r\n j = f.index(s2, i+len(s1))\r\nexcept:\r\n pass\r\nforward = bool(j > -1)\r\n\r\ni = -1\r\nj = -1\r\ntry:\r\n i = b.index(s1)\r\n j = b.index(s2, i+len(s1))\r\nexcept:\r\n pass\r\...
{"inputs": ["atob\na\nb", "aaacaaa\naca\naa", "aaa\naa\naa", "astalavista\nastla\nlavista", "abacabadabacaba\nabacaba\nabacaba", "a\na\na", "ab\nb\na", "aaa\naaaa\naaaa", "bbabbbbababbaabaabaa\nabb\nbaab", "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababa...
UNKNOWN
PYTHON3
CODEFORCES
136
012fb38aed25051ef0d630880d765f11
New Year and Rating
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
[ "s, t = -10 ** 8, 10 ** 8\r\nn = int(input())\r\nfor i in range(n):\r\n c, d = map(int, input().split())\r\n if d == 1:\r\n s = max(s, 1900)\r\n if d == 2:\r\n t = min(t, 1899)\r\n if s > t:\r\n print('Impossible')\r\n exit()\r\n s = s + c\r\n t = t + c\r\nif (t > 4*10*...
{"inputs": ["3\n-7 1\n5 2\n8 2", "2\n57 1\n22 2", "1\n-5 1", "4\n27 2\n13 1\n-50 1\n8 2", "6\n8 1\n-22 1\n9 2\n-7 2\n85 2\n77 1", "7\n-56 1\n-85 2\n-88 2\n-36 1\n-25 2\n8 2\n61 2", "15\n20 2\n-31 2\n80 2\n-18 2\n-44 2\n37 2\n-90 2\n76 2\n14 2\n8 2\n-40 2\n22 2\n21 2\n20 2\n-29 2", "50\n67 1\n89 2\n83 1\n-26 1\n88 2\n-2...
UNKNOWN
PYTHON3
CODEFORCES
10
01517ece5fcece11600c08415abcaafc
Launch of Collider
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis...
[ "n = int(input())\r\ns = input()\r\narr = list(map(int, input().split()))\r\nans = []\r\nfor i in range(n):\r\n if(i == n-1):\r\n break\r\n if((s[i] == \"R\" and s[i+1] == \"L\")):\r\n ans.append(arr[i+1]-arr[i])\r\nfor i in range(len(ans)):\r\n ans[i] = int(ans[i]/2)\r\nif not ans:\r\n pr...
{"inputs": ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60", "4\nRLLR\n46 230 264 470", "6\nLLRLLL\n446 492 650 844 930 970", "8\nRRLLLLLL\n338 478 512 574 594 622 834 922", "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000", "2\nRL\n0 1000000000", "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134...
UNKNOWN
PYTHON3
CODEFORCES
278
016b50223ce131e6509352043eb14e1e
A + B Strikes Back
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. Output the ...
[ "import time\r\ntime.sleep(0.99)\r\nprint(sum([int(i) for i in input().split()]))", "b = input().split()\r\na = int(b[0])\r\n\r\nc = int(b[1])\r\nprint(a+c)", "a , b = input().split()\r\nprint (int(a) + int(b))", "x = input().split()\r\nprint((int(x[0])+int(x[1])))", "a,n=map(int,(input()).split())\r\nprint...
{"inputs": ["5 14", "381 492", "536 298", "143 522", "433 126", "723 350", "632 264", "923 488", "522 92", "953 553", "242 86", "151 691", "441 915", "740 519", "339 433", "629 657", "538 261", "828 485", "117 399", "399 280"], "outputs": ["19", "873", "834", "665", "559", "1073", "896", "1411", "614", "1506", "328", "...
UNKNOWN
PYTHON3
CODEFORCES
72
017e2da2b87f663a7b0412bf0bb88b7d
Pathwalks
You are given a directed graph with *n* nodes and *m* edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges...
[ "import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u * z + v\r\n\r\ndef update(i, x):\r\n i += l1\r\n tree[i] = x\r\n i //= 2\r\n while i:\r\n tree[i] = max(tree[2 * i], tree[2 * i + 1])\r\n i //= 2\r\n ...
{"inputs": ["3 3\n3 1 3\n1 2 1\n2 3 2", "5 5\n1 3 2\n3 2 3\n3 4 5\n5 4 0\n4 5 8", "5 10\n3 4 8366\n5 1 6059\n2 1 72369\n2 2 35472\n5 3 50268\n2 4 98054\n5 1 26220\n2 3 24841\n1 3 42450\n3 1 59590", "1000 10\n11 368 48256\n192 176 81266\n236 360 25346\n377 962 3089\n486 176 49857\n693 810 36660\n692 698 35141\n879 822 1...
UNKNOWN
PYTHON3
CODEFORCES
1
0198aee040e76bb04226c286f11fe8f5
Beautiful Subarrays
One day, ZS the Coder wrote down an array of integers *a*<=with elements *a*1,<=<=*a*2,<=<=...,<=<=*a**n*. A subarray of the array *a* is a sequence *a**l*,<=<=*a**l*<=<=+<=<=1,<=<=...,<=<=*a**r* for some integers (*l*,<=<=*r*) such that 1<=<=≤<=<=*l*<=<=≤<=<=*r*<=<=≤<=<=*n*. ZS the Coder thinks that a subarray of *a*...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef insert(x, la):\r\n j = 0\r\n for i in p:\r\n if x & i:\r\n if not G[j] >> 25:\r\n la += 1\r\n G[j] ^= la << 25\r\n j = la\r\n else:\r\n ...
{"inputs": ["3 1\n1 2 3", "3 2\n1 2 3", "3 3\n1 2 3", "1 1\n1", "10 1\n1 1 0 1 0 1 1 0 0 0", "100 80\n85 16 22 81 86 64 53 7 123 114 53 25 29 23 61 125 29 108 53 7 57 46 83 73 24 26 55 121 67 93 85 28 73 59 11 34 63 90 37 111 47 127 80 104 94 51 93 106 63 33 17 44 89 11 111 111 54 89 63 81 107 63 127 27 74 71 8 111 111...
UNKNOWN
PYTHON3
CODEFORCES
1
01a5f5ded65d03fe7fc2de116d20b0d1
Equidistant String
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings *s* and *t* of the same length consisting of digits zero and one as the...
[ "# Enter your code here. Read input from STDIN. Print output to STDOUT\nimport math\n\nif __name__ == '__main__':\n a = input().strip()\n b = input().strip()\n c = []\n swap = False\n sc = 0\n for x, y in zip(a, b):\n \tif x == y:\n \t\tc.append(x)\n \telse:\n \t\tif swap:\n \t\t\tc...
{"inputs": ["0001\n1011", "000\n111", "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110011111", "0000000001000000000000100000100001000000\n111111101111110111111111111111111...
UNKNOWN
PYTHON3
CODEFORCES
10
01bfc3784ea08c84790d108192aa612c
George and Job
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. You are to choose *k* pairs of integers:...
[ "import sys\r\ninput = sys.stdin.readline\r\n \r\nn, m, k = map(int, input().split())\r\nw = list(map(int, input().split()))\r\nd = [0]\r\nfor i in w:\r\n d.append(d[-1]+i)\r\nq = [[0]*(n+1) for i in range(k+1)]\r\nfor i in range(1, k+1):\r\n for j in range(m, n+1):\r\n q[i][j] = max(q[i][j-1], q[i-1][...
{"inputs": ["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0", "13 8 1\n73 7 47 91 54 74 99 11 67 35 84 18 19", "8 3 1\n8 46 37 81 81 57 11 2", "20 5 3\n96 46 67 36 59 95 88 43 92 58 1 31 69 35 36 77 56 27 3 23", "16 2 2\n50 78 5 26 26 16 14 35 46 8 37 31 92 52 97 24", "22 1 6\n21 34 48 26 37 85 24 85 57 92 88 53 17 7 47 2...
UNKNOWN
PYTHON3
CODEFORCES
5
01d730e4a6dd38da0827d97f48da0d44
The Smallest String Concatenation
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest concatenation. The first line contains integer *n* — the number of st...
[ "from functools import cmp_to_key\ndef cmp(x,y):\n if x+y>y+x:\n return 1\n else:\n return -1\na=[]\nn=int(input())\nfor i in range(n):\n\ta.append(input())\nans=\"\"\nfor s in sorted(a,key=cmp_to_key(cmp)):\n\tans+=s\nprint(ans)\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()...
{"inputs": ["4\nabba\nabacaba\nbcd\ner", "5\nx\nxx\nxxa\nxxaa\nxxaaa", "3\nc\ncb\ncba", "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc", "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt...
UNKNOWN
PYTHON3
CODEFORCES
107
02539bfd285d339972f06b994febecca
MUH and House of Cards
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of *n* playing cards. Let's describe the house they want to make: 1. The house consists of some non-zero number of floors. 1. Each f...
[ "n,a,b=int(input()),0,0\r\nfor i in range(1,int(1e12)+1):\r\n if i**2>1e12:break\r\n a+=3*i-1\r\n if a>n:break\r\n if(n-a)%3==0:b+=1\r\nprint(b)", "import math\r\nn = int(input())\r\nx = math.floor((-7 + math.sqrt(1 + 24 * n)) / 6 + 1)\r\nif (n - 2 * x) % 3 == 0:\r\n print((x - 1) // 3 + 1)\r\nelif (n - 2 * ...
{"inputs": ["13", "6", "26", "1000000000000", "571684826707", "178573947413", "420182289478", "663938115190", "903398973606", "149302282966", "388763141382", "71", "98", "99", "100", "1312861", "1894100308", "152", "153", "154", "155", "156", "157", "158", "1", "2", "3", "4"], "outputs": ["1", "0", "2", "272165", "2057...
UNKNOWN
PYTHON3
CODEFORCES
24
02838d9aa9cf134a419923b3ef00fd19
Wasted Time
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers. Mr. Scrooge's signature can be represented as a polyline ...
[ "from math import sqrt\r\n\r\nn, k = map(int, input().split())\r\nx1, y1 = map(float, input().split())\r\n\r\ndistance = 0.0\r\nfor i in range(n - 1):\r\n x2, y2 = map(float, input().split())\r\n distance += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\r\n x1 = x2\r\n y1 = y2\r\ntime = distance / 50\r\nprint(t...
{"inputs": ["2 1\n0 0\n10 0", "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0", "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0", "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8", "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 ...
UNKNOWN
PYTHON3
CODEFORCES
321
0294956260ffc57415c62e502d6f06e5
Hungry Sequence
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers. A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if: - Its elements are in i...
[ "n=int(input())\r\nfor i in range(n):\r\n print(i+n*10,end=\" \")\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\nfor i in range(10 ** 7 - n + 1, 10 ** 7 + 1):\r\n print(i, end = ' ')", "import math as mt\r\nfrom collections import defaultdict,deque\r\nfrom bisect import bis...
{"inputs": ["3", "5", "1", "1000", "100000", "46550", "61324", "13176", "73274", "86947", "26342", "22345", "19639", "12337", "67989", "57610", "63287", "952", "77840", "42157", "46375", "55142", "60299", "28862", "48251", "2", "4"], "outputs": ["2 9 15", "11 14 20 27 31", "3", "3000 3001 3002 3003 3004 3005 3006 3007 ...
UNKNOWN
PYTHON3
CODEFORCES
85
029f228d7eb147443760a391f1dc7620
Multithreading
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of *n* different threads ordered by the time of the latest message in the threa...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\nans=-1\r\nfor i in range(n-1):\r\n if a[i]>a[i+1]: ans=i\r\nprint(ans+1)\r\n\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\nans = n-1\r\nwhile ans>0 and l[ans-1]<l[ans]:\r\n\tans-=1\r\nprint(ans)\r\n", "n = (int)(input())\r\na = (list)(...
{"inputs": ["5\n5 2 1 3 4", "3\n1 2 3", "4\n4 3 2 1", "5\n1 2 5 3 4", "1\n1", "2\n1 2", "2\n2 1", "3\n2 1 3", "6\n4 5 6 1 2 3", "10\n10 5 9 4 1 8 3 7 2 6", "3\n1 3 2", "3\n3 1 2", "4\n1 2 3 4", "4\n2 3 1 4", "6\n3 2 1 6 4 5", "7\n2 3 4 5 6 7 1", "8\n2 6 8 3 1 4 7 5", "9\n6 7 1 2 3 5 4 8 9", "10\n1 2 3 4 5 6 7 8 9 10", ...
UNKNOWN
PYTHON3
CODEFORCES
8
02a4d66a3ae38146633b88368fa96f9b
Hongcow Solves A Puzzle
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed tha...
[ "import sys\n\nn, m = map(int, input().split())\na = [input() for _ in range(n)]\n\nmin_i, min_j = n, m\nmax_i, max_j = 0, 0\n\nfor i in range(n):\n for j in range(m):\n if a[i][j] == 'X':\n min_i, min_j = min(min_i, i), min(min_j, j)\n max_i, max_j = max(max_i, i), max(max_j, j)\n\n...
{"inputs": ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
UNKNOWN
PYTHON3
CODEFORCES
61
02c1e35e9eff2d7124426da03ece97a2
Dress'em in Vests!
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him...
[ "# 161A-sua bai >> accepted\n# n: num of solder\n# m: num of vest\n# x: margin duoi\n# y: margin tren\n# chu giai giai thuat: i chay tu 0>>n, neu ao vest b[j] nho hon (a[i]-x), thi tang j (xet bo ao vest tiep theo) cho toi khi tim\n# thay j phu hop, sau do xet xem ung voi j do, ao vest co phu hop voi soldier i ko (...
{"inputs": ["5 3 0 0\n1 2 3 3 4\n1 3 5", "3 3 2 2\n1 5 9\n3 5 7", "1 1 0 0\n1\n1", "1 1 0 0\n1\n2", "2 3 1 4\n1 5\n1 2 2", "20 30 1 4\n1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5", "33 23 17 2\n1 1 2 2 2 3 3 3 3 3 3 4 4 4 4 4 5 5 5 6 6 7 7 7 8 8 8 8 8 9 9 10 10\n...
UNKNOWN
PYTHON3
CODEFORCES
93
02cd7b9d37376a7c11ec52de11154752
Vasya and Petya's Game
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number *y*?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can a...
[ "def input_ints():\r\n return list(map(int, input().split()))\r\n\r\ndef main():\r\n n = int(input())\r\n ans = []\r\n for x in range(2, n + 1):\r\n s = set()\r\n xx = x\r\n for y in range(2, n + 1):\r\n while xx % y == 0:\r\n xx /= y\r\n s.a...
{"inputs": ["4", "6", "1", "15", "19", "20", "37", "211", "557", "907", "953", "289", "400", "900", "625", "729", "784", "31", "44", "160", "322", "894", "998", "1000", "1000", "30"], "outputs": ["3\n2 4 3 ", "4\n2 4 3 5 ", "0", "9\n2 4 8 3 9 5 7 11 13 ", "12\n2 4 8 16 3 9 5 7 11 13 17 19 ", "12\n2 4 8 16 3 9 5 7 11 13...
UNKNOWN
PYTHON3
CODEFORCES
111
02e7235a4efc5e9f5db9210fca03d2b6
Parking Lot
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as *L* meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors ...
[ "l, b, f = map(int, input().split())\r\np = [[-b, -b, -192], [l + f, l + f, -38]]\r\nn = int(input())\r\nfor i in range(1, n + 1):\r\n a, h = map(int, input().split())\r\n if a == 1:\r\n k = False\r\n for w in range(len(p) - 1):\r\n if p[w + 1][0] - p[w][1] >= b + f + h:\r\n ...
{"inputs": ["30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4", "10 1 1\n1\n1 12", "10 1 1\n1\n1 9", "10 1 1\n1\n1 10", "10 1 1\n2\n1 3\n1 6", "10 1 1\n2\n1 3\n1 7", "10 1 1\n5\n1 1\n1 2\n1 3\n2 2\n1 4", "10 1 1\n5\n1 4\n2 1\n1 3\n2 3\n1 1", "10 1 1\n5\n1 2\n1 3\n1 1\n1 4\n1 2", "20 1 ...
UNKNOWN
PYTHON3
CODEFORCES
3
02e9375c13cac03e36e52098a49ad00c
Duff and Weight Lifting
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to ...
[ "n = int(input())\na = [int(x) for x in input().split()]\nl = [0] * (10**6 + 100)\nfor x in a:\n\tl[x] += 1\ncur = 0\nans = 0\nfor x in l:\n\tcur += x\n\tif cur % 2:\n\t\tans += 1\n\tcur //= 2\nprint(ans)\n", "from sys import stdin\r\n\r\ninput, Max = stdin.readline, 2 * 10 ** 6\r\nn, mem, ans = int(input()), [0]...
{"inputs": ["5\n1 1 2 3 3", "4\n0 1 2 3", "1\n120287", "2\n28288 0", "2\n95745 95745", "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599", "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743", "35\n0 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", "35\n13...
UNKNOWN
PYTHON3
CODEFORCES
18
02f31067aa2dceb4da4eac2111fd03a2
Weather Tomorrow
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where...
[ "n = int(input())\r\nvals = list(map(int,(input().split())))\r\narith = True\r\ndiff = vals[0]-vals[1]\r\nfor i in range(n-1):\r\n if vals[i]-vals[i+1]!=diff:\r\n arith = False\r\n break\r\nif arith:\r\n print(vals[-1]-diff)\r\nelse:\r\n print(vals[-1])", "import sys\r\n\r\n\r\nn = int(inpu...
{"inputs": ["5\n10 5 0 -5 -10", "4\n1 1 1 1", "3\n5 1 -5", "2\n900 1000", "2\n1 2", "3\n2 5 8", "4\n4 1 -2 -5", "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955", "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000", "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 ...
UNKNOWN
PYTHON3
CODEFORCES
161
030d1fdc1e4a2a83646aa091f343382b
Product Sum
Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special. You are given an array *a* of length *n*. The characteristic of this array is the value  — the sum of the produc...
[ "from sys import stdin, stdout\r\n\r\ndef calculate(m0,c0,m1,c1):\r\n return (c0-c1)/(m1-m0)\r\n\r\nn = int(stdin.readline())\r\n\r\nA = [int(x) for x in stdin.readline().split()]\r\nsigma = [0]\r\nfor i in range(n-1):\r\n sigma.append(sigma[-1]+A[i])\r\nrunning_sum = sum([A[i]*(i+1) for i in range(n)])\r\n\r...
{"inputs": ["4\n4 3 2 5", "5\n1 1 2 7 1", "3\n1 1 2", "5\n1 2 3 4 5", "5\n-1 -2 -3 -4 -5", "4\n0 0 0 0", "7\n0 0 0 -1 0 0 0", "2\n1000000 -1000000", "2\n1 1", "2\n-1 -1", "2\n-1000000 1000000", "2\n0 0", "4\n2 1 3 4", "5\n1 2 5 4 5", "4\n2 3 4 1", "4\n4 1 2 3", "6\n5 7 11 83 14 999", "4\n87 213 141 1"], "outputs": ["39...
UNKNOWN
PYTHON3
CODEFORCES
1
031738b2a795984b97cacc3dcba12ad1
NP-Hard Problem
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot...
[ "n,m = list(map(int,input().split()))\r\ngraph = [[]for _ in range(n)]\r\ncolor = [0]*n\r\nfor i in range(m):\r\n a,b = list(map(int,input().split()))\r\n graph[a-1].append(b-1)\r\n graph[b-1].append(a-1)\r\nfor i in range(n):\r\n if color[i]:\r\n continue\r\n color[i] = 1\r\n queue = [i]\r...
{"inputs": ["4 2\n1 2\n2 3", "3 3\n1 2\n2 3\n1 3", "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1", "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3", "10 17\n5 1\n8 1...
UNKNOWN
PYTHON3
CODEFORCES
63
033bfbcebdec2b5dc7db142182fedf45
Unlucky Ticket
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches th...
[ "\nn = int(input())\ns = input()\n\nl = sorted(list(int(i) for i in s[:n]))\nr = sorted(list(int(i) for i in s[n:]))\n\n\nstrictly_less = all(l[i] < r[i] for i in range(n))\nstrictly_more = all(l[i] > r[i] for i in range(n))\n\nif strictly_less or strictly_more:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \t...
{"inputs": ["2\n2421", "2\n0135", "2\n3754", "1\n33", "2\n3444", "3\n221323", "3\n132432", "1\n10", "3\n999000", "5\n2563434512", "10\n01101001000011011110", "10\n10001222212022211120", "10\n36828132853144011224", "20\n1011022122111202122200100211021100001122", "20\n5232324254212415411311123313002001301121", "20\n74058...
UNKNOWN
PYTHON3
CODEFORCES
11
03454594327b444c412678ff95f26c95
none
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение мо...
[ "s=input()\r\nf=False\r\nfor i in range(1,len(s)):\r\n if s[i:]==s[:len(s[i:])] and len(s[i:])-1>=i:\r\n print('YES')\r\n print(s[i:])\r\n f=True\r\n break\r\nif not f:\r\n print('NO')\r\n", "inp = input()\r\nn = len(inp)//2+1\r\nt = False\r\nfor i in range(n,len(inp)):\r\n i...
{"inputs": ["abrakadabrabrakadabra", "acacacaca", "abcabc", "abababab", "tatbt", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "r", "zaz", "zaza", "gg", "gagaga", "hhhh", "sssss", "nxnxnx", "vygvygv", "rlrlrlrl", "zyzyzyzyz", "jjjjjjjjjj", "kkhuskkhusk", "gzgzgz...
UNKNOWN
PYTHON3
CODEFORCES
23
039b1b6532f6ce80b8a7a1e89f40c15a
Freelancer's Dreams
Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least *p* experience points, and a desired flat in Moscow costs *q* dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions t...
[ "from fractions import Fraction\r\n \r\n \r\ndef higher(x1, y1, x2, y2):\r\n if x1 == 0:\r\n if x2 == 0:\r\n return \r\n \r\n \r\ndef min_days(p, q, pr):\r\n ma = max(a for a, b in pr)\r\n mb = max(b for a, b in pr)\r\n pr.sort(key=lambda t: (t[0], -t[1]))\r\n ch = [(0, mb)]\r\n ...
{"inputs": ["3 20 20\n6 2\n1 3\n2 6", "4 1 1\n2 3\n3 2\n2 3\n3 2", "3 12 12\n5 1\n2 2\n1 5", "3 12 12\n5 1\n4 4\n1 5", "3 1 1\n1 1\n1 1\n1 1", "1 4 6\n2 3", "1 3 4\n2 3", "2 1 1000000\n2 4\n5 2", "2 1000000 1\n2 4\n5 2", "2 1000000 1000000\n2 4\n5 2", "6 2 2\n2 4\n5 2\n5 2\n2 4\n2 4\n5 2", "1 3 5\n2 3", "2 10 3\n2 4\n5...
UNKNOWN
PYTHON3
CODEFORCES
1
039e46a507fde708d36bb8263ef7e2c3
Supermarket
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo. Now imagine you'd...
[ "n,m = list(map(int,input().split()))\nlst = []\nfor nt in range(n):\n st = list(map(int,input().split()))\n lst.append(st[0]/st[1])\nprint(min(lst)*m)\n\n\t\t\t \t \t\t\t\t \t\t\t\t\t\t \t\t \t\t", "N, M = map(int,input().split())\r\nminCost = float('inf')\r\nfor i in range(N):\r\n A, B = map(int...
{"inputs": ["3 5\n1 2\n3 4\n1 3", "2 1\n99 100\n98 99", "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 82\n38 62\n11 50\n55 84\n1 97\n12 67\n51 96\n51 7\n1 100\n79 61\n66 54\n97 93\n52 75\n80 54\n98 73\n29 28\...
UNKNOWN
PYTHON3
CODEFORCES
128
03d5dd4aac643323dbd9adf0c37c9842
Mysterious strings
The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). Output a single string. The input contains a single integer *a* (1<=≤<=*a*<=≤<=40). Output a single string. Sample Input 2 8 29 Sample Output Adams Van Buren Harding
[ "pres = [\"Washington\",\r\n\"Adams\",\r\n\"Jefferson\",\r\n\"Madison\",\r\n\"Monroe\",\r\n\"Adams\",\r\n\"Jackson\",\r\n\"Van Buren\",\r\n\"Harrison\",\r\n\"Tyler\",\r\n\"Polk\",\r\n\"Taylor\",\r\n\"Fillmore\",\r\n\"Pierce\",\r\n\"Buchanan\",\r\n\"Lincoln\",\r\n\"Johnson\",\r\n\"Grant\",\r\n\"Hayes\",\r\n\"Garfiel...
{"inputs": ["2", "8", "29", "1", "3", "4", "5", "6", "7", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"], "outputs": ["Adams", "Van Buren", "Harding", "Washington", "Jefferson", "Mad...
UNKNOWN
PYTHON3
CODEFORCES
10
03d757ac8e067015d78fcba7c26d2d05
Pair Of Lines
You are given *n* points on Cartesian plane. Every point is a lattice point (i.<=e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? The first lin...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef f(x1, y1, x2, y2, x3, y3):\r\n if x1 == x2 == x3:\r\n return True\r\n if y1 == y2 == y3:\r\n return True\r\n if (x2 - x1) * (y3 - y2) == (x3 - x2) * (y2 - y1):\r\n return True\r\n else:\r\n return False\r\n\r\nn = int(input...
{"inputs": ["5\n0 0\n0 1\n1 1\n1 -1\n2 2", "5\n0 0\n1 0\n2 1\n1 1\n2 3", "1\n-1000000000 1000000000", "5\n2 -1\n-4 1\n0 -9\n5 -9\n9 -10", "5\n6 1\n10 5\n10 -2\n-2 -10\n-4 -9", "5\n-10 3\n4 -5\n-9 5\n-5 -3\n-4 -6", "5\n2 9\n-1 -4\n-3 -8\n-4 8\n7 2", "10\n315 202\n315 203\n315 204\n-138 -298\n-136 -295\n-134 -292\n-132 -...
UNKNOWN
PYTHON3
CODEFORCES
18
03db32b23169c055b48a935a37e2844e
Good Matrix Elements
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha...
[ "n = int(input())\r\ns, k = 0, n // 2\r\na, b, c = k - 1, k + 1, n - 1\r\nfor i in range(k):\r\n t = tuple(map(int, input().split()))\r\n s += t[i] + t[k] + t[c - i]\r\ns += sum(map(int, input().split()))\r\nfor i in range(k):\r\n t = tuple(map(int, input().split()))\r\n s += t[b + i] + t[k] + t[a - i]\...
{"inputs": ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "1\n3", "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33", "3\n19 7 16\n12 15 5\n15 15 5", "3\n36 4 33\n11 46 32\n20 49 34", "3\n79 91 74\n33 82 22\n18 28 54", "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8...
UNKNOWN
PYTHON3
CODEFORCES
434
03edda8ff108e60d56a12e459a0e1a1f
Mahmoud and Ehab and the message
Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning. Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word ...
[ "def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n\r\n# For fast IO use sys.stdout.write(str(x) + \"\\n\") instead of print\r\nimport sys\r\nimport math\r\ninput = sy...
{"inputs": ["5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second", "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second", "1 1 1\na\n1000000000\n1 1\na", "1 1 10\na\n1000000000\n1 1\na a a a a a a a a a"], "outputs": ["107", "116", "1000000000", "10000000000"...
UNKNOWN
PYTHON3
CODEFORCES
47
040bb78bbb1dd5c653a6320cc380215f
They Are Everywhere
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ...
[ "import sys\r\nfrom collections import Counter\r\n\r\nread = sys.stdin.readline\r\nwrite = sys.stdout.write\r\n\r\nn = int(read())\r\ns = read().strip()\r\ntypes = len(set(s))\r\n\r\nans = len(s)\r\n\r\nfrequencies = Counter()\r\nmatches = 0\r\n\r\nl = 0\r\nfor r in range(len(s)):\r\n frequencies[s[r]] += 1\r\n ...
{"inputs": ["3\nAaA", "7\nbcAAcbc", "6\naaBCCe", "1\nA", "1\ng", "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "2\nAA", "4\nqqqE", "10\nrrrrroooro", "15\nOCOCCCCiCOCCCOi", "20\nVEVnVVnWnVEVVnEVBEWn", "25\ncpcyPPjPPcPPPPcppPcPpppcP", "30\nsssssAsesssssssssssssessssssss", "35\ngdXdddgddddddddggggXdbgdggdgdd...
UNKNOWN
PYTHON3
CODEFORCES
109
04143337bc6301f1c0a0f52dec037b2b
Secrets
Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of o...
[ "n=int(input())\r\nwhile n%3==0:\r\n n//=3\r\nprint((n-1)//3+1)", "n = int(input())\r\n\r\na = 1\r\n\r\nwhile n % a == 0:\r\n a *= 3\r\n\r\nprint ((n - 1) // a + 1)\r\n", "base,n=1,int(input())\r\nwhile(n%base==0):base*=3\r\nprint(n//base+1)", "from fractions import Decimal\nimport math\nn=Decimal(input()...
{"inputs": ["1", "4", "3", "8", "10", "100000000000000000", "99999999999999999", "50031545098999707", "16677181699666569", "72900000000000", "99999999999999997", "58061299250691018", "49664023559436051", "66708726798666276", "29442431889534807", "70414767176369958", "93886356235159944", "97626528902553453", "5201315788...
UNKNOWN
PYTHON3
CODEFORCES
44
0416ef6a5a2762f89c51ac4faf0ffdc7
Fishes
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size *n*<=×<=*m*, divided into cells of size 1<=×<=1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size *r*<=×<=*r*, designe...
[ "# https://codeforces.com/problemset/problem/912/D\r\nimport heapq\r\nfrom heapq import heappush as push\r\nfrom heapq import heappop as pop\r\n\r\nbase = 100009\r\nQ=[]\r\nused={}\r\nans=0\r\n\r\ndx = [0,0,-1,1]\r\ndy = [-1,1,0,0]\r\n\r\ndef f(x, y):\r\n x1, x2 = min(x, r-1), max(0, x-n+r)\r\n y1, y2 = mi...
{"inputs": ["3 3 2 3", "12 17 9 40", "1 1 1 1", "10 10 5 100", "7 1 1 4", "1000 1000 59 100000", "100000 100000 1000 100000", "100000 100000 100000 100000", "3 100000 2 88700", "200 100000 55 100000", "74 2 1 36", "2 59 1 112", "96 33 24 928", "20 78 8 997", "44 22 13 515", "68 66 33 2353", "96 7 4 534", "20 59 2 88", ...
UNKNOWN
PYTHON3
CODEFORCES
7
0437e878aba50d6c66e452cc1721fe0a
Inversion Counting
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=...
[ "n = int(input())\r\n\r\nlst = []\r\nfor x in input().split():\r\n lst.append(int(x))\r\n\r\nm = int(input())\r\npair = []\r\nfor x in range(m):\r\n (l, r) = map(int, input().split())\r\n pair.append((l, r))\r\n\r\nk = 0\r\nfor x in range(0, len(lst) - 1):\r\n for y in range(x + 1, len(lst)):\r\n ...
{"inputs": ["3\n1 2 3\n2\n1 2\n2 3", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3", "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5", "3\n2 1 3\n3\n2 3\n1 1\n1 3", "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1"], "outputs": ["odd\neven", "odd\nodd\nodd\neven", "odd\nodd\neven\nodd\neven", "even\neven\nodd", "even\nev...
UNKNOWN
PYTHON3
CODEFORCES
22
0440d4b084c8c1d84009e461ec1ace99
Monitor
Recently Luba bought a monitor. Monitor is a rectangular matrix of size *n*<=×<=*m*. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square *k*<=×<=*k* consisting entirely of broken pixels. She knows that *q* pix...
[ "import sys\nimport math\n# Fast input\ninput = sys.stdin.readline\n# Fast output\ndef print(*args, **kwargs):\n sep = kwargs.get('sep', ' ')\n end = kwargs.get('end', '\\n')\n file = kwargs.get('file', sys.stdout)\n flush = kwargs.get('flush', False)\n output = sep.join(map(str, args)) + end\n fi...
{"inputs": ["2 3 2 5\n2 1 8\n2 2 8\n1 2 1\n1 3 4\n2 3 2", "3 3 2 5\n1 2 2\n2 2 1\n2 3 5\n3 2 10\n2 1 100", "29 50 5 29\n21 42 1565821\n21 43 53275635\n21 44 2717830\n21 45 9579585\n21 46 20725775\n22 42 2568372\n22 43 9584662\n22 44 31411635\n22 45 5089311\n22 46 4960702\n23 42 11362237\n23 43 42200296\n23 44 18762146\...
UNKNOWN
PYTHON3
CODEFORCES
9
04481b5ba35a75a5c9e06aebb7a9aecb
none
A subsequence of length |*x*| of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is a string *x*<==<=*s**k*1*s**k*2... *s**k*|*x*| (1<=≤<=*k*1<=&lt;<=*k*2<=&lt;<=...<=&lt;<=*k*|*x*|<=≤<=|*s*|). You've got two strings — *s* and *t*. Let's consider all subsequences of string *s*, coinciding...
[ "import os, sys\r\nfrom io import BytesIO, IOBase\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buff...
{"inputs": ["abab\nab", "abacaba\naba", "abc\nba", "babbbbbaba\nab", "accbacabaa\nbada", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "hqxibotrjfqrgwrydtlpkzeqrkfgzdylfokmaguwafdgwltgvqobnouttrrfuavfkqcoqxk...
UNKNOWN
PYTHON3
CODEFORCES
2
0476ba2ad7a62519c2f6fdbd6fda8d81
Three-dimensional Turtle Super Computer
A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×<=1<=×<=1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbe...
[ "def check(d, i, j, l):\n global result, save\n if d[i][j][l] == 1:\n if d[i + 1][j][l] == 1 and d[i - 1][j][l] == 1:\n #save.append([i, j, l])\n result += 1\n return\n if d[i][j + 1][l] == 1 and d[i][j - 1][l] == 1:\n result += 1\n #save.ap...
{"inputs": ["2 2 3\n000\n000\n\n111\n111", "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111", "1 1 10\n0101010101", "1 1 1\n0", "1 1 1\n1", "3 1 1\n1\n\n1\n\n1", "3 1 1\n1\n\n0\n\n1", "1 3 1\n1\n1\n1", "1 3 1\n1\n0\n1", "1 1 3\n111", "1 1 3\n101", "1 1 3\n011", "1 1 3\n110", "1 1 1\n0", "1 1 1\n1", "1 1 1\n1", "...
UNKNOWN
PYTHON3
CODEFORCES
4
04864f2df7b493cedb5e2f8c34d74442
Mahmoud and Ehab and the wrong algorithm
Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is: Given an undirected tree consisting of *n* nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (*u*,<=*v*) that belongs to the tree, either *u* i...
[ "n=int(input())\r\nif n<6:\r\n print(-1)\r\nelse:\r\n print(1, 2)\r\n print(1, 3)\r\n print(1, 4)\r\n for i in range(5, n+1):\r\n print(2, i)\r\nfor i in range(2, n+1):\r\n print(1, i)\r\n \r\n \r\n ", "import sys\nfrom sys import stdout\n\ninput = sys.stdin.readline\ninf = f...
{"inputs": ["2", "8", "99", "100", "100000", "3212", "54321", "54320", "3", "4", "5", "6", "7", "67575", "99999", "2048", "2047", "2049", "10101", "11", "13", "21", "31", "43", "57", "73", "91", "111", "133", "157", "183", "211", "241", "273", "307", "343", "381", "421"], "outputs": ["-1\n1 2", "1 2\n1 3\n1 4\n2 5\n2 6...
UNKNOWN
PYTHON3
CODEFORCES
25
04e13680b7777e44cc9c0ac35893c010
Fractal
Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a...
[ "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input1():\r\n with open('input.txt') as fp:\r\n return fp.readlines()\r\n\r\n\r\ndef output1(ans: str):\r\n with open('output.txt', mode='w') as fp:\r\n fp.write(ans)\r\n\r\n\r\ndef input2():\r\n return [line.decode('utf-8') ...
{"inputs": ["2 3\n.*\n..", "3 2\n.*.\n***\n.*.", "2 1\n..\n..", "2 2\n*.\n*.", "2 2\n**\n*.", "2 2\n*.\n..", "2 3\n*.\n.*", "2 3\n..\n**", "2 3\n*.\n**", "2 4\n**\n..", "2 4\n*.\n.*", "2 4\n.*\n.*", "2 5\n.*\n*.", "2 5\n*.\n..", "2 5\n..\n*.", "2 5\n**\n*.", "3 1\n*..\n...\n..*", "3 2\n**.\n.**\n..*", "3 2\n..*\n***\n*...
UNKNOWN
PYTHON3
CODEFORCES
11
0508cbfc663dea93f2f87627fdcebe7e
none
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree. Recall that tree is a connected graph consisting of *n* vertices and *n*<=-<=1 edges. Limak chose a tree with *n* vertices. He has infinit...
[ "from collections import Counter\n\n\ndef tree(n, E):\n N = {i:set() for i in range(1, n+1)}\n for a, b in E:\n N[a].add(b)\n N[b].add(a)\n\n if max(len(s) for s in N.values()) <= 2:\n return True\n\n D = set()\n L = Counter()\n for n, s in N.items():\n if len(s) > 1:\n...
{"inputs": ["8\n1 2\n1 3\n1 6\n6 4\n6 7\n6 5\n7 8", "13\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13", "1", "20\n5 15\n20 4\n11 18\n1 14\n18 2\n14 17\n8 10\n13 1\n11 6\n14 16\n12 8\n9 3\n13 15\n8 17\n3 13\n1 18\n17 7\n9 20\n19 12", "50\n38 13\n29 35\n32 25\n34 1\n11 26\n26 14\n31 35\n10 40\n34 2\n28 ...
UNKNOWN
PYTHON3
CODEFORCES
1
0518fb8493dd93509d6e21921f277812
Graph And Its Complement
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes. In an undirected graph loops (edg...
[ "n, a, b = [int(x) for x in input().split()]\r\n\r\nflag = False\r\nif b > a:\r\n a, b = b, a\r\n flag = True\r\n\r\ndef possible(n, a, b):\r\n if a > n:\r\n return False\r\n \r\n if a > 1:\r\n return b == 1\r\n \r\n if a == 1:\r\n return n >= 4 or n == 1\r\n\r\nif possible...
{"inputs": ["3 1 2", "3 3 3", "5 1 1", "123 1 84", "2 1 1", "1 1 1", "3 1 1", "5 2 2", "1000 734 1", "1000 1 1000", "1000 1 1", "4 1 1", "4 4 1", "3 1 3", "2 1 2", "101 1 1", "102 1 1", "103 1 1", "104 1 1", "6 1 1", "3 2 1", "5 1 2", "4 1 2", "2 2 1", "3 3 1", "2 2 2", "1 1 1", "2 1 1", "2 1 2", "2 2 1", "2 2 2", "3 1...
UNKNOWN
PYTHON3
CODEFORCES
14
052458b267a31782153438b583a8d4da
none
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, '<=+<=' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are *n*<=+<=1 levels in the game and ZS the Coder start at the level 1. When ZS the Coder is at level *k*, he can : 1. Pr...
[ "import math\r\nn = int(input())\r\ndis = 2\r\n\r\nfor i in range(1, n + 1):\r\n ans = (i)*(i + 1)*(i + 1) - dis/i\r\n print(int(ans))\r\n dis = math.sqrt(dis + ans*i)\r\n", "import sys\r\ninput=sys.stdin.buffer.readline\r\nimport os\r\nfrom math import*\r\n\r\n\r\nn=int(input())\r\nprev=2\r\nk=1\r\nfor ...
{"inputs": ["3", "2", "4", "1", "100000", "2016", "12345", "99997", "99998", "9999", "99999", "17823", "22222", "29137", "7"], "outputs": ["2\n17\n46", "2\n17", "2\n17\n46\n97", "2", "2\n17\n46\n97\n176\n289\n442\n641\n892\n1201\n1574\n2017\n2536\n3137\n3826\n4609\n5492\n6481\n7582\n8801\n10144\n11617\n13226\n14977\n16...
UNKNOWN
PYTHON3
CODEFORCES
75
054ce7512149b0f6a34fc8b79aa13f5d
Inna and Nine
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nin...
[ "R=lambda:map(int,input().split())\r\nimport math as m\r\ns=input()\r\na=[]\r\nf=''\r\nfor i in range(1,len(s)):\r\n if(int(s[i])+int(s[i-1])==9):\r\n f+=s[i-1]\r\n else:\r\n f+=s[i-1]\r\n if(len(f)>=2):\r\n if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')):\r\n ...
{"inputs": ["369727", "123456789987654321", "1", "3636363636363454545454543636363636454545452727272727218181818181999111777", "1188", "121212912121291299129191219", "181818918181891918918181918189181818181891818191818191819189", "121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912...
UNKNOWN
PYTHON3
CODEFORCES
23
05568f0510335c290838d9a7505f1465
Physical Education
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of s...
[ "def vasya_and_physcult(count, a_str, b_str):\r\n size = int(count)\r\n a = list(map(int, a_str.split()))\r\n b = list(map(int, b_str.split()))\r\n changes_count = 0\r\n result = \"\"\r\n for i in range(size):\r\n current_index = i\r\n for j in range(i,size):\r\n if b[j] =...
{"inputs": ["4\n1 2 3 2\n3 2 1 2", "2\n1 100500\n1 100500", "3\n652586118 652586118 652586118\n652586118 652586118 652586118", "4\n681106577 681106577 675077178 675077178\n675077178 681106577 681106577 675077178", "5\n470138369 747764103 729004864 491957578 874531368\n874531368 729004864 491957578 747764103 470138369",...
UNKNOWN
PYTHON3
CODEFORCES
20
056de076ab150c454056758d41d8219c
Sereja and Array
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms: 1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. In...
[ "from collections import deque,Counter\nfrom math import *\nimport sys\nimport random\nfrom bisect import *\nfrom functools import reduce\nfrom sys import stdin\nimport copy\ninput = lambda: sys.stdin.readline().rstrip()\n\nn,m=map(int,input().split())\narr=list(map(int,input().split()))\nval = 0\nfor _ in range(m)...
{"inputs": ["10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9", "1 3\n1\n1 1 2\n2 1\n3 1", "1 1\n1\n3 1", "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539", "6 5\n545129895 918519812 2334334 5655406...
UNKNOWN
PYTHON3
CODEFORCES
49
05716554bbc7565df04ab6d6e39d8f9f
Complete the Word
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n...
[ "from sys import exit\r\n\r\nword = [x for x in input()]\r\n\r\nfor i in range(len(word) - 25):\r\n if len(word[i:i+26]) == 26 and \\\r\n len(set([x for x in word[i:i+26] if x != '?'])) == len([x for x in word[i:i+26] if x != '?']): #checking if there are no duplicated letters apart from the question mar...
{"inputs": ["ABC??FGHIJK???OPQR?TUVWXY?", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "??????????????????????????", "AABCDEFGHIJKLMNOPQRSTUVW??M", "QWERTYUIOPASDFGHJKL???????", "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z", "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N", ...
UNKNOWN
PYTHON3
CODEFORCES
50
0588fa72eb0c014d60c9745d2add7b81
Codehorses T-shirts
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not. ...
[ "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nd = {'S':0, 'L':0, 'M':0, 'XS':0, 'XL':0, 'XXS':0, 'XXL':0, 'XXXS':0, 'XXXL':0}\r\nfor i in range(n):\r\n d[input()[:-1]] += 1\r\nfor i in range(n):\r\n d[input()[:-1]] -= 1\r\n\r\nc = 0\r\nfor i in d:\r\n if d[i] > 0:\r\n c +=...
{"inputs": ["3\nXS\nXS\nM\nXL\nS\nXS", "2\nXXXL\nXXL\nXXL\nXXXS", "2\nM\nXS\nXS\nM", "1\nXXXL\nXXXL", "1\nM\nM", "4\nS\nL\nXXS\nXXS\nM\nL\nXXS\nXXL", "5\nXS\nXXXS\nL\nXS\nM\nXL\nS\nXS\nM\nXXXL", "1\nS\nM", "26\nS\nL\nM\nL\nS\nXXXS\nXXXS\nM\nXXXS\nXXXS\nM\nXXS\nM\nXXXL\nM\nXL\nXXXL\nXXXS\nXXL\nL\nM\nM\nL\nXL\nXS\nXXL\nX...
UNKNOWN
PYTHON3
CODEFORCES
11
059a71d9633f932c6edaabb9305ea26a
Mancala
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ...
[ "from re import I\r\n\r\n\r\na = list(map(int,input().split()))\r\nmax = 0\r\nfor i in range(14):\r\n if a[i]>0:\r\n j = i+1 \r\n add_to_every = a[i]//14\r\n rem = a[i]%14\r\n temp =[x for x in a]\r\n temp[i]=0\r\n temp = [x+add_to_every for x in temp]\r\n while r...
{"inputs": ["0 1 1 0 0 0 0 0 0 7 0 0 0 0", "5 1 1 1 1 0 0 0 0 0 0 0 0 0", "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1", "0 0 0 0 0 0 0 0 0 0 0 0 0 15", "1 0 0 0 0 1 0 0 0 0 1 0 0 0", "5 5 1 1 1 3 3 3 5 7 5 3 7 5", "787 393 649 463 803 365 81 961 989 531 303 407 579 915", "8789651 44...
UNKNOWN
PYTHON3
CODEFORCES
111
05ac57c4c15a08896e1efcdb65649bac
Numbers Joke
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer. The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). Output a single integer. Sample Input 3 Sample Output 27
[ "#-------------Program--------------\r\n#----Kuzlyaev-Nikita-Codeforces----\r\n#-------------Training-------------\r\n#----------------------------------\r\n\r\nr=[4, 22, 27, 58, 85, 94, 121, 166,\r\n 202, 265, 274, 319, 346, 355, 378, \r\n 382, 391, 438, 454, 483, 517, 526, \r\n 535, 562, 576, 588, 627, 634,...
{"inputs": ["3", "1", "2", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"], "outputs": ["27", "4", "22", "58", "85", "94", "121", "166", "202", "265", "274", "319", "346", "355", "378", "382", "391", "438", "454"...
UNKNOWN
PYTHON3
CODEFORCES
24
05c9845a84c52803655e2c54586f7453
Team
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
[ "n = int(input())\r\nk = 0\r\nfor i in range(n):\r\n arr = [int(i) for i in input().split()]\r\n if arr.count(1) > 1:\r\n k += 1\r\nprint(k)", "n=int(input())\nres=0\nfor i in range(n):\n messi=input()\n a,b,c=messi.split()\n a=int(a)\n b=int(b)\n c=int(c)\n s=a+b+c\n if s>=2:\n re...
{"inputs": ["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1", "1\n1 0 0", "2\n1 0 0\n1 1 1", "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "50\n...
UNKNOWN
PYTHON3
CODEFORCES
999
05f0b9b170e310374e26b71e9260191f
Cards with Numbers
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t...
[ "import sys\nsys.stdin = open(\"input.txt\", \"r\")\nsys.stdout = open(\"output.txt\", \"w\")\nn=int(input())\nd={}\nfor x,y in enumerate(input().split(),1):\n d.setdefault(y,[]).append(x)\nif any(len(d[i])%2!=0 for i in d):\n print(-1)\n exit(0)\nfor i in d:\n print(\"\\n\".join(\"{0} {1}\".format(*k) ...
{"inputs": ["3\n20 30 10 30 20 10", "1\n1 2", "5\n2 2 2 2 2 1 2 2 1 2", "5\n2 1 2 2 1 1 1 1 1 2", "5\n1 2 2 2 1 2 2 1 2 1", "5\n3 3 1 1 1 3 2 3 1 2", "5\n1 1 3 1 3 3 3 1 1 1", "5\n3 1 1 1 2 3 3 3 2 1", "5\n3 3 2 2 3 3 1 3 1 3", "5\n4 1 3 1 4 1 2 2 3 1", "100\n8 6 7 8 7 9 1 7 3 3 5 8 7 8 5 4 8 4 8 1 2 8 3 7 8 7 6 5 7 9 ...
UNKNOWN
PYTHON3
CODEFORCES
39
05f3813e54a31452a7c624ac072aa875
Little Artem and Time Machine
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset. Artem wants to create a basic multiset of integers. He wants these structure to support operations of three typ...
[ "from bisect import *\r\nu, v = {}, {}\r\nfor q in range(int(input())):\r\n a, t, x = map(int, input().split())\r\n if x not in u: u[x], v[x] = [], []\r\n if a < 3: insort([v, u][-a][x], t)\r\n else: print(bisect(u[x], t) - bisect(v[x], t))", "from math import inf\r\nfrom collections import *\r\nimpor...
{"inputs": ["6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5", "3\n1 1 1\n2 2 1\n3 3 1", "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n3 3 1000000000\n3 10 1000000000\n3 6 1000000000\n3 7 1000000000", "12\n1 9 1\n1 8 1\n1 7 1\n1 6 1\n1 1 1\n1 2 1\n1 3 1\n1 4 1\n2 5 1\...
UNKNOWN
PYTHON3
CODEFORCES
5
05fa03f3eb832b74a941e6432563aadd
Dima and Bacteria
Dima took up the biology of bacteria, as a result of his experiments, he invented *k* types of bacteria. Overall, there are *n* bacteria at his laboratory right now, and the number of bacteria of type *i* equals *c**i*. For convenience, we will assume that all the bacteria are numbered from 1 to *n*. The bacteria of ty...
[ "#!/usr/bin/env python3\nfrom sys import stdin\nfrom bisect import bisect_left, bisect_right\n \nINF = int(1e9)\n\ndef find(par, a):\n if par[a] == a:\n return a\n par[a] = find(par, par[a])\n return par[a]\n\ndef union(par, rnk, a, b):\n a = find(par,a)\n b = find(par,b)\n if a==b:\n ...
{"inputs": ["4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2", "3 1 2\n2 1\n1 2 0", "3 2 2\n2 1\n1 2 0\n2 3 1", "3 0 2\n1 2", "10 9 3\n4 4 2\n1 2 0\n2 4 0\n3 2 0\n5 6 0\n6 7 0\n7 8 0\n9 10 0\n1 5 2\n2 6 1", "10 9 1\n10\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n5 6 0\n6 7 0\n7 8 0\n8 9 0\n9 10 0", "10 0 10\n1 1 1 1 1 1 1 1 1 1", "16 20 4\n4 ...
UNKNOWN
PYTHON3
CODEFORCES
1
0615c80fbe63792e7a7c26d2d3476754
none
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two wo...
[ "from collections import Counter\n\ndef solve(n, t, c):\n possible = True\n res = [-1] * n\n taken = set()\n todo = set(range(n))\n for i in range(n):\n if c[t[i][0]] > 1:\n if t[i][1] in taken:\n return []\n res[i] = 1\n taken.add(t[i][1])\n ...
{"inputs": ["2\nDINAMO BYTECITY\nFOOTBALL MOSCOW", "2\nDINAMO BYTECITY\nDINAMO BITECITY", "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP", "3\nABC DEF\nABC EFG\nABD OOO", "3\nABC DEF\nABC EFG\nABC EEEEE", "3\nABC DEF\nABC EFG\nABD CABA", "3\nABC DEF\nABC EFG\nABD EABA", "1\nAAA AAA", "1\nAAAAAAAAAAAAAAAAAA...
UNKNOWN
PYTHON3
CODEFORCES
20
06173cd8b7ea515c61bf91fb1fbd4364
Checkpoints
Vasya takes part in the orienteering competition. There are *n* checkpoints located along the line at coordinates *x*1,<=*x*2,<=...,<=*x**n*. Vasya starts at the point with coordinate *a*. His goal is to visit at least *n*<=-<=1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints...
[ "from sys import stdin, stdout\r\ndef read():\r\n\treturn stdin.readline().rstrip()\r\n\r\ndef read_int():\r\n\treturn int(read())\r\n \r\ndef read_ints():\r\n\treturn list(map(int, read().split()))\r\n \r\ndef solve():\r\n\tn,a=read_ints()\r\n\tx=sorted(z-a for z in read_ints())\r\n\tif n==1:\r\n\t\tprint(0)\r\n\t...
{"inputs": ["3 10\n1 7 12", "2 0\n11 -10", "5 0\n0 0 1000 0 0", "1 0\n0", "2 1\n4 -8", "3 4\n4 2 4", "4 7\n8 -4 -10 6", "5 7\n8 3 1 6 4", "6 -9\n-10 -7 4 -7 0 3", "9 -3\n-10 -7 -3 -4 7 -6 10 -10 -7", "18 8\n19 18 20 11 16 12 20 17 15 11 16 13 20 13 14 16 10 12", "26 3\n20 15 19 20 17 10 15 20 16 14 19 12 18 15 14 16 13...
UNKNOWN
PYTHON3
CODEFORCES
15
062efed583eda19d45f4333603d05a53
Palindromic characteristics
Palindromic characteristics of string *s* with length |*s*| is a sequence of |*s*| integers, where *k*-th number is the total number of non-empty substrings of *s* which are *k*-palindromes. A string is 1-palindrome if and only if it reads the same backward as forward. A string is *k*-palindrome (*k*<=&gt;<=1) if and...
[ "def main():\r\n s = input()\r\n n = len(s)\r\n isPalindrome = [[False for i in range(n + 1)] for i in range(n + 1)]\r\n for i in range(n):\r\n isPalindrome[i][i] = True\r\n for i in range(n - 1, -1, -1):\r\n for j in range(i + 1, n):\r\n if (s[i] == s[j] and (i + 1 == j or i...
{"inputs": ["abba", "abacaba", "qqqpvmgd", "wyemcafatp"], "outputs": ["6 1 0 0 ", "12 4 1 0 0 0 0 ", "11 3 0 0 0 0 0 0 ", "11 1 0 0 0 0 0 0 0 0 "]}
UNKNOWN
PYTHON3
CODEFORCES
5
06386d77d27605b3fec1289bcc6af161
Bamboo Partition
Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are *n* bamboos in a row, and the *i*-th from the left is *a**i* meters high. Vladimir has just planted *n* bamboos in a ro...
[ "n, k = map(int, input().split())\na = list(map(int, input().split()))\nkq, sumA, u = 0, sum(a), 1\nwhile u <= k + sumA:\n d = (k + sumA)//u\n tongbichat = 0\n for i in range(n):\n tongbichat += d*((a[i]+d-1)//d) - a[i]\n if tongbichat <= k:\n kq = max(kq, d)\n r = (k + sumA)//u\n u ...
{"inputs": ["3 4\n1 3 5", "3 40\n10 30 50", "20 53\n32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59 18", "100 82\n51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 ...
UNKNOWN
PYTHON3
CODEFORCES
1
067e7234724da9d9c1cb31ab72d4a909
Magic Powder - 2
The term of this problem is the same as the previous one, the only exception — increased restrictions. The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a...
[ "def f(x):\r\n L=k\r\n for i in range(n):\r\n if(B[i]//A[i]<x):\r\n L=L-(A[i]*x-B[i])\r\n if(L<0):\r\n return True\r\n return False\r\np=input()\r\np=p.split()\r\nn=int(p[0])\r\nk=int(p[1])\r\nA=[int(i) for i in input().split()]\r\nB=[int(i) for i in input().split()]\r\n...
{"inputs": ["1 1000000000\n1\n1000000000", "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1", "3 1\n2 1 4\n11 3 16", "4 3\n4 3 5 6\n11 12 14 20", "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000", "20 925\n7 3...
UNKNOWN
PYTHON3
CODEFORCES
29
0681fa22f91c489c7e99aad261d5855a
Nicholas and Permutation
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th...
[ "def max_dist(n,a):\r\n minpos = a.index(min(a))\r\n maxpos = a.index(max(a))\r\n if minpos<maxpos:\r\n ldist=minpos\r\n rdist = n-maxpos-1\r\n if ldist>rdist:\r\n dist=maxpos\r\n else:\r\n dist=n-minpos-1\r\n else:\r\n ldist=maxpos\r\n rdi...
{"inputs": ["5\n4 5 1 3 2", "7\n1 6 5 3 4 7 2", "6\n6 5 4 3 2 1", "2\n1 2", "2\n2 1", "3\n2 3 1", "4\n4 1 3 2", "5\n1 4 5 2 3", "6\n4 6 3 5 2 1", "7\n1 5 3 6 2 4 7", "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8...
UNKNOWN
PYTHON3
CODEFORCES
173
06e6a39440ec9fd2a3aa96176416c5ee
k-th divisor
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). If *n* has less than *k* di...
[ "import sys\r\nimport math\r\nfrom collections import Counter\r\n\r\n# n = int(input())\r\n# a = list(map(int, input().split()))\r\n\r\nn, k = map(int, input().split())\r\nless = []\r\nmore = []\r\ni = 1\r\ncount = 0\r\nroot = int(math.sqrt(n))\r\n\r\nwhile i <= root :\r\n if n % i == 0 :\r\n less.append(...
{"inputs": ["4 2", "5 3", "12 5", "1 1", "866421317361600 26880", "866421317361600 26881", "1000000000000000 1000000000", "1000000000000000 100", "1 2", "4 3", "4 4", "9 3", "21 3", "67280421310721 1", "6 3", "3 3", "16 3", "1 1000", "16 4", "36 8", "49 4", "9 4", "16 1", "16 6", "16 5", "25 4", "4010815561 2", "49 3",...
UNKNOWN
PYTHON3
CODEFORCES
124
070bac60163b9e1c87fd09be5eaeae25
Lucky Sum of Digits
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
[ "a=int(input())\r\nfor i in range(a):\r\n for x in range(a):\r\n if 4*i+7*x==a:\r\n print('4'*i+'7'*x)\r\n exit()\r\nprint(-1)", "#IMPORTS \r\nfrom sys import stdin, stdout\r\n\r\n#INPUTS\r\nN = int(stdin.readline())\r\n\r\n#CODE \r\nSEVEN = 0\r\nFOUR = 0\r\nPOSS = True\r\nwhile(N%...
{"inputs": ["11", "10", "64", "1", "4", "7", "12", "1000000", "47", "100", "700", "485", "111", "85", "114", "474", "74", "1000", "1024", "4444", "45784", "10000", "9854", "186", "10416", "10417", "3840", "100000", "9876", "99999", "777777", "854759", "11000", "18951", "999999", "888887", "999998", "40008", "10691", "5...
UNKNOWN
PYTHON3
CODEFORCES
219
07177f40679304b8f0d506e8d92c9512
Team Olympiad
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
[ "n = int(input())\r\nx = list(map(int, input().split()))\r\na = [i + 1 for i, j in enumerate(x) if j == 1]\r\nb = [i + 1 for i, j in enumerate(x) if j == 2]\r\nc = [i + 1 for i, j in enumerate(x) if j == 3]\r\nif not a or not b or not c:\r\n print(0)\r\nelse:\r\n print(min(len(a), len(b), len(c)))\r\n for ...
{"inputs": ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2", "1\n2", "2\n3 1", "3\n2 1 2", "3\n1 2 3", "12\n3 3 3 3 3 3 3 3 1 3 3 2", "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2", "12\n3 1 1 1 1 1 1 2 1 1 1 1", "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 ...
UNKNOWN
PYTHON3
CODEFORCES
694
073164f4014b9db1f36759f83b7074e3
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n...
[ "n,m,k = map(int,input().split())\r\na = []\r\nfor i in range(m+1):\r\n a.append(int(input()))\r\nlast = format(a[-1], '#024b')\r\ncount = 0 \r\nres = 0\r\nfor i in range(m):\r\n count = 0\r\n tmp = format(a[i], '#024b')\r\n\r\n for j in range(24):\r\n if last[j]!=tmp[j]:\r\n count+=1\...
{"inputs": ["7 3 1\n8\n5\n111\n17", "3 3 3\n1\n2\n3\n4", "4 2 2\n5\n6\n7", "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10", "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1", "6 8 2\n46\n59\n38\n5\n13\n54\n26\n62\n18", "5 6 3\n16\n9\n24\n5\n17\n27\n20", "7 9 1\n27\n7\n12\n29\n51\n67\n9\n112\n62\n68", "9 20 2\n197\n45\n217\n9\n156\n335\n21\n90\n33\n...
UNKNOWN
PYTHON3
CODEFORCES
41
07492363653c8057e4b8cca99052bbec
Suspects
As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to *n*. After that, he asked each one: "Which one committed the crime?". Suspect number *i*...
[ "[n, m] = input().split()\r\nn = int(n)\r\nm = int(m)\r\n \r\narr = []\r\nps = []\r\nns = []\r\nsuspects = []\r\n\r\nfor i in range(0, n):\r\n a = input()\r\n a = int(a)\r\n arr.append(a)\r\n ps.append(0)\r\n ns.append(0)\r\n suspects.append(0)\r\n\r\nsum_ps = 0\r\nsum_ns = 0\r\nfor i in arr:\r\n ...
{"inputs": ["1 1\n+1", "3 2\n-1\n-2\n-3", "4 1\n+2\n-3\n+4\n-1", "1 0\n-1", "2 2\n+1\n+1", "2 1\n+2\n+1", "2 0\n-2\n-2", "3 1\n+2\n+3\n+3", "6 3\n+5\n+5\n+5\n+1\n+1\n+1", "4 3\n-4\n-3\n-1\n-3", "10 4\n-8\n+1\n-6\n-10\n+5\n-6\n-8\n-8\n-4\n-8", "10 5\n-4\n+4\n+4\n-9\n-9\n-4\n-4\n+2\n-9\n-4", "7 2\n+5\n+5\n+5\n-2\n+1\n-5\...
UNKNOWN
PYTHON3
CODEFORCES
10
074aa427f0a9d0b96a63e7af248d4ad5
Hard Process
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). The first line contains two integers *n...
[ "n, k = map(int, input().split())\na = list(map(int, input().split()))\n\n# Initialize variables\nleft = 0\nright = 0\nmax_length = 0\nmax_left = 0\nzero_count = 0\n\n# Iterate through the array\nwhile right < n:\n if a[right] == 0:\n zero_count += 1\n \n # If the number of zeros in the current wind...
{"inputs": ["7 1\n1 0 0 1 1 0 1", "10 2\n1 0 0 1 0 1 0 1 0 1", "1 0\n0", "1 0\n0", "7 0\n0 1 0 0 0 1 0", "7 2\n1 0 1 1 0 0 0", "7 3\n1 0 0 0 0 1 0", "3 0\n1 1 1", "1 0\n1", "2 0\n0 1", "1 1\n0", "3 1\n0 0 1", "2 0\n0 0", "3 1\n0 0 0", "7 7\n1 0 1 0 0 0 0", "1 1\n1", "3 0\n0 0 0", "7 3\n1 1 1 1 1 1 1", "10 3\n0 0 1 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
104
075ac97ff5b98f22b52883039bbd0352
I_love_\%username\%
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
[ "n = int(input())\r\nnumbers = list(map(int, input().split()))\r\nbest = worst = numbers[0]\r\namazing = 0\r\n\r\nfor current in numbers[1:]:\r\n if current < worst:\r\n worst = current\r\n amazing += 1\r\n if current > best:\r\n best = current\r\n amazing += 1\r\n\r\nprint(amazing...
{"inputs": ["5\n100 50 200 150 200", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "1\n6", "2\n2 1", "5\n100 36 53 7 81", "5\n7 36 53 81 100", "5\n100 81 53 36 7", "10\n8 6 3 4 9 10 7 7 1 3", "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "10\n1 3 3 4 6 7 7 8 9 10", "10\n1952 1862 1812 1746 1675 16...
UNKNOWN
PYTHON3
CODEFORCES
810
075aef5c4937c2c8ac9c008072e0cfb6
Automatic Door
There is an automatic door at the entrance of a factory. The door works in the following way: - when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, - when one or several people come to the door and it is open, all people immed...
[ "n1,m,a,d=list(map(int,input().split()))\r\nt=list(map(int,input().split()))\r\nfrom bisect import *\r\nfrom math import *\r\ninsort(t,a*n1)\r\npred=0\r\nk=0\r\nkpred=0\r\nn=0\r\nstep=d//a+1\r\nsol=0\r\nfl=0\r\nfor i in t:\r\n if (i > pred):\r\n if fl == 0:\r\n n=(i-pred+(pred%a))//a\r\n ...
{"inputs": ["1 1 3 4\n7", "4 3 4 2\n7 9 11", "10 10 51 69\n154 170 170 183 251 337 412 426 445 452", "70 10 26 17\n361 371 579 585 629 872 944 1017 1048 1541", "100 20 49 52\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 3944 4344 4390 4649 4800", "100 30 36 47\n44 155 275 390 464 532 1186 120...
UNKNOWN
PYTHON3
CODEFORCES
2
07674258e17dc495bf72c77045b75824
Devu and Partitioning of the Array
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him? Given an array consisting of distinct integers. Is it possible to partition the whole array into *k* disjoint non-empty pa...
[ "import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\n#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\na...
{"inputs": ["5 5 3\n2 6 10 5 9", "5 5 3\n7 14 2 9 5", "5 3 1\n1 2 3 7 5", "10 5 3\n194757070 828985446 11164 80016 84729 117765558 111730436 164044532 419732980 48834", "10 6 3\n861947514 34945 190135645 68731 44833 387988147 84308862 878151920 458358978 809653252", "10 8 3\n677037706 41099140 89128206 168458947 367939...
UNKNOWN
PYTHON3
CODEFORCES
12
0778aa7a20f7b27334849051c11f9602
Students and Shoelaces
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f...
[ "from collections import defaultdict\r\nn,m=map(int,input().split())\r\ndic=defaultdict(list)\r\nli=[0]*n\r\nfor i in range(m):\r\n u,v=list(map(int,input().split()))\r\n u=u-1\r\n v=v-1\r\n li[u]+=1\r\n li[v]+=1\r\n dic[u].append(v)\r\n dic[v].append(u)\r\nr=0\r\nfor i in range(n):\r\n res=...
{"inputs": ["3 3\n1 2\n2 3\n3 1", "6 3\n1 2\n2 3\n3 4", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "100 0", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "5 4\n1 4\n4 3\n4 5\n5 2", "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11", "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7", "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 ...
UNKNOWN
PYTHON3
CODEFORCES
237
07902d236432619d14659700820648c9
Print Check
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr...
[ "def main():\r\n n, m, k = map(int, input().split())\r\n lst = [[0] * m for _ in range(n)]\r\n rows = {}\r\n cols = {}\r\n for i in range(k):\r\n q, idx, a = map(int, input().split())\r\n if q == 1:\r\n rows[idx - 1] = (a, i)\r\n else:\r\n cols[idx - 1] = (a...
{"inputs": ["3 3 3\n1 1 3\n2 2 1\n1 2 2", "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1", "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1", "4 6 8\n1 2 1\n2 2 2\n2 5 2\n1 1 1\n1 4 1\n1 3 2\n2 1 1\n2 6 1", "2 2 3\n1 1 1\n1 2 1\n2 1 2", "1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 1 4", "2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7", "2 1 1\n1 2 10000...
UNKNOWN
PYTHON3
CODEFORCES
67
07989c83d8bc7dc0fdea38e2fd47631e
Limit
You are given two polynomials: - *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*. Calculate limit . The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤...
[ "import math\r\nimport time\r\nfrom collections import defaultdict,deque\r\nfrom sys import stdin,stdout\r\nfrom bisect import bisect_left,bisect_right,bisect\r\ndef gcd(a,b):\r\n if(b==0):\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\nn,m=map(int,stdin.readline().split())\r\na=list(map(int,st...
{"inputs": ["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2", "1 2\n5 3\n-3 2 -1", "1 2\n-4 8\n-2 5 -3", "3 2\n4 3 1 2\n-5 7 0", "2 1\n-3 5 1\n-8 0", "1 1\n-5 7\n3 1", "2 2\n-4 2 1\n-5 8 -19", "0 100\n1\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...
UNKNOWN
PYTHON3
CODEFORCES
26
07cfb7284bc4b16ef707dca90a4ae19b
Ciel and Flowers
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
[ "def f(x): return x // 3\r\n\r\nr, g, b = map(int, input().split())\r\nm = min(r, g, b)\r\nans = 0\r\nfor i in range(max(0, m - 30), m + 1):\r\n ans = max(ans, i + f(r - i) + f(g - i) + f(b - i))\r\nprint(ans)\r\n", "r,g,b = map(int, input().split(\" \"))\r\nres = 0\r\nres += r//3\r\nres += g//3\r\nres += b//3...
{"inputs": ["3 6 9", "4 4 4", "0 0 0", "0 3 6", "7 8 9", "8 8 9", "15 3 999", "32 62 92", "123456789 123456789 123456789", "3 5 5", "666806767 385540591 357848286", "80010646 727118126 817880463", "829651016 732259171 572879931", "242854896 442432924 180395753", "139978911 5123031 935395222", "553182792 10264076 395427...
UNKNOWN
PYTHON3
CODEFORCES
164
07e8e7ca410450aa80ee6f50332b2730
Nested Segments
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices ...
[ "from sys import stdin\r\n\r\nn = int(input())\r\nseg = []\r\ninp = stdin.readlines()\r\n\r\nfor i in range(n):\r\n l, r = map(int, inp[i].split())\r\n seg.append([l, r, i + 1])\r\n \r\n#seg.sort(key = lambda x: x[1], reverse = True)\r\nseg.sort(key = lambda x: x[0])\r\n\r\nif n == 1: print(-1, -1)\r\nelse...
{"inputs": ["5\n1 10\n2 9\n3 9\n2 3\n2 9", "3\n1 5\n2 6\n6 20", "1\n1 1000000000", "2\n1 1000000000\n1 1000000000", "2\n1 1000000000\n500000000 500000000", "2\n1 10\n2 10", "2\n10 20\n10 11", "3\n1 10\n10 20\n9 11", "3\n1 1\n2 3\n2 2", "4\n1 10\n2 11\n3 10000000\n3 100000000", "2\n3 7\n3 9", "3\n1 2\n2 3\n1 2", "3\n5 6...
UNKNOWN
PYTHON3
CODEFORCES
26
0805544b42a2fa2cf7c8af86b1828a24
Woodcutters
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
[ "n=int(input())\r\nif n==1:\r\n a=map(int,input().split())\r\n print(1)\r\nif n>1:\r\n s=[]\r\n b=0\r\n for i in range(n):\r\n a=list(map(int,input().split()))\r\n s.append(a)\r\n for i in range(1,len(s)-1):\r\n if s[i][0]-s[i-1][0]>s[i][1]:\r\n b+=1\r\n elif...
{"inputs": ["5\n1 2\n2 1\n5 10\n10 9\n19 1", "5\n1 2\n2 1\n5 10\n10 9\n20 1", "4\n10 4\n15 1\n19 3\n20 1", "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 ...
UNKNOWN
PYTHON3
CODEFORCES
119
0809402a1a60bd55b9c7d727fb789750
I'm Feeling Lucky!
You have one chip and one chance to play roulette. Are you feeling lucky? none Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). Sample Input Sample Output
[ "print(\"odd\")\r\n\t \t \t\t \t\t\t\r\n\t \t\t\t \t \r\n \t \t \t\t\t\t\r\n\t \t# ihgfuierhqfwerbvg qgjiowehfuebhwlgho;shg;ohawf;wohf;woehfa;wlfh\r\n\t \t\t\t\t\t \r\n\t \t\t\t \t\t\t\r\n \t\t \t\t \t \r\n \t \t\t\t\t", "#include <bits/stdc++.h>\r\nprint(\"odd\")\r\n\r\n \t \t\t \r\n\t \t...
{"inputs": ["1", "2"], "outputs": ["Red", "Red"]}
UNKNOWN
PYTHON3
CODEFORCES
6
081a9bd5d32d2b49603b55c4d22f0f1a
CGCDSSQ
Given a sequence of integers *a*1,<=...,<=*a**n* and *q* queries *x*1,<=...,<=*x**q* on it. For each query *x**i* you have to count the number of pairs (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=*n* and *gcd*(*a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*)<==<=*x**i*. is a greatest common divisor of *v*1,<=*v*2,<=...,<=*v**n*...
[ "import sys;I=sys.stdin.readline;from collections import defaultdict as DD\r\nR=lambda:map(int,I().split());n,=R();a=[*R()];q,=R();z,V=DD(int),DD(int)\r\ndef gcd(a,b):\r\n while a!=0:a,b=b%a,a\r\n return b\r\nfor x in a:\r\n cur=DD(int)\r\n for y in V:g=gcd(y,x);cur[g]+=V[y]\r\n cur[x]+=1;V=cur\r\n for y in V...
{"inputs": ["3\n2 6 3\n5\n1\n2\n3\n4\n6", "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000", "10\n2 2 4 3 2 4 4 2 4 2\n104\n3\n3\n1\n4\n1\n1\n4\n1\n1\n3\n1\n1\n4\n1\n1\n1\n4\n3\n1\n1\n4\n1\n1\n1\n1\n1\n4\n1\n1\n1\n4\n1\n1\n4\n1\n1\n1\n1\n1\n4\n4\n1\n3\n1\n4\n1\n1\n1\n4\n1\n2\n4\n1\n4\n1\n4\n1\n4\n3\n1\...
UNKNOWN
PYTHON3
CODEFORCES
14
081d8e6da4564dd6581c8fa783184064
Bear and Tower of Cubes
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side *a* has volume *a*3. A tower consisting of blocks with sides *a*1,<=*a*2,<=...,<=*a**k* has the total volume *a*13<=...
[ "def main():\n def f(n):\n if n < 8:\n return [n, n]\n a = int((n + .5) ** 0.3333333333333333)\n r1 = f(n - a * a * a)\n r1[1] += a * a * a\n a -= 1\n r2 = f(3 * a * (a + 1))\n r2[1] += a * a * a\n if r1 < r2:\n r1 = r2\n r1[0] ...
{"inputs": ["48", "6", "1", "994", "567000123", "123830583943", "3842529393411", "999999993700000", "2", "7", "8", "9", "112", "113", "114", "265", "995", "200385", "909383000", "108000000057", "385925923480002", "735412349812385", "980123123123123", "999088000000000", "409477218238716", "409477218238717", "40947721823...
UNKNOWN
PYTHON3
CODEFORCES
12
083a9815944008ba711925b5f50cf089
Quest
Polycarp is making a quest for his friends. He has already made *n* tasks, for each task the boy evaluated how interesting it is as an integer *q**i*, and the time *t**i* in minutes needed to complete the task. An interesting feature of his quest is: each participant should get the task that is best suited for him, d...
[ "from collections import defaultdict\n\n\nif __name__ == '__main__':\n n, T = [int(_) for _ in input().split()]\n data = defaultdict(list)\n for i in range(n):\n t, q = [int(_) for _ in input().split()]\n data[T - t].append(q)\n\n prev_level = []\n for level_id in range(1, T + 1):\n ...
{"inputs": ["5 5\n1 1\n1 1\n2 2\n3 3\n4 4", "5 5\n4 1\n4 2\n4 3\n4 4\n4 5", "2 2\n1 1\n2 10", "10 1\n1 732\n1 649\n1 821\n1 756\n1 377\n1 216\n1 733\n1 420\n1 857\n1 193", "26 5\n2 377\n3 103\n1 547\n2 700\n3 616\n5 363\n2 316\n5 260\n3 385\n2 460\n4 206\n4 201\n3 236\n1 207\n1 400\n2 382\n2 365\n1 633\n1 775\n4 880\n1...
UNKNOWN
PYTHON3
CODEFORCES
2
084b9cdce2412ac171a9ce35f14235bf
A and B and Compilation Errors
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix...
[ "n = int(input())\r\n# n, m = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\narr2 = sorted(list(map(int, input().split())))\r\narr3 = sorted(list(map(int, input().split())))\r\n\r\nfor i in range(n):\r\n if i == n-1:\r\n print(arr[i])\r\n break\r\n\r\n if arr[i] !=...
{"inputs": ["5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "3\n1 2 3\n3 2\n2", "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 38...
UNKNOWN
PYTHON3
CODEFORCES
469
085cd5f8330878529b11be96555d4370
Modular Exponentiation
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108)....
[ "from math import log2\r\nn = int(input())\r\nm = int(input())\r\nif log2(m) >= n:\r\n print(m % 2**n)\r\nelse:\r\n print(m)", "def modular_exponentiation(n, m):\n return m % 2 ** n\n\nif __name__ == \"__main__\":\n n = int(input())\n m = int(input())\n invertido = modular_exponentiation(n, m)\n print(...
{"inputs": ["4\n42", "1\n58", "98765432\n23456789", "8\n88127381", "32\n92831989", "92831989\n25", "100000000\n100000000", "7\n1234", "1\n1", "1\n100000000", "100000000\n1", "1\n2", "2\n1", "2\n2", "2\n3", "2\n4", "2\n5", "25\n33554432", "26\n33554432", "25\n67108864", "26\n67108864", "25\n92831989", "26\n92831989", "2...
UNKNOWN
PYTHON3
CODEFORCES
207
0882f289635cddade3200c48974d967a
Summer sell-off
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag...
[ "n,f = list(map(int,input().split()))\r\nout = []\r\ndata = []\r\nans = 0\r\nfor i in range(n):\r\n a,b = list(map(int,input().split()))\r\n ans += min(a,b)\r\n out.append(min(a*2,b)- min(a,b))\r\nout.sort(reverse=True)\r\nfor i in range(f):\r\n ans+=out[i]\r\n\r\nprint(ans)", "n, f = list(map(int, in...
{"inputs": ["4 2\n2 1\n3 5\n2 3\n1 5", "4 1\n0 2\n0 3\n3 5\n0 6", "1 1\n5 8", "2 1\n8 12\n6 11", "2 1\n6 7\n5 7", "2 1\n5 7\n6 7", "2 1\n7 8\n3 6", "2 1\n9 10\n5 8", "2 1\n3 6\n7 8", "1 0\n10 20", "2 1\n99 100\n3 6", "4 2\n2 10\n3 10\n9 9\n5 10", "2 1\n3 4\n2 8", "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n...
UNKNOWN
PYTHON3
CODEFORCES
161
088b9540ecc22ef3dbc2ddd6c0379edb
Mysterious numbers - 1
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. Output a single integer. The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. Output a single integer. Sample Input 3 14 27 12 100 200 Sample Output 44 48 102
[ "# LUOGU_RID: 101709040\na=input().split()\r\na[1]=a[1][-1::-1]\r\nprint(int(a[0])+int(a[1]))", "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: jalpaiguri Govt Enggineerin College\r\n Date:30/03/2020\r\n'''\r\nfrom math import gcd,sqrt,ceil\r\ndef ii():return int(input())\r\ndef mi():return map(i...
{"inputs": ["3 14", "27 12", "100 200", "0 0", "31415 92653", "1000000000 0", "0 1000000000", "1000000000 1000000000", "804289383 846930886", "681692777 714636915", "957747793 424238335", "719885386 649760492", "596516649 189641421", "25202362 350490027", "783368690 102520059", "44897763 967513926", "365180540 54038342...
UNKNOWN
PYTHON3
CODEFORCES
134
088e63003cb5ff192da74dde87343ee2
Cubes for Masha
Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a ro...
[ "n=int(input())\r\nL=[]\r\nfor i in range(n):\r\n L.append(list(map(int,input().split())))\r\n\r\nfor i in range(1,100):\r\n t=str(i)\r\n b=False\r\n if len(t)==1:\r\n for j in range(len(L)):\r\n if i in L[j]:\r\n b=True\r\n break\r\n if b==False:\r...
{"inputs": ["3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9", "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5", "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8", "1\n5 2 2 5 6 7", "1\n7 6 5 8 9 0", "1\n2 5 9 6 7 9", "1\n6 3 1 9 4 9", "1\n1 9 8 3 7 8", "2\n1 7 2 0 4 3\n5 2 3 6 1 0", "2\n6 0 1 7...
UNKNOWN
PYTHON3
CODEFORCES
66
088f715b6f6f4cbc5ca4bf8d45009bac
Shark
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the d...
[ "def main():\r\n n = int(input())\r\n ori_a = [int(x) for x in input().split()]\r\n pos = {ori_a[i]: i for i in range(len(ori_a))}\r\n seg = [dict(left=None, right=None) for i in range(len(ori_a))]\r\n \r\n a = sorted(ori_a)\r\n seg_size = 0\r\n seg_num = 0\r\n fi_k = a[0]\r\n fi_seg_num ...
{"inputs": ["8\n1 2 7 3 4 8 5 6", "6\n25 1 2 3 14 36", "20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11", "7\n1 2 5 7 3 4 6", "1\n1000000000", "1\n1", "2\n1 2", "2\n2 1", "22\n22 1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11 21", "63\n32 48 31 56 30 47 29 60 28 46 27 55 26 45 25 62 24 44 23 54 22 43 21 59 2...
UNKNOWN
PYTHON3
CODEFORCES
5
089b8a488dba959a972c0b836cdecbcb
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of *n* rows and *m* columns. Each cell consis...
[ "import queue\r\nMAX = 500\r\ndr = [0,0,1,-1]\r\ndc = [1,-1,0,0]\r\n \r\ndef isValid(r, c):\r\n return r in range(m) and c in range(n)\r\n \r\ndef BFS(sr, sc, fr, fc):\r\n q = [0] * (MAX * MAX)\r\n left = right = 0\r\n q[0] = (sr, sc)\r\n while left <= right:\r\n ur, uc = q[left]\r\n left += 1\r\n for...
{"inputs": ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "5 3\n.XX\n...\n.X.\n.X.\n...\n1 3\n4 1", "1 1\nX\n1 1\n1 1", "1 6\n.X...X\n1 2\n1 5", "7 1\nX\n.\n.\n.\nX\n.\n.\n5 1\n3 1", "1 2\nXX\n1 1\n1 1", "2 1\n.\nX\n2...
UNKNOWN
PYTHON3
CODEFORCES
10
08aee82431bd65836b8729845b0259d3
Building Permutation
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
[ "def solve (n,seq) :\r\n seq.sort()\r\n start = 1\r\n moves = 0\r\n while start <= n :\r\n if seq[start-1] != start :\r\n moves += abs(seq[start-1] - start)\r\n start += 1\r\n \r\n \r\n return moves\r\n \r\n \r\nn = int(input())\r\nseq = list(map(int,input...
{"inputs": ["2\n3 0", "3\n-1 -1 2", "5\n-3 5 -3 3 3", "10\n9 6 -2 4 1 1 1 9 6 2", "9\n2 0 0 6 5 4 1 9 3", "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 9...
UNKNOWN
PYTHON3
CODEFORCES
473