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
bca8f2c3bacf7b7637b3e7c60e95a021
Fly, freebies, fly!
Everyone loves a freebie. Especially students. It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flown freebie helps him to pass the upcoming exam. In the night before the exam on mathematical analysis *n...
[ "n = int(input())\r\np = list(map(int,input().split()))\r\nT = int(input())\r\np.sort()\r\nfs = 0\r\nmaxx = 0\r\nfor i in range(n):\r\n while fs<n and p[fs]-p[i]<=T:\r\n fs+=1\r\n maxx = max(maxx,fs-i)\r\nprint(maxx)", "read = lambda: map(int, input().split())\r\nn = int(input())\r\na = sorted(read(...
{"inputs": ["6\n4 1 7 8 3 8\n1", "4\n4 2 1 5\n2", "10\n4 7 1 3 8 5 2 1 8 4\n3", "8\n39 49 37 28 40 17 50 2\n10", "2\n1 1\n1", "2\n1 1\n2", "2\n1 1\n1000", "2\n1 2\n2", "2\n450 826\n1000", "3\n3 1 1\n1", "3\n3 1 2\n2", "3\n3 4 3\n1", "3\n3 4 3\n1", "100\n63 69 36 40 74 31 86 42 81 95 60 55 98 98 2 16 84 37 61 47 81 91 8...
UNKNOWN
PYTHON3
CODEFORCES
36
bcbdca7bed3cf5b0c900d268a0fbb27e
Casinos and travel
John has just bought a new car and is planning a journey around the country. Country has *N* cities, some of which are connected by bidirectional roads. There are *N*<=-<=1 roads and every city is reachable from any other city. Cities are labeled from 1 to *N*. John first has to select from which city he will start hi...
[ "n=int(input())\na = [0]*(n+1)\nfor i in range(n-1):\n for i in input().split():\n a[int(i)]+=1\nl = a.count(1)\nprint ((l*2**(n-l+1)+(n-l)*(2**(n-l)))%(10**9+7))\n \t\t\t \t \t\t\t\t\t\t\t\t\t\t \t\t\t \t \t\t\t\t", "n = int(input())\r\ncnt = [[] for _ in range(n)]\r\nfor i in range (n - 1):\r\n f...
{"inputs": ["2\n1 2", "3\n1 2\n2 3", "4\n1 2\n2 3\n3 4"], "outputs": ["4", "10", "24"]}
UNKNOWN
PYTHON3
CODEFORCES
6
bcbfe74a23a31ba03505e0c77eeef23c
Alena And The Heater
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following proced...
[ "n = int(input())\r\n\r\narr = [int(z) for z in input().split()]\r\n\r\nb = [int(z) for z in input()]\r\n\r\nl, r = -10**9, 10**9\r\n\r\nfor i in range(1, n):\r\n\r\n if b[i] != b[i-1]:\r\n\r\n if b[i] == 1:\r\n for k in range(5):\r\n l = max(l-1, arr[i-k]) + 1\r\n if b[i]...
{"inputs": ["5\n1 2 3 4 5\n00001", "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110", "10\n-8 -9 -9 -7 -10 -10 -8 -8 -9 -10\n0000000011", "11\n226 226 226 226 226 227 1000000000 1000000000 228 1000000000 1000000000\n00001111110", "95\n-97 -98 -92 -93 94 96 91 98 95 85 90 86 84 83 81 79 82 79 73 -99 -91 -93 -92 -97 -85 -88 -...
UNKNOWN
PYTHON3
CODEFORCES
23
bcc97263183979d209e5ab6a23185300
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are *n* extensions, the *i*-th of them multiplies the width or the length (b...
[ "f = lambda: map(int, input().split())\r\na, b, h, w, n = f()\r\nc = sorted(list(f()), key=lambda x: -x)\r\nd = {(h, w), (w, h)}\r\nfor i, q in enumerate([1] + c):\r\n for u, v in d.copy():\r\n h, w = u, v * q\r\n if a <= w and b <= h or a <= h and b <= w:\r\n print(i)\r\n exi...
{"inputs": ["3 3 2 4 4\n2 5 4 10", "3 3 3 3 5\n2 3 5 4 2", "5 5 1 2 3\n2 2 3", "3 4 1 1 3\n2 3 2", "572 540 6 2 12\n2 3 2 2 2 3 3 3 2 2 2 2", "375 905 1 1 17\n2 2 3 3 3 3 3 3 2 2 2 2 3 2 2 2 3", "37 23 4 1 16\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "20 19 6 8 18\n3 4 2 3 4 3 2 4 2 2 4 2 4 3 2 4 4 2", "11 11 5 3 11\n4 4 2 4 ...
UNKNOWN
PYTHON3
CODEFORCES
1
bcce2d002f657ac7dccfcbef1ce7137d
Average Numbers
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of th...
[ "from math import gcd,lcm,sqrt,factorial\r\ndef solve():\r\n s=sum(a)\r\n AVG=s//n\r\n if s%n:print(0);return\r\n li,ans=[],0\r\n for i in range(n):\r\n if AVG==a[i]:\r\n li.append(i+1)\r\n ans+=1\r\n print(ans)\r\n print(*li)\r\n\r\nif __name__ == '__main__':\r\n ...
{"inputs": ["5\n1 2 3 4 5", "4\n50 50 50 50", "3\n2 3 1", "2\n4 2", "2\n1 1", "10\n3 3 3 3 3 4 3 3 3 2", "10\n15 7 10 7 7 7 4 4 7 2", "6\n2 2 2 2 2 2", "6\n3 3 3 3 3 3", "4\n6 6 6 7", "2\n1 2", "3\n3 3 4", "5\n7 6 6 6 6", "4\n3 5 5 9", "3\n99 100 99", "4\n5 6 5 5", "6\n1 1 2 1 1 1", "2\n4 5", "4\n1 1 1 2", "3\n1 2 4", ...
UNKNOWN
PYTHON3
CODEFORCES
130
bcd6a289c4ca64bddbb3a92d687dfda3
Sum of Nestings
Recall that the bracket sequence is considered regular if it is possible to insert symbols '+' and '1' into it so that the result is a correct arithmetic expression. For example, a sequence "(()())" is regular, because we can get correct arithmetic expression insering symbols '+' and '1': "((1+1)+(1+1))". Also the foll...
[ "import sys\ninput = sys.stdin.buffer.readline\ndef ints():\n return map(int, input().split())\n\nn, k=ints()\n\nif k > (n-1)*n//2:\n print(\"Impossible\")\n exit(0)\n\nsum=0\nans=''\nfor i in range(n+1):\n if sum+i>k:\n ans+='('*(i)\n ans+=')'*(i-(k-sum))\n if i!=n:\n an...
{"inputs": ["3 1", "4 6", "2 5", "1 0", "2 0", "2 1", "3 0", "10 42", "3 2", "3 3", "4 1", "4 2", "4 0", "4 3", "4 4", "4 5", "20 132", "5 0", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "5 11", "50 282", "100 4298", "201 19557", "301 43259", "333 3286", "400 14432", "500 12169", "1000 101063...
UNKNOWN
PYTHON3
CODEFORCES
9
bce21ee8b1160c20c0b326ab3867d800
none
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's ...
[ "s=str(input())\r\nn=len(s)\r\nlstl=[]\r\nlstr=[]\r\nfor i in range(0,n):\r\n if(s[i]=='l'):\r\n lstl.append(i+1)\r\n else:\r\n lstr.append(i+1)\r\n\r\nlstl.reverse()\r\nfor i in lstr:\r\n print(i)\r\nfor i in lstl:\r\n print(i)\r\n", "def main():\n line = input()\n l = [None] * le...
{"inputs": ["llrlr", "rrlll", "lrlrr", "lllrlrllrl", "llrlrrrlrr", "rlrrrllrrr", "lrrlrrllrrrrllllllrr", "rlrrrlrrrllrrllrlrll", "lllrrlrlrllrrrrrllrl", "rrrllrrrlllrlllrlrrr", "rrlllrrrlrrlrrrlllrlrlrrrlllrllrrllrllrrlrlrrllllrlrrrrlrlllrlrrrlrlrllrlrlrrlrrllrrrlrlrlllrrllllrl", "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrr...
UNKNOWN
PYTHON3
CODEFORCES
145
bcf965fe41db5c767e712d73903ad8b4
IQ Test
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 ...
[ "a = list(map(int, input().split()))\r\n\r\nif a[0] > a[-1] and a[0]/a[1] == a[1]/a[2] and a[1]/a[2] == a[2]/a[3]:\r\n print(int(a[-1]/(a[0]/a[1]) if int(a[-1]/(a[0]/a[1])) == (a[-1]/(a[0]/a[1])) else 42))\r\n\r\nelif a[-1] > a[0] and a[1]/a[0] == a[2]/a[1] and a[2]/a[1] == a[3]/a[2]:\r\n print(int(a[-1]*(a[1...
{"inputs": ["836 624 412 200", "1 334 667 1000", "501 451 400 350", "836 624 412 200", "1 334 667 1000", "11 234 457 680", "640 431 222 13", "1 1 1 1", "1 10 100 1000", "3 18 108 648", "512 384 288 216", "891 297 99 33", "64 160 400 1000", "501 451 400 350", "501 450 400 350", "4 32 48 64", "9 8 7 5", "992 994 998 1000...
UNKNOWN
PYTHON3
CODEFORCES
15
bcfaa0ca75d2308244afef49d1cea846
Eight Point Sets
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int...
[ "a = []\r\nxDistinct = []\r\nyDistinct = []\r\n\r\nfor i in range(0, 8):\r\n [n1, n2] = map(int, input().split())\r\n a.append([n1, n2])\r\n\r\n if(n1 not in xDistinct):\r\n xDistinct.append(n1)\r\n\r\n if(n2 not in yDistinct):\r\n yDistinct.append(n2)\r\n\r\n\r\ncountDistinctX = len(xDist...
{"inputs": ["0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2", "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "1000000 1000000\n1000000 999999\n1000000 999998\n999999 1000000\n999999 999998\n999998 1000000\n999998 999999\n999998 999998", "0 0\n1 0\n0...
UNKNOWN
PYTHON3
CODEFORCES
36
bd184280a9f5454d5dab9c2732b3319e
Login Verification
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ...
[ "ss = input()\r\nst = \"\"\r\nfor j in range(len(ss)):\r\n c = ss[j]\r\n if 'A' <= c <= 'Z':\r\n c = chr(ord(c) + ord('a') - ord('A'))\r\n if c == 'o':\r\n c = '0'\r\n if c == 'l' or c == 'i':\r\n c = '1'\r\n st += c\r\ns = st\r\nn = int(input())\r\nfor i in range(n):\r\n ss =...
{"inputs": ["1_wat\n2\n2_wat\nwat_1", "000\n3\n00\nooA\noOo", "_i_\n3\n__i_\n_1_\nI", "La0\n3\n2a0\nLa1\n1a0", "abc\n1\naBc", "0Lil\n2\nLIL0\n0Ril", "iloO\n3\niIl0\noIl0\nIooO", "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o", "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuo...
UNKNOWN
PYTHON3
CODEFORCES
193
bd2451122914e33f4f8c5309b0ce78a4
Ralph And His Magic Field
Ralph has a magic field which is divided into *n*<=×<=*m* blocks. That is to say, there are *n* rows and *m* columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to *k*, where *k* ...
[ "import sys\r\nimport math\r\nfrom collections import defaultdict,deque\r\nimport heapq\r\nn,m,k=map(int,sys.stdin.readline().split())\r\nmod=10**9+7\r\nans=pow(2,(n-1)*(m-1),mod)\r\nif m%2!=0 and n%2==0 and k==-1:\r\n ans=0\r\nif m%2==0 and n%2!=0 and k==-1:\r\n ans=0\r\nprint(ans)\r\n", "n,m,k=map(int,inp...
{"inputs": ["1 1 -1", "1 3 1", "3 3 -1", "2 7 1", "1 1 1", "2 4 -1", "173 69 -1", "110 142 1", "162 162 -1", "49 153 -1", "94 182 1", "106666666 233333333 1", "2 2 1", "146 34 -1", "94 86 -1", "2529756051797760 2682355969139391 -1", "3126690179932000 2474382898739836 -1", "3551499873841921 2512677762780671 -1", "361345...
UNKNOWN
PYTHON3
CODEFORCES
18
bd3cadf754cab70e6a2d233db4f043b8
Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some pr...
[ "n = int(input())\r\nl = list(map(int,input().split()))\r\nsum = 0\r\nimport math\r\ndef check(n,i):\r\n for j in range(int(math.log2(n)),-1,-1):\r\n k = pow(2,j)+ i\r\n if k <= n-1:\r\n # print(j)\r\n # print(\"go\")\r\n return k\r\none = check(n,0) \r\nl[one]= l[0...
{"inputs": ["4\n1 0 1 2", "8\n1 2 3 4 5 6 7 8", "5\n4 1 4 7 6", "9\n13 13 7 11 3 9 3 5 5", "30\n8 17 20 15 18 15 20 10 5 13 5 4 15 9 11 14 18 15 7 16 18 9 17 7 10 9 5 13 17 16", "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100...
UNKNOWN
PYTHON3
CODEFORCES
76
bd4762d12fc7e77b0c0d4de102cb8527
Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are *n* toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turne...
[ "n,a=int(input()),[]\r\nfor i in range(n):\r\n x = list(map(int, input().split(\" \")))\r\n if 1 not in x and 3 not in x:\r\n a.append(i+1)\r\nprint(len(a))\r\nprint(*sorted(a))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nans = []\r...
{"inputs": ["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1", "1\n-1", "2\n-1 0\n0 -1", "2\n-1 1\n2 -1", "2\n-1 2\n1 -1", "2\n-1 3\n3 -1"], "outputs": ["2\n1 3 ", "0", "1\n1 ", "2\n1 2 ", "1\n2 ", "1\n1 ", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
18
bd5208069eb280e2184f0cb0354c9f46
Roman Digits
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence s...
[ "n = int(input().strip())\n\ndef C(n, r):\n c = 1\n for i in range(r):\n c = c * (n-i)\n for i in range(r):\n c = c // (i+1)\n return c\n\ndef calc(n, r):\n if n < 0: return 0\n return C(n+r-1, r-1)\n\nans = 0\n\n# case 1: d = 0\nfor i in range(5):\n ans += calc(n-i, 2)\n\nfor i i...
{"inputs": ["1", "2", "10", "1000", "2000", "5000", "10000", "111199", "101232812", "1000000000", "3", "4", "5", "6", "7", "8", "9", "11", "12", "13", "55", "100", "150", "1200", "9999999", "100000000", "500000000", "600000000", "709000900", "999999999", "12", "10", "20", "35", "56", "83", "116", "155", "198", "244", "...
UNKNOWN
PYTHON3
CODEFORCES
61
bd719ab213ef0b26f27fe550275da0a6
Bishwock
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board wi...
[ "a = input()\nb = input()\nn = len(a)\nans = 0\nl = 2\ni = 0\nif a[0] == \"X\":\n l -= 1\nif b[0] == \"X\":\n l -= 1\nwhile i < n - 1:\n count = 0\n if a[i + 1] == \"0\":\n count += 1\n if b[i + 1] == \"0\":\n count += 1\n if l + count >= 3:\n ans += 1\n if l + count ==...
{"inputs": ["00\n00", "00X00X0XXX0\n0XXX0X00X00", "0X0X0\n0X0X0", "0XXX0\n00000", "0\n0", "0\nX", "X\n0", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "0000X0X...
UNKNOWN
PYTHON3
CODEFORCES
64
bd87b63d0f16726a4b3413a926b48787
Colliders
By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated. In 2312 there was a startling discov...
[ "n, m = map(int, input().split())\r\nn += 1\r\n \r\ns = [[] for i in range(n)]\r\n\r\nfor j in range(2, n, 2): \r\n s[j] = [2]\r\n \r\nfor i in range(3, n, 2):\r\n if s[i]: continue\r\n for j in range(i, n, i): \r\n s[j].append(i)\r\n\r\npresent, alreadyOn, status = {}, set(), ['']*m\r\nfor c in ...
{"inputs": ["10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3", "7 5\n+ 7\n+ 6\n+ 4\n+ 3\n- 7", "10 5\n+ 2\n- 8\n- 4\n- 10\n+ 1", "10 10\n+ 1\n+ 10\n- 1\n- 10\n+ 1\n- 1\n+ 7\n+ 8\n+ 6\n- 7", "15 15\n+ 12\n+ 6\n+ 13\n- 13\n+ 7\n+ 14\n+ 8\n+ 13\n- 13\n+ 15\n+ 4\n+ 10\n+ 11\n+ 2\n- 14", "2 20\n+ 1\n+ 2\n- 2\n+ 2...
UNKNOWN
PYTHON3
CODEFORCES
15
bd93876715337bec98a7dcf52670749a
Selection of Personnel
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the...
[ "from math import factorial\na = int(input())\ns = ((factorial(a)//(factorial(5)*factorial(a-5)))+(factorial(a)//(factorial(6)*factorial(a-6)))+(factorial(a)//(factorial(7)*factorial(a-7))))\nprint(s)\n", "from math import comb\r\nn = int(input())\r\nprint(comb(n, 5) + comb(n, 6) + comb(n, 7))\r\n", "n = int(in...
{"inputs": ["7", "8", "9", "10", "321", "624", "666", "700", "776", "777"], "outputs": ["29", "92", "246", "582", "66715035255088", "7147161340917624", "11292070960994226", "16017044425409540", "33019955679376860", "33319741730082870"]}
UNKNOWN
PYTHON3
CODEFORCES
22
bd9edbfd06ea3a9c193aa506376798d5
Queue at the School
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea...
[ "q, r = map(int, input().split())\r\nt1 = input()\r\nt = []\r\nfor o in t1:\r\n t.append(o)\r\nfor j in range(r):\r\n i = 0\r\n while i < len(t)-1:\r\n if t[i] == 'B' and t[i + 1] == 'G':\r\n t[i], t[i + 1] = t[i + 1], t[i]\r\n i += 2\r\n else:\r\n i += 1\r\nt...
{"inputs": ["5 1\nBGGBG", "5 2\nBGGBG", "4 1\nGGGB", "2 1\nBB", "2 1\nBG", "6 2\nBBGBBG", "8 3\nBBGBGBGB", "10 3\nBBGBBBBBBG", "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBG...
UNKNOWN
PYTHON3
CODEFORCES
274
bda0355b3e14ac689c64b4f8e787b398
Fedor and Essay
After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all...
[ "from collections import defaultdict\n\n\ndef process_word(word, index):\n return word.count('r'), len(word), index.setdefault(word, len(index))\n\n\ndef main():\n index = {}\n input()\n essay = list(map(lambda word: process_word(word, index), input().lower().split()))\n queue = essay[:]\n\n syn =...
{"inputs": ["3\nAbRb r Zz\n4\nxR abRb\naA xr\nzz Z\nxr y", "2\nRuruRu fedya\n1\nruruRU fedor", "1\nffff\n1\nffff r", "2\nYURA YUrA\n1\nyura fedya", "5\nhello my name is fedya\n2\nhello hi\nis i", "5\nawiuegjsrkjshegkjshegseg g soeigjseg www s\n3\nwww s\nawiuegjsrkjshegkjshegseg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...
UNKNOWN
PYTHON3
CODEFORCES
4
bdb9dc8c6e0599d351c32f5631a32ceb
Igor and his way to work
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
[ "from collections import defaultdict, deque, Counter\r\nfrom functools import lru_cache\r\nfrom heapq import heappush, heappop\r\nfrom bisect import bisect_right, bisect_left\r\n\r\ndef inpNum():\r\n return int(input())\r\ndef inpStr():\r\n return input()\r\ndef inpSepNum():\r\n return map(int, input().spl...
{"inputs": ["5 5\nS....\n****.\n.....\n.****\n..T..", "1 2\nST", "3 1\nS\n*\nT", "3 3\n*..\n...\nTS.", "3 3\nT.*\n*.*\n*S*", "7 7\n.S.****\n...*.*.\n.****..\n.*.**.*\n..T*...\n***..*.\n*******", "3 3\n**T\n*S*\n***", "2 2\nST\n*.", "2 2\nS.\n.T", "2 2\nTS\n.*", "2 2\n.T\nS*"], "outputs": ["NO", "YES", "NO", "YES", "YES...
UNKNOWN
PYTHON3
CODEFORCES
16
bdbd3d0e9509abf077169578711b6d9d
Cookies
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
[ "n = int(input())\r\na = [int(i) for i in input().split()]\r\nx = sum(a)\r\ncounter = 0\r\n\r\nfor i in range(len(a)):\r\n difference = x - a[i]\r\n if difference % 2 == 0:\r\n counter = counter + 1\r\n\r\nprint(counter)", "n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\n\r\n\r\nSum=sum(l)\...
{"inputs": ["1\n1", "10\n1 2 2 3 4 4 4 2 2 2", "11\n2 2 2 2 2 2 2 2 2 2 99", "2\n1 1", "2\n2 2", "2\n1 2", "7\n7 7 7 7 7 7 7", "8\n1 2 3 4 5 6 7 8", "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
729
bdc6c256029b80385a04823c5aed31f5
Stages
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are $n$ stages available. The ro...
[ "a='abcdefghijklmnopqrstuvwxyz'\r\nn,k=map(int,input().split( ))\r\ns=list(input())\r\ns.sort()\r\ng=(a.index(s[0])+1)\r\nk-=1\r\np=1\r\nm=''\r\nm+=s[0]\r\nwhile k!=0:\r\n if a.index(s[p])-a.index(m[len(m)-1])>=2:\r\n m+=s[p]\r\n g+=(a.index(s[p])+1)\r\n k-=1\r\n p+=1\r\n if p==n and k...
{"inputs": ["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb", "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa", "1 1\na", "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
213
bdccebbc59ea21c3a871ae1558ed6845
The Sum of the k-th Powers
There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109<=+<=7 (so you should find the remainder after dividing the answer by the value 109<=+<=7). The only line contains two integers *n*,<=*k* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*k*<=≤<=106). Pri...
[ "import os\r\nimport sys\r\nimport time\r\nfrom io import BytesIO, IOBase\r\n\r\n# region fastio\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in ...
{"inputs": ["4 1", "4 2", "4 3", "4 0", "10 0", "1 1", "1 0", "1 1000000", "1000000000 0", "100 100", "10000 100", "100 10000", "1000000000 1000000", "1000000 1000000", "999999 1000000", "77674473 447444", "333312494 795258", "761637147 673329", "335185991 514401", "203702132 355473", "1000000000 999935"], "outputs": [...
UNKNOWN
PYTHON3
CODEFORCES
5
bdd1384c3c4e5c12f47e15657aa8931f
Square and Rectangles
You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the ...
[ "# LUOGU_RID: 116314114\nn, s = int(input()), 0\r\nmix = miy = float('inf')\r\nmaxx = maxy = -1\r\nfor i in range(n):\r\n a, b, c, d = *map(int, input().split()),\r\n s += (c-a)*(d-b)\r\n mix, miy = min(mix, a), min(miy, b)\r\n maxx, maxy = max(maxx, c), max(maxy, d)\r\nif maxx-mix == maxy-miy:\r\n i...
{"inputs": ["5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400", "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 31400...
UNKNOWN
PYTHON3
CODEFORCES
10
bde75bac39cbfe4af0d371bb6c7c6336
Encryption (easy)
Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo...
[ "n, P = map(int, input().split())\r\na = list(map(lambda x: int(x) % P, input().split()))\r\npre = a[0]\r\nsuf = sum(a[1:]) % P\r\nnum = pre + suf\r\nfor i in range(1, n - 1):\r\n pre += a[i]\r\n pre %= P\r\n suf -= a[i]\r\n if suf < 0:\r\n suf += P\r\n\r\n num = max(num, pre + suf)\r\n\r\npri...
{"inputs": ["4 10\n3 4 7 2", "10 12\n16 3 24 13 9 8 7 5 12 12", "2 2\n9 9", "2 2\n8 8", "5 50\n1 1 1 1 1", "5 50\n100 150 200 100 50"], "outputs": ["16", "13", "2", "0", "5", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
52
bdfe2b1e3fe543e13b9b8077113d91f6
Oleg and shares
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ...
[ "import math\r\n\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\na.sort()\r\nr=a[0]%k;t=0\r\nfor i in range(1,n):\r\n if a[i]%k!=r:\r\n print(-1)\r\n break\r\n else:\r\n t+=(a[i]-a[0])//k\r\nelse:\r\n print(t)\r\n", "n, k=map(int, input().split())\na=list(m...
{"inputs": ["3 3\n12 9 15", "2 2\n10 9", "4 1\n1 1000000000 1000000000 1000000000", "1 11\n123", "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 7...
UNKNOWN
PYTHON3
CODEFORCES
171
be28a9f0e51e26043794e8ef4aac3703
Work Group
One Big Software Company has *n* employees numbered from 1 to *n*. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call person *a* a subordinates of another person *b*, if either *b* is an...
[ "n = int(input())\r\nt = [list(map(int, input().split())) for q in range(n)]\r\nn += 1\r\nu = [-1e7] * n\r\nv = [0] * n\r\nfor i, (j, a) in list(enumerate(t, 1))[::-1]:\r\n u[i] = max(u[i], v[i] + a)\r\n v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])\r\nprint(u[1])" ]
{"inputs": ["7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2", "1\n-1 42", "2\n-1 3\n1 2", "3\n-1 3\n1 1\n1 2", "3\n-1 1\n1 2\n1 3", "3\n-1 3\n1 2\n2 1", "20\n-1 100\n1 10\n2 26\n2 33\n3 31\n2 28\n1 47\n6 18\n6 25\n9 2\n4 17\n6 18\n6 2\n6 30\n13 7\n5 25\n7 11\n11 7\n17 40\n12 43", "20\n-1 100\n1 35\n2 22\n3 28\n3 2\n4 8\n3 17\n2...
UNKNOWN
PYTHON3
CODEFORCES
1
be357e1a04067eead63b9cf1cc2b9af5
Little Frog
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha...
[ "n=int(input())\r\nj=1\r\nk=n\r\nfor i in range(n):\r\n if i%2 ==0:\r\n print(j,end=\" \")\r\n j +=1\r\n else:\r\n print(k,end=\" \")\r\n k-=1\r\nprint(\"\")", "n = int(input())\r\n# print(n//2+1)\r\nif n & 1:\r\n for i in range(1, n//2+2):\r\n # print(i, n-i+1, end=' '...
{"inputs": ["2", "3", "4", "5", "6", "1", "9149", "2877", "2956", "3035", "3114", "3193", "3273", "7000", "7079", "4653", "9995", "9996", "9997", "9998", "9999", "10000"], "outputs": ["1 2 ", "1 3 2 ", "1 4 2 3 ", "1 5 2 4 3 ", "1 6 2 5 3 4 ", "1 ", "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 914...
UNKNOWN
PYTHON3
CODEFORCES
123
be67cd8ea92d99b084fd6081677642af
Tree of Life (easy)
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of *n* points...
[ "n = int(input())\nt = [0] * n\nout = 0\nfor _ in range(n-1):\n\ta, b = input().split(' ')\n\ta, b = [int(a), int(b)]\n\tt[a-1] += 1\n\tt[b-1] += 1\nfor x in t:\n\tout += x * (x-1) / 2\nprint(int(out))\n", "n = int(input())\r\nd = [0] * (n + 1)\r\nfor _ in range(n - 1):\r\n x, y = map(int, input().split())\r\n ...
{"inputs": ["4\n1 2\n1 3\n1 4", "5\n1 2\n2 3\n3 4\n3 5", "2\n1 2", "3\n2 1\n3 2", "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4"], "outputs": ["3", "4", "0", "1", "11"]}
UNKNOWN
PYTHON3
CODEFORCES
24
be8d9759934859ff03c9d87c8f9ded2f
Friends
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just c...
[ "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nd = [0]*5\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n d[a-1] += 1\r\n d[b-1] += 1\r\nif d.count(2) == 5:\r\n print('FAIL')\r\nelse:\r\n print('WIN')\r\n", "from sys import stdin,stdout\r\nii1 = lambda: int(s...
{"inputs": ["4\n1 3\n2 3\n1 4\n5 3", "5\n1 2\n2 3\n3 4\n4 5\n5 1", "1\n4 3", "6\n1 3\n2 3\n1 2\n5 3\n4 2\n4 5", "2\n1 3\n2 5", "3\n5 3\n4 3\n4 5", "5\n1 3\n3 2\n2 4\n5 4\n1 5", "7\n1 3\n5 1\n1 4\n2 1\n5 3\n4 5\n2 5", "5\n5 1\n4 1\n2 3\n4 5\n3 1", "0", "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "4\n1 2\n2 3...
UNKNOWN
PYTHON3
CODEFORCES
65
beb216e4c28803c082eec7de44f0dd98
none
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 two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits...
[ "a=input()\r\nb=input()\r\nk1=0\r\nk2=0\r\nfor i in range (len(a)):\r\n if a[i]!=b[i]:\r\n if a[i]=='4':\r\n k1+=1\r\n else:\r\n k2+=1\r\nd=max(k1,k2)\r\nprint (d)", "a=input()\r\nb=input()\r\nf=0\r\ns=0\r\nfor i in range(len(a)):\r\n if a[i]!=b[i]:\r\n if a[i]==\"...
{"inputs": ["47\n74", "774\n744", "777\n444", "74747474\n77777777", "444444444444\n777777777777", "4744744447774474447474774\n4477774777444444444777447", "7\n4", "4\n7", "7777777777\n7777777774", "47777777777\n77777777774", "47747477747744447774774444444777444747474747777774\n4477744477447744777744477447777747777444447...
UNKNOWN
PYTHON3
CODEFORCES
110
bec9ea76bca8acdbb8400cd3fe1e396f
The Artful Expedient
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
[ "import sys\r\n\r\nn = int(sys.stdin.readline())\r\narr1 = list(map(int, sys.stdin.readline().split()))\r\narr2 = list(map(int, sys.stdin.readline().split()))\r\ncnt = 0\r\narr = arr1 + arr2\r\nfor i in arr:\r\n for j in arr:\r\n temp = i ^ j\r\n if temp == 2 * n:\r\n cnt += 1\r\nprint('Kar...
{"inputs": ["3\n1 2 3\n4 5 6", "5\n2 4 6 8 10\n9 7 5 3 1", "1\n1\n2000000", "2\n97153 2000000\n1999998 254", "15\n31 30 29 28 27 26 25 24 23 22 21 20 19 18 17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 12...
UNKNOWN
PYTHON3
CODEFORCES
84
bed62bfd6378b367e3fe0617a419b84a
Save the problem!
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
[ "n=int(input())\r\nprint(2*n-1, 2)\r\nprint(1, 2)", "n = int(input())\r\nprint (max(1,n*2-2),2,end=\" \\n\")\r\nprint (1,2,end=\" \")", "n=int(input())\r\nprint(n*2-1,2)\r\nprint(1,2)", "n = int(input())\r\nprint(max(1, (n - 1) * 2), 2)\r\nprint(1, 2)\r\n", "n = int(input())\r\n\r\nif n % 2 == 0:\r\n pri...
{"inputs": ["18", "3", "314", "1023", "100000", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "239", "4063", "65536", "65535", "65537", "99991", "99990", "99992", "99971", "99990", "2", "99991"], "outputs": ["30 4\n1 5 10 25", "20 2\n5 2", "183 4\n6 5 2 1...
UNKNOWN
PYTHON3
CODEFORCES
43
beda8b32b0ec9b99868f00941d309d79
Tyndex.Brome
Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome! The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac...
[ "from bisect import bisect_left\r\nn,k=map(int,input().split())\r\nq=\"abcdefghijklmnopqrstuvwxyz\"\r\na={i:[] for i in q}\r\n\r\nfor key,value in enumerate(input()):a[value].append(key)\r\n#print(a)\r\ndef g(t):return [(t[i]+t[i-1])//2 for i in range(1,len(t))] #类似于二分查找的思路 //便于快速确定位置\r\nc={i:g(a[i]) for i in q}...
{"inputs": ["2 10\ncodeforces\ncodeforces\ncodehorses", "9 9\nvkontakte\nvcontacte\nvkontrakte\nvkollapse\nvkrokodile\nvtopke\nvkapuste\nvpechke\nvk\nvcodeforcese", "3 3\nbyg\ndwg\nl\nx", "4 4\nlocw\na\nr\nba\nxuv", "5 5\nvpjjx\njj\ne\nnor\nuthm\nbf", "10 10\nczuanvzpiq\nc\ng\ni\nx\na\ny\nz\nk\nf\nx", "15 15\ndtpbfpabi...
UNKNOWN
PYTHON3
CODEFORCES
4
bee568ff74ad54cec8202b1f59786496
Physics Practical
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h...
[ "x = open(\"input.txt\", \"r\")\nn = int(x.readline())\nc = sorted(map(int, x.readline().split()))\na, b = 0, n-1\nfor i in range(n):\n while a < n-1 and 2 * c[i] >= c[a+1]:\n a += 1\n b = min(b, n+i-a-1)\nopen(\"output.txt\", \"w\").write(str(b))\n \t\t\t\t \t\t\t \t \t \t\t \t\t\t \t\t", "i...
{"inputs": ["6\n4 5 3 8 3 7", "4\n4 3 2 4", "6\n5 6 4 9 4 8", "4\n5 4 1 5", "2\n3 2", "10\n39 9 18 13 6 16 47 15 1 24", "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45", "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18", "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 2...
UNKNOWN
PYTHON3
CODEFORCES
71
beedede080fa2c18f6b59e2bbe40ce40
Malek Dance Club
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n* members. Each member of MDC is assigned a unique id *i* from 0 to 2*n*<=-<=1. The same holds for eac...
[ "s=input()\na=int(s,2)\nn=len(s)\nprint((a*(2**(n-1)))%1000000007)\n\n", "s=input()\r\na=int(s,2)\r\nn=len(s)\r\nprint((a*(2**(n-1)))%1000000007)", "s = input()[::-1]\r\nans = 0\r\nfor i in range(len(s)):\r\n if s[i] == '0':\r\n ans = ans * 2 % (10 ** 9 + 7)\r\n else:\r\n ans = (ans * 2 + 2 ...
{"inputs": ["11", "01", "1", "1111111111111111111111111111111111", "0000000000000000000000000000000000000", "11111111111111111111111111111111111000000000000000000000000000", "00000000000000000000111111111111111111111111111111111111111111", "10100101000010011110101011011110001", "0101010000101011111100111100100010101001...
UNKNOWN
PYTHON3
CODEFORCES
22
bf3e927823c777d2ef7bd32bc83e59eb
Easter Eggs
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s...
[ "n=int(input())\r\narr=['R','O','Y','G']\r\nprint(\"BIV\",end='')\r\nfor i in range(n-3):\r\n\tprint(arr[i%4],end='')", "n=int(input())\r\na='ROYGBIV'\r\nfor i in range(7,n):\r\n for j in ['R','O','Y','G','B','I','V']:\r\n if j!=a[i-1] and j!=a[i-2] and j!=a[i-3] and (i+1<n or j!=a[(i+1)%n]) and (i+2<n ...
{"inputs": ["8", "13", "7", "10", "14", "50", "9", "11", "12", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "28", "29", "34", "43", "61", "79", "81", "92", "95", "96", "97", "98", "99", "100"], "outputs": ["ROYGBIVG", "ROYGBIVOYGBIV", "ROYGBIV", "ROYGBIVYGB", "ROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBI...
UNKNOWN
PYTHON3
CODEFORCES
274
bf4dd0423ecea20ddef0b68b094f200c
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
[ "n = int(input())\r\nl = list(map(int,input().split()))\r\np = max(l)\r\nv=0\r\nr=0\r\nfor i in l:\r\n v = p-i\r\n r+=v\r\nprint(r)\r\n \r\n ", "a=int(input())\r\nb=list(map(int,input().split()))\r\nm=max(b)\r\nq=sum(b)\r\nprint(a*m-q)", "\n\ndef solve():\n n = int(input())\n numbers = input()...
{"inputs": ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12", "3\n1 2 3", "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 24154...
UNKNOWN
PYTHON3
CODEFORCES
1,122
bf66bc37c82f2c30ec50a774ce6d0932
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-...
[ "import math\r\nn = int(input())\r\nl = [int(p) for p in input().strip('\\n').split(' ')]\r\na = max(l)\r\nb = int(math.ceil(max(l)/2))\r\nc = int(math.floor(max(l)/2)) + 1\r\ntemp = -1 * (sum(l) - a - b - c)\r\nprint(str(temp))\r\n", "n = int(input())\nl = [int(x) for x in input().split()]\nl.sort()\nprint(2*l[n...
{"inputs": ["3\n1 2 1", "5\n20 4 3 2 1", "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086", "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194", "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 63849...
UNKNOWN
PYTHON3
CODEFORCES
147
bf68fad205ecadb130b7e87b5aac8a68
Chris and Road
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
[ "f = lambda: map(int, input().split())\r\nn, w, v, u = f()\r\nk = t = 0\r\nv /= u\r\nfor i in range(n):\r\n x, y = f()\r\n d = x / v - y\r\n k |= d < 0\r\n t = max(t, d)\r\nif k: w += t\r\nprint(w / u)" ]
{"inputs": ["5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4", "3 3 5 2\n3 1\n4 0\n5 1", "3 3 2 4\n0 1\n2 1\n1 2", "3 3 1 1\n0 0\n1 1\n0 2", "9 10 5 2\n22 5\n25 0\n29 0\n31 2\n32 5\n31 8\n29 10\n25 10\n23 8", "10 10 2 4\n-4 5\n-3 2\n-1 0\n3 0\n5 2\n6 5\n5 8\n3 10\n-1 10\n-2 9", "10 10 1 4\n-1 5\n0 2\n2 0\n5 0\n7 1\n9 5\n8 8\n6 10\n2 ...
UNKNOWN
PYTHON3
CODEFORCES
1
bf78b5d20ae69dfbd2374b041a0e3b55
Valera and Tubes
Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*). Valera w...
[ "def print_tube(a):\r\n\tprint(len(a),end = \" \")\r\n\tprint(\" \".join(map(lambda x: \" \".join(str(i) for i in x), a)))\r\nn, m, k = map(int, input().split())\r\nres = [(x+1,y+1) for x in range(n) for y in range(m)[::(1 if (x%2 == 0) else -1)]]\r\nfor i in range(k-1):\r\n\tprint_tube(res[2*i:2*i+2])\r\nprint_tub...
{"inputs": ["3 3 3", "2 3 1", "2 3 1", "300 300 2", "300 300 150", "300 299 299", "300 300 45000", "300 299 44850", "2 2 2", "2 3 3", "3 3 4", "5 5 12", "7 5 17", "135 91 4352", "32 27 153", "74 83 2667", "296 218 5275", "89 82 2330", "15 68 212", "95 4 177", "60 136 8", "91 183 7827", "2 15 3", "139 275 10770", "114 2...
UNKNOWN
PYTHON3
CODEFORCES
91
bf841357522a9a2799b0b9ada43e47dd
Ksusha and Array
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! The first line contains integer ...
[ "n = int(input())\r\na = list(map(int,input().split()))\r\nrs = min(a)\r\nfor i in a:\r\n if i%rs!=0:\r\n print(-1)\r\n exit()\r\nprint(rs)", "garbage = int(input())\r\nl = list(map(int, input().rstrip().split(\" \")))\r\nm = min(l)\r\nr = m\r\nfor i in l:\r\n if i%m !=0:\r\n r = -1\r\n...
{"inputs": ["3\n2 2 4", "5\n2 1 3 1 6", "3\n2 3 5", "1\n331358794", "5\n506904227 214303304 136194869 838256937 183952885", "2\n500000000 1000000000", "2\n4 6", "5\n10 8 6 4 2", "2\n6 10", "1\n1000000000", "2\n6 8", "5\n2 2 2 2 1000000000", "2\n6 4"], "outputs": ["2", "1", "-1", "331358794", "-1", "500000000", "-1", "2...
UNKNOWN
PYTHON3
CODEFORCES
187
c008ffb743cb2d9e14ef24a4fd1394ae
Mages and Monsters
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values *x**i* and *y**i* — damage per second and mana cost per second, respectivel...
[ "#!/usr/bin/env python3\n\n# solution after hint\n# (instead of best hit/mana spell store convex hull of spells)\n# O(n^2) instead of O(n log n)\n\n\n[q, m] = map(int, input().strip().split())\nqis = [tuple(map(int, input().strip().split())) for _ in range(q)]\n\nmod = 10**6\n\nj = 0\nspell_chull = [(0, 0)] # lowe...
{"inputs": ["3 100\n1 4 9\n2 19 49\n2 19 49", "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "2 424978864039\n2 7 3\n2 10 8", "3 10\n1 1 1\n2 1 1\n2 999999 999999", "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 9...
UNKNOWN
PYTHON3
CODEFORCES
1
c01e2b377cf5803a3db4c18e169a42d5
Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores *t* points, he wins the set; then the ...
[ "#!/usr/bin/env python3\n\nimport itertools\n\nn = int(input())\na = [int(x) for x in input().split()]\n\nwinner = a[-1]\nlooser = 3 - winner\nserve_win_cnt, serve_loose_cnt, win_pos, loose_pos, result = [0], [0], [-1], [-1], []\nwin_cnt = a.count(winner)\n\nfor i in range(n):\n if a[i] == winner:\n win_p...
{"inputs": ["5\n1 2 1 2 1", "4\n1 1 1 1", "4\n1 2 1 2", "8\n2 1 2 1 1 1 1 1", "14\n2 1 2 1 1 1 1 2 1 1 2 1 2 1", "10\n1 1 2 2 1 1 2 2 1 1", "20\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1", "186\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1...
UNKNOWN
PYTHON3
CODEFORCES
1
c0315ec500973071a258e2b530a085a5
Maxim Buys an Apartment
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale. Maxim often visi...
[ "n,k=map(int,input().split())\r\nm=0\r\nif n==k or k==0:\r\n print(0,0)\r\nelif 3*k<=n:\r\n print(1,2*k)\r\nelif k<=n:\r\n print(1,n-k)\r\nelse:\r\n print(0,0)", "# LUOGU_RID: 132834153\nn,k=map(int,input().split())\r\nprint(1-(k==0 or k==n),min(n-k,k*2))\r\n", "a=[int(x) for x in input().split()]\r...
{"inputs": ["6 3", "10 1", "10 9", "8 0", "8 8", "966871928 890926970", "20 2", "1 0", "1 1", "2 0", "2 1", "2 2", "7 2", "8 3", "9 4", "10 3", "10 4", "10 5", "1000 1000", "1000 333", "1000 334", "999 333", "999 334", "998 332", "998 333", "89 4", "66 50", "88 15", "95 43", "900 344", "777 113", "964 42", "982 867", "...
UNKNOWN
PYTHON3
CODEFORCES
82
c0519a7dc6f0c45ebc244c6c22cec56d
Max History
You are given an array *a* of length *n*. We define *f**a* the following way: - Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=&lt;<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*. Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 1...
[ "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\n\r\n\r\np = 10**9+7 \r\ndef process(A):\r\n n = len(A)\r\n fact_dict = [1]\r\n for i in range(1, n+1):\r\n x = fact_dict[-1]\r\n fact_dict.append((i*x) % p)\r\n A.sort()\r\n m = A[-1]\r\n curr = 0\r\n answer = 0\r\n for i...
{"inputs": ["2\n1 3", "3\n1 1 2", "6\n1 4 5 2 3 3", "8\n8 7 5 4 6 6 6 6", "8\n1 2 3 9 100 100 100 100", "1\n364489807", "1\n194945396", "9\n25401015 88843847 702650194 306965770 57623156 571088345 835502151 56113403 116176210", "3\n855856619 518546431 920370158", "7\n686312223 948248999 138090108 566544521 711825575 41...
UNKNOWN
PYTHON3
CODEFORCES
3
c05fc5f9b4c21dc89887cfb96b7400ea
Colored Balls
There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that: - each ball belongs to exactly one of the sets, - there are no empty sets, - there is no ...
[ "def judge(lists, x):\n ans = 0\n for i in lists:\n t = i//x\n d = i%x\n if d == 0:\n ans += t\n elif t+d >= x-1:\n ans += t+1\n else:\n return -1\n\n return ans\n\nwhile True:\n try:\n n = input()\n balls = list(map(int, ...
{"inputs": ["3\n4 7 8", "2\n2 7", "1\n1", "1\n1000000000", "2\n1000000000 1", "2\n9 6", "2\n948507270 461613425", "5\n8 7 4 8 3", "5\n11703 91351 99 16279 50449", "20\n3 2 1 1 1 2 2 2 3 3 1 1 3 2 3 3 2 3 3 2", "20\n895 8894 6182 5852 9830 7562 8854 4004 5909 4979 6863 2987 3586 1319 513 5496 9543 9561 6590 5063", "200\...
UNKNOWN
PYTHON3
CODEFORCES
5
c086d2e71d8091df7b4eef2dd781beec
Valera and Number
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below: Now Valera wonders: given the values *x*, *k* and *p*, what is the expected value of the resulting number *s*? The first line of the input contains three integers *x*,<=*k*,<=*p* (1<=≤<=*x*<=≤<=109; 1<=≤<=*k*<=≤<=200...
[ "def lbt(x):return 0 if x&1 else lbt(x>>1)+1\r\nx,k,p=map(int,input().split())\r\np,m=p/100,k>>1\r\nf=[lbt(x+i) for i in range(k+1)]\r\nfor i in range(k):\r\n\tg=[0]*(k+1)\r\n\tfor j in range(k+1):\r\n\t\tif j>=1:g[j-1]+=(1-p)*f[j]\r\n\t\tif j<=m:g[j<<1]+=p*(f[j]+1)\r\n\tf=g\r\nprint('%.8f'%f[0])" ]
{"inputs": ["1 1 50", "5 3 0", "5 3 25", "1132123 200 0", "1213112 200 100", "490879136 12 75", "114566801 2 55", "331870050 6 98", "252615193 9 45", "224314221 19 51", "510823354 20 18", "573292218 200 77", "465672965 100 95", "853095531 50 72", "254290166 200 95", "206910020 200 4", "680841078 112 48", "92021679 54 2...
UNKNOWN
PYTHON3
CODEFORCES
1
c08a7770e7aaa6e439fb7923a9c9b201
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with *n* notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal....
[ "import sys\r\n \r\ndef solve():\r\n n = int(sys.stdin.readline())\r\n a = [0] + [int(i) for i in sys.stdin.readline().split()]\r\n \r\n dp = [[0]*(n + 1) for i in range(n + 1)]\r\n ans = 0\r\n \r\n maxnum = [0] * (10**5 + 2)\r\n maxmod = [0] * 7\r\n \r\n for y in range(n + 1):\r\n maxmo...
{"inputs": ["4\n1 2 4 5", "6\n62 22 60 61 48 49", "2\n1 4", "2\n5 4", "10\n9 6 8 5 5 2 8 9 2 2", "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333", "10\n1 1 1 1 1 1 1 1 1 1", "4\n15 11 28 17", "3\n1 36 6", "6\n3 12 4 12 5 6", "6\n7 20 21 22 23 28"], "outputs": ["4", "5", "2", "2", "9", "6", "10", "2", "3",...
UNKNOWN
PYTHON3
CODEFORCES
1
c0a0039fbe76bdb7d48cb9d1f504232e
System Administrator
Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair o...
[ "n, m, v = map(int, input().split())\r\ndef main(n, m, v):\r\n if m < n - 1 or m > (n - 3) * (n - 2) // 2 + n - 1:\r\n print(-1)\r\n return\r\n for i in range(1, n+1):\r\n if i == v:\r\n continue\r\n print(i, v)\r\n edges = n - 1\r\n for i in range(1, n):\r\n ...
{"inputs": ["5 6 3", "6 100 1", "10 26 1", "20 155 1", "30 393 29", "50 535 8", "100 4283 65", "1000 51277 488", "10000 57971 8854", "100000 99999 41895", "99999 100000 66180", "99997 99997 72727", "100000 100000 100000", "100000 100000 1", "100000 99999 100000", "100000 99999 1", "100000 99998 100000", "100000 99998 1...
UNKNOWN
PYTHON3
CODEFORCES
12
c0c1479e7ce5028f5eaa529aedd3e85c
Bars
Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can eit...
[ "import sys\r\nfrom math import *\r\nfrom fractions import gcd\r\nfrom random import * # randint(inclusive,inclusive)\r\nreadints=lambda:map(int, input().strip('\\n').split())\r\nfrom itertools import permutations, combinations\r\ns = \"abcdefghijklmnopqrstuvwxyz\"\r\n# print('', end=\" \")\r\n# for i in {1..5}; do...
{"inputs": ["3 3\n010", "8 3\n01010110", "9 5\n001100110", "2 2\n00", "3 2\n010", "3 2\n000", "3 3\n000", "4 2\n0000", "4 2\n0100", "4 2\n0010", "4 2\n0110", "4 3\n0000", "4 3\n0010", "4 3\n0100", "4 3\n0110", "4 4\n0000", "4 4\n0100", "4 4\n0010", "4 4\n0110", "10 3\n0111011010", "100 19\n00110111100111111110101111011...
UNKNOWN
PYTHON3
CODEFORCES
7
c0c31df16741dd7d0059f2a9ec8f3864
Super Agent
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
[ "kl=\"\";\r\nfor i in range(3):\r\n kl+=input();\r\nprint(['NO','YES'][kl==kl[::-1]]);", "s=input()\ns+=input()\ns+=input()\nflag=True\nfor i in range(5):\n if(s[i]!=s[8-i]):\n flag=False\n break;\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=input()\...
{"inputs": ["XX.\n...\n.XX", ".X.\n.X.\n.X.", "XXX\nXXX\nXXX", "XXX\nX.X\nXXX", "X..\n.X.\n..X", "...\nX.X\nX..", ".X.\nX.X\n.X.", "X.X\n.X.\nX.X", "...\n...\n..X", "XXX\n...\nXXX", "..X\nX..\n..X", ".X.\n...\nX.X", "X.X\nX.X\nX.X", ".X.\nX.X\nXX.", "...\nXXX\nXXX", "XXX\n..X\nXXX", "X..\nX.X\n.X.", "...\n..X\nXXX", "....
UNKNOWN
PYTHON3
CODEFORCES
320
c0f901607f527b8e6f3e00116e7c7ab4
Petya and Square
Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not ha...
[ "a,b,c=map(int,input().split())\r\nif(b==a//2 or b==a//2+1) and (c==a//2 or c==a//2+1):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")" ]
{"inputs": ["4 1 1", "2 2 2", "8 2 5", "6 1 6", "2 1 1", "2 1 2", "2 2 1", "4 2 2", "4 2 3", "4 2 4", "60 30 30", "60 34 30", "60 31 29", "100 61 30", "100 52 50", "100 51 51", "100 1 2", "100 1 8", "100 19 99", "100 18 82", "100 100 50", "100 51 100", "100 100 100", "6 3 3", "6 4 4", "6 3 1", "6 3 5", "8 4 4", "6 3 2"...
UNKNOWN
PYTHON3
CODEFORCES
1
c1099b4137bcb0dc819f8df0ea6630c3
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge)....
[ "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\njauap=0\r\nfor i in a:\r\n while i>k*2:\r\n jauap+=1\r\n k=k*2\r\n k=max(k,i)\r\nprint(jauap)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\ncurr = 0\r\nans = 0\r\nwh...
{"inputs": ["3 3\n2 1 9", "4 20\n10 3 6 3", "1 1000000000\n1", "1 1\n3", "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 ...
UNKNOWN
PYTHON3
CODEFORCES
61
c11ed3f7cf93b87239cbf0e5d6a42e5b
Alyona and Numbers
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
[ "def inp():\r\n return map(int, input().split())\r\n\r\n\r\ndef fill_arr(n):\r\n return [0 for x in range(n)]\r\n\r\n\r\nx, y = inp()\r\na, b = fill_arr(5), fill_arr(5)\r\nfor i in range(1, x + 1):\r\n a[i % 5] += 1\r\nfor i in range(1, y + 1):\r\n b[i % 5] += 1\r\nsum = a[0] * b[0]\r\nfor i in range(1,...
{"inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21", "10 15", "1 1", "1 1000000", "1000000 1", "1000000 1000000", "944 844", "368 984", "792 828", "920 969", "640 325", "768 170", "896 310", "320 154", "744 999", "630 843", "54 688", "478 828", "902 184", "31 29", "751 169", "879 14", "7 858", "431 702", "855 355...
UNKNOWN
PYTHON3
CODEFORCES
371
c12241ccb6ccd236b53aeca845120461
Ciel and Duel
Fox Ciel is playing a card game with her friend Jiro. Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the follo...
[ "from bisect import bisect_left, bisect_right, insort\nfrom itertools import chain, repeat, starmap\nfrom functools import reduce\nfrom math import log\nfrom operator import add, eq, ne, gt, ge, lt, le, iadd\nfrom collections.abc import Sequence\n\n\nclass SortedList:\n DEFAULT_LOAD_FACTOR = 1000\n\n def __in...
{"inputs": ["2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "1 1\nATK 100\n99", "4 8\nDEF 100\nDEF 200\nDEF 300\nATK 100\n100\n101\n201\n301\n1\n1\n1\n1", "3 4\nDEF 100\nATK 200\nDEF 300\n101\n201\n301\n1", "4 4\nDEF 0\nDEF 0\nDEF 0\nATK ...
UNKNOWN
PYTHON3
CODEFORCES
5
c15f635616d643c4688b14322dc81920
Amr and Music
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for ...
[ "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\n#a.sort()\r\nl=[]\r\nfor i in range(n):\r\n l.append((a[i],i+1))\r\nl.sort()\r\ncnt=0\r\np=[]\r\ns=0\r\nk=0\r\n#print(l)\r\nfor i in range(n):\r\n s=s+l[i][0]\r\n if s<=m:\r\n cnt+=1\r\n p.append(l[i][1])\r\n else:\r\n ...
{"inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4", "2 100\n100 100", "3 150\n50 50 50", "4 0\n100 100 100 100", "100 7567\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
UNKNOWN
PYTHON3
CODEFORCES
192
c1728962a6cce0de630f0372867289aa
Game Shopping
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
[ "n, m = [int(x) for x in input().split(' ')]\nc = [int(x) for x in input().split(' ')]\na = [int(x) for x in input().split(' ')]\ncnt = 0\nfor i in range(n):\n if c[i] <= a[0]:\n a.pop(0)\n cnt += 1\n if len(a) <= 0: break \nprint(cnt)\n", "def main():\n [n_games, n_bills] = [int(_) for _ in input().sp...
{"inputs": ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "5 1\n1 1 1 1 1\n5", "5 1\n10 1 1 1 1\n1000", "5 1\n100 100 100 100 100\n100", "2 1\n2 1\n1", "2 3\n3 1\n2 4 2", "1 5\n4\n1 4 3 3 2", "5 3\n4 2 3 1 1\n2 1 3", "3 5\n5 2 5\n1 4 1 4 2", "7 3\n9 7 10 2 1 1 1\n...
UNKNOWN
PYTHON3
CODEFORCES
321
c1a730423f27fa14659fb6ff4387706b
Looking for Order
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl canno...
[ "#!/usr/bin/env python\n'''\n' Author: Cheng-Shih Wong\n' Email: [email protected]\n' Date: 2017-08-08\n'''\n\nfrom itertools import chain\nfrom time import time\n\ndef main():\n\n BITS = [1 << sh for sh in range(24)]\n B2N = {v: u for u, v in enumerate(BITS)}\n\n def getPt():\n return tupl...
{"inputs": ["0 0\n2\n1 1\n-1 1", "1 1\n3\n4 3\n3 4\n0 0", "-3 4\n1\n2 2", "7 -7\n2\n3 1\n-3 8", "3 -9\n3\n0 -9\n-10 -3\n-12 -2", "4 -1\n4\n14 -3\n-11 10\n-3 -5\n-8 1", "7 -11\n5\n-1 7\n-7 -11\n12 -4\n8 -6\n-18 -8", "11 3\n6\n-17 -17\n-4 -9\n15 19\n7 4\n13 1\n5 -6", "-6 4\n7\n-10 -11\n-11 -3\n13 27\n12 -22\n19 -17\n21 -...
UNKNOWN
PYTHON3
CODEFORCES
6
c1e7da4ca3f099a03821e7eefe9f889b
Ilya and Escalator
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue en...
[ "n , p , t = input ( ) . split ( )\n\nn = int ( n )\np = float ( p )\nt = int ( t )\n\nif n >= t :\n\n ans = 0\n \n for tt in range ( t ) :\n \n ans = p * ( ans + 1 ) + ans * ( 1 - p )\n \n print(round(ans,7))\n \n exit()\n \nN = [ 0 for i in range ( n + 1 ) ]\n\nN [ 0 ] =...
{"inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2", "2000 0.61 2000", "100 1.00 200", "417 0.57 742", "100 0.01 53", "300 0.05 55", "1400 0.02 200", "2000 0.01 234", "1 0.01 2000", "300 0.99 1000", "400 0.96 1754", "2000 0.93 100", "1000 0.90 1733", "1 1.00 1", "2000 1.00 2000", "2000 0.00 2000", "2000 0.01 2000", "2000 0....
UNKNOWN
PYTHON3
CODEFORCES
25
c20295e447351fec89195b82e112921a
Preparing Olympiad
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contes...
[ "n,l,r,x = [int(x) for x in input().split()]\r\ntemp2 = sorted([int(x) for x in input().split()])\r\ndef choo(h,amount,prev,total):\r\n #print(prev)\r\n if amount == h:\r\n #print(total,prev,h)\r\n if temp2[prev[-1]] - temp2[prev[0]] >= x and total >= l and total <= r:\r\n return 1\r\n else:\r\n ...
{"inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20", "4 15 60 10\n10 20 30 25", "1 10 20 1\n15", "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 ...
UNKNOWN
PYTHON3
CODEFORCES
67
c238239f5c75f82bf35be066d8493e38
Sonya and Queries
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b...
[ "n = int(input())\r\na = []\r\nwk1 = \"0\" * 18\r\nrules = str.maketrans(\"0123456789\", \"0101010101\")\r\ntrans = lambda x : str.translate(x, rules)\r\nd = {}\r\nfor _ in range(n):\r\n x, y = input().split()\r\n y = int(trans(y), 2)\r\n if x == \"+\":\r\n d[y] = d.get(y, 0) + 1\r\n elif x == \"...
{"inputs": ["12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "4\n+ 200\n+ 200\n- 200\n? 0", "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\...
UNKNOWN
PYTHON3
CODEFORCES
30
c24a81f69a8987d5a513e4987cd9b6b9
Arpa’s obvious problem and Mehrdad’s terrible solution
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad di...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nfrom collections import defaultdict\r\n\r\nN,X = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nM = max(A)\r\n\r\nans = 0\r\nlib = defaultdict(int)\r\nfor a in A:\r\n ans+=lib[a^X]\r\n lib[a]+=1\r\n \r\nprint(ans)\r\n\...
{"inputs": ["2 3\n1 2", "6 1\n5 1 2 3 4 1", "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 1...
UNKNOWN
PYTHON3
CODEFORCES
16
c25593723134889d759fd6786d906c97
none
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ...
[ "n=int(input())\r\nl=[]\r\nl1=[]\r\nfor i in range(n):\r\n l.append([int(j) for j in input().split()])\r\n l1.append(0)\r\ni=0\r\nwhile (i<n):\r\n if (l1[i]==0):\r\n l1[i]=1\r\n v=l[i][0]\r\n d=0\r\n for j in range(i+1,n):\r\n if (l1[j]==0):\r\n l[j][2]...
{"inputs": ["5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 ...
UNKNOWN
PYTHON3
CODEFORCES
10
c25b6da41baeb504d209ee704414dbfc
Area of a Star
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star. A "star" figure having *n*<...
[ "from math import *\r\nn,r = map(int,input().split()) \r\nprint(n*r*r/(1/tan(pi/(2*n))+1/tan(pi/n)))", "# /**\r\n# * author: brownfox2k6\r\n# * created: 16/08/2023 16:36:45 Hanoi, Vietnam\r\n# **/\r\n\r\nfrom math import tan, pi\r\n\r\nn, r = map(int, input().split())\r\n\r\nstri = (r**2) / (2 * (1/tan(p...
{"inputs": ["7 10", "5 1", "7 1000", "11 1000000000", "999999937 1", "999999929 2", "999999929 1000000000", "603530531 585244", "7369339 31415926", "2341 5001"], "outputs": ["108.395919545675", "1.122569941449", "1083959.195456745256", "1061689977712182980.125000000000", "1.047197551197", "4.188790204786", "10471975511...
UNKNOWN
PYTHON3
CODEFORCES
2
c261497be852ac543fbe17bd9a243b60
Vulnerable Kerbals
You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1. You would like to construct a sequence satisfying the properties: - Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m*...
[ "maxn = 200500\r\ng = [[] for i in range(maxn)] # Array de array g[i][j] en el cual la posicion i representa gcd(a,m)\r\n # y en el array [j] se guardan todos los ¨a¨ con gcd comunes\r\ndp = [0 for i in range(maxn)] # guarda la profundidad mayor para cada nodo\r\nban = [0 for i in rang...
{"inputs": ["0 5", "3 10\n2 9 1", "0 1", "0 720", "0 9997", "0 200000", "10 200000\n7853 79004 71155 23846 63333 31964 47634 15792 39758 55551", "3 19997\n4524 13719 9073", "3 19997\n2024 4058 6143", "3 19997\n6068 18563 12338"], "outputs": ["5\n1 2 4 3 0", "6\n3 9 2 9 8 0", "1\n0", "397\n1 7 413 263 389 467 77 283 299...
UNKNOWN
PYTHON3
CODEFORCES
2
c27368c56a4d9ea1647917157aef81aa
Check the string
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
[ "# import sys\r\n# input = sys.stdin.readline\r\n\r\nfor _ in range(1):#int(input())):\r\n s = input()\r\n a, b, c = 0, 0, 0\r\n flag = 0\r\n if (s[0] == 'a'): a += 1\r\n for i in range(1, len(s)):\r\n if (s[i] >= s[i-1]):\r\n if (s[i] == 'a'):\r\n a += 1\r\n ...
{"inputs": ["aaabccc", "bbacc", "aabc", "aabbcc", "aaacccbb", "abc", "acba", "bbabbc", "bbbabacca", "aabcbcaca", "aaaaabbbbbb", "c", "cc", "bbb", "bc", "ccbcc", "aaa", "aaccaa", "a", "b", "abca", "aabbcccc", "abac", "abcc", "abcb", "aacc", "aabbaacccc", "aabb", "ac", "abbacc", "abacc", "ababc", "aa", "aabaccc", "bbcc",...
UNKNOWN
PYTHON3
CODEFORCES
120
c28cf0add33a4e63ce6077ddf93bd7e9
Devu, the Dumb Guy
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
[ "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\nc=0\r\nfor i in range(n):\r\n c+=x[i]*max((m-i),1)\r\nprint(c)", "\n\"\"\"\nSolved by Fuad Ashraful BBabu\n#soled date 12 july 2019\n#verdict : AC \n\n\"\"\"\n\n\nn,p=map(int,input().split())\n\n\n\nar=list(map(int,input().split()...
{"inputs": ["2 3\n4 1", "4 2\n5 1 2 1", "3 3\n1 1 1", "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3", "1 1\n9273", "1 1\n1", "1 2\n1", "1 2\n2", "2 1\n1 2"], "outputs": ["11", "10", "6", "65", "196", "9273", "1", "2", "4", "3"]}
UNKNOWN
PYTHON3
CODEFORCES
299
c2a566fe43974d07b567fd3c0e438366
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $Ox$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $Ox$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recently, ...
[ "n=int(input())\r\nlast_r=None\r\nlast_b=None\r\nlast_p=None\r\nans=0\r\nmax_r=0\r\nmax_b=0\r\nmax_p=0\r\nfor _ in range(n):\r\n s=input().split()\r\n x=int(s[0])\r\n c=s[1]\r\n if c=='B':\r\n if last_b!=None:\r\n ans+=x-last_b\r\n max_b=max(max_b,x-last_b)\r\n last_b...
{"inputs": ["4\n-5 R\n0 P\n3 P\n7 B", "5\n10 R\n14 B\n16 B\n21 R\n32 R", "10\n66 R\n67 R\n72 R\n73 R\n76 R\n78 B\n79 B\n83 B\n84 B\n85 P", "10\n61 R\n64 R\n68 R\n71 R\n72 R\n73 R\n74 P\n86 P\n87 B\n90 B", "15\n-9518 R\n-6858 P\n-6726 B\n-6486 R\n-4496 P\n-4191 P\n-772 B\n-258 R\n-194 P\n1035 R\n2297 P\n4816 B\n5779 R\n...
UNKNOWN
PYTHON3
CODEFORCES
6
c2d5c5716d620d4c3e6264bef5bdc57b
Wizards and Trolleybuses
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of *d* meters from the depot. We know for the *i*-th trolleybus that ...
[ "n, a, d = map(int, input().split())\r\nt = 0;\r\nfor i in range (n):\r\n t0, v = map(int, input().split())\r\n t1 = v / a\r\n s1 = v**2 / (2*a)\r\n if s1 > d:\r\n t = max(t, t0 + (2*d/a)**0.5)\r\n else:\r\n t = max(t0 + t1 + (d - s1)/v, t)\r\n print(t)\r\n", "from sys import stdin...
{"inputs": ["3 10 10000\n0 10\n5 11\n1000 1", "1 2 26\n28 29", "7 8 3\n1 3\n5 26\n7 3\n10 15\n18 7\n21 17\n23 21", "3 6 6\n2 10\n14 19\n18 14", "10 7 8\n2 4\n3 13\n4 7\n5 1\n9 16\n10 9\n12 18\n16 4\n17 16\n20 6", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12", "1 2 7\n20 13", "3 3 3\n13 1\n18 12\n19 2", "...
UNKNOWN
PYTHON3
CODEFORCES
13
c2fb46bcb0c07141a390386eb43d17e6
Success Rate
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
[ "def div(a, b):\r\n\treturn (a+b-1)//b\r\n\r\nfor t in range(int(input())):\r\n\tx,y,p,q = map(int,input().split())\r\n\tif q == 1:\r\n\t\tif p == 0 and x == 0 or p == 1 and x == y:\r\n\t\t\tprint(0)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\telse:\r\n\t\tz = max(max(div(x,p),div(y,q)),max(div(y-x,q-p),0))\r\n\t\tprint(z...
{"inputs": ["4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2", "5\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000...
UNKNOWN
PYTHON3
CODEFORCES
55
c305e3530a54f2ea0d43187252188974
Game of Stones
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: - The game starts with *n* piles of stones indexed from 1 to *n*. The *i*-th pile contains *s**i* stones.- The players make their moves alternatively. A...
[ "ans=0\r\nfor _ in range(int(input())):\r\n ans^=int((8*int(input())+1)**0.5-1)//2\r\nprint(['YES', 'NO'][ans>0])" ]
{"inputs": ["1\n5", "2\n1\n2", "3\n34\n44\n21", "6\n34\n44\n21\n55\n1\n36", "14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32", "10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59", "12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40", "118\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n2...
UNKNOWN
PYTHON3
CODEFORCES
1
c32aecaf273108e539a4710735fff11f
Gosha is hunting
Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Poke...
[ "import sys\r\nreadline=sys.stdin.readline\r\n\r\ndef Bisect_Float(ok,ng,is_ok,eps=1e-12,cnt=0):\r\n if cnt:\r\n for _ in range(cnt):\r\n mid=(ok+ng)/2\r\n if is_ok(mid):\r\n ok=mid\r\n else:\r\n ng=mid\r\n else:\r\n while abs(ok-ng)...
{"inputs": ["3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443", "8 4 1\n0.425 0.709 0.507 0.932 0.085 0.389 0.215 0.508\n0.471 0.825 0.240 0.981 0.184 0.241 0.810 0.711", "7 4 4\n0.642 0.036 0.552 0.936 0.866 0.905 0.40...
UNKNOWN
PYTHON3
CODEFORCES
1
c33a7c4403551ca5163e14847cc720c9
Bus of Characters
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
[ "n = int(input())\r\nw = list(map(int, input().split()))\r\nent = input()\r\nmp = {w[i]: i+1 for i in range(n)}\r\nsorted(mp)\r\nw.sort()\r\nptr = 0\r\nstk = []\r\nfor i in range(2 * n):\r\n if ent[i] == \"0\":\r\n print(mp[w[ptr]], end=\" \")\r\n stk.append(mp[w[ptr]])\r\n ptr += 1\r\n e...
{"inputs": ["2\n3 1\n0011", "6\n10 8 9 11 13 5\n010010011101", "1\n1\n01", "1\n1000000\n01", "2\n1 1000000\n0011", "2\n1000000000 1\n0101", "2\n1000000000 999999999\n0011", "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111"], "outputs": ["2 1 1 2 ", "6 6 2 3 3 1 4 4 1 2 5 5 ", "1 1 ", "1 1 ", "1 2 2 1 ", "2 2 1 1...
UNKNOWN
PYTHON3
CODEFORCES
68
c33ee1ebed2d67a1fc93b05bf3e8b65a
Eugeny and Play List
Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then son...
[ "n, m = map(int, input().split())\r\n\r\nsongs = []\r\nc = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n c += a * b\r\n songs.append(c)\r\n\r\nv = list(map(int, input().split()))\r\nsi = 0\r\nfor it in v:\r\n while songs[si] < it:\r\n si += 1\r\n print(si + 1)", "import bisect\r\n\r\nn,...
{"inputs": ["1 2\n2 8\n1 16", "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9", "3 3\n2 8\n5 1\n10 5\n13 16 62", "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85", "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177", "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265", "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 11...
UNKNOWN
PYTHON3
CODEFORCES
100
c34576ad4cc651a3744cc85ae9b0a608
Replace To Make Regular Bracket Sequence
You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;. The following d...
[ "s = input()\r\nop = '{[(<'\r\ncl = {'{':'}', '[':']', '(':')', '<':'>'}\r\n\r\ncnt = 0\r\nflag = False\r\nfor elem in s:\r\n\r\n if elem in op:\r\n cnt += 1\r\n else:\r\n cnt -= 1\r\n if cnt < 0:\r\n flag = True\r\n break\r\nif cnt != 0 or flag:\r\n print('Imposs...
{"inputs": ["[<}){}", "{()}[]", "]]", ">", "{}", "{}", "{]", "{]", "{]", "[]{[]({)([", "(([{>}{[{[)]]>>]", "((<>)[]<]><]", "[[([[(>]>)))[<)>", "({)[}<)](}", "(}{)[<][)(]}", ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([", "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>...
UNKNOWN
PYTHON3
CODEFORCES
73
c35efd66426b5bd961aa720f0ee29dcb
Guilty --- to the kitchen!
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of *n* ingredients that have to be mixed in prop...
[ "n, V = list(map(float, input().split(\" \")))\na = list(map(int, input().split(\" \")))\nb = list(map(float, input().split(\" \")))\nminB = min(b)\nif minB == 0:\n print(0)\nelse:\n x = b[0]/a[0]\n for i, j in enumerate(a):\n if x > b[i]/a[i]:\n x = b[i]/a[i]\n output = sum(a)*x\n ...
{"inputs": ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60", "2 100\n1 1\n50 50", "2 100\n1 2\n33 66", "3 10000\n1 1 1\n100 0 100", "7 5100\n21 93 52 80 5 46 20\n79 37 74 54 22 15 90", "10 2707\n80 91 41 99 99 48 81 25 80 17\n88 79 64 78 4 54 38 92 77 61", "19 8111\n44 75 80 69 90 64 58 8 93 50 44 39 7 25 14 5...
UNKNOWN
PYTHON3
CODEFORCES
43
c3b0f25282825914e3165f036647ca3b
Wrath
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
[ "inp=lambda:map(int,input().split())\r\nn=int(input())\r\n\r\nl=list(inp())\r\n\r\nm=[1000000]*(10**6+1)\r\n\r\n\r\nfor i in range(n-1,-1,-1):\r\n m[i]=min(m[i+1],i-l[i])\r\n\r\ncnt=0\r\nfor i in range(0,n):\r\n if(m[i+1]>i) :\r\n cnt+=1\r\n\r\nprint(cnt)\r\n\r\n\r\n\r\n\r\n", "import sys\r\ninput = ...
{"inputs": ["4\n0 1 0 10", "2\n0 0", "10\n1 1 3 0 0 0 2 1 0 3", "10\n0 0 2 0 0 3 3 2 2 0", "1\n0", "5\n0 0 0 1 0", "6\n3 1 1 0 3 3", "8\n0 0 0 1 0 0 1 2", "1\n1000000000", "2\n1 3", "2\n1000000000 1000000000", "11\n1 0 0 1 1 3 2 0 0 2 3", "1\n1"], "outputs": ["1", "2", "3", "2", "1", "4", "1", "5", "1", "1", "1", "4", ...
UNKNOWN
PYTHON3
CODEFORCES
206
c3caabd20656dfea798193d9f8828c62
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML ...
[ "import fileinput\r\n\r\ns = ''\r\nfor line in fileinput.input():\r\n s += line.strip()\r\n\r\n#print(s)\r\n\r\nif s[0] == '<':\r\n s = s[1:]\r\nif s[-1] == '>':\r\n s = s[:-1]\r\n#print(s)\r\na = s.split('><')\r\n#print(a)\r\nans = []\r\nb = []\r\nfor i in a:\r\n if i == 'table':\r\n b.append(0)...
{"inputs": ["<table><tr><td></td></tr></table>", "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></t...
UNKNOWN
PYTHON3
CODEFORCES
7
c3d790805eede963d52bb39905c572fe
Queries about less or equal elements
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second lin...
[ "n, m = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\nA.sort()\n\nresult = []\n\ndef bb(A, num):\n ini = 0\n final = len(A) - 1\n \n while ini <= final:\n mid = (ini + final) // 2\n if A[mid] <= num:\n ini = mid + 1\n ...
{"inputs": ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5", "1 1\n-1\n-2", "1 1\n-80890826\n686519510", "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -9296...
UNKNOWN
PYTHON3
CODEFORCES
241
c3f6f1b2d8283ce5173cfcc44bb75b45
Intersection
You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0. Write the program which finds the number of points in the intersection of two given sets. The first line of the input con...
[ "a1, b1, c1 = list(map(int, input().split()))\na2, b2, c2 = list(map(int, input().split()))\n\nif(b1 != 0 and b2 != 0):\n if(a1*b2 == a2*b1):\n if(c1*b2 == c2*b1):\n print(-1) \n else:\n print(0) \n\n else:\n print(1)\n\nelif(b1 == 0 and b2 == 0):\n if(a1 != 0):\n...
{"inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0", "0 0 0\n0 0 0", "1 1 1\n1 1 1", "8 3 -4\n-5 2 7", "-1 -1 0\n0 -1 -1", "-1 -1 0\n1 1 -1", "-1 -1 1\n0 -1 0", "0 0 0\n1 -1 -1", "0 0 1\n-1 1 -1", "0 1 -1\n-1 1 -1", "1 0 -1\n0 0 -1", "0 1 1\n1 0 0", "1 0 0\n0 0 1", "1 -1 -1\n1 -1 0", "1 0 0\n0 1 1", "1 -1 1\n-1 -1 1", "1 0 0\n...
UNKNOWN
PYTHON3
CODEFORCES
15
c3fb39355574a7e1da59bd733c53c45c
Parallelepiped
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. The first and the single line contains three space-separated integers — the areas of the parallelepiped's fa...
[ "import math\r\nz = []\r\nz[0:] = map(int, input().split())\r\nz.sort()\r\nlst1 = []\r\nlst2 = []\r\nlst3 = []\r\nlst = [1]\r\n\r\nfor i in range(1,z[1]):\r\n if i not in lst and z[0] % i == 0 and z[2] % i == 0: #and i not in lst:# and z[2] % i == 0:\r\n lst.append(i)\r\n #break\r\n if i not i...
{"inputs": ["1 1 1", "4 6 6", "20 10 50", "9 4 36", "324 9 36", "1333 93 129", "1022 584 112", "66 174 319", "912 276 1748", "65 156 60", "1 10000 10000", "1485 55 27", "152 108 4104", "1656 6900 1350", "12 14 42", "615 18 1230", "680 60 408", "644 966 6", "1 432 432", "2239 2239 1", "4106 8212 2", "10000 10000 10000",...
UNKNOWN
PYTHON3
CODEFORCES
622
c405d7dde8cef7bb4e1c964e697aa3e5
T-Shirt Hunt
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination r...
[ "l=input().split()\np,x,y=int(l[0])-26,int(l[1]),int(l[2])\ndef ch(n):\n\ti=(n//50)%475\n\tfor c in range(25):\n\t\ti=(i*96+42)%475\n\t\tif i==p:return 0\n\treturn 1\nz=y+(x-y)%50\nwhile ch(z):z+=50\nif z>x:\n\tn=(z-x)//50\n\tprint((n>>1)+(n&1))\nelse:\n\tprint('0')\n\n", "def checkWin(s,p):\r\n i=(s//50)%475\...
{"inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900", "264 19252 10888", "176 9670 9174", "42 11 6", "412 17647 15917", "91 4883 4302", "200 16031 15842", "186 18666 18329", "486 9748 9598", "180 4213 4207", "329 19989 1", "390 11676 2570", "173 7017 4512", "38 6404 5034", "...
UNKNOWN
PYTHON3
CODEFORCES
31
c40e9d6ff14b79d32f1975a0c3702047
Dima and Staircase
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i...
[ "I=lambda:map(int,input().split())\r\nn,=I()\r\nl=[*I()]\r\nm,=I()\r\nq=0\r\nr=\"\"\r\nfor i in range(m):\r\n w,h=I()\r\n q=max(q,l[w-1])\r\n r+=str(q)+\"\\n\"\r\n q+=h\r\nprint(r)", "from sys import stdin\r\n\r\n\r\ndef ip():\r\n return stdin.readline().split()\r\n\r\n\r\nif __name__ == \"__main__...
{"inputs": ["5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "3\n1 2 3\n2\n1 1\n3 1", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "8\n6 10 18 23 30 31 31 33\n1\n5 3", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2", "5\n4 7 10 12 12\n9\n3 9\n2 1\n3 5\n4 7\n1 1\n5 1\n1 7\n2 4\n4 10", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6", "3\n2 10 15\n1\...
UNKNOWN
PYTHON3
CODEFORCES
38
c428cb3795453c6365d8f87de077feb5
Mike and palindrome
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
[ "text=input()\r\nn=len(text)\r\nc=0\r\nfor i in range(n):\r\n if text[i]!=text[n-i-1]:\r\n c=c+1\r\nif (n%2==0):\r\n if(c==2):\r\n print(\"yes\")\r\n else:\r\n print(\"no\")\r\nelif(n%2==1):\r\n if (c==2 or c==0):\r\n print(\"yes\")\r\n else:\r\n print(\"no\")", "...
{"inputs": ["abccaa", "abbcca", "abcda", "kyw", "fccf", "mnlm", "gqrk", "glxlg", "czhfc", "broon", "rmggmr", "wvxxzw", "ukvciu", "vrnwnrv", "vlkjkav", "guayhmg", "lkvhhvkl", "ffdsslff", "galjjtyw", "uosgwgsou", "qjwmjmljq", "ustrvrodf", "a", "qjfyjjyfjq", "ysxibbixsq", "howfslfwmh", "ekhajrjahke", "ucnolsloncw", "jrzsf...
UNKNOWN
PYTHON3
CODEFORCES
163
c471ea63a38a1fc6ba0d6161cb75b220
Bertown Subway
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station...
[ "from sys import stdin\r\n\r\n\r\ndef main():\r\n\tn = int(stdin.readline())\r\n\tar = list(map(int, stdin.readline().split()))\r\n\tcheck = [False] * n\r\n\tans_list = []\r\n\tfor i in range(n):\r\n\t\tif not check[i]:\r\n\t\t\tcount = 0\r\n\t\t\tcurr = i\r\n\t\t\twhile not check[curr]:\r\n\t\t\t\tcheck[curr] = Tr...
{"inputs": ["3\n2 1 3", "5\n1 5 4 3 2", "1\n1", "2\n1 2", "2\n2 1", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 ...
UNKNOWN
PYTHON3
CODEFORCES
48
c481daf3fd61e80e4acb7dd5b3b0ad8b
EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native ...
[ "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n\r\n\r\nimport collections\r\n\r\n\r\ndef find(parents, i):\r\n if parents[i] == i:\r\n return i\r\n result = find(parents, parents[i])\r\n parents[i] = result\r\n return result\r\n\r\n\r\ndef union(parents, i, j):\r\n i, j = find(parents, ...
{"inputs": ["6 1\n2 0 4 0 6 0", "6 2\n2 3 0 5 6 0", "4 1\n0 0 0 0", "6 2\n0 0 1 0 4 5", "10 7\n10 8 6 5 0 0 0 4 3 9", "10 1\n8 7 0 2 0 10 0 0 3 5", "10 4\n0 1 4 2 7 0 10 0 5 8", "10 2\n0 7 0 10 8 0 4 2 3 0", "10 2\n10 0 9 0 0 4 2 6 8 0", "10 7\n7 9 2 10 0 0 0 3 5 1", "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"], "...
UNKNOWN
PYTHON3
CODEFORCES
7
c490d53ce60b1d95c8f1965c603a15cd
Challenge Pennants
Because of budget cuts one IT company established new non-financial reward system instead of bonuses. Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting...
[ "n=int(input())\r\nprint(((n+4)*(n+3)*(n+2)*(n+1)*n*(n+2)*(n+1)*n)//720)", "x = int(input()) + 1\r\nresult = (x**3 - x)**2 * (x*x + 5*x + 6) // 720\r\nprint(result)\r\n", "t = int(input())\r\nk = (t+2)*(t+1)*t\r\nm = k*(t+3)*(t+4)\r\nprint(m*k//720)", "from math import comb, factorial\r\nn = int(input())\r\ni...
{"inputs": ["2", "1", "3", "4", "5", "6", "7", "12", "28", "43", "139", "321", "100", "498", "500"], "outputs": ["24", "1", "210", "1120", "4410", "14112", "38808", "1589952", "817586560", "21766594410", "212332162372330", "163013183025830865", "15789964684000", "5392730685240975000", "5567867859752100000"]}
UNKNOWN
PYTHON3
CODEFORCES
7
c4925395433ef9f0418e15736bd8532f
Squares
Vasya has found a piece of paper with a coordinate system written on it. There are *n* distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to *n*. It turned out that points with coordinates (0,<=0) and (*a**i*,<=*a**i*) are the opposite corners of the *i*-th square. Vasya wa...
[ "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nif n-k>=0:\r\n \r\n print( str(l[n-k])+\" \"+str(l[n-k]))\r\nelse:\r\n print(-1)", "class Input:\r\n take_list_input = lambda : list(map(int, input().split()))\r\n take_string_input = lambda : input()\r\n take_strin...
{"inputs": ["4 3\n5 1 3 4", "3 1\n2 4 1", "4 50\n5 1 10 2", "3 4\n5 1 4", "1 1\n2", "1 2\n10", "10 5\n68 78 70 3 77 2 24 17 96 63", "5 2\n10 9 19 12 14", "2 2\n7 2", "2 1\n8 20", "2 40\n33 29", "5 10\n7 5 9 10 8", "9 8\n83 6 90 96 42 71 11 82 51", "40 30\n115644639 84968781 502201719 185562964 985439338 904909761 98746...
UNKNOWN
PYTHON3
CODEFORCES
4
c49fbe44ec18bf074af51a7b17df7ae3
Maze
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a...
[ "directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]\r\n\r\ndef main():\r\n height, width, walls_to_add = map(int, input().split())\r\n total_open_squares = height * width\r\n maze = []\r\n\r\n for _ in range(height):\r\n maze.append(list(input().strip()))\r\n\r\n total_open_squares -= sum(row.cou...
{"inputs": ["5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "3 3 2\n#.#\n...\n#.#", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "1 1 0\n.", "2 3 1\n..#\n#..", "2 3 1\n#..\n..#", "3 3 1\n...\n.#.\n..#", "3 3 1\n...\n.#.\n#..", "5 4 4\n#..#\n....\n.##.\n....\n#..#", "5 5 2\n.#..#\n..#.#\n#....\n##.#.\...
UNKNOWN
PYTHON3
CODEFORCES
97
c4a1a34f497ee40fd471d8de5b3c962b
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
[ "n, m = map(int, input().split())\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\np = [0] * m\nc = [i -1 for i in c]\ns = sum(k)\ncnt = k.count(0)\nl = 0\nr = 0\nwhile r < n and cnt < m:\n p[c[r]] += 1\n if p[c[r]] == k[c[r]]:\n cnt += 1\n r += 1\nif cnt != m:\n print(-...
{"inputs": ["8 3\n3 3 1 2 2 1 1 3\n3 1 1", "6 5\n1 2 4 2 4 3\n0 0 1 0 0", "1 1\n1\n1", "2 1\n1 1\n1", "2 1\n1 1\n2", "2 2\n1 2\n1 1", "2 2\n2 2\n1 1", "3 3\n3 3 2\n0 0 1", "4 4\n4 4 4 4\n0 1 1 1", "2 2\n1 1\n1 0", "3 3\n3 3 3\n0 0 1", "4 4\n2 4 4 3\n0 1 0 0", "2 2\n2 1\n0 1", "3 3\n3 1 1\n1 1 1", "4 4\n1 3 1 4\n1 0 0 1...
UNKNOWN
PYTHON3
CODEFORCES
7
c4ad62bddbc94c55cc70b08762937167
Bombs
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point w...
[ "#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nn, = readln()\nans = []\nfor x, y in sorted([readln() for _ in range(n)], key=lambda x: abs(x[0]) + abs(x[1])):\n if x > 0:\n ans.append('1 %d R' % x)\n if x < 0:\n ans.append('1 %d L' % -x)\n if y > 0:\n a...
{"inputs": ["2\n1 1\n-1 -1", "3\n5 0\n0 5\n1 0", "1\n-277226476 314722425", "2\n-404192496 -968658337\n556071553 -256244640", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2"], "outputs": ["12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\...
UNKNOWN
PYTHON3
CODEFORCES
11
c4b0d56e3f40a886b55753344382562d
Minimization
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)). The second line contains *n* i...
[ "def solve(n, k, As):\r\n As.sort()\r\n m, r = divmod(n, k)\r\n dp = [0] * (r + 1)\r\n for i in range(1, k):\r\n im = i * m\r\n new_dp = [0] * (r + 1)\r\n new_dp[0] = dp[0] + As[im] - As[im - 1]\r\n for h in range(1, min(i, r) + 1):\r\n new_dp[h] = max(dp[h], dp[h ...
{"inputs": ["3 2\n1 2 4", "5 2\n3 -5 3 -5 3", "6 3\n4 3 4 3 2 5", "2 1\n1 100", "4 3\n1 2 4 8", "5 2\n1 2 8 8 16", "10 3\n-999999914 -999999976 -999999966 -999999952 29 54 -999999963 -999999959 -999999974 48", "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -999...
UNKNOWN
PYTHON3
CODEFORCES
2
c4dd3e1e06a63ef2153e3968b846c4ce
Really Big Numbers
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
[ "def main():\r\n def sumofdigit(n):\r\n temp=0\r\n while(n>0):\r\n temp+=n%10\r\n n=n//10\r\n return temp\r\n\r\n def F(x):\r\n return x-sumofdigit(x)\r\n\r\n def findout(s):\r\n test=s-s%10+10\r\n while(1):\r\n if F(test)>=s:\r\n ...
{"inputs": ["12 1", "25 20", "10 9", "300 1000", "500 1000", "1000 2000", "10000 1000", "1000000000000000000 1000000000000000000", "1000000000000000000 100000000000000000", "1000000000000000000 10000000000000000", "1000000000000000000 1000000000000000", "1000000000000000000 100000000000000", "1000000000000000000 200000...
UNKNOWN
PYTHON3
CODEFORCES
89
c4ed979e1e7dc2e04476df656d461770
Square Table
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each ...
[ "import math\r\nn,m = input().split(' ')\r\nn,m = int(n),int(m)\r\nfix = [[1],[3,4],[1,2,2],[1,1,3,5],[1,1,1,2,3]]\r\n\r\na = n\r\nparts = list()\r\nb = a\r\nwhile b > 0:\r\n parts.append(math.floor(b**0.5))\r\n b-=math.floor(b**0.5)**2\r\nlcm = math.lcm(*parts)\r\na_out = list()\r\nfor i in range(len(parts))...
{"inputs": ["1 1", "1 2", "4 1", "1 4", "2 1", "2 4", "48 2", "3 75", "33 1", "4 23", "58 2", "2 11", "7 14", "48 24", "77 93", "77 20", "30 31", "100 100"], "outputs": ["1 ", "3 4 ", "1 \n1 \n1 \n1 ", "1 1 1 1 ", "3 \n4 ", "3 3 3 3 \n4 4 4 4 ", "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3...
UNKNOWN
PYTHON3
CODEFORCES
3
c4f24bad678c0dc44f16444d1931b0f5
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
[ "n = int(input())\r\nnum = map(int, input().rstrip().split())\r\nif 1 in num:\r\n\tprint(-1)\r\nelse:\r\n\tprint(1)", "n, a = int(input()), (int(i) for i in input().split())\nres = -1 if 1 in a else 1\nprint(res)\n", "'''input\n5\n1 2 3 4 5\n'''\nn = int(input())\nl = list(map(int, input().split()))\nprint(-1 i...
{"inputs": ["5\n1 2 3 4 5", "1\n2", "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97...
UNKNOWN
PYTHON3
CODEFORCES
304
c50b1b965f540f3178cb912f00fd25cf
Spyke Talks
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe...
[ "def cocktail_sort(a):\r\n n = len(a)\r\n swapped = True\r\n start = 0\r\n end = n-1\r\n while (swapped == True):\r\n \r\n # reset the swapped flag on entering the loop,\r\n # because it might be true from a previous\r\n # iteration.\r\n swapped = False\r\n \r\n # l...
{"inputs": ["6\n0 1 7 1 7 10", "3\n1 1 1", "1\n0", "5\n2 2 1 1 3", "1\n1", "10\n4 21 3 21 21 1 1 2 2 3", "2\n1 2", "5\n0 0 0 0 0", "6\n6 6 0 8 0 0", "10\n0 0 0 0 0 1 0 1 0 1", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
61
c544dbf38e7f9a8e6286d2e4f208c1e3
Puzzles
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
[ "n, m = map(int, input().split())\r\npuzzles = sorted(list(map(int, input().split())))\r\nmin_diff = float('inf')\r\ndiff = 0\r\nfor a, _ in enumerate(range(m - n + 1 )):\r\n diff = puzzles[n-1] - puzzles[a]\r\n min_diff = min(min_diff, diff)\r\n # print(diff)\r\n\r\n n+=1\r\nmin_diff = min(min_diff, d...
{"inputs": ["4 6\n10 12 10 7 5 22", "2 2\n4 4", "2 10\n4 5 6 7 8 9 10 11 12 12", "4 5\n818 136 713 59 946", "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "4 25\n226 790 628 52...
UNKNOWN
PYTHON3
CODEFORCES
385
c58eac4bb58780bf424ac77f4fb18275
Physical Education and Buns
The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression. To achieve the goal, the gym teacher ordered a lot of magical buns from the dining ...
[ "q = 10001\r\nn, a = int(input()), list(map(int, input().split()))\r\na.sort()\r\nfor i in range(40000 // (n - 1) + 1):\r\n b = [a[j] - j * i for j in range(n)]\r\n u, v = max(b), min(b)\r\n p = (u - v + 1) // 2\r\n if p < q: q, s, d = p, v + p, i\r\nprint(q)\r\nprint(s, d)\r\n\n", "q=10001\r\nn,a=int...
{"inputs": ["5\n-3 -4 -2 -3 3", "5\n2 -3 -1 -4 3", "6\n94 65 -33 -43 60 -24", "3\n-10000 10000 -10000", "2\n0 0", "7\n-1 -2 -4 -10 6 6 5", "10\n-10 3 -16 -15 14 -16 13 -6 -8 18", "50\n-67 -84 -89 80 40 42 -38 30 74 -12 -66 27 1 11 -45 -44 2 -70 -59 -70 -59 -59 62 100 -5 1 91 79 47 -64 -51 -88 -5 37 82 87 79 46 76 47 60...
UNKNOWN
PYTHON3
CODEFORCES
2
c597f61ed8d5dea2daccb09176049488
Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
[ "from operator import itemgetter\r\nn=int(input().strip())\r\nans=0\r\nl=[]\r\nfor i in range(n):\r\n\tl.append([int(x) for x in input().strip().split()])\r\n \r\nl.sort(key=itemgetter(1))\r\nx=l[0][1]\r\ny=1\r\nfor i in range(1,len(l)):\r\n\tif l[i][1]!=x:\r\n\t\tans=ans+(y*(y-1))//2\r\n\t\tx=l[i][1]\r\n\t\ty=1\r\...
{"inputs": ["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "1\n-5 -90", "2\n315 845\n-669 -762", "3\n8911 7861\n-6888 7861\n8911 7861", "2\n-1 1000000000\n0 -1", "2\n1000000000 0\n-7 1", "2\n1 4\n2 1", "2\n1 0\n0 2333333", "2\n2 1\...
UNKNOWN
PYTHON3
CODEFORCES
194