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
82d5d3e126087dd42f8f9e7919edf755
Line to Cashier
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
[ "class CodeforcesTask408ASolution:\r\n def __init__(self):\r\n self.result = ''\r\n self.cash_count = 0\r\n self.client_cashwise = []\r\n self.baskets = []\r\n\r\n def read_input(self):\r\n self.cash_count = int(input())\r\n self.client_cashwise = [int(x) for x in inp...
{"inputs": ["1\n1\n1", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3", "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7 9 6 5",...
UNKNOWN
PYTHON3
CODEFORCES
356
82e4d503992da73823380c942016218f
Three Base Stations
The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the *x**i* coordinate. The village consists of *n* houses, the *i*-th house is located in the point with coordinates of *x**i*. TELE3, a cellular communication provider ...
[ "#!/usr/bin/env\tpython\n#-*-coding:utf-8 -*-\nn=int(input())\nX=sorted(map(int,input().split()))\ni=1-n\nj=n-2\ns=0\nn=X[j]-X[i]\nwhile s<n:\n\tl,r=X[i]-X[0],X[-1]-X[j]\n\tif l<r:\n\t\tif n<=l:\n\t\t\ts=n\n\t\t\tbreak\n\t\ti+=1\n\t\ts=l\n\telse:\n\t\tif n<=r:\n\t\t\ts=n\n\t\t\tbreak\n\t\tj-=1\n\t\ts=r\n\tn=X[j]-X[...
{"inputs": ["4\n1 2 3 4", "3\n10 20 30", "5\n10003 10004 10001 10002 1", "1\n1", "2\n1 1", "9\n9 8 7 6 5 4 3 2 1", "2\n2 2", "3\n2 1 2", "4\n6 6 8 3", "5\n18 80 86 18 51", "10\n26 21 20 91 22 28 92 62 47 69", "4\n70 20 94 30", "3\n8 8 8", "2\n12 38", "7\n36 15 36 29 11 38 38", "5\n9 6 15 6 10", "1\n8", "2\n8 12", "3\n3...
UNKNOWN
PYTHON3
CODEFORCES
4
82ee089a14af73326406db1448d794ff
Football
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
[ "line = input()\nans = \"NO\"\n\nfor i in range(len(line) - 6):\n if line[i: i + 7].count('0') == 7 or line[i: i + 7].count('1') == 7:\n ans = \"YES\"\n break\nprint(ans)\n", "'''A. Football'''\r\nn = input()\r\nx=0\r\nif '1111111' in n or '0000000' in n:\r\n print('YES')\r\nelse:\r\n print...
{"inputs": ["001001", "1000000001", "00100110111111101", "11110111111111111", "01", "10100101", "1010010100000000010", "101010101", "000000000100000000000110101100000", "100001000000110101100000", "100001000011010110000", "010", "10101011111111111111111111111100", "1001101100", "1001101010", "1111100111", "001101100011...
UNKNOWN
PYTHON3
CODEFORCES
880
82ffce87fe11c128652285a581fb9b47
Drinks
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
[ "n=int(input())\r\nx=input()\r\nnum=x.split(\" \")\r\nsum=0\r\nfor m in num:\r\n sum+=int(m)\r\n\r\nprint(sum/n)", "x = int(input())\r\ny = (input())\r\nz = y.split(' ')\r\ns = 0\r\nfor j in z:\r\n\ts += int(j)\r\n# for i in y:\r\n# \ts += int(i)\r\nprint (s/x)", "n=int(input())\r\nprint(sum(list(map(int,inp...
{"inputs": ["3\n50 50 100", "4\n0 25 50 75", "3\n0 1 8", "5\n96 89 93 95 70", "7\n62 41 78 4 38 39 75", "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "29\n84 99 72 96 83 92 95 98 97 ...
UNKNOWN
PYTHON3
CODEFORCES
1,064
8342d9ba17f6a37a5b5912b897f44355
Lucky Tickets
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a...
[ "a = [0] * 3\r\n_ = input()\r\nfor n in map(int, input().split()):\r\n a[n % 3] += 1\r\n\r\nprint(a[0] // 2 + min(a[1], a[2]))", "input()\r\ntickets = [int(i) for i in input().split()]\r\ntickets1 = []\r\ntickets2 = []\r\ntickets3 = []\r\nfor k in tickets:\r\n if k % 3 == 0:\r\n tickets3.append(k)\r\...
{"inputs": ["3\n123 123 99", "6\n1 1 1 23 10 3", "3\n43440907 58238452 82582355", "4\n31450303 81222872 67526764 17516401", "5\n83280 20492640 21552119 7655071 47966344", "6\n94861402 89285133 30745405 41537407 90189008 83594323", "7\n95136773 99982752 97528336 79027944 96847471 96928960 89423004", "1\n19938466", "2\n5...
UNKNOWN
PYTHON3
CODEFORCES
51
8349f6da202ade7b78d88bc6bfcd1ba8
Anton and Fairy Tale
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\n\r\n\r\nif m >= n:\r\n print(n)\r\n exit()\r\n\r\nl, h = m+1, n+1\r\n\r\nwhile l < h:\r\n mi = (l+h)//2\r\n x = mi-m-1\r\n c = (1+x)*x//2\r\n if n-mi > c:\r\n l = mi + 1\r\n else:\r\n h = mi\r\npr...
{"inputs": ["5 2", "8 1", "32 5", "1024 1024", "58044 52909", "996478063 658866858", "570441179141911871 511467058318039545", "1 1", "1000000000000000000 1000000000000000000", "1000000000000000000 999999999999997145", "1 1000000000000000000", "1000000000000000000 1", "999999998765257149 10", "999999998765257150 10", "9...
UNKNOWN
PYTHON3
CODEFORCES
5
836531ed000ab9717afb7fee73310986
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
[ "def f():\r\n t = []\r\n for i in range(8):\r\n p = input()\r\n for j in range(8):\r\n if p[j] == 'K': t += [i, j]\r\n if t[2] - t[0] in (0, 4) and t[1] - t[3] in (-4, 0, 4): return 'YES'\r\n return 'NO'\r\nfor i in range(int(input()) - 1):\r\n print(f())\r\n input()\r\npr...
{"inputs": ["2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "3\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n####K#K#\n\n........\nK......K\n........\n#......#\n.#....#.\n..###...
UNKNOWN
PYTHON3
CODEFORCES
13
83779125e360c0f88aa14c07c743b788
The Wall (hard)
So many wall designs to choose from! Even modulo 106<=+<=3, it's an enormous number. Given that recently Heidi acquired an unlimited supply of bricks, her choices are endless! She really needs to do something to narrow them down. Heidi is quick to come up with criteria for a useful wall: - In a useful wall, at least...
[ "mod = 10 ** 6 + 3\r\n\r\ndef prod(a, b):\r\n return [[sum([a[i][k] * b[k][j] for k in range(len(b))]) % mod for j in range(len(b[0]))] for i in range(len(a))]\r\n\r\nc, w, h = map(int, input().split())\r\n\r\na = [[0] * (w + 1) for _ in range(w + 1)]\r\nfor i in range(w):\r\n a[i][i + 1] = 1\r\n \r\nfor c...
{"inputs": ["1 1 1", "1 2 2", "1 2 3", "3 2 2", "5 4 9", "40 37 65", "100000000 100 100", "99999999 97 99", "100000000 1 100", "100000000 100 1", "100000000 1 1", "13 66 38", "13 66 57", "13 66 76", "13 66 95", "13 99 38", "13 99 57", "13 99 76", "13 99 95", "85714284 66 76", "85714284 66 95", "85714284 99 76", "857142...
UNKNOWN
PYTHON3
CODEFORCES
1
83864a1e87e1a3b2c1a1a3d603379ad0
Card Game
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want. To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ...
[ "slv = {'6':0, '7':1, '8':2, '9':3, 'T':4, 'J':5, 'Q':6, 'K':7, 'A':8}\r\nkozyr = input()\r\ncard1, card2 = input().split()\r\n\r\nval1 = card1 [0]\r\nmast1 = card1 [1]\r\n\r\nval2 = card2 [0]\r\nmast2 = card2 [1]\r\n\r\nif mast1 == mast2:\r\n if slv[val1] > slv [val2]:\r\n print ('YES')\r\n else:\r\n ...
{"inputs": ["H\nQH 9S", "S\n8D 6D", "C\n7H AS", "C\nKC 9C", "D\n7D KD", "H\n7H KD", "D\nAS AH", "H\nKH KS", "C\n9H 6C", "C\n9H JC", "D\nTD JD", "H\n6S 7S", "D\n7S 8S", "S\n8H 9H", "C\n9D TD", "H\nTC JC", "C\nJH QH", "H\nQD KD", "D\nKS AS", "S\nAH 6H", "H\n7D 6D", "S\n8H 7H", "D\n9S 8S", "S\nTC 9C", "H\nJS TS", "S\nQD J...
UNKNOWN
PYTHON3
CODEFORCES
119
83971be6bedcf3ef74de89eaa3c3fd4f
ZgukistringZ
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one. GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Subst...
[ "from collections import Counter\nfrom copy import deepcopy\n\ndef getMax(c1, c2):\n ret = 1 << 32\n for k in c2.keys():\n ret = min(ret, c1[k]//c2[k])\n return ret\n\na, b, c = input(), input(), input()\ncounterA, counterB, counterC = Counter(a), Counter(b), Counter(c)\n\ncntB, cntC = 0, getMax(cou...
{"inputs": ["aaa\na\nb", "pozdravstaklenidodiri\nniste\ndobri", "abbbaaccca\nab\naca", "lemigazalemiolemilicomzalemljenje\nlemi\nzlo", "xxxbbbcccoca\nca\ncb", "aleksandrehteosidatedodam\nevo\nsi", "cumurcumur\num\ncur", "saljivdzijasamjaneki\nneki\nja", "lebronnojameslebronprogrammers\nje\nbro", "lukavpastaakojelukav\n...
UNKNOWN
PYTHON3
CODEFORCES
15
839a326aaf591e7fbcb6196222397274
Party
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure. At each step he selects...
[ "from collections import defaultdict\r\n#get the inputs, split and turn to int\r\nn,m=map(int,input().split())\r\ndef count(x):\r\n c=0\r\n while x > 0:\r\n c+=1\r\n x = x & (x - 1)\r\n return c\r\n \r\n#create a dictionary\r\ng=defaultdict(list)\r\n\r\n#run m times the number of times a user...
{"inputs": ["5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5", "4 4\n1 2\n1 3\n1 4\n3 4", "1 0", "2 1\n2 1", "3 2\n1 3\n2 3", "22 31\n5 11\n6 3\n10 1\n18 20\n3 21\n12 10\n15 19\n1 17\n17 18\n2 21\n21 7\n2 15\n3 2\n19 6\n2 19\n13 16\n21 19\n13 5\n19 3\n12 22\n9 20\n14 11\n15 21\n7 8\n2 6\n15 6\n6 21\n15 3\n4 22\n14 8\n16 9", "22 36\n...
UNKNOWN
PYTHON3
CODEFORCES
2
83a372c034fbb5f2b404ab2b3fb81eb4
Fox and Box Accumulation
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box...
[ "n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nh = [0] * 101 \r\nfor i in range(n):\r\n for j in range(101):\r\n if(a[i] >= h[j]):\r\n h[j] += 1 \r\n break\r\n\r\nc = 101 - h.count(0)\r\nprint(c)\r\n ", "n=int(input())\r\na=list(map(int,input().s...
{"inputs": ["3\n0 0 10", "5\n0 1 2 3 4", "4\n0 0 0 0", "9\n0 1 0 2 0 1 1 2 10", "1\n0", "2\n0 0", "2\n0 1", "2\n100 99", "9\n0 1 1 0 2 0 3 45 4", "10\n1 1 1 1 2 2 2 2 2 2", "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ...
UNKNOWN
PYTHON3
CODEFORCES
131
83a8455c279507ddbd012d7953b13774
Bill Total Value
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "*name*1*price*1*name*2*price*2...*name**n**price**n*", where *name**i* (name of th...
[ "from typing import Tuple, List\r\n\r\n\r\ndef parse_prices(s: str) -> List[str]:\r\n \"\"\"\r\n Парсинг всех прайсов из входных данных\r\n :param s: Входные данные, пример: 'a13.32b0.31c1.111.08'\r\n :return: Массив из price'ов, пример: ['13.32', '0.31', '1.111.08']\r\n \"\"\"\r\n\r\n s: s...
{"inputs": ["chipsy48.32televizor12.390", "a1b2c3.38", "aa0.01t0.03", "test0.50test0.50", "a500b500", "tcjbjlbtjf329.910", "iwpcfsmzen297.618.42ff585.209.84", "dpinb27.277fwxpdbfg709.917vocemjru16.491ade860.722tvb870.469.51wrpgy565.046gddrwv202.271.28", "vayscqiwpc686.919.75bwyudkz759.174kgqq444.563.54feupje806.486.78v...
UNKNOWN
PYTHON3
CODEFORCES
5
83f28d9be0614e982868c126897fb64e
Cycle In Maze
The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is emp...
[ "from collections import deque\r\n\r\nn, m, k = map(int, input().split())\r\nif k % 2 != 0:\r\n print(\"IMPOSSIBLE\")\r\n exit()\r\ngrid = [[] for _ in range(n)]\r\nsr, sc = -1, -1 # starting row and column\r\nfor r in range(n):\r\n grid[r] = input()\r\n c = grid[r].find('X')\r\n if c != -1:\r\n ...
{"inputs": ["2 3 2\n.**\nX..", "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "3 3 4\n***\n*X*\n***", "1 1 1\nX", "1 2 2\nX.", "1 5 4\n.X**.", "1 10 1\n........X.", "1 20 10\n*.*..............*.X", "2 1 1\nX\n.", "2 2 2\nX*\n.*", "2 5 2\n.....\n*.*.X", "2 10 4\n******....\n*.****.*X*", "2 20 26\n.****..*.**.**.*.......
UNKNOWN
PYTHON3
CODEFORCES
2
83f5f45e8eab08931e16ddeb28420b18
GCD Table
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={...
[ "import math as ma\r\nimport sys\r\ninput=sys.stdin.readline\r\n\r\ndef fu(b):\r\n for i in b:\r\n if b[i]!=0:\r\n return i\r\n return -1\r\n\r\ndef gcd(a,b):\r\n if a%b==0:\r\n return b\r\n else:\r\n return gcd(b,a%b)\r\n\r\nn=int(input())\r\na=list(map(int,input().split...
{"inputs": ["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1", "2\n54748096 1 641009859 1", "3\n1 7 923264237 374288891 7 524125987 1 1 1", "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "5\n...
UNKNOWN
PYTHON3
CODEFORCES
52
83f7d2cee6458359e3b27ec171ad250c
GukiZ and Contest
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
[ "wwe=int(input())\r\ns=list(map(int,input().split()))\r\np=sorted(s,reverse=True)\r\nk={}\r\nfor i in s:\r\n if i in k:\r\n print(k[i],end=' ')\r\n else:\r\n for j in range(len(p)):\r\n if p[j]==i:\r\n print(j+1,end=' ')\r\n ...
{"inputs": ["3\n1 3 3", "1\n1", "5\n3 5 3 4 5", "7\n1 3 5 4 2 2 1", "11\n5 6 4 2 9 7 6 6 6 6 7", "1\n2000", "2\n2000 2000", "3\n500 501 502", "10\n105 106 1 1 1 11 1000 999 1000 999", "6\n1 2 3 4 5 6", "7\n6 5 4 3 2 1 1", "8\n153 100 87 14 10 8 6 5", "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 5...
UNKNOWN
PYTHON3
CODEFORCES
667
83fe6169fa7fac345ddf7b7d2caff627
Load Balancing
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server. In order to balance the load for each server, you want to reassign some tasks to make the differe...
[ "'''\r\n7\r\n10 11 10 11 10 11 11\r\n'''\r\nn = int(input())\r\na = list(map(int,input().split()))\r\n\r\ns= sum(a)\r\n\r\na.sort(reverse=True)\r\nout = [s//n]*n\r\nrem = s%n\r\nfor i in range(rem):\r\n out[i]+=1\r\nres = 0\r\nfor i in range(n):\r\n res+=abs(a[i]-out[i])\r\nprint (res//2)\r\n", "imp...
{"inputs": ["2\n1 6", "7\n10 11 10 11 10 11 11", "5\n1 2 3 4 5", "10\n0 0 0 0 0 0 0 0 0 0", "1\n0", "1\n20000", "3\n1 10000 20000", "10\n19999 19999 20000 20000 19999 20000 20000 20000 19999 19999", "10\n8 5 5 5 6 6 6 6 5 5", "2\n10 3", "5\n6 5 9 7 6", "5\n2 10 20 30 50", "7\n2 2 2 2 2 3 4"], "outputs": ["2", "0", "3",...
UNKNOWN
PYTHON3
CODEFORCES
64
843b8ddbf88ea9a774a44e936780d7b5
Arrays
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. The first line contai...
[ "n,m=map(int,input().split())\r\na,b=map(int,input().split())\r\narr1=list(map(int,input().split()))\r\narr2=list(map(int,input().split()))\r\ni=0\r\nj=0\r\nwhile(i<n and j<m and i<a):\r\n if(arr1[i]<arr2[j]):\r\n i+=1\r\n else:\r\n j+=1\r\nif(i<a or m-j<b):\r\n print(\"NO\")\r\nelse:\r\n ...
{"inputs": ["3 3\n2 1\n1 2 3\n3 4 5", "3 3\n3 3\n1 2 3\n3 4 5", "5 2\n3 1\n1 1 1 1 1\n2 2", "3 5\n1 1\n5 5 5\n5 5 5 5 5", "1 1\n1 1\n1\n1", "3 3\n1 1\n1 2 3\n1 2 3", "3 3\n1 2\n1 2 3\n1 2 3", "3 3\n2 2\n1 2 3\n1 2 3", "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "10 15\n1 15\n...
UNKNOWN
PYTHON3
CODEFORCES
381
84638ad2b8ecfc61e5c49b99e7a47d5b
Cinema
Overall there are *m* actors in Berland. Each actor has a personal identifier — an integer from 1 to *m* (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has *k* favorite actors. He watched the movie trailers for the next month and wrote the following informat...
[ "import sys\n \nf = open(\"input.txt\")\ng = open(\"output.txt\", \"w\")\nm, k = map(int, f.readline().strip().split())\nv = frozenset(map(int, f.readline().strip().split()))\nn = int(f.readline().strip())\n \nx = []\n \nfor _ in range(n):\n f.readline().strip()\n f.readline().strip()\n info = [0, 0, 0] # ...
{"inputs": ["5 3\n1 2 3\n6\nfirstfilm\n3\n0 0 0\nsecondfilm\n4\n0 0 4 5\nthirdfilm\n1\n2\nfourthfilm\n1\n5\nfifthfilm\n1\n4\nsixthfilm\n2\n1 0", "5 3\n1 3 5\n4\njumanji\n3\n0 0 0\ntheeagle\n5\n1 2 3 4 0\nmatrix\n3\n2 4 0\nsourcecode\n2\n2 4", "10 1\n1\n4\na\n1\n3\nb\n1\n4\nc\n1\n5\nd\n1\n2", "2 1\n1\n2\na\n1\n2\nb\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
10
8469dddf318b05524edbda28b5a9bcfa
Sereja ans Anagrams
Sereja has two sequences *a* and *b* and number *p*. Sequence *a* consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Similarly, sequence *b* consists of *m* integers *b*1,<=*b*2,<=...,<=*b**m*. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions *q* (*q*<=+<=(*m*<=-<=1)·*p*<=...
[ "# import sys, io, os\n# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\nfrom collections import defaultdict,Counter\n\ndef solve(n,m,p,a,b):\n ans=[]\n cb=Counter(b)\n for q in range(min(p,n-(m-1)*p)):\n arr = [a[i] for i in range(q,n,p)]\n lb=len(cb.keys())\n cnt=cb.cop...
{"inputs": ["5 3 1\n1 2 3 2 1\n1 2 3", "6 3 2\n1 3 2 2 3 1\n1 2 3", "68 16 3\n5 3 4 3 3 3 2 2 2 3 2 4 2 2 2 2 4 3 5 1 1 2 2 2 3 1 5 1 2 2 1 5 1 5 3 2 3 5 2 1 1 4 2 3 4 3 4 3 3 1 3 4 1 5 2 5 3 4 4 1 4 5 5 1 1 2 2 2\n5 4 4 3 5 1 1 2 3 2 2 1 3 3 2 2", "44 11 4\n4 3 3 3 4 3 4 5 1 3 4 2 4 4 2 2 1 5 3 1 5 2 3 2 4 4 5 3 2 2 2...
UNKNOWN
PYTHON3
CODEFORCES
3
8480e73bfbab69837dd4c9ed947c982c
Minimum number of steps
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<...
[ "import math as m\r\nt=1\r\n#t=int(input())\r\nmod=10**9+7\r\nwhile t:\r\n t-=1\r\n s=input()\r\n ans,cost=0,0\r\n for i in range(len(s)):\r\n if s[i]=='a':\r\n cost=(cost*2+1)%mod\r\n else :\r\n ans+=cost\r\n print(ans%mod)\r\n", "new_seq = list(input())\nnew_bs...
{"inputs": ["ab", "aab", "aaaaabaabababaaaaaba", "abaabaaabbabaabab", "abbaa", "abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb", "aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba", "aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb", "aaabaaaabbababbaabbababbbbaaaaaaabbabbba", "abbbbababbabbbbbaba...
UNKNOWN
PYTHON3
CODEFORCES
132
84a1ec15b35327250779bfbc7b9c9430
Non-square Equation
Let's consider equation: where *x*,<=*n* are positive integers, *s*(*x*) is the function, equal to the sum of digits of number *x* in the decimal number system. You are given an integer *n*, find the smallest positive integer root of equation *x*, or else determine that there are no such roots. A single line contains...
[ "def dsum(n):\r\n m = 0\r\n while n>0:\r\n m += n%10\r\n n //= 10\r\n return m\r\n\r\ndef bs(s,n):\r\n l,r=0,int(1e9)\r\n while l<=r:\r\n m = (l+r)//2\r\n nn = m*(m+s)\r\n if nn==n: return m\r\n if nn>n: r = m-1\r\n if nn<n: l = m+1\r\n return...
{"inputs": ["2", "110", "4", "8", "10000000100000000", "10000006999999929", "172541340", "172580744", "10000100000", "1000001000000", "100000010000000", "425", "1085", "4296409065", "9211004165221796", "1245131330556680", "40000000400000000", "90000000900000000", "160000001600000000", "250000002500000000", "36000000360...
UNKNOWN
PYTHON3
CODEFORCES
21
84a5a2ed7fa8dc2da713daa96a556173
Inna, Dima and Song
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the *i*-th note at ...
[ "q=lambda:map(int,input().split())\r\nn,=q()\r\na=list(q())\r\nb=list(q())\r\nc=0\r\nfor i,j in zip(a,b):\r\n if j==1:\r\n c-=1\r\n elif i*2>=j:\r\n c+=((j//2)*(j-(j//2)))\r\n else:\r\n c-=1\r\nprint(c)", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().s...
{"inputs": ["3\n1 1 2\n2 2 3", "1\n2\n5", "10\n2 2 3 4 5 6 7 8 9 10\n2 2 3 4 5 6 7 8 9 10", "10\n1 2 3 4 5 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "3\n10000 10000 10000\n5000 5000 1", "2\n1 1\n2 1"], "outputs": ["4", "-1", "96", "94", "12499999", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
13
84f6356702ad0c9612055335da1b33e8
Almost Difference
Let's denote a function You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*. The second line contai...
[ "n = int(input())\r\narr = [int(x) for x in input().split()]\r\ncnt = {0 : 0}\r\nans = 0\r\npref = [0] * n\r\nfor i in range(0, n):\r\n ans += arr[i] * i\r\n if i > 0:\r\n ans -= pref[i - 1]\r\n pref[i] += pref[i - 1]\r\n if arr[i] + 1 in cnt:\r\n ans += cnt[arr[i] + 1]\r\n if arr[i] - 1 in c...
{"inputs": ["5\n1 2 3 1 3", "4\n6 6 5 5", "4\n6 6 4 4", "1\n1", "1\n1000000000", "2\n1 1000000000", "5\n1 999999996 999999998 999999994 1000000000", "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 ...
UNKNOWN
PYTHON3
CODEFORCES
116
8502ae13f38ef5bda917a038126041ce
Xor-sequences
You are given *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n*. A sequence of integers *x*1,<=<=*x*2,<=<=...,<=<=*x**k* is called a "xor-sequence" if for every 1<=<=≤<=<=*i*<=<=≤<=<=*k*<=-<=1 the number of ones in the binary representation of the number *x**i* *x**i*<=<=+<=<=1's is a multiple of 3 and for all 1<=≤<=*i*...
[ "mod=10**9+7\r\n\r\ndef popcount(n):\r\n c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555)\r\n c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333)\r\n c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f)\r\n c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff)\r\n c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ff...
{"inputs": ["5 2\n15 1 2 4 8", "5 1\n15 1 2 4 8", "10 1\n44 65 23 44 100 19 19 23 19 40", "10 2\n93 93 85 48 44 98 93 100 98 98", "10 100\n22 0 41 63 22 41 17 22 15 42", "10 1000000000\n454240622 216977025 454240622 509843007 509843007 26552516 488949284 708817573 453191950 447767457", "100 576460752303423487\n0 0 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
2
851cdc37572844db5ff8db560c7a80ca
Contest
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
[ "# python 3\n\na, b, c, d = list(map(int, input().split()))\n\nMisha = max(3*a/10, a-a/250*c)\nVasya = max(3*b/10, b-b/250*d)\nif Misha > Vasya:\n print(\"Misha\")\nelif Misha < Vasya:\n print(\"Vasya\")\nelse:\n print(\"Tie\")\n", "x=list(map(int, input().split()))\r\na=x[0]\r\nb=x[1]\r\nc=x[2]\r\nd=x[3...
{"inputs": ["500 1000 20 30", "1000 1000 1 1", "1500 1000 176 177", "1500 1000 74 177", "750 2500 175 178", "750 1000 54 103", "2000 1250 176 130", "1250 1750 145 179", "2000 2000 176 179", "1500 1500 148 148", "2750 1750 134 147", "3250 250 175 173", "500 500 170 176", "250 1000 179 178", "3250 1000 160 138", "3000 20...
UNKNOWN
PYTHON3
CODEFORCES
553
852f4210021e60c31e87d025668e7b9b
Vitaliy and Pie
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ...
[ "n = int(input())\r\ns = input()\r\nD = dict()\r\nD_mins = dict()\r\nfor i in range(len(s)):\r\n if i % 2 == 0:\r\n if s[i] in D:\r\n D[s[i]] += 1\r\n else:\r\n D[s[i]] = 1\r\n\r\n if s[i] in D_mins:\r\n D_mins[s[i]] = min(D_mins[s[i]], D[s[i]])\r\n el...
{"inputs": ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ", "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "5\naArRaRaR", "2\ndA", "2\ncB", "10\nhNcMeXsSlHsUwYeMcA", "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZ...
UNKNOWN
PYTHON3
CODEFORCES
246
853497d6bbbf49820ca1f6a476d78703
Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are *n* cities in the kingdom, numbered from 1 to *n*. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally,...
[ "def main():\n n, m = map(int, input().split())\n n += 1\n cluster, dest, ab = list(range(n)), [0] * n, [[] for _ in range(n)]\n\n def root(x):\n if x != cluster[x]:\n cluster[x] = x = root(cluster[x])\n return x\n\n for _ in range(m):\n a, b = map(int, input().split()...
{"inputs": ["4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "3 6\n1 2\n1 3\n2 1\n2 3\n3 1\n3 2", "8 12\n6 1\n7 5\n2 5\n4 1\n6 3\n4 3\n5 7\n1 3\n5 2\n2 7\n4 6\n7 2", "2 1\n1 2", "10 4\n8 4\n9 8\n2 8\n8 1", "8 7\n6 3\n2 4\n3 7\n8 2\n4 8\n7 6\n3 2", "10 10\n10 6\n9...
UNKNOWN
PYTHON3
CODEFORCES
1
853733567b5c4563940cc2a07c2be496
Holidays
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. The first line of the input contains a positi...
[ "w,e=divmod(int(input()),7)\nprint(w*2+int(e==6),w*2+min(e,2))\n", "n=int(input())\r\n\r\ndic={1:[0,1],2:[0,2],3:[0,2],4:[0,2],5:[0,2],6:[1,2],7:[2,2]}\r\nif n%7==0:\r\n temp=n//7\r\n print(temp*2,temp*2)\r\nelse:\r\n if n>7:\r\n a=n//7\r\n ma=a*2+dic[n%7][1]\r\n mi=a*2+dic[n%7][0]\r...
{"inputs": ["14", "2", "1", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "1000000", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "100", "99", "98", "97", "96", "95", "94", "93", "92", "91", "90", "89", "88", "87", "86", "85", "84", "83", "82", "81", "80", "1000...
UNKNOWN
PYTHON3
CODEFORCES
131
855032e57951f02044cbcf81b424f300
Seating of Students
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with *n* rows and *m*...
[ "import random\r\nn, m = map(int, input().split())\r\nif n < 4 and m < 4 and not((n == 1 and m == 1) or (m == 3 and n == 3)): print(\"NO\"); quit()\r\npedy = [list() for i in range(n * m + 1)]\r\nfor i in range(n * m):\r\n if i % m != 0: pedy[i+1].append(i)\r\n if i % m != m - 1: pedy[i + 1].append(i + 2)\r\n...
{"inputs": ["2 4", "2 1", "1 1", "1 2", "1 3", "2 2", "2 3", "3 1", "3 2", "3 3", "1 4", "4 1", "4 2", "1 100000", "100000 1", "316 316", "315 316", "316 315", "315 315", "100 1000", "1000 100", "10 10000", "10000 10", "100 1", "1 100", "100 2", "2 100", "100 3", "3 100", "100 4", "4 100", "101 1", "1 101", "101 2", "2...
UNKNOWN
PYTHON3
CODEFORCES
3
85596ef8043e36b06fa4d003d852efc2
Sets
Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose *n* non-empty sets in such a way, that no two of them have common elements. One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possib...
[ "#Med_Neji\r\n#x,y=map( lambda x:int(x)//abs(int(x)) ,input().split())\r\n#x,y=map(int,input().split())\r\n#n=int(input())\r\n#l=list(map(int,input().split()))\r\n#s=input()\r\n#x=0\r\nn=int(input())\r\nl = [(set(input().split()[1:])) for _ in range(n*(n-1)//2)]\r\nif n==2:\r\n l=list(l[0])\r\n print(1,l[0...
{"inputs": ["4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "3\n2 1 2\n2 1 3\n2 2 3", "3\n2 1 2\n10 1 90 80 70 60 50 40 30 20 10\n10 2 10 20 30 40 50 60 70 80 90", "4\n4 56 44 53 43\n3 109 44 43\n3 109 56 53\n3 43 62 44\n3 62 56 53\n2 109...
UNKNOWN
PYTHON3
CODEFORCES
5
855ca95248a5bfd9520047e02b8110e6
Scarborough Fair
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
[ "n, m = map(int, input().rstrip().split())\r\ns=list(input())\r\nfor i in range(m):\r\n l, r, c1,c2 = map(str,input().rstrip().split())\r\n for j in range(int(l)-1,int(r)):\r\n if s[j]==c1:\r\n s[j]=c2\r\nprint(\"\".join(s))", "a = list(map(int,input().split()))\r\nn = a[0]\r\nm = a[1]\r\n...
{"inputs": ["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3...
UNKNOWN
PYTHON3
CODEFORCES
476
8567369105f3e809e62c03d1c311d0cd
Serial Time!
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is t...
[ "(k, n, m) = map(int, input().split())\r\na = []\r\nfor i in range(k):\r\n s = input()\r\n a.append([])\r\n for j in range(n):\r\n a[-1].append(list(input()))\r\ns = input()\r\n(x, y) = map(int, input().split())\r\nx -= 1\r\ny -= 1\r\n\r\nstart = (0, x, y)\r\nsosed = set()\r\nsosed.add(start)\r\npos...
{"inputs": ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1", "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1", "4 7 8\n\n........\n........\n........\n........\n........\n........\n.........
UNKNOWN
PYTHON3
CODEFORCES
43
85793c04d5569f7c730e40f2446a5307
Writing a Song
One of the Hedgehog and his friend's favorite entertainments is to take some sentence or a song and replace half of the words (sometimes even all of them) with each other's names. The friend's birthday is approaching and the Hedgehog decided to make a special present to his friend: a very long song, where his name wil...
[ "n, k = map(int, input().split())\r\np = input()\r\na = input()\r\nres = ['0'] * n\r\n \r\ndef m(tmp):\r\n return chr(ord('a') + k // 2) if tmp == 'a' else 'a'\r\n \r\nfor i in range(len(a)):\r\n if a[i] == '1':\r\n l = i\r\n for j in range(len(p)):\r\n res[l] = p[j]\r\n ...
{"inputs": ["5 2\naba\n101", "5 2\na\n10001", "6 2\nabba\n101", "12 5\nabacaba\n010001", "9 3\nac\n10100101", "19 2\naababaaba\n10000100001", "5 2\naaa\n101", "10 2\naaa\n11000111", "15 2\naaa\n0000000000111", "20 2\naba\n001000000000000000", "10 2\naabb\n0000000", "15 2\naabb\n010000000100", "20 2\nabbb\n0000000000010...
UNKNOWN
PYTHON3
CODEFORCES
1
857b3fe7b4bcc1427ca1e7b6f66dfde4
Chilly Willy
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous...
[ "n=210\r\nk=int(input())\r\nif (k<=2): print(-1)\r\nelse: print(n*((10**(k-1))//n+1))", "n=int(input())\r\nif(n<=2):\r\n print (-1)\r\nelse:\r\n print (((pow(10,n-1)//210)+1)*210)", "n=int(input())\r\n\r\nif n<3:\r\n print(-1)\r\nelse:\r\n k=int(pow(10,n-1))\r\n l=k+210-(k%210)\r\n print(l)\r\...
{"inputs": ["1", "5", "6", "4", "15", "16", "17", "7", "120", "8", "3", "2", "9", "10", "11", "12", "13", "14", "100000", "99999", "99998", "99997", "99996", "99995", "99994", "99993", "99992", "99991", "99990", "99989", "99988", "99987", "99988", "99987", "99986", "10000", "5000", "5001", "5002", "121", "122", "123", ...
UNKNOWN
PYTHON3
CODEFORCES
137
85b83a877cca38028c1baed68103d7b7
Spongebob and Squares
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly *x* distinct squares in the table consisting of *n* rows and *m* columns. For example, in a 3<=×<=5 table there are 15 squares with side one, 8 squares with si...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nx = int(input())\r\nn, u, v = 1, 0, 0\r\nz = []\r\nwhile True:\r\n a, b = u - n * n, -n * u + v - x\r\n if a * n < b:\r\n break\r\n if not b % a:\r\n m = b // a\r\n z.append((n, m))\r\n u += n...
{"inputs": ["26", "2", "8", "1", "5005", "17284", "151618", "360700", "500500500", "200200", "800800", "200000800200", "999999999999999999", "128593726482159", "50044422", "18", "30", "20", "649708734844", "649030984", "333333333", "5050505060", "1000000000000000000", "18270000000000", "10102030405090000", "50004000222...
UNKNOWN
PYTHON3
CODEFORCES
5
85c1e0800313be21370c1a51af05aa89
String Problem
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary ch...
[ "import math\r\nimport random \r\nimport time\r\nfrom decimal import *\r\nfrom collections import defaultdict\r\nfrom bisect import bisect_left as lower_bound\r\nfrom bisect import bisect_right as upper_bound\r\n\r\n\r\nimport sys,threading\r\n#sys.setrecursionlimit(5*(10**5)+2)\r\n#threading.stack_size(99000000)\r...
{"inputs": ["uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "a\nb\n3\na b 2\na b 3\nb a 5", "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0", "xhtuopq\nrtutbz\n10\nh x 10\nx d 3\nr u 4\nu d 1\nt o 100\no t 7\np e 1\ne f 1\nb f 2\nz q 19", "abad\nabad\n6\na c 3\nb x 100\nd e 7\nr r 10\no t 17\na a 4", "bbad\nabxd\n4\nb a ...
UNKNOWN
PYTHON3
CODEFORCES
3
85c72846a552ae1e070a07f77d2c6f4a
Diverse Permutation
Permutation *p* is an ordered set of integers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*. Your task is to find such permutation *p* of length *n*, that the group of number...
[ "n, k = map(int, input().split())\r\ncur = 1\r\nx = 0\r\na = [0] * (n + 1)\r\nwhile k > 0:\r\n a[cur] = 1\r\n print(cur, end=(' '))\r\n if x == 0:\r\n cur = cur + k\r\n x = 1\r\n else:\r\n cur = cur - k\r\n x = 0\r\n k = k - 1\r\nfor i in range(1, n + 1):\r\n if a[i] ==...
{"inputs": ["3 2", "3 1", "5 2", "5 4", "10 4", "10 3", "10 9", "100000 99999", "99999 99998", "42273 29958", "29857 9843", "27687 4031", "25517 1767", "23347 20494", "10931 8824", "98514 26178", "6591 407", "94174 30132", "92004 85348", "59221 29504", "2 1", "4 1", "4 2", "100000 1", "99999 1", "99998 2", "99999 5000"...
UNKNOWN
PYTHON3
CODEFORCES
103
85eec64b53510690a189a65c7bf24c65
Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\na1=a.count(a[0])\r\na2=a.count(a[-1])\r\nif a[0]==a[-1]:\r\n c=n*(n-1)//2\r\nelse:\r\n c=a1*a2\r\nprint(a[-1]-a[0],c)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nif len(set(a)) == 1:\r\n print(0,n*(n-1)//2)\r\nelse...
{"inputs": ["2\n1 2", "3\n1 4 5", "5\n3 1 2 3 1", "2\n1 1", "3\n1 1 1", "4\n1 1 1 1", "5\n1 1 1 1 1", "5\n2 2 2 2 2", "10\n2 2 2 2 2 2 2 2 2 2", "3\n2 2 2", "3\n3 3 3", "2\n10000000 100000000", "5\n5 5 5 5 5", "5\n3 3 3 3 3", "6\n1 1 1 1 1 1", "2\n5 6", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1000000000 1000000000 1000000000 1...
UNKNOWN
PYTHON3
CODEFORCES
135
85f0c3dca52d0319e2f5851dc7cb4d59
Funny Game
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
[ "n=int(input())\r\na=list(map(int, input().split()))\r\np=s=sum(a)\r\nfor i in range(n-2, 0, -1):\r\n\ts-=a[i+1]\r\n\tp=max(p, s-p)\r\nprint(p)", "n = int(input())\na = [0]*(n+1)\ni = 1\nfor v in map(int, input().split()):\n a[i] = v\n i += 1\n \nfor i in range(1, n+1):\n a[i] = a[i-1]+a[i]\n\ndp = [-...
{"inputs": ["3\n2 4 8", "4\n1 -7 -2 3", "10\n35 11 35 28 48 25 2 43 23 10", "100\n437 89 481 95 29 326 10 304 97 414 52 46 106 181 385 173 337 148 437 133 52 136 86 250 289 61 480 314 166 69 275 486 117 129 353 412 382 469 290 479 388 231 7 462 247 432 488 146 466 422 369 336 148 460 418 356 303 149 421 146 233 224 432...
UNKNOWN
PYTHON3
CODEFORCES
3
85fe13c6ddb305a3920fa99f8970df6d
Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
[ "x = str(input())\r\ndef isnearlucky(x):\r\n count = 0\r\n for char in x:\r\n if char == \"4\" or char == \"7\":\r\n count += 1\r\n continue\r\n count = str(count)\r\n count = count.replace(\"4\",\"\")\r\n count = count.replace(\"7\",\"\")\r\n if len(count) == 0:\r\n ...
{"inputs": ["40047", "7747774", "1000000000000000000", "7", "4", "474404774", "4744000695826", "10000000004744744", "446486416781684178", "999999999", "7777", "87414417444", "111222333444555667", "1", "4700", "3794555488744477", "444444444444444444", "474447447774444774", "777777777777777", "34777745021000000", "963", ...
UNKNOWN
PYTHON3
CODEFORCES
483
8612e0f6e2ddc420a3b9875dd71b5f62
Set Theory
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for al...
[ "d = [-1] * 1000001\r\nfor t in range(int(input())):\r\n n, a = int(input()), list(map(int, input().split()))\r\n a.sort()\r\n for i in range(n):\r\n for j in range(i + 1, n): d[a[j] - a[i]] = t\r\n i = 1\r\n while any(d[i * j] == t for j in range(1, n)): i += 1\r\n print(\"YES\\n\" + ' '....
{"inputs": ["3\n3\n1 10 100\n1\n1\n2\n2 4", "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 51 7 33 80 83...
UNKNOWN
PYTHON3
CODEFORCES
9
8613f1b0afa3b8dfd3e8f7af9121480c
National Property
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
[ "# -*- coding: utf-8 -*-\n\n\n\nimport math\n\nimport collections\n\nimport bisect\n\nimport heapq\n\nimport time\n\nimport random\n\nimport itertools\n\n\n\n\"\"\"\n\ncreated by shhuan at 2017/10/18 16:22\n\n\n\n\"\"\"\n\n\n\nM, N = map(int, input().split())\n\n\n\nwords = []\n\nfor i in range(M):\n\n words.app...
{"inputs": ["4 3\n1 2\n1 1\n3 1 3 2\n2 1 1", "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4", "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1", "4 4\n3 3 4 1\n4 3 4 2 2\n4 2 1 2 3\n3 4 2 2", "3 5\n2 1 2\n2 1 5\n2 4 4", "2 1\n10 1 1 1 1 1 1 1 1 1 1\n25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10 3\n2 3 2\n1 3\n3 ...
UNKNOWN
PYTHON3
CODEFORCES
3
863575ab8345ae9d711a4048f919eb2e
Glass Carving
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular *w* mm <=×<= *h* mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to prac...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nw, h, n = map(int, input().split())\r\n\r\nl = [0, w]\r\nr = [0, h]\r\nd = []\r\nfor i in range(n):\r\n a, b = input()[:-1].split()\r\n b = int(b)\r\n l.append(b) if a == 'V' else r.append(b)\r\n d.append((a, b))\r\n\r\nl.sort()\r\nr.sort()\r\nd.rever...
{"inputs": ["4 3 4\nH 2\nV 2\nV 3\nV 1", "7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1", "2 2 1\nV 1", "2 2 1\nH 1", "2 2 2\nV 1\nH 1", "2 2 2\nH 1\nV 1", "10 10 10\nV 6\nH 8\nV 4\nV 8\nH 2\nH 5\nV 9\nH 7\nH 3\nV 7", "5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3", "15 5 10\nV 13\nV 10\nV 3\nH 2\nV 9\nV 7\nV 2\nH 1\nV 4...
UNKNOWN
PYTHON3
CODEFORCES
4
86712ff51baabd9cb0cad3df9de22aca
Arya and Bran
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ...
[ "n,k=map(int, input().split())\r\na=list(map(int, input().split())) \r\nfor i in range(n):\r\n c=min(k,a[i],8)\r\n if i!=n-1:\r\n a[i+1]+=a[i]-c\r\n k-=c\r\n if k==0:\r\n print(i+1)\r\n break\r\nelse:\r\n print(\"-1\")\r\n", "n,k = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nt,...
{"inputs": ["2 3\n1 2", "3 17\n10 10 10", "1 9\n10", "10 70\n6 5 2 3 3 2 1 4 3 2", "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 5...
UNKNOWN
PYTHON3
CODEFORCES
139
867538c2ec9791c52fc38b83949d76a7
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are *n* players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the *i*-th player contains *m**i* numbers. During the game the host t...
[ "def subset(s1,s2):\n\td={}\n\tfor i in s1:\n\t\td[i]=1\n\tflag=0\n\tfor i in s2:\n\t\tif i not in d:\n\t\t\tflag=1\n\t\t\tbreak\n\tif flag==0:\n\t\treturn True\n\telse:\n\t\treturn False\n\nn=int(input())\nl=[]\nfor i in range(n):\n\tl.append(list(map(int,input().split()))[1:])\nfor i in range(n):\n\tans='YES'\n\t...
{"inputs": ["3\n1 1\n3 2 4 1\n2 10 11", "2\n1 1\n1 1", "1\n1 1", "2\n1 2\n1 3", "2\n1 1\n2 1 2", "2\n2 1 2\n1 1", "2\n3 5 21 7\n6 15 5 100 21 7 17", "2\n6 15 5 100 21 7 17\n3 5 21 7", "10\n1 4\n1 2\n1 3\n1 5\n1 1\n1 4\n1 3\n1 5\n1 2\n1 1", "3\n1 1\n1 2\n1 1", "10\n3 2 3 4\n1 1\n1 1\n1 2\n1 3\n1 4\n1 1\n1 3\n2 4 5\n2 1 ...
UNKNOWN
PYTHON3
CODEFORCES
23
8676255daaf99564013bbc9970f823f2
Dividing Island
A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island. The island can be conventionally represented as two ...
[ "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\na, b, c, d, n = map(int, input().split())\r\nparty = list(map(int, input().split()))\r\nisland = [['.'] * (a + c) for _ in range(max(b, d))]\r\n\r\ni, j, ub, lb = (b - 1 ...
{"inputs": ["3 4 2 2 3\n5 8 3", "3 2 1 4 4\n1 2 3 4", "1 2 1 1 1\n3", "1 2 1 3 2\n3 2", "3 2 4 4 20\n1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "5 4 2 3 26\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "11 5 4 13 5\n18 21 22 23 23", "1 13 1 14 7\n4 5 5 4 4 3 2", "15 1 1 25 6\n3 14 7 7 5 4", "20 30 40 50 1\n2600...
UNKNOWN
PYTHON3
CODEFORCES
3
86992df511c35724e491b550c53aaae0
Ice cream coloring
Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?" We have a tree *T* with *n* vertices and *m* types of ice cream numerated from 1 to *m*. Each vertex *i* has a set of *s**i* types of ice cream. Vertices whic...
[ "import sys\r\nfrom sys import stdin\r\nfrom collections import deque\r\n\r\nn,m = map(int,stdin.readline().split())\r\n\r\ns = []\r\n\r\nans1 = 0\r\n\r\nfor i in range(n):\r\n\r\n lis = list(map(int,stdin.readline().split()))[1:]\r\n s.append(lis)\r\n ans1 = max(ans1 , len(lis))\r\n\r\n\r\nlis = [ [] for ...
{"inputs": ["3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3", "4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3", "7 35\n3 17 20 32\n4 3 14 24 25\n4 4 10 17 26\n7 2 9 13 17 23 28 30\n9 1 2 7 8 13 16 18 33 35\n8 5 6 11 15 17 22 29 34\n5 12 19 21 27 31\n2 1\n3 1\n4 3\n5 4\n6 3\n7 4", "7 39\n7 5 10 15 27 31 33 39\n7 5 16 21 27 28 29 33\n3 15 26 ...
UNKNOWN
PYTHON3
CODEFORCES
1
8699b4e498214d26bc63282f383bc860
Game with Tokens
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*. The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or righ...
[ "#FB HACKERCUP\r\nimport os,sys,math\r\nfrom io import BytesIO, IOBase\r\n\r\nif sys.version_info[0] < 3:\r\n from _builtin_ import xrange as range\r\n from future_builtins import ascii, filter, hex, map, oct, zip\r\n\r\nfrom bisect import bisect_left as lower_bound, bisect_right as upper_bound \r\ndef so(): ...
{"inputs": ["4\n-2 -1\n0 1\n0 -3\n2 -1", "4\n-2 0\n-1 1\n0 -2\n1 -1", "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2", "1\n1 2", "4\n0 99999\n-99999 0\n99999 0\n0 -99999", "10\n-1 3\n-1 7\n-8 -4\n5 14\n-6 -7\n11 -8\n-11 0\n5 -1\n9 4\n-2 -14", "50\n-15 -80\n-80 21\n90 38\n-10...
UNKNOWN
PYTHON3
CODEFORCES
1
86a3244023545fd311c4e9765040d5ad
Case of Fugitive
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of *n* narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line...
[ "import sys\r\n# sys.setrecursionlimit(10**9)\r\n# import random\r\n# from collections import Counter, defaultdict, deque\r\n# from functools import lru_cache, reduce\r\n# from itertools import accumulate,product\r\nfrom heapq import nsmallest, nlargest, heapify, heappop, heappush\r\n# from bisect import bisect_lef...
{"inputs": ["4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8", "2 2\n11 14\n17 18\n2 9", "2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999", "5 10\n1 2\n3 3\n5 7\n11 13\n14 20\n9 10 2 9 10 4 9 9 9 10", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5", "6 9\n1 4\n10 18\n23 29\n33 43\n46 57\n59 77\n11 32 3...
UNKNOWN
PYTHON3
CODEFORCES
3
86bbcc5761032fc0723cc9aa7716bfc2
Four Divisors
If an integer *a* is divisible by another integer *b*, then *b* is called the divisor of *a*. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let’s define a function *D*(*n*) — number of integers between 1 and *n* (inclusive) which has exactly four positive divisors. Between 1 and 10 only the...
[ "def prime_pi(n):\r\n if n <= 1:\r\n return 0\r\n elif n <= 3:\r\n return 2\r\n v = int(n ** 0.5) - 1\r\n while v ** 2 <= n:\r\n v += 1\r\n v -= 1\r\n smalls = [(i + 1) // 2 for i in range(v + 1)]\r\n s = (v + 1) // 2\r\n roughs = [2 * i + 1 for i in range(s)]\r\n lar...
{"inputs": ["10", "20", "1", "27", "100", "1000", "10000", "100000", "1000000", "100000000", "1000000000", "10000000000", "100000000000", "353964", "437388", "553516", "636940", "753068", "803788", "24403439", "907519567", "790635695", "968719119", "146802543", "324885967", "448485", "324885968"], "outputs": ["3", "5",...
UNKNOWN
PYTHON3
CODEFORCES
3
86bc5ff4cc000d8c473eea68cc66405e
Gerald and Path
The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to illuminate this path ...
[ "import dataclasses\r\nimport sys\r\n\r\n\r\ninf = float('inf')\r\n\r\n# change stdout buffer size\r\nbuffer = open(1, 'w', 10**6)\r\n\r\n\r\n# fast printing function\r\ndef print(*args, sep=' ', end='\\n'):\r\n buffer.write(sep.join(str(arg) for arg in args) + end)\r\n\r\n\r\n# flush stdout\r\ndef flush():\r\n ...
{"inputs": ["3\n1 1\n2 2\n3 3", "4\n1 2\n3 3\n4 3\n6 2", "5\n3 3\n4 1\n2 2\n0 3\n9 5", "5\n3 3\n4 3\n6 4\n2 3\n1 5", "5\n1 2\n7 5\n9 4\n5 1\n3 5", "5\n7 2\n3 5\n2 4\n8 1\n9 5", "5\n7 1\n5 5\n1 4\n4 4\n2 2", "5\n9 5\n2 4\n3 3\n5 2\n1 1", "3\n0 3\n3 3\n6 3", "3\n0 3\n4 3\n7 3", "10\n78329099 25986078\n9003418 30942874\n3...
UNKNOWN
PYTHON3
CODEFORCES
2
86ce3ffc590e44c16fbff25c2821701e
A Piece of Cake
How to make a cake you'll never eat. Ingredients. - 2 carrots - 0 calories - 100 g chocolate spread - 1 pack of flour - 1 egg Method. 1. Put calories into the mixing bowl. 1. Take carrots from refrigerator. 1. Chop carrots. 1. Take chocolate spread from refrigerator. 1. Put chocolate spread into the mix...
[ "s = input().split()\r\nans = 0\r\npos = 0\r\nfor i in s:\r\n ans += int(i) * pos\r\n pos += 1; \r\nprint(ans)", "a = list(map(int, input().split()))\r\ns = 0\r\nfor i in range(len(a)):\r\n s += a[i] * i\r\nprint(s)\r\n", "\"\"\"==========================================================================...
{"inputs": ["4 1 2 3 4", "4 802 765 992 1", "4 220 380 729 969", "3 887 104 641", "12 378 724 582 387 583 241 294 159 198 653 369 418", "14 36 901 516 623 703 971 304 394 491 525 464 219 183 648", "3 287 979 395", "19 702 667 743 976 908 728 134 106 380 193 214 71 920 114 587 543 817 248 537", "11 739 752 364 649 626 7...
UNKNOWN
PYTHON3
CODEFORCES
34
86e9c457887ad23b21c89ed45b4524d1
Tetris
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. ...
[ "n,m=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nlst=[0]*(n+1)\r\nfor i in a:\r\n lst[i]+=1\r\nres=max(lst)\r\nfor i in range(1,n+1):\r\n if lst[i]<res:\r\n res=lst[i]\r\nprint(res)", "first_input = [int(x) for x in input().split()]\nn = first_input[0]\nm = first_input[1]\n\ns...
{"inputs": ["3 9\n1 1 2 2 2 3 1 2 3", "1 7\n1 1 1 1 1 1 1", "1 1\n1", "3 5\n1 1 1 2 3", "4 6\n4 4 4 4 4 4", "4 6\n2 3 4 4 4 4", "3 12\n1 1 1 1 2 2 2 2 3 3 3 3", "8 8\n2 2 3 4 5 6 7 8", "100 1\n50", "2 1\n2", "2 1\n1", "2 4\n1 2 1 1", "3 4\n3 2 2 2", "2 2\n2 2", "2 5\n2 1 1 2 1", "15 3\n13 14 15", "4 9\n1 2 3 1 2 3 1 2 ...
UNKNOWN
PYTHON3
CODEFORCES
225
86eadace39c4974d7855296691977d3a
Complete The Graph
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of...
[ "import heapq\r\nimport random\r\nimport sys\r\nfrom math import inf\r\nfrom types import GeneratorType\r\n\r\nRANDOM = random.randint(1, 10 ** 9)\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def read_str():\r\n return sys.stdin.readline()\r\n\r\n d...
{"inputs": ["5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "2 1 123456789 0 1\n0 1 0", "2 1 999999999 1 0\n0 1 1000000000", "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6", "100 1 123456 99 0\n0 99 123456", "1000 1 5 999 0\n0 999 0", "1000 1 1000000000 998 0\n0 999 0", "4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12", "4 4...
UNKNOWN
PYTHON3
CODEFORCES
6
86f346636148be5c88089eb977a30d94
Sum of Digits
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
[ "s=input()\r\nc=0\r\nwhile(len(s)>1):\r\n sum=0\r\n for i in s:\r\n sum+=int(i)\r\n s=str(sum)\r\n c+=1\r\nprint(c)", "from collections import Counter\ndef transform(s):\n c = Counter(s)\n val = 0\n for k in c:\n val += (ord(k)-ord('0'))*c[k]\n return str(val)\n\ns = input()\...
{"inputs": ["0", "10", "991", "99", "100", "123456789", "32", "86", "2", "8", "34", "13", "28", "23", "57", "29", "353869285", "549548646", "858893424", "644818852", "360322525", "122937520", "288403032", "677257481", "58059561", "211288847", "339900034079539584", "784084029310269952", "774730557264864000", "4782338071...
UNKNOWN
PYTHON3
CODEFORCES
734
870be526ad4079cf2e6c4b1dc17092df
Reconnaissance
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
[ "string = input().split(' ')\r\n\r\nn = int(string[0])\r\nd = int(string[1])\r\n\r\nheights = input().split(' ')\r\n\r\ntotal = 0\r\n\r\nfor i in range(n):\r\n for j in range(n):\r\n if i != j:\r\n if abs(int(heights[i])-int(heights[j])) <= d:\r\n total += 1\r\n\r\nprint(total)", "n, d =map( int ,...
{"inputs": ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55", "6 10\n4 6 4 1 9 3", "7 100\n19 1694 261 162 1 234 513", "8 42\n37 53 74 187 568 22 5 65", "10 4\n11 6 76 49 28 20 57 152 5 32", "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 22...
UNKNOWN
PYTHON3
CODEFORCES
264
87448a33bcad98078c557bcb497905c7
Infinite Sequence
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ...
[ "n=int(input())\r\n\r\ndef is_ok(mid):\r\n if mid*(mid+1)//2<n:\r\n return True\r\n else:\r\n return False\r\n \r\ndef binary_search(ng,ok):\r\n while abs(ng-ok)>1:\r\n mid=(ok+ng)//2\r\n if is_ok(mid):\r\n ok=mid\r\n else:\r\n ng=mid\r\n return ok\r\n\r\nm=binary_search(10**9,0)\r\npr...
{"inputs": ["3", "5", "10", "55", "56", "1000000000000", "847194127849", "294719472984", "999999911791", "999999911792", "100000000000000", "1", "99993", "99994", "99995", "99990", "2", "99991", "99992", "99996", "99997", "99998", "99999", "1021", "4", "23", "9994", "99939", "99999998250180", "6", "8", "35", "100", "10...
UNKNOWN
PYTHON3
CODEFORCES
164
87666ee7bb3f34a6210d448d76e7181e
Preorder Test
For his computer science class, Jacob builds a model tree with sticks and balls containing *n* nodes in the shape of a tree. Jacob has spent *a**i* minutes building the *i*-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough ...
[ "import sys\ninput = sys.stdin.readline\nn, k = map(int, input().split())\na = [int(i) for i in input().split()]\ng = [[] for _ in range(n)]\nfor i in range(n - 1):\n\tu, v = map(int, input().split())\n\tg[u-1].append(v-1)\n\tg[v-1].append(u-1)\n\nstack = [0]\ndone = [False] * n\npar = [0] * n\norder = []\nwhile le...
{"inputs": ["5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3", "4 2\n1 5 5 5\n1 2\n1 3\n1 4", "2 1\n1 100000\n2 1", "2 2\n1 1000000\n1 2", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8", "10 3\n703660 186846 317819 628672 74457 58472 247014 480113 252764 ...
UNKNOWN
PYTHON3
CODEFORCES
1
8790f27d226d7ec0ce3b1e544a70f2fc
Xor-MST
You are given a complete undirected graph with *n* vertices. A number *a**i* is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a**i*<=*xor*<=*a**j*. Calculate the weight of the minimum spanning tree in this graph. The first line contains *n* (1<=≤<=*n*<=≤<=200000) — the nu...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef insert(x, la):\r\n j = 0\r\n for i in p:\r\n if x & i:\r\n if not G[j] >> 25:\r\n la += 1\r\n G[j] ^= la << 25\r\n j = la\r\n else:\r\n ...
{"inputs": ["5\n1 2 3 4 5", "4\n1 2 3 4", "1\n1"], "outputs": ["8", "8", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
1
8795970e6387f383db66fbe5d5eb72ad
Candy Boxes
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {*x*1,<=*x*2,<=*x*3,<=*x*4} (*x*1<=≤<=*x*2<=≤<=*x*3<=≤<=*x*4) arithmetic mean is , median is and range is ...
[ "n = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\na = sorted(a)\n#print(a)\nif n == 0:\n print('YES')\n print(1)\n print(1)\n print(3)\n print(3)\nelif n == 1:\n print('YES')\n print(a[0])\n print(3 * a[0])\n print(3 * a[0])\nelif n == 2:\n if a[0] * 3 >= a[1]:...
{"inputs": ["2\n1\n1", "3\n1\n1\n1", "4\n1\n2\n2\n3", "0", "1\n125", "2\n472\n107", "3\n215\n137\n256", "4\n49\n464\n28\n118", "4\n172\n84\n252\n163", "2\n66\n135", "1\n190", "3\n184\n100\n71", "3\n361\n387\n130", "3\n146\n247\n182", "3\n132\n44\n126", "2\n172\n148", "3\n276\n311\n442", "3\n324\n301\n131", "4\n186\n129...
UNKNOWN
PYTHON3
CODEFORCES
11
87a54f067b31ebfad0da83002caa68eb
Colorful Graph
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*. Let's consider all vertices of the graph, that are painted some color *k*. Let...
[ "#parsea una línea\ndef parser():\n return [int(x) for x in input().split()] \n \n#Recibiendo n y m\nn,m=parser()\n#Recibiendo los colores de los vertices\ncolors_vertices=parser()\n\n#Hallando el mayor de los colores\nupper=max(colors_vertices)\n\n#Se crean una cantidad de sets igual al numero mayor\nadjac...
{"inputs": ["6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6", "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4", "3 1\n13 13 4\n1 2", "2 1\n500 300\n1 2", "6 5\n2 2 2 1 2 2\n4 5\n4 2\n5 2\n4 1\n2 3", "8 8\n3 3 2 3 3 3 1 3\n8 2\n6 3\n2 3\n2 6\n5 6\n4 2\n7 5\n1 6", "10 27\n1 1 3 2 4 1 3 2 4 1\n9 3\n7 8\n9 7\n6 5\n7 6\n7 4\n...
UNKNOWN
PYTHON3
CODEFORCES
16
87b26ff597826f7c8a05c6ccd32d831d
Parallel Programming
Polycarpus has a computer with *n* processors. Also, his computer has *n* memory cells. We'll consider the processors numbered by integers from 1 to *n* and that the memory cells are consecutively numbered by integers from 1 to *n*. Polycarpus needs to come up with a parallel program model. For each memory cell number...
[ "n, k = map(int, input().split())\r\na = [1 for i in range(n + 1)]\r\na[n] = 0\r\nfor iter in range(k):\r\n for i in range(1, n - 1):\r\n target = n - i\r\n if a[i + 1] > target - a[i]:\r\n # find right number\r\n target -= a[i]\r\n print(n - target, end=' ')\r\n ...
{"inputs": ["1 1", "3 2", "4 2", "2 1", "2 20", "1 20", "10000 20", "10 4", "10 5", "10 6", "128 7", "127 7", "129 8", "130 8", "131 8", "1024 10", "1024 11", "1023 10", "10000 14", "8192 13", "8190 13", "8192 14", "8123 13", "5000 13", "2000 11", "2198 14", "2512 12"], "outputs": ["1", "2 3 3\n3 3 3", "2 3 4 4\n3 4 4 ...
UNKNOWN
PYTHON3
CODEFORCES
2
87bd4ba8f7cee70856277e730dc4dac4
Lucky Numbers (easy)
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
[ "def luckyNumber(n):\r\n \r\n queue = []\r\n queue.append((0,0))\r\n \r\n while queue != []:\r\n pair = queue.pop(0)\r\n val = pair[0]\r\n c = pair[1]\r\n \r\n if c == 0 and val >= n:\r\n return val\r\n else:\r\n queue.append((val * 10 +...
{"inputs": ["4500", "47", "1", "12", "4587", "100", "1007", "99999999", "491020945", "1000000000", "777777", "99999999", "474", "85469", "7474747", "2145226", "5556585", "87584777", "77777777", "999999999", "74477744", "444444444", "467549754", "147474747", "555", "100000", "74777443", "4700007", "70070077", "123", "74...
UNKNOWN
PYTHON3
CODEFORCES
18
87cd06539720d164c8bb461f4a43badf
Olympiad in Programming and Sports
There are *n* students at Berland State University. Every student has two skills, each measured as a number: *a**i* — the programming skill and *b**i* — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to ta...
[ "#!/usr/bin/env python3\nfrom itertools import accumulate\nfrom heapq import heappop, heappush\n\n\ndef top(ppl_indices, vals, start):\n Q = []\n res = [0 for i in range(len(ppl_indices))]\n for k, idx in enumerate(ppl_indices):\n heappush(Q, -vals[idx])\n if k >= start:\n res[k] =...
{"inputs": ["5 2 2\n1 3 4 5 2\n5 3 2 1 4", "4 2 2\n10 8 8 3\n10 7 9 4", "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "2 1 1\n100 101\n1 100", "4 1 1\n100 100 1 50\n100 100 50 1", "2 1 1\n3 2\n3 2", "2 1 1\n9 6\n3 10", "2 1 1\n1 17\n5 20", "3 1 1\n5 4 2\n1 5 2", "3 1 1\n10 5 5\n9 1 4", "3 1 1\n17 6 2\n2 19 19", "4 1 2\n4 2 4 5\n3 2 5...
UNKNOWN
PYTHON3
CODEFORCES
1
87f45615ea3832b39e3e4fb9c33c420c
Vitaly and Cycle
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of *n* vertices and *m* edges, no...
[ "def read_data():\r\n n, m = map(int, input().split())\r\n Es = [[] for v in range(n)]\r\n for e in range(m):\r\n a, b = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n Es[a].append(b)\r\n Es[b].append(a)\r\n return n, m, Es\r\n\r\ndef solve(n, m, Es):\r\n if m ...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3", "3 3\n1 2\n2 3\n3 1", "3 0", "6 3\n1 2\n4 3\n6 5", "100000 0", "5 4\n1 2\n1 3\n1 4\n1 5", "6 3\n1 2\n2 3\n4 5", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "59139 0", "9859 0", "25987 0", "9411 0", "25539 0", "59139 1\n10301 5892", "9859 1\n1721 9478", "76259 0", "92387 0", "6 4\n1 2\n2 3\n3 ...
UNKNOWN
PYTHON3
CODEFORCES
4
87fa1fe92bd779cf0b2298740f0f708c
IQ test
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
[ "n=int(input())\r\nm=input().split()\r\njishu=0\r\noushu=0\r\nfor i in range(3):\r\n k=int(m[i])/2-int(m[i])//2\r\n if k==0:\r\n oushu+=1\r\n else:\r\n jishu+=1\r\nif jishu>oushu:\r\n for i in range(n):\r\n kt=int(m[i])/2-int(m[i])//2\r\n if kt==0:\r\n print(i+1)\r...
{"inputs": ["5\n2 4 7 8 10", "4\n1 2 1 1", "3\n1 2 2", "3\n100 99 100", "3\n5 3 2", "4\n43 28 1 91", "4\n75 13 94 77", "4\n97 8 27 3", "10\n95 51 12 91 85 3 1 31 25 7", "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 9...
UNKNOWN
PYTHON3
CODEFORCES
3,134
87fbfafa354e50b7c4f052a6f1671e69
Kostya the Sculptor
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has *n* stones which are rectang...
[ "n = int(input())\r\n\r\nINF = 10**10\r\nind = 0\r\nans = 0\r\ntemp = 0\r\na = []\r\nd = dict()\r\n\r\nS = sorted([sorted(list(map(int, input().split())) , reverse = True) + [i + 1] for i in range(n)], reverse = True)\r\n\r\n\r\nans = S[0][2]\r\na = [S[0][-1]]\r\n\r\nfor i in range(1, n):\r\n if S[i][0] == S[i-1...
{"inputs": ["6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "1\n1 1 1", "2\n2 3 1\n2 2 3", "1\n1000000000 1000000000 1000000000", "3\n100 100 100\n25 63 11\n63 15 11", "2\n999999999 1000000000 1000000000\n1000000000 1000000000 1000000000", "3\n1 1 2\n1 2 2\n1 1 1"...
UNKNOWN
PYTHON3
CODEFORCES
23
880524f2cab75c03474a3bd4b45b4390
Months and Years
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. ...
[ "a1 = '31 28 31 30 31 30 31 31 30 31 30 31 '\r\na2 = '31 29 31 30 31 30 31 31 30 31 30 31 '\r\ns = a1+a1+a1+a2+a1+a1\r\nt = int(input())\r\na = input().strip()\r\nans = 'NO'\r\nif a in s:\r\n ans = 'YES'\r\nprint(ans)", "import sys\n\n\ndef readlines(type=int):\n return list(map(type, sys.stdin.readline().s...
{"inputs": ["4\n31 31 30 31", "2\n30 30", "5\n29 31 30 31 30", "3\n31 28 30", "3\n31 31 28", "24\n29 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "4\n31 29 31 30", "24\n31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31", "8\n31 29 31 30 31 30 31 31", "1\n29", "8\n31 29 31...
UNKNOWN
PYTHON3
CODEFORCES
94
88133b86e2c023a0f6539769a94a9b40
Nastya and an Array
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
[ "n = int(input())\r\ns = [int(i) for i in input().split() if int(i) != 0]\r\nprint(len(set(s)))", "n=int(input())\nli=list(map(int,input().split()))\nli.sort()\nif(len(set(li))==1 and li[0]!=0):\n\tprint(1)\nelif(len(set(li))==1 and li[0]==0):\n\tprint(0)\nelse:\n\tc=0\n\tfor i in set(li):\n\t\tif i!=0:\n\t\t\tc=...
{"inputs": ["5\n1 1 1 1 1", "3\n2 0 -1", "4\n5 -6 -5 1", "1\n0", "2\n21794 -79194", "3\n-63526 95085 -5239", "3\n0 53372 -20572", "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899", "5\n806 0 1308 1954 683", "8\n-26 0 -249 -289 -126 -206 288 -11", "10\n2 2 2 1 2 -1 0 2 -1 1", "1\n...
UNKNOWN
PYTHON3
CODEFORCES
398
881a96925d078b4a047e5ae1de94811c
Tennis Tournament
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 ...
[ "n,b,p = map(int,input().split())\r\nprint((n-1)*(2*b+1),n*p)", "#Justin Hershberger\r\n#Py3.5\r\n\r\nimport fileinput\r\n\r\ndef test():\r\n\tpass\r\nif __name__ == '__main__':\r\n\tnum_args = 1\r\n\tfor arg in range(num_args):\r\n\t\tn,b,p = map(int, input().split())\r\n\r\n\t#m is the number of participants of...
{"inputs": ["5 2 3", "8 2 4", "10 1 500", "20 500 1", "100 123 99", "500 1 1", "500 500 500", "500 237 474", "1 2 3", "1 2 133", "1 2 100", "1 3 4", "1 10 15", "1 1 1", "1 2 5", "1 500 500", "1 3 8", "10 10 10", "1 3 5", "1 2 1", "1 2 4", "1 10 10", "1 345 345", "7 12 13", "1 500 1", "1 12 13", "1 500 499", "1 100 90",...
UNKNOWN
PYTHON3
CODEFORCES
206
881c7f55aadf15000b9369d6a844f275
Special Offer! Super Price 999 Bourles!
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors. Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, ...
[ "from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\nfrom bisect import bisect_right, bisect_left\nfrom fractions import Fraction as frac\nimport math\nhpop = heappop\nhpush = heappush\nMOD = 10**9 + 7\n\ndef calc(x):\n d_sum = sum(map(int,str(x)))\n ...
{"inputs": ["1029 102", "27191 17", "1 0", "9 0", "20 1", "100 23", "10281 1", "2111 21", "3021 112", "1000000000000000000 999999999999999999", "29287101 301", "302918113 8113", "23483247283432 47283432", "47283432 7283432", "7283432 7283431", "2304324853947 5853947", "2485348653485 123483", "29845435345 34543", "23487...
UNKNOWN
PYTHON3
CODEFORCES
25
88266cf22d8ea93df609d6d5f1431549
Hyperdrive
In a far away galaxy there are *n* inhabited planets, numbered with numbers from 1 to *n*. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, *n*<=-<=1 spa...
[ "import sys\nfrom math import sqrt, inf\nfrom functools import cache\n\n\nreadline = sys.stdin.readline\n\nplanets = []\n\ndef read():\n N = int(readline().strip())\n for _ in range(N):\n planets.append(tuple([int(w) for w in readline().split()]))\n\ndef solve() -> float:\n @cache\n def dist(a: l...
{"inputs": ["4\n0 0 0\n0 0 1\n0 1 0\n1 0 0", "3\n5 -5 4\n-5 -4 2\n-1 1 2", "3\n28 -69 72\n-36 9 -49\n94 83 95", "4\n-7 -72 93\n-40 42 49\n31 76 -36\n-56 12 -1", "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7", "10\n-3461 4259 -7268\n9964 2370 6622\n4530 5607 -6609\n-3777 4888 6057\n-5403 7982 -651\n4828 -6712 ...
UNKNOWN
PYTHON3
CODEFORCES
3
8843d9cd7c335b57fabb3ef78d487be8
Computer Game
Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level: 1) The boss has t...
[ "n, max_val, reg = map(int, input().split())\r\npow_vals = [0] * (n + 1)\r\ndmg_vals = [0] * (n + 1)\r\nfor i in range(1, n + 1):\r\n pow_vals[i], dmg_vals[i] = map(int, input().split())\r\nused = [False] * (n + 1)\r\ncur = max_val\r\ntot = 0\r\nans = -1\r\nm = 0\r\na = [0] * (n + 1)\r\nb = [0] * (n + 1)\r\nfor ...
{"inputs": ["2 10 3\n100 3\n99 1", "2 100 10\n100 11\n90 9", "10 100 5\n61 3\n55 2\n12 6\n39 5\n21 10\n39 7\n16 1\n10 1\n70 5\n100 7", "20 1000 35\n10 6\n66 38\n81 11\n18 46\n80 54\n76 55\n100 7\n96 23\n24 37\n4 24\n4 50\n71 4\n83 15\n7 23\n100 44\n99 34\n100 17\n100 66\n23 15\n90 35", "20 1000 100\n49 26\n46 36\n1 114...
UNKNOWN
PYTHON3
CODEFORCES
2
88489b3c20b36851c8a0ae9fd612ebab
African Crossword
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
[ "n , m = map(int,input().split())\r\narr = []\r\n\r\nfor i in range(n):\r\n arr.append(input())\r\nres = list(zip(*arr)) \r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if arr[i].count(arr[i][j])==1:\r\n if res[j].count(arr[i][j])==1:\r\n print(arr[i][j],end=\"\")\r\n ...
{"inputs": ["3 3\ncba\nbcd\ncbc", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "4 4\nusah\nusha\nhasu\nsuha", "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe", "15 3\njhg\njkn\njui\nfth\no...
UNKNOWN
PYTHON3
CODEFORCES
262
884ce38c4e05ce1b7792e50f06613eae
Burning Midnight Oil
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin...
[ "def test(n,k):\n sumi = n \n i = 1\n while n >= k **i :\n sumi += n // k**i\n i+=1\n return sumi\n\nn,k = map(int,input().split())\nstart = 1\nend = n\nans = -1\nwhile start <= end :\n mid = (start +end) //2\n res = test(mid,k)\n if res < n :\n start = mid +1\n elif res >= n :\n ans = mid\n ...
{"inputs": ["7 2", "59 9", "1 9", "11 2", "747 2", "6578 2", "37212 2", "12357 2", "7998332 2", "86275251 2", "75584551 2", "6 3", "43 4", "811 3", "3410 4", "21341 4", "696485 4", "8856748 3", "2959379 4", "831410263 3", "2 5", "19 6", "715 7", "9122 5", "89117 6", "689973 7", "3024524 5", "67127156 6", "412262167 7",...
UNKNOWN
PYTHON3
CODEFORCES
171
884fb11aa9749ce2a54ec963e9036754
Find a car
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help. Form...
[ "mod = 1000000007\r\ndef sum(x,y,k,add) :\r\n if k<add:return 0\r\n up=x+add\r\n if up>k:up=k\r\n add=add+1\r\n return y*(((add+up)*(up-add+1)//2)%mod)%mod\r\ndef solve(x,y,k,add=0) :\r\n if x==0 or y==0:return 0\r\n if x>y:x,y=y,x\r\n pw = 1\r\n while (pw<<1)<=y:pw<<=1\r\n if pw<=x:re...
{"inputs": ["4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2", "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16", "10\n1 1 2 2 8\n3 4 5 9 4\n2 10 5 10 6\n8 5 10 8 8\n1 2 8 2 20\n8 6 10 8 20\n6 7 6 7 9\n8 5 10 10 13\n1 8 10 9 13\n9 8 10 9 3...
UNKNOWN
PYTHON3
CODEFORCES
1
88707b4cec2285331afee820a59c2935
Tennis Championship
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are st...
[ "n = int(input())\r\na, b = 1, 1\r\nans = 0\r\nwhile a + b <= n:\r\n a = a + b\r\n a, b = b, a\r\n ans += 1\r\nprint(ans)", "def main():\n n = int(input())\n a = b = r = 1\n while b <= n:\n a, b, r = b, a + b, r + 1\n print(r - 2)\n\n\nif __name__ == '__main__':\n main()\n", "def gam...
{"inputs": ["2", "3", "4", "10", "1000", "2500", "690000", "3000000000", "123456789123456789", "5", "143", "144", "145", "232", "233", "234", "679891637638612257", "679891637638612258", "679891637638612259", "1000000000000000000", "10235439547", "1240723548", "92353046212453", "192403205846532", "13925230525389", "1204...
UNKNOWN
PYTHON3
CODEFORCES
107
887f5c0fe1611ba2eb173a645088bda2
Vladik and cards
Vladik was bored on his way home and decided to play the following game. He took *n* cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions: - the number of oc...
[ "import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return (m + 1) * u + v\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nm = 8\r\nx = [[] for _ in range(m)]\r\nfor i in range(n):\r\n x[a[i] - 1].append(i)\r\ns = 0\r\n...
{"inputs": ["3\n1 1 1", "8\n8 7 6 5 4 3 2 1", "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8", "1\n8", "2\n5 4", "3\n3 3 2", "18\n3 6 6 8 8 1 1 4 4 3 3 5 5 7 7 2 2 3", "5\n2 6 1 2 6", "6\n4 3 1 6 7 4", "7\n8 8 2 6 1 8 5", "8\n2 8 4 7 5 3 6 1", "8\n8 6 3 6 7 5 5 3", "15\n5 2 2 7 5 2 6 4 3 8 1 8 4 2 7", "15\n8 8 1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
88833c580e1089eeff007f19c143dece
Pencils and Boxes
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n* of *n* integer numbers — saturation of the color of each pencil. Now Mis...
[ "n, k, d = map(int, input().split()) \r\nA = [0]*(n + 1)\r\nB = sorted(map(int, input().split()))\r\nfor i in range(1, n + 1):\r\n A[i] = B[i - 1]\r\nA.sort()\r\ndp = [0]*(n + 1)\r\ndp[0] = 1\r\ncnt= 0\r\nl=0\r\nfor i in range (k, n + 1):\r\n if dp[i - k] : cnt += 1\r\n while i - l + 1 > k and A[i]-A[l+1] ...
{"inputs": ["6 3 10\n7 2 7 7 4 2", "6 2 3\n4 5 3 13 4 10", "3 2 5\n10 16 22", "8 7 13\n52 85 14 52 92 33 80 85", "6 4 0\n1 3 2 4 2 1", "10 4 9\n47 53 33 48 35 51 18 47 33 11", "3 2 76\n44 5 93", "5 2 9\n3 8 9 14 20", "8 2 3\n1 2 3 4 10 11 12 13", "10 3 3\n1 1 2 4 5 6 9 10 11 12", "7 3 3\n1 1 3 4 4 4 7", "8 3 6\n1 2 3 3...
UNKNOWN
PYTHON3
CODEFORCES
10
888e5c0f86ce38c7eb6f2a5f40de8280
Sereja and Swaps
As usual, Sereja has array *a*, its elements are integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Let's introduce notation: A swap operation is the following sequence of actions: - choose two indexes *i*,<=*j* (*i*<=≠<=*j*); - perform assignments *tmp*<==<=*a*[*i*],<=*a*[*i*]<==<=*a*[*j*],<=*a*[*j*]<==<=*tmp*. What max...
[ "def solve(curr,other,k):\r\n t=0 \r\n while t<k and t<len(curr) and t<len(other) and other[t]>curr[t]:\r\n t+=1 \r\n return t\r\n\r\nn,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nmaxx=-10**100\r\nfor i in range(n):\r\n curr=[]\r\n other=sorted(arr[:i]+arr[i+1:],reverse...
{"inputs": ["10 2\n10 -1 2 2 2 2 2 2 -1 10", "5 10\n-1 -1 -1 -1 -1", "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466", "29 6\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7", "9 9\n-767 148 -323 -818 41 -22...
UNKNOWN
PYTHON3
CODEFORCES
19
8890a94989620c9df947b82ca957f018
Perfect Squares
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in ...
[ "\r\nn = int(input())\r\nl = sorted(list(map(int, input().split())))\r\n\r\nfor i in range(n - 1, -1, -1):\r\n\tkey = l[i]\r\n\tif key < 0:\r\n\t\tprint(key)\r\n\t\texit()\r\n\r\n\tif int(key ** 0.5) ** 2 != key:\r\n\t\tprint(key)\r\n\t\texit()", "from math import*\r\nn=int(input())\r\nl=set(map(int,input().split...
{"inputs": ["2\n4 2", "8\n1 2 4 8 16 32 64 576", "3\n-1 -4 -9", "5\n918375 169764 598796 76602 538757", "5\n804610 765625 2916 381050 93025", "5\n984065 842724 127449 525625 573049", "2\n226505 477482", "2\n370881 659345", "2\n4 5", "2\n3 4", "2\n999999 1000000", "3\n-1 -2 -3", "2\n-1000000 1000000", "2\n-1 0", "1\n2",...
UNKNOWN
PYTHON3
CODEFORCES
90
8891a9d7e5544bb50fc3a3842c39a9cf
Zero-One
Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him. Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card c...
[ "s = input()\r\n\r\na, b, c = (s.count(x) for x in \"01?\")\r\n\r\n# print(\"{} {} {}\".format(a, b, c))\r\n\r\nif(a + c > b):\r\n print(\"00\")\r\nif(a + c + 2 > b >= a - c):\r\n if(s[-1] != '?'):\r\n if(s[-1] == '0'):\r\n print('10')\r\n else:\r\n print('01')\r\n else:...
{"inputs": ["????", "1010", "1?1", "111?", "000?", "1??1?", "?111111?00?", "??????????0????????????????0000000000000", "1?1?1?1?0?10", "?0101", "??0101", "??1010", "00", "11", "1110110101111111001111111110111011100001110111011001011111111111011010011111?111111?011111110001010110011111010111100111?111101010011101010?011...
UNKNOWN
PYTHON3
CODEFORCES
2
889f498ec3484cf118ca64ffd0df42d2
Balanced Substring
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to deter...
[ "n=int(input())\r\nT=input()\r\nd={0:-1}\r\ns=0\r\nmix=0\r\n \r\nfor i in range(n):\r\n\ts+=1-(T[i]=='0')*2\r\n\tif s not in d:\r\n\t\td[s]=i\r\n\telse:\r\n\t\tif(i-d[s])> mix:\r\n\t\t\tmix=i-d[s]\r\nprint(mix)", "from itertools import accumulate\r\n\r\nn = int(input())\r\ns = input().strip()\r\n\r\na = [0] + lis...
{"inputs": ["8\n11010111", "3\n111", "11\n00001000100", "10\n0100000000", "13\n0001000011010", "14\n00000100101011", "14\n01111101111111", "18\n110010101101111111", "11\n00010000011", "10\n1000010110", "15\n100000100000011", "18\n011010101110111101", "10\n0011011111", "3\n011", "14\n11111111111111", "65\n11001000110001...
UNKNOWN
PYTHON3
CODEFORCES
139
88a4ecba4c2e6aa84406f8ca64e0117c
Help King
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive. Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, ...
[ "import math\r\nfrom fractions import Fraction\r\nimport time\r\n\r\nMAXN = 10000\r\n\r\ndef solve(free_nodes, n):\r\n\tseq = []\r\n\tused = {}\r\n\r\n\tused[0] = 0\r\n\tpos = 0\r\n\twhile used.get(free_nodes) == None:\r\n\t\tused[free_nodes] = pos\r\n\t\ttoss = 0\r\n\t\twhile free_nodes < n:\r\n\t\t\ttoss += 1\r\n...
{"inputs": ["2", "3", "4", "8", "7", "6", "1", "5", "96", "54", "49", "57", "21", "43", "56", "46", "91", "13", "82", "69", "77", "27", "63", "60", "42", "29", "99", "19", "89", "356", "377", "376", "199", "563", "768", "777", "721", "629", "589", "698", "897", "100", "898", "778", "408", "915", "659", "380", "826", "5...
UNKNOWN
PYTHON3
CODEFORCES
9
88a9414a5b52e94c5b877e3e07e40bc0
Award Ceremony
All-Berland programming contest comes to an end. In total, *n* teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team the value *a**i* is given — the number of points the *i*-th team has earned...
[ "n = int(input())\r\na = []\r\nd = []\r\np = []\r\nfor i in range(n):\r\n ai, di = map(int, input().split())\r\n a.append(ai)\r\n d.append(di)\r\n p.append((ai, -i))\r\n p.append((ai + di, -i)) \r\np.sort()\r\ns = []\r\nfor i in range(n):\r\n s.append((p.index((a[i], -i)), p.index((a[i] + d[i], -i...
{"inputs": ["4\n17 -14\n52 -5\n1 52\n6 0", "5\n4 5\n3 2\n5 -3\n6 -2\n4 3", "3\n2 1\n1 -1\n1 2", "5\n4 1\n5 4\n3 5\n4 5\n5 2", "10\n3 3\n1 1\n1 2\n2 2\n3 4\n3 2\n4 3\n2 2\n2 2\n1 2", "20\n5 4\n1 5\n5 4\n4 5\n4 5\n1 1\n5 3\n3 3\n4 5\n1 4\n5 2\n4 2\n4 4\n5 1\n1 1\n5 3\n2 4\n2 4\n1 2\n2 3", "40\n5 4\n1 4\n5 1\n3 4\n1 4\n5 ...
UNKNOWN
PYTHON3
CODEFORCES
1
88c00f744c62257aff2d2df925559c97
Blinds
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ...
[ "# LUOGU_RID: 101448633\nn, m, *a = map(int, open(0).read().split())\r\nans = []\r\nfor i in range(m, 101):\r\n ans += i * sum(x // i for x in a),\r\nprint(max(ans))", "n,L=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nans=0\r\nfor clen in range(L,101):\r\n csum=sum(y//clen for y i...
{"inputs": ["4 2\n1 2 3 4", "5 3\n5 5 7 3 1", "2 3\n1 2", "2 2\n3 3", "5 2\n2 4 1 1 3", "7 4\n3 2 1 1 1 3 2", "10 1\n1 2 2 6 6 1 2 5 5 6", "10 2\n6 3 1 1 6 4 6 1 6 3", "15 6\n1 6 6 5 2 10 4 4 7 8 7 3 5 1 2", "20 2\n13 3 6 11 6 11 9 1 1 2 5 2 9 15 14 10 3 12 3 13", "25 20\n10 8 4 6 12 14 19 18 19 9 21 16 16 15 10 15 12 ...
UNKNOWN
PYTHON3
CODEFORCES
34
88d941a8d49063c57c8e264ff7932a42
Polycarp's Practice
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann...
[ "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=sorted(a,reverse=True)\r\nb=b[:k]\r\nc=k\r\nprint(sum(b))\r\nj=0\r\nfor i in range(n):\r\n if(a[i] in b and c!=1):\r\n print(i+1-j,end=' ')\r\n j=i+1\r\n b.remove(a[i])\r\n c-=1\r\n if(c==1):\r\n print(n-...
{"inputs": ["8 3\n5 4 2 6 5 1 9 2", "5 1\n1 1 1 1 1", "4 2\n1 2000 2000 2", "1 1\n2000", "1 1\n1234", "3 2\n1 1 1", "4 2\n3 5 1 1", "5 3\n5 5 6 7 1", "6 4\n1 1 1 1 2 2", "5 3\n5 5 6 6 4", "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12", "1 1\n1996", "5 3\n5 5 5 9 10", "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9...
UNKNOWN
PYTHON3
CODEFORCES
86
88f39d68bb4b079df4d1512539367c6f
Practice
Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are *n* players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 ...
[ "from math import *\r\nf1=open('input.txt','r')\r\nn=int(f1.readline())\r\nf1.close()\r\na=[[] for i in range(int(log(n,2))+1)]\r\ndef f(l,r,d=0):\r\n global a\r\n if l!=r:\r\n m=(l+r)//2\r\n a[d]+=list(range(l,m+1))\r\n f(l,m,d+1)\r\n f(m+1,r,d+1)\r\nf(1,n)\r\nb=0\r\nfor i in rang...
{"inputs": ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "13", "15", "16", "18", "20", "100", "110", "120", "140", "157", "171", "199", "200", "213", "231", "240", "250", "253", "260", "270", "271", "277", "280", "290", "300", "700", "730", "766", "777", "800", "832", "855", "869", "888", "900", "914", "930", "9...
UNKNOWN
PYTHON3
CODEFORCES
4
88f417c9a8ac80f7a8d7bd045bd77bc2
Lucky Sorting
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya got an array consisting of *n* numbers, it is the gift for his birthday. Now he wants to sort ...
[ "from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = [0] + list(map(int, input().split()))\r\nx = list(a)\r\nx.sort()\r\ns = 0\r\nfor i in range(1, n + 1):\r\n u = [0] * 10\r\n for j in str(a[i]):\r\n u...
{"inputs": ["2\n4 7", "3\n4 2 1", "7\n77 66 55 44 33 22 11", "7\n1 2 3 4 5 6 7", "4\n47 1 7 2", "10\n8 4 7 5 9 5 8 5 10 1000", "3\n3 2 1", "1\n9", "5\n4 7 47 744 1", "7\n4 4 4 4 7 7 7", "3\n1 100 4777", "10\n1 8 4 9 5 9 5 8 55 777777", "20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "20\n5 45 8 9 4 8 7 4 5 8 ...
UNKNOWN
PYTHON3
CODEFORCES
2
890dc69313bd417ff2d70cfa1ba21d98
Analyzing Polyline
As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that. Let's consider a set of fun...
[ "from math import gcd\r\nimport sys\r\nn = int(sys.stdin.readline())\r\nres = set()\r\nfor _ in range(n):\r\n k,b = map(int,sys.stdin.readline().split())\r\n if k!=0:\r\n a = gcd(k,b)\r\n if k*b>0:\r\n res.add((abs(b//a),abs(k//a)))\r\n else:\r\n res.add((-abs(b//a),...
{"inputs": ["1\n1 0", "3\n1 0\n0 2\n-1 1", "3\n-2 -4\n1 7\n-5 1", "10\n9 9\n-5 2\n-2 9\n0 6\n6 7\n-1 -10\n-8 6\n3 6\n-3 -9\n0 4", "10\n-4 -9\n5 9\n-4 -1\n6 -1\n-10 -10\n3 4\n3 5\n3 10\n9 7\n4 -7", "5\n3 3\n2 2\n2 -3\n-3 3\n-1 1", "4\n0 2\n-1 -2\n1 0\n-2 2", "10\n-1 2\n0 1\n-2 0\n1 1\n-1 -1\n-2 1\n-2 2\n2 -1\n0 -1\n-1 0...
UNKNOWN
PYTHON3
CODEFORCES
4
8916d23cafaf87358fda6c265d1c3240
Maximum path
You are given a rectangular table 3<=×<=*n*. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is ma...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na1 = list(map(int, input().split()))\r\na2 = list(map(int, input().split()))\r\na3 = list(map(int, input().split()))\r\ninf = pow(10, 15)\r\nfor _ in range(2):\r\n a1.append(-inf)\r\n a2.append(-inf)\r\n a3.append(0)\r\ndp1 = [-inf] * (n ...
{"inputs": ["3\n1 1 1\n1 -1 1\n1 1 1", "5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10", "15\n-87 -91 31 63 91 35 -14 51 20 20 -20 -94 -59 77 76\n11 81 22 -29 91 -26 -10 -12 46 10 100 88 14 64 41\n26 -31 99 -39 -30 30 28 74 -7 21 2 32 -60 -74 46", "20\n16 82 25 21 -60 9 29 -55 70 54 -50 10 -19 40 46 41 31 -66 1 85\n...
UNKNOWN
PYTHON3
CODEFORCES
3
8945042f2c8d6960cb0d9cc6116dc3de
Skills
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly *n* skills. Each skill is represented by a non-negative integer *a**i* — the current skill level. All skills have the same maximum level *A*. Al...
[ "import itertools\nimport bisect\n\nn, A, cf, cm, m = [int(x) for x in input().split()]\nskills = [int(x) for x in input().split()]\nsorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))\nbottom_lift = [0 for i in range(n)]\nfor i in range(1, n):\n bottom_lift[i] = bottom_lift[i-1] + i * (sorted_ski...
{"inputs": ["3 5 10 1 5\n1 3 1", "3 5 10 1 339\n1 3 1", "2 6 0 1 4\n5 1", "1 1000000000 1000 1000 1000000000000000\n0", "1 100 1 2 30\n1", "1 100 1 2 30\n71", "1 1000000000 1000 1000 1000000000000000\n1000000000", "5 5 10 20 50\n0 0 0 0 0", "5 5 10 20 50\n3 3 3 3 3", "4 5 3 7 15\n4 3 3 1", "3 6 4 6 8\n6 4 5"], "outputs...
UNKNOWN
PYTHON3
CODEFORCES
4
89491360e66f8310e95485370a17fd93
none
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prim...
[ "q = int(input().strip())\r\n\r\nfor _ in range(q):\r\n\tn = int(input().strip())\r\n\r\n\tprimes = [1,3,5,7,11]\r\n\t#if n is odd..\r\n\tif n&1:\r\n\t\tif n in primes:\r\n\t\t\tprint(-1)\r\n\t\telse:\r\n\t\t\tprint(((n-9)//4)+1)\r\n\telse:\r\n\t\tif n==2:\r\n\t\t\tprint(-1)\r\n\t\telse:\r\n\t\t\tprint(n//4)\r\n", ...
{"inputs": ["1\n12", "2\n6\n8", "3\n1\n2\n3", "6\n1\n2\n3\n5\n7\n11", "3\n4\n6\n9", "20\n8\n13\n20\n12\n9\n16\n4\n19\n7\n15\n10\n6\n14\n11\n3\n2\n5\n17\n18\n1", "100\n611\n513\n544\n463\n38\n778\n347\n317\n848\n664\n382\n108\n718\n33\n334\n876\n234\n22\n944\n305\n159\n245\n513\n691\n639\n135\n308\n324\n813\n459\n304\n1...
UNKNOWN
PYTHON3
CODEFORCES
127
895d55b60d3cf7fbe8a8d7aee6e5bf90
Tourist Problem
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a*...
[ "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Jun 3 11:57:46 2020\n\n@author: shailesh\n\"\"\"\n\nfrom math import gcd\n\ndef reduce_fraction(x,y):\n d = gcd(x,y)\n x = x//d\n y = y//d\n return x,y\n\nN = int(input())\n\nA = [int(i) for i in input().split()]\n\nA.sort()\n\nd0...
{"inputs": ["3\n2 3 5", "4\n1 5 77 2", "5\n3 3842 288 199 334", "7\n1 2 3 40 52 33 86", "7\n1 10 100 1000 10000 1000000 10000000", "6\n3835302 971984 8706888 1080445 2224695 1093317", "40\n8995197 7520501 942559 8012058 3749344 3471059 9817796 3187774 4735591 6477783 7024598 3155420 6039802 2879311 2738670 5930138 4604...
UNKNOWN
PYTHON3
CODEFORCES
35
896e4fa6c27d59192730b1a332916bbd
Center Alignment
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck! The input file consists ...
[ "import fileinput\n\ns = []\nleft = True\n\nfor line in fileinput.input():\n s.append(line[:-1])\n\nl = len(max(s, key=len))\n\nfor i in range(len(s)):\n free = l - len(s[i])\n sp = free//2\n if free%2==0:\n s[i] = '*' + sp*' ' + s[i] + sp*' ' + '*'\n else:\n if left:\n s[i] ...
{"inputs": ["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck", "0\n2", "O\no\nd", "0v uO M6Sy", "fm v\nOL U W", "vb\nJ\nyU\nZ", "N\nSV\nEh\n6f\nX6\n9e", "Pj\nA\nFA\nP\nVJ\nU\nEb\nW", "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA", "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\...
UNKNOWN
PYTHON3
CODEFORCES
104
898bd3d15572e3c5b3a6e55eee7cebf1
Minimum Sum
Petya has *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two...
[ "b=['a','b','c','d','e','f','g','h','i','j']\r\nl=[0]*10\r\nz=[]\r\nn=int(input())\r\nfor i in range(n):\r\n s=input()\r\n z.append(s[0])\r\n for j in range(len(s)):\r\n l[b.index(s[j])]+=10**(len(s)-j-1)\r\ns=0\r\nh=0\r\nj=1\r\nfor k in range(10):\r\n ma=0\r\n for i in range(10):\r\n i...
{"inputs": ["3\nab\nde\naj", "5\nabcdef\nghij\nbdef\naccbd\ng", "3\naa\njj\naa", "9\na\nb\nc\nd\nf\ng\nh\ni\nj", "5\nbdgbh\nadi\naa\ngjh\ngh", "6\nchafj\nabhj\nfhe\nhfbd\njifgg\ng", "1\nh", "7\nffh\nfhec\nfbchc\ng\ndfbhi\ncdbdi\ni", "8\ne\nbhbib\nj\ndgb\njjbgb\nei\ndggbdh\nhfbbfj", "10\ncf\ncha\nceiab\ng\naajac\ndj\nhe...
UNKNOWN
PYTHON3
CODEFORCES
41
898f5cceb39732df2744828494acaa59
Different Subsets For All Tuples
For a sequence *a* of *n* integers between 1 and *m*, inclusive, denote *f*(*a*) as the number of distinct subsequences of *a* (including the empty subsequence). You are given two positive integers *n* and *m*. Let *S* be the set of all sequences of length *n* consisting of numbers from 1 to *m*. Compute the sum *f*(*...
[ "n,m=map(int,input().split())\r\nx,y,M=0,1,1000000007\r\nfor i in range(n):\r\n\tx=((2*m-1)*x+y)%M;y=y*m%M\r\nprint((y+m*x)%M)", "P = 10**9 + 7\r\n\r\nn, k = map(int, input().split())\r\n\r\nprint(n + 1 if k == 1 else (k * pow(2 * k - 1, n, P) - pow(k, n, P)) * pow(k - 1, P - 2, P) % P)\n", "from sys import std...
{"inputs": ["1 3", "2 2", "3 3", "1 1000000", "1000000 1", "500 500", "1000000 1000000"], "outputs": ["6", "14", "174", "2000000", "1000001", "383255233", "247171672"]}
UNKNOWN
PYTHON3
CODEFORCES
8
899ad686a6f5f7729afbc31a2d42123f
Tree Construction
During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so he asks you to help. You are given a sequence $a$, consisting of $n$ distinct integers, that is used to construct the binary search tree. Below is the form...
[ "from bisect import *\r\nn=int(input())\r\nd,a=[(0,0)],[0]*n\r\nfor i,x in enumerate(map(int,input().split())):\r\n no=bisect(d,(x,0))-1\r\n l,y=d[no]\r\n a[i]=str(y)\r\n d[no:no+1]=[(l,x),(x,x)]\r\nprint(' '.join(a[1:]))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).rea...
{"inputs": ["3\n1 2 3", "5\n4 2 3 1 6", "2\n1 2", "10\n991309218 517452607 870021923 978357992 136426010 10601767 302627526 883615372 163475700 600546765", "2\n656402233 488475947"], "outputs": ["1 2", "4 2 2 4", "1", "991309218 517452607 870021923 517452607 136426010 136426010 978357992 302627526 870021923", "65640223...
UNKNOWN
PYTHON3
CODEFORCES
3
899dbfc5766d6ae6850a7869f0de87da
Reversing Encryption
A string $s$ of length $n$ can be encrypted by the following algorithm: - iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algor...
[ "n = int(input())\r\ns = list(input())\r\nfor d in range(1,n+1):\r\n\ts[0:d] = reversed(s[0:d]) if n%d == 0 else s[0:d]\r\nprint(\"\".join(s))\t", "\r\nn = int(input())\r\ns = input()\r\n\r\ndef get_divisors(n):\r\n\ti=2\r\n\toriginal = n\r\n\tres = []\r\n\tfor i in range(2,n+1):\r\n\t\tif n%i==0:\r\n\t\t\tres.ap...
{"inputs": ["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz", "2\nir", "3\nilj", "4\njfyy", "6\nkrdych", "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj", "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy", "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacyga...
UNKNOWN
PYTHON3
CODEFORCES
173