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
f66884c846d9ab53effb39a95437459d
Race Against Time
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with ...
[ "# LUOGU_RID: 116460278\na,b,c,d,e = map(int,input().split())\r\na,b,c,d,e = (5*a+0.5)%60,(b+0.5)%60,(c+0.5)%60,5*d,5*e\r\nf,g = min(d,e),max(d,e)\r\nif (f<a<g or f<b<g or f<c<g) and ((0<a<f or g<a<60) or (0<b<f or g<b<60) or (0<c<f or g<c<60)):\r\n print('NO')\r\nelse:\r\n print('YES')", "h,m,s,t1,t2 = map...
{"inputs": ["12 30 45 3 11", "12 0 1 12 1", "3 47 0 4 9", "10 22 59 6 10", "3 1 13 12 3", "11 19 28 9 10", "9 38 22 6 1", "5 41 11 5 8", "11 2 53 10 4", "9 41 17 10 1", "6 54 48 12 6", "12 55 9 5 1", "8 55 35 9 3", "3 21 34 3 10", "2 52 1 12 3", "7 17 11 1 7", "11 6 37 6 4", "9 6 22 8 1", "3 10 5 5 9", "7 12 22 11 2", ...
UNKNOWN
PYTHON3
CODEFORCES
67
f67e84e95f79dcc728e8824d78e742f1
Necklace
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). ...
[ "from fractions import gcd\nfrom functools import reduce\n\n\nLETTERS = 'abcdefghijklmnopqrstuvwxyz'\n\n\ndef necklace_odd(a):\n oi = next(i for i, ai in enumerate(a) if ai%2)\n o = a[oi]\n g = reduce(gcd, a)\n s = [LETTERS[i] * (a[i]//(2*g)) for i in range(len(a)) if i != oi]\n return g, (''.join(s)...
{"inputs": ["3\n4 2 1", "1\n4", "2\n1 1", "1\n2", "1\n3", "1\n5", "2\n2 2", "3\n1 2 4", "3\n3 3 3", "3\n3 3 6", "3\n6 6 6", "3\n6 6 9", "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", "3\n7 7 21", "2\n95 50", "3\n30 30 15", "3\n1 50 70", "2\n70 10", "10\n100 100 100 50 20 300 400 300 350 320", "4\n1100 220 6...
UNKNOWN
PYTHON3
CODEFORCES
3
f6b787869ae37c46c36ee88999a86ba8
Kuro and Walking Route
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which h...
[ "import io,os\r\ninput=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nri=lambda: int(input())\r\nrl=lambda: list(map(int,input().split()))\r\nrs=lambda: input().decode().rstrip('\\n\\r')\r\nfrom collections import deque as dq\r\ninf=float(\"inf\")\r\nmod=10**9 + 7\r\n\r\n\r\ndef DFS(gr,B,F):\r\n n=len(gr...
{"inputs": ["3 1 3\n1 2\n2 3", "3 1 3\n1 2\n1 3", "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 5...
UNKNOWN
PYTHON3
CODEFORCES
14
f6ed80837137f82f9377e02bf1061dd1
Median on Segments (Permutations Edition)
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
[ "n, m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nd = {0: 1}\r\ncheck, q, ans = 0,0,0\r\nfor i in a:\r\n if i < m:\r\n q -= 1\r\n elif i > m:\r\n q += 1\r\n else:\r\n check = 1\r\n if check:\r\n ans += d.get(q,0)+d.get(q-1,0)\r\n else:\r\n ne...
{"inputs": ["5 4\n2 4 5 3 1", "5 5\n1 2 3 4 5", "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9", "1 1\n1", "2 1\n1 2", "2 1\n2 1", "2 2\n1 2", "2 2\n2 1", "3 1\n1 2 3", "3 1\n1 3 2", "3 1\n2 1 3", "3 1\n2 3 1", "3 1\n3 1 2", "3 1\n3 2 1", "5 2\n2 1 3 4 5", "6 3\n3 6 1 4 2 5", "7 4\n1 7 6 4 2 3 5", "8 7\n2 3 6 8 7 5 4 1", "...
UNKNOWN
PYTHON3
CODEFORCES
17
f6efa3da33b7fe29692c702f81aaa53e
Cut Ribbon
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
[ "n, a, b, c = map(int, input().split())\r\n\r\ntemp = 0\r\n\r\nfor i in range(n+1):\r\n for j in range(n+1):\r\n if i*a + j*b <= n:\r\n if (n - (i*a + j*b)) % c == 0:\r\n flag = i + j + (n - (i*a + j*b)) // c\r\n if flag > temp and flag != 0:\r\n ...
{"inputs": ["5 5 3 2", "7 5 5 2", "4 4 4 4", "1 1 1 1", "4000 1 2 3", "4000 3 4 5", "10 3 4 5", "100 23 15 50", "3119 3515 1021 7", "918 102 1327 1733", "3164 42 430 1309", "3043 317 1141 2438", "26 1 772 2683", "370 2 1 15", "734 12 6 2", "418 18 14 17", "18 16 28 9", "14 6 2 17", "29 27 18 2", "29 12 7 10", "27 23 4 ...
UNKNOWN
PYTHON3
CODEFORCES
168
f6f6f7f83556081cb3f54ab634ecbaef
Jumping on Walls
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. ...
[ "from collections import deque\r\ndef can_escape(n, k, left, right):\r\n visited = [[False, False] for _ in range(n)]\r\n queue = deque([(0, 0, 0)]) # позиция, стена, время\r\n while queue:\r\n pos, wall, time = queue.popleft()\r\n if pos >= n:\r\n return 'YES'\r\n if visit...
{"inputs": ["7 3\n---X--X\n-X--XX-", "6 2\n--X-X-\nX--XX-", "10 1\n-X-X-X-X-X\nX-X-X-X-X-", "5 4\n-X---\n----X", "6 2\n--X--X\nXX-X-X", "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----", "1 1\n-\nX", "2 1\n-X\nX-", "2 1\n-X\n-X", "1 20\n-\n-", "1 100000\n-\n-...
UNKNOWN
PYTHON3
CODEFORCES
12
f7024bf1d013c03844cb96bcc9fa93bb
Chamber of Secrets
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anyb...
[ "from collections import deque\r\nfrom collections import defaultdict\r\n\r\nn, m = map(int, input().split())\r\nINF = 10 ** 9\r\nvisited=defaultdict(int)\r\n\r\ng = [[] for _ in range(n + m)] # 0..(n-1) -- rows, n..n+m-1 -- columns\r\n\r\nfor i in range(n):\r\n s=input()\r\n for j,c in enumerate(s):\r\n ...
{"inputs": ["3 3\n.#.\n...\n.#.", "4 3\n##.\n...\n.#.\n.#.", "3 3\n###\n###\n###", "3 4\n..##\n....\n..#.", "4 3\n#.#\n...\n...\n.##", "4 4\n##..\n..#.\n...#\n...#", "5 5\n...#.\n.....\n.....\n.....\n..#.#", "5 5\n.....\n.#...\n.....\n.....\n#.###", "5 5\n.....\n.###.\n..##.\n..##.\n...#.", "5 5\n.##..\n.##..\n.#.#.\n....
UNKNOWN
PYTHON3
CODEFORCES
9
f717d6d18d0b83f713963b87aacd0bcb
Five-In-a-Row
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i...
[ "l = [input() for _ in range(10)]\r\n\r\nfor c in range(5):\r\n t = ['X'] * 5\r\n t[c] = '.'\r\n for i in range(10):\r\n for j in range(6):\r\n cnt = 0\r\n for k in range(5):\r\n if l[i][j + k] == '.':\r...
{"inputs": ["O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X", "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.", "..O..X.X..\n.O..X...O.\n........O.\n...O..O...\nX.XX....X.\n..O...
UNKNOWN
PYTHON3
CODEFORCES
45
f718d17fcf33e09f943d8d3f2aa51ab5
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
[ "n = int(input())\r\nflag = False\r\nfor i in range(n):\r\n name, before, after = map(str, input().split())\r\n if flag is False:\r\n if int(before) >= 2400 and int(after) > int(before):\r\n flag = True\r\n continue\r\nprint('YES' if flag is True else 'NO')\r\n", "n=int(input())\r\ncan=...
{"inputs": ["3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "1\nDb -3373 3591", "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\n...
UNKNOWN
PYTHON3
CODEFORCES
365
f76189f114131cbaa9af76123ee3508a
Red-Green Towers
There are *r* red and *g* green blocks for construction of the red-green tower. Red-green tower can be built following next rules: - Red-green tower is consisting of some number of levels; - Let the red-green tower consist of *n* levels, then the first level of this tower should consist of *n* blocks, second level —...
[ "r0,g0=map(int,input().split())\r\nh0=int((2*(r0+g0)+0.25)**0.5-0.5)\r\nsum=(h0*(h0+1))//2\r\nmod=10**9+7\r\nremain=r0+g0-sum\r\nf=[[0 for _ in range(r0+1)] for _ in range(2)]\r\nfor i in range(min(remain,r0)+1):\r\n f[(h0+1)%2][i]=1\r\n# print(f)\r\nfor h in range(h0,-1,-1):\r\n for i in range(r0+1):\r\n ...
{"inputs": ["4 6", "9 7", "1 1", "3 3", "2 19", "18 3", "100000 1", "1 100000", "6 6", "10 10", "200000 200000", "0 1", "1 0", "0 200000", "200000 0", "199396 0", "199395 0", "0 199397", "121147 78249", "78250 121147", "121146 78249", "199585 199586", "199586 199586", "199585 199585", "107344 159729", "2954 1977", "255...
UNKNOWN
PYTHON3
CODEFORCES
2
f7633c6db0a40963f948f432f5ef18b8
Three Garlands
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s...
[ "a=[int(x) for x in input().split()]\r\nif 1 in a:\r\n print(\"YES\")\r\nelif a.count(2)>=2:\r\n print(\"YES\")\r\nelif a.count(3)==3:\r\n print(\"YES\")\r\nelif set(a)=={2,4,4}:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "k1,k2,k3=map(int,input().split())\nif (k1==2 and k2==2) or (k3==2 a...
{"inputs": ["2 2 3", "4 2 3", "1499 1498 1500", "1500 1500 1500", "100 4 1", "4 2 4", "3 3 3", "2 3 6", "2 3 3", "4 4 2", "1 1 1", "2 11 2", "4 4 4", "4 4 5", "3 3 2", "3 6 6", "2 3 2", "1 1 3", "3 3 4", "2 4 4", "2 2 2", "2 10 10", "3 4 4", "2 5 5", "2 4 5", "228 2 2", "2 998 1000", "2 6 6", "6 4 7", "2 5 2", "2 100 1...
UNKNOWN
PYTHON3
CODEFORCES
75
f7641ca673ddd74e3ceea30537a93912
Word Cut
Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w*<==<=*xy*. A split operation is transforming word *w*<==<=*xy* into word *u*<==<=*yx*. For ex...
[ "# Problem: B. Word Cut\r\n# Contest: Codeforces - Croc Champ 2012 - Round 2\r\n# URL: https://codeforces.com/problemset/problem/176/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n\r\nimport sys\r\nimport random\r\nfrom types import GeneratorType\r\nimport bisect\r\nimport io, os\r\nfrom bisect import *\r\...
{"inputs": ["ab\nab\n2", "ababab\nababab\n1", "ab\nba\n2", "aaa\naaa\n0", "hi\nhi\n1", "abcd\ncbad\n5", "ab\nba\n10", "voodoo\ndoovoo\n100000", "ababab\nbababa\n100000", "abcdefgh\ncdefghab\n666", "aaaabaaaaaaaaaaabaaaaaaa\naaaaaaaaaabaaaaaaaaabaaa\n7477", "ssgqcodnqgfbhqsgineioafkkhcmmmihbiefialidgkffrhaiekebpieqgpplm...
UNKNOWN
PYTHON3
CODEFORCES
24
f77027b5a8bdd60ddf914fe8d79e9619
Coprime Subsequences
Let's call a non-empty sequence of positive integers *a*1,<=*a*2... *a**k* coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array *a* consisting of *n* positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109<...
[ "from collections import defaultdict, deque, Counter\r\nimport sys\r\nfrom decimal import *\r\nfrom heapq import heapify, heappop, heappush\r\nimport math\r\nimport random\r\nimport string\r\nfrom copy import deepcopy\r\nfrom itertools import combinations, permutations, product\r\nfrom operator import mul, itemgett...
{"inputs": ["3\n1 2 3", "4\n1 1 1 1", "7\n1 3 5 15 3 105 35", "1\n1", "1\n100000", "5\n10 8 6 4 6", "5\n5 1 3 5 4", "5\n5 1 6 6 6", "10\n9 6 8 5 5 2 8 9 2 2", "10\n2 2 16 16 14 1 9 12 15 13", "50\n17 81 20 84 6 86 11 33 19 46 70 79 23 64 40 99 78 70 3 10 32 42 18 73 35 36 69 90 81 81 8 25 87 23 76 100 53 11 36 19 87 89...
UNKNOWN
PYTHON3
CODEFORCES
16
f787e15865d3fc919c7733bf0d10c0ca
none
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation...
[ "\r\nn = int(input())\r\np = [int(i) - 1 for i in input().split()]\r\n\r\nchd = [0] * (n + 2)\r\ndev = 0\r\ndd = 0\r\n\r\nfor i in range(n):\r\n shi = p[i] - i\r\n dev += abs(shi)\r\n if p[i] <= i:\r\n dd += 1\r\n shi = n + shi\r\n chd[shi] += 2\r\n else:\r\n dd -= 1\r\n ...
{"inputs": ["3\n1 2 3", "3\n2 3 1", "3\n3 2 1", "2\n1 2", "2\n2 1", "10\n10 1 9 2 8 3 7 4 6 5", "108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40...
UNKNOWN
PYTHON3
CODEFORCES
3
f792ab42d078f44a187ba4dbaad41927
Breaking Good
Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers. Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of...
[ "import collections\nimport heapq\nif __name__ == '__main__':\n n, m = [int(x) for x in input().split()]\n G = collections.defaultdict(list)\n road = []\n for i in range(m):\n s, e, f = [int(x) for x in input().split()]\n road.append((s, e, f))\n G[s].append((e, f))\n G[e].ap...
{"inputs": ["2 1\n1 2 0", "4 4\n1 2 1\n1 3 0\n2 3 1\n3 4 1", "8 9\n1 2 0\n8 3 0\n2 3 1\n1 4 1\n8 7 0\n1 5 1\n4 6 1\n5 7 0\n6 8 0", "9 10\n1 2 0\n2 3 0\n1 4 1\n4 5 1\n4 6 1\n6 7 1\n1 7 0\n1 8 0\n7 8 0\n9 7 1", "5 6\n1 2 0\n3 2 0\n5 1 1\n1 3 1\n5 3 0\n4 3 1", "15 31\n6 2 0\n5 15 1\n2 3 1\n6 9 1\n13 12 0\n2 7 0\n15 3 0\n3...
UNKNOWN
PYTHON3
CODEFORCES
2
f7aa8d7390b43237f204ef5ed371668b
Hometask
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot ...
[ "import sys;sc = sys.stdin.readline;out=sys.stdout.write\r\ns=str(sc());n=int(sc());ans=0\r\nfor e in range(n):\r\n ss=str(sc());a,b=0,0\r\n for e in s:\r\n if e==ss[0]:a+=1\r\n elif e==ss[1]:b+=1\r\n else :ans+=min(a,b);a=0;b=0\r\n ans+=min(a,b)\r\nout(str(ans)) ", "s = input()\r\nn...
{"inputs": ["ababa\n1\nab", "codeforces\n2\ndo\ncs", "nllnrlrnll\n1\nrl", "aludfbjtwnkgnfl\n1\noy", "pgpgppgggpbbnnn\n2\npg\nnb", "eepeeeeppppppeepeppe\n1\npe", "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy", "drvwfaacccwnncfwuptsorrrvvvrgdzytrwweeexzyyyxuwuuk\n13\nld\nac\nnp\nrv\nmo\njh...
UNKNOWN
PYTHON3
CODEFORCES
16
f7b93766b035c712017b0bdc774bdecf
Chess Tourney
Berland annual chess tournament is coming! Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizer...
[ "n=int(input())\r\na=sorted(list(map(int,input().split())))\r\nprint('YES' if a[n-1]<a[n] else 'NO')", "input()\r\n\r\nl = list(map(int, input().split()))\r\nl.sort()\r\n\r\nif l[len(l) // 2] > l[len(l) // 2 - 1]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\na2=sorted(list(map(in...
{"inputs": ["2\n1 3 2 4", "1\n3 3", "5\n1 1 1 1 2 2 3 3 3 3", "5\n1 1 1 1 1 2 2 2 2 2", "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "1\n2 3", "100\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 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 1 1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
131
f7ecc31f6717583a02c3bf8945146bfa
Worms Evolution
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ...
[ "n = int(input())\r\ndata = list(input().split())\r\nnumbers_list = list(map(int, data))\r\nnumbers = sorted(numbers_list)\r\n\r\ni = 0\r\nj = 1\r\n\r\nwhile i != n - 1:\r\n if numbers[i] + numbers[j] not in numbers:\r\n if i == n - 2:\r\n print(\"-1\")\r\n break\r\n if j != n...
{"inputs": ["5\n1 2 3 5 7", "5\n1 8 1 5 1", "4\n303 872 764 401", "6\n86 402 133 524 405 610", "8\n217 779 418 895 996 473 3 22", "10\n858 972 670 15 662 114 33 273 53 310", "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 ...
UNKNOWN
PYTHON3
CODEFORCES
131
f811d54f672bee985c0aacecb9dada21
Report
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands...
[ "# HEY STALKER\r\nn, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nk = []\r\nfor t in range(m):\r\n x, y = map(int, input().split())\r\n while len(k) > 0 and k[-1][1] < y:\r\n k.pop()\r\n k.append([x, y])\r\na = 0\r\nb = k[0][1] - 1\r\nk.append([0, 0])\r\nsr = sorted(l[:b+1...
{"inputs": ["3 1\n1 2 3\n2 2", "4 2\n1 2 4 3\n2 3\n1 2", "4 1\n4 3 2 1\n1 4", "5 1\n1 2 3 4 5\n2 5", "6 2\n3 1 2 6 4 5\n1 6\n2 3", "10 3\n6 4 0 2 -3 7 8 -9 1 5\n1 8\n1 4\n2 2", "100 30\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65...
UNKNOWN
PYTHON3
CODEFORCES
29
f853095fb8e1806dff3305c2c7f1356a
Two Heaps
Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cub...
[ "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\na = [int(x) for x in stdin.readline().split()]\r\na = sorted([(a[x], x) for x in range(n*2)])\r\n\r\ngroup = {}\r\n\r\nfor x,ind in a:\r\n if x in group:\r\n group[x].append(ind)\r\n else:\r\n group[x] = [ind]\r\n\r\ng2 = []\r\n\r\nfor x...
{"inputs": ["1\n10 99", "2\n13 24 13 45", "5\n21 60 18 21 17 39 58 74 62 34", "10\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98", "20\n80 56 58 61 75 60 25 49 59 15 43 39 21 73 67 13 75 31 18 87 32 44 53 15 53 76 79 94 85 80 27 25 48 78 32 18 20 78 46 37", "50\n49 13 81 20 73 62 19 49 65 95 32 84 24 96 5...
UNKNOWN
PYTHON3
CODEFORCES
9
f862e4461b9c0bb971a8c79bb1c73e64
Not Wool Sequences
A sequence of non-negative integers *a*1,<=*a*2,<=...,<=*a**n* of length *n* is called a wool sequence if and only if there exists two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression means...
[ "a,b=map(int,input().split())\r\nans=1;mod=1000000009;gh=pow(2,b,mod)\r\nfor i in range(1,1+a):ans=(ans*(gh-i))%mod\r\nprint(ans)", "MOD = int(1e9+9)\r\n\r\ndef fast_power(b, e):\r\n res = 1\r\n while e:\r\n if e % 2 == 1:\r\n res = res * b % MOD\r\n b = b * b % MOD \r\n e >>...
{"inputs": ["3 2", "4 2", "1 2", "4 11", "5 100", "5444 31525", "60282 92611", "62600 39199", "14095 86011", "78606 36436", "25063 54317", "86232 41348", "94882 95834", "83781 52238", "21857 94145", "7413 87155", "7683 65667", "88201 96978", "50664 46559", "60607 63595", "85264 15318", "100000 100000", "100000 16", "10...
UNKNOWN
PYTHON3
CODEFORCES
8
f871e22e89df88a072982b9d30fa1a08
Petya and Post
Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post office. In the office he receives a portion of letters and a car. Then ...
[ "import sys\n\nN = 0\nA = [] # gas of a station\nB = [] # dist to next station\nresult = []\n\ndef read_input():\n global N, A, B, result\n readline = sys.stdin.readline\n N = int(readline().strip())\n A = [int(w) for w in readline().split()]\n B = [int(w) for w in readline().split()]\n result = [...
{"inputs": ["4\n1 7 2 3\n8 1 1 3", "8\n1 2 1 2 1 2 1 2\n2 1 2 1 2 1 2 1", "20\n31 16 20 30 19 35 8 11 20 45 10 26 21 39 29 52 8 10 37 49\n16 33 41 32 43 24 35 48 19 37 28 26 7 10 23 48 18 2 1 25", "20\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...
UNKNOWN
PYTHON3
CODEFORCES
2
f87bced97729877cde26614688d8cc40
Online Meeting
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat. One day the director of the F ...
[ "n, m = map(int, input().split())\r\n \r\ncovers_all = set(range(1, n+1))\r\n \r\nin_there = set([])\r\n \r\noccurred = set([])\r\nminus_delete_candidates = set([])\r\nplus_delete_candidates = set([])\r\n \r\nfor i in range(m):\r\n\ta, b = input().split()\r\n\tb = int(b)\r\n\tif a == '+':\r\n\t\tin_there.add(b)\r\n...
{"inputs": ["5 4\n+ 1\n+ 2\n- 2\n- 1", "3 2\n+ 1\n- 2", "2 4\n+ 1\n- 1\n+ 2\n- 2", "5 6\n+ 1\n- 1\n- 3\n+ 3\n+ 4\n- 4", "2 4\n+ 1\n- 2\n+ 2\n- 1", "1 1\n+ 1", "2 1\n- 2", "3 5\n- 1\n+ 1\n+ 2\n- 2\n+ 3", "10 8\n+ 1\n- 1\n- 2\n- 3\n+ 3\n+ 7\n- 7\n+ 9", "5 5\n+ 5\n+ 2\n+ 3\n+ 4\n+ 1", "5 4\n+ 1\n- 1\n+ 1\n+ 2", "10 3\n+ 1...
UNKNOWN
PYTHON3
CODEFORCES
1
f88938594102e07665a6daf0fe883b8d
Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string *s* consisting of lowercase Latin letters. At once you can choose any position in ...
[ "import collections\n\ns = collections.Counter(sorted(list(input())))\nodds = [c for c in s if s[c] % 2]\n\nlength = len(odds)\nfor i in range(length // 2):\n s[odds[i]] += 1\n s[odds[length - i - 1]] -= 1\n\ninfix = odds[length // 2] if length % 2 else \"\"\nprefix = \"\".join([c * (s[c] // 2) for c in s])\n...
{"inputs": ["aabc", "aabcd", "u", "ttttt", "xxxvvvxxvv", "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww", "aabbcccdd", "baaab", "aaabbbhhlhlugkjgckj", "aabcc", "bbbcccddd", "zzzozzozozozoza", "aaabb", "zza", "azzzbbb", "bbaaccddc", "aaabbbccc", "aaaaabbccdd", "aaab...
UNKNOWN
PYTHON3
CODEFORCES
32
f8a456e2fbac83b186fed6c3beb0157b
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write *n* progress tests, for each test they will get a mark from 1 to *p*. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all t...
[ "n,k,p,x,y=map(int,input().split())\r\nq=list(map(int,input().split()))\r\ncy,cx=0,0\r\nfor i in q: cy+=(i<y)\r\nif cy>(n-1)//2: print(-1)\r\nelse:\r\n w=[]\r\n for i in range(min(n-k,n//2-cy)): w.append(1)\r\n while len(w)<n-k: w.append(y)\r\n if sum(q)+sum(w)>x: print(-1)\r\n else: print(*w)", "n...
{"inputs": ["5 3 5 18 4\n3 5 4", "5 3 5 16 4\n5 5 5", "5 3 5 17 4\n5 5 5", "5 3 5 12 1\n5 5 1", "5 3 5 13 1\n5 5 1", "7 4 5 26 5\n5 2 4 5", "7 4 5 27 5\n5 2 4 5", "1 0 1000 999 1000", "1 0 1000 1000 1000", "1 0 1000 1000 999", "995 1 1000 1772 2\n1", "993 0 1000 63930 1", "5 3 5 25 4\n3 3 3", "7 4 5 25 5\n5 5 4 5", "7 ...
UNKNOWN
PYTHON3
CODEFORCES
7
f8b348afc539834c64b2f852cbcc0b6e
Increasing Sequence
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
[ "n, d = map(int, input().split())\r\np, v = 0, 0\r\nfor b in map(int, input().split()):\r\n if b <= p:\r\n c = (p + d - b) // d\r\n v += c\r\n b += c * d\r\n p = b\r\nprint(v)", "from math import ceil\r\na=input().split()\r\nb=input().split()\r\nc=0\r\nfor i in range (1,int(a[0])):\r\n ...
{"inputs": ["4 2\n1 3 3 2", "2 1\n1 1", "2 1\n2 5", "2 1\n1 2", "2 1\n1 1", "2 7\n10 20", "2 7\n1 1", "3 3\n18 1 9", "3 3\n15 17 9", "3 3\n10 9 12", "10 3\n2 1 17 10 5 16 8 4 15 17", "10 3\n6 11 4 12 22 15 23 26 24 26", "10 3\n10 24 13 15 18 14 15 26 33 35", "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 8...
UNKNOWN
PYTHON3
CODEFORCES
229
f8e254217a50cd8cfe9726c4fd64f082
Game of Credit Cards
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the...
[ "import sys\r\nn=int(sys.stdin.readline())\r\nsher=list(input())\r\nmon=list(input())\r\nsher.sort()\r\nmon.sort()\r\n#minimum no of flicks Mon will get\r\nc=mon.copy()\r\nd=sher.copy()\r\ni=0\r\nj=0\r\nans1=0\r\nans2=0\r\nwhile(i<n and j<n):\r\n if c[i]>=d[j]:\r\n i+=1\r\n j+=1\r\n else:\r\n ...
{"inputs": ["3\n123\n321", "2\n88\n00", "1\n4\n5", "1\n8\n7", "2\n55\n55", "3\n534\n432", "3\n486\n024", "5\n22222\n22222", "5\n72471\n05604", "5\n72471\n72471", "5\n72471\n41772", "8\n99999999\n99999999", "8\n01234567\n01234567", "8\n07070707\n76543210", "8\n88888888\n98769876", "8\n23456789\n01234567", "5\n11222\n221...
UNKNOWN
PYTHON3
CODEFORCES
174
f915e41a0bd233ff98b58882ba47ed03
Problems for Round
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules: - Problemset ...
[ "from collections import deque\r\ndef bfs(i, G, V):\r\n V[i] = 1\r\n Q = deque([i])\r\n while Q:\r\n u = Q.popleft()\r\n for v in G[u]:\r\n if not V[v]:\r\n V[v] = 1 if V[u] == 2 else 2\r\n Q.append(v)\r\n else:\r\n if V[v] ==...
{"inputs": ["5 2\n1 4\n5 2", "3 3\n1 2\n2 3\n1 3", "3 2\n3 1\n3 2", "2 0", "2 1\n1 2", "3 0", "3 1\n1 2", "3 1\n1 3", "100000 0", "4 2\n1 2\n3 4", "3 1\n2 3", "3 2\n1 2\n1 3", "3 2\n1 2\n2 3", "4 0", "100000 1\n100000 1", "100000 1\n26711 97965", "100000 10\n99562 479\n643 99684\n593 99867\n99529 175\n99738 616\n99523 ...
UNKNOWN
PYTHON3
CODEFORCES
34
f92c029ea391d554908f59e9e6fabd23
Circle Line
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ...
[ "num = int(input())\nstations = list(map(int,list(input().split())))\npoints = sorted(list(map(int,list(input().split()))))\n\nsum1 = sum(stations[points[0]-1:points[1]-1])\nsum2 = sum(stations) - sum(stations[points[0]-1:points[1]-1])\n\nif sum1 < sum2:\n print(sum1)\nelse:\n print(sum2)\n\t \t \t \t\t\t\t ...
{"inputs": ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1", "5\n16 13 10 30 15\n4 2", "6\n89 82 87 32 67 33\n4 4", "7\n2 3 17 10 2 2 2\n4 2", "3\n4 37 33\n3 3", "8\n87 40 96 7 86 86 72 97\n6 8", "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "34...
UNKNOWN
PYTHON3
CODEFORCES
295
f93d8e4fa0765000b58f5a3f530474f7
Kay and Snowflake
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of *n* nodes. The root of tree has index 1. Kay is very intereste...
[ "# [https://codeforces.com/contest/685/submission/42128998 <- https://codeforces.com/contest/685/status/B <- https://codeforces.com/contest/685 <- https://codeforces.com/blog/entry/45556 <- https://codeforces.com/problemset/problem/685/B <- https://algoprog.ru/material/pc685pB]\r\n\r\nimport bisect\r\n\r\nn, q = [i...
{"inputs": ["7 4\n1 1 3 3 5 3\n1\n2\n3\n5", "2 2\n1\n1\n2"], "outputs": ["3\n2\n3\n6", "2\n2"]}
UNKNOWN
PYTHON3
CODEFORCES
2
f948aec78c25fd48780db400dd2e905b
Rank List
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
[ "a,b = map(int,input().split())\r\nmat = []\r\nfor i in range(a) :\r\n arr = list(map(int,input().split()))\r\n mat.append(arr)\r\nmat = sorted(mat, key = lambda x : (-x[0],x[1]))\r\nprint(mat.count(mat[b-1]))", "n,k = map(int,input().split())\r\na,d = [],{}\r\nfor i in range(n):\r\n\tl = tuple(map(int,inpu...
{"inputs": ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "3 2\n3 3\n3 3\n3 3", "4 3\n10 3\n6 10\n5 2\n5 2", "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "3 1\n2 1\n1 1\n1 2", "1 1\n28 28", ...
UNKNOWN
PYTHON3
CODEFORCES
143
f971e5a1ca10583a10bfb7fe8f0d6ebd
Points on Line
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
[ "import sys\r\ninput = sys.stdin.readline\r\ndef inInt():\r\n return int(input())\r\ndef inStr():\r\n return input().strip(\"\\n\")\r\ndef inIList():\r\n return(list(map(int,input().split())))\r\ndef inSList():\r\n return(input().split())\r\n\r\ndef solve(case, d):\r\n ans = 0\r\n j = 0\r\n for...
{"inputs": ["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50", "10 5\n31 36 43 47 48 50 56 69 71 86", "10 50\n1 4 20 27 65 79 82 83 99 100", "10 90\n24 27 40 41 61 69 73 87 95 97", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -4...
UNKNOWN
PYTHON3
CODEFORCES
271
f992f4c7e4d9227cecb52b2bd79864d2
Grandfather Dovlet’s calculator
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typi...
[ "d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\r\na, b = map(int, input().split())\r\n \r\nnums = str(list(range(a, b+1)))\r\nr = 0\r\nfor i in range(len(d)):\r\n r += d[i] * nums.count(str(i))\r\nprint(r)", "f=lambda:map(int,input().split())\r\na=[6,2,5,5,4,5,6,3,7,6]\r\nsm=0\r\nx,y=f()\r\ns=str(list(range(x,y+1)))\r\nf...
{"inputs": ["1 3", "10 15", "1 100", "100 10000", "213 221442", "1 1000000", "1000000 1000000", "222145 353252", "2 1000000", "1 999999", "192 200"], "outputs": ["12", "39", "928", "188446", "5645356", "28733372", "38", "3860750", "28733370", "28733334", "122"]}
UNKNOWN
PYTHON3
CODEFORCES
111
f9a7d083273864ce5cfc8a3db52acfc5
Strongly Connected City
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes...
[ "n, m = map(int, input(\"\").split())\r\nrow_order = [ char for char in input(\"\")]\r\ncol_order = [char for char in input(\"\")]\r\n\r\nclass Node():\r\n def __init__(self, id):\r\n self.row_id, self.col_id = id\r\n self.children = []\r\n\r\n def add_child(self, child_node_id):\r\n sel...
{"inputs": ["3 3\n><>\nv^v", "4 6\n<><>\nv^v^v^", "2 2\n<>\nv^", "2 2\n>>\n^v", "3 3\n>><\n^^v", "3 4\n>><\n^v^v", "3 8\n>><\nv^^^^^^^", "7 2\n<><<<<>\n^^", "4 5\n><<<\n^^^^v", "2 20\n><\n^v^^v^^v^^^v^vv^vv^^", "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^", "20 2\n<><<><<>><<<>><><<<<\n^^", "20 2\n><>><>><>><<<><<><><\n^v", "11 12\...
UNKNOWN
PYTHON3
CODEFORCES
129
f9a85cbfe549efd66c2fb1f532902fe2
Jamie and Binary Sequence (changed after round)
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. ...
[ "from heapq import heapify,heappop,heappush\r\nn, k = map(int, input().split())\r\nheap1 = []\r\nheap2 = []\r\nMAX = int(1e5)+10\r\ns = []\r\nheapify(heap1)\r\nheapify(heap2)\r\ni = 0\r\ncnt = 0\r\nwhile 1 << i <= n:\r\n if 1<<i & n: heappush(heap1,-i);heappush(heap2,-i);cnt += 1\r\n i += 1\r\nif cnt > k: pri...
{"inputs": ["23 5", "13 2", "1 2", "1 1", "1000000000000000000 100000", "7 2", "7 3", "7 4", "521325125150442808 10", "498518679725149504 1000", "464823731286228582 100000", "1 4", "9 4", "3 4", "144 4", "59 4", "78 4", "192 4", "107 4", "552 5", "680 5", "808 5", "1528 5", "1656 5", "26972 8", "23100 8", "19228 8", "2...
UNKNOWN
PYTHON3
CODEFORCES
8
f9c5a5763559e747e28b34dcacc8f6e9
Difference Row
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu...
[ "def main():\n n = int(input())\n nums = sorted(list(map(int, input().split(' '))))\n temp = nums[0]\n nums[0] = nums[-1]\n nums[-1] = temp\n print(' '.join(map(str, nums)))\n\nmain()\n", "\r\ninput()\r\na=list(map(int,input().split()))\r\na=sorted(a)\r\nb=a[1:len(a)-1]\r\nb=sorted(b)\r\n#print(...
{"inputs": ["5\n100 -100 50 0 -50", "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939", "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 28...
UNKNOWN
PYTHON3
CODEFORCES
144
f9e30533a717a56cf7677d43d0cff780
Ball
*N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ...
[ "from bisect import bisect_left as lower_bound\r\nfrom bisect import bisect_right as upper_bound\r\n\r\n# SortedList ( akin to ordered multiset )\r\n# A = SortedList() or A = SortedList([123,456,321,77])\r\n# A.insert(777)\r\n# A.pop(1)\r\n# A[0] , A[-1]\r\n# A.count(777)\r\n# A.lower_bound(456)\r\n# A.upper_bound(...
{"inputs": ["3\n1 4 2\n4 3 2\n2 5 3", "5\n2 8 10 0 7\n7 7 3 0 10\n2 8 3 2 2", "5\n3 0 0 2 0\n7 10 7 4 0\n9 1 6 1 9", "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5", "5\n9 7 0 2 10\n8 6 5 5 9\n1 9 3 0 1", "10\n7 7 10 1 2 1 7 1 5 9\n9 10 6 2 5 6 7 7 5 5\n2 7 4 0 7 10 5 6 2 2", "10\n7 7 0 1 2 6 0 10 3 5\n5 8 4 0 3 4 7 10 5 0\n0 10...
UNKNOWN
PYTHON3
CODEFORCES
2
f9eb516e2cbf8e42e3e834b5fb2eebba
The Child and Homework
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The chi...
[ "a=['0']*4\r\nb=[\"\"]*4\r\nc=[0]*4\r\nfor i in range(4):\r\n a[i],b[i]=map(str,input().split('.'))\r\n c[i]=len(b[i])\r\nc=sorted(c)\r\nx=0\r\nif(c[0]*2<=c[1]):\r\n x=1\r\nif(c[2]*2<=c[3]):\r\n if(x==0):\r\n x=2\r\n else:\r\n x=0\r\nif(x==1):\r\n for i in range(4):\r\n if(len...
{"inputs": ["A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "A.ab\nB.abcde\nC.ab\nD.abc", "A.c\nB.cc\nC.c\nD.c", "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_b...
UNKNOWN
PYTHON3
CODEFORCES
142
f9ee988bce99481ccbaa17ab2d8b86b1
Mysterious numbers - 2
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces. Output a single integer. The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces. Output a single integer. Sample Input 2 3 2 13 14 ...
[ "a,b,c=eval(input().replace(' ',','))\ndef func(x):\n if x==0:\n return a\n if x==1:\n return b\n return func(x-1)+func(x-2)\nprint(func(c))", "a, b, c = map(int, input().split())\r\nexec('a, b = b, a + b;' * c)\r\nprint(a)", "a, s, n = map(int, input().split())\r\nfor i in range(n):\r\n ...
{"inputs": ["2 3 2", "13 14 1", "14 5 9", "17 18 3", "1 1 1", "4 6 7", "1 1 20", "20 20 1", "20 20 20", "12 9 18", "1 19 15", "5 5 5", "10 11 12", "3 7 17", "8 2 9"], "outputs": ["5", "14", "464", "53", "1", "110", "10946", "20", "218920", "42420", "11967", "40", "2474", "14140", "236"]}
UNKNOWN
PYTHON3
CODEFORCES
17
f9fcb4af74ccacc29497705beb13400c
One-Way Reform
There are *n* cities and *m* two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roa...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\nline = lambda : [int(x) for x in input().split()]\r\n\r\ndef ecyc(graph: list[list[int]], edges: list[int]) -> list[list[int]]:\r\n \"\"\"Finds euler cycles of `graph`\r\n\r\n\r\nCan only be used if all degrees of nodes in `graph` are even. If the\r\ngraph ...
{"inputs": ["2\n5 5\n2 1\n4 5\n2 3\n1 3\n3 5\n7 2\n3 7\n4 2", "4\n9 17\n3 6\n2 6\n6 9\n4 1\n2 8\n1 9\n7 9\n8 5\n1 7\n4 9\n6 7\n3 4\n9 3\n8 4\n2 1\n3 8\n2 7\n5 6\n2 5\n3 4\n1 3\n4 5\n5 3\n2 3\n12 8\n10 2\n9 2\n6 9\n10 6\n8 2\n4 10\n11 2\n4 11\n19 10\n6 2\n3 12\n17 7\n2 19\n17 4\n1 13\n7 1\n13 7\n6 8\n11 7", "1\n200 0", ...
UNKNOWN
PYTHON3
CODEFORCES
2
fa0b50fbf360b509f5fb8c307ce28ba4
Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
[ "# بسم الله الرحمن الرحيم\r\n# صلو على نبينا محمد صلى الله عليه و سلم\r\n\r\n\r\n##############--->>>>> Mohamed Mostafa Mohamed Abdelhamed <<<<<---##############\r\n\r\n\"\"\"\r\n ____ _ _____ \r\n / ___|___ __| | ___| ___|__ _ __ ___...
{"inputs": ["heavymetalisheavymetal", "heavymetalismetal", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua", "metametaheavyetalalmetalavylkeoheavyhemetaleavycdk", "hg"], "outputs": ["3", "2", "3", "5", "3", "...
UNKNOWN
PYTHON3
CODEFORCES
9
fa95baebd3d1219835ac38b5de362bb9
Roma and Changing Signs
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s...
[ "n, m = map(int, input(). split())\r\narr = list(map(int, input(). split()))\r\nq = 0\r\nfor i in range(min(n, m)):\r\n if arr[i] < 0:\r\n arr[i] *= (-1)\r\n q += 1\r\n else:\r\n break\r\nif m <= q:\r\n print(sum(arr))\r\nelse:\r\n if (m - q) % 2:\r\n arr. sort()\r\n p...
{"inputs": ["3 2\n-1 -1 1", "3 1\n-1 -1 1", "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5...
UNKNOWN
PYTHON3
CODEFORCES
79
fa9e6b7e16715652317cbfb661c3b1f5
none
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe...
[ "n = int(input())\r\ns = str(input())\r\nl = int(len(s))\r\nans = \"\"\r\ncnt = 0\r\ns += '$'\r\nfor i in range (l) :\r\n if (s[i] != 'a' and s[i] != 'e' and s[i] != 'i' and s[i] != 'o' and s[i] != 'u' and s[i] != 'y'):\r\n ans += s[i]\r\n continue\r\n cnt += 1\r\n if (s[i] != s[i + 1]):\r\n ...
{"inputs": ["13\npobeeeedaaaaa", "22\niiiimpleeemeentatiioon", "18\naeiouyaaeeiioouuyy", "24\naaaoooiiiuuuyyyeeeggghhh", "36\naeiouyaaeeiioouuyyaaaeeeiiiooouuuyyy", "100\noiyufyyyioueoudosizoryuoedatenougiuaeuouuyoiimaeigeeycewuooyovacoiyuaygfuuaiaeuahuieeafxsciylaebeufi", "200\nmmffggzvuuzzlkafduueqocuybiiaaeeoiioouaa...
UNKNOWN
PYTHON3
CODEFORCES
48
faad69b01b68c5b762c9f2b9f2e0453f
Anti-Palindromize
A string *a* of length *m* is called antipalindromic iff *m* is even, and for each *i* (1<=≤<=*i*<=≤<=*m*) *a**i*<=≠<=*a**m*<=-<=*i*<=+<=1. Ivan has a string *s* consisting of *n* lowercase Latin letters; *n* is even. He wants to form some string *t* that will be an antipalindromic permutation of *s*. Also Ivan has de...
[ "import sys\r\nfrom heapq import heappop, heappush\r\n\r\nclass Edge:\r\n def __init__(self, u, v, cap, cost, rev):\r\n self.u = u\r\n self.v = v\r\n self.cap = cap\r\n self.flow = 0\r\n self.cost = cost\r\n self.rev = rev\r\n\r\ndef add_edge(adj, u, v, capv, costv):\r\n...
{"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1", "8\nabaccaba\n1 2 3 4 5 6 7 8", "8\nabacabca\n1 2 3 4 4 3 2 1", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 74 94 4...
UNKNOWN
PYTHON3
CODEFORCES
2
fab2904a98f86333c60dab6a407ca40b
Coloring a Tree
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On eac...
[ "N = int(input())\ncon = [0]\nvert = [i for i in range(1,N+1)]\na = input().split(\" \")\nfor i in range(N-1):\n con.append(int(a[i])-1)\ncolor=[]\na = input().split(\" \")\nfor i in range(N):\n color.append(int(a[i]))\ncur = [color[0] for i in range(N)]\nsteps=1\nfor i in range(1,N):\n if cur[con[i]]==col...
{"inputs": ["6\n1 2 2 1 5\n2 1 1 1 1 1", "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "2\n1\n2 2", "3\n1 1\n2 2 2", "4\n1 2 1\n1 2 3 4", "4\n1 2 3\n4 1 2 4", "5\n1 2 1 4\n1 1 1 2 2", "3\n1 2\n2 1 1", "4\n1 1 1\n3 1 3 1", "4\n1 1 2\n4 1 4 1", "4\n1 2 2\n3 1 2 3", "3\n1 1\n1 2 2"], "outputs": ["3", "5", "1", "1", "4", "4", "2", "2",...
UNKNOWN
PYTHON3
CODEFORCES
136
fb0053531c0e388ce49fc51a56856d5c
Coprime Arrays
Let's call an array *a* of size *n* coprime iff *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1, where *gcd* is the greatest common divisor of the arguments. You are given two numbers *n* and *k*. For each *i* (1<=≤<=*i*<=≤<=*k*) you have to determine the number of coprime arrays *a* of size *n* such that for every *j* (1<=≤<...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\nans = 0\r\np2 = [pow(i, n, mod) for i in range(k + 1)]\r\ndp0 = [1] * (k + 1)\r\ndp = [0] * (k + 1)\r\ncnt = 0\r\nfor i in range(2, k + 1):\r\n dp0i = dp0[i]\r\n dp[i] += dp0i\r\n dp[i] %= mod\r\n ...
{"inputs": ["3 4", "2000000 8", "1000 1000", "400000 400000", "1000 2000", "400000 800000", "1000 3000", "400000 1200000", "1000 4000", "400000 1600000", "1000 5000", "400000 2000000", "2000 1000", "800000 400000", "2000 2000", "800000 800000", "2000 3000", "800000 1200000", "2000 4000", "800000 1600000", "2000 5000", ...
UNKNOWN
PYTHON3
CODEFORCES
3
fb0ee76ebf2e3c8996349f51635551f9
Heads or Tails
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by t...
[ "x,y,a,b=map(int,input().split())\r\nd=list()\r\nfor i in range(a,x+1):\r\n for j in range(b,y+1):\r\n if j<i:\r\n d.append((i,j))\r\nprint(len(d))\r\nfor el in d:\r\n print(*el)", "x,y,a,b=map(int,input().split())\r\ns=[]\r\nfor i in range(a,x+1):\r\n for j in range(b,y+1):\r\n ...
{"inputs": ["3 2 1 1", "2 4 2 2", "1 1 1 1", "4 5 2 3", "10 6 3 4", "10 10 1 1", "9 7 4 7", "5 5 3 2", "10 10 1 1", "20 10 1 8", "10 20 4 6", "50 50 1 30", "60 50 30 40", "100 100 1 1", "100 99 10 13", "99 100 20 7", "100 90 100 83", "80 100 1 50", "100 39 70 5", "70 80 30 80", "100 100 1 1", "100 100 100 5", "99 99 1 ...
UNKNOWN
PYTHON3
CODEFORCES
67
fb100470ea9dd5ea633506679773b01e
Poster
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of *n* characters, so the decorators hung a l...
[ "n,k=map(int,input('').split()) \r\nlozung=list(input())\r\nif n-k<k:\r\n for i in range(k,n):\r\n print('RIGHT')\r\n for i in reversed(range(0,n)):\r\n print ('PRINT ',lozung[i])\r\n if i!=0:print('LEFT')\r\nelse:\r\n# print('2')\r\n for i in reversed(range(0,k-1)...
{"inputs": ["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!", "7 3\nME,YOU.", "10 1\nEK5JQMS5QN", "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK", "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F", "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHS...
UNKNOWN
PYTHON3
CODEFORCES
110
fb31e30d59f65c09b714f42e0893a6fa
Birds
Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp needs strong magic. There are *n* trees in a row on an alley in a park, there is a nest on each of the trees. In the *i*-th nest there are *c**i* birds; to summon one bird from this nest Imp needs to stay under this tree and it costs...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, w, b, x = map(int, input().split())\r\nc = list(map(int, input().split()))\r\ncost = list(map(int, input().split()))\r\ndp0 = [w]\r\ns = 0\r\ninf = pow(10, 15) + 1\r\nfor i, u in zip(c, cost):\r\n s += i\r\n dp = [-1...
{"inputs": ["2 12 0 4\n3 4\n4 2", "4 1000 10 35\n1 2 4 5\n1000 500 250 200", "2 10 7 11\n2 10\n6 1", "5 1 4 6\n3 4 6 5 1\n3 0 10 2 9", "75 262 870 596\n22 13 37 6 15 25 5 1 2 13 6 3 14 7 8 15 6 15 10 3 1 21 33 2 7 14 17 7 4 9 16 29 31 4 31 16 3 11 13 38 3 14 8 18 9 3 1 10 1 5 10 16 7 5 33 9 24 9 8 13 3 31 8 18 33 17 22...
UNKNOWN
PYTHON3
CODEFORCES
1
fb358ff1430bb7b1c364bc7027e80b87
Leaving the Bar
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$. Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th...
[ "def my_cmp(x):\r\n if x[0] == 0:\r\n return float('inf')\r\n return x[1]/x[0]\r\n\r\ndef dis(a, b):\r\n return a*a + b*b\r\n\r\nn = int(input())\r\nv = []\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n v.append((x, y, i))\r\nv.sort(key = my_cmp)\r\nx, y = 0, 0\r\nans = [0]*n\r...
{"inputs": ["3\n999999 0\n0 999999\n999999 0", "1\n-824590 246031", "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899", "6\n1000000 0\n1000000 0\n-1000000 0\n0 1000000\n0 -1000000\n0 -1000000", "8\n-411248 143802\n300365 629658\n363219 343742\n396148...
UNKNOWN
PYTHON3
CODEFORCES
3
fb35ad5ba58debd68f0aba5949e0c149
Little Artem and Presents
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art...
[ "a = int(input())\r\nprint(a // 3 * 2 + (a % 3 > 0))", "def solve(n):\n if n == 1:\n return 1\n return n-round(n/3)\n \ndef main():\n n =int(input())\n print(solve(n))\n\nmain()", "n=int(input())\r\nprint((((n*2)+1))//3) ", "n=int(input())\r\nt=(n//3)*2\r\nprint(1+t if n%3 else t)", "n = int(input...
{"inputs": ["1", "2", "3", "4", "100", "101", "102", "1000000000", "5", "6", "999999999", "999999998", "999999997", "999999996", "999999995", "999999994", "999999993", "999999992", "999999991", "1000", "10000", "100000", "1000000", "10000000", "100000000", "7"], "outputs": ["1", "1", "2", "3", "67", "67", "68", "666666...
UNKNOWN
PYTHON3
CODEFORCES
365
fb4f19ca832f912bcbe6c0aec5b2d3cd
Chat Online
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it d...
[ "p,q,l,r =map(int,input().split())\r\nll,kk=set(),[]\r\nfor _ in range(p):\r\n x,y=map(int,input().split())\r\n for i in range(x,y+1):\r\n ll.add(i)\r\nfor _ in range(q):\r\n x,y=map(int,input().split())\r\n kk.append([x,y])\r\nres=0\r\nfor i in range(l,r+1):\r\n flag=False\r\n for m in kk:...
{"inputs": ["1 1 0 4\n2 3\n0 1", "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "5 2 27 452\n148 154\n421 427\n462 470\n777 786\n969 978\n245 247\n313 322", "3 6 25 785\n273 275\n391 397\n775 783\n84 89\n348 354\n480 483\n552 556\n711 716\n838 844", "1 6 364 421\n649 688\n31 39\n438 441\n516 524\n609 615\n708 710\n850 851...
UNKNOWN
PYTHON3
CODEFORCES
8
fb638f1ba3ca020d1c377de702d1dada
Substrings Sort
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su...
[ "n=int(input())\r\nstringVector=[]\r\nfor i in range(n):\r\n stringVector.append(input())\r\nstringVector=list(sorted(stringVector, key=lambda x: (-len(x),x)))[::-1]\r\nok=\"YES\"\r\nfor i in range(n-1):\r\n if stringVector[i] not in stringVector[i+1]:\r\n ok=\"NO\"\r\n break\r\nprint(ok)\r\nif ...
{"inputs": ["5\na\naba\nabacaba\nba\naba", "5\na\nabacaba\nba\naba\nabab", "3\nqwerty\nqwerty\nqwerty", "1\nwronganswer", "3\na\nb\nab", "2\nababaab\nabaab", "2\nq\nqq", "5\nabab\nbab\nba\nab\na", "3\nb\nc\nd", "3\naba\nbab\nababa", "4\na\nba\nabacabac\nb", "4\nab\nba\nabab\na", "3\naaa\naab\naaab", "2\nac\nabac", "2\n...
UNKNOWN
PYTHON3
CODEFORCES
169
fb72cf1ab655d21cc8e2271adda07ca1
Guess the Permutation
Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n...
[ "w=eval(input())\r\nh=w\r\nMatrix = [[0 for x in range(w)] for y in range(h)] \r\ni=0\r\nwhile (i<w):\r\n Matrix[i]=list(map(int,input().split()))\r\n i+=1\r\ni=0\r\nwhile(i<w):\r\n a=set(Matrix[i])\r\n if (len(a)<len(Matrix[i])):\r\n i+=1\r\n else:\r\n s=Matrix[i]\r\n k=0\r\...
{"inputs": ["2\n0 1\n1 0", "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1 6 2 0 3 4 8 8 7\n3 1 3 2 3 0 3 3 3 3\n4 1 4 2 4 3 0 4 4 4\n5 1 6 2 8 3 4 0 9 7\n5 1 6 2 8 3 4 9 0 7\n5 1 6 2 7 3 4 7 7 0", "4\n0 1 3 2\n1 0 ...
UNKNOWN
PYTHON3
CODEFORCES
123
fb74f0c531da115dd79246f7353102f6
Ace It!
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer. The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits....
[ "a=str(input())\ns=0\nfor i in range(len(a)):\n if a[i]=='A':\n s+=1\n elif a[i]=='1':\n s+=10\n else:\n s+=int(a[i])\nprint(s)", "s = list(input())\ndex = 0\nfor i in s:\n if i == \"A\":\n dex += 1\n elif i == \"1\":\n dex += 10\n else:\n dex += int(i)\...
{"inputs": ["A221033", "A223635", "A232726", "A102210", "A231010", "A222222", "A555555", "A102222", "A234567", "A987654", "A101010", "A246810", "A210210", "A458922", "A999999", "A888888", "A232232", "A222210", "A710210", "A342987", "A987623", "A109109", "A910109", "A292992", "A388338", "A764598", "A332567", "A108888", ...
UNKNOWN
PYTHON3
CODEFORCES
43
fb9cfeffe8719c2c83cb84f4009cb5d2
Little Elephant and Broken Sorting
The Little Elephant loves permutations of integers from 1 to *n* very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1,<=2,<=3,<=...,<=*n*. This time the Little Elephant has permutation *p*1,<=*p*2,<=......
[ "import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heapp...
{"inputs": ["2 1\n1 2\n1 2", "4 3\n1 3 2 4\n1 2\n2 3\n1 4", "7 4\n7 6 4 2 1 5 3\n1 3\n2 1\n7 2\n3 5", "10 1\n1 2 3 4 5 6 7 8 9 10\n1 10", "9 20\n9 8 7 6 5 4 3 2 1\n4 6\n9 4\n5 9\n6 8\n1 9\n5 8\n6 9\n7 3\n1 9\n8 3\n4 5\n9 6\n3 8\n4 1\n1 2\n3 2\n4 9\n6 7\n7 5\n9 6", "20 7\n3 17 7 14 11 4 1 18 20 19 13 12 5 6 15 16 9 2 8 ...
UNKNOWN
PYTHON3
CODEFORCES
1
fbd08e2f563c304ba65fe1928a5c64af
none
You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide. We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from the given set such that angle between vectors and is acute (i.e. strictly less than ). Otherwise, the poin...
[ "import sys\r\nimport math\r\n\r\nn = int(input())\r\nif(n > 20):\r\n print(0)\r\n sys.exit()\r\n\r\npoints = []\r\nfor i in range(n):\r\n p = list(map(int, input().split()))\r\n points.append(p)\r\n\r\ngood = []\r\n\r\nclass Vector:\r\n def __init__(self, first, last):\r\n self.elems = [last[...
{"inputs": ["6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0", "1\n0 0 0 0 0", "2\n0 1 2 3 4\n5 6 7 8 9", "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -...
UNKNOWN
PYTHON3
CODEFORCES
24
fbd8081c2cfde92f282508744d168fcb
Bulls and Cows
The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all...
[ "import sys\nlines = sys.stdin.readlines()\nn = int(lines[0].strip())\nquery = []\nfor i in range(1, n+1):\n (a, b, c) = lines[i].strip().split(\" \")\n query.append((a, int(b), int(c)))\ndef compare(i):\n digits = str(i)\n digits = \"0\" *(4-len(digits)) + digits\n if len(set(list(digits))) != 4: re...
{"inputs": ["2\n1263 1 2\n8103 2 1", "2\n1234 2 2\n1256 0 2", "2\n0123 1 1\n4567 1 2", "1\n1234 0 0", "4\n4789 1 0\n7189 1 0\n7829 1 0\n7893 1 0", "4\n1789 1 0\n7198 1 0\n9817 1 0\n8971 1 0", "6\n1234 3 0\n1235 3 0\n1236 3 0\n1237 3 0\n1238 3 0\n1239 3 0", "3\n0123 0 4\n1230 0 4\n3012 0 4", "1\n0714 1 1", "2\n0159 1 0\...
UNKNOWN
PYTHON3
CODEFORCES
14
fbe7c79a79bced6e28d91c1e7989b060
Fortune Telling
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a...
[ "n=int(input())\r\na=sorted(map(int,input().split()))\r\nb,c=0,-1\r\nfor i in a:\r\n b+=i\r\n if i%2==1 and c==-1:\r\n c=i\r\nif b%2:\r\n print(b)\r\nelse:\r\n print(0 if c==-1 else b-c)", "import re\r\nimport sys\r\nfrom bisect import bisect, bisect_left, insort, insort_left\r\nfrom collection...
{"inputs": ["1\n1", "1\n2", "3\n5 6 7", "2\n5 7", "3\n1 2 3", "4\n4 3 1 2", "10\n90 72 76 60 22 87 5 67 17 65", "10\n18 42 20 68 88 10 87 37 55 51", "100\n25 43 35 79 53 13 91 91 45 65 83 57 9 41 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 4...
UNKNOWN
PYTHON3
CODEFORCES
58
fc15856b0b1fce8b88f14daf45f5346a
Painting Fence
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from o...
[ "import sys\r\n\r\n# import math\r\n# import os\r\n# import random\r\n# from bisect import bisect, bisect_left\r\n# from collections import *\r\n# from functools import reduce\r\n# from heapq import heapify, heappop, heappush\r\n# from itertools import *\r\n# from io import BytesIO, IOBase\r\n# from string import *...
{"inputs": ["5\n2 2 1 2 1", "2\n2 2", "1\n5", "5\n2 2 1 2 2", "5\n2 2 1 5 1", "1\n1", "1\n1000000000", "2\n999635584 999595693", "10\n3 3 6 4 2 3 2 2 3 3", "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4", "6\n100 100 100 100 100 1", "7\n5 5 1 5 5 4 1", "4\n3 4 5 6", "4\n2 3 4 5", "8\n5000 5000 5 5000 5000 5000 5000 5000", "10\n4 4 4...
UNKNOWN
PYTHON3
CODEFORCES
5
fc1b001cfed3da5734fdd1993f262d18
Demiurges Play Again
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on *n* nodes, *m* of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves...
[ "import sys\r\nfin = sys.stdin\r\nn = int(fin.readline())\r\nut = [-1] * n\r\nvc = [[] for i in range(0, n)]\r\ncvc = [[] for i in range(0, n)]\r\nnr = [0] * n\r\nfor i in range(0, n - 1):\r\n a, b = [int(number) for number in fin.readline().split()]\r\n a -= 1\r\n b -= 1\r\n vc[a].append(b)\r\n cvc[...
{"inputs": ["5\n1 2\n1 3\n2 4\n2 5", "6\n1 2\n1 3\n3 4\n1 5\n5 6", "1", "2\n1 2", "3\n1 2\n1 3", "10\n1 2\n1 3\n3 4\n3 5\n4 6\n1 7\n3 8\n2 9\n6 10", "50\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n2...
UNKNOWN
PYTHON3
CODEFORCES
1
fc3f5cc330553f4dda9bd40e698161f3
Quantity of Strings
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly *n*, based on the alphabet of size *m*. Any its substring with length equal to *k* is a palindrome. How many such strings exist? Your task ...
[ "n, m, k = map(int, input().split())\r\nmod = 1000000007\r\n\r\nans = pow(m, n, mod) if k == 1 or k > n else (\r\n pow(m, (n + 1) >> 1, mod) if k == n else (m * m if k & 1 else m))\r\n\r\nprint(ans)\r\n", "n, m, k = input().split(' ')\nn = int(n)\nm = int(m)\nk = int(k)\nif k > n:\n\tprint(pow(m, n, 1000000007...
{"inputs": ["1 1 1", "5 2 4", "7 4 20", "8 13 9", "10 23 9", "10 25 8", "997 1752 1000", "784 1 1999", "341 9 342", "777 1 777", "542 13 542", "1501 893 1501", "1321 95 2", "2000 1000 3", "1769 849 1000", "1000 2 1", "345 1777 1", "1999 2000 2000", "1984 1847 1992", "2000 2000 2000", "1451 239 1451", "2000 2000 1", "12...
UNKNOWN
PYTHON3
CODEFORCES
15
fc5b374c0c467d1243d8dce71f849633
Remove Duplicates
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. The first line contains a single integer $n$ ($1 \le n \...
[ "no_inputs = int(input())\nnums = list(map(int, input().split()))\n\nunique_nums = []\nfor num in nums[::-1]:\n if num not in unique_nums:\n unique_nums.append(num)\nprint(len(unique_nums))\nprint(\" \".join(str(item) for item in unique_nums[::-1]))\n\n\t\t\t\t \t \t\t\t\t\t \t \t \t\t\t\t\t\t \t \t\t"...
{"inputs": ["6\n1 5 5 1 6 1", "5\n2 4 2 4 4", "5\n6 6 6 6 6", "7\n1 2 3 4 2 2 3", "9\n100 100 100 99 99 99 100 100 100", "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 ...
UNKNOWN
PYTHON3
CODEFORCES
191
fc7661143e4b4a08461bb4de57185e76
Connecting Universities
Treeland is a country in which there are *n* towns connected by *n*<=-<=1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2*k* universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network...
[ "from collections import defaultdict\r\ndef put(): return map(int, input().split())\r\n\r\ndef dfs():\r\n s = [(1,0)]\r\n ans = 0\r\n vis = [0]*(n+1)\r\n while s:\r\n i,p = s.pop()\r\n if vis[i]==0:\r\n vis[i]=1\r\n s.append((i,p))\r\n for j in tree[i]:\r\n...
{"inputs": ["7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6", "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8", "41 3\n11 10 15 35 34 6\n28 2\n25 3\n9 4\n11 5\n7 6\n24 7\n19 8\n1 9\n34 10\n23 11\n17 12\n32 13\n32 14\n32 15\n33 16\n8 17\n19 18\n40 19\n15 20\n6 21\n41 22\n35 23\n13 24\n6 25\n22 26\n4 27\n31 28\n34 ...
UNKNOWN
PYTHON3
CODEFORCES
7
fc7f2f0fe3c4df9f28490f80781ce3fe
The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob go...
[ "#!/usr/bin/pypy3\n\nfrom sys import stdin,stderr\nfrom collections import defaultdict\n\ndef readInts(): return map(int,stdin.readline().strip().split())\ndef print_err(*args,**kwargs): print(*args,file=stderr,**kwargs)\n \ndef dfs(n,g,b):\n s = [(1,0,1)]\n b_depth = 0\n parents = [ None for _ in range...
{"inputs": ["4 3\n1 2\n2 3\n2 4", "5 2\n1 2\n2 3\n3 4\n2 5", "2 2\n2 1", "3 3\n2 1\n3 1", "3 3\n1 2\n3 2", "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8", "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8", "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6", "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12...
UNKNOWN
PYTHON3
CODEFORCES
13
fc8112700bb19b73b5f2cb0b6e677aac
Robot Arm
Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is colored red and the endpoint at (*i*,<=0) is colored blue for all segments. Thus, the blue endpo...
[ "import math\r\no = 524288\r\npi = math.acos(-1)\r\na = [0] * (2 * o)\r\nx = [0.0] * (2 * o)\r\ny = [0.0] * (2 * o)\r\nz = [0] * (2 * o)\r\n\r\nn, m = map(int, input().split())\r\nfor i in range(n):\r\n a[i + o] = x[i + o] = 1\r\nfor i in range(o - 1, 0, -1):\r\n x[i] = x[i << 1] + x[i << 1 | 1]\r\nfor _ in r...
{"inputs": ["5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1", "1 1\n2 1 302", "50 50\n1 41 261\n2 47 324\n1 41 256\n1 31 339\n2 23 116\n2 44 184\n2 32 115\n1 40 301\n2 40 303\n1 29 309\n2 49 348\n2 47 356\n1 41 263\n2 42 276\n1 45 135\n1 33 226\n2 31 166\n1 50 171\n2 47 166\n2 50 284\n2 25 324\n2 48 307\n2 41 176\n1 50 353\n1 45 32...
UNKNOWN
PYTHON3
CODEFORCES
1
fc94946d03aa4b544ec22213ebaed643
Jury Size
In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the prob...
[ "from datetime import date, timedelta\r\nimport math\r\n\r\n\r\nw=open('output.txt', 'w')\r\nr=open('input.txt', 'r')\r\noplympiads = []\r\n\r\nmin_date = date(2014,1,1)\r\nmax_date = date(2011,1,1)\r\n\r\nn = int(r.readline())\r\n\r\nfor _ in range(n):\r\n m, d, p, t = map(int, r.readline().split())\r\n oply...
{"inputs": ["2\n5 23 1 2\n3 13 2 3", "3\n12 9 2 1\n12 8 1 3\n12 8 2 2", "1\n1 10 1 13", "3\n3 16 25 1\n3 15 9 34\n3 14 90 87", "4\n2 15 52 53\n2 15 35 81\n2 15 39 96\n2 14 87 7", "5\n3 6 40 89\n3 4 24 64\n2 28 83 1\n3 3 15 32\n3 8 54 28", "10\n8 8 4 18\n8 10 100 36\n8 9 17 51\n8 10 90 8\n8 10 64 45\n8 10 90 81\n8 11 20...
UNKNOWN
PYTHON3
CODEFORCES
9
fcc1dd7c8d355e18d211514350671eac
Curriculum Vitae
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer...
[ "n, a = int(input()), [int(x) for x in input().split()]\r\nprint(n - min([a[:i].count(1) + a[i + 1:].count(0) for i in range(n)]))\r\n", "n = int(input())\r\nm=list(map(int,input().split()))\r\nx=m.count(0)\r\ny=n-x\r\na=0\r\nb=0\r\nl=max(x,y)\r\nfor i in range(n):\r\n if m[i]==1:\r\n a+=1\r\n c=...
{"inputs": ["4\n1 1 0 1", "6\n0 1 0 0 1 0", "1\n0", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
88
fccff7b6eaf8ac7a2e50f9817666b74d
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
[ "maxn = 10**5 + 5\nmod = 10**9 + 7\ntest_case, k = map(int, input().split())\n\ndp = [0] * maxn\nsum = [0] * maxn\ndp[0] = 1\nfor i in range(1, maxn):\n dp[i] = dp[i - 1]\n if (i >= k):\n dp[i] = (dp[i] + dp[i - k]) % mod\nfor i in range(1, maxn):\n sum[i] = (sum[i - 1] + dp[i]) % mod\n\nfor _ in ra...
{"inputs": ["3 2\n1 3\n2 3\n4 4", "1 1\n1 3", "1 2\n64329 79425"], "outputs": ["6\n5\n5", "14", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
28
fcd19da2696717da4756587afbd33c82
Epic Game
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
[ "import math\r\na , b, n= [int(i) for i in input().split()]\r\nans = False\r\nwhile True:\r\n if ans == False:\r\n g = math.gcd(a,n)\r\n n -=g\r\n if n <=0:\r\n print(int(ans))\r\n break\r\n ans = not ans\r\n else:\r\n g = math.gcd(b,n)\r\n n -=g...
{"inputs": ["3 5 9", "1 1 100", "23 12 16", "95 26 29", "73 32 99", "1 1 1", "41 12 65", "13 61 100", "100 100 10", "12 24 26", "73 21 96", "17 22 81", "14 88 97", "42 81 17", "34 36 19", "21 87 12", "97 92 98", "49 25 62", "29 17 44", "10 1 10", "99 98 100", "100 100 1", "11 99 55", "8 13 21", "34 55 89", "21 34 55", ...
UNKNOWN
PYTHON3
CODEFORCES
780
fcf8b343a907be0b2bab4149edfec28a
Valhalla Siege
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
[ "def get_pos(curr, strength_left, arrow):\n l = curr\n h = n - 1\n\n while (l < h):\n m = (l + h) // 2\n strength_req = strength[m] - strength[curr] + strength_left\n if strength_req > arrow:\n h = m\n elif strength_req == arrow:\n return m\n else:\n...
{"inputs": ["5 5\n1 2 1 2 1\n3 10 1 1 1", "4 4\n1 2 3 4\n9 1 10 6", "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "1 1\n56563128\n897699770", "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4...
UNKNOWN
PYTHON3
CODEFORCES
129
fd02ef2593cc46942a3abcb5c85a76c8
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can...
[ "n, k = map(int, input().split())\r\np = [0 for i in range(n+1)]\r\nd = p.copy()\r\nfor i in range(k):\r\n a = list(map(int, input().split()))\r\n l = len(a)\r\n for j in range(1, l - 1):\r\n p[a[j]] = a[j+1]\r\n d[a[j+1]] = 1\r\nc = 1\r\nwhile p[c] == c + 1:\r\n c = p[c]\r\nans = 0\r\nfor...
{"inputs": ["3 2\n2 1 2\n1 3", "7 3\n3 1 3 7\n2 2 5\n2 4 6", "1 1\n1 1", "3 2\n1 2\n2 1 3", "5 3\n1 4\n3 1 2 3\n1 5", "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8", "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2", "20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 12 18 19\n4 1 3 6 16", "50 10\n6 17 21 31 42 45 49...
UNKNOWN
PYTHON3
CODEFORCES
36
fd0688f764c0b19252d911aef21b9a3b
AND-permutations
Given an integer *N*, find two permutations: 1. Permutation *p* of numbers from 1 to *N* such that *p**i*<=≠<=*i* and *p**i*<=&amp;<=*i*<==<=0 for all *i*<==<=1,<=2,<=...,<=*N*. 1. Permutation *q* of numbers from 1 to *N* such that *q**i*<=≠<=*i* and *q**i*<=&amp;<=*i*<=≠<=0 for all *i*<==<=1,<=2,<=...,<=*N*. &amp;...
[ "from math import log\r\nfrom sys import exit\r\nn = int(input())\r\na = [i for i in range(n + 1)]\r\n\r\ndef ans(n):\r\n if n <= 0 or n % 2:\r\n return\r\n j, cr = (1 << int(log(n, 2))), 1\r\n while j + cr - 1 <= n:\r\n a[j - cr], a[j + cr - 1] = a[j + cr - 1], a[j - cr]\r\n cr += 1\r...
{"inputs": ["3", "6", "100000", "15", "16", "17", "1", "2", "4", "5", "7", "8", "9", "10", "31", "32", "33", "63", "64", "65", "127", "128", "129", "255", "256", "257", "511", "512", "513", "1023", "1024", "1025", "2047", "2048", "2049", "4095", "4096", "4097", "8191", "8192", "8193", "16383", "16384", "16385", "32767"...
UNKNOWN
PYTHON3
CODEFORCES
1
fd06e19867352ee76d0b1a3b9ab11217
Ann and Books
In Ann's favorite book shop are as many as *n* books on math and economics. Books are numbered from 1 to *n*. Each of them contains non-negative number of problems. Today there is a sale: any subsegment of a segment from *l* to *r* can be bought at a fixed price. Ann decided that she wants to buy such non-empty subs...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v, w):\r\n return (u * m + v) * m + w\r\n\r\nn, k = map(int, input().split())\r\nt = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nu = [0] * (n + 1)\r\nfor i in range(n):\r\n x = a[i...
{"inputs": ["4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4", "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4", "10 10\n2 1 1 1 1 1 1 1 1 2\n0 10 10 0 0 10 10 10 10 0\n10\n4 10\n3 7\n9 9\n2 9\n10 10\n5 5\n2 2\n6 8\n3 4\n1 3", "10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8", "1...
UNKNOWN
PYTHON3
CODEFORCES
2
fd09090ef729ff93446db38cf1352d0b
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
[ "s=input()\r\nn=int(input())\r\nm=\"z\"\r\nf=0\r\nfor i in range(n):\r\n t=input()\r\n if t.find(s)==0:\r\n f=1\r\n if t<=m:\r\n m=t\r\nif f==0:\r\n print(s)\r\nelse:\r\n print(m)", "x=str(input());ans=\".\";ln = len(x)\r\nfor i in range(int(input())):\r\n\ts=str(input())\r\n\...
{"inputs": ["next\n2\nnextpermutation\nnextelement", "find\n4\nfind\nfindfirstof\nfindit\nfand", "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "dzwzyj\n7\nwvixktp\...
UNKNOWN
PYTHON3
CODEFORCES
135
fd0a5d9f400dd636829e4e517f91376f
Friends and Presents
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the...
[ "def main():\r\n cnt1, cnt2, x, y = list(map(int, input().split()))\r\n l, r = -1, 10**18\r\n ans = 10**18\r\n while l+1 < r:\r\n v = (l + r) // 2\r\n if max(cnt1 - v // y + v//(x*y), 0) + max(cnt2 - v // x + v // (x*y), 0)<= v - v//x - v//y + v // (x * y):\r\n ans = min(ans, v)...
{"inputs": ["3 1 2 3", "1 3 2 3", "916200 69682 2 3", "808351 17767 433 509", "8851 901 20897 26183", "5099 2895 16273 29473", "5099 2895 16273 29473", "4969 694 293 2347", "683651932 161878530 2 5", "325832598 637961741 2 3", "999999999 1 2 3", "11006 976 6287 9007", "150064728 173287472 439 503", "819712074 101394406...
UNKNOWN
PYTHON3
CODEFORCES
33
fd147d05260e80bd25ba2a334bf9f277
Comparing Two Long Integers
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can r...
[ "#ROUNIAAUDI\r\nanswerOne=input().lstrip('0')\r\nanswerTwo=input().lstrip('0')\r\n#print(a)\r\nif(len(answerOne)!=len(answerTwo)) :\r\n print(\">\" if len(answerOne)>len(answerTwo) else \"<\")\r\nelse :\r\n print(\">\" if answerOne>answerTwo else \"<\" if answerTwo > answerOne else \"=\")\r\n\r\n", "x = inp...
{"inputs": ["9\n10", "11\n10", "00012345\n12345", "0123\n9", "0123\n111", "9\n9", "0\n0000", "1213121\n1213121", "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "...
UNKNOWN
PYTHON3
CODEFORCES
93
fd1ce315ca7b872f90047714c866c036
Inventory
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the...
[ "n = int(input())\r\na = list(map(int, input().split()))\r\ns = set(a)\r\nk = set(range(1, n+1))\r\nneed = k-s\r\nvis = set()\r\n\r\nfor i in range(n):\r\n if a[i] in vis:\r\n a[i] = need.pop()\r\n else:\r\n if a[i] not in k:\r\n a[i] = need.pop()\r\n vis.add(a[i])\r\n ...
{"inputs": ["3\n1 3 2", "4\n2 2 3 3", "1\n2", "3\n3 3 1", "5\n1 1 1 1 1", "5\n5 3 4 4 2", "5\n19 11 8 8 10", "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 73...
UNKNOWN
PYTHON3
CODEFORCES
88
fd83dbf0a860282e31913add3b44f5c3
Permutations
A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine tha...
[ "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nres = [0 for i in range(n)]\r\nb = [[a[i], i] for i in range(n)]\r\n\r\nb.sort()\r\nok = True\r\n\r\nlast = 0\r\nlast_count = 10 ** 10\r\ncur_count = 10 ** 10\r\nit = 1\r\n\r\nfor i in range(n):\r\n if b[i][0] - last >= 2:\r\n ok = False\r\n ...
{"inputs": ["9\n1 2 3 1 2 1 4 2 5", "4\n4 3 2 1", "4\n1 2 2 3", "1\n1", "1\n2", "5\n1 1 1 1 1", "3\n2 1 1", "6\n3 3 2 2 1 1", "2\n1000 1", "5\n2 2 1 1 3", "10\n2 1 2 4 6 1 5 3 7 1", "10\n4 1 2 1 3 3 1 2 2 1", "10\n1 2 5 1 1 1 4 1 3 2", "20\n2 7 3 8 4 6 3 7 6 4 13 5 1 12 1 10 2 11 5 9", "20\n1 1 1 2 3 1 5 9 5 8 4 6 7 3 ...
UNKNOWN
PYTHON3
CODEFORCES
19
fd8886c6850c1ea1e514d52a6f360e82
Autocompletion
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e...
[ "# python3\n# utf-8\n\nclass Trie:\n def __init__(self):\n self.letter___node = {}\n self.words_nr = 0\n\n def add_word(self, word):\n word = word + '$'\n curr_node = self\n for letter in word:\n if letter not in curr_node.letter___node:\n curr_node...
{"inputs": ["snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.", "'co-co-co, codeforces?!'", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning ...
UNKNOWN
PYTHON3
CODEFORCES
1
fd92b19e89743bc74823f16a399a7d87
none
Hamed has recently found a string *t* and suddenly became quite fond of it. He spent several days trying to find all occurrences of *t* in other strings he had. Finally he became tired and started thinking about the following problem. Given a string *s* how many ways are there to extract *k*<=≥<=1 non-overlapping subst...
[ "#!/usr/bin/env python\n# coding=utf-8\n\ns, t = input(), input()\nn, m = len(s), len(t)\nt = '$'.join((t, s))\np = [0]\nk = 0\nfor i in range(1, n + m + 1):\n while k and t[k] != t[i]:\n k = p[k - 1]\n if t[k] == t[i]:\n k += 1\n p.append(k)\nans = [0] * n\nsums = [0] * (n + 1)\ncurs = 0\nwa...
{"inputs": ["ababa\naba", "welcometoroundtwohundredandeightytwo\nd", "ddd\nd", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv", "a\na", "a\naa", "a\nb", "ababababab\nabab"], "ou...
UNKNOWN
PYTHON3
CODEFORCES
3
fdcea445eb25dcf698ddd83d96b0a8bf
Sysadmin Bob
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitra...
[ "s=input().split('@'); n=len(s)-1\r\nfor i in range(1,n):\r\n if len(s[i])<2: print('No solution'); exit()\r\n else: s[i]=s[i][0]+','+s[i][1:]\r\nif n>0 and s and s[0] and s[n]: print('@'.join(s))\r\nelse: print('No solution')", "# -*- coding: utf-8 -*-\r\n\r\ns = input().split('@')\r\nn = len(s) - 1\r\n \r...
{"inputs": ["a@aa@a", "a@a@a", "@aa@a", "aba@caba@daba", "asd@qwasd@qwasd@qwasd@qwasd@qw", "qwer@ty", "@", "g", "@@", "@@@", "r@@", "@@r", "@r@", "w@", "@e", "jj", "@gh", "n@m", "kl@", "fpm", "@@@@", "q@@@", "@d@@", "@@v@", "@@@c", "@@zx", "@x@a", "@pq@", "w@@e", "e@s@", "ec@@", "@hjk", "e@vb", "tg@q", "jkl@", "werb", ...
UNKNOWN
PYTHON3
CODEFORCES
22
fdd530dfaa50125be7d4251073dd47dd
Hiring Staff
A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least *k* people must work in the store. Berland has a law that determines the order of working days and non-worki...
[ "n, m, k = map(int, input().split())\nspan = n+m+1\ncount = (span+1)*[0]\ncount[span] = k\nkey = (span+1)*[False]\nkey[1] = True\nhire = []\nday = 1\nwhile True:\n\twhile day <= span and count[day] >= k:\n\t\tday += 1\n\tif day > span:\n\t\tif key[span]:\n\t\t\tbreak\n\t\tday -= 1\n\twhile not key[day]:\n\t\tday -=...
{"inputs": ["4 3 2", "3 3 1", "5 5 3", "7 6 8", "8 3 2", "5 1 1", "6 5 1", "2 1 1", "2 2 1", "3 1 1", "3 2 1", "3 3 1", "4 1 1", "4 2 1", "4 3 1", "4 4 1", "183 1 1", "284 282 1", "359 358 1", "801 801 1", "1000 1 1", "1000 999 1", "1000 1000 1", "2 1 2", "2 2 2", "3 1 2", "3 2 2", "3 3 2", "4 1 2", "4 2 2", "4 3 2", "...
UNKNOWN
PYTHON3
CODEFORCES
6
fde4f9235dd44012d3470d60a923de13
Sereja and Intervals
Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*m*). Interval [*l*1,<=*r*1] belongs to interval [*l*2,<=*r*2] if the following condition is met: *l*2<=≤<=*l*1<=≤<=*r*1<=≤<=*r*2. Sereja w...
[ "MOD = 1000000007\r\nn, m, x = map(int, input().split())\r\nif n > m:\r\n print(0)\r\n exit()\r\ndp = [[0] * (n + 1) for _ in range(n + 1)]\r\ndp[0][0] = 1\r\nfor i in range(1, m + 1):\r\n for j in range(n, -1, -1):\r\n for k in range(j, -1, -1):\r\n if i == x:\r\n dp[j][k]...
{"inputs": ["1 1 1", "3 5 1", "2 3 3", "11 79 54", "18 46 26", "8 96 61", "154 5 3", "34 22 8", "29 27 7", "12 68 35", "23 12 10", "6 42 23", "143 645 43", "14 724 55", "166 36 1", "273 41 17", "54 806 191", "6159 7 7", "115 624 37", "8 967 200", "112 440 258", "490 119 1", "745 116 85", "52 978 871", "37 746 303", "10...
UNKNOWN
PYTHON3
CODEFORCES
1
fe12c51426fe404f0b6fb444fa11ed53
Convex Shape
Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during ...
[ "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef exi():\r\n print(\"NO\")\r\n sys.exit()\r\n\r\n\r\nI = lambda: list(map(int, input().split()))\r\ng = []\r\nn, m = I()\r\nfor i in range(n):\r\n g.append(list(input()))\r\nfor i in range(n):\r\n temp = 0\r\n for j in range(1, m):\r\n ...
{"inputs": ["3 4\nWWBW\nBWWW\nWWWB", "3 1\nB\nB\nW", "1 1\nB", "1 2\nBB", "2 1\nB\nB", "1 2\nBW", "2 1\nW\nB", "5 5\nWBBBW\nWBBBW\nWBBWW\nWBBBW\nWWWWW", "5 5\nWBBWW\nBBBWW\nBBBWW\nBBBWW\nBBBBB", "5 5\nWWWBB\nBBBBB\nWWWBB\nWWWBB\nWWWBW", "5 5\nWBBBW\nWBBWW\nWBBWW\nBBBWW\nBBWWW", "5 5\nWBBBB\nWBBBB\nWBBBB\nBBBBB\nBBBBB",...
UNKNOWN
PYTHON3
CODEFORCES
7
feaa637b31fdce3c496608b4398a079b
Tricky Function
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
[ "import os\nimport math\ncumsum = [int(x) for x in os.read(0, os.fstat(0).st_size).split()]\nn = cumsum[0]\ncumsum[0] = 0\nfor i in range(n):\n cumsum[i+1] += cumsum[i]\n\n\ndef work(besta, i, sqrtbesta, lowerbound, upperbound, cumsumi):\n for j in range(i+1, min(n, i - 1 + sqrtbesta) + 1):\n if lowerb...
{"inputs": ["4\n1 0 0 -1", "2\n1 -1", "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -55 92 3 -22 43 -30 48 -27 88 -58 41 36 8 -40 -30 -18 16 22 -66 -91 -46 48...
UNKNOWN
PYTHON3
CODEFORCES
4
feb6b1e03e665a72ca3cb3f0ccfc5ca2
Two Arithmetic Progressions
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0. The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a...
[ "def exgcd(i, j):\r\n if j == 0:\r\n return 1, 0, i\r\n u, v, d = exgcd(j, i % j)\r\n return v, u - v * (i // j), d\r\nma, ra, mb, rb, L, R = map(int, input().split(' '))\r\nL = max(L, ra, rb)\r\nif L > R:\r\n print(0)\r\n exit(0)\r\nif ra > rb:\r\n ma, ra, mb, rb = mb, rb, ma, ra\r\n_, _, ...
{"inputs": ["2 0 3 3 5 21", "2 4 3 0 6 17", "2 0 4 2 -39 -37", "1 9 3 11 49 109", "3 81 5 72 -1761 501", "8 -89 20 67 8771 35222", "1 -221 894 86403 -687111 141371", "1 -1074 271 17741 -2062230 1866217", "3 2408 819 119198 -8585197 7878219", "1 341 8581 3946733 -59420141 33253737", "1 10497 19135 2995296 -301164547 -18...
UNKNOWN
PYTHON3
CODEFORCES
9
febea4f23d6799418a46ea0af82f70af
Permutation
You are given a permutation of numbers from 1 to *n*. Determine whether there's a pair of integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=*n*; *a*<=≠<=*b*) such that the element (note, that it is usual division, not integer one) is between *a* and *b* in this permutation. First line consists of a single integer *n* (1<=≤<=*n*...
[ "n = int(input())\r\nv = list(map(int, input().split()))\r\nans = \"NO\"\r\np = []\r\nfor i in range(n + 1):\r\n p.append(-1)\r\nfor i in range(n):\r\n p[v[i]] = i\r\nfor i in range(n - 1):\r\n for j in range(i + 1, min(n, i + 6)):\r\n if v[i] * 2 - v[j] >= 1 and v[i] * 2 - v[j] <= n and p[v[i] * 2 ...
{"inputs": ["4\n1 3 4 2", "5\n1 5 2 4 3", "100\n17 41 19 23 46 16 10 31 82 12 77 32 11 71 83 25 98 18 34 59 13 73 80 65 37 22 6 2 24 5 94 42 51 63 52 92 97 26 93 38 36 87 64 70 14 43 68 85 33 44 74 89 56 1 69 88 20 49 48 21 84 90 7 47 39 55 81 86 76 57 3 62 15 78 100 60 61 66 91 30 58 35 99 96 54 27 79 9 29 50 45 72 75...
UNKNOWN
PYTHON3
CODEFORCES
1
fecd3371aac8091bff48bc8e2f52941c
Kalevitch and Chess
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, th...
[ "d=0\r\nc=0\r\nfor i in range (0,8):\r\n a=input()\r\n if a!='BBBBBBBB' and d==0:\r\n d=1\r\n for j in range (0,8):\r\n if a[j]=='B':\r\n c+=1\r\n if a=='BBBBBBBB':\r\n c+=1\r\nprint(c)\r\n", "#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input()...
{"inputs": ["WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nB...
UNKNOWN
PYTHON3
CODEFORCES
170
fed340b160e4eb32c6a5954134630705
Hierarchy
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of emp...
[ "n = int(input())\ne = map(int, input().split())\nm = int(input())\n\naux = [-1] * n\nfor _ in range(m):\n a, b, c = map(int, input().split())\n b -= 1\n\n if aux[b] == -1: aux[b] = c\n else: aux[b] = min(aux[b], c)\n\nif aux.count(-1) > 1: print(-1)\nelse: print(sum(aux) + 1)\n\n \t\t\t \t \t \t\t\...
{"inputs": ["4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5", "3\n1 2 3\n2\n3 1 2\n3 1 3", "1\n2\n0", "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7", "3\n9 4 5\n5\n3 2 4\n1 2 4\n3 2 8\n1 3 5\n3 2 5", "3\n2 5 9\n5\n3 1 7\n2 1 1\n2 1 6\n2 1 2\n3 1 5", "3\n6 2 9\n5\n1 2 10\n3 1 4\n1 2 5\n1 2 2\n3 1 4", "4\n10 6 7 4\n5\n1 3 1\n3 4 1\n...
UNKNOWN
PYTHON3
CODEFORCES
85
fee1c0d82e0df1ec46bbb228704921c3
Relatively Prime Graph
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
[ "from array import array\r\nfrom sys import stdin\r\nimport bisect\r\nfrom bisect import *\r\nimport itertools\r\nfrom itertools import *\r\n\r\ndef scan_gen():\r\n for line in stdin: yield from iter(line.split())\r\nscan = scan_gen()\r\ndef nint(): return int(next(scan))\r\ndef nintk(k): return tuple(nint() for...
{"inputs": ["5 6", "6 12", "572 99643", "571 99403", "100 3043", "10 31", "1 1", "2 1", "100000 1", "100000 99999", "100000 100000", "1000 100000", "572 99644", "571 99404", "100 3044", "10 32", "100000 99998", "55910 88645", "72050 72069", "53599 55493", "56557 100000", "1001 100000", "50000 100000", "530 100000", "46...
UNKNOWN
PYTHON3
CODEFORCES
28
fef0dc43ecff47f600561e8599217ddf
Bookshelves
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the ne...
[ "n,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ndp = [[set() for _ in range(k)] for _ in range(n)]\r\nfor i in range(n - 1,-1,-1):\r\n x = a[i]\r\n for j in range(i + 1, n):\r\n for d in range(k - 1):\r\n for y in dp[j][d]:\r\n dp[i][d + 1].add(x & y...
{"inputs": ["10 4\n9 14 28 1 7 13 15 29 2 31", "7 3\n3 14 15 92 65 35 89", "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16", "20 15\n927353279298143 655102800384382 40376603048780 1008958973042960 1123049780860278 853122601026128 154596679092462 2000...
UNKNOWN
PYTHON3
CODEFORCES
12
fefe761d353a35a1825f8de3622e0e44
Phone numbers
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three...
[ "\r\na = int(input())\r\nb = input()\r\nc = ''\r\nd = ''\r\nif a % 2 == 0:\r\n for i in range(0,a,2):\r\n c += b[i]+b[i+1]+'-'\r\nelse:\r\n for i in range(0,a-3,2):\r\n d += b[i]+b[i+1]+'-'\r\nif a % 2 == 0:\r\n print(c[:-1])\r\n\r\nelse:\r\n print(d+b[-3:])\r\n", "import sys\r\nimport m...
{"inputs": ["6\n549871", "7\n1198733", "2\n74", "2\n33", "3\n074", "3\n081", "4\n3811", "5\n21583", "8\n33408349", "9\n988808426", "10\n0180990956", "15\n433488906230138", "22\n7135498415686025907059", "49\n2429965524999668169991253653390090510755018570235", "72\n49192533778411177050014761988172752557003973550743936062...
UNKNOWN
PYTHON3
CODEFORCES
157
ff10d04958977d2d3ed41f2c817605a8
String Compression
Ivan wants to write a letter to his friend. The letter is a string *s* consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string *s* instea...
[ "def prefix(s):\n p = [0]\n for i in range(1, len(s)):\n j = p[-1]\n while j > 0 and s[j] != s[i]:\n j = p[j - 1]\n if s[i] == s[j]:\n j += 1\n p.append(j)\n return p\n\n\ns = input()\nn = len(s)\nans = [0] * (n + 1)\ni = n - 1\n\nwhile i >= 0:\n p = pre...
{"inputs": ["aaaaaaaaaa", "abcab", "cczabababab", "kbyjorwqjk", "baaabbbaba", "aaaaaaaaaa", "cbbbcccbbc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "hltcdvuobkormkxkbmpfjniilublkrckmvvxemcyietgxcyjgrjwsdsgsfmoqnmbxozfavxopklhldhnsjpxhejxaxuctxeifglx", "agdmd...
UNKNOWN
PYTHON3
CODEFORCES
3
ff140e99d830432ae85962a533046d13
Feed the cat
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are...
[ "from math import ceil\nH,M=input().split()\nh,d,c,n=input().split()\nH,M,h,d,c,n=int(H),int(M),int(h),int(d),int(c),int(n)\nif H<20:\n print(min(ceil(h/n)*c,ceil((h+d*(1200-H*60-M))/n)*0.8*c))\nelse:\n print(ceil(h/n)*0.8*c)", "# Standard Input\r\nimport sys\r\n\r\n\r\ndef main():\r\n file = sys.stdin ...
{"inputs": ["19 00\n255 1 100 1", "17 41\n1000 6 15 11", "16 34\n61066 14 50 59", "18 18\n23331 86 87 41", "10 48\n68438 8 18 29", "08 05\n63677 9 83 25", "00 00\n100000 100 100 100", "20 55\n100000 100 100 100", "23 59\n100000 100 100 100", "00 00\n1 100 100 100", "21 26\n33193 54 97 66", "20 45\n33756 24 21 1", "14 3...
UNKNOWN
PYTHON3
CODEFORCES
144
ff421c3540ee1df661234b450f1c7093
Chip Play
Let's consider the following game. We have a rectangular field *n*<=×<=*m* in size. Some squares of the field contain chips. Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right. The player may choose a chip and make a move with it. The...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\ns = [list(input().rstrip()) for _ in range(n)]\r\nl = n * m\r\nd = {76:0, 82:1, 85:2, 68:3}\r\ndp0 = [[] for _ in range(l)]\r\nfor i in range(n):\r\n si = s[i]\r\n x = [n * m]\r\n ...
{"inputs": ["4 4\nDRLD\nU.UL\n.UUR\nRDDL", "2 2\nRD\nUL", "5 5\nUD..L\nRRD..\n..RDD\nUUL..\nDDLRR", "10 10\n.L.....R..\n.........U\n..D....D..\n.R......L.\n....L.....\n.........D\n......U...\nD....R....\n...U......\n........L.", "17 13\n...LD.UR.RUU.\nLDLULDUDRRDRL\nDD.RRLRUR.UD.\nRU...D...LD..\n.UR.R...URUUD\n.RURD.RL...
UNKNOWN
PYTHON3
CODEFORCES
1
ff63427e0a246e9a8c857186864b88ce
k-String
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string...
[ "alphabet=[0]*27\r\n# print(alphabet)\r\na=int(input())\r\nc=input()\r\n# print(a)\r\nd=False\r\nseta=set()\r\nsetalfabet=set()\r\nfor i in range(len(c)):\r\n b=int(ord(c[i])-ord('a'))\r\n alphabet[b]+=1\r\n setalfabet.add(c[i])\r\nvalue=0\r\nlista=[]\r\nfor i in range(27):\r\n if alphabet[i]%a!=0:\r\n ...
{"inputs": ["2\naazz", "3\nabcabcabz", "1\na", "2\nabba", "2\naaab", "7\nabacaba", "5\naaaaa", "3\naabaaaaabb", "2\naaab", "2\nbabac", "3\nbbbccc", "2\naa", "250\ncecececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececec...
UNKNOWN
PYTHON3
CODEFORCES
324
ff80a5b10d8a65e60f520fb16ca6252b
none
Fox Ciel is participating in a party in Prime Kingdom. There are *n* foxes there (include Fox Ciel). The i-th fox is *a**i* years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 1. Each table has at least 3 foxes sitting around it. 1...
[ "def main():\r\n def find_root(g):\r\n if list_4[g] != g:\r\n list_4[g] = find_root(list_4[g])\r\n return list_4[g]\r\n\r\n def depth_first_search(g):\r\n if free[g]:\r\n free[g], a, pv = False, list_1[g], list_2[g]\r\n for i, p in enumerate(list_2):\r\n ...
{"inputs": ["4\n3 4 8 9", "5\n2 2 2 2 2", "12\n2 3 4 5 6 7 8 9 10 11 12 13", "24\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25", "4\n2 2 9973 9967", "30\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31", "20\n76 38 74 176 106 134 12 88 66 178 63 105 199 99 29 67 135 ...
UNKNOWN
PYTHON3
CODEFORCES
1
ff9235cd44659116788a8be5c260fa52
Lucky Permutation
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine ...
[ "def lucky(x):\r\n return str(x).count('4') + str(x).count('7') == len(str(x))\r\n\r\ndef quantity_luckynum(n):\r\n s = str(n)\r\n if s[0] < '4':\r\n return 0\r\n if s[0] == '4':\r\n return quantity_luckynum(s[1:])\r\n if s[0] < '7':\r\n return 2 ** (len(s) - 1)\r\n if s[0] ==...
{"inputs": ["7 4", "4 7", "7 1", "7 5040", "10 1023", "7 7477", "10 10000", "3 7", "27 1", "40 8544", "47 1", "47 8547744", "50 1000000000", "64 87", "98 854555", "100 1", "9985 5888454", "1 1", "1 2", "2 1000000000", "10 1000000000", "20 1000000000", "777777 1", "777777 2", "777474 10000", "1000000000 1", "777777777 5...
UNKNOWN
PYTHON3
CODEFORCES
5
ffffc0199ae7229539d28ba0d02e9047
Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
[ "s = input()\r\n\r\ndef chk(s):\r\n for i in range(len(s)):\r\n if s[i] != s[len(s) - i - 1]:\r\n return False\r\n return True\r\n\r\nfor i in range(len(s) + 1):\r\n for j in range(26):\r\n ns = s[:i] + chr(ord('a') + j) + s[i:]\r\n if chk(ns):\r\n print(ns)\r\n ...
{"inputs": ["revive", "ee", "kitayuta", "evima", "a", "yutampo", "fft", "shuseki", "lsdijfjisl", "ewcdcwerp", "noon", "add", "iq", "hogloid", "yosupo", "stat", "level", "iwiwi", "racecar", "dog", "squirrel", "slime", "palindrome", "nqwcvcwqn", "lsdijfjisl", "jewiiwefj", "vnwmvvmonv", "zennyuu", "mrtoudai", "z", "babccb...
UNKNOWN
PYTHON3
CODEFORCES
108