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
71036523df309a43e8e98745069c0f05
Palindromic Times
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th...
[ "s = input()\r\ns1 = s\r\ns1 = s1.split(\":\")\r\ns1[0] = int(s1[0])\r\ns1[1] = int(s1[1])\r\nwhile(1):\r\n s1[1] += 1\r\n s1[1] = s1[1]%60\r\n if s1[1] == 0:\r\n s1[0] += 1\r\n s1[0] = s1[0]%24\r\n a = str(s1[0])\r\n b = str(s1[1])\r\n if len(a) == 1:\r\n a = \"0\" + a\r\n ...
{"inputs": ["12:21", "23:59", "15:51", "10:44", "04:02", "02:11", "12:15", "07:07", "00:17", "04:55", "02:17", "07:56", "00:29", "23:31", "19:30", "12:14", "17:32", "03:44", "07:15", "18:42", "08:56", "04:50", "14:32", "23:23", "08:35", "03:32", "07:59", "14:12", "23:52", "16:36", "17:50", "06:59", "16:50", "00:00", "2...
UNKNOWN
PYTHON3
CODEFORCES
151
7106a5a4ccf392528293f254daca3836
Permutations
You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum: Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt*...
[ "import itertools\nn, m = tuple(int(x) for x in input().split())\nlstN = [x for x in range(1,n+1)]\n\ndef funcP(seq):\n\tres = 0\n\tfor i in range(len(seq)):\n\t\tfor j in range(i, len(seq)):\n\t\t\tres += min(seq[i:j+1])\n\treturn res\n\nallPerm = [(perm,funcP(perm)) for perm in itertools.permutations(lstN)]\nallP...
{"inputs": ["2 2", "3 2", "1 1", "3 1", "3 3", "3 4", "4 1", "4 3", "4 4", "4 8", "5 2", "5 7", "5 15", "6 23", "7 7", "7 44", "8 1", "8 127", "8 128"], "outputs": ["2 1 ", "1 3 2 ", "1 ", "1 2 3 ", "2 3 1 ", "3 2 1 ", "1 2 3 4 ", "1 3 4 2 ", "1 4 3 2 ", "4 3 2 1 ", "1 2 3 5 4 ", "1 4 5 3 2 ", "4 5 3 2 1 ", "2 5 6 4 3 ...
UNKNOWN
PYTHON3
CODEFORCES
48
713151a56baa3874daf5f2778bd1c45e
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<...
[ "_, values,i,years = int(input()),[int(i) for i in input().split(\" \")],1,[]\nif 1 in values:\n\tyears.append(values.index(1))\n\ti=2\n\twhile i in values[years[-1]:]:\n\t\tyears.append(values[years[-1]:].index(i)+years[-1])\n\t\ti+=1\nprint(len(years))\nif len(years) !=0:\n\tfor year in years:\n\t\tprint(2001+yea...
{"inputs": ["10\n-2 1 1 3 2 3 4 -10 -2 5", "3\n-1 -2 -3", "1\n0", "1\n0", "2\n-1 1", "2\n-1 1", "2\n-2 0", "2\n3 -3", "3\n1 1 1", "3\n-2 -2 1", "4\n-4 2 3 -1", "5\n-3 -3 -4 2 -2", "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 ...
UNKNOWN
PYTHON3
CODEFORCES
52
7138af4685444691c2b25b0bdce983e3
Destruction of a Tree
You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given t...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nif n%2 == 0:\r\n print(\"NO\")\r\n exit()\r\nparent = list(map(int,input().split()))\r\nprint(\"YES\")\r\ns = [0]*n\r\nG = [[] for _ in range(n)]\r\nroot = -1\r\nfor i in range(n):\r\n parent[i] -= 1 \r\n if parent[i] != -1:\r\n ...
{"inputs": ["5\n0 1 2 1 2", "4\n0 1 2 3", "1\n0", "8\n3 1 4 0 4 2 4 5", "100\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33 46 19 22 83 56 67 62 82 57 16 29 36 84 71 42 66 78 54 73 45 82 80 67 88 79 69 61 66 5 36 24 60 96 21 77 67 68 29 87 37 91 34 78 43 0 69 49 62 16 2 68 79 57 1 60 12 39 99 14 37 30 9...
UNKNOWN
PYTHON3
CODEFORCES
2
716e110f0464198d037e1dd300a49754
Bear and Five Cards
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards wi...
[ "list1 = list(map(int,input().split()))\r\nn =0\r\nfor i in set(list1):\r\n if (list1.count(i)>1):\r\n n = max(n,i*min(3,list1.count(i)))\r\nprint(sum(list1)-n) \r\n ", "t = sorted(list(map(int, input().split())))\r\nb = []\r\nfor i in range(5):\r\n\tif t.count(t[i])>1:\r\n\t\tif t.count(t[i])>3:...
{"inputs": ["7 3 7 3 20", "7 9 3 1 8", "10 10 10 10 10", "8 7 1 8 7", "7 7 7 8 8", "8 8 8 2 2", "8 8 2 2 2", "5 50 5 5 60", "100 100 100 100 100", "1 1 1 1 1", "29 29 20 20 20", "20 29 20 29 20", "31 31 20 20 20", "20 20 20 31 31", "20 31 20 31 20", "20 20 20 30 30", "30 30 20 20 20", "8 1 8 8 8", "1 1 1 8 1", "1 2 3 4...
UNKNOWN
PYTHON3
CODEFORCES
133
7191b886b2342aa9f0bc1752ce01932b
Pasha and String
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ...
[ "I=input\r\ns=list(I())\r\nS=len(s)\r\nn=int(I())\r\nt=0\r\n*l,=sorted(map(int,I().split()))\r\nfor i in range(S//2):\r\n while t<n and l[t]<=i+1:t+=1\r\n if t%2:s[i],s[S-i-1]=s[S-i-1],s[i]\r\nprint(''.join(s))", "x=list(input())\r\nl=len(x)\r\nc=input()\r\nlst=[0]*(l//2+1)\r\nfor i in input().split():\r\n ...
{"inputs": ["abcdef\n1\n2", "vwxyz\n2\n2 2", "abcdef\n3\n1 2 3", "jc\n5\n1 1 1 1 1", "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3", "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12", "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybe...
UNKNOWN
PYTHON3
CODEFORCES
104
71bdb35746c7c54bba2602aa6767893a
Arthur and Brackets
Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2*n*. Unlike Arthur, Sasha understood the top...
[ "n = int(input())\nL = [tuple(map(int, input().split(' '))) for i in range(n)]\nans = []\ntry :\n for l,r in reversed(L) :\n d,a=1,\"(\"\n while d < l :\n d += len(ans[-1])\n a += ans.pop()\n if d > r : raise IndexError\n a += \")\"\n ans.append(a)\nexcept...
{"inputs": ["4\n1 1\n1 1\n1 1\n1 1", "3\n5 5\n3 3\n1 1", "3\n5 5\n3 3\n2 2", "3\n2 3\n1 4\n1 4", "6\n1 5\n2 4\n1 1\n1 1\n1 1\n1 1", "3\n1 4\n2 2\n1 1", "5\n1 3\n2 5\n3 4\n1 2\n1 9", "2\n3 3\n3 3", "1\n1 1", "10\n9 9\n5 5\n1 1\n1 1\n13 13\n11 11\n1 1\n5 5\n1 1\n1 1", "50\n97 97\n61 61\n59 59\n29 29\n13 13\n7 7\n5 5\n3 3...
UNKNOWN
PYTHON3
CODEFORCES
1
71e025842157ee5552327ed027b3b6d3
Substring
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the large...
[ "from collections import defaultdict, deque\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nl = list(input())\r\ndeg = [0 for i in range(n)]\r\ngraph = defaultdict(list)\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n graph[...
{"inputs": ["5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "1 1\nf\n1 1", "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\...
UNKNOWN
PYTHON3
CODEFORCES
24
71f7922bb52860546e0b6c4ad6365d5d
Quasi-palindrome
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str...
[ "s=input()\r\ns=s[::-1]\r\ns=str(int(s))\r\nif s==s[::-1]:\r\n print('YES')\r\nelse:\r\n print('NO')", "x=list(input())\r\nx.reverse()\r\ng=False\r\nwhile len(x)>1:\r\n if x[0]=='0' and g==False:\r\n x.pop(0)\r\n else:\r\n g=True\r\n if x[0]!=x[-1]:\r\n print('NO')\r\n ...
{"inputs": ["131", "320", "2010200", "1", "1000000000", "999999999", "999999998", "102000", "210000000", "213443120", "99", "22002", "1010", "1201", "6460046", "503435", "21002", "101001", "200102", "20010002", "33003", "100101", "1021", "1101", "10101100", "101", "1011", "11010", "10110", "110000", "2011", "10020001",...
UNKNOWN
PYTHON3
CODEFORCES
246
72154bce8f297ac2e3f2dbe058abef0e
Marvolo Gaunt's Ring
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he...
[ "def main():\r\n n, p, q, r = map(int, input().split())\r\n a = list(map(int, input().split()))\r\n ans = -float('inf')\r\n mx = -float('inf')\r\n mx1 = -float('inf')\r\n for i in range(n):\r\n mx = max(mx, a[i] * p)\r\n mx1 = max(mx1, mx + a[i] * q)\r\n ans = max(ans, mx1 + a...
{"inputs": ["5 1 2 3\n1 2 3 4 5", "5 1 2 -3\n-1 -2 -3 -4 -5", "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 7001...
UNKNOWN
PYTHON3
CODEFORCES
96
72192ff030fb3bf908ee666a246cd70b
Mentors
In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$. A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a &gt; r_b)$ and programmers $a$ and $b$ are not in a quarrel. You are...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom bisect import *\r\n\r\nN,K = map(int, input().split())\r\nR = list(map(int, input().split()))\r\n\r\nA = sorted(R)\r\n\r\nP = [[] for _ in range(N)]\r\nfor _ in range(K):\r\n u,v = map(int, input().split())\r\n u-=1;v-=1\r\n P[u].append(R...
{"inputs": ["4 2\n10 4 10 15\n1 2\n4 3", "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "2 0\n3 1", "2 0\n1 1", "10 35\n322022227 751269818 629795150 369443545 344607287 250044294 476897672 184054549 986884572 917181121\n6 3\n7 3\n1 9\n7 9\n10 7\n3 4\n8 6\n7 4\n6 10\n7 2\n3 5\n6 9\n3 10\n8 7\n6 5\n8 1\n8 5\n1 7\n8 1...
UNKNOWN
PYTHON3
CODEFORCES
22
7228f18da7fed17083cc15458e82d310
Domino piling
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
[ "# n = int(input())\r\n# words = [input() for i in range(n)]\r\n# def shorter(word):\r\n# if len(word) <= 10:\r\n# return word\r\n# else:\r\n# return word[0] + str(len(word)-2) + word[-1]\r\n\r\n# for i in words:\r\n# print(shorter(i))\r\n\r\n\r\n# n = int(input())\r\n# sol = [input().sp...
{"inputs": ["2 4", "3 3", "1 5", "1 6", "1 15", "1 16", "2 5", "2 6", "2 7", "2 14", "2 15", "1 4", "2 16", "3 5", "3 6", "3 10", "3 14", "3 15", "3 16", "5 7", "16 16", "15 16", "2 3", "15 15", "14 16", "11 13", "5 16", "8 15", "2 2", "3 4", "4 4", "1 1", "1 2", "1 3", "14 15"], "outputs": ["4", "4", "2", "3", "7", "8...
UNKNOWN
PYTHON3
CODEFORCES
3,908
722da95a33955b90c2bf82a34b3bb610
Pig and Palindromes
Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of *n* rows and *m* columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to *n*, and the columns — from left to right with numbers from 1 to *m*. Let's ...
[ "\r\nimport sys\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())\r\nprint = lambda d: sys.stdout.write(str(d) + \"\\n\") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。\r\n\r\nMOD = 10 ** 9 + 7\r...
{"inputs": ["3 4\naaab\nbaaa\nabba", "2 2\nab\naa", "3 5\nqqqrw\nwqqtw\newqqq", "1 5\nabbba", "1 5\nabbbb", "1 4\nabca", "5 1\na\na\na\na\na", "5 2\nab\nab\ncc\nba\nba", "5 3\naba\naba\nccc\nbaa\nbaa", "5 5\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa", "5 5\naaaaa\nadaaa\naaaaa\naaaaa\naacaa", "5 5\naaaqa\naaaaa\naaaaa\naaaaa\n...
UNKNOWN
PYTHON3
CODEFORCES
5
72392bfc46fcb8be3645ce5e5dc8ca05
Mountain Scenery
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th...
[ "n , k = [int(x) for x in input().split()]\r\n\r\ncords = [int(x) for x in input().split()]\r\n\r\ncounter = 1\r\nfor e in range(k):\r\n changed = False\r\n while not changed:\r\n if cords[counter] - cords[counter - 1] > 1 and cords[counter] - cords[counter + 1] > 1:\r\n changed = True\r\n ...
{"inputs": ["3 2\n0 5 3 5 1 5 2", "1 1\n0 2 0", "1 1\n1 100 0", "3 1\n0 1 0 1 0 2 0", "3 1\n0 1 0 2 0 1 0", "3 3\n0 100 35 67 40 60 3", "7 3\n1 2 1 3 1 2 1 2 1 3 1 3 1 2 1", "100 100\n1 3 1 3 1 3 0 2 0 3 1 3 1 3 1 3 0 3 1 3 0 2 0 2 0 3 0 2 0 2 0 3 1 3 1 3 1 3 1 3 0 2 0 3 1 3 0 2 0 2 0 2 0 2 0 2 0 3 0 3 0 3 0 3 0 2 0 3 ...
UNKNOWN
PYTHON3
CODEFORCES
128
724a4c13f3ca6aa5877b722fc19e0413
Resource Distribution
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units. In order for production to work, it ...
[ "I = lambda:list(map(int, input().split()))\r\nn,x1,x2 = I()\r\nservers = I()\r\nidx = list(range(n))\r\nidx.sort(key = lambda i : servers[i])\r\n\r\ndef solve(a, b, rev):\r\n j = len(idx)-1\r\n while j >= 0 and (n-j)*servers[idx[j]] < b:\r\n j -= 1\r\n if j < 0:\r\n return\r\n i = j-1\r\n...
{"inputs": ["6 8 16\n3 5 2 9 8 7", "4 20 32\n21 11 11 12", "4 11 32\n5 5 16 16", "5 12 20\n7 8 4 11 9", "2 1 1\n1 1", "2 1 1\n1 1000000", "2 1 1\n1000000000 1000000000", "2 1 2\n1 1", "15 250 200\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41", "4 12 11\n4 4 6 11"], "outputs": ["Yes\n4 2\n3 1 2 6\n5 4", "Yes\n1 3\n1\n2 ...
UNKNOWN
PYTHON3
CODEFORCES
8
72820233354134500e4063498a6717f0
Weird Rounding
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*. In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t...
[ "def f():\n ipt = input().strip().split()\n k = int(ipt[1])\n ns = ipt[0]\n a = [int(i) for i in ns]\n n = len(a)\n flag = 1\n for i in a:\n if i== 0:\n flag = 0\n break\n \n if n< k+1:\n if flag==0:\n print(n-1)\n return\n ...
{"inputs": ["30020 3", "100 9", "10203049 2", "0 1", "0 9", "100 2", "102030404 2", "1000999999 3", "12000000 4", "1090090090 5", "10 1", "10 2", "10 9", "100 1", "100 3", "101010110 3", "101010110 1", "101010110 2", "101010110 4", "101010110 5", "101010110 9", "1234567890 1", "1234567890 2", "1234567890 9", "200000000...
UNKNOWN
PYTHON3
CODEFORCES
179
72b27ecee4e2a8f3268f429ae77dad23
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair ...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn=int(input())\r\nE=[[] for i in range(n+1)]\r\n\r\nfor i in range(n-1):\r\n x,y=map(int,input().split())\r\n E[x].append(y)\r\n E[y].append(x)\r\n\r\nK=list(map(int,input().split()))\r\n\r\ndef dfs(fr,target):\r\n Q=[fr]\r\n USE=[-1]*(n+1)\r\n\r\n ...
{"inputs": ["3\n1 2\n2 3\n3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4 8", "8\n4 3\n6 7\n8 6\n6 1\n4 6\n6 5\n6 2\n3 2 7 8 5", "8\n4 3\n1 4\n8 5\n7 6\n3 5\n7 3\n4 2\n2 6 8", "20\n4 13\n17 7\n19 10\n18 1\n5 15\n2 6\n11 7\n3 6\n5 1...
UNKNOWN
PYTHON3
CODEFORCES
13
72b42c09aa731632c82d0fda042cc4d8
Lucky Subsequence
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence *a* consisting of *n* integers. The subsequence of the sequence *a* is such su...
[ "import sys\nMOD = 10 ** 9 + 7\ndef is_lucky(n):\n n = str(n)\n return n.count('4') + n.count('7') == len(n)\ndef get_inv(n):\n return pow(n, MOD - 2, MOD)\ndef c(n, k):\n if n < k or k < 0:\n return 0\n global fact, rfact\n return (fact[n] * rfact[k] * rfact[n - k]) % MOD\n \nfact = [1]\nr...
{"inputs": ["3 2\n10 10 10", "4 2\n4 4 7 7", "7 4\n1 2 3 4 5 6 7", "7 4\n7 7 7 7 7 7 7", "10 1\n1 2 3 4 5 6 7 8 9 10", "10 7\n1 2 3 4 5 6 7 8 9 10", "20 7\n1 4 5 8 47 777777777 1 5 4 8 5 9 5 4 7 4 5 7 7 44474", "5 2\n47 47 47 47 47", "13 5\n44 44 44 44 44 44 44 44 77 55 66 99 55", "3 2\n1 47 47", "2 2\n47 47", "2 2\n44...
UNKNOWN
PYTHON3
CODEFORCES
3
72bbbcff66eb716aa7bc1702a512ce3d
Dima and Guards
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b...
[ "n = int(input())\na = list(map(int, input().split(' ')))\nb = list(map(int, input().split(' ')))\nc = list(map(int, input().split(' ')))\nd = list(map(int, input().split(' ')))\ncost = []\ncost.append(min(a[0],a[1])+min(a[2],a[3]))\ncost.append(min(b[0],b[1])+min(b[2],b[3]))\ncost.append(min(c[0],c[1])+min(c[2],c[...
{"inputs": ["10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3", "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000", "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1", "100\n1 1 2 2\n1...
UNKNOWN
PYTHON3
CODEFORCES
57
72d25ec743d032211913d9611cd07a45
Square Earth?
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side *n*. T...
[ "n,x1,y1,x2,y2 =map(int, input().split())\r\ndef f(x,y,n):\r\n if y==0 or x==n:\r\n return x+y\r\n else:\r\n return 4*n - x - y\r\na = abs(f(x1,y1,n) - f(x2,y2,n))\r\nprint(min(a, 4*n-a))\r\n", "def dis(x,y,d):\r\n if y==0 or x==d:\r\n return x+y\r\n else:\r\n return 4*d - ...
{"inputs": ["2 0 0 1 0", "2 0 1 2 1", "100 0 0 100 100", "4 0 3 1 4", "10 8 10 10 0", "26 21 0 26 14", "15 0 1 11 0", "26 26 7 26 12", "6 6 0 2 6", "5 1 5 2 5", "99 12 0 35 99", "44 44 31 28 0", "42 42 36 5 0", "87 87 66 0 5", "85 0 32 0 31", "30 20 30 3 0", "5 4 0 5 1", "40 24 40 4 0", "11 0 2 11 4", "82 0 11 35 0", "...
UNKNOWN
PYTHON3
CODEFORCES
28
7307aab67e8176e638767b6378a44995
Chocolate Bar
You have a rectangular chocolate bar consisting of *n*<=×<=*m* single squares. You want to eat exactly *k* squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or ve...
[ "from collections import defaultdict, deque, Counter\r\nfrom heapq import heapify, heappop, heappush\r\nimport math\r\nfrom copy import deepcopy\r\nfrom itertools import combinations, permutations, product, combinations_with_replacement\r\nfrom bisect import bisect_left, bisect_right\r\n\r\nimport sys\r\ndef input(...
{"inputs": ["4\n2 2 1\n2 2 3\n2 2 2\n2 2 4"], "outputs": ["5\n5\n4\n0"]}
UNKNOWN
PYTHON3
CODEFORCES
3
733c09dbb540865f8619f90de41154e5
The Wall
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th...
[ "import sys\r\n\r\n_gcd = lambda s, m, n : m if n==0 else _gcd(s, n, m % n)\r\ngcd = lambda m, n : _gcd(_gcd, m, n)\r\nlcm = lambda m, n : m // gcd(m, n) * n\r\n\r\n\r\n(x, y, a, b) = list(map(int, input().split()))\r\n\r\nz = lcm(x, y)\r\n\r\nprint(b//z-(a-1)//z)\r\n", "def main():\n x, y, a, b = map(int, inp...
{"inputs": ["2 3 6 18", "4 6 20 201", "15 27 100 10000", "105 60 3456 78910", "1 1 1000 100000", "3 2 5 5", "555 777 1 1000000", "1000 1000 1 32323", "45 125 93451125 100000000", "101 171 1 1000000000", "165 255 69696 1000000000", "555 777 666013 1000000000", "23 46 123321 900000000", "321 123 15 1000000", "819 1000 95...
UNKNOWN
PYTHON3
CODEFORCES
148
7342c11337a3f2aed7498a23929c2593
GCD Table
Consider a table *G* of size *n*<=×<=*m* such that *G*(*i*,<=*j*)<==<=*GCD*(*i*,<=*j*) for all 1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*. *GCD*(*a*,<=*b*) is the greatest common divisor of numbers *a* and *b*. You have a sequence of positive integer numbers *a*1,<=*a*2,<=...,<=*a**k*. We say that this sequence occurs in t...
[ "\r\n\r\nfrom math import gcd\r\n\r\n\r\ndef LCM(a, b):\r\n if min(a, b) == 0: return max(a, b)\r\n return a // gcd(a, b) * b\r\n\r\n\r\nclass Eqn():\r\n def __init__(self, r, mod):\r\n self.r = r\r\n self.mod = mod\r\n\r\n\r\ndef bye():\r\n print(\"NO\")\r\n exit(0)\r\n\r\n\r\ndef exgc...
{"inputs": ["100 100 5\n5 2 1 2 1", "100 8 5\n5 2 1 2 1", "100 100 7\n1 2 3 4 5 6 7", "5 5 5\n1 1 1 1 1", "11 10 1\n11", "108 942 35\n1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 31 1 3 1 1 3 1 1 3 1 1", "1000000000000 1000000000000 116\n1587924000 7 2 3 4 5 6 1 56 9 10 1 12 13 2 105 16 1 18 1 620 3 14 1 24 25 26 27...
UNKNOWN
PYTHON3
CODEFORCES
6
735a04aff31665beb4885fab2271e2bf
Playing with Paper
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle...
[ "a,b = list(map(int,input().split()))\r\nans = 0\r\nwhile True:\r\n if b>a:\r\n a,b = b,a\r\n if a%b==0:\r\n ans+=a//b\r\n break\r\n else:\r\n ans+=a//b\r\n a = a%b\r\nprint(ans)", "a, b = [int(i) for i in input().split()]\r\nq = a//b\r\nans = q\r\nwhile (a - q*b != 0):...
{"inputs": ["2 1", "10 7", "1000000000000 1", "3 1", "4 1", "3 2", "4 2", "1000 700", "959986566087 524054155168", "4 3", "7 6", "1000 999", "1000 998", "1000 997", "42 1", "1000 1", "8 5", "13 8", "987 610", "442 42", "754 466", "1000000000000 999999999999", "1000000000000 999999999998", "941 14", "998 2", "1000 42", ...
UNKNOWN
PYTHON3
CODEFORCES
312
736d64400df84fb0b7e53e0ca922c7a8
Polycarpus' Dice
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough...
[ "n, a = [int(next_token) for next_token in input().split()]\r\nd = [int(next_token) for next_token in input().split()]\r\ns = sum(d)\r\nans = []\r\nfor i in range(n):\r\n k_min = max(a - s + d[i], 1)\r\n k_max = min(a - n + 1, d[i])\r\n ans.append(k_min - 1 + d[i] - k_max)\r\nprint(' '.join(map(str, ans)))...
{"inputs": ["2 8\n4 4", "1 3\n5", "2 3\n2 3", "1 1\n3", "1 2\n3", "2 2\n2 3", "2 4\n2 3", "3 3\n5 1 5", "3 4\n5 1 5", "3 5\n5 1 5", "3 6\n5 1 5", "3 7\n5 1 5", "3 8\n5 1 5", "3 5\n1 2 100", "10 20\n1 1 1 1 5 100 1 1 1 1", "5 50\n1 1 1 1 1000000", "5 50\n2 2 2 2 1000000", "5 50\n10 10 10 10 1000000", "10 19\n1 5 6 1 6 4...
UNKNOWN
PYTHON3
CODEFORCES
70
73844bd17524419c97f556d2c107bd32
Clothes
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item h...
[ "import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nA = list(map(int, input().split()))\r\ng = [set() for i in range(n)]\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n a, b = a-1, b-1\r\n g[a].add(b)\r\n g...
{"inputs": ["3 3\n1 2 3\n1 2\n2 3\n3 1", "3 2\n2 3 4\n2 3\n2 1", "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1", "4 3\n10 10 5 1\n2 1\n3 1\n3 4", "4 0\n9 8 2 10", "4 3\n5 5 9 6\n3 2\n1 4\n3 4", "4 3\n5 1 10 1\n2 1\n3 2\n1 4", "4 3\n1 2 8 6\n1 3\n1 4\n3 4", "4 4\n9 3 3 1\n1 2\n3 1\n3 2\n4 3", "4 3\n6 8 10 1\n2 3\n1 4\n3 4", "4 5\n4...
UNKNOWN
PYTHON3
CODEFORCES
15
73ac9650486f781ac4e25a416255efdb
Cutting Carrot
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles tri...
[ "from math import sqrt\n\nn, h = map(int, input().split())\n\nfor i in range(1, n):\n print(h*sqrt(i/n), end=' ' if i +1 < n else '\\n')\n\t\t\t\t\t\t\t \t\t \t\t\t \t\t \t\t\t \t\t \t\t\t", "from math import sqrt\r\n\r\nn,hn = list(map(int,input().split()))\r\nkn = sqrt(n)\r\nh = hn/kn\r\nfor i in range(1,...
{"inputs": ["3 2", "2 100000", "1000 100000", "2 1", "1000 1", "20 17", "999 1", "998 99999", "574 29184", "2 5713", "937 23565", "693 39706", "449 88550", "642 37394", "961 53535", "4 31901", "4 23850", "4 72694", "4 21538", "4 70383", "5 1", "5 1", "5 1", "5 1", "5 1", "20 1", "775 1", "531 1", "724 1", "917 1", "458...
UNKNOWN
PYTHON3
CODEFORCES
167
73c2c373039ed01f1cd16fb20ce3d7a7
Lucky Mask
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer *n* the number that is obtained after successive writing ...
[ "def mask(x):\n s = \"\"\n for i in str(x):\n if i == '4' or i == '7':\n s += i\n return int(s)\n\na, b = map(int, input().split())\nfor i in range(a + 1, 177778):\n if '4' in str(i) or '7' in str(i):\n if mask(i) == b:\n print(i)\n break", "import sys\r\...
{"inputs": ["1 7", "100 47", "458 47", "7 7", "547 47", "77 77", "44 4", "740 4", "100000 77777", "77777 77777", "47 74", "74 77", "77 74", "98545 7474", "99997 4", "100000 7", "99997 47", "47774 774", "47744 7", "45896 4", "45679 77777", "99979 77", "10 77777", "1 47774", "47774 47774", "47580 47774", "55557 74", "597...
UNKNOWN
PYTHON3
CODEFORCES
33
73c44a48d44126430dc7349b0c20f436
Magnum Opus
Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci...
[ "a = [int(i) for i in input().split()]\nprint(min(a[0], a[1], a[2] // 2, a[3] // 7, a[4] // 4))", "a,b,c,d,e = map(int,input().split())\nprint(min(a,b,c // 2,d // 7,e // 4))", "cnt = [1, 1, 2, 7, 4]\narr = list(map(int, input().split(\" \")))\n \nfor i in range(5):\n arr[i] //= cnt[i]\n \nprint(min(arr))\n",...
{"inputs": ["2 4 6 8 10", "50 27 17 31 89", "50 87 29 81 21", "74 21 36 68 80", "75 82 48 95 12", "41 85 14 43 23", "94 28 3 29 9", "94 21 36 89 20", "60 92 82 71 53", "46 68 3 0 51", "12 39 3 50 84", "12 31 47 31 84", "79 2 93 92 16", "65 46 3 77 81", "31 38 47 26 13", "42 9 59 19 24", "51 19 70 5 78", "51 56 14 99 21...
UNKNOWN
PYTHON3
CODEFORCES
17
73d950c4bb08b0f14ae222ba7f1c8b69
Compatible Numbers
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* &amp; *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 &amp; 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 &amp; 1102<==<=102. You are given an...
[ "from collections import defaultdict, Counter,deque\r\nfrom math import sqrt, log10, log, floor, factorial,gcd\r\nfrom bisect import bisect_left, bisect_right\r\nfrom itertools import permutations,combinations\r\nimport sys, io, os\r\ninput = sys.stdin.readline\r\n# input=io.BytesIO(os.read(0,os.fstat(0).st_size))....
{"inputs": ["2\n90 36", "4\n3 6 3 6", "5\n10 6 9 8 2", "10\n4 9 8 3 2 6 8 2 9 7", "10\n3 5 18 12 4 20 11 19 15 6", "15\n8 4 9 3 6 6 6 6 1 6 7 1 8 9 2", "20\n280 983 126 941 167 215 868 748 383 554 917 285 43 445 331 800 527 998 503 164", "5\n1 4 2 3 5", "1\n1", "1\n4000000", "1\n2097152"], "outputs": ["36 90", "-1 -1 -...
UNKNOWN
PYTHON3
CODEFORCES
7
73e0e3099a08bef90835f286bcd130e8
none
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties: - *G* has exactly *n* vertices, numbe...
[ "import collections\r\n\r\nn, m = map(int, input().split())\r\nans, A, B, C = [''] * n, [], [], []\r\nd = collections.defaultdict(list)\r\nfor i in range(m):\r\n x, y = map(int, input().split())\r\n d[y - 1].append(x - 1)\r\n d[x - 1].append(y - 1)\r\nfor k, v in d.items(): #set 'b'\...
{"inputs": ["2 1\n1 2", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n1 3\n1 4\n3 4", "1 0", "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2", "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n...
UNKNOWN
PYTHON3
CODEFORCES
12
740f0bdf10e187653b10fb1e412b52c9
Game
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2...
[ "n1,n2,k1,k2=map(int,input().split())\r\nif n1>n2:\r\n\tprint(\"First\")\r\nelif n1<n2:\r\n\tprint(\"Second\")\r\nelif n1==n2:\r\n\tprint(\"Second\")", "n1, n2, k1, k2=map(int, input().split())\nif(n1>n2):\n print(\"First\")\nif(n1<=n2):\n print(\"Second\")\n", "n1, n2, a, b = [int(i) for i in input().spl...
{"inputs": ["2 2 1 2", "2 1 1 1", "5 7 4 1", "5 7 1 4", "5 7 10 10", "5 7 1 10", "1 1 1 1", "50 50 50 50", "50 49 1 2", "50 48 3 1", "48 50 12 11", "49 50 11 12", "49 49 4 1", "49 49 3 3", "1 50 1 50", "1 50 50 50", "50 1 1 1", "50 1 1 50", "32 31 10 9", "32 4 17 3"], "outputs": ["Second", "First", "Second", "Second", ...
UNKNOWN
PYTHON3
CODEFORCES
375
741bb1f946dda8d9d2ae4bdb4ddc08bc
T-shirts Distribution
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nsize = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']\r\nnum = {size[i]: i for i in range(6)}\r\n\r\n\r\ndef distribute():\r\n for i in range(n):\r\n if len(want[i]) == 1:\r\n w = want[i][0]\r\n if cnt[w] == 0:\r\n return False\r\...
{"inputs": ["0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,XXL\nXL", "1 3 0 2 2 2\n10\nL,XL\nS,M\nXXL,XXXL\nS,M\nS,M\nXXXL\nXL,XXL\nXXL\nS,M\nXL", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\n...
UNKNOWN
PYTHON3
CODEFORCES
12
74216fbb643744f747461380b71d0be3
Checking the Calendar
You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t...
[ "m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\nwd = ['monday', 'tuesday', 'wednesday', \"thursday\", \"friday\", \"saturday\", \"sunday\"]\na, b = [wd.index(input()) for i in range(2)]\nfor i in range(7):\n cur = i\n for j in range(11):\n nxt = (cur + m[j]) % 7\n if cur == a and nxt == b...
{"inputs": ["monday\ntuesday", "sunday\nsunday", "saturday\ntuesday", "tuesday\nthursday", "friday\nwednesday", "sunday\nsaturday", "monday\nmonday", "monday\nwednesday", "monday\nthursday", "monday\nfriday", "monday\nsaturday", "monday\nsunday", "tuesday\nmonday", "tuesday\ntuesday", "tuesday\nwednesday", "tuesday\nfr...
UNKNOWN
PYTHON3
CODEFORCES
156
74244487ce06cc0da0e22a0572c585c6
Leha and Function
Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical expectation of the minimal element among all *k*-element subsets. But only function does n...
[ "R=lambda:map(int,input().split())\r\nn=int(input())\r\na=sorted(R())\r\nc=[0]*n\r\nfor i,(_,j) in enumerate(sorted(zip(R(),range(n)))):\r\n c[j]=a[-1-i]\r\nprint(' '.join(map(str,c)))", "n = int(input())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\na.sort()\r\nb = sorted([(...
{"inputs": ["5\n7 3 5 3 4\n2 1 3 2 3", "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2"], "outputs": ["4 7 3 5 3", "2 6 4 5 8 8 6"]}
UNKNOWN
PYTHON3
CODEFORCES
54
7431c78681efd4e5818be5fd32cb59e8
Fox and Cross
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several...
[ "def check(a, b, n):\n\treturn a>=0 and b>=0 and a<n and b<n\n\ndef solve():\n\tn = int(input())\n\tar = []\n\tfor i in range(n):\n\t\tar.append(input())\n\n\tcross = [[0]*n for _ in range(n)]\n\n\taddc = [(1, 0), (2, 0), (1, -1), (1, 1)]\n\n\tfor i in range(n):\n\t\tfor j in range(n):\n\t\t\tif ar[i][j] == \"#\" a...
{"inputs": ["4\n####\n####\n####\n####", "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "5\n.....\n.#...\n####.\n.####\n...#.", "5\n#....\n###..\n.###.\n..##.\n..##.", "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#.....
UNKNOWN
PYTHON3
CODEFORCES
68
7432deec97885b39b604ea686f87155a
Hockey
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name *w* and the collection of forbidden substrings *s*1,<=*s*2,<=...,<=*s**n*. All those strings consist of uppercase and low...
[ "n= int(input())\r\nb = []\r\nfor i in range(n):\r\n b.append(input())\r\nw = input()\r\nlet = input()\r\nbad=[]\r\nfor i in range(len(w)):\r\n bad.append(True)\r\nfor i in range(len(w)):\r\n mx = 0\r\n for j in range(n):\r\n if w[i:].lower().startswith(b[j].lower()):\r\n mx =max(mx,le...
{"inputs": ["3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt", "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na", "2\naCa\ncba\nabAcaba\nc", "3\nlol\nhello\neho\nPetrUnited\nt", "2\ntrsd\ndream\nPetrsDreamOh\ny", "1\nPetrsDreamOh\nPetrsDreamOh\nh", "3\netr\ned\nied\nPetrUnited\nd", "3\netr\ned\nied\nPetrUnited\nz",...
UNKNOWN
PYTHON3
CODEFORCES
4
743d2125ab70ce92fbcc50088321ef71
Theatre Square
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
[ "'''Vipin'''\n# cook your dish here\nn,m,a=map(int,input().split())\nif a>n and a>m:\n print(\"1\")\nelse:\n if n%a>0:\n n=n//a+1 \n else:\n n=n//a\n \n if m%a>0:\n m=(m//a)+1 \n else:\n m=m//a\n \n ans = n*m \n print(ans)\n \n \n\t\t \t ...
{"inputs": ["6 6 4", "1 1 1", "2 1 1", "1 2 1", "2 2 1", "2 1 2", "1 1 3", "2 3 4", "1000000000 1000000000 1", "12 13 4", "222 332 5", "1000 1000 10", "1001 1000 10", "100 10001 1000000000", "1000000000 1000000000 1000000000", "1000000000 1000000000 999999999", "1000000000 1000000000 192", "1000000000 987654321 1", "45...
UNKNOWN
PYTHON3
CODEFORCES
2,260
7451485ce70557064845f1b022da2b0b
Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All *n* participants who have made it to the finals found themselves in a huge *m*-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elev...
[ "# n, m = tuple([int(x) for x in input().split()])\n# cycle_length = (m - 1) * 2\n# for _ in range(n):\n# \ta, b, c = tuple([int(x) for x in input().split()])\n# \ta -= 1\n# \tb -= 1\n# \tif(a > b):\n# \t\ta = cycle_length - a\n# \t\tb = cycle_length - b\n# \telif(a == b):\n# \t\tprint(c)\n# \t\tcontinue\n# \tif(a ...
{"inputs": ["7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0", "5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5", "5 5\n1 3 4\n4 4 2\n3 2 1\n2 4 0\n1 5 3", "8 5\n2 2 91\n5 1 97\n5 1 36\n5 4 19\n2 5 50\n4 2 1\n1 4 9\n3 2 32", "7 5\n2 2 85\n4 3 76\n4 1 17\n5 4 70\n2 5 3\n3 3 14\n3 1 51", "5 2\n1 2 0\n2 1 1\n2 2 0\n2 2 5\n2 1...
UNKNOWN
PYTHON3
CODEFORCES
6
745a11c35b7aa99d52b544581262721d
Strange Game On Matrix
Ivan is playing a strange game. He has a matrix *a* with *n* rows and *m* columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's...
[ "import sys\r\n\r\nn, m, k = map(int, input().split())\r\nmatrix = [[0]*m] + [list(map(int, input().split())) for _ in range(n)]\r\n\r\nfor j in range(m):\r\n for i in range(1, n+1):\r\n matrix[i][j] += matrix[i-1][j]\r\n\r\nans = [0, 0]\r\n\r\nfor j in range(m):\r\n max_one, rem = 0, 0\r\n for i in...
{"inputs": ["4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1", "3 2 1\n1 0\n0 1\n0 0", "3 4 2\n0 1 1 1\n1 0 1 1\n1 0 0 1", "3 57 3\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0\n1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 0 1...
UNKNOWN
PYTHON3
CODEFORCES
37
745d4711d6cd7d0f3f5f9cb57cbb1ba9
Elephant
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
[ "n = int(input())\r\nmoves = 0\r\nwhile n >0 :\r\n if n >=5:\r\n n-=5\r\n elif n>=4:\r\n n-=4\r\n elif n>=3:\r\n n-=3\r\n elif n>=2:\r\n n-=2\r\n elif n>= 1:\r\n n-=1\r\n\r\n moves+=1\r\n\r\nprint(moves)", "x = int(input()) \npasos = (x + 4) // 5 \nprint(pasos...
{"inputs": ["5", "12", "999999", "41", "1000000", "1", "2", "3", "4", "534204", "469569", "502877", "942212", "97", "53", "89", "574", "716", "729", "8901", "3645", "4426", "46573", "86380", "94190", "999990", "999991", "999992", "999993", "999994", "999995", "999996", "999997", "999998"], "outputs": ["1", "3", "200000...
UNKNOWN
PYTHON3
CODEFORCES
759
74746b6772a19f1dff2accd003348e03
Sonya and Robots
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi...
[ "\"\"\"\nhttp://codeforces.com/problemset/problem/1004/C\n\"\"\"\ninput()\narr = map(int, input().split())\nhash_ = {}\ncnt = 0\nfor x in arr:\n if x not in hash_:\n cnt += len(hash_)\n hash_[x] = len(hash_)\n else:\n cnt += len(hash_) - hash_[x]\n hash_[x] += len(hash_) - hash_[x]...
{"inputs": ["5\n1 5 4 1 3", "7\n1 2 1 1 1 3 2", "10\n2 2 4 4 3 1 1 2 3 2", "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "1\n1"], "outputs": ["9", "7", "14", "20", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
126
7483de00921fbbd67ba427bdfb4a54c8
Punctuation
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: - if there is no punctuation mark between two word...
[ "import re\r\n\r\ns = input().strip()\r\ns = re.sub('\\s+', ' ', s)\r\ns = re.sub('\\s?([.,!?])\\s?', '\\\\1 ', s)\r\nprint(s)", "s = input().split()\n\npunc = [\".\", \",\", \"!\", \"?\"]\n\ncom_ind = [(x, y) for x, row in enumerate(s) for y, col in enumerate(row) if(col in punc)]\ncom_ind.sort(reverse = True, k...
{"inputs": ["galileo galilei was an italian physicist ,mathematician,astronomer", "galileo was born in pisa", "jkhksdfhsdfsf", "a a a a a", "ksdfk sdlfsdf sdf sdf sdf", "gdv", "incen q", "k ? gq dad", "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb", "mck . gq dauqminf wee bazyzy humnv d...
UNKNOWN
PYTHON3
CODEFORCES
44
74957bef0ae6692daca852a9741e1138
Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself). The first line of the input contains two integers *n* an...
[ "import math\r\nN = 15\r\nmat = 0\r\ninf = 1000000000\r\nanswer = inf\r\n\r\n\r\n\r\ndef Get_Cycle_Length(v,graph):\r\n global mat\r\n global answer\r\n if len(v) == 0:\r\n answer = min(answer,mat)\r\n return\r\n end = v.pop()\r\n i = 0\r\n while i<len(v):\r\n se = v.pop(i)\r\...
{"inputs": ["4 6\n1 2 10\n2 3 1000\n3 4 10\n4 1 1000\n4 2 5000\n1 3 2", "2 9\n1 2 9\n1 2 9\n2 1 9\n1 2 8\n2 1 9\n1 2 9\n1 2 9\n1 2 11\n1 2 9", "2 10\n1 2 9\n1 2 9\n2 1 9\n1 2 8\n2 1 9\n1 2 9\n1 2 9\n1 2 11\n1 2 9\n1 2 9", "15 14\n1 2 1\n2 3 1\n2 4 1\n3 5 1\n3 6 1\n4 7 1\n4 8 1\n5 9 1\n5 10 1\n6 11 1\n6 12 1\n7 13 1\n7 ...
UNKNOWN
PYTHON3
CODEFORCES
4
74b1be24aae77b05b2d4dbcef091a8da
Spiders
One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower t...
[ "import math\r\nimport sys\r\nfrom bisect import bisect_right, bisect_left, insort_right\r\nfrom collections import Counter, defaultdict\r\nfrom heapq import heappop, heappush\r\nfrom itertools import accumulate\r\nfrom sys import stdout\r\n\r\nR = lambda: map(int, input().split())\r\nsys.stdin = open('input.txt', ...
{"inputs": ["1\n3 1 2 2 3", "2\n3 1 2 1 3\n4 1 2 2 3 2 4", "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5", "3\n3 1 2 2 3\n5 2 5 5 3 3 4 5 1\n9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3", "7\n2 2 1\n4 1 4 2 3 1 2\n3 3 1 3 2\n5 1 4 3 5 1 2 1 3\n6 4 5 1 3 4 2 3 6 5 1\n7 1 3 3 6 7 4 7 1 5 2 3 5\n10 6 8 2 6 6 3 2 7 2 4 6 10 3 1 6 ...
UNKNOWN
PYTHON3
CODEFORCES
14
74c7eb05a7a7c46fb862f9ab7cfa58e0
Mashmokh and Tokens
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest o...
[ "import math\r\nn,a,b=map(int,input().split())\r\narr = list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n x=(math.floor(arr[i]*a/b))\r\n arr[i]-=(math.ceil(x*b/a))\r\nprint(*arr)", "\"\"\"\r\nCodeforces Round 240 Div 1 Problem B\r\n\r\nAuthor : chaotic_iak\r\nLanguage: Python 3.3.4\r\n\"\"\"\r\n...
{"inputs": ["5 1 4\n12 6 11 9 1", "3 1 2\n1 2 3", "1 1 1\n1", "1 1 1000000000\n1000000000", "1 1 1000000000\n999999999", "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999"], "outputs": ["0 2 3 1 1 ", "1 0 1 ", "0 ", "0 ", "999999999 ", "99999999 9999999...
UNKNOWN
PYTHON3
CODEFORCES
78
750b2e050867ca435456d6232b303fd1
Ivan and Powers of Two
Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=≥<=0) need to be added to the pi...
[ "n = int(input())\r\nseq = [int(x) for x in input().split()]\r\n \r\ndef inseri(s, n):\r\n\tif n in s:\r\n\t\ts.remove(n)\r\n\t\tinseri(s, n+1)\r\n\telse:\r\n\t\ts.add(n)\r\n \r\n \r\ns = set()\r\nfor i in seq:\r\n\tinseri(s, i)\r\n \r\nm = max(s)\r\nprint(m-len(s)+1)", "n=int(input())\na=list(map(int,input().spl...
{"inputs": ["4\n0 1 1 1", "1\n3", "1\n0", "1\n2000000000", "1\n1", "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2"], "outputs": ["0", "3", "0", "2000000000", "1", "5"]}
UNKNOWN
PYTHON3
CODEFORCES
20
752107aaa1473f689aaa56e39034671e
Timofey and cubes
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup...
[ "n=int(input())\r\na=list(input().split())\r\nk=n//2\r\nfor i in range(0,k,2):\r\n a[i],a[n-i-1]=a[n-i-1],a[i]\r\nprint(*a)", "n = int(input())\na = list(map(int, input().split()))\nif n % 2 == 0:\n for i in range(n//2):\n if i % 2 == 0:\n print(a[-i - 1], end=' ')\n else:\n ...
{"inputs": ["7\n4 3 7 6 9 1 2", "8\n6 1 4 2 5 6 9 2", "1\n1424", "9\n-7 9 -4 9 -6 11 15 2 -10", "2\n21968 5686", "5\n241218936 -825949895 -84926813 491336344 -872198236", "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 6...
UNKNOWN
PYTHON3
CODEFORCES
222
7541acbed93b5dd57610e64bd1571264
Lazy Security Guard
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ...
[ "from math import sqrt\r\n\r\nn = int(input())\r\n\r\nside_of_s = int(sqrt(n))\r\nare_of_s = side_of_s * side_of_s\r\nrest = n - are_of_s\r\n\r\noutput = side_of_s * 4\r\n\r\nif rest > 0:\r\n output += 2\r\n rest -= side_of_s\r\n\r\nif rest > 0:\r\n output += 2\r\n\r\nprint(output)\r\n", "n = int(input()...
{"inputs": ["4", "11", "22", "3", "1024", "101", "30", "1000000", "1", "2", "5", "6", "7", "8", "9", "10", "999000", "999001", "999999", "933206", "718351", "607443", "347887", "246206", "151375", "12639", "3751", "3607", "124", "64", "31", "23", "15", "19", "59637"], "outputs": ["8", "14", "20", "8", "128", "42", "22"...
UNKNOWN
PYTHON3
CODEFORCES
224
754c9237727a83ab77d875525e1bac65
Pie Rules
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be ...
[ "import math\r\nfrom random import random\r\n\r\ndef getInt():\r\n return(int(input()))\r\n\r\ndef getInts():\r\n line = input().split()\r\n return [int(l) for l in line]\r\n\r\ndef getFloat():\r\n return(float(input()))\r\n\r\ndef getFloats():\r\n line = input().split()\r\n return [float(l) for l...
{"inputs": ["3\n141 592 653", "5\n10 21 10 21 10", "1\n100000", "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000...
UNKNOWN
PYTHON3
CODEFORCES
68
7556993199c339a3be059e3c49eb86dc
I Wanna Be the Guy
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
[ "n=int(input())\r\np=set(map(int,input().split()[1:]))\r\nq=set(map(int,input().split()[1:]))\r\na=set(range(1,n+1))\r\nal=p.union(q)==a\r\nif al:\r\n print(\"I become the guy.\")\r\nelse:\r\n print(\"Oh, my keyboard!\")", "# Read input\r\nn = int(input())\r\np_info = list(map(int, input().split()))\r\nq_...
{"inputs": ["4\n3 1 2 3\n2 2 4", "4\n3 1 2 3\n2 2 3", "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5", "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 5...
UNKNOWN
PYTHON3
CODEFORCES
291
75bd96eaf1d058b3b0acafa7aaf06d1a
Maximum Absurdity
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign ...
[ "n, k = map(int, input().split())\r\nv = list(map(int, input().split()))\r\ns, dp = [0 for i in range(0, n)], [0 for i in range(0, n)]\r\nsol, a, b = 0, 0, 0\r\n\r\nfor i in range(n-1, -1, -1):\r\n s[i] = v[i]\r\n if i+1 < n: s[i] += s[i+1]\r\n if i+k < n: s[i] -= v[i+k]\r\n\r\n dp[i] = s[i]\r\n if i...
{"inputs": ["5 2\n3 6 1 1 6", "6 2\n1 1 1 1 1 1", "6 2\n1 4 1 2 5 6", "4 1\n1 2 2 2", "6 3\n15 20 1 15 43 6", "12 3\n1 2 1 15 2 3 6 8 3 3 8 6", "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3", "2 1\n1 1", "2 1\n1000000000 999999999", "3 1\n100 30 563", "3 1\n547468 78578678 6467834", "4 1\n90000 34567 90000 90001", "4 2\n999999 88...
UNKNOWN
PYTHON3
CODEFORCES
53
75d7721c34fb451b39638108c261fdfe
Segments
You are given *n* segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails ne...
[ "import sys\r\nfrom array import array # noqa: F401\r\nfrom operator import itemgetter\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn = int(input())\r\na = [(x, y) if x < y else (y, x) for _ in range(n) for x, y in (map(int, input().split()),)]\r\na.sort(key=itemgett...
{"inputs": ["2\n0 2\n2 5", "5\n0 3\n4 2\n4 8\n8 10\n7 7", "3\n40 -83\n52 -80\n-21 -4", "4\n67 -88\n37 -62\n-26 91\n-99 -50", "5\n45 58\n22 6\n-32 36\n49 -37\n43 62", "10\n47 -85\n71 40\n-87 64\n76 73\n52 -51\n-20 -57\n-14 -77\n-45 -11\n-56 -48\n81 20", "35\n-47 61\n-73 -15\n9 43\n43 -49\n13 -6\n48 -65\n49 -84\n-6 76\n4...
UNKNOWN
PYTHON3
CODEFORCES
19
75fe450019cc75c44b9c4a2ed5ad2024
Chain Reaction
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however....
[ "import sys,os,io\r\nfrom sys import stdin\r\nfrom bisect import bisect_left , bisect_right\r\ndef ii():\r\n return int(input())\r\ndef li():\r\n return list(map(int,input().split()))\r\nif(os.path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\") ; sys.stdout = open(\"output.txt\",\"w\") \r\...
{"inputs": ["4\n1 9\n3 1\n6 1\n7 4", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "1\n0 1", "1\n0 1000000", "1\n1000000 1000000", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7", "5\n1 1\n3 1\n5 1\n7 10\n8 10", "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1"], "outputs": ["1", "3", "0", "0", "0", "4", "...
UNKNOWN
PYTHON3
CODEFORCES
87
7623e6a775ed42e82fa807f998873abf
Checkposts
Your city has *n* junctions. There are *m* one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions. To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction *i* can protect junction *j...
[ "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\nw = [0] + list(map(int, input().split()))\r\nm = int(input())\r\nM = 10**9+7\r\nd = [[] for i in range(n+1)]\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n d[a].append(b)\r\nq = list(range(1...
{"inputs": ["3\n1 2 3\n3\n1 2\n2 3\n3 2", "5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1", "10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9", "2\n7 91\n2\n1 2\n2 1", "10\n1 1 1 1 1 1 1 2 2 2\n15\n2 3\n2 4\n4 1\n4 7\n4 10\n4 5\n4 8\n2 6\n3 2\n1 2\n7 2\n10 2\n5 2\n8 2\n6 2", "1...
UNKNOWN
PYTHON3
CODEFORCES
4
7633fd36fd792dd159c25f0914eed4c8
King of Thieves
In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that wil...
[ "from math import ceil\r\n\r\ndef solution(n, level):\r\n\tmax_jump = ceil(n / 4) - 1\r\n\tplatforms = [i for i in range(n) if level[i] == '*']\r\n\tans = any('*****' in level[start::jump] for jump in range(1, max_jump + 1) for start in platforms)\r\n\treturn ('no', 'yes')[ans]\r\n\r\nn = int(input())\r\nlevel = in...
{"inputs": ["16\n.**.*..*.***.**.", "11\n.*.*...*.*.", "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.", "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**", "56\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..", "64\n***.*...*...*.***.....*.....**.*****.*.*...*..*.*..***.....
UNKNOWN
PYTHON3
CODEFORCES
54
76493a7daaff07951caf248451558065
Guards In The Storehouse
Polycarp owns a shop in the capital of Berland. Recently the criminal activity in the capital increased, so Polycarp is thinking about establishing some better security in the storehouse of his shop. The storehouse can be represented as a matrix with *n* rows and *m* columns. Each element of the matrix is either . (an...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\nif n >= m:\r\n s = [list(input().rstrip()) for _ in range(n)]\r\nelse:\r\n s = [[] for _ in range(m)]\r\n for _ in range(n):\r\n s0 = list(input().rs...
{"inputs": ["1 3\n.x.", "2 2\nxx\nxx", "2 2\n..\n..", "3 1\nx\n.\nx", "100 2\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n.....
UNKNOWN
PYTHON3
CODEFORCES
3
76669443e7378ca137df9628ed85e6a9
Fashion in Berland
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fast...
[ "n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\nif n == 1:\r\n if lst[0] == 1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n zeros = lst.count(0)\r\n if zeros == 1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "def solve():\r\n m = ...
{"inputs": ["3\n1 0 1", "3\n1 0 0", "3\n1 1 0", "3\n1 1 1", "3\n0 0 1", "3\n0 0 0", "3\n0 1 1", "3\n0 1 0", "2\n0 1", "2\n1 0", "2\n0 0", "2\n1 1", "1\n1", "1\n0", "10\n1 0 1 1 1 1 1 1 1 1", "5\n1 1 1 1 0", "4\n1 0 1 0", "4\n1 1 0 0", "10\n0 0 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 1 1 1 1 1", "123\n1 1 1 1 1 1 1 1 1 1 1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
166
7684443c62d44e19ea93c1ba3f6df7b4
Levko and Table
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. The sin...
[ "n, k = map(int, input().split());\r\na = list(range(n));\r\nfor i in range (0, n):\r\n a[i] = list(range(n));\r\n for j in range (0, n):\r\n if j == i:\r\n a[i][j] = k;\r\n else: a[i][j] = 0;\r\n print(*a[i], sep=\" \")", "import sys\r\n\r\ndef input(): return sys.stdin.readl...
{"inputs": ["2 4", "4 7", "1 8", "9 3", "31 581", "100 1000", "100 999", "99 998", "100 997", "81 111", "1 407", "54 341", "92 460", "34 47", "11 547", "100 1", "99 1", "99 2", "2 7", "100 100", "4 3", "3 2"], "outputs": ["4 0 \n0 4 ", "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 ", "8 ", "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0...
UNKNOWN
PYTHON3
CODEFORCES
367
768e6345e264704e23f22e7840d3742a
none
There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the...
[ "import math\r\nfrom copy import deepcopy\r\ndef position_point_plan(p):\r\n if p[0]<=0 and p[1]>0 :\r\n return 0\r\n if p[0]<0 and p[1]<=0 :\r\n return 1\r\n if p[0]>=0 and p[1]<0 :\r\n return 2\r\n if p[0]>0 and p[1]>=0 :\r\n return 3\r\n\r\ndef is_parallel(triangle):\r\n ...
{"inputs": ["1 1", "5 5", "5 10", "2 2", "5 6", "5 11", "10 15", "935 938", "999 1000", "1000 1000", "15 20", "20 15", "629 865", "45 872", "757 582", "173 588", "533 298", "949 360", "661 175", "728 299", "575 85", "385 505", "755 865", "395 55", "600 175", "280 210", "180 135", "140 105", "440 330", "130 312", "65 15...
UNKNOWN
PYTHON3
CODEFORCES
18
76bb3f769dfb164c76a4fe5eac98c396
School
There are *n* students studying in the 6th grade, in group "B" of a berland secondary school. Every one of them has exactly one friend whom he calls when he has some news. Let us denote the friend of the person number *i* by *g*(*i*). Note that the friendships are not mutual, i.e. *g*(*g*(*i*)) is not necessarily equal...
[ "maxn = 1000010\nb = [0] * maxn\nv = [0] * maxn\ng = [0] * maxn\nvis = [0] * maxn\nn, m = map(int, input().split())\nans = 0\ng[1:n+1] = map(int, input().split())\nv[1:m+1] = map(int, input().split())\nb[1:m+1] = map(int, input().split())\nfor i in range(1, m+1):\n a = (v[i] + ans - 1) % n + 1\n t = b[i]\n ...
{"inputs": ["3 4\n2 3 1\n1 2 3 4\n1 2 3 4", "8 6\n7 6 4 2 3 5 5 7\n10 4 3 8 9 1\n1 1 1 2 2 2", "2 2\n2 1\n3304501 9446989\n1 1", "7 3\n7 5 5 1 1 1 1\n9034254 4422892 8872331\n1 2 2", "15 10\n15 3 15 10 11 8 12 5 12 1 4 14 2 2 1\n7571484 4599112 1145547 6936854 5801110 425356 2034668 588381 3181461 3390332\n3 3 1 1 3 1 ...
UNKNOWN
PYTHON3
CODEFORCES
2
76bcef84c53dbedb2f1b4529391130b6
Thoroughly Bureaucratic Organization
Once *n* people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person per day. As a consequence, each of *n* people made an appointment on one of...
[ "\r\ndef go(m, k):\r\n\trem, ans, binom = m*k, 0, 1\r\n\tones = 0\r\n\twhile ones <= k:\r\n\t\ttake = min(1 if ones == 0 else rem//ones, binom)\r\n\t\tif take == 0:\r\n\t\t\tbreak\r\n\t\tans += take\r\n\t\trem -= ones * take\r\n\t\tbinom = binom*(k-ones)//(ones+1)\r\n\t\tones += 1\r\n\treturn ans\r\n\r\ndef solve()...
{"inputs": ["5\n4 1\n4 2\n7 3\n1 1\n42 7", "12\n11 4\n9 2\n10000 100\n1000000000 2345\n123456 1234567\n123456 65536\n5 55\n5 3\n2323 10\n999111000 232323\n999888777 777888999\n999888777 777", "17\n1 1000000000\n1000000000 1\n1000000000 1000000000\n1000000000 999999999\n999999999 1000000000\n1 2\n2 1\n2 3\n3 2\n2 100000...
UNKNOWN
PYTHON3
CODEFORCES
1
76da8f8730411f205ecf823f2528d55c
none
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well. This time Igor K. got disappointed in ...
[ "import math\r\n\r\ncount, length, first, last = map(int, input().split())\r\nresult = 0\r\n\r\nif (length == 1 or\r\n math.ceil(last / length) - math.ceil(first / length) == 0 or\r\n (first % length == 1 and last % length == 0) or\r\n (first % length == 1 and last == count)):\r\n \r\n result = 1\r\n...
{"inputs": ["11 4 3 9", "20 5 2 20", "1 1 1 1", "26 5 2 18", "21 5 1 15", "21 5 1 21", "21 5 8 14", "20 4 1 20", "21 5 1 13", "21 5 4 15", "17 3 1 16", "19 5 7 19", "18 2 1 13", "21 3 6 11", "21 5 3 12", "21 3 6 10", "28 5 4 26", "21 5 6 18", "21 5 4 21", "17 5 6 17", "21 5 9 12", "21 3 6 7", "21 5 7 9", "12 4 5 8", "2...
UNKNOWN
PYTHON3
CODEFORCES
6
76e6bb403b4b2b2676a6771e9d9e4d1e
Friends or Not
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ...
[ "n,d=map(int,input().split())\r\nans,hist=[],[]\r\nfor i in range(n):\r\n s=input().split()\r\n t=int(s[2])\r\n for x in hist:\r\n if 0<t-x[2]<=d and s[0]==x[1] and s[1]==x[0]:\r\n a=sorted([x[0],x[1]])\r\n if not a in ans: ans.append(a)\r\n hist.append([s[0],s[1],t])\r\npri...
{"inputs": ["4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4", "1 1000\na b 0", "2 1\na b 0\nb a 0", "3 1\na b 1\nb c 2\nc d 3", "10 2\nlutdc xfavzancwrokyzzkpco 0\nxfavzancwrokyzzkpco lutdc 1\nlutdc vydvatbnibttqgn 2\nxfavzancwrokyzzkpco vydvatbnibttqgn 2\nvydvatbnibttqgn lutdc 3\nlutdc xfavzancwrokyzzkpco...
UNKNOWN
PYTHON3
CODEFORCES
9
771139a2d1667bd0deb3cbea3e7902e4
IQ Test
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the...
[ "from copy import deepcopy\r\n\r\nzoz=[]\r\n\r\nfor i in range(4):\r\n zoz.append(list(input()))\r\n \r\ndef check(zoz):\r\n for i in range(3):\r\n for j in range(3):\r\n if zoz[i][j]==zoz[i][j+1] and zoz[i+1][j]==zoz[i+1][j+1] and zoz[i+1][j]==zoz[i][j]:\r\n return True\r\...
{"inputs": ["###.\n...#\n###.\n...#", ".##.\n#..#\n.##.\n#..#", ".#.#\n#.#.\n.#.#\n#.#.", "##..\n..##\n##..\n..##", "#.#.\n#.#.\n.#.#\n.#.#", ".#.#\n#.#.\n#.#.\n#.#.", ".#.#\n#.#.\n#.#.\n.#.#", "#.#.\n#.#.\n#.#.\n#.#.", ".#.#\n.#.#\n.#.#\n.#.#", "#..#\n.##.\n####\n####", "#.#.\n.###\n#.#.\n.###", "#..#\n.##.\n.##.\n#.....
UNKNOWN
PYTHON3
CODEFORCES
221
7733ab8e2222578e78c4856a48ff3078
System of Equations
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
[ "import sys\nimport math\n\ndef function():\n n, m = map(int, input().split())\n ans = 0 \n for a in range(1001):\n for b in range(1001):\n if (a**2) + b == n and a + (b**2) == m:\n ans+=1\n print(ans)\n return\n\n\nif __name__ == '__main__':\n function()\n", "n,...
{"inputs": ["9 3", "14 28", "4 20", "18 198", "22 326", "26 104", "14 10", "8 20", "2 8", "20 11", "57 447", "1 1", "66 296", "75 683", "227 975", "247 499", "266 116", "286 916", "307 341", "451 121", "471 921", "502 346", "535 59", "555 699", "747 351", "790 64", "810 704", "855 225", "902 34", "922 514", "971 131", ...
UNKNOWN
PYTHON3
CODEFORCES
522
77493b95633982ea7b597a0e3aff9aa0
Ksusha the Squirrel
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ...
[ "n,k = map(int, input().split())\r\nprint(\"YES\" if max([len(s) for s in input().split('.')])<k else \"NO\")", "n,k=map(int,input().split())\r\na=input()\r\n \r\nb=[]\r\nr=0\r\n \r\ni=0\r\nwhile i<n:\r\n \r\n if a[i]=='#':\r\n r+=1\r\n else:\r\n b+=[r]\r\n r=0\r\n i+=1\...
{"inputs": ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###.", "2 200\n..", "2 1\n..", "2 2\n..", "2 100000\n..", "3 1\n.#.", "3 2\n.#.", "3 10000\n.#."], "outputs": ["YES", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
174
77559f3bff47a375c58414034dd838e5
Bear and Three Balls
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes th...
[ "#http://codeforces.com/contest/653/problem/A\r\nimport sys\r\n\r\nlen_input = input()\r\nseq_input = input().split()\r\n#seq_input = '18 55 16 17'.split()\r\n# seq_input = '40 41 43 44 44 44'.split()\r\n# seq_input = '5 972 3 4 1 4 970 971'.split()\r\n# seq_input = ''.split()\r\n# seq_input = '998 30 384 289 505 3...
{"inputs": ["4\n18 55 16 17", "6\n40 41 43 44 44 44", "8\n5 972 3 4 1 4 970 971", "3\n959 747 656", "4\n1 2 2 3", "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543", "50\...
UNKNOWN
PYTHON3
CODEFORCES
184
775bf86700385871a4c415dd98d0e276
Jon Snow and his Favourite Number
Jon Snow now has to fight with White Walkers. He has *n* rangers, each of which has his own strength. Also Jon Snow has his favourite number *x*. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon n...
[ "\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\nn, k, x = map(int, input().split())\r\nrangers = list(map(int, input().split()))\r\nfor i in range(min(k, 8 + (k & 3))):\r\n\trangers.sort()\r\n\trangers = [ran...
{"inputs": ["5 1 2\n9 7 11 15 5", "2 100000 569\n605 986", "10 10 98\n1 58 62 71 55 4 20 17 25 29", "100 100 96\n11 79 47 73 77 66 50 32 26 38 8 58 45 86 35 49 63 13 35 61 52 44 16 80 32 18 8 4 49 90 78 83 72 3 86 71 96 93 97 60 43 74 58 61 21 96 43 92 31 23 64 60 14 77 27 45 71 27 49 41 40 22 72 50 14 73 72 91 39 54 6...
UNKNOWN
PYTHON3
CODEFORCES
4
77648609db63b536c2fed07fc8dfd61b
Open Communication
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set ...
[ "def rp():\n cs = list(map(int, input().split(' ')))\n cs = list(zip(cs[0::2], cs[1::2]))\n return cs\n\ndef dist(p1, p2):\n return len(set(p1).union(set(p2))) - 2\n\ninput()\n\nps = [rp(), rp()]\n\ntheyCan = True\nmyPos = set()\n\nfor ps1, ps2 in [ps, ps[::-1]]:\n for p1 in ps1:\n pos = set()...
{"inputs": ["2 2\n1 2 3 4\n1 5 3 4", "2 2\n1 2 3 4\n1 5 6 4", "2 3\n1 2 4 5\n1 2 1 3 2 3", "2 1\n1 2 1 3\n1 2", "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1", "3 3\n1 2 5 6 7 8\n2 3 4 5 8 9", "4 3\n1 2 4 5 6 7 8 9\n1 2 8 9 3 1", "3 4\n2 1 8 9 3 1\n1 2 4 5 6 7 8 9", "3 8\n8 9 8 5 9 2\n8 4 8 3 2 6 4 2 4 3 3 7 3 6 1 6", "9 1\n3...
UNKNOWN
PYTHON3
CODEFORCES
19
777032d786f2e0f4f7249941810cd2e2
Dreamoon and WiFi
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de...
[ "#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list)\r\n#from collections import deque as dq #deque e.g. myqueue=dq(list)\r\n#append/appendleft/appendright/pop/popleft\r\n#from bisect import bisect as bis #a=[1,3,4,6,7,8] #bis(a,5)-->3\r\n#import bisect #bisect.bisect_left(a,4)-->2 #bisect.bise...
{"inputs": ["++-+-\n+-+-+", "+-+-\n+-??", "+++\n??-", "++++++++++\n+++??++?++", "--+++---+-\n??????????", "+--+++--+-\n??????????", "+\n+", "-\n?", "+\n-", "-\n-", "-\n+", "+\n?", "++++++++++\n++++++++++", "++++++++++\n++++-+++++", "----------\n++++++++++", "++++++++++\n++++??++++", "----------\n+++?++++-+", "+++++++++...
UNKNOWN
PYTHON3
CODEFORCES
212
77882bc7c3a1570e125a93874785cc09
none
Imagine that you are in a building that has exactly *n* floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to *n*. Now you're on the floor number *a*. You are very bored, so you want to take the lift. Floor number *b* has a secret lab, the entry is forbidd...
[ "import math\r\nimport sys\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def _read():\r\n return sys.stdin.readline().strip()\r\n\r\n def read_int(self):\r\n return int(self._read())\r\n\r\n def read_float(self):\r\n return float(sel...
{"inputs": ["5 2 4 1", "5 2 4 2", "5 3 4 1", "2 2 1 1", "10 1 10 2", "2222 1206 1425 2222", "3 2 3 1", "5 1 2 1", "50 48 41 2", "50 25 21 50", "5000 1 100 3", "100 1 30 500", "50 5 2 50", "35 9 10 35", "10 1 3 4", "22 9 18 3", "500 500 498 4999", "300 300 299 300", "100 3 30 5000", "222 187 134 500", "300 299 300 300",...
UNKNOWN
PYTHON3
CODEFORCES
5
778b2187fee20fcdab6240e536a76739
The Text Splitting
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the st...
[ "n, p, q = map(int, input().split())\r\ns = input()\r\nif p > q:\r\n p, q = q, p\r\nfor i in range(0, n + 1, q):\r\n if (n - i) % p == 0:\r\n print(i // q + (n - i) // p)\r\n for j in range(0, i, q):\r\n print(s[j:j + q])\r\n for j in range(i, n, p):\r\n print(s[j:j ...
{"inputs": ["5 2 3\nHello", "10 9 5\nCodeforces", "6 4 5\nPrivet", "8 1 1\nabacabac", "1 1 1\n1", "10 8 1\nuTl9w4lcdo", "20 6 4\nfmFRpk2NrzSvnQC9gB61", "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6", "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde", "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu", "60 52 8\...
UNKNOWN
PYTHON3
CODEFORCES
99
779fdfa680ef6b95e64785246e21ff16
Face Detection
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<...
[ "n,m=map(int,input().split())\r\na=[list(input()) for i in range(n)]\r\nd=set(['f','a','c','e'])\r\nk=0\r\nfor i in range(n-1):\r\n\tfor j in range(m-1):\r\n\t\tif a[i][j] in d:\r\n\t\t\ts=set()\r\n\t\t\ts.add(a[i][j])\r\n\t\t\ts.add(a[i+1][j])\r\n\t\t\ts.add(a[i+1][j+1])\r\n\t\t\ts.add(a[i][j+1])\r\n\t\t\tif s==d...
{"inputs": ["4 4\nxxxx\nxfax\nxcex\nxxxx", "4 2\nxx\ncf\nae\nxx", "2 3\nfac\ncef", "1 4\nface", "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx", "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk", "1 1\np", "2 5\nacdmw\nefazb", "5 2\ndz\nda\nsx\nyu\nzz", "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn", "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay"...
UNKNOWN
PYTHON3
CODEFORCES
260
77cd1f091319b7e918a798512706abd9
Subsegments
Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maxi...
[ "from sys import *\r\nfrom bisect import *\r\nfrom collections import *\r\np = list(map(int, stdin.read().split()))\r\nn, k = p[0], p[1]\r\ns, d = [], Counter(p[2:2 + k])\r\nt = sorted(q for q in d if d[q] == 1)\r\ng = lambda: s.append(str(t[-1]) if t else 'Nothing')\r\ng()\r\nfor a, b in zip(p[2:], p[2 + k:]):\r\n...
{"inputs": ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2", "10 3\n-55\n-35\n-80\n91\n-96\n-93\n-39\n-77\n4\n29", "10 3\n-13\n26\n-97\n-38\n43\n-12\n80\n3\n8\n45", "10 3\n-84\n25\n-25\n8\n60\n-74\n-98\n48\n-55\n38", "10 3\n-62\n-81\n46\n22\n-84\n19\n-86\n44\n-84\n-73", "10 3\n-6\n2\n79\n-49\n86\n13\n-31\n-71\n57\n93", "...
UNKNOWN
PYTHON3
CODEFORCES
3
77dd332fafec225b0a001ffa4b0736af
Restoring IPv6
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef"....
[ "n = int(input())\r\nres = \"\"\r\nfor i in range(n):\r\n short = input()\r\n blocks = short.split(':')\r\n if '' in blocks:\r\n countOfNull = 9 - len(blocks)\r\n # short[short.index('::')+1]\r\n short = short.replace(\"::\", \":0000\"*countOfNull + \":\")\r\n blocks = short.split('...
{"inputs": ["6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "20\n0:0:9e39:9:b21:c9b:c:0\n0:0:0:0:0:a27:6b:cb0a\n2:7:4d:b:0:3:2:f401\n17:2dc6::0:89e3:0:dc:0\nca:4:0:0:d6:b999:e:0\n4af:553:b29:dd7:2:5b:0:7\n0:c981:8f...
UNKNOWN
PYTHON3
CODEFORCES
41
780a1c7b659cc52202d5fb7c7b7d95ba
Collective Mindsets (hard)
Heidi got one brain, thumbs up! But the evening isn't over yet and one more challenge awaits our dauntless agent: after dinner, at precisely midnight, the *N* attendees love to play a very risky game... Every zombie gets a number *n**i* (1<=≤<=*n**i*<=≤<=*N*) written on his forehead. Although no zombie can see his own...
[ "t = int(input())\r\nfor i in range(t):\r\n n, r = map(int, input().split())\r\n l = list(map(int, input().split()))\r\n if r == 1:\r\n s = sum(l) % n\r\n if s == 0:\r\n s = n\r\n print(s)\r\n else:\r\n s = 2 * l[0] - r + 1 - sum(l)\r\n s = s % n\r\n ...
{"inputs": ["4\n2 1\n1\n2 2\n1\n2 1\n2\n2 2\n2", "4\n2 1\n1\n2 2\n1\n2 1\n2\n2 2\n2", "27\n3 1\n1 1\n3 2\n1 1\n3 3\n1 1\n3 1\n2 1\n3 2\n2 1\n3 3\n2 1\n3 1\n3 1\n3 2\n3 1\n3 3\n3 1\n3 1\n1 2\n3 2\n1 2\n3 3\n1 2\n3 1\n2 2\n3 2\n2 2\n3 3\n2 2\n3 1\n3 2\n3 2\n3 2\n3 3\n3 2\n3 1\n1 3\n3 2\n1 3\n3 3\n1 3\n3 1\n2 3\n3 2\n2 3\...
UNKNOWN
PYTHON3
CODEFORCES
3
780ea41ae2abba43273b718c11ef01fa
Kyoya and Colored Balls
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of...
[ "from math import comb\r\ndec=10**9 + 7\r\n\r\nk =int(input())\r\n\r\ncolor_counts = [0] * k\r\n\r\nfor i in range(0, k):\r\n color_counts[i] = int(input())\r\n\r\nresult = 1\r\ncurr = color_counts[0]\r\n\r\nfor i in range(1,k):\r\n result = result * comb(curr + color_counts[i] - 1 , color_counts[i] - 1) % de...
{"inputs": ["3\n2\n2\n1", "4\n1\n2\n3\n4", "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "5\n10\n10\n10\n10\n10", "11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2", "1\n1", "13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76", "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\...
UNKNOWN
PYTHON3
CODEFORCES
113
7817fa3aebed2caadd9283cb701d61ca
Black-and-White Cube
You are given a cube of size *k*<=×<=*k*<=×<=*k*, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face. Your task is to paint each of *k*3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied: - each white cube has exactly 2 ...
[ "if __name__ == \"__main__\":\r\n n = int(input())\r\n if n % 2 == 1:\r\n print(-1)\r\n exit()\r\n str1 = ''.join(['bb' if i % 2 == 1 else 'ww' for i in range(n // 2)])\r\n str2 = ''.join(['bb' if i % 2 == 0 else 'ww' for i in range(n // 2)])\r\n\r\n for i in range(n):\r\n str1, ...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",...
UNKNOWN
PYTHON3
CODEFORCES
8
781ae30408322baa7c0802c2f4550202
String Transformation
You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nx = 'abcdefghijklmnopqrstuvwxyz'\r\ns = list(input()[:-1])\r\nn = len(s)\r\nans = 0\r\na = 97\r\nfor i in range(n):\r\n if s[i] <= chr(a):\r\n s[i] = chr(a)\r\n a += 1\r\n if a == 123:\r\n ans = 1\r\n break\r\nif ans == 0...
{"inputs": ["aacceeggiikkmmooqqssuuwwyy", "thereisnoanswer", "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs", "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "abcdefghijklmnopqrstuvwxxx", "abcdefghijklmnopqrstuvwxya", "aaaaaaaaaaaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
68
7857ee10aa0bd43979386048eba04748
Tourist's Notes
A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most ...
[ "n, m = map(int, input().split())\r\nres, pd, ph = 0, 0, 0\r\nfor i in range(m):\r\n d, h = map(int, input().split())\r\n if i == 0:\r\n res = h + (d - 1)\r\n else:\r\n delta_d = d - pd\r\n delta_h = abs(h - ph)\r\n if delta_h > delta_d:\r\n print(\"IMPOSSIBLE\")\r\n ...
{"inputs": ["8 2\n2 0\n7 0", "8 3\n2 0\n7 0\n8 3", "10 10\n1 0\n2 0\n3 0\n4 0\n5 1\n6 2\n7 3\n8 2\n9 3\n10 4", "50 10\n1 42\n7 36\n16 40\n21 40\n26 39\n30 41\n32 41\n36 40\n44 37\n50 41", "50 10\n5 17\n7 15\n10 4\n15 11\n18 13\n21 15\n31 5\n34 13\n40 15\n49 16", "100 50\n1 53\n3 51\n4 50\n6 48\n9 45\n12 48\n14 46\n16 4...
UNKNOWN
PYTHON3
CODEFORCES
21
786f75d6b052237b13d2da32090caf0a
Berland and the Shortest Paths
There are $n$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $1$ to $n$. It is known that, from the capital (the city with the number $1$), you can rea...
[ "from collections import deque\r\nn,r,k=map(int,input().split())\r\nedges=[[] for _ in range(n)]\r\nedge=[]\r\nfor i in range(r):\r\n temp=list(map(int,input().split()))\r\n edge.append([temp[0]-1,temp[1]-1])\r\n edges[temp[0]-1].append(temp[1]-1)\r\n edges[temp[1]-1].append(temp[0]-1)\r\nd=[float('inf'...
{"inputs": ["4 4 3\n1 2\n2 3\n1 4\n4 3", "4 6 3\n1 2\n2 3\n1 4\n4 3\n2 4\n1 3", "5 6 2\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5", "2 1 200000\n2 1", "3 2 100000\n1 2\n2 3", "3 2 100000\n1 2\n1 3", "3 3 1000\n1 2\n2 3\n3 1", "5 6 166666\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5", "5 6 10\n4 5\n3 2\n3 5\n1 3\n5 1\n1 2", "6 9 10\n3 5\n3 2\n1 3\...
UNKNOWN
PYTHON3
CODEFORCES
3
7876e81248cf45d60db62213c103a381
C*++ Calculations
C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (*expression* is the main term): - *expression...
[ "import re\r\n\r\nu = int\r\nG = input\r\nX = sorted\r\ny = print\r\nA = re.findall\r\na = u(G())\r\nb = X([[u((i[0]or '+')+(i[1]or '1')), i[3]]\r\n for i in A('(\\+|-)?(\\d{0,4})(\\*)?(a\\+\\+|\\+\\+a)', G())])\r\nz = 0\r\nfor i in b:\r\n if i[1] == 'a++':\r\n z += i[0]*a\r\n else:\r\n z ...
{"inputs": ["1\n5*a++-3*++a+a++", "3\na+++++a", "-668\n820*a+++402*++a-482*++a", "902\n600*++a+411*a+++20*a++-340*++a-306*++a+485*a++-776*a+++417*a+++70*a++-703*a++", "-215\n840*++a+183*++a-975*++a+301*a+++874*a++", "-211\n849*a++-419*a+++720*++a-543*a+++193*a++-506*++a", "-206\n859*a++-655*a+++466*++a-786*++a+512*a+++...
UNKNOWN
PYTHON3
CODEFORCES
6
787aba56bc9a1aaf3dc9a8864f8cf62f
Timofey and remoduling
Little Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime *m*. Also, Timofey likes to look for arithmetical progressions everywhere. One of his birthday presents was a sequence of distinct integers *a*1,<=*a*2,<=....
[ "import sys\r\n\r\ndef modInverse(x, y, mod):\r\n res = 1\r\n x = x % mod\r\n while(y > 0):\r\n if(y&1):\r\n res = (res * x) % mod\r\n y = y // 2\r\n x = (x * x) % mod\r\n \r\n return res\r\n\r\ndef isEqual(a, b):\r\n for i in range(len(a)):\r\n if (a[i] != b...
{"inputs": ["17 5\n0 2 4 13 15", "17 5\n0 2 4 13 14", "5 3\n1 2 3", "17 8\n7 9 11 13 15 1 3 5", "13 2\n0 11", "3 1\n0", "2 1\n1", "241 120\n235 136 237 28 90 60 27 122 239 59 72 46 180 233 182 21 206 153 97 112 94 219 52 109 31 17 8 152 3 118 191 222 214 119 217 39 33 40 1 164 38 173 42 82 130 229 226 73 44 155 85 41 2...
UNKNOWN
PYTHON3
CODEFORCES
2
788a3dee5440e886594b2630be6fc988
none
Filya just learned new geometry object — rectangle. He is given a field consisting of *n*<=×<=*n* unit cells. Rows are numbered from bottom to top with integer from 1 to *n*. Columns are numbered from left to right with integers from 1 to *n*. Cell, located at the intersection of the row *r* and column *c* is denoted a...
[ "import random\r\n\r\nclass interactor:\r\n def __init__(self, n):\r\n def correct(a, b, c, d, n):\r\n arr = [[0 for i in range(n + 1)] for j in range(n + 1)]\r\n for i in range(a[0], a[1] + 1):\r\n for j in range(b[0], b[1] + 1):\r\n arr[i][j] += 1\...
{"inputs": ["5\n2 2 2 2\n3 4 3 5", "10\n1 2 4 2\n1 6 4 9", "10\n2 2 4 4\n7 10 9 10", "10\n1 1 10 1\n5 5 5 10", "10\n3 4 10 4\n1 1 10 1", "100\n8 7 90 37\n4 64 4 100", "10\n1 3 1 3\n5 6 5 6", "8\n5 5 5 5\n7 7 7 7", "65536\n56677 37631 57096 58131\n37503 6356 53664 37172", "32768\n17828 4528 27798 14063\n19889 15555 2346...
UNKNOWN
PYTHON3
CODEFORCES
2
78954224f7bdc7ecf9906476c7b560db
Dispute
Valera has *n* counters numbered from 1 to *n*. Some of them are connected by wires, and each of the counters has a special button. Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly conn...
[ "import sys\nimport re\nfrom math import gcd, factorial as fact, hypot, atan2, pi,ceil,sqrt,log2,dist,isqrt\ntry: from math import lcm\nexcept: pass\ntry: from icecream import ic\nexcept: ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a)\nfrom heapq import *\nfrom random import *\nfrom itertools impor...
{"inputs": ["5 5\n2 3\n4 1\n1 5\n5 3\n2 1\n1 1 2 0 2", "4 2\n1 2\n3 4\n0 0 0 0", "3 3\n2 3\n1 3\n1 2\n1 1 3", "4 6\n3 4\n2 3\n2 4\n1 2\n1 3\n4 1\n4 0 2 3", "7 10\n5 4\n1 4\n7 4\n1 2\n6 2\n7 3\n7 2\n5 7\n6 1\n5 1\n3 3 0 3 4 1 4", "9 15\n7 4\n4 6\n3 2\n7 2\n8 1\n9 8\n9 6\n2 8\n7 8\n6 7\n3 6\n7 5\n3 5\n3 7\n1 7\n3 0 5 2 0...
UNKNOWN
PYTHON3
CODEFORCES
1
7897a1fc1ebef585fd78b52d787c82b8
Igor In the Museum
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i...
[ "import sys\r\nfrom collections import deque\r\n\r\n# import itertools\r\n# import math\r\n# import os\r\n# import random\r\n# from bisect import bisect, bisect_left\r\n# from collections import *\r\n# from functools import reduce\r\n# from heapq import heapify, heappop, heappush\r\n# from io import BytesIO, IOBase...
{"inputs": ["5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "4 4 1\n****\n*..*\n*.**\n****\n3 2", "3 3 1\n***\n*.*\n***\n2 2", "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2", "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 ...
UNKNOWN
PYTHON3
CODEFORCES
10
78ad365464eb2d196e496497bb74dac6
3-palindrome
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su...
[ "n = int(input())\r\ns = 'bbaa' * (n // 4 + 1)\r\ns = s[:n]\r\nprint(s)", "n = int(input())\r\nthingo=[\"a\",\"a\",\"b\",\"b\"]\r\n\r\n\r\nprint(int(n/4)*\"aabb\" + \"\".join(thingo[:n%4]))", "n = int(input())\r\nk=\"aabb\"\r\nprint(k*(n//4)+k[:n%4])", "s, n = \"aabb\", int(input())\r\nprint(s * ((n >> 1) >> ...
{"inputs": ["2", "3", "38", "47", "59", "67", "77", "89", "98", "109", "117", "1", "200000", "100000", "143670", "104217", "17879", "131809", "140873", "77859", "153022", "179227", "182801", "5188", "86539", "12802", "120289", "132866", "133377", "31775", "160397", "161415", "163623", "22942", "134767", "52257", "64905...
UNKNOWN
PYTHON3
CODEFORCES
236
78cd454c6bfd25122af23d08c5adc899
Undoubtedly Lucky Numbers
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits *x* and *y*. For example, if *x*<==<=4, and *y*<==<=7, then numbers 47, 744, 4 are lucky. Let's call a positive integer *a* undoubtedly lucky, if...
[ "n = int(input())\nm = set()\n\ndef dfs(num, x, y):\n global n\n if num == 0 or num > n:\n return\n m.add(num)\n num *= 10\n dfs(num + x, x, y)\n dfs(num + y, x, y)\n\nfor x in range(10):\n for y in range(10):\n if x == y:\n continue\n dfs(x, x, y)\n\nprint(len(m...
{"inputs": ["10", "123", "1", "2", "1000", "1000000000", "999999999", "999999998", "999999997", "909090901", "142498040", "603356456", "64214872", "820040584", "442198", "784262", "642678", "468390", "326806", "940", "356", "68", "132", "72", "89", "1", "3", "4", "5", "6", "7", "8", "9", "101", "102"], "outputs": ["10"...
UNKNOWN
PYTHON3
CODEFORCES
45
78ce6dee4e09ffe09fe48a5bcd2ea123
Yaroslav and Sequence
Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array el...
[ "n, t = int(input()), list(map(int, input().split()))\r\np = list(map(abs, t))\r\ns = sum(p)\r\nif n & 1 == 0 and len([0 for i in t if i < 0]) & 1: s -= 2 * min(p)\r\nprint(s)", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=sorted(map(abs,a))\r\nk=0\r\nfor x in a:\r\n if x<0: k+=1\r\nif k%2==0 or n%...
{"inputs": ["2\n50 50 50", "2\n-1 -100 -1", "3\n-959 -542 -669 -513 160", "4\n717 473 344 -51 -548 703 -869", "5\n270 -181 957 -509 -6 937 -175 434 -625", "6\n-403 901 -847 -708 -624 413 -293 709 886 445 716", "7\n-236 533 869 903 655 -714 27 890 -311 800 307 -682 665", "8\n-338 134 708 -761 -135 535 631 -354 -259 -973...
UNKNOWN
PYTHON3
CODEFORCES
12
78d130ce1afd05b3b09a51d2895466ea
Power Consumption Calculation
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
[ "n, P1, P2, P3, T1, T2=map(int,input().split())\r\ns=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if i==0:\r\n t=l\r\n if T1>=(l-t):\r\n s+=(l-t)*P1\r\n else:\r\n s+=T1*P1\r\n if T2>=(l-T1-t):\r\n s+=(l-T1-t)*P2\r\n else:\r\n s+=T2...
{"inputs": ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100", "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245", "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434", "7 4...
UNKNOWN
PYTHON3
CODEFORCES
171
78f4855baf50ff5eef1bbd27a0eaf775
Buns
Lavrenty, a baker, is going to make several buns with stuffings and sell them. Lavrenty has *n* grams of dough as well as *m* different stuffing types. The stuffing types are numerated from 1 to *m*. Lavrenty knows that he has *a**i* grams left of the *i*-th stuffing. It takes exactly *b**i* grams of stuffing *i* and ...
[ "n,m,c,d=map(int,input().split())\r\nar=[0]*1005\r\nfor i in range(c,n+1):\r\n ar[i]=ar[i-c]+d\r\nfor i in range(m):\r\n a,b,c,d=map(int,input().split())\r\n for j in range(a//b):\r\n e=n\r\n while(e>=c):\r\n ar[e]=max(ar[e],ar[e-c]+d)\r\n e-=1\r\nprint(ar[n])\r\n", "n...
{"inputs": ["10 2 2 1\n7 3 2 100\n12 3 1 10", "100 1 25 50\n15 5 20 10", "10 1 5 2\n100 1 2 3", "10 1 5 11\n3 1 3 8", "10 2 11 5\n100 1 3 10\n100 1 2 4", "5 8 6 5\n1 2 5 4\n1 2 6 7\n1 2 3 5\n1 2 1 6\n1 2 8 3\n1 2 2 4\n1 2 5 6\n1 2 7 7", "300 4 100 2\n10 1 24 5\n10 1 25 6\n10 1 26 7\n10 1 27 8", "1 1 1 1\n1 1 1 1", "2 1...
UNKNOWN
PYTHON3
CODEFORCES
33
78f83e8784694ae9326e4d91df76bbed
Team Work
You have a team of *N* people. For a particular task, you can pick any non-empty subset of people. The cost of having *x* people for the task is *x**k*. Output the sum of costs over all non-empty subsets of people. Only line of input contains two integers *N* (1<=≤<=*N*<=≤<=109) representing total number of people an...
[ "import sys\r\n\r\n\r\ndef I(): return int(sys.stdin.readline().rstrip())\r\ndef MI(): return map(int,sys.stdin.readline().rstrip().split())\r\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\r\ndef LI2(): return list(map(int,sys.stdin.readline().rstrip()))\r\ndef S(): return sys.stdin.readlin...
{"inputs": ["1 1", "3 2", "5 3", "12 4", "20 5", "522 4575", "1426 4445", "81 3772", "629 3447", "2202 3497", "2775 4325", "3982 4784", "2156 3417", "902 1932", "728 3537", "739 3857", "1918 4211", "3506 4679", "1000000000 5000", "2500 5000", "158260522 4575", "602436426 4445", "861648772 81", "433933447 629", "2627034...
UNKNOWN
PYTHON3
CODEFORCES
6
78fff4dcbecda8aae8ffe88f4ae1b36f
Tram
The tram in Berland goes along a straight line from the point 0 to the point *s* and back, passing 1 meter per *t*1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points *x*<==<=0 and *x*<==<=*s*. Igor is at the point *x*1. He should...
[ "def solve(a,i,j,m,n,o,d):\r\n if i>j:\r\n i=a-i\r\n j=a-j\r\n o=a-o\r\n d*=-1\r\n tmp=n*(j-i)\r\n c=0\r\n if d==-1:\r\n c=o+i\r\n elif o<=i:\r\n c=i-o\r\n else:\r\n c=2*a-(o-i)\r\n tmp=min(tmp,(c+j-i)*m)\r\n return tmp\r\n\r\na,i,j=map(int,in...
{"inputs": ["4 2 4\n3 4\n1 1", "5 4 0\n1 2\n3 1", "5 4 0\n5 14\n1 -1", "10 7 2\n7 9\n9 -1", "20 5 19\n163 174\n4 1", "1000 610 733\n226 690\n357 1", "40 31 14\n628 1000\n36 1", "100 20 83\n186 434\n64 -1", "200 179 81\n126 457\n37 -1", "400 30 81\n193 1000\n338 1", "500 397 440\n202 1000\n75 1", "600 443 587\n260 1000\...
UNKNOWN
PYTHON3
CODEFORCES
5
792832800768d03ba046bbaf6bc7252b
Beru-taxi
Vasiliy lives at point (*a*,<=*b*) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested *n* available Beru-taxi nearby. The *i*-th taxi is located at point (*x**i*,<=*y**i*) and moves with a speed *v**i*. Consider that each of *n* drivers will m...
[ "from math import sqrt\r\na, b = map(int, input().split())\r\nans = 100000\r\nfor _ in range(int(input())):\r\n x, y, v = map(int, input().split())\r\n q = sqrt(pow(abs(x-a),2)+pow(abs(y-b),2))/v\r\n if q < ans:\r\n ans = q\r\nprint(ans)\r\n", "# https://codeforces.com/problemset/problem/706/A\r\n...
{"inputs": ["0 0\n2\n2 0 1\n0 2 2", "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10", "2 2\n10\n8 10 1\n14 18 5\n2 2 1\n4 2 2\n5 2 1\n0 2 1\n2 10 4\n10 2 4\n14 18 20\n14 18 10", "-100 100\n3\n100 100 1\n-100 0 5\n-100 -100 20", "5 5\n4\n20 5 1\n20 5 3\n20 5 5\n20 5 15", "0 0\n6\n12 0 1\n0 12 12\n12 0 6\n12 0 3\n0 12 4\n12 0 2", "0 0\n...
UNKNOWN
PYTHON3
CODEFORCES
19
793101446ecf77b43dcb093365a0c277
Arthur and Table
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d...
[ "\nn = int(input())\nlengths = list(map(int, input().split()))\ncosts = list(map(int, input().split()))\nsum = 0\nlength_to_sum = {}\nlength_to_count = {}\ncost_to_lengths = {}\n\nfor i in range(n):\n length, cost = lengths[i], costs[i]\n sum += cost\n length_to_sum[length] = length_to_sum.setdefault(length, 0) ...
{"inputs": ["2\n1 5\n3 2", "3\n2 4 4\n1 1 1", "6\n2 2 1 1 3 3\n4 3 5 5 2 1", "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146", "10\n15 16 19 5 14 19 6 17 7 19\n140 183 186 195 67 25 70 56 54 132", "20\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\n24 137 173 189 43 164 2 11 142 153 16 20...
UNKNOWN
PYTHON3
CODEFORCES
15
79517c03da7240d02d74e5c8b15b5af8
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=&gt;<=1) is such maximum element *x**j*, that the following inequality holds: . The lucky number of the sequence of distinct positive integers *x*1,<=*x*2,<...
[ "def maximum_xor_secondary(sequence):\n stack, answer = [], 0\n for x in sequence:\n while stack:\n answer = max(answer, stack[-1] ^ x)\n if stack[-1] > x:\n break\n else:\n stack.pop()\n stack.append(x)\n\n return answer\n\n\nsiz...
{"inputs": ["5\n5 2 1 4 3", "5\n9 8 3 5 7", "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446", "10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331", "10\n30301275 19973434 63004643 54007648 93722492 91677384 58694045 41546981 15552151 ...
UNKNOWN
PYTHON3
CODEFORCES
20
7955c1f6f1073143e4e2612f93654a80
Little Pony and Harmony Chest
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers *b**i* is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony se...
[ "import math\r\ninf = float('inf')\r\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]\r\nm = len(primes)\r\n\r\nto_choose = [[] for _ in range(1 << m)]\r\nmask = {}\r\nfor i in range(1, 60):\r\n v = 0\r\n for j in range(m):\r\n if math.gcd(i, primes[j]) > 1:\r\n v |...
{"inputs": ["5\n1 1 1 1 1", "5\n1 6 4 2 8", "10\n16 3 16 10 12 5 14 14 15 27", "10\n8 7 11 5 17 24 28 18 7 8", "10\n22 17 28 14 14 26 20 28 21 27", "10\n28 13 14 9 26 21 25 16 4 22", "100\n11 27 18 3 26 1 23 2 28 21 28 18 7 26 13 4 12 11 1 29 9 23 6 27 15 6 26 25 11 21 26 29 29 8 18 29 3 24 2 28 7 7 11 23 26 29 30 18 3...
UNKNOWN
PYTHON3
CODEFORCES
1
7957d1deb681dae7bde5b711125af628
Defragmentation
In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to *n*. The disk has *m* recorded files, the *i*-th file occupies clusters with numbers *a**i*,<=1, *a**i*,<=2, ..., *a**i*,<=*n**i*. These clusters are not nece...
[ "import sys\r\nn, m, *inp = map(int, sys.stdin.read().split())\r\n\r\ninp.reverse()\r\nf = [[0 for x in range(201)] for y in range(201)] #2D Array\r\nc = [(0,0)]*201\r\nf_size = [0]*201\r\n\r\ndef putData(f_id, s_id, c_id):\r\n global f, c\r\n f[f_id][s_id] = c_id\r\n c[c_id] = (f_id, s_id)\r\n\r\nfor ...
{"inputs": ["7 2\n2 1 2\n3 3 4 5", "7 2\n2 1 3\n3 2 4 5", "2 1\n1 2", "3 1\n2 3 1", "3 2\n1 3\n1 2", "5 3\n1 2\n1 4\n1 5", "7 3\n1 7\n2 6 5\n3 4 3 2", "7 2\n3 1 3 5\n3 2 4 6", "10 1\n5 7 4 6 9 2", "7 2\n2 2 1\n3 3 4 5", "7 2\n2 1 2\n3 4 5 6", "20 5\n7 12 16 14 17 20 4 15\n2 7 8\n1 5\n5 3 6 18 11 2\n4 9 13 19 1", "20 10...
UNKNOWN
PYTHON3
CODEFORCES
2
798e69af66946802a90c8b03fcdb29c4
Pie or die
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at...
[ "n, m, k = map(int, input().split())\r\nfor i in range(k):\r\n x, y = map(int, input().split())\r\n if min(n-x, x-1, m-y, y-1) <5:\r\n print('YES')\r\n exit()\r\nprint('NO')", "n, m, k = map(int, input().split())\nwin = False\nfor i in range(k):\n x, y = map(int, input().split())\n if ab...
{"inputs": ["2 2 1\n1 2", "3 4 0", "100 50 2\n50 25\n50 25", "20 20 4\n10 10\n10 10\n10 10\n10 10", "15 15 1\n8 8", "8 8 2\n4 4\n5 5", "100 100 2\n50 96\n51 96", "100 100 2\n50 95\n51 95", "20 20 1\n16 10", "20 20 4\n15 9\n15 10\n15 11\n15 12", "11 11 1\n6 6", "11 11 1\n6 5", "35 13 20\n13 8\n19 8\n24 7\n20 6\n23 7\n23...
UNKNOWN
PYTHON3
CODEFORCES
10