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
d6a3ee2245008b12cf3816a9aeb24318
Treasure
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that th...
[ "s = input()\r\nn = len(s)\r\np, curr = n - 1, 0\r\nwhile s[p] != '#':\r\n\tif s[p] == ')': curr += 1\r\n\telse: curr -= 1\r\n\tp -= 1\r\n\tif curr < 0:\r\n\t\tprint(-1)\r\n\t\texit()\r\ncnt_hash, curr = s.count('#'), 0\r\nfor i in range(p):\r\n\tif s[i] == '(': curr += 1\r\n\telse: curr -= 1\r\n\tif curr < 0:\r\n\...
{"inputs": ["(((#)((#)", "()((#((#(#()", "#", "(#)", "(((((#(#(#(#()", "#))))", "((#(()#(##", "##((((((()", "(((((((((((((((((((###################", "((#)(", "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##", ")((##((###", "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(...
UNKNOWN
PYTHON3
CODEFORCES
41
d6b80df56f0740882baccaea55763e55
Binary Blocks
You are given an image, that can be represented with a 2-d *n* by *m* grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integer *k*<=&gt;<=1 and split the image into *k* by *k* blocks. If *n* and ...
[ "#!/usr/bin/env python\n# coding:utf-8\n# Copyright (C) dirlt\n\nfrom sys import stdin\n\n\ndef run(n, m, pixels):\n ans = 1 << 30\n\n acc = [[0] * (m + 1) for _ in range(n + 1)]\n for i in range(n):\n for j in range(m):\n acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])\n for...
{"inputs": ["3 5\n00100\n10110\n11001"], "outputs": ["5"]}
UNKNOWN
PYTHON3
CODEFORCES
4
d6fd979c02770bacad2724d75d957157
none
Dreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both *a* and *b*. Let *S* be a set of exactly four distinct integers greater than 0. Define *S* to be of rank *k* if and only if for all pairs of distinct elements *s**i*, *s**j* from *S*, . Given *k* and *n*, Dr...
[ "n,k =[int(i) for i in input().split(' ')]\nprint(k*(6*n-1))\nfor i in range(n):\n\tprint(k*(6*i+1), k*(6*i+2), k*(6*i+3), k*(6*i+5))\n\t\n", "n,k=[int(e) for e in input().split()]\r\nprint(k*(6*(n-1)+5))\r\nfor i in range(n):\r\n print(k*(6*i+1),k*(6*i+2),k*(6*i+3),k*(6*i+5))", "a, b = map(int, input().spli...
{"inputs": ["1 1", "2 2", "7 7", "13 7", "15 27", "19 21", "113 97", "10000 100", "10000 1", "1 100", "9252 39", "8096 59", "4237 87", "3081 11", "9221 39", "770 59", "5422 87", "1563 15", "407 39", "6518 18", "1171 46", "7311 70", "6155 94", "7704 18", "3844 46", "1 10"], "outputs": ["5\n1 3 4 5", "22\n2 6 8 10\n14 18...
UNKNOWN
PYTHON3
CODEFORCES
12
d70abc6e8f9f2a1e2b0c2d7894d9ea5d
Ostap and Grasshopper
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr...
[ "n,k = map(int,input().split())\r\ncell = list(map(str,input().strip()))\r\na = cell.index(\"G\")\r\nb = cell.index(\"T\")\r\nif(a>b):\r\n if((a-b)%k != 0):\r\n print(\"NO\")\r\n else:\r\n for i in range(1,(a-b)//k + 1):\r\n if(cell[b + k*i] == \"#\"):\r\n print(\"NO\")...
{"inputs": ["5 2\n#G#T#", "6 1\nT....G", "7 3\nT..#..G", "6 2\n..GT..", "2 1\nGT", "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####", "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####", "2 1\nTG", "99 ...
UNKNOWN
PYTHON3
CODEFORCES
254
d72a89e9db8adcfc03dadf9a643d3dcd
Playing with Superglue
Two players play a game. The game is played on a rectangular board with *n*<=×<=*m* squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue. We'll des...
[ "n,m,x1,y1,x2,y2 = map(int, input().split())\r\nn = abs(x1 - x2)\r\nm = abs(y1 - y2)\r\nif n > 4 or m > 4:\r\n print(\"Second\")\r\nelif n <= 3 and m <= 3:\r\n print(\"First\")\r\nelif min(n, m) <= 2:\r\n print(\"First\")\r\nelse:\r\n print(\"Second\")", "n,m,X,Y,x,y=map(int,input().split())\r\na=[abs...
{"inputs": ["1 6 1 2 1 6", "6 5 4 3 2 1", "10 10 1 1 10 10", "1 2 1 1 1 2", "4 4 1 4 4 1", "25 32 17 18 20 19", "30 1 10 1 20 1", "28 17 20 10 27 2", "5 5 1 1 5 5", "5 4 1 4 5 1", "95 28 50 12 50 13", "7 41 3 5 3 6", "45 62 28 48 28 50", "57 17 12 7 12 10", "73 88 30 58 30 62", "33 13 12 1 12 6", "49 34 38 19 38 25", "...
UNKNOWN
PYTHON3
CODEFORCES
2
d73ca18f12aeb17663480d60129a16fa
Sagheer, the Hausmeister
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sid...
[ "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\nn,m=map(int,input().strip().split())\r\na=[]\r\nL=[]\r\nR=[]\r\nt={}\r\nfor i in range(n):\r\n b=input()\r\n a.append(b)\r\n L.append(9000000)\r\n R.append(0)\r\n t[i]=0\r\na.reverse()\r\nfor i in range(n):\r\n for j in range(m+2):\r\n i...
{"inputs": ["2 2\n0010\n0100", "3 4\n001000\n000010\n000010", "4 3\n01110\n01110\n01110\n01110", "3 2\n0000\n0100\n0100", "1 89\n0000000000000000000000000000000100000000000000010000000000010000000000000000000000000000000", "2 73\n000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000...
UNKNOWN
PYTHON3
CODEFORCES
28
d766f3f2527be1fa3b8d7c99ab891efc
Eugeny and Array
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a...
[ "I = lambda: map(int, input().split())\r\n\r\n_, m = I()\r\nA = list(I())\r\nx, y = 2*A.count(-1), 2*A.count(1)\r\nB = []\r\n\r\nfor _ in range(m):\r\n L, R = I()\r\n k = R-L+1\r\n B.append(1 - (k%2 or x<k or y<k))\r\n\r\nprint(*B)", "from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\n...
{"inputs": ["2 3\n1 -1\n1 1\n1 2\n2 2", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "3 3\n1 1 1\n2 2\n1 1\n1 1", "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "...
UNKNOWN
PYTHON3
CODEFORCES
60
d7919219ff4ad6a38979999432fab8f8
Two Paths
As you know, Bob's brother lives in Flatland. In Flatland there are *n* cities, connected by *n*<=-<=1 two-way roads. The cities are numbered from 1 to *n*. You can get from one city to another moving along the roads. The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland....
[ "n = int(input())\np = [[] for i in range(n + 1)]\nfor j in range(n - 1):\n a, b = map(int, input().split())\n p[a].append(b)\n p[b].append(a)\ndef g(b, c):\n x = y = d = 0\n for a in p[b]:\n if a != c:\n s, z = g(a, b)\n z, y, x = sorted([x, y, z])\n d = max(d...
{"inputs": ["4\n1 2\n2 3\n3 4", "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7", "6\n1 2\n2 3\n2 4\n5 4\n6 4", "2\n2 1", "3\n3 1\n1 2", "3\n1 3\n2 1", "4\n4 2\n2 3\n2 1", "4\n2 3\n1 3\n2 4", "4\n3 2\n3 4\n1 4", "5\n1 5\n5 2\n4 2\n3 1", "5\n2 4\n2 5\n1 5\n2 3", "5\n1 2\n5 1\n3 2\n3 4", "5\n5 3\n3 1\n4 1\n4 2", "6\n1 2\n2 5\n4 5\n4 6\...
UNKNOWN
PYTHON3
CODEFORCES
16
d794d52aeb02422c0b71909eeaae5488
Email address
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address ([[email protected]](/cdn-cgi/l/email-protection)). It is known that a proper email add...
[ "s=input()\nt=s[0]+s[1:].replace('at','@',1)\ns=t[0]+t[1:-1].replace('dot','.')+t[-1]\nprint(s)\n\n\t\t \t \t\t\t \t \t\t \t \t\t \t", "str=input().strip()\nstr=str[0]+str[1:].replace(\"at\",\"@\",1)\nstr=str[0]+str[1:-1].replace(\"dot\",\".\")+str[-1]\nprint(str)\n \t \t \t\t\t\t \t \t\t \t \t\...
{"inputs": ["vasyaatgmaildotcom", "dotdotdotatdotdotat", "aatt", "zdotdotatdotz", "dotdotdotdotatdotatatatdotdotdot", "taatta", "doatdt", "catdotdotdotatatdotdotdotnatjdotatdotdotdoteatatoatatatoatatatdotdotatdotdotwxrdotatfatgfdotuatata", "hmatcxatxatdotatlyucjatdothatdotcatatatdotqatatdotdotdotdotatjddotdotdotqdotdot...
UNKNOWN
PYTHON3
CODEFORCES
42
d79706d0befbed03f9a2c3c0383c9b22
Petya and Coloring
Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size *n*<=×<=*m* (*n* rows, *m* columns) in *k* colors. Besides, the coloring should have the following property: for any vertical line that passes along the grid lines and divides the board in two non-empty part...
[ "M, Mod = 10**3 + 3, 10**9 + 7\nn, m, k = [int(x) for x in input().split()]\nif m == 0:\n print(0)\nelif m == 1:\n print(pow(k, n, Mod))\nelse:\n C = [[0 for j in range(M)] for i in range(M)]\n for i in range(n + 1):\n C[i][0] = 1\n for j in range(1, i + 1):\n C[i][j] = (C[i - 1...
{"inputs": ["2 2 1", "2 2 2", "3 2 2", "7 8 15", "5 3 1", "5 100 1", "5 20 25", "6 6 8", "1 1 1000000", "3 3 2", "1000 1000 1000000", "1000 2 1000000", "1000 1 992929", "997 752 10001", "994 2 999999", "1 1000 298298", "2 1000 100202", "3 997 999997", "777 777 777777", "105 3 2", "105 3 3", "126 125 440715", "755 51 70...
UNKNOWN
PYTHON3
CODEFORCES
1
d7bf7d8f27e219e6e217db033c1b8e5d
Touchy-Feely Palindromes
The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output "Yes" or "No". The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. Output "Yes" or "No". Sample Input 373 121 436 Sample Output Yes No Ye...
[ "import sys\r\ninput = lambda: sys.stdin.readline().strip()\r\ns2 = str(input())\r\nif \"1\" in s2 or \"2\" in s2:\r\n print(\"No\")\r\nelse:\r\n an = \"\"\r\n s = list(s2)\r\n for i in range(len(s)):\r\n if s2[i] == \"4\":\r\n s[i] = \"6\"\r\n elif s2[i] == \"5\":\r\n ...
{"inputs": ["373", "121", "436", "7", "8", "4357087936", "806975480", "3333333333", "90785", "7467467", "64", "584609", "69154", "363567", "557654", "772961", "788958", "992045", "116325", "320432", "314729", "531816", "673902416", "880089713", "004176110"], "outputs": ["Yes", "No", "Yes", "Yes", "No", "Yes", "Yes", "Y...
UNKNOWN
PYTHON3
CODEFORCES
11
d7c0e156ffc26e831fc39e4852202444
HQ
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ... The only line of the input is a string between 1 and 106 characters long. Output "Yes" or "No". Sample Input HHHH HQHQH HHQHHQH HHQQHHQQHH Sample Output Yes No No Yes
[ "a = input()\r\nb = []\r\nh = ''\r\nc = 0\r\nfor i in a:\r\n\tif i == 'Q':\r\n\t\tc += 1\r\nif c == 0:\r\n\tprint('Yes')\r\n\texit(0)\r\nr = -1\r\nfor i in range(1001):\r\n\tif i*i == c:\r\n\t\tr = i\r\n\t\tbreak\r\nif r == -1:\r\n\tprint('No')\r\n\texit(0)\r\nh = [a.split('Q')[0], a.split('Q')[-1]]\r\nc = [len(h[0...
{"inputs": ["HHHH", "HQHQH", "HHQHHQH", "HHQQHHQQHH", "Q", "HHHHHHHHHHQHHH", "HHQHQQQHHH", "QQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQHQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQQQQQQQHQQQQ", "QHQHHQQQQQQQQQQQHQQHQHQQQQQQHQHQQQQQQQQQQQHQQQQQQQHQQHQQHQQQQQQQQQQQQQQQQQQQQHHQQQQQQQQQQHQQQQHHQHQQHQQQQQHQQQQQQ...
UNKNOWN
PYTHON3
CODEFORCES
1
d7c14ba7d0d268bccc5cdb4f6d715a9e
George and Sleep
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*. Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ...
[ "# Description of the problem can be found at http://codeforces.com/problemset/problem/387/A\r\n\r\nl_s = list(map(int, input().split(\":\")))\r\nl_t = list(map(int, input().split(\":\")))\r\n\r\nif l_t[1] > l_s[1]:\r\n l_s[0] -= 1\r\n \r\nprint(\"%02d:%02d\" % ((l_s[0] - l_t[0]) % 24, (l_s[1] - l_t[1]) % 60)...
{"inputs": ["05:50\n05:44", "00:00\n01:00", "00:01\n00:00", "23:59\n23:59", "23:44\n23:55", "00:00\n13:12", "12:00\n23:59", "12:44\n12:44", "05:55\n07:12", "07:12\n05:55", "22:22\n22:22", "22:22\n22:23", "23:24\n23:23", "00:00\n00:00", "23:30\n00:00", "01:00\n00:00", "05:44\n06:00", "00:00\n23:59", "21:00\n01:00", "21:...
UNKNOWN
PYTHON3
CODEFORCES
174
d7c490b20064d171af4f83b4f37404d4
Is your horseshoe on the other hoof?
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
[ "shoes = list(input().split())\r\nshoes = list(map(int, shoes))\r\ncolours = []\r\ncount = 0\r\n\r\nfor i in range(len(shoes)):\r\n if shoes[i] in colours:\r\n count += 1\r\n else:\r\n colours.append(shoes[i])\r\nprint(count)\r\n", "print(4 - len(set(map(int , input().split()))))\r\n", "n = ...
{"inputs": ["1 7 3 3", "7 7 7 7", "81170865 673572653 756938629 995577259", "3491663 217797045 522540872 715355328", "251590420 586975278 916631563 586975278", "259504825 377489979 588153796 377489979", "652588203 931100304 931100304 652588203", "391958720 651507265 391958720 651507265", "90793237 90793237 90793237 907...
UNKNOWN
PYTHON3
CODEFORCES
957
d7c8cf60a201788ba8180140d2bc22a2
Cells Not Under Attack
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ...
[ "import sys\r\ninput = lambda:sys.stdin.readline()\r\n\r\nint_arr = lambda: list(map(int,input().split()))\r\nstr_arr = lambda: list(map(str,input().split()))\r\nget_str = lambda: map(str,input().split())\r\nget_int = lambda: map(int,input().split())\r\nget_flo = lambda: map(float,input().split())\r\n\r\nmod = 1000...
{"inputs": ["3 3\n1 1\n3 1\n2 2", "5 2\n1 5\n5 1", "100000 1\n300 400", "10 4\n2 8\n1 8\n9 8\n6 9", "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14", "70 31\n22 39\n33 ...
UNKNOWN
PYTHON3
CODEFORCES
143
d7e7fbc84916c4ba69a3a51b3f1490a9
none
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string *s* of length *n* comes out from Tavas' mouth instead. Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on *s*. Malekas has a favorite string *p*. He determined all positions ...
[ "# -*- coding: utf-8 -*-\n\n\n\n\n\ndef solve():\n\n n, m = map(int, input().split())\n\n p = input()\n\n if m == 0:\n\n return powmod(n)\n\n delta = len(p) - 1\n\n ys = map(int, input().split())\n\n tail = 0\n\n free_chars = 0\n\n for y in ys:\n\n if y > tail:\n\n f...
{"inputs": ["6 2\nioi\n1 3", "5 2\nioi\n1 2", "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacbabcaccccccaacacabbbbbacabbaaacbcbbaccaccabbbbaabbacacbabccaabcabbbcacaaccbabbcaaaaaabccbbcabcacbcbcabcbcbbaabacaaccccabacaaaccacaaabbacacabbcccacbaabcacacbbaaaccaccbaccccccbccaabcacaacabaccababacabcccbcbbacbabacbcb...
UNKNOWN
PYTHON3
CODEFORCES
1
d7edd56a5eee20eab6b6d09fdcfa9b83
Partial Sums
You've got an array *a*, consisting of *n* integers. The array elements are indexed from 1 to *n*. Let's determine a two step operation like that: 1. First we build by the array *a* an array *s* of partial sums, consisting of *n* elements. Element number *i* (1<=≤<=*i*<=≤<=*n*) of array *s* equals . The operation *x*...
[ "n, k = map(int, input().split())\nnum = list(map(int, input().split()))\nMOD = 10 ** 9 + 7\n\ncf = [1]\nfor i in range(1, 2020):\n cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD)\n\nans = [0 for i in range(n)]\nfor i in range(n):\n for j in range(i + 1):\n ans[i] = (ans[i] + cf[i - j] *...
{"inputs": ["3 1\n1 2 3", "5 0\n3 14 15 92 6", "1 1\n3", "1 0\n0", "1 0\n123", "1 1\n0", "4 1\n3 20 3 4", "5 20\n11 5 6 8 11", "17 239\n663 360 509 307 311 501 523 370 302 601 541 42 328 200 196 110 573", "13 666\n84 89 29 103 128 233 190 122 117 208 119 97 200", "42 42\n42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 ...
UNKNOWN
PYTHON3
CODEFORCES
6
d82160a9327225936bababa5b49ea27a
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He ha...
[ "# LUOGU_RID: 116285050\nn=int(input())\r\nd={}\r\nc=[]\r\nfor _ in range(n):\r\n a,b=input().split()\r\n b=int(b)\r\n if a not in c:\r\n c.append(a)\r\n if a not in d:\r\n d[a]=b\r\n else:\r\n if d[a]<b:\r\n d[a]=b\r\nprint(len(d))\r\nm=len(c)\r\nx=[0]*m\r\nfor i in r...
{"inputs": ["5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "3\nvasya 200\nkolya 1000\nvasya 1000", "1\nvasya 1000", "5\nvasya 1000\nvasya 100\nkolya 200\npetya 300\noleg 400", "10\na 1\nb 2\nc 3\nd 4\ne 5\nf 6\ng 7\nh 8\ni 9\nj 10", "10\nj 10\ni 9\nh 8\ng 7\nf 6\ne 5\nd 4\nc 3\nb 2\na 1", "1\ntest 0"], "out...
UNKNOWN
PYTHON3
CODEFORCES
10
d828a1ebc83918c509c284ac5175b86f
Infinity Gauntlet
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors...
[ "dict1={\"purple\":\"Power\", \"green\":\"Time\", \"blue\":\"Space\", \"orange\":\"Soul\", \"red\":\"Reality\", \"yellow\":\"Mind\"}\nn=int(input())\nn_list=[]\nprint(6-n)\nfor i in range(n):\n g=input()\n n_list.append(g)\nfor k,v in dict1.items():\n if k not in n_list:\n print(v)\n \t \t\t\t\t\t\t \t\t...
{"inputs": ["4\nred\npurple\nyellow\norange", "0", "6\npurple\nblue\nyellow\nred\ngreen\norange", "1\npurple", "3\nblue\norange\npurple", "2\nyellow\nred", "1\ngreen", "2\npurple\ngreen", "1\nblue", "2\npurple\nblue", "2\ngreen\nblue", "3\npurple\ngreen\nblue", "1\norange", "2\npurple\norange", "2\norange\ngreen", "3\n...
UNKNOWN
PYTHON3
CODEFORCES
452
d84f506511837749a50dc95afd9a9b7e
Watering Flowers
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values *r*1(*r*1<=≥<=0) and *r*2(*r*2<=≥<=0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such *r*1 and *r*2 that all the flowers are watered, that is, fo...
[ "import sys\r\ninput=sys.stdin.readline\r\nn,x1,y1,x2,y2=map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n x,y=map(int,input().split())\r\n l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2])\r\nl.sort(reverse=True)\r\ns=10**18\r\nq=0\r\nfor u,v in l:\r\n s=min(s,u+q)\r\n q=max(q,v)\r\nprint(min(s,q))"...
{"inputs": ["2 -1 0 5 3\n0 2\n5 2", "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "5 -6 -4 0 10\n-7 6\n-9 7\n-5 -1\n-2 1\n-8 10", "10 -68 10 87 22\n30 89\n82 -97\n-52 25\n76 -22\n-20 95\n21 25\n2 -3\n45 -7\n-98 -56\n-15 16", "1 -10000000 -10000000 -10000000 -9999999\n10000000 10000000"], "outputs": ["6", "33", "100", "22034", "799...
UNKNOWN
PYTHON3
CODEFORCES
1
d85233139efbd43e85b826d96e5960b8
Tram
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
[ "total_stop = int(input())\r\nmax = 0\r\ncurrent = 0\r\nfor i in range(total_stop):\r\n a,b = map(int,input().split())\r\n if i == 0:\r\n max = b\r\n current = b\r\n else:\r\n current = (current - a) + b\r\n if current > max:\r\n max = current\r\nprint(max)\r\n", "n...
{"inputs": ["4\n0 3\n2 5\n4 2\n4 0", "5\n0 4\n4 6\n6 5\n5 4\n4 0", "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "3\n0 1\n1 1\n1 0", "4\n0 1\n0 1\n1 0\n1 0", "3\n0 0\n0 0\n0 0", "3\n0 1000\n1000 1000\n1000 0", "5\n0 73\n73 189\n189 766\n766 0\n0 0", "5\n0 0\n0 0\n0 0\n0 1\n1 0", "5\n0 917\n917 923\n904 992\...
UNKNOWN
PYTHON3
CODEFORCES
1,051
d868b148d0994ff39d9a316418f8fd80
Numbers
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all c...
[ "N = int(input())\r\ns = 0\r\n\r\ndef gcd(a, b):\r\n while(b):\r\n a, b = b, a%b\r\n return a\r\n\r\nfor i in range(2, N):\r\n n = N\r\n while(n>0):\r\n s += n%i\r\n n = n//i\r\n\r\nt = gcd(s, N-2)\r\nprint(str(s//t)+\"/\"+str((N-2)//t))", "import math\r\ndef numberToBase(n, b):\r...
{"inputs": ["5", "3", "1000", "927", "260", "131", "386", "277", "766", "28", "406", "757", "6", "239", "322", "98", "208", "786", "879", "702", "948", "537", "984", "934", "726", "127", "504", "125", "604", "115", "27", "687", "880", "173", "264", "785", "399", "514", "381", "592", "417", "588", "852", "959", "841", "...
UNKNOWN
PYTHON3
CODEFORCES
200
d87d73991024db39a19d5ff2ebaac5eb
Word
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
[ "s=input()\r\n\r\nascii_lower=0\r\nascii_upper=0\r\nstr=''\r\nfor ele in s:\r\n if ord(ele) <= 90:\r\n ascii_upper+=1\r\n elif ord(ele) >= 97:\r\n ascii_lower+=1\r\n\r\nif ascii_lower>=ascii_upper:\r\n print(s.lower())\r\nelse:\r\n print(s.upper())\r\n\r\n", "stroka = input()\r\ncounter1...
{"inputs": ["HoUse", "ViP", "maTRIx", "BNHWpnpawg", "VTYGP", "CHNenu", "ERPZGrodyu", "KSXBXWpebh", "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "ISAGFJFARYFB...
UNKNOWN
PYTHON3
CODEFORCES
5,171
d87fa0907cbb094c1645c41452b5fceb
Game with Points
You are playing the following game. There are *n* points on a plane. They are the vertices of a regular *n*-polygon. Points are labeled with integer numbers from 1 to *n*. Each pair of distinct points is connected by a diagonal, which is colored in one of 26 colors. Points are denoted by lowercase English letters. Ther...
[ "from collections import deque\r\n\r\n__author__ = 'asmn'\r\n\r\nn = int(input())\r\nend = tuple(sorted(map(lambda x: int(x) - 1, input().split())))\r\nst = (0, 1, 2)\r\nmat = [input() for i in range(n)]\r\nv = set([st])\r\npath = {}\r\ndist = {st: 0}\r\nqueue = deque([st])\r\n\r\nwhile end not in v and len(queue) ...
{"inputs": ["4\n2 3 4\n*aba\na*ab\nba*b\nabb*", "4\n2 3 4\n*abc\na*ab\nba*b\ncbb*", "3\n1 2 3\n*aa\na*a\naa*", "10\n9 8 6\n*abbbababb\na*babbaaaa\nbb*bbaabab\nbab*bbbaab\nbbbb*baaab\nababb*baaa\nbaabab*bba\naabaaab*ab\nbaaaaaba*a\nbabbbaaba*", "10\n3 9 5\n*aabbbaaaa\na*abbaaaaa\naa*baaaabb\nbbb*bbbaba\nbbab*babaa\nbaab...
UNKNOWN
PYTHON3
CODEFORCES
1
d8a91763417050f3c37bf81e2019ac08
Mr. Kitayuta, the Treasure Hunter
The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are *n* gems in the Shuseki Islands in total, and the *i*-th gem is located on island...
[ "import bisect\r\nimport collections\r\nimport math\r\nimport os\r\nimport sys\r\n\r\n# input = sys.stdin.buffer.readline\r\n\r\n# t = int(input())\r\n# n, m = map(int, input().split())\r\n# A = list(map(int, input().split()))\r\n# grid = [list(map(int, input().split())) for _ in range(n)]\r\n\r\nn, d = map(int, in...
{"inputs": ["4 10\n10\n21\n27\n27", "8 8\n9\n19\n28\n36\n45\n55\n66\n78", "13 7\n8\n8\n9\n16\n17\n17\n18\n21\n23\n24\n24\n26\n30", "8 4\n9\n15\n15\n16\n22\n25\n25\n28", "1 30000\n30000", "1 12345\n23456", "1 1\n30000", "5 4\n4\n5\n9\n21\n25", "8 7\n8\n15\n18\n19\n23\n24\n25\n27", "11 15\n15\n18\n19\n19\n21\n23\n24\n26\...
UNKNOWN
PYTHON3
CODEFORCES
6
d8ae5fce78d6970e097ff460a8ea8ae4
Fly
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$. Flight from $x$ to $y$ consists ...
[ "n = int(input())\r\nm = int(input())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nif 1 in a or 1 in b:\r\n\tprint(-1)\r\nelse:\r\n\tt = m/(b[0]-1)\r\n\tfor i in range(n-1, 0, -1):\r\n\t\tt += (t+m)/(a[i]-1)\r\n\t\tt += (t+m)/(b[i]-1)\r\n\tt += (t+m)/(a[0]-1)\r\n\tprint(t)", "f...
{"inputs": ["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3", "3\n3\n1 2 1\n2 2 2", "4\n4\n2 3 2 2\n2 3 4 3", "5\n2\n1 2 2 1 2\n4 5 1 4 1", "7\n7\n3 2 6 2 2 2 5\n4 7 5 6 2 2 2", "2\n1000\n12 34\n56 78", "8\n4\n1 1 4 1 3 1 8 1\n1 1 1 1 1 3 1 2", "9\n2\n8 7 1 1 3 7 1 2 4\n4 1 1 8 7 7 1 1 5", "10...
UNKNOWN
PYTHON3
CODEFORCES
116
d8c9a461ab8269197b4cbd138999561f
Bender Problem
Robot Bender decided to make Fray a birthday present. He drove *n* nails and numbered them from 1 to *n* in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordin...
[ "def main():\r\n n, m = map(int, input().split())\r\n nails = []\r\n for _ in range(n):\r\n nails.append(tuple(map(int, input().split())))\r\n rods = list(map(int, input().split()))\r\n rods_count1, rods_count2 = {}, {}\r\n for i, rod in enumerate(rods):\r\n if rod not in rods_count1...
{"inputs": ["4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "4 4\n0 0\n0 1\n1 1\n1 0\n1 1 1 1", "6 2\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2", "6 3\n0 0\n2 0\n2 2\n1 2\n1 1\n0 1\n4 2 2", "4 4\n-8423 7689\n6902 7689\n6902 2402\n-8423 2402\n20612 20612 91...
UNKNOWN
PYTHON3
CODEFORCES
9
d8d102de0b8305a5013c4be7d50a80f4
Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). Output a single inte...
[ "x , y = map(int, input().split())\r\na = [x,y,y-x,-x,-y,x-y]\r\nn = int(input())\r\nif n<=6:\r\n print(a[n-1]%1000000007)\r\nelse:\r\n print(a[(n%6)-1] % 1000000007)", "n,m=map(int,input().split())\r\na=int(input())\r\nl=[n,m,m-n,n*-1,m*-1,n-m]\r\nr=l[((a-1)%6)]\r\nprint(r%1000000007)", "def slv(x):\r\n ...
{"inputs": ["2 3\n3", "0 -1\n2", "-9 -11\n12345", "0 0\n1000000000", "-1000000000 1000000000\n2000000000", "-12345678 12345678\n1912345678", "728374857 678374857\n1928374839", "278374837 992837483\n1000000000", "-693849384 502938493\n982838498", "-783928374 983738273\n992837483", "-872837483 -682738473\n999999999", "-8...
UNKNOWN
PYTHON3
CODEFORCES
166
d8def71219429750efca943f33e2929e
Two Bags of Potatoes
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first...
[ "y,k,n=map(int,input().split())\r\nx=k*(1+y//k)-y\r\nflag=0\r\nwhile x+y<=n:\r\n flag=1\r\n print(x,end=\" \")\r\n x+=k\r\nif flag==0:\r\n print(-1)", "y,k,n = map(int,input().split())\r\nx = k - y%k\r\nf = 0\r\nwhile x+y <= n:\r\n print(x,end=\" \")\r\n x += k\r\n f = 1\r\nif f==0:\r\n pr...
{"inputs": ["10 1 10", "10 6 40", "10 1 20", "1 10000 1000000000", "84817 1 33457", "21 37 99", "78 7 15", "74 17 27", "79 23 43", "32 33 3", "55 49 44", "64 59 404", "61 69 820", "17 28 532", "46592 52 232", "1541 58 648", "15946 76 360", "30351 86 424", "1 2 37493", "1 3 27764", "10 4 9174", "33 7 4971", "981 1 3387"...
UNKNOWN
PYTHON3
CODEFORCES
278
d8f8774e428312b2de356559e7c80362
View Angle
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a...
[ "t=int(input())\r\nimport math\r\nan=[]\r\nep=10**-16\r\nfor _ in range (t):\r\n x,y=list(map(int,input().split()))\r\n if(x>0 and y>0):\r\n an.append(180*math.atan(abs(y)/((abs(x))+ep))/math.pi)\r\n elif(x<0 and y>0):\r\n an.append(180-180*math.atan(abs(y)/((abs(x))+ep))/math.pi)\r\n elif...
{"inputs": ["2\n2 0\n0 2", "3\n2 0\n0 2\n-2 2", "4\n2 0\n0 2\n-2 0\n0 -2", "2\n2 1\n1 2", "1\n1 1", "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8", "10\n-1 28\n1 28\n1 25\n0 23\n-1 24\n-1 22\n1 27\n0 30\n1 22\n1 21", "10\n-5 9\n-10 6\n-8 8\n-9 9\n-6 5\n-8 9\n-5 7\n-6 6\n-5 10\n-8 7", "10\n6 -9\n9 -5\n10 -5\...
UNKNOWN
PYTHON3
CODEFORCES
41
d8fedd0313ef52a71b02caf1971f7059
2Char
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi...
[ "n = int(input())\r\na = []\r\nb = []\r\nfor i in range(n):\r\n s = input()\r\n a.append(sorted(list(set(s))))\r\n b.append(len(s))\r\nv = 0\r\nfor i in range(97,97+25):\r\n for j in range(98,97+26):\r\n u = 0\r\n for k in range(n):\r\n for c in a[k]:\r\n if ord(c)...
{"inputs": ["4\nabb\ncacc\naaa\nbbb", "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa", "1\na", "2\nz\nz", "5\nabcde\nfghij\nklmno\npqrst\nuvwxy", "6\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg\ngggggg", "6\naaaaaa\naaaaaa\nbbbbbb\nbbbbbb\naaabbb\nababab", "1\nabc", "2\nabc\nbca", "3\nab\nba\nzzz", "3\nab\nba\nzzzzz", "5\nzzz\nz...
UNKNOWN
PYTHON3
CODEFORCES
104
d912639c658962fc49408726816d8926
Vanya and Food Processor
Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed *h* and the processor smashes *k* centimeters of potato each second. If there are less than *k* centimeters remaining, than during this second processor smashes all the remaining potato. V...
[ "import math\r\n\r\nn,h,k=map(int,input().split())\r\n\r\nx=list(map(int,input().split()))\r\n\r\nsec=0\r\ns=0\r\nind=0\r\nwhile(1):\r\n if ind>=n:\r\n break\r\n while(ind<n and s+x[ind]<=h):\r\n s+=x[ind]\r\n ind+=1\r\n sec+=s//k\r\n s=s%k\r\n\r\n if ind<n and s+x[ind]>h and s<k...
{"inputs": ["5 6 3\n5 4 3 2 1", "5 6 3\n5 5 5 5 5", "5 6 3\n1 2 1 1 1", "10 100 80\n76 75 73 71 76 74 73 70 78 75", "10 100 88\n11 23 69 6 71 15 25 1 43 37", "10 100 81\n100 97 96 98 98 95 100 97 97 99", "10 1000000000 34\n262467899 490831561 793808758 450543931 364178715 95212706 14245051 92006075 424282318 436927280"...
UNKNOWN
PYTHON3
CODEFORCES
7
d9166e3b0f0ed9de32f8e9449f984a1c
Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*. In a single second, he can modify the length of a single side of the current triangle suc...
[ "x,y=map(int,input().split(' '))\r\nans=0\r\nA=[y]*3\r\nwhile(sum(A)<x*3):\r\n\tA.sort()\r\n\tA[0]=min(x,A[1]+A[2]-1)\r\n\tans+=1\r\nprint(ans)\r\n", "from math import sqrt\nimport sys\n\nx, y = [int(i) for i in input().split()]\na = y\nb = y\nc = y\ncount = 0\nwhile a != x or b != x or c != x:\n min_side = mi...
{"inputs": ["6 3", "8 5", "22 4", "4 3", "57 27", "61 3", "5 4", "10 6", "20 10", "30 5", "25 24", "25 3", "12 7", "18 6", "100000 3", "100000 9999", "9999 3", "5323 32", "6666 66", "38578 32201", "49449 5291", "65310 32879", "41183 4453", "49127 9714", "19684 12784", "15332 5489", "33904 32701", "9258 2966", "21648 11...
UNKNOWN
PYTHON3
CODEFORCES
106
d919c3dbfa754f9bf126bdc7d28bb833
Benches
The city park of IT City contains *n* east to west paths and *n* north to south paths. Each east to west path crosses each north to south path, so there are *n*2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possib...
[ "ans = 1\nn = int(input())\n\nfor i in range(5,0,-1):\n ans*=n\n n-=1\n\nans = (ans**2)//120\nprint(ans)\n\n\n\t \t \t \t\t \t\t \t \t \t", "from math import comb\n\nfac_5 = 120\nn = int(input())\n\nplacement_possib = n * (n - 1) * (n - 2) * (n - 3) * (n - 4)\ntotal = comb(n, 5) * placement_pos...
{"inputs": ["5", "6", "7", "15", "17", "72", "83", "95", "99", "100"], "outputs": ["120", "4320", "52920", "1082161080", "4594961280", "23491596420472320", "101159538130177920", "402852449038723320", "613867215317368320", "680185280130048000"]}
UNKNOWN
PYTHON3
CODEFORCES
23
d94229bdeee493d6d40f8e91e0886a42
Little Dima and Equation
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions *x* (0<=&lt;<=*x*<=&lt;<=109) of the equation: where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi...
[ "def number_sum(number):\r\n number = str(number)\r\n num_sum = 0\r\n for elem in number:\r\n num_sum += int(elem)\r\n return num_sum\r\n\r\ndef main():\r\n a,b,c = map(int,input().split())\r\n answers = []\r\n for i in range(1,82):\r\n if 0<b*i**a+c<10**9 and number_sum(b*i**a+c)...
{"inputs": ["3 2 8", "1 2 -18", "2 2 -1", "1 1 0", "1 37 963", "1 298 -1665", "1 3034 -9234", "5 9998 9998", "5 10000 10000", "5 65 352", "5 9999 9999", "4 2099 -38", "1 1 -6708", "5 36 -46", "5 8975 -4", "3 2794 -3354", "5 1 4473", "5 1 -9999", "4 4 6", "5 19 -666", "5 5 -865", "2 8468 -3666", "4 9359 -3039", "5 5706 ...
UNKNOWN
PYTHON3
CODEFORCES
30
d947c674f71ad1869e3b4e4c2a9b4d08
Allowed Letters
Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup! Actually, Polycarp has already came up with the name but some improvement ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ns = list(input().rstrip())\r\npow2 = [1]\r\nfor _ in range(6):\r\n pow2.append(2 * pow2[-1])\r\np = pow2[6]\r\ncnt = [0] * p\r\nfor i in s:\r\n cnt[pow2[i - 97]] += 1\r\nsp = set(pow2)\r\nu = [[pow2[i]] for i in range(6...
{"inputs": ["bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef", "abacaba\n0", "fc\n2\n1 cfab\n2 f", "bbcbbc\n6\n1 c\n2 c\n3 b\n4 ab\n5 ab\n6 ab", "abcdefffffffffffffff\n5\n20 abcde\n19 abcde\n18 abcde\n17 abcde\n16 abcde", "abcdefffffffffffffff\n20\n1 acf\n2 cdef\n3 ef\n4 def\n5 adef\n6 acdef\n7 bdef\n8 abdf\n9 bcdf\n10 abf\n11...
UNKNOWN
PYTHON3
CODEFORCES
1
d9838a48b531ba63f2671bdf2b42d709
Russian Roulette
After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of *n* bullet slots able to contain exactly *k* bullets, now the boys have a chance to resolve the problem once and for all. Sash...
[ "n,k,p=map(int,input().split())\r\nif n%2:n,k=n-1,k-1\r\nfor i in range(p):\r\n x=int(input())\r\n z=((k<=n//2 and x%2==0 and x>n-2*k) or (k>n//2 and(x%2==0 or (x>n-2*(k-n//2)))) or (x>n and k>=0))\r\n print(['.','X'][z],end='')", "n,k,p=map(int,input().split())\r\nif n%2:n,k=n-1,k-1\r\nfor i in range(p):\r\n ...
{"inputs": ["3 1 3\n1\n2\n3", "6 3 6\n1\n2\n3\n4\n5\n6", "5 2 5\n1\n2\n3\n4\n5", "4 2 8\n1\n3\n4\n2\n3\n4\n1\n2", "4 0 4\n1\n2\n3\n4", "10 2 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "12 2 12\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12", "9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9", "15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\...
UNKNOWN
PYTHON3
CODEFORCES
3
d987e074cea379ef806078ed3db3e1f4
Help Caretaker
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse. He's got problems wi...
[ "n, m = map(int, input().split())\nswapped = False\nif n < m:\n n, m = m, n\n swapped = True\nans = '' \nif n == 1 and m == 1:\n\tans = '''0\n.'''\nif n == 2 and m == 1:\n\tans = '''0\n.\n.'''\nif n == 2 and m == 2:\n\tans = '''0\n..\n..'''\nif n == 3 and m == 1:\n\tans = '''0\n.\n.\n.'''\nif n == 3 and m == ...
{"inputs": ["3 3", "5 6", "2 2", "4 2", "3 4", "5 3", "4 4", "3 6", "5 4", "5 5", "1 1", "1 2", "2 1", "1 3", "3 1", "1 4", "4 1", "1 5", "5 1", "1 6", "2 3", "3 2", "6 1", "1 7", "7 1", "1 8", "2 4", "8 1", "1 9", "9 1", "2 5", "5 2", "2 6", "4 3", "6 2", "2 7", "7 2", "3 5", "2 8", "8 2", "2 9", "6 3", "9 2", "4 5", ...
UNKNOWN
PYTHON3
CODEFORCES
2
d994761ff4339bef8b16efd63c03a5fc
GukiZ and GukiZiana
Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called *GukiZiana*. For given array *a*, indexed with integers from 1 to *n*, and number *y*, *GukiZiana*(*a*,<=*y*) represents maximum value of *j*<=-<=*i*, such that *a**j*<==<=*a**i*<==<=*y*. If there is no *y* as an ele...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, q = map(int, input().split())\r\na = list(map(int, input().split()))\r\nm = 555\r\nm0 = n // m + min(n % m, 1)\r\ns = [set() for _ in range(m0)]\r\nfor i in range(m0):\r\n for j in range(i * m, min((i + 1) * m, n)):\r\n...
{"inputs": ["4 3\n1 2 3 4\n1 1 2 1\n1 1 1 1\n2 3", "2 3\n1 2\n1 2 2 1\n2 3\n2 4", "8 5\n1 1 1 2 1 3 1 1\n2 1\n1 1 8 1\n2 2\n1 2 5 2\n2 4", "8 8\n1 9 1 9 2 3 4 5\n1 3 7 1\n2 6\n2 8\n2 9\n1 1 7 3\n2 11\n2 1000000000\n1 1 1 1", "7 3\n2 4 5 2 3 2 8\n2 2\n1 3 4 1\n2 4", "2 2\n1000000000 1000000000\n1 1 2 1\n2 1000000000", "...
UNKNOWN
PYTHON3
CODEFORCES
1
d9a29a5abec504e0145e12b7ca9942e3
Arpa and a research in Mexican wave
Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-t...
[ "mass = input().split()\r\n\r\nn = int(mass[0])\r\nk = int(mass[1])\r\nt = int(mass[2])\r\n\r\n\r\n'''for i in range(1, t + 1):\r\n if i <= k:\r\n result = result + 1\r\n elif i <= n:\r\n result = result\r\n else:\r\n result = result - 1\r\n'''\r\n\r\nif t <= k:\r\n print(t)\r\nelif...
{"inputs": ["10 5 3", "10 5 7", "10 5 12", "840585600 770678331 788528791", "25462281 23343504 8024619", "723717988 205757169 291917494", "27462087 20831796 15492397", "966696824 346707476 1196846860", "290274403 41153108 327683325", "170963478 151220598 222269210", "14264008 309456 11132789", "886869816 281212106 5289...
UNKNOWN
PYTHON3
CODEFORCES
246
d9ad52fdcdc20660bf62fa8976e10a19
Bus Number
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. ...
[ "fact = [0 for _ in range(35)]\r\nfact[0] = 1\r\nfor q in range(1,35):\r\n fact[q] = fact[q-1]*q\r\namts = []\r\nans = 0\r\ndef multinom():\r\n tot = 0\r\n for i in amts:\r\n tot = tot + i\r\n ret = fact[tot]\r\n for i in amts:\r\n ret = ret / fact[i]\r\n return ret\r\n\r\nt = int(in...
{"inputs": ["97", "2028", "1", "10", "168", "999999", "987654320023456789", "1000000000000000000", "74774", "2", "3", "4", "5", "6", "7", "8", "9", "101010101", "1010101010", "707070707070707070", "19293", "987650", "123456", "900008", "1000000", "9900111", "11112222", "88888880", "100000009", "203456799", "890009800",...
UNKNOWN
PYTHON3
CODEFORCES
18
d9b86edee53889453397f5b7ce5a5e84
Brain Network (hard)
Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of ...
[ "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n ...
{"inputs": ["2\n1", "3\n1\n2", "10\n1\n1\n1\n1\n3\n3\n7\n5\n5", "120\n1\n1\n2\n2\n3\n3\n4\n4\n5\n5\n6\n6\n7\n7\n8\n8\n9\n9\n10\n10\n11\n11\n12\n12\n13\n13\n14\n14\n15\n15\n16\n16\n17\n17\n18\n18\n19\n19\n20\n20\n21\n21\n22\n22\n23\n23\n24\n24\n25\n25\n26\n26\n27\n27\n28\n28\n29\n29\n30\n30\n31\n31\n32\n32\n33\n33\n34\n...
UNKNOWN
PYTHON3
CODEFORCES
1
d9cd69ac96b0cfa8b5d217423bac58b2
Fedor and coupons
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has *n* discount coupons, the *i*-th of them can be used with products w...
[ "import sys\r\ninput=sys.stdin.readline\r\nimport heapq\r\nif __name__==\"__main__\":\r\n n,m=map(int,input().split())\r\n arr=[]\r\n for i in range(n):\r\n h,t=map(int,input().split())\r\n arr.append([h,t,i+1])\r\n arr.sort()\r\n q,res,idx,poped,areas=[],0,0,[],set()\r\n for i in ra...
{"inputs": ["4 2\n1 100\n40 70\n120 130\n125 180", "3 2\n1 12\n15 20\n25 30", "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "7 6\n-8 6\n7 9\n-10 -5\n-6 10\n-7 -3\n5 8\n4 10", "9 6\n-7 -3\n-3 10\n-6 1\n-1 8\n-9 4\n-7 -6\n-5 -3\n-10 -2\n3 4", "7 7\n9 10\n-5 3\n-6 2\n1 6\n-9 6\n-10 7\n-7 -5", "23 2\n-629722518 -626148345\n7399...
UNKNOWN
PYTHON3
CODEFORCES
4
da0df1b8f82f23e6dd788cf13a0aa7a2
Cola
To celebrate the opening of the Winter Computer School the organizers decided to buy in *n* liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly *a* bottles 0.5 in volume, *b* one-liter bottles and *c...
[ "import sys\ninput=sys.stdin.readline\nprint=sys.stdout.write\nn,a,b,c=map(int,input().split())\nn*=2\nans=0\nfor i in range(b+1):\n\tfor j in range(c+1):\n\t\tif i*2+j*4<=n and i*2+j*4+a>=n:\n\t\t\tans+=1\nprint(str(ans))", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninp...
{"inputs": ["10 5 5 5", "3 0 0 2", "1 0 0 0", "1 1 0 0", "1 2 0 0", "1 0 1 0", "1 0 2 0", "1 0 0 1", "2 2 2 2", "3 3 2 1", "3 10 10 10", "5 2 1 1", "7 2 2 2", "7 3 0 5", "10 20 10 5", "10 0 8 10", "10 19 15 100", "20 1 2 3", "20 10 20 30", "25 10 5 10", "101 10 0 50", "101 10 10 50", "505 142 321 12", "999 999 899 299"...
UNKNOWN
PYTHON3
CODEFORCES
23
da2883d92f1247d31b17cf7ed15d3203
Saitama Destroys Hotel
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor...
[ "n,s=(map(int,input().split()))\r\nx=[]\r\nfor i in range(n):\r\n a,b=(map(int,input().split()))\r\n x.append([a,b])\r\nx.sort(key=lambda i:i[0],reverse=True)\r\nc=0\r\np=s\r\nfor i in x:\r\n c=max(i[1],c+p-i[0])\r\n p=i[0]\r\nc+=i[0]\r\nprint(c)", "n, s = map(int, input().split())\nMAXN = 1010\nT = [...
{"inputs": ["3 7\n2 1\n3 8\n5 2", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "1 1000\n1000 1000", "1 1\n1 1", "1 1000\n1 1", "1 1000\n1 1000", "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1...
UNKNOWN
PYTHON3
CODEFORCES
179
da2f1cf3fd4cb162fa2d6e760291b9b8
Hyperspace Jump (easy)
The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independe...
[ "# _\r\n#####################################################################################################################\r\n\r\ndef main():\r\n return nShipsWithSameCoordinate(int(input()), {})\r\n\r\n\r\ndef nShipsWithSameCoordinate(nShips, nShipsAt):\r\n ships_Coordinates = list(range(nShips))\r\n f...
{"inputs": ["4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7", "10\n(44+98)/19\n(36+58)/47\n(62+74)/68\n(69+95)/82\n(26+32)/29\n(32+46)/39\n(32+24)/28\n(47+61)/54\n(39+13)/26\n(98+98)/98", "30\n(89+76)/87\n(81+78)/18\n(60+97)/32\n(41+14)/48\n(55+65)/27\n(29+15)/95\n(64+13)/96\n(78+30)/75\n(43+6)/60\n(69+34)/48\n(62+2)/97...
UNKNOWN
PYTHON3
CODEFORCES
55
da43b3d2628ee657c28f06e7172069e1
Not simply beatiful strings
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a ...
[ "s = input()\r\nl = list(set(s))\r\nans = 1\r\nif (len(l)>4) or (len(l)<=1):\r\n ans = 0\r\nelse:\r\n if len(l)==2:\r\n c1=0\r\n c0=0\r\n for i in range(len(s)):\r\n if s[i]==l[0]:\r\n c0+=1\r\n else:\r\n c1+=1\r\n if (c1<2) or (c...
{"inputs": ["ababa", "zzcxx", "yeee", "a", "bbab", "abcd", "abc", "abcdaaaa", "aaaaaaaaaaaaaaa", "adb", "dcccbad", "bcbccccccca", "abcdefgh", "aabcdef", "aabc", "ssab", "ccdd", "abcc", "ab", "abcde", "aa", "aaabbb", "bbbba", "abbbc", "baabaa", "abacabadde", "aabbcc", "abbc", "aaaaaaabbbbbbcder", "aabb", "aabbccddee", "...
UNKNOWN
PYTHON3
CODEFORCES
110
da5eb88fa07a9f4934cdc5e65e4121a0
Coprocessor
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depen...
[ "n, m = (int(x) for x in input().strip().split())\r\n\r\ncoproc = [int(x) for x in input().strip().split()]\r\nedges = []\r\nfor _ in range(m):\r\n edges.append((int(x) for x in input().strip().split()))\r\n\r\ninorder = [0] * n \r\nadj = [[] for _ in range(n)]\r\nfor u, v in edges:\r\n adj[v].append(u)\r\n ino...
{"inputs": ["4 3\n0 1 0 1\n0 1\n1 2\n2 3", "4 3\n1 1 1 0\n0 1\n0 2\n3 0", "10 39\n0 1 0 1 0 1 1 0 1 1\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 9\n5 6\n5 7\n5 8\n5 9\n6 8\n6 9\n7 8\n7 9\n8 9", "10 16\n0 1 1 0 0 1 1...
UNKNOWN
PYTHON3
CODEFORCES
2
da6fcb2593d5a371fcd55ed5d106176c
Between the Offices
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem...
[ "n=int(input())\r\nstroka=input()\r\nSF=0\r\nFS=0\r\nplusiki=0\r\nwhile plusiki<n-1:\r\n if stroka[plusiki]=='S' and stroka[plusiki+1]=='F':\r\n SF=SF+1\r\n if stroka[plusiki]=='F' and stroka[plusiki+1]=='S':\r\n FS=FS+1\r\n plusiki=plusiki+1\r\nif SF>FS:\r\n print('YES')\r\nelse:\r\n p...
{"inputs": ["4\nFSSF", "2\nSF", "10\nFFFFFFFFFF", "10\nSSFFSFFSFF", "20\nSFSFFFFSSFFFFSSSSFSS", "20\nSSFFFFFSFFFFFFFFFFFF", "20\nSSFSFSFSFSFSFSFSSFSF", "20\nSSSSFSFSSFSFSSSSSSFS", "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS", "100\nFFFFFFFFFFFFFFFFFFFFFFFFF...
UNKNOWN
PYTHON3
CODEFORCES
887
da8590f2c736c318d86e744275cbf270
Chips
Gerald plays the following game. He has a checkered field of size *n*<=×<=*n* cells, where *m* various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for *n*<=-<=1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from ...
[ "I = input\r\nn,m = map(int , I().split())\r\nb = [1] * n * 2\r\nb[0] = b[n - 1] = b[n] = b[2 * n - 1] = 0\r\nfor i in range(m):\r\n r , c = map(int , I().split())\r\n b[r - 1] = b[n + c - 1] = 0\r\nif n % 2 and b[n // 2] and b[n + n // 2] : b[n // 2] = 0\r\nprint(sum(b))", "def solve():\n n, m = map(int...
{"inputs": ["3 1\n2 2", "3 0", "4 3\n3 1\n3 2\n3 3", "2 1\n1 1", "2 3\n1 2\n2 1\n2 2", "5 1\n3 2", "5 1\n2 3", "1000 0", "999 0", "5 5\n3 2\n5 4\n3 3\n2 3\n1 2", "5 5\n3 2\n1 4\n5 1\n4 5\n3 1", "5 5\n2 2\n5 3\n2 3\n5 1\n4 4", "6 5\n2 6\n6 5\n3 1\n2 2\n1 2", "6 5\n2 6\n5 2\n4 3\n6 6\n2 5", "6 5\n2 1\n6 4\n2 2\n4 3\n4 1"...
UNKNOWN
PYTHON3
CODEFORCES
7
da8ef89e28fe6467a869a3a606647489
Range Increments
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array *a* for all indexes in the segment [*l*,<=*r*]. In other words, this function does the following: Polycarpus knows the state of the array...
[ "N = 100000\r\nv = []\r\nfor i in range(0, N) :\r\n\tv.append([])\r\n\r\nline = input()\r\nn = int(line)\r\nline = input()\r\nlineSplit = line.split()\r\na = 0\r\nfor i in range(0, len(lineSplit)) :\r\n\tb = int(lineSplit[i])\r\n\tif b > a :\r\n\t\tfor j in range(a, b) :\r\n\t\t\tv[j].append([i, -1])\r\n\telif b < ...
{"inputs": ["6\n1 2 1 1 4 1", "5\n1 0 1 0 1", "1\n1", "1\n100000", "5\n1 2 3 4 5", "12\n0 1 1 1 3 4 3 3 3 3 2 2", "2\n1 1", "2\n2 1", "2\n1 3", "2\n2 4", "3\n1 1 1", "3\n0 2 1", "3\n2 2 1", "3\n2 4 2", "5\n1 1 0 0 0", "5\n0 0 1 1 0", "5\n1 0 2 1 0", "5\n2 1 2 3 3", "20\n4 5 4 4 3 2 2 1 2 2 2 3 3 4 2 2 2 1 1 1", "20\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
3
da9eae118d525876722583eb6f68b38b
Cakeminator
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
[ "n, m = [int(i) for i in input().split()]\r\nmas = [input() for _ in range(n)]\r\ncount = 0\r\nfor i in range(n-1,-1,-1):\r\n if 'S' not in mas[i]:\r\n count += m\r\n del mas[i]\r\n n -= 1\r\nfor j in range(m-1, -1, -1):\r\n flag = False\r\n for i in range(n):\r\n flag += 'S' ==...
{"inputs": ["3 4\nS...\n....\n..S.", "2 2\n..\n..", "2 2\nSS\nSS", "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "3 5\n..S..\nSSSSS\n..S..", "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS", "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS...
UNKNOWN
PYTHON3
CODEFORCES
520
dae0c1d757095ab713064ab15b0d198f
Happy Line
Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of *n* Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people,...
[ "n = int(input())\r\nline = [int(i) for i in input().split()]\r\n\r\nfor i in range(len(line)):\r\n line[i]+=i\r\nline.sort()\r\nfor i in range(len(line)):\r\n line[i]-=i\r\n\r\nimpossivel = False\r\nfor i in range(len(line)-1):\r\n if(line[i]>line[i+1]):\r\n impossivel = True\r\n break\r\nif...
{"inputs": ["2\n11 8", "5\n10 9 7 10 6", "3\n12 3 3", "4\n7 3 9 10", "1\n1", "5\n15 5 8 6 3", "1\n1000000000", "2\n2 1", "3\n11 1 9", "1\n0", "20\n38 32 21 44 26 24 15 32 34 40 31 33 33 13 26 28 12 10 14 18", "20\n43 38 20 41 16 37 27 29 19 17 24 19 28 8 14 32 13 21 32 16", "20\n44 50 41 18 28 31 21 38 12 20 28 15 12 2...
UNKNOWN
PYTHON3
CODEFORCES
13
db083a6098652bce07324df7bb974915
Sherlock and his girlfriend
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1. Watson gave Sherlock a challenge to color these jewelry pie...
[ "import math\nn=int(input())\nlt=[2]*(n+1)\nl=[2]\nfor i in range(2,n+2):\n for j in range(2,int(math.sqrt(i))+2):\n if i%j==0:\n break\n else:\n lt[i-1]=1\n l.append(i)\nlt[1]=1\nif n<3:\n print(1)\nelse:\n print(2)\nprint(*lt[1:])\n#print(l)\n \t\t \t \t\t \t \t\t ...
{"inputs": ["3", "4", "17", "25", "85", "105", "123", "452", "641", "293", "733", "1", "10", "287", "3202", "728", "3509", "5137", "2023", "4890", "8507", "1796", "3466", "1098", "11226", "11731", "11644", "14553", "17307", "23189", "6818", "1054", "28163", "30885", "27673", "11656", "36325", "31205", "29958", "1696", ...
UNKNOWN
PYTHON3
CODEFORCES
127
db1ffc2ec8f3719b2f915150a1a936fc
Vladik and chat
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them. At first, he need to download *t* chats. Vladik coded a script which should have downloaded the chats, however, something went wrong...
[ "import re\n\ndef proc(msgs):\n\tchg = False\n\tfor i, msg in enumerate(msgs):\n\t\tif msg[0] != '?': continue\n\t\tppn = msg[1]\n\t\tif i > 0: ppn.discard(msgs[i-1][0])\n\t\tif i != len(msgs)-1: ppn.discard(msgs[i+1][0])\n\t\tif len(ppn) == 1:\n\t\t\tmsg[0] = ppn.pop()\n\t\t\tchg = True\n\treturn chg\n\ndef is_val...
{"inputs": ["1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi", "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine", "2\n3\nnetman vladik Fedosik\n2\n?: users are netman, vladik, Fedosik\nvladik: something wrong with this chat\n4\nnetman tigerrrrr banany2001 klinchuh\n4\n?: tigerrrrr, banany2...
UNKNOWN
PYTHON3
CODEFORCES
3
db2e54f81215aad936adfd11356f0fc8
Pair of Numbers
Simon has an array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Today Simon asked you to find a pair of integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), such that the following conditions hold: 1. there is integer *j* (*l*<=≤<=*j*<=≤<=*r*), such that all integers *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r...
[ "from collections import defaultdict\r\nfrom math import gcd\r\nfrom sys import stdin\r\n\r\ninput = stdin.readline\r\n\r\nclass SparseTable:\r\n def __init__(self, data, func=max):\r\n self.func = func\r\n self.data = [list(data)]\r\n i, n = 1, len(data)\r\n while 2 * i <= n:\r\n ...
{"inputs": ["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11", "1\n1343", "1\n1000000", "1\n5", "1\n1", "2\n1 1000000", "2\n999999 1000000", "5\n3 3 6 2 2"], "outputs": ["1 3\n2 ", "1 4\n1 ", "5 0\n1 2 3 4 5 ", "1 0\n1 ", "1 0\n1 ", "1 0\n1 ", "1 0\n1 ", "1 1\n1 ", "2 0\n1 2 ", "2 2\n1 3 "]}
UNKNOWN
PYTHON3
CODEFORCES
5
db44ea9c41db94f6084b977e4c7cafc7
Adjacent Replacements
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occu...
[ "n = int(input())\r\na = [int(s) for s in input().split(' ')]\r\nb = [str(c - ((c + 1) % 2)) for c in a]\r\nprint(' '.join(b))\r\n", "n=int(input())\r\na=[int(x) for x in input().split()]\r\nfor i in a:\r\n print(i-1+i%2,end=' ')", "input()\r\nprint(*[x-1 if x%2 == 0 else x for x in map(int, input().split())])...
{"inputs": ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "1\n999999999", "1\n1000000000", "1\n210400", "5\n100000000 100000000 100000000 100000000 100000000", "1\n2441139", "2\n2 2", "3\n2 2 2", "2\n4 4"], "outputs": ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 99999999...
UNKNOWN
PYTHON3
CODEFORCES
217
db75ce1739f74864cfa3c19dc9613c42
New Reform
Berland has *n* cities connected by *m* bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the roa...
[ "#cycle detection\r\ndef dfs(node,par):\r\n seen[node] = 1\r\n for each in adj[node]:\r\n if seen[each] == 0:\r\n if dfs(each,node) == True: return True\r\n else:\r\n if each != par: return True\r\n return False\r\n\r\nn,m = map(int,input().split())\r\nadj = [list() for ...
{"inputs": ["4 3\n2 1\n1 3\n4 3", "5 5\n2 1\n1 3\n2 3\n2 5\n4 3", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6", "4 4\n1 2\n2 3\n3 4\n4 1", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10...
UNKNOWN
PYTHON3
CODEFORCES
16
db7e46473014ad3cea73d78b576463bc
Table
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are...
[ "n,m=map(int,input().split());x,y=[],[];b=0\r\nfor i in range(n):\r\n\tt=list(map(int,input().split()))\r\n\tfor j in range(m):\r\n\t\tif t[j]==1:y.append(j+1);x.append(i+1)\r\nfor i in y:\r\n\tif i==1 or i==m:b=2;break\r\nfor i in x:\r\n\tif i==1 or i==n:b=2;break\r\nif b==2:print(2)\r\nelse:print(4)", "n, m = m...
{"inputs": ["3 3\n0 0 0\n0 1 0\n0 0 0", "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0", "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
127
dba7d865f424682bcd9b24c0a012fd31
Xors on Segments
You are given an array with *n* integers *a**i* and *m* queries. Each query is described by two integers (*l**j*,<=*r**j*). Let's define the function . The function is defined for only *u*<=≤<=*v*. For each query print the maximal value of the function *f*(*a**x*,<=*a**y*) over all *l**j*<=≤<=*x*,<=*y*<=≤<=*r**j*,<= ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v, w):\r\n return (u * z + v) * z + w\r\n\r\ndef update1(x, c):\r\n i = x ^ l1\r\n tree1[i], color1[i] = x, c\r\n i >>= 1\r\n for _ in range(w):\r\n j, k = i << 1, i << 1 ^ 1\r\n if color...
{"inputs": ["6 3\n1 2 3 4 5 6\n1 6\n2 5\n3 4", "1 1\n1\n1 1", "6 20\n10 21312 2314 214 1 322\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n2 2\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 4\n4 5\n4 6\n5 5\n5 6\n6 6", "1 1\n1\n1 1", "5 10\n10 2 7 8 8\n2 5\n3 4\n5 5\n1 3\n3 4\n2 2\n2 5\n4 5\n5 5\n1 2"], "outputs": ["7\n7\n7", "1", "10\n21313\...
UNKNOWN
PYTHON3
CODEFORCES
1
dbc16444769ffff8737f6cd7f40829fd
Party
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amo...
[ "for _ in range(int(input())):\r\n print(max(0, int(input()) - 2))\r\n", "for i in range(int(input())):\r\n x = int(input())\r\n print(max(0,x-2))", "import sys\r\ninputs,first = sys.stdin.readlines(),True\r\nfor i in inputs:\r\n\tif first:\r\n\t\tfirst = False\r\n\telse:\r\n\t\tprint(max(0,int(i)-2))", "t...
{"inputs": ["1\n3"], "outputs": ["1"]}
UNKNOWN
PYTHON3
CODEFORCES
43
dbc7d5ef45096d9e8efa03e27e9f8068
Olya and Energy Drinks
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u * m + v\r\n\r\ndef bfs(x1, y1, x2, y2):\r\n q1, q2 = [], []\r\n q1.append((x1, y1))\r\n dist = [inf] * l\r\n dist[f(x1, y1)] = 0\r\n d = 0\r\n while q1:\r\n for i, j in q1...
{"inputs": ["3 4 4\n....\n###.\n....\n1 1 3 1", "3 4 1\n....\n###.\n....\n1 1 3 1", "2 2 1\n.#\n#.\n1 1 2 2", "10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n#.#.#.#.#.\n#.#.#...#.\n#.#.#####.\n#.#.......\n6 6 10 2", "10 10 3\n##########\n##########\n##########\n##########\n##########\...
UNKNOWN
PYTHON3
CODEFORCES
6
dbcbc232b85bbf107db4ffb4922cc8f3
Puzzling Language
In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usua...
[ "from sys import stdin,stdout\r\n# from os import _exit\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,facto...
{"inputs": ["$$$", "Codeforces", "!\"#$%&'()*", "zyxwvutsrq", "z", "!", "Q", "\\RM3uy$>", "fQs1@=", "%n<VD0Q=eO", "[=iG", "&o+(", "9IHC0", ">,05jka@?", "j0&)@0=", "ouuj0an8;", "\\ZN).!R$N<", "4]", "YYiu0", "3^7Ib`nt^\"", "WnX/v-1&", "<Zno", "&.Uv", "4Vo", "R8", "uNC", "*)f>H.;!P", "=veAmKR]N'", "\\RD?XXd", "\"8c]Q@6&e"...
UNKNOWN
PYTHON3
CODEFORCES
5
dbf788c2f5d9376e093d86306456040f
Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
[ "n,k=map(int,input().split())\r\nlist1=list(map(int,input().split()))\r\nx=0\r\nxx=100000001\r\nindex=0\r\nfor i in range(k):\r\n s=0\r\n for j in range(x,n,k):\r\n s+=list1[j]\r\n if(s<xx):\r\n xx=s\r\n index=x\r\n x+=1\r\nprint(index+1)", "n, k = map(int,input().split())\r\na = ...
{"inputs": ["6 2\n3 2 1 6 5 4", "10 5\n1 3 5 7 9 9 4 1 8 5", "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10 10\n8 4 5 7 6 9 2 2 3 5", "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1", "1 1\n1", "2 1\n1 1", "4 2\n2 1 1 3", "15 5\n5 5 5 5 5 1 2 3 4 5 ...
UNKNOWN
PYTHON3
CODEFORCES
75
dc2aae63f53571f5e0dedbbc0e5197f4
Swapping Characters
We had a string *s* consisting of *n* lowercase Latin letters. We made *k* copies of this string, thus obtaining *k* identical strings *s*1,<=*s*2,<=...,<=*s**k*. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the s...
[ "import sys\r\n\r\nk, n = map(int, input().split())\r\ns = [list(word.rstrip()) for word in sys.stdin]\r\n\r\ndouble = True if max(s[0].count(chr(i+97)) for i in range(26)) > 1 else False\r\ndiff = [set() for _ in range(k)]\r\ndiff_cnt = [0]*k\r\nfor i in range(1, k):\r\n for j in range(n):\r\n if s[0][j]...
{"inputs": ["3 4\nabac\ncaab\nacba", "3 4\nkbbu\nkbub\nubkb", "5 4\nabcd\ndcba\nacbd\ndbca\nzzzz", "3 2\nxh\nxh\nxh", "3 4\nkbub\nkbbu\nubkb", "1 2\nyu", "1 3\nvts", "2 2\nnm\nnm", "2 3\nghn\nghn", "3 2\ncg\ncg\ncg", "3 3\nuvh\nvhu\nhuv", "100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nq...
UNKNOWN
PYTHON3
CODEFORCES
1
dc300f461142b79d550b3d60d2b8001e
Hag's Khashba
Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering. Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and othe...
[ "from math import hypot, atan2, cos, sin, sqrt, pi\nimport sys\n\nmapInt = lambda:map(int,sys.stdin.buffer.readline().split())\n\nN, Q = mapInt()\n\n# Get points from input\npoints = {}\nfor n in range(N) :\n x, y = mapInt()\n points[n+1] = [x,y]\n\n# Calculate COM (centroid)\ncentroid = [0,0]\nA = 0\nfor n i...
{"inputs": ["3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3", "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1", "10 10\n0 -100000000\n1 -100000000\n1566 -99999999\n2088 -99999997\n2610 -99999994\n3132 -99999990\n3654 -99999985\n4176 -99999979\n4698 -99999972\n5220 -99999964\n1 2 5\n2 1\n1 1 7\n2 5\n1 5 4\n1 4 2\n2 8\n1 7 9\n2 1\n1 2 10", "...
UNKNOWN
PYTHON3
CODEFORCES
3
dc37a49da0b1d0da6a7014102922695b
Sereja and Suffixes
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s...
[ "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Dec 7 14:01:59 2022\r\n\r\n@author: 86138\r\n\"\"\"\r\n\r\nn,m=map(int,input().split())\r\nli=list(map(int,input().split()))\r\ns=set();dp=[0]*n;p=0\r\nfor i in range(n-1,-1,-1):\r\n if li[i] not in s:\r\n p+=1\r\n s.add(li[i]);dp[i]=p\r\nli_1=[]\r\...
{"inputs": ["10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "2 2\n8 4\n1\n1", "1 5\n5\n1\n1\n1\n1\n1", "4 7\n3 1 4 2\n4\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
314
dc8e5f65bf595e4b9d2f2ca02084f9da
MADMAX
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with *n* vertices and *m* edges. There's a character written on each edge, a l...
[ "# int(input())\n\n# [int(i) for i in input().split()]\n\nimport sys\n\nsys.setrecursionlimit(20000)\n\ndef go(v,w,last):\n\n if game[v][w][last] >= 0: return(game[v][w][last])\n\n\n\n flag = 0\n\n move = 0\n\n\n\n for p in edges_out[v]:\n\n if p[1] >= last:\n\n move = 1\n\n ...
{"inputs": ["4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b", "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h", "2 1\n1 2 q", "8 20\n2 4 a\n1 8 a\n1 2 v\n8 4 h\n1 7 w\n5 4 h\n2 8 h\n7 4 i\n4 3 w\n6 8 l\n1 4 v\n1 3 g\n5 3 b\n1 6 a\n7 3 w\n6 4 f\n6 7 g\n7 8 n\n5 8 g\n2 6 j", "3 2\n1 3 l\n2 1 v", "100 1\n92 93 p"], "outputs...
UNKNOWN
PYTHON3
CODEFORCES
5
dc9dc468e2c937fdd3ca5379031d8341
Fingerprints
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
[ "n,m=[int(x) for x in input().split()]\r\nnum=[int(x) for x in input().split()]\r\nop=[int(x) for x in input().split()]\r\nfin=[]\r\nfor x in num:\r\n\tif x in op:\r\n\t\tfin.append(str(x))\r\nprint(' '.join(fin))", "n, m = map(int, input().split(\" \"))\r\nsequence = list(map(int, input().split(\" \")))\r\nfinge...
{"inputs": ["7 3\n3 5 7 1 6 2 8\n1 2 7", "4 4\n3 4 1 0\n0 1 7 9", "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8", "1 1\n4\n4", "3 7\n6 3 4\n4 9 0 1 7 8 6", "10 1\n9 0 8 1 7 4 6 5 2 3\n0", "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6", "8 2\n7 2 9 6 ...
UNKNOWN
PYTHON3
CODEFORCES
645
dcec153142741226f333194eb0ae6f7c
Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $-100$, while the second group is positioned in suc...
[ "n, m = map(int, input().strip().split())\r\ny1 = list(map(int, input().strip().split()))\r\ny2 = list(map(int, input().strip().split()))\r\n\r\ny1.sort()\r\ny2.sort()\r\nu1 = list()\r\nu2 = list()\r\np = 0\r\nwhile p < n:\r\n q = p\r\n while q < n and y1[q] == y1[p]:\r\n q += 1\r\n u1.append((y1[p]...
{"inputs": ["3 9\n1 2 3\n1 2 3 7 8 9 11 12 13", "5 5\n1 2 3 4 5\n1 2 3 4 5", "50 50\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625 975 457 414 434 146 602 235 86 240 756 161 675\n222 371 393 634 76 268 348 294 227 429 ...
UNKNOWN
PYTHON3
CODEFORCES
3
dcf673ff4e3d272a4fef682339c0d6ea
Lucky Tickets
Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such ...
[ "from collections import defaultdict\r\n \r\nfours = [list() for i in range(10001)]\r\nfor a in range(10):\r\n for b in range(10):\r\n for c in range(10):\r\n for d in range(10):\r\n num = (a, b, c, d)\r\n variants = set()\r\n variants.add(a + b + c ...
{"inputs": ["0 3", "7 4", "0 10000", "1 10000", "9999 10000", "9998 10000", "9997 10000", "9973 10000", "0 300000", "1 300000", "10000 300000", "9999 300000", "9973 300000", "9998 300000", "2 10000", "3 10000", "4 10000", "5 10000", "7 10000", "14 10000", "9996 10000", "10 10000", "256 10000", "9240 10000", "7560 10000...
UNKNOWN
PYTHON3
CODEFORCES
1
dcfbb6638db328393fdcbc6d1ec406d6
Lucky Sum
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ...
[ "# Author Name: Ajay Meena\r\n# Codeforce : https://codeforces.com/profile/majay1638\r\nimport sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nfrom bisect import bisect_right\r\nfrom sys import stdin, stdout\r\n\r\n# -------------- INPUT FUNCTIONS ------------------\r\n\r\n\r\ndef get_ints_in_variables(): re...
{"inputs": ["2 7", "7 7", "1 9", "4 7", "12 47", "6 77", "1 100", "1000000000 1000000000", "77 77", "69 788", "474 747", "4 77777", "1 1000000", "47 744447", "47444 1000000000", "48 854888", "854444 985555", "774744 774747", "654 987654", "477777 1000000000", "77777 777777777", "963 85555574", "47 7444", "1 1000000000"...
UNKNOWN
PYTHON3
CODEFORCES
76
dcffb99df12778203441b22c7fe377c7
Jzzhu and Numbers
Jzzhu have *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. We will call a sequence of indexes *i*1,<=*i*2,<=...,<=*i**k* (1<=≤<=*i*1<=&lt;<=*i*2<=&lt;<=...<=&lt;<=*i**k*<=≤<=*n*) a group of size *k*. Jzzhu wonders, how many groups exists such that *a**i*1 &amp; *a**i*2 &amp; ... &amp; *a**i**k*<==<=0 (1<=≤<=*k*...
[ "import sys\r\ndef I(): return int(sys.stdin.readline().rstrip())\r\ndef MI(): return map(int,sys.stdin.readline().rstrip().split())\r\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\r\ndef LI2(): return list(map(int,sys.stdin.readline().rstrip()))\r\ndef S(): return sys.stdin.readline().rstr...
{"inputs": ["3\n2 3 3", "4\n0 1 2 3", "6\n5 2 0 5 2 1", "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "10\n450661 128600 993228 725823 293549 33490 843121 903634 556169 448234", "1\n0", "1\n1", "6\n524 529 5249 524 529 529", "55\n0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 3 4 5 6 7 8 9 4 5 6 7 8 9 5 6 7 8 9 6...
UNKNOWN
PYTHON3
CODEFORCES
6
dd23dd1684258e60b52f6529bf828f6c
Amusing Joke
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
[ "s1=input()\r\ns2=input()\r\ns3=input()\r\n\r\ns1sort = sorted(s1)\r\ns2sort = sorted(s2)\r\ns3sort = sorted(s3)\r\n\r\n# print(s1sort)\r\n\r\ns4 = s1sort+s2sort\r\ns4sort=sorted(s4)\r\n# print(s3sort)\r\n# print(s4)\r\n# print(s4)\r\nans=1\r\n\r\nif len(s3)!=len(s4):\r\n print(\"NO\")\r\n exit()\r\nelse:\r\n...
{"inputs": ["SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "B\nA\nAB", "ONDOL\nJNPB\nONLNJBODP", "Y\nW\nYW", "OI\nM\nIMO", "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "JUTCN\nPIGMZOPMEUFADQBW\nN...
UNKNOWN
PYTHON3
CODEFORCES
789
dd2461a6f9dafd41268ba6bff8d1830d
Domino
We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4<=×<=*n* recta...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\n\r\n\r\nif n % 2:\r\n x1 = ('aacc' * n)[:n-1]\r\n x2 = ('ccaa' * n)[:n-1]\r\n x3 = ('bbdd' * n)[:n-1]\r\n x4 = ('ddbb' * n)[:n-1]\r\n print(x1+'e')\r\n print(x2+'e')\r\n print('f'+x3)\r\n print('f'+x4)\r\nelse:\r\n x1 = ...
{"inputs": ["4", "2", "3", "5", "1", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"], "outputs": ["aacc\nbbdd\nzkkz\nzllz", "aa\nbb\naa\nbb", "aab\nccb\nbaa\nbcc...
UNKNOWN
PYTHON3
CODEFORCES
11
dd26a1454c8815b3a6c8070afb3087a8
Road to Post Office
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to *d* kilometers. Vasiliy's car is not new — it breaks after driven every *k* kilometers and Vasiliy needs *t* seconds to repair it. After repairing his car Vasiliy can drive again (but after *k* kilometers ...
[ "d,k,a,b,t=map(int,input().split())\r\n\r\ndef calc(mid):\r\n x=min(d,k+mid*k)\r\n return x*a+(d-x)*b+t*mid\r\n# k+n*k<=d\r\n# n<=(d-k)//k\r\n\r\nL,R=-1,(d-k)//k+1\r\nwhile L+2<R:\r\n c1=L+(R-L)//3\r\n c2=R-(R-L)//3\r\n if calc(c1)<calc(c2):\r\n R=c2\r\n else:\r\n L=c1\r\n\r\nans=9*10**18\r\nfor i in ra...
{"inputs": ["5 2 1 4 10", "5 2 1 4 5", "1 1 1 2 1", "1000000000000 1000000 999999 1000000 1000000", "997167959139 199252 232602 952690 802746", "244641009859 748096 689016 889744 927808", "483524125987 264237 209883 668942 244358", "726702209411 813081 730750 893907 593611", "965585325539 329221 187165 817564 718673", ...
UNKNOWN
PYTHON3
CODEFORCES
8
dd382f408ce546f2af364af2e0257c42
Levels and Regions
Radewoosh is playing a computer game. There are *n* levels, numbered 1 through *n*. Levels are divided into *k* regions (groups). Each region contains some positive number of consecutive levels. The game repeats the the following process: 1. If all regions are beaten then the game ends immediately. Otherwise, the sys...
[ "def calc(a,b):\r\n return (dp[i-1][a]-dp[i-1][b]+sum[b]*rev[b]-sum[a]*rev[a])/(sum[b]-sum[a])\r\nn,k=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nsum=[0]\r\nrev=[0]\r\nres=0.0\r\nfor i in x:\r\n sum.append(sum[-1]+i)\r\n rev.append(rev[-1]+1.0/i)\r\n res += sum[-1] / i\r\ndp = [[0.0]...
{"inputs": ["4 2\n100 3 5 7", "6 2\n1 2 4 8 16 32", "10 5\n47 56 21 20 50 47 26 10 57 58", "10 5\n39 49 99 91 66 14 32 26 83 49", "20 3\n71 85 56 41 96 52 11 71 59 8 63 87 91 51 40 60 41 59 34 93", "20 4\n25 66 10 18 67 40 66 49 3 51 61 29 10 72 71 22 63 4 74 67", "20 5\n79 44 59 91 54 28 30 35 42 95 56 58 29 89 93 73 ...
UNKNOWN
PYTHON3
CODEFORCES
1
dd4ab5a1ab3442824ebf7d06e96b723b
Kicker
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the ...
[ "p11 = list(map(int, input().split()))\r\np12 = list(map(int, input().split()))\r\np21 = list(map(int, input().split()))\r\np22 = list(map(int, input().split()))\r\n\r\ndef f(a, b, c, d):\r\n if a[0] > d[1] and b[1] > c[0]:\r\n return 1\r\n if a[0] < d[1] and b[1] < c[0]:\r\n return 2\r\n ret...
{"inputs": ["1 100\n100 1\n99 99\n99 99", "1 1\n2 2\n3 3\n2 2", "3 3\n2 2\n1 1\n2 2", "80 79\n79 30\n80 81\n40 80", "10 10\n4 9\n8 9\n7 6", "10 2\n9 3\n3 1\n9 4", "6 3\n6 10\n2 5\n4 4", "8 7\n1 5\n7 4\n8 8", "2 7\n8 4\n4 6\n10 8", "8 3\n4 9\n6 1\n5 6", "10 5\n3 1\n1 9\n1 2", "6 5\n10 6\n8 1\n3 2", "6 2\n7 5\n5 4\n8 6",...
UNKNOWN
PYTHON3
CODEFORCES
15
dd6ed2b719807458cc8a9b1d59a13cfd
Maximum Subsequence
You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty. Print the maximum possibl...
[ "import bisect\n \nn,M= tuple(map(int,input().split()))\n\nnums = list(map(int,input().split()))\n\nr1,r2 = [],[]\ndef dfs(index,last,sum,check):\n\n if index == last:\n if check == 1:\n r1.append(sum)\n else:\n r2.append(sum)\n return\n\n dfs(index+1,last,sum,check...
{"inputs": ["4 4\n5 2 4 1", "3 20\n199 41 299", "5 10\n47 100 49 2 56", "5 1000\n38361 75847 14913 11499 8297", "10 10\n48 33 96 77 67 59 35 15 14 86", "10 1000\n16140 63909 7177 99953 35627 40994 29288 7324 44476 36738", "30 10\n99 44 42 36 43 82 99 99 10 79 97 84 5 78 37 45 87 87 11 11 79 66 47 100 8 50 27 98 32 27",...
UNKNOWN
PYTHON3
CODEFORCES
21
dd7a7a3defc3f56ae33425c26d2916d1
DZY Loves Hash
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==...
[ "p,n=map(int,input().split())\r\nD=[-1]*p\r\nfor i in range(n):\r\n y=int(input())\r\n if D[y%p]!=-1:\r\n print(i+1)\r\n exit()\r\n else:\r\n D[y%p]=0\r\nprint(-1)", "p, n = map(int, input().split())\r\nhash_table = [False] * p\r\nans = -1\r\n\r\nfor i in range(n):\r\n x = int(input...
{"inputs": ["10 5\n0\n21\n53\n41\n53", "5 5\n0\n1\n2\n3\n4", "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537", "2 2\n788371161\n801743052", "10 6\n812796223\n122860157\n199259103\n597650585\n447742024\n521549402", "300 2\n822454942\n119374431", "300 2\n823284367\n507345500", "2 5\n791579811\n356...
UNKNOWN
PYTHON3
CODEFORCES
212
dd967a53482a424ba1d1d758c4d3a4a0
An abandoned sentiment from past
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
[ "n,k= map(int,input().split())\r\narr = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nif k >= 2:\r\n print(\"Yes\")\r\nelse:\r\n if k == 1:\r\n arr[arr.index(0)] = b[0]\r\n x = [i for i in arr]\r\n x.sort()\r\n if x == arr:\r\n print(\"No\")\r\n...
{"inputs": ["4 2\n11 0 0 14\n5 4", "6 1\n2 3 0 8 9 10\n5", "4 1\n8 94 0 4\n89", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80", "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112...
UNKNOWN
PYTHON3
CODEFORCES
246
ddda23f7ef553a81823a6b2e7064dfe1
USB vs. PS/2
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ...
[ "usb, ps, both = map(int, input().split())\r\na, b = [], []\r\nmax_, total = 0, 0\r\n \r\nfor _ in range(int(input())):\r\n cost, type = input().split()\r\n if type == 'USB':\r\n a.append(int(cost))\r\n else:\r\n b.append(int(cost))\r\n\r\na = sorted(a, reverse=True)\r\nb = sorted(b, reverse=...
{"inputs": ["2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2", "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB", "3 0 3\n0", "1 2 4\n12\n257866589 PS/2\n246883568 USB\n104396128 USB\n99...
UNKNOWN
PYTHON3
CODEFORCES
42
ddec47bec5554b2e632d663d5064df4e
Sea Battle
Galya is playing one-dimensional Sea Battle on a 1<=×<=*n* grid. In this game *a* ships are placed on the grid. Each of the ships consists of *b* consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after ea...
[ "# Why do we fall ? So we can learn to pick ourselves up.\r\n\r\n\r\nfrom itertools import groupby\r\nn,a,b,k = map(int,input().split())\r\ns = input()\r\nsg = [list(g) for s,g in groupby(s)]\r\nll = 0\r\nhits = []\r\nfor i in range(0,len(sg)):\r\n if sg[i][0] == '0' and len(sg[i]) >= b:\r\n for hit in ra...
{"inputs": ["5 1 2 1\n00100", "13 3 2 3\n1000000010001", "1 1 1 0\n0", "2 2 1 0\n00", "5 4 1 0\n00000", "10 2 2 0\n0000000000", "20 1 3 5\n01001010000000010010", "100 17 4 11\n0100000100000000000000001000000000010001100000000000101000000000000000000000001000001000010000000000"], "outputs": ["2\n2 5 ", "2\n3 5 ", "1\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
28
ddecee6a7da306e0f17ed95f4412dcba
Prime Problem
In Berland prime numbers are fashionable — the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays! Yet even this is not enough to make the Berland people happy. On the...
[ "# primes below sum(1,...,6000)\r\nprimes = [2]\r\nfor i in range(3, 190000, 2):\r\n isPrime = True\r\n for k in primes:\r\n if k * k > i:\r\n break\r\n if i % k == 0:\r\n isPrime = False\r\n break\r\n if isPrime: primes.append(i)\r\ndef is_prime(a):\r\n if...
{"inputs": ["8", "2", "3", "4", "5", "6", "7", "8", "9", "10", "23", "233", "1009", "2009", "4009", "4509", "2539", "5000", "4999", "4997", "5997", "5998", "5999", "6000", "11", "2109", "4890", "4356", "1075", "169", "5792", "2244", "2757", "3769", "3789", "3510", "962", "1834", "5544", "5558", "1005", "3904", "4691", ...
UNKNOWN
PYTHON3
CODEFORCES
1
ddf9a9ecc2e1e7a99780d4ed3a38540f
Shortest Path Queries
You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). There are three types of queries you ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u << 20 ^ v\r\n\r\ndef unite(s, t, w):\r\n while s ^ root[s]:\r\n w ^= d[s]\r\n s = root[s]\r\n while t ^ root[t]:\r\n w ^= d[t]\r\n t = root[t]\r\n if s == t:\r...
{"inputs": ["5 5\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 5 1\n5\n3 1 5\n1 1 3 1\n3 1 5\n2 1 5\n3 1 5"], "outputs": ["1\n1\n2"]}
UNKNOWN
PYTHON3
CODEFORCES
1
de1be60077eb96d5bef6f2b195c6890c
Dreamoon and Stairs
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? The single line contains two space separated integ...
[ "n,m = map(int,input().split())\r\nans = 0\r\nif m>n:\r\n ans = -1\r\nelse:\r\n if n%2 == 0:\r\n ans = n//2\r\n else:\r\n ans = n//2+1\r\n\r\n while ans%m != 0:\r\n ans+=1\r\n\r\nprint(ans)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn, m = map(int, input().split())...
{"inputs": ["10 2", "3 5", "29 7", "2 2", "1 2", "10000 2", "10000 3", "10000 10", "9999 3", "9999 2", "9999 10", "9999 9", "18 10", "19 10", "20 10", "21 10", "7688 5", "4608 5", "3979 2", "9985 6", "3230 8", "24 9", "3275 8", "6240 7", "5227 4", "3832 6", "4 2", "6 3", "10 5", "3 2", "6 4", "5 2", "8 2", "9 9", "4 5"...
UNKNOWN
PYTHON3
CODEFORCES
261
de529027519466567e75557d762da495
Magic Spheres
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,...
[ "a,b,c = map(int, input().split())\nx,y,z = map(int, input().split())\nextra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2\nneed = max(0, x-a) + max(0, y-b) + max(0, z-c)\nprint(\"Yes\" if need<=extra else \"No\")\n\n", "a=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\np=0\r\nk=0\r\nfo...
{"inputs": ["4 4 0\n2 1 2", "5 6 1\n2 7 2", "3 3 3\n2 2 2", "0 0 0\n0 0 0", "0 0 0\n0 0 1", "0 1 0\n0 0 0", "1 0 0\n1 0 0", "2 2 1\n1 1 2", "1 3 1\n2 1 1", "1000000 1000000 1000000\n1000000 1000000 1000000", "1000000 500000 500000\n0 750000 750000", "500000 1000000 500000\n750001 0 750000", "499999 500000 1000000\n7500...
UNKNOWN
PYTHON3
CODEFORCES
131
de6126ca010eecf21706ad036f0b3f16
PolandBall and White-Red graph
PolandBall has an undirected simple graph consisting of *n* vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: whi...
[ "\r\ndef PolandBall(n, k):\r\n # condiciones que no cumplen con los requisitos\r\n if n < 4 or k > 3 or k == 1 or (k == 2 and n == 4):\r\n print('-1')\r\n return\r\n\r\n # si k=2\r\n if k == 2:\r\n print(n-1)\r\n for i in range(1, n):\r\n print(str(i)+' '+str(i+1))...
{"inputs": ["4 1", "5 2", "500 3", "1000 2", "10 2", "590 3", "1000 5", "5 3", "100 49", "4 2", "4 3", "5 4", "5 1", "7 2", "1000 1", "1000 3", "1000 4", "999 1", "999 2", "999 3", "999 4", "999 5", "8 2", "9 2", "6 3", "7 3", "8 3", "9 3", "10 3", "527 2", "218 2", "565 2", "11 2", "237 2", "107 2", "494 2", "40 2", "...
UNKNOWN
PYTHON3
CODEFORCES
2
de8e21fefe42129a166a2cb60fb65d72
none
Group of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four nanobots, placed on a surface of a plate, can run a powerful chain reaction under certain conditions. To be precise, researchers introd...
[ "import sys\nsys.stderr = sys.stdout\n\nfrom collections import namedtuple\n\nBot = namedtuple('Bot', ('x', 'y', 'i'))\n\n\ndef yxi(bot):\n return bot.y, bot.x, bot.i\n\n\ndef reaction1(B, V):\n Bv = sorted(B[i] for i in range(4) if V[i])\n Bh = sorted((B[i] for i in range(4) if not V[i]), key=yxi)\n S ...
{"inputs": ["2\n1 1\n1 -1\n-1 1\n-1 -1\n1 1\n2 2\n4 4\n6 6", "1\n31 85\n9 49\n52 57\n11 85", "1\n183 65\n100 121\n138 31\n81 31", "1\n152 76\n152 112\n118 17\n83 129", "1\n54 42\n41 32\n83 57\n83 28", "1\n41 153\n-6 153\n112 92\n6 83", "1\n78 92\n98 10\n40 -17\n122 112", "1\n97 85\n108 10\n24 91\n29 10", "1\n3 0\n5 0\n...
UNKNOWN
PYTHON3
CODEFORCES
1
de907226bd55c2ddee0d451765d2e50c
Ralph and Mushrooms
Ralph is going to collect mushrooms in the Mushroom Forest. There are *m* directed paths connecting *n* trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantas...
[ "import sys\r\nimport math\r\nfrom collections import defaultdict\r\n\r\nclass TarjanSolver:\r\n def __init__(self):\r\n self.b = None\r\n self.dfn = None\r\n self.low = None\r\n self.s = None\r\n self.v = None\r\n self.r = None\r\n self.a = None\r\n self.o...
{"inputs": ["2 2\n1 2 4\n2 1 4\n1", "3 3\n1 2 4\n2 3 3\n1 3 8\n1", "1 0\n1"], "outputs": ["16", "8", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
2
de95ee4db2f47d9dd85262de180228c9
Olympic Medal
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/...
[ "import math\r\nx = list(map(int, input().split()))\r\ny = list(map(int, input().split()))\r\nz = list(map(int, input().split()))\r\nA, B = map(int, input().split())\r\ncalc = (B*max(y[1:])*(max(x[1:]))**2)/((A*min(z[1:]))+B*max(y[1:]))\r\nprint(math.sqrt(calc))\r\n\r\n", "import math\nr = list(map(int, input().s...
{"inputs": ["3 1 2 3\n1 2\n3 3 2 1\n1 2", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "1 5\n1 3\n1 7\n515 892", "2 3 2\n3 2 3 1\n2 2 1\n733 883", "2 4 2\n3 1 2 3\n2 2 3\n676 769", "2 4 2\n3 2 3 1\n2 3 1\n772 833", "2 1 2\n3 2 3 1\n2 1 3\n452 219", "2 3 2\n3 3 2 1\n2 3 2\n417 202", "2 1 2\n3 1 2 3\n2 3 2\n596 206", "2 1 2\n3 3 1...
UNKNOWN
PYTHON3
CODEFORCES
111
deed43691dc1ca42f8825b9adbcbbdef
Dense Subsequence
You are given a string *s*, consisting of lowercase English letters, and the integer *m*. One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nm = int(input())\r\ns = [0] + list(input().rstrip())\r\nn = len(s) - 1\r\nu = [[] for _ in range(130)]\r\nfor i in range(1, n + 1):\r\n u[s[i]].append(i)\r\nx = [0] * (n + 1)\r\nfor i in range(97, 123):\r\n for j in u[i...
{"inputs": ["3\ncbabc", "2\nabcab", "3\nbcabcbaccba", "5\nimmaydobun", "5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzknetdibv", "10\nefispvmzuutsrpxzfrykhabznxiyquwvhwhrksrgzodtuepfvamilfdynapzhzyhncorhzuewrrkcduvuhwsrprjrmgctnvrdtpj", "20\nhlicqhxayiodyephxlfoetfketnaa...
UNKNOWN
PYTHON3
CODEFORCES
7
df24cb0120d4b4002bc23bc05b50de93
Cloud of Hashtags
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashta...
[ "n = int(input())\r\nhash_tags = []\r\nfor i in range(n):\r\n hash_tag = input()\r\n hash_tags.append(hash_tag)\r\n \r\nfor j in range(n - 1, 0, -1):\r\n first_tag = hash_tags[j - 1]\r\n second_tag = hash_tags[j]\r\n flag = True\r\n for i in range(1, min(len(first_tag), len(second_tag))):\r\n ...
{"inputs": ["3\n#book\n#bigtown\n#big", "3\n#book\n#cool\n#cold", "4\n#car\n#cart\n#art\n#at", "3\n#apple\n#apple\n#fruit", "1\n#h", "2\n#y\n#q", "3\n#sima\n#simb\n#sima", "1\n#lxqnqdnkpeayhxh", "6\n#abu\n#abc\n#ac\n#bk\n#bmm\n#bb", "7\n#a\n#aab\n#abc\n#abq\n#ab\n#ac\n#z", "15\n#a\n#a\n#b\n#c\n#e\n#i\n#k\n#m\n#o\n#r\n#...
UNKNOWN
PYTHON3
CODEFORCES
21
df35371b016a964a5bd7dcf6fa8d0ecd
Dome
The input contains a single floating-point number *x* with exactly 6 decimal places (0<=&lt;<=*x*<=&lt;<=5). Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If several solutions exist, output any of them. Solution will exist for all tests. Sample Input 1.200000 2.57...
[ "import sys\r\nx = float(sys.stdin.readline())\r\ndiff = x\r\nfor a in range(1, 11):\r\n for h in range(1, 11):\r\n t = pow((a*a*h*h)/(a*a+4*h*h), 0.5)\r\n if diff > abs(x - t):\r\n diff = abs(x-t)\r\n ans_a = a\r\n ans_h = h\r\nprint(ans_a, ans_h)\r\n", "import m...
{"inputs": ["1.200000", "2.572479", "4.024922", "0.447214", "0.493197", "0.496139", "0.498273", "0.499026", "0.499230", "0.499376", "0.832050", "0.894427", "0.948683", "0.976187", "0.986394", "0.989949", "0.993884", "1.404494", "1.483405", "1.561738", "1.736486", "1.920553", "1.923048", "1.940285", "2.121320", "2.27777...
UNKNOWN
PYTHON3
CODEFORCES
7
df7bd7b4c72c71c76502c093a86fd21f
Optical Experiment
Professor Phunsuk Wangdu has performed some experiments on rays. The setup for *n* rays is as follows. There is a rectangular box having exactly *n* holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from ...
[ "import sys\nfrom collections import deque\nfrom bisect import bisect_left\n\n# INPUT\nN, UP, DOWN = 0, [], []\n# OUTPUT\nresult = 1\n\ndef read_input():\n global N, UP, DOWN\n readline = sys.stdin.readline\n N = int(readline().rstrip())\n UP = [int(w) for w in readline().split()]\n DOWN = [int(w) fo...
{"inputs": ["5\n1 4 5 2 3\n3 4 2 1 5", "3\n3 1 2\n2 3 1", "5\n1 2 4 5 3\n1 5 4 2 3", "3\n3 1 2\n1 3 2", "7\n1 5 2 7 4 3 6\n6 3 1 2 5 4 7", "4\n1 4 2 3\n2 3 1 4", "4\n2 4 1 3\n2 3 1 4", "10\n4 7 8 1 2 3 5 9 6 10\n6 3 8 7 10 2 1 4 5 9", "7\n1 5 7 2 4 3 6\n3 2 5 7 6 1 4", "9\n1 7 4 9 3 8 2 5 6\n8 4 7 1 3 2 9 6 5", "5\n1 4...
UNKNOWN
PYTHON3
CODEFORCES
3
df928cfd18ea2303b90a1ab6e9203bda
Nastya and a Game
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that , where *p* is the product of all integers on the given array, *s* is their sum, and *k* is a given constant for...
[ "n, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nfrom itertools import accumulate\r\nC = [0]+A\r\nC = list(accumulate(C))\r\nA = [0]+A\r\nP = [0]*(n+1)\r\nx = 0\r\n# P[i]: iの直前にある2以上の項のindex\r\nfor i in range(1, n+1):\r\n P[i] = x\r\n if A[i] > 1:\r\n x = i\r\nINF = 2*10**18+...
{"inputs": ["1 1\n1", "4 2\n6 3 8 1", "94 58\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 58 1 1 1 29 58 58 1 1 29 1 1 1 1 2 1 58 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 29 1 1 1 1 1 58 1 29 1 1 1 1 1 1 1 1 1 1 1 1 58 1 1 1 1 1 2 1 1 1", "6 76\n1 38 1 1 1 1", "16 53\n53 1 1 1 1 1 53 1 1 1 1 1 1 1 1 1", "13 16\...
UNKNOWN
PYTHON3
CODEFORCES
5
df97b5535fa90dfe37d6d91ebf948021
Brand New Easy Problem
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's probl...
[ "import itertools\n\n\ndef count_inversions(enumerate_seq):\n tmp = list(enumerate_seq[:])\n result = 0\n for i in range(len(tmp)):\n for j in range(len(tmp) - 1):\n if tmp[j][0] > tmp[j + 1][0]:\n result += 1\n tmp[j], tmp[j + 1] = tmp[j + 1], tmp[j]\n re...
{"inputs": ["4\nfind the next palindrome\n1\n10 find the previous palindrome or print better luck next time", "3\nadd two numbers\n3\n1 add\n2 two two\n3 numbers numbers numbers", "4\nthese papers are formulas\n3\n6 what are these formulas and papers\n5 papers are driving me crazy\n4 crazy into the night", "3\nadd two ...
UNKNOWN
PYTHON3
CODEFORCES
1
df9a647d53279e1dac6634dddd5e6756
Timofey and a tree
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes ...
[ "n = int(input())\r\nu = []\r\nv = []\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n u.append(a)\r\n v.append(b)\r\n \r\nc = [0] + [int(x) for x in input().split()]\r\n \r\ne = 0\r\ndic = {}\r\n \r\nfor i in range(1, n+1):\r\n dic[i] = 0\r\n \r\ndef plus(dic, n):\r\n if n in dic:\r\...
{"inputs": ["4\n1 2\n2 3\n3 4\n1 2 1 1", "3\n1 2\n2 3\n1 2 3", "4\n1 2\n2 3\n3 4\n1 2 1 2", "3\n2 1\n2 3\n1 2 3", "4\n1 2\n2 4\n4 3\n1 1 3 2", "2\n1 2\n1 1", "10\n5 7\n4 5\n10 2\n3 6\n1 2\n3 4\n8 5\n4 9\n2 3\n15 15 15 15 5 15 26 18 15 15", "8\n1 2\n1 3\n3 5\n3 6\n1 4\n4 7\n4 8\n1 3 1 1 1 1 1 2", "3\n2 1\n2 3\n4 4 4", "...
UNKNOWN
PYTHON3
CODEFORCES
42
df9c6cd618727a365f261b12f93c16e7
Three Logos
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e...
[ "import sys\ninput = sys.stdin.readline\nimport math\n\ndef read_int():\n return int(input())\n\ndef read_ints():\n return map(int, input().split())\n\ndef read_int_list():\n return [int(i) for i in input().split()]\n\ndef read_string():\n return input().strip()\n\nx1, y1, x2, y2, x3, y3 = read_ints()\n...
{"inputs": ["5 1 2 5 5 2", "4 4 2 6 4 2", "1 3 1 3 3 1", "2 4 1 4 1 4", "7 2 7 2 7 3", "1 10 6 10 3 10", "20 1 20 1 18 20", "75 31 69 100 25 31", "6 23 23 12 5 23", "40 12 2 40 26 40", "3 49 1 49 49 45", "56 6 35 56 15 56", "70 6 70 62 70 2", "80 65 80 12 3 80", "90 20 54 90 90 16", "75 100 19 100 6 100", "17 100 100 2...
UNKNOWN
PYTHON3
CODEFORCES
4
dfce938d392bea22ed9c82eaa6a4d150
none
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given *n* points in the plane, find a pair of points betwe...
[ "n,k=map(int, input().split())\nif(n*(n-1)//2 <=k):\n\tprint('no solution')\nelse:\n\tfor i in range(n):\n\t\tprint(0,i)", "r= lambda x:(x*(x+1))//2\r\na,b=map(int,input().split())\r\nif r(a-1)<=b:exit(print(\"no solution\"))\r\nfor i in range(a):print(0,0+i)", "n, k = [int(x) for x in input().split()]\r\nif n ...
{"inputs": ["4 3", "2 100", "5 6", "8 20", "6 15", "1808 505823289", "1850 507001807", "1892 948371814", "1788 94774524", "1947 944738707", "1989 367830", "1885 1096142", "1854 631695", "1750 215129", "1792 341122", "1834 1680860", "1657 1371995", "1699 1442450", "1595 1271214", "2000 1998999", "2000 1000000000", "2 1"...
UNKNOWN
PYTHON3
CODEFORCES
20