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
45f188f5201885d972fc4e9a0a94d835
Football
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
[ "n = int(input())\r\nscores = {}\r\nfor i in range(n):\r\n team = input()\r\n scores[team] = scores.get(team, 0) + 1\r\nprint(max(scores.items(), key=lambda x: x[1])[0])", "a = int(input())\r\ncount = 0\r\ncount2 = 0\r\nindex = 0\r\nlis = []\r\nfor i in range(a):\r\n b = input()\r\n lis.append(b)\r\n\...
{"inputs": ["1\nABC", "5\nA\nABA\nABA\nA\nA", "2\nXTSJEP\nXTSJEP", "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "3\nAZID\nEERWBC\nEERWBC", "3\nHNCGYL\nHNCGYL\nHNCGYL", "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "4\nA\nA\nKUDLJMXCSE\nA", "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "5\nPKUZYTFYWN\nPKUZYTFYW...
UNKNOWN
PYTHON3
CODEFORCES
1,490
460c08cffe5027fca3f0e2f9dde6d342
Playing Cubes
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa...
[ "n,m = map(int,input().split())\nvasya = min(n,m)\npetya = n+m-1-vasya\nprint('{} {}'.format(petya,vasya))\n\n \n\n\n\n", "# import sys\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\ndef read_line():\r\n return [int(x) for x in input().split()]\r\n\r\ndef read_i...
{"inputs": ["3 1", "2 4", "1 1", "2 1", "4 4", "10 7", "5 13", "7 11", "1 2", "10 10", "50 30", "80 120", "304 122", "500 800", "900 1000", "1 1000", "997 9", "341 678", "784 913", "57 888", "100000 100000", "10000 100000", "9999 99999", "12 100000", "9999 31411", "12930 98391", "98813 893", "99801 38179", "831 69318",...
UNKNOWN
PYTHON3
CODEFORCES
124
463cccac2b9d40599dd729d945815394
Handshakes
On February, 30th *n* students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came ...
[ "import sys\r\nmaxn = 200500\r\nv = [[] for _ in range(maxn)]\r\nanswer = []\r\nn = int(input())\r\ndata = list(map(int, input().split()))\r\nfor i in range(n):\r\n x = data[i]\r\n v[x].append(i + 1)\r\nit = n\r\ncur = 0\r\nwhile it > 0:\r\n while cur >= 0 and not v[cur]:\r\n cur -= 3\r\n if cur ...
{"inputs": ["5\n2 1 3 0 1", "9\n0 2 3 4 1 1 0 2 2", "4\n0 2 1 1", "5\n1 0 2 1 0", "1\n0", "5\n3 0 4 1 2", "3\n1 0 0", "7\n3 0 0 4 2 2 1", "10\n1 0 2 3 3 0 4 4 2 5", "7\n2 4 3 5 1 6 0", "10\n6 2 8 1 4 5 7 3 9 3", "5\n2 0 3 1 1", "7\n2 2 3 3 4 0 1", "11\n3 1 1 1 2 2 0 0 2 1 3", "6\n0 1 2 1 2 0", "13\n1 2 0 4 2 1 0 2 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
6
4640822bd3e4682b578383e2576f98b9
New Year and Entity Enumeration
You are given an integer *m*. Let *M*<==<=2*m*<=-<=1. You are also given a set of *n* integers denoted as the set *T*. The integers will be provided in base 2 as *n* binary strings of length *m*. A set of integers *S* is called "good" if the following hold. 1. If , then . 1. If , then 1. 1. All elements of *...
[ "from collections import defaultdict\n\ndef E1():\n\n mod = 10 ** 9 + 7\n\n comb = [[1]]\n for i in range(1, 1010):\n x = [1]\n for j in range(1, i):\n x.append((comb[i - 1][j - 1] + comb[i - 1][j]) % mod)\n x.append(1)\n comb.append(x)\n\n dp = [1]\n for i in r...
{"inputs": ["5 3\n11010\n00101\n11000", "30 2\n010101010101010010101010101010\n110110110110110011011011011011", "30 10\n001000000011000111000010010000\n000001100001010000000000000100\n000110100010100000000000101000\n110000010000000001000000000000\n100001000000000010010101000101\n001001000000000100000000110000\n00000001...
UNKNOWN
PYTHON3
CODEFORCES
3
465ff9110ae1b813c6cf3bc7353b4144
Ultra-Fast Mathematician
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
[ "line1 = input()\r\nline2 = input()\r\noutput = []\r\nfor i in range(0,len(line1)):\r\n if line1[i] == line2[i]:\r\n output.append(0)\r\n else:\r\n output.append(1)\r\n print(int(output[i]),end = \"\")\r\n", "a = input()\nb = input()\noutput = \"\"\n \nfor i in range(len(a)):\n if a[i] =...
{"inputs": ["1010100\n0100101", "000\n111", "1110\n1010", "01110\n01100", "011101\n000001", "10\n01", "00111111\n11011101", "011001100\n101001010", "1100100001\n0110101100", "00011101010\n10010100101", "100000101101\n111010100011", "1000001111010\n1101100110001", "01011111010111\n10001110111010", "110010000111100\n0011...
UNKNOWN
PYTHON3
CODEFORCES
3,247
46813e083a580aa84a87678a0366f22b
Cipher
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of somethin...
[ "p = int(1e9+7)\r\nMAXM = 2500\r\nMAXN = 100\r\n\r\ndef pre():\r\n F = [[1]+[0]*MAXM]\r\n for i in range(1,MAXN+1):\r\n T = [0]*(MAXM+1)\r\n for j in range(MAXM,-1,-1):\r\n k1 =max(0,j-25)\r\n T[j]=sum(F[-1][k1:j+1])%p\r\n F.append(T)\r\n return F\r\n\r\nF = p...
{"inputs": ["1\nab", "1\naaaaaaaaaaa", "2\nya\nklmbfxzb", "1\na", "1\nz", "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "1\nmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmn", "15\nejkf\nkc\nu\nznmjnznzn\nbjk...
UNKNOWN
PYTHON3
CODEFORCES
6
46a482ff61fe6337db5ac40a5cc6f9f2
Blood Cousins Return
Polycarpus got hold of a family tree. The found tree describes the family relations of *n* people, numbered from 1 to *n*. Every person in this tree has at most one direct ancestor. Also, each person in the tree has a name, the names are not necessarily unique. We call the man with a number *a* a 1-ancestor of the man...
[ "import sys\r\nimport random\r\nfrom math import gcd, lcm, sqrt, isqrt, perm, comb, factorial, log2, ceil, floor\r\nfrom collections import Counter, defaultdict, deque\r\nfrom functools import lru_cache, reduce, cmp_to_key\r\nfrom itertools import accumulate, combinations, permutations\r\nfrom heapq import nsmalles...
{"inputs": ["6\npasha 0\ngerald 1\ngerald 1\nvalera 2\nigor 3\nolesya 1\n5\n1 1\n1 2\n1 3\n3 1\n6 1", "6\nvalera 0\nvalera 1\nvalera 1\ngerald 0\nvalera 4\nkolya 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "1\nc 0\n20\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "2...
UNKNOWN
PYTHON3
CODEFORCES
3
46aca1272ff0ff57506eb619248874fd
Exponential notation
You are given a positive decimal number *x*. Your task is to convert it to the "simple exponential notation". Let *x*<==<=*a*·10*b*, where 1<=≤<=*a*<=&lt;<=10, then in general case the "simple exponential notation" looks like "aEb". If *b* equals to zero, the part "Eb" should be skipped. If *a* is an integer, it shou...
[ "def f(q):\r\n i = 0\r\n while i < len(q) and q[i] == '0': i += 1\r\n return q[i:]\r\ndef g(q):\r\n i = len(q)\r\n while i > 0 and q[i - 1] == '0': i -= 1\r\n return q[:i]\r\na, b = (input() + '.').split('.')[:2]\r\na, b = f(a), g(b)\r\ne = len(a) - 1\r\nif not b: a = g(a)\r\nif not a:\r\n e = ...
{"inputs": ["16", "01.23400", ".100", "100.", "9000", "0.0012", "0001100", "1", "1.0000", "2206815224318443962208128404511577750057653265995300414539703580103256087275661997018352502651118684", ".642190250125247518637240673193254850619739079359757454472743329719747684651927659872735961709249479", "143529100720960530144...
UNKNOWN
PYTHON3
CODEFORCES
30
46b59a64a8ffb4422af5f48e844aa3b1
Wet Shark and Bishops
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o...
[ "size = 10\r\nn = int(input())\r\ncnt = 0\r\ndp1, dp2 = {}, {}\r\nfor i in range(n):\r\n i, j = map(int, input().split())\r\n s, d = i + j, i - j\r\n if not s in dp1.keys():\r\n dp1[s] = 0\r\n if not d in dp2.keys():\r\n dp2[d] = 0\r\n dp1[s] += 1\r\n dp2[d] += 1\r\nfor v in dp1.valu...
{"inputs": ["5\n1 1\n1 5\n3 3\n5 1\n5 5", "3\n1 1\n2 3\n3 5", "3\n859 96\n634 248\n808 72", "3\n987 237\n891 429\n358 145", "3\n411 81\n149 907\n611 114", "3\n539 221\n895 89\n673 890", "3\n259 770\n448 54\n926 667", "3\n387 422\n898 532\n988 636", "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 ...
UNKNOWN
PYTHON3
CODEFORCES
95
46b8719c37868c51adb2235f67a51d17
Greed
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<...
[ "n=int(input())\nleft=[int(x) for x in input().split()]\ncap=[int(x) for x in input().split()]\nm1=max(cap)\nl=cap;l.remove(m1);\nm2=max(l)\nif m1+m2>=sum(left):\n print(\"YES\")\nelse:\n print('NO')\n \t \t\t\t\t \t\t \t\t\t\t\t \t\t\t\t\t \t\t \t", "n= int(input())\r\n\r\ncan = list(map(int, input().s...
{"inputs": ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3", "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85", "4\n25 35 7 31\n70 37 43 35", "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42", "5\n22 5 19 16 32\n26 10 43 38 37", "5\n32 4 22 40 26\n39 20 3...
UNKNOWN
PYTHON3
CODEFORCES
424
46cfca38244a5a8772fa79339e7ec2e8
Legacy
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are *n* planets in their universe numbered from 1 to *n*. Rick is in planet number *s* (the earth) and he doesn't know where Morty is. As we all...
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nfrom heapq import heappush, heappop\r\nINF=10**18\r\ndef dijkstra(start,n):\r\n dist=[INF]*n\r\n hq=[(0,start)]\r\n dist[start]=0\r\n seen=[False]*n\r\n while hq:\r\n w,v=heappop(hq)\r\n if dist[v]<w:\r\n continue\r\n seen[v]=Tr...
{"inputs": ["3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17", "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16", "6 1 5\n1 3 6 80612370", "10 8 7\n1 10 7 366692903\n1 4 8 920363557\n2 7 5 10 423509459\n2 2 5 7 431247033\n2 7 3 5 288617239\n2 7 3 3 175870925\n3 9 3 8 651538651\n3 4 2 5 826387883", "1 1 1\n1 1 1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
46daac6efffe7aaf48972ca9d1a4c15c
Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The len...
[ "s=str(input())\r\ns=list(s)\r\na=s[0]\r\na=a.upper()\r\ns[0]=a\r\ny=\"\".join(s)\r\nprint(y)", "n = input()\r\nk = n[0].upper()\r\nprint(k+n[1:])", "def solve(word):\r\n return word[0].upper() + word[1:]\r\n \r\n\r\ndef main():\r\n word = input().strip() # string values\r\n print(solve(word))\r\n\r...
{"inputs": ["ApPLe", "konjac", "a", "A", "z", "ABACABA", "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsO...
UNKNOWN
PYTHON3
CODEFORCES
767
46daf8147d3fdd3c5f879a6c1f5892f2
Petya and His Friends
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*. Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *...
[ "from functools import reduce\nfrom itertools import combinations\nfrom operator import mul\n\n# https://prime-numbers.info/list/first-50-primes\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,...
{"inputs": ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "2", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"], "outputs": ["15\n10\n...
UNKNOWN
PYTHON3
CODEFORCES
52
46ecb3ceb53efac8fd05e4dde7dbd4d1
String Task
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
[ "string = input()\n\nstring = string.lower()\nstr_ = \"\"\n\nfor i in string:\n if i not in \"aouiye\":\n str_ += \".\" + i\n\nprint(str_)", "string = input()\r\nnewstring=\"\"\r\nVowels =[\"a\", \"o\", \"y\", \"e\", \"u\", \"i\"]\r\nfor i in string.lower():\r\n if i in Vowels:\r\n continue\r\...
{"inputs": ["tour", "Codeforces", "aBAcAba", "obn", "wpwl", "ggdvq", "pumesz", "g", "zjuotps", "jzbwuehe", "tnkgwuugu", "kincenvizh", "xattxjenual", "ktajqhpqsvhw", "xnhcigytnqcmy", "jfmtbejyilxcec", "D", "ab", "Ab", "aB", "AB", "ba", "bA", "Ba", "BA", "aab", "baa", "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAok...
UNKNOWN
PYTHON3
CODEFORCES
643
46ff3c92b7b33ba7e270a4dcfa4db14f
An overnight dance in discotheque
The crowdedness of the discotheque would never stop our friends from having fun, but a bit more spaciousness won't hurt, will it? The discotheque can be seen as an infinite *xy*-plane, in which there are a total of *n* dancers. Once someone starts moving around, they will move only inside their own movement range, whi...
[ "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import *\r\nfrom math import pi\r\n\r\ndef contain(i, j):\r\n xi, yi, ri = xyr[i]\r\n xj, yj, rj = xyr[j]\r\n \r\n if ri<rj:\r\n return False\r\n \r\n d2 = (xi-xj)**2+(yi-yj)**2\r\n return d2<=(ri-rj)**2\r\n \r\ndef bfs...
{"inputs": ["5\n2 1 6\n0 4 1\n2 -1 3\n1 -2 1\n4 -1 1", "8\n0 0 1\n0 0 2\n0 0 3\n0 0 4\n0 0 5\n0 0 6\n0 0 7\n0 0 8", "4\n1000000 -1000000 2\n1000000 -1000000 3\n-1000000 1000000 2\n-1000000 1000000 1000000", "15\n-848 0 848\n-758 0 758\n-442 0 442\n-372 0 372\n-358 0 358\n-355 0 355\n-325 0 325\n-216 0 216\n-74 0 74\n-1...
UNKNOWN
PYTHON3
CODEFORCES
9
472992bea3ed7a1eadbb6fdb6f8eb35f
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
[ "n = int(input())\nenabled = [False] * 26\na = [[False]*26 for i in range(26)]\nfor i in range(n):\n s = list(map(lambda x: ord(x)-ord('a'), input()))\n for c in s:\n enabled[c] = True\n for i in range(len(s)-1):\n a[s[i]][s[i+1]] = True\npos = sum(enabled)\nans = [0]*pos\n\ndef topSort(v):\n...
{"inputs": ["3\nbcd\nab\ncdef", "4\nx\ny\nz\nw", "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz", "1\nf", "1\nqwertyuiopzxcvbnmasdfghjkl", "3\ndfghj\nghjkl\nasdfg", "4\nab\nab\nab\nabc", "3\nf\nn\nux", "2\nfgs\nfgs", "96\nc\ndhf\no\nq\nry\nh\nr\nf\nji\nek\ndhf\np...
UNKNOWN
PYTHON3
CODEFORCES
34
475b7be76ae3f929743f3c88553a97fc
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil a...
[ "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\ndef cal(a,b):...
{"inputs": ["3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32", "446799 395535 281981 494983 755701 57488\n20\n770380 454998\n147325 211816\n818964 223521\n408463 253399\n49120 2537...
UNKNOWN
PYTHON3
CODEFORCES
11
475dc6ca9903a8d02e194e325948ea5f
Stones on the Table
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. The first line contains integer *n*...
[ "n = input()\nn = int(n)\n\nstones = input()\n\nans = 0\n\nfor i in range(1, n):\n if stones[i] == stones[i-1]:\n ans = ans + 1\n\nprint(ans)\n\n\n\t\t \t \t\t\t \t\t \t\t\t\t\t\t\t \t\t\t", "number_or_stones = int(input())\r\nprom = input()\r\ncel = []\r\nfor i in range(number_or_stones):\r\n ce...
{"inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG", "1\nB", "2\nBG", "3\nBGB", "4\nRBBR", "5\nRGGBG", "10\nGGBRBRGGRB", "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "15\nBRRBRGGBBRRRRGR", "20\nRRGBBRBRGRGBBGGRGRRR", "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "35\nGBBGBRGBBGGRBBGBRRGGRR...
UNKNOWN
PYTHON3
CODEFORCES
557
475fa21447f510f90f4948dce380007d
Choosing Laptop
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those propertie...
[ "l=[];c=[]\r\nn=int(input())\r\nfor _ in range(n):\r\n\tt=list(map(int,input().split()))\r\n\tl.append(t)\r\n\tc.append(t[3])\r\n\r\ns = []\r\nfor i in range(n):\r\n\tf=0\r\n\tfor j in range(n):\r\n\t\tif i==j:\r\n\t\t\tcontinue\r\n\t\tif l[i][0]<l[j][0] and l[i][1]<l[j][1] and l[i][2]<l[j][2]:\r\n\t\t\tf=1\r\n\t\t...
{"inputs": ["5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "2\n1500 500 50 755\n1600 600 80 700", "2\n1500 512 50 567\n1600 400 70 789", "4\n1000 300 5 700\n1100 400 10 600\n1200 500 15 500\n1300 600 20 400", "10\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3...
UNKNOWN
PYTHON3
CODEFORCES
94
478f06460e80a324b95824a6a5f2042e
Simple XML
Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's d...
[ "x = input()[1:-1].split('><')\r\nn = 0\r\nfor i in range(len(x)):\r\n c = x[i]\r\n if '/' not in c:\r\n print('{}<{}>'.format(' '*2*n, c))\r\n n += 1\r\n else:\r\n n -= 1\r\n print('{}<{}>'.format(' ' * 2 * n, c))\r\n", "xml = input()\r\ntags = xml.split('>')[:-1]\r\n\r\nfor ...
{"inputs": ["<a><b><c></c></b></a>", "<a><b></b><d><c></c></d></a>", "<z></z>", "<u><d></d></u><j></j>", "<a></a><n></n><v><r></r></v><z></z>", "<c><l></l><b><w><f><t><m></m></t></f><w></w></w></b></c>", "<u><d><g><k><m><a><u><j><d></d></j></u></a></m><m></m></k></g></d></u>", "<x><a><l></l></a><g><v></v><d></d></g><z>...
UNKNOWN
PYTHON3
CODEFORCES
91
479b4867ec26d62324e7d5242bf28120
Jury Marks
Polycarp watched TV-show where *k* jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the *i*-th jury member gave *a**i* po...
[ "import bisect\r\nimport sys\r\ninput = sys.stdin.readline\r\nsys.setrecursionlimit(100000)\r\nfrom collections import defaultdict, deque\r\nfrom itertools import permutations\r\np = print\r\nr = range\r\ndef I(): return int(input())\r\ndef II(): return list(map(int, input().split()))\r\ndef S(): return input()[:-1...
{"inputs": ["4 1\n-5 5 0 20\n10", "2 2\n-2000 -2000\n3998000 4000000", "1 1\n-577\n1273042", "2 1\n614 -1943\n3874445", "3 1\n1416 -1483 1844\n3261895", "5 1\n1035 1861 1388 -622 1252\n2640169", "10 10\n-25 746 298 1602 -1453 -541 -442 1174 976 -1857\n-548062 -548253 -546800 -548943 -548402 -548794 -549236 -548700 -549...
UNKNOWN
PYTHON3
CODEFORCES
27
479ca5fddac6e338fcb23a04e17b977c
Luba And The Ticket
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
[ "x=int(input())\r\ndef s(a):\r\n r=0\r\n while a>0:\r\n r+=a%10\r\n a//=10\r\n return r\r\ndef d(a,b):\r\n r=0\r\n for i in range(6):\r\n if a%10!=b%10:\r\n r += 1\r\n a//=10\r\n b//=10\r\n return r\r\nc=6\r\nfor i in range(1000000):\r\n if s(i%1000)==s(i//1000):\r\n c=min(c,d(x,i))\r\...
{"inputs": ["000000", "123456", "111000", "120111", "999999", "199880", "899889", "899888", "505777", "999000", "989010", "651894", "858022", "103452", "999801", "999990", "697742", "242367", "099999", "198999", "023680", "999911", "000990", "117099", "990999", "000111", "000444", "202597", "000333", "030039", "000009"...
UNKNOWN
PYTHON3
CODEFORCES
81
479de0715abdea147828ecdaa989f2df
Sereja and Subsequences
Sereja has a sequence that consists of *n* positive integers, *a*1,<=*a*2,<=...,<=*a**n*. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence *a*. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences t...
[ "BIT = [0] * (1000001)\r\ndp = [0] * (1000001)\r\nMOD = 1000000007\r\nans = 0\r\ndef query(p):\r\n ret = 0\r\n i = p\r\n while i:\r\n ret = (ret + BIT[i]) % MOD\r\n i -= i & -i\r\n return ret\r\ndef update(p, v):\r\n i = p\r\n while (i <= 1000000):\r\n BIT[i] = (BIT[i] + v) % ...
{"inputs": ["1\n42", "3\n1 2 2", "5\n1 2 3 4 5", "4\n11479 29359 26963 24465", "5\n5706 28146 23282 16828 9962", "6\n492 2996 11943 4828 5437 32392", "7\n14605 3903 154 293 12383 17422 18717", "8\n19719 19896 5448 21727 14772 11539 1870 19913", "9\n3 3 2 2 3 2 1 1 2", "10\n3 3 3 2 1 2 3 2 3 1", "42\n8 5 1 10 5 9 9 3 5 ...
UNKNOWN
PYTHON3
CODEFORCES
2
47ee1524fbb3f6faaf6dae5f5894c84b
Painting Pebbles
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in p...
[ "keeper=input()\r\nn, m=keeper.split(' ')\r\nkeeper2=input()\r\ntp=keeper2.split(' ')\r\nmap_object=map(int, tp)\r\narr=list(map_object)\r\nif (max(arr))-(min(arr)) > int(m): print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n for x in arr:\r\n for y in range(0,int(x)): print(int(y)%int(m)+1, end=\" \")\r\n ...
{"inputs": ["4 4\n1 2 3 4", "5 2\n3 2 4 1 3", "5 4\n3 2 4 3 5", "4 3\n5 6 7 8", "5 6\n3 7 2 1 2", "9 5\n5 8 7 3 10 1 4 6 3", "2 1\n7 2", "87 99\n90 28 93 18 80 94 68 58 72 45 93 72 11 54 54 48 74 63 73 7 4 54 42 67 8 13 89 32 2 26 13 94 28 46 77 95 94 63 60 7 16 55 90 91 97 80 7 97 8 12 1 32 43 20 79 38 48 22 97 11 92 ...
UNKNOWN
PYTHON3
CODEFORCES
61
47f8f717c6b31e6b2e7253424ace3ed8
Next Test
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
[ "\r\n\r\ndef main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n count = 1\r\n arr.sort()\r\n\r\n for i in arr:\r\n if i != count:\r\n print(count)\r\n exit()\r\n count += 1\r\n\r\n print(count)\r\n\r\n\r\n\r\nmain()\r\n", "n = int(i...
{"inputs": ["1\n1", "2\n2 1", "3\n3 4 1", "4\n6 4 3 5", "5\n3 2 1 7 4", "6\n4 1 2 5 3 7", "7\n3 2 1 6 5 7 4", "8\n2 8 3 7 6 9 1 5", "9\n10 5 9 3 8 7 1 2 4", "10\n7 2 3 8 9 6 5 4 1 10", "1\n1", "2\n1 2", "3\n2 4 1", "4\n4 2 3 1", "5\n3 1 4 2 5", "6\n1 3 6 7 2 4", "7\n1 5 4 7 2 3 6", "8\n12 1 6 5 2 8 3 4", "9\n3 2 7 5 6 ...
UNKNOWN
PYTHON3
CODEFORCES
318
47ff0c9c87017ecba81beeb5b030881e
Mafia
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
[ "from cmath import inf\r\nimport math\r\nimport sys\r\nfrom os import path\r\n#import bisect\r\n#import math\r\nfrom functools import reduce\r\nimport collections\r\nimport sys\r\n \r\nif (path.exists('CP/input.txt')):\r\n sys.stdout = open('CP/output.txt', 'w')\r\n sys.stdin = open('CP/input.txt', 'r')\r\n ...
{"inputs": ["3\n3 2 2", "4\n2 2 2 2", "7\n9 7 7 8 8 7 8", "10\n13 12 10 13 13 14 10 10 12 12", "10\n94 96 91 95 99 94 96 92 95 99", "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 97...
UNKNOWN
PYTHON3
CODEFORCES
137
4845678942c09d8042afede09d048a1e
Unimodal Array
Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arra...
[ "# -*- coding: utf-8 -*-\n\"\"\"831.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3\n\"\"\"\n\n#https://codeforces.com/contest/831/problem/A Unimodal Array\n\na=int(input())\nb=list(map(int,input().split...
{"inputs": ["6\n1 5 5 5 4 2", "5\n10 20 30 20 10", "4\n1 2 1 2", "7\n3 3 3 3 3 3 3", "6\n5 7 11 11 2 1", "1\n7", "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 5...
UNKNOWN
PYTHON3
CODEFORCES
159
48476289549aff4bc826a1d50d25b85c
Block Towers
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be ...
[ "import collections\r\nimport math\r\n\r\nn, m = map(int, input().split())\r\nx = min(2 * n, 3 * m) // 6\r\na, b = 2 * n, 3 * m\r\nwhile x:\r\n while a <= b and x:\r\n a += 2\r\n x -= 1\r\n if a % 6 == 0:\r\n a += 2\r\n while b < a and x:\r\n b += 3\r\n x -= 1\r\n...
{"inputs": ["1 3", "3 2", "5 0", "4 2", "0 1000000", "1000000 1", "1083 724", "1184 868", "1285 877", "820189 548173", "968867 651952", "817544 553980", "813242 543613", "961920 647392", "825496 807050", "974174 827926", "969872 899794", "818549 720669", "967227 894524", "185253 152723", "195173 150801", "129439 98443"...
UNKNOWN
PYTHON3
CODEFORCES
42
4854574506ddb794691963b9439cc563
Destroying Array
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find o...
[ "import sys\r\ninput = lambda :sys.stdin.readline()[:-1]\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n####...
{"inputs": ["4\n1 3 2 5\n3 4 1 2", "5\n1 2 3 4 5\n4 2 3 5 1", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8", "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4", "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7...
UNKNOWN
PYTHON3
CODEFORCES
37
488c56b385b3bc0349a543525b06b080
Calendar Reform
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year t...
[ "F = {}\r\n\r\ndef f(k):\r\n if not k in F:\r\n s, i, j = 0, 4, 4\r\n while i <= k:\r\n s += i * f(k // i)\r\n i += j + 1\r\n j += 2\r\n F[k] = (k * (k + 1)) // 2 - s\r\n return F[k]\r\n\r\ndef g(k):\r\n s, i, j = 0, 4, 4\r\n while i <= k:\r\n ...
{"inputs": ["25 3", "50 5", "1 1", "1 2", "1 10", "1 5000000", "5000000 5000000", "4000000 5000000", "3000000 5000000", "1000000 5000000", "1 10000000"], "outputs": ["30", "125", "1", "3", "38", "8224640917276", "24674231279431", "21384022194564", "18094224526592", "11514506860120", "32898872196712"]}
UNKNOWN
PYTHON3
CODEFORCES
4
48b421286a3242f5c7b4c7f7ae6e7623
Bear and Prime Numbers
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *...
[ "#bisect.bisect_left(a, x, lo=0, hi=len(a)) is the analog of std::lower_bound()\r\n#bisect.bisect_right(a, x, lo=0, hi=len(a)) is the analog of std::upper_bound()\r\n#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list)\r\n#from collections import deque as dq #deque e.g. myqueue=dq(list)\r\n#appe...
{"inputs": ["6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4", "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123", "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792", "1\n6\n1\n2 3", "1\n10000000\n1\n2000000000 2000000000", "12\n2 4 8 16 32 64 128 256 512 1024 2048 4096\n14\n2 2\n2 2000000000\n4 4\n8 8\n16 16\n3...
UNKNOWN
PYTHON3
CODEFORCES
13
48b50de9de6967190c06c4926651aaaa
Pythagorean Theorem II
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s...
[ "n=int(input())\r\ndic={}\r\nfor i in range(1,n+1):\r\n dic[i*i]=0\r\nans=0\r\nfor i in range(1,n+1):\r\n for j in range(i,n+1):\r\n if (i*i)+(j*j) in dic:\r\n ans+=1\r\nprint(ans)\r\n", "n=int(input())\r\nimport math\r\n \r\nv = 0\r\nfor i in range(2,n+1):\r\n for j in range(i,n+1):\r\...
{"inputs": ["5", "74", "1000", "586", "2", "362", "778", "194", "906", "659", "75", "787", "851", "563", "979", "395", "755", "171", "883", "400", "817", "177", "593", "305", "721", "785", "497", "913", "625", "334", "10000", "9999"], "outputs": ["1", "35", "881", "472", "0", "258", "653", "120", "786", "535", "37", "6...
UNKNOWN
PYTHON3
CODEFORCES
97
48dea5d3b269153c9936806a0c9b97dc
Perfect Encoding
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o...
[ "\r\nimport decimal\r\nfrom math import ceil, floor, inf, log\r\n\r\nn = input()\r\nif n=='1':\r\n print(1)\r\n exit()\r\ndecimal.getcontext().prec = len(n)+6\r\ndecimal.getcontext().Emax = len(n)+6\r\nlog3 = log(10)*(len(n)-1)/log(3)\r\npref = n\r\nif len(pref)>20:\r\n pref = pref[:20]\r\npref = pref[0] +...
{"inputs": ["36", "37", "12345678901234567890123456789", "1", "2", "3", "4", "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "710578858933137458068945311385923411361750305113825125553645790612290407508150966702638025462019898281658661470271198618633853971796952242...
UNKNOWN
PYTHON3
CODEFORCES
2
48e78a1eb2688cd13b05a10a8592caf5
The Last Fight Between Human and AI
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
[ "n, k = map(int, input().split())\r\na = [input() for _ in range(n + 1)]\r\nc = len([_ for _ in a if _ == '?'])\r\nprint('Yes' if k == 0 and (a[0] == '0' or a[0] == '?' and (n + 1 - c) % 2 == 1) or k != 0 and (c > 0 and n % 2 == 1 or c == 0 and sum([_ * pow(k, i, 10**15 + 91) for i, _ in enumerate(map(int, a))]) % ...
{"inputs": ["1 2\n-1\n?", "2 100\n-10000\n0\n1", "4 5\n?\n1\n?\n1\n?", "68 -9959\n-3666\n-3501\n9169\n5724\n1478\n-643\n-3039\n-5537\n-4295\n-1856\n-6720\n6827\n-39\n-9509\n-7005\n1942\n-5173\n-4564\n2390\n4604\n-6098\n-9847\n-9708\n2382\n7421\n8716\n9718\n9895\n-4553\n-8275\n4771\n1538\n-8131\n9912\n-4334\n-3702\n7035...
UNKNOWN
PYTHON3
CODEFORCES
1
490145635522fa9a26bed3be4055b932
Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has *n* cities, numbered from 1 to *n*, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef make_graph(n, m):\r\n x, s = [], [0] * (n + 3)\r\n for _ in range(m):\r\n u, v = map(int, input().split())\r\n s[u + 2] += 1\r\n s[v + 2] += 1\r\n x.append(u)\r\n x.append(v)\r\n ...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3", "3 1\n1 2", "8 14\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n5 6\n6 7", "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n3 4\n2 3\n2 4\n1 3\n2 1\n4 1", "4 4\n2 3\n1 2\n3 4\n1 3", "5 8\n5 1\n5 2\n5 3\n3 1\n1 4\n4 2\n3 2\n5 4", "5 10\n3 5\n5 1\n1 3\n1 4\n2...
UNKNOWN
PYTHON3
CODEFORCES
1
490201d0bd08c1c3ad12301c1024bdd5
Antipalindrome
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
[ "def is_pal(S):\r\n\r\n for i in range(0, len(S)):\r\n\r\n if S[i] != S[-(i+1)]: return False\r\n\r\n return True\r\n\r\nwhile True:\r\n S = input()\r\n\r\n if not is_pal(S):\r\n\r\n print(len(S))\r\n\r\n else:\r\n\r\n if S.count(S[0]) == len(S):\r\n\r\n print(0)\r\n\r...
{"inputs": ["mew", "wuffuw", "qqqqqqqq", "ijvji", "iiiiiii", "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "ijvxljt", "fyhcncnchyf", "ffffffffffff", "fyhcncfsepqj", "ybejrrlbcinttnicblrrjeby", "yyyyyyyyyy...
UNKNOWN
PYTHON3
CODEFORCES
453
493b20f8548f7eeddc61d9e27d46a567
Beauty Pageant
General Payne has a battalion of *n* soldiers. The soldiers' beauty contest is coming up, it will last for *k* days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The v...
[ "\r\nN,K = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nlib = {}\r\n\r\nfor a in A:\r\n nlib = {}\r\n nlib[str(a)] = [a]\r\n for b,k in lib.items():\r\n nlib[b] = k\r\n t = int(b)+a\r\n nlib[str(t)] = k+[a]\r\n lib = nlib\r\n if len(lib)>=K:break\r\n ...
{"inputs": ["3 3\n1 2 3", "2 1\n7 12", "1 1\n1000", "5 8\n10 3 8 31 20", "5 15\n1 2 3 4 5", "8 25\n6 8 3 7 2 1 4 9", "10 9\n5 10 2 14 15 6 3 11 4 1", "10 27\n17 53 94 95 57 36 47 68 48 16", "6 5\n17 35 15 11 33 39", "10 27\n17 53 94 95 57 36 47 68 48 16", "30 122\n5858 8519 5558 2397 3059 3710 6238 8547 2167 9401 471 9...
UNKNOWN
PYTHON3
CODEFORCES
12
496ca3229acb846a688f9099b6dd5e8a
Valera and Elections
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo...
[ "from sys import stdin\r\ninput=stdin.readline\r\nn=int(input())\r\ng=[[] for i in range(n)]\r\ncolor=[0]*n\r\nfor _ in range(n-1):\r\n x,y,t=map(int,input().split())\r\n g[x-1].append(y-1)\r\n g[y-1].append(x-1)\r\n if t==2:\r\n color[x-1]=color[y-1]=1\r\ndp=[0]*n\r\nq=[(-1,0,0)] # parent,vertex,state=0/1\r...
{"inputs": ["5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "2\n1 2 1", "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2", "2\n2 1 1", "2\n1 2 2", "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1", "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2", "10\...
UNKNOWN
PYTHON3
CODEFORCES
27
4974f12e3cb593b80705adf0a057f681
Fair Game
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with...
[ "n = int(input())\r\na = []\r\nfor i in range(n):\r\n a.append(int(input()))\r\np = 0\r\nv = 0\r\na = sorted(a)\r\nflag = True\r\nfor i in range(n//2):\r\n p = a[i]\r\n v = a[-1]\r\n m = a.count(p)\r\n z = a.count(v)\r\n if m+z != n:\r\n break\r\n if m == z and p != v:\r\n print(\...
{"inputs": ["4\n11\n27\n27\n11", "2\n6\n6", "6\n10\n20\n30\n20\n10\n20", "6\n1\n1\n2\n2\n3\n3", "2\n1\n100", "2\n1\n1", "2\n100\n100", "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43", "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n1...
UNKNOWN
PYTHON3
CODEFORCES
208
4982d2f28521315d88b166ca7f5f239e
Cards
User ainta loves to play with cards. He has *a* cards containing letter "o" and *b* cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. 1. At first, the score is 0. 1. For each block of contiguous "o"s with length *x* the score increases by *x*2. 1....
[ "# Made By Mostafa_Khaled \nbot = True \na,b=map(int,input().split())\n\n\n\ndef sqr(x):\n\n return x*x\n\n\n\ndef work( num, flag=0 ):\n\n ans=sqr(a-num+1)+num-1\n\n could = min(b, num+1)\n\n\n\n cc=b//could\n\n res=b%could\n\n\n\n ans-=res * sqr(cc+1) + (could-res)*sqr(cc)\n\n if flag:\n\n ...
{"inputs": ["2 3", "4 0", "0 4", "8 6", "28691 28312", "1 1", "46000 39000", "1234 5678", "19310 18", "38 5", "2 122", "9966 12376", "4 2", "0 26501", "500 500", "98751 29491", "1 18468", "75232 0", "83093 94343", "86224 91008", "92608 85844", "94989 92701", "83195 80484", "4 9", "8 10", "223 874", "206 209", "493 442"...
UNKNOWN
PYTHON3
CODEFORCES
4
49b905b62f9c5824272b2291ceda48cc
New Year and North Pole
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40<=000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20<=000 kilometers. Limak, a polar bear, lives on the...
[ "n = int(input())\r\nk1 = 0\r\nk2 = 0\r\nfor i in range(n):\r\n s = input().split()\r\n a = int(s[0])\r\n b = s[1]\r\n if k1 == 0 and b != 'South':\r\n k2 = 1\r\n if k1 == 20000 and b != 'North':\r\n k2 = 1\r\n if b =='South':\r\n k1 += a\r\n if b == 'North':\r\n k1 ...
{"inputs": ["5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "2\n15000 South\n4000 East", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "3\n20000 South\n10 East\n20000 North", "2\n1000 North\n1000 South", "4\n50 South\n50 North\n15000 South\n15000 North", "1\n1 South", "1\n1 East",...
UNKNOWN
PYTHON3
CODEFORCES
6
49bbc3a391b0992b425b3d452dcca37e
The Great Mixing
Sasha and Kolya decided to get drunk with Coke, again. This time they have *k* types of Coke. *i*-th type is characterised by its carbon dioxide concentration . Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration . The drink should also be tasty...
[ "from collections import deque\r\nn, k = map(int, input().split())\r\nd = set(int(x)-n for x in input().split())\r\n \r\nq = deque()\r\nq.append(0)\r\n \r\nvisited = {i : False for i in range(-1000, 1001)}\r\ndist = {i : 0 for i in range(-1000, 1001)}\r\n \r\nans = -1\r\nvisited[0] = True\r\nfound = ...
{"inputs": ["400 4\n100 300 450 500", "50 2\n100 25", "500 3\n1000 5 5", "500 1\n1000", "874 3\n873 974 875", "999 2\n1 1000", "326 18\n684 49 373 57 747 132 441 385 640 575 567 665 323 515 527 656 232 701", "314 15\n160 769 201 691 358 724 248 47 420 432 667 601 596 370 469", "0 1\n0", "0 1\n1000", "345 5\n497 135 21 ...
UNKNOWN
PYTHON3
CODEFORCES
2
49f2657e95388d8b4d1a4f0171e94002
Caesar's Legions
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had *n*1 footmen and *n*2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that *k*1 footmen standing successively one after another, or there are strictly more than *k*2 ...
[ "MOD = 100000000\r\ndic = {}\r\n \r\n \r\ndef fun(x1, x2, op) -> int:\r\n result = 0\r\n key = x1, x2, op\r\n if key in dic.keys():\r\n return dic[key]\r\n \r\n if op == 0:\r\n if x2 <= 0:\r\n return x1 <= k1\r\n I = min(x1, k1)\r\n for i in range(1, I + 1):\r\n ...
{"inputs": ["2 1 1 10", "2 3 1 2", "2 4 1 1", "10 10 5 7", "12 15 7 2", "20 8 4 8", "15 8 2 6", "100 100 10 10", "20 15 10 9", "18 4 3 1", "19 12 5 7", "20 4 9 4", "24 30 5 1", "56 37 4 1", "28 65 5 9", "67 26 6 1", "57 30 5 9", "56 40 3 2", "34 57 1 1", "78 21 10 1", "46 46 2 5", "34 55 2 9", "46 51 4 5", "64 23 3 6",...
UNKNOWN
PYTHON3
CODEFORCES
5
4a24486ea6580c3b63d77eca7df64ea9
New Year's Eve
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
[ "def precompute(arr) :\r\n arr[0] = 1\r\n for index in range(1,60) :\r\n arr[index] = arr[index-1]*2\r\n\r\ndef solve(n,k,power) :\r\n if k == 1 :\r\n return n\r\n \r\n else :\r\n for index in range(59,-1,-1):\r\n if power[index] <= n :\r\n return po...
{"inputs": ["4 3", "6 6", "2 2", "1022 10", "415853337373441 52", "75 12", "1000000000000000000 1000000000000000000", "1 1", "1000000000000000000 2", "49194939 22", "228104606 17", "817034381 7", "700976748 4", "879886415 9", "18007336 10353515", "196917003 154783328", "785846777 496205300", "964756444 503568330", "848...
UNKNOWN
PYTHON3
CODEFORCES
176
4a289f586bb2e6645c79c7f0cf249edc
Gerald is into Art
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec...
[ "n, m = map(int, input().split())\r\nx, y = map(int, input().split())\r\nz, t = map(int, input().split())\r\nif (x + z <= n and max(y, t) <= m) or (x + z <= m and max(y, t) <= n) or \\\r\n (x + t <= n and max(y, z) <= m) or (x + t <= m and max(y, z) <= n) or \\\r\n (y + z <= n and max(x, t) <= m) or (...
{"inputs": ["3 2\n1 3\n2 1", "5 5\n3 3\n3 3", "4 2\n2 3\n1 2", "3 3\n1 1\n1 1", "1000 1000\n999 999\n1 1000", "7 7\n5 5\n2 4", "3 3\n2 2\n2 2", "2 9\n5 1\n3 2", "9 9\n3 8\n5 2", "10 10\n10 5\n4 3", "10 6\n10 1\n5 7", "6 10\n6 3\n6 2", "7 10\n7 5\n1 7", "10 10\n7 4\n3 5", "4 10\n1 1\n9 3", "8 7\n1 7\n3 2", "5 10\n5 2\n3...
UNKNOWN
PYTHON3
CODEFORCES
90
4a2923425f3801d7d9f54971416d2e24
Fox And Polygon
Fox Ciel just designed a puzzle game called "Polygon"! It is played using triangulations of a regular *n*-edge polygon. The goal is to transform one triangulation to another by some tricky rules. Triangulation of an *n*-edge poylgon is a set of *n*<=-<=3 diagonals satisfying the condition that no two diagonals share a...
[ "\r\nimport sys,random,bisect\r\nfrom collections import deque,defaultdict\r\nfrom heapq import heapify,heappop,heappush\r\nfrom itertools import permutations\r\nfrom math import log,gcd\r\n\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\n\r\nn...
{"inputs": ["4\n1 3\n2 4", "6\n2 6\n3 6\n4 6\n6 2\n5 2\n4 2", "8\n7 1\n2 7\n7 3\n6 3\n4 6\n6 1\n6 2\n6 3\n6 4\n6 8", "5\n5 2\n2 4\n5 2\n5 3", "5\n5 2\n2 4\n4 1\n3 1", "10\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n5 1\n5 2\n5 3\n5 7\n5 8\n5 9\n5 10", "20\n15 17\n15 18\n11 15\n11 18\n13 15\n13 11\n6 11\n6 18\n8 11\n8 6\n9 11\n...
UNKNOWN
PYTHON3
CODEFORCES
1
4a300e8ace2b5a9aa665fdd66426a084
Economy Game
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ...
[ "n = int(input())\r\n\r\nfor i in range(0, n+1, 1234567):\r\n for j in range(0, n-i+1, 123456):\r\n if (n - i - j) % 1234 == 0:\r\n print(\"YES\")\r\n exit()\r\n\r\nprint(\"NO\")", "while True:\r\n try: \r\n num = int(input())\r\n k = 0\r\n for a in range(num//1234567+1)...
{"inputs": ["1359257", "17851817", "1000000000", "17851818", "438734347", "43873430", "999999987", "27406117", "27404883", "27403649", "27402415", "27401181", "999999999", "999999244", "999129999", "17159199", "13606913", "14841529", "915968473", "980698615", "912331505", "917261049", "999999997", "12345", "1234", "124...
UNKNOWN
PYTHON3
CODEFORCES
56
4a3abdb3853aba03dd032f21afa9b29e
Vanya and Cubes
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must...
[ "n = int(input())\n\nlevels = 0\nprev, current = 0, 0\nadd = 0\ns = 0\nwhile True:\n if levels % 2 == 1: add += 1\n current = prev + 1 + 2 * add if levels % 2 == 0 else prev + 2 * add\n s += current\n if s > n: break\n prev = current\n levels += 1\nprint(levels)", "n = int(input())\r\nh= 0\r\nsc...
{"inputs": ["1", "25", "2", "4115", "9894", "7969", "6560", "4", "3", "5", "19", "20", "9880", "9879", "7770", "7769", "2925", "220", "219", "3046", "7590", "1014", "7142", "9999", "10000"], "outputs": ["1", "4", "1", "28", "38", "35", "33", "2", "1", "2", "3", "4", "38", "37", "35", "34", "25", "10", "9", "25", "34", ...
UNKNOWN
PYTHON3
CODEFORCES
291
4a53944b64c9021707880d6929270e7b
Blown Garland
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is workin...
[ "s = input()\r\nans = \"\"\r\nfor j in range(4):\r\n for i in s[j::4]:\r\n if i!='!':\r\n ans += i\r\n break\r\n \r\narr = {}\r\narr['R'] = 0\r\narr['B'] = 0\r\narr['Y'] = 0\r\narr['G'] = 0\r\n \r\nfor j in range(4):\r\n for i in s[j::4]:\r\n if i=='!':\r\n arr[a...
{"inputs": ["RYBGRYBGR", "!RGYB", "!!!!YGRB", "!GB!RG!Y!", "RYBG", "!Y!!!Y!!G!!!G!!B!!R!!!!B!!!!!Y!!G!R!!!!!!!!!!!!B!!!!GY!B!!!!!YR!G!!!!!!B!Y!B!!!!!!R!G!!!!!!!G!R!!!!B", "!R!GBRYG!RYGB!!G!!YG!!Y!!", "RBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGY", "GYRB!", "RBYGR"...
UNKNOWN
PYTHON3
CODEFORCES
25
4abb8eb6057670c2c03f4e296ac68c82
Restaurant Tables
In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate...
[ "n, a, b = map(int, input().split())\n\nc = 0\n\nans = 0\n\nfor v in map(int, input().split()):\n\tif v == 1:\n\t\tif a:\n\t\t\ta -= 1\n\t\telif b:\n\t\t\tb -= 1\n\t\t\tc += 1\n\t\telif c:\n\t\t\tc -= 1\n\t\telse:\n\t\t\tans += 1\n\telse:\n\t\tif b:\n\t\t\tb -= 1\n\t\telse:\n\t\t\tans += 2\n\nprint(ans)", "def ch...
{"inputs": ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1", "1 1 1\n1", "2 1 2\n2 2", "5 1 3\n1 2 2 2 1", "7 6 1\n1 1 1 1 1 1 1", "10 2 1\n2 1 2 2 2 2 1 2 1 2", "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2", "1 1 1\n1", "1 1 1\n2", "1 200000 200000\n2", "30 10 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2", "...
UNKNOWN
PYTHON3
CODEFORCES
104
4acf4ae14d6675929825cacfbbbf1acd
Nastya Studies Informatics
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (*a*,<=*b*) good, if *GCD*(*a*,<=*b*)<==<=*x* and *LCM*(*a*,<=*b*)<==<=*y*, where *GCD*(*a*,...
[ "def gcd(a,b):\r\n if(b==0):\r\n return(a)\r\n return(gcd(b,a%b))\r\nl,r,x,y=map(int,input().split())\r\nif(y%x!=0):\r\n print(0)\r\nelse:\r\n c=0\r\n k=y//x\r\n i=1\r\n while(i*i<=k):\r\n if(k%i==0):\r\n j=k//i\r\n if((l<=j*x and j*x<=r) and (l<=i*x and i*x<...
{"inputs": ["1 2 1 2", "1 12 1 12", "50 100 3 30", "1 1000000000 1 1000000000", "1 1000000000 158260522 200224287", "1 1000000000 2 755829150", "1 1000000000 158260522 158260522", "1 1000000000 877914575 877914575", "232 380232688 116 760465376", "47259 3393570 267 600661890", "1 1000000000 1 672672000", "1000000000 10...
UNKNOWN
PYTHON3
CODEFORCES
30
4adbfa2180fc0d9acc69d767c335bc86
Chat Order
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then...
[ "n = int(input())\r\nv = []\r\nfor i in range(n):\r\n name = input()\r\n v.append(name)\r\n# v contains all names in the initial order\r\n# now we have to process the list in reverse order\r\ns = set() # should use set() for set\r\nfor i in range(n-1, -1, -1): # start from the last index, dec by 1, stop at -1\r\n...
{"inputs": ["4\nalex\nivan\nroman\nivan", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "1\nwdi", "2\nypg\nypg", "3\nexhll\nexhll\narruapexj", "3\nfv\nle\nle", "8\nm\nm\nm\nm\nm\nm\nm\nm", "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "...
UNKNOWN
PYTHON3
CODEFORCES
358
4ae677cc69c7c41198e0d5325cef87d9
Xenia and Divisors
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held: - *a*<=&lt;<=*b*<=&lt;<=*c*; - *a* divides *b*, *b* divide...
[ "# 1 2 4\n# 1 2 6\n# 1 3 6\n\nn = int(input())\narr = list(map(int, input().split()))\n\nfrom collections import Counter\n\nc = Counter(arr)\n\nif 5 in arr or 7 in arr or arr.count(1) != n//3 or arr.count(2)+arr.count(3) != n//3 or (3 in arr and arr.count(3) > arr.count(6)):\n print(-1)\nelse:\n for i in rang...
{"inputs": ["6\n1 1 1 2 2 2", "6\n2 2 1 1 4 6", "3\n1 2 3", "3\n7 5 7", "3\n1 3 4", "3\n1 1 1", "9\n1 3 6 6 3 1 3 1 6", "6\n1 2 4 1 3 5", "3\n1 3 7", "3\n1 1 1", "9\n1 2 4 1 2 4 1 3 6", "12\n3 6 1 1 3 6 1 1 2 6 2 6", "9\n1 1 1 4 4 4 6 2 2", "9\n1 2 4 6 3 1 3 1 5", "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4", "3\n2 3 6", "3\n2 ...
UNKNOWN
PYTHON3
CODEFORCES
155
4b157272fc9144a33406e44107e41fc0
Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee ...
[ "n, k, q = map(int, input().split())\nllist = [0] * 200001\n\nfor i in range(n):\n a, b = map(int, input().split())\n llist[b] += 1\n llist[a - 1] -= 1\n\nfor i in range(len(llist) - 2, -1, -1):\n llist[i] += llist[i + 1]\n\nif llist[0] >= k:\n llist[0] = 1\n\nelse:\n llist[0] = 0\nfor i in range(...
{"inputs": ["3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "2 1 1\n1 1\n200000 200000\n90 100", "1 1 1\n1 1\n1 1", "1 1 1\n200000 200000\n200000 200000"], "outputs": ["3\n3\n0\n4", "0", "1", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
107
4b2a63e8f645fb7d2ae4b5d1e88f3dd5
GCD of Polynomials
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way: This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *P*(*x*). is called the remainder of division of polynomial by polynomial ...
[ "f = [[1], [0, 1]]\n\nn = int(input())\n\nfor i in range(2, n + 1):\n\tl = [0] + f[i - 1]\n\tfor j in range(len(f[i - 2])):\n\t\tl[j] = (l[j] + f[i - 2][j]) & 1\n\tf.append(l)\n\nprint(n)\nprint(*f[n])\nprint(n - 1)\nprint(*f[n - 1])\n\n\n\n# Made By Mostafa_Khaled", "\r\nimport sys\r\n\r\nn = int(sys.stdin.readl...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",...
UNKNOWN
PYTHON3
CODEFORCES
11
4b3f5628318bf19366fb2f1bd0cf93fc
Domino Effect
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges *n* dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the domino...
[ "n=int(input())\r\ns=input()\r\nc=0\r\nm,l,r=0,-1,-1\r\nfor i in range(n):\r\n if c==0:\r\n if s[i]=='R':\r\n m+=i\r\n c=1\r\n r=i\r\n elif s[i]=='L':\r\n c=1\r\n l=i\r\n elif r>-1 and s[i]=='L':\r\n if (i-r)%2==0:\r\n m+=1...
{"inputs": ["14\n.L.R...LR..L..", "1\n.", "1\nL", "1\nR", "2\nL.", "2\nRL", "2\n..", "10\nR........L", "9\nR.......L", "6\n..L.RL", "34\n..R...L..RL..RLRLR...L....R....L..", "2\nLR", "2\n.R", "2\nR.", "2\n.L", "3\nRLR", "3\nLRL", "5\n.L.R.", "5\n.R.L.", "5\nRL.RL", "14\nLR..LR....LRLR", "34\n.RL.R.L.R..L.R...L.R....L.R...
UNKNOWN
PYTHON3
CODEFORCES
2
4b48e957142639581342a8c65a0beda0
Smallest number
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced...
[ "def solve(index):\r\n if index==3:\r\n for x in arr:\r\n if x>=0:\r\n ans[0]=min(ans[0],x)\r\n return \r\n for i in range(4):\r\n if arr[i] !=-1:\r\n for j in range(4):\r\n if i==j or arr[j]==-1:\r\n continue\r\n ...
{"inputs": ["1 1 1 1\n+ + *", "2 2 2 2\n* * +", "1 2 3 4\n* + +", "15 1 3 1\n* * +", "8 1 7 14\n+ + +", "7 17 3 25\n+ * +", "13 87 4 17\n* * *", "7 0 8 15\n+ + *", "52 0 43 239\n+ + +", "1000 1000 999 1000\n* * *", "720 903 589 804\n* * *", "631 149 496 892\n* * +", "220 127 597 394\n* + +", "214 862 466 795\n+ + +", "...
UNKNOWN
PYTHON3
CODEFORCES
34
4b49d862e1af6b9a457569a38e2ed5c2
Rational Resistance
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil...
[ "def euc(a, b):\r\n if b==0:\r\n return 0\r\n return a//b + euc(b, a%b)\r\n\r\na, b = [int(i) for i in input().split()]\r\nprint(euc(a,b))\r\n", "def rec(s,t):\r\n if s==0 or t==0:\r\n return 0\r\n if (t>s):\r\n return rec(t,s)\r\n return s//t + rec(s%t,t)\r\n\r\ns,t = map(int,input().split(...
{"inputs": ["1 1", "3 2", "199 200", "1 1000000000000000000", "3 1", "21 8", "18 55", "1 2", "2 1", "1 3", "2 3", "1 4", "5 2", "2 5", "4 5", "3 5", "13 4", "21 17", "5 8", "13 21", "74 99", "2377 1055", "645597 134285", "29906716 35911991", "3052460231 856218974", "288565475053 662099878640", "11504415412768 127540361...
UNKNOWN
PYTHON3
CODEFORCES
65
4b555db9f755aa0d187fe9ae322aa163
Running Track
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating *t*. On planet AMI-1511 the coating of the t...
[ "\r\ns = input()\r\nlen_s = len(s)\r\nreversed_s = s[::-1]\r\nt = input()\r\nlen_t = len(t)\r\nres = 0\r\ntracks = []\r\nstep = 0\r\n\r\nwhile step < len_t:\r\n if t[step : step + 1] not in s:\r\n print(-1)\r\n exit()\r\n \r\n plus = 1\r\n while (t[step : step + plus] in s or t[step : ...
{"inputs": ["abc\ncbaabc", "aaabrytaaa\nayrat", "ami\nno", "r\nr", "r\nb", "randb\nbandr", "aaaaaa\naaaaa", "aaaaaa\naaaaaaa", "qwerty\nywertyrewqqq", "qwerty\nytrewq", "azaza\nzazaz", "mnbvcxzlkjhgfdsapoiuytrewq\nqwertyuiopasdfghjklzxcvbnm", "imnothalfthemaniusedtobetheresashadowhangingovermeohyesterdaycamesuddenlywgk...
UNKNOWN
PYTHON3
CODEFORCES
4
4b567bd6e01c14c6cad914fb1e248b98
Luxurious Houses
The capital of Berland has *n* multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in a...
[ "t = int(input())\r\na = input().split()\r\nh = []\r\nmh = 0\r\nfor i in range(t - 1, -1, -1):\r\n h.append(max(0, mh + 1 - int(a[i])))\r\n mh = max(mh, int(a[i]))\r\nprint(*h[::-1])\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nh = list...
{"inputs": ["5\n1 2 3 1 2", "4\n3 2 1 4", "1\n2", "2\n5 4", "5\n10 18 36 33 20", "5\n91 96 94 95 91", "10\n9 6 8 5 5 2 8 9 2 2", "10\n55 50 51 53 53 52 50 54 54 53", "20\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "20\n82 78 86 80 80 76 88 74 70 88 71 75 73 72 79 85 79 90 79 77", "40\n66 68 59 100 55...
UNKNOWN
PYTHON3
CODEFORCES
13
4b60048a0e4b413fa9ba63a4af5433db
Lucky Probability
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the ...
[ "import itertools as it\n\n\n\nall_lucky = []\n\nfor length in range(1, 10):\n for comb in it.product(['7', '4'], repeat=length):\n all_lucky += [int(''.join(comb))]\n\nall_lucky.sort()\n\n# print(len(all_lucky))\n\npl, pr, vl, vr, k = map(int, input().split())\n\nresult = 0\n\ndef inters_len(a, b, c, d):...
{"inputs": ["1 10 1 10 2", "5 6 8 10 1", "1 20 100 120 5", "1 10 1 10 3", "1 100 1 100 2", "47 95 18 147 4", "1 1000000000 1 1000000000 47", "1 2 3 4 12", "1 50 64 80 4", "1 128 45 99 2", "45 855 69 854 7", "1 1000 1 1000 2", "999 999 1000 1000 1", "789 5888 1 10 7", "1 1000 1 1000 14", "4 4 7 7 2", "7 7 4 4 2", "2588 ...
UNKNOWN
PYTHON3
CODEFORCES
10
4b6a67bb76e77433f586d37d78ecdfae
Sofa Thief
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ...
[ "import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nd = int(input())\r\nn, m = map(int, input().split())\r\n\r\nL = []\r\nR = []\r\nT = []\r\nB = []\r\n\r\nXY = []\r\nfor i in range(d):\r\n x1, y1, x2, y2 = map(int, input().split())\r\n L.append((min(x1, x2)))\r\...
{"inputs": ["2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1", "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0", "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0", "1\n1 2\n1 1 1 2\n0 0 0 0", "1\n2 1\n2 1 1 1\n0 0 0 0", "1\n1000 1000\n63 902 63 901\n0 0 0 0", "6\n10 10\n3 6 3 7\n4 9 5 9\n5 4 5 3\n7 1 8 1\n9 10 8 10\n7 7 7 8\n0 5 2 3", "2\n4 4\n3 1 ...
UNKNOWN
PYTHON3
CODEFORCES
5
4b6ebb7fe049d8c36c6388590e93ec3c
Prime Gift
Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn how to solve number theory problems in the past year. That's why instead of Ded Moroz he was visited by his teammate Andrew, who solemnly presented him with a set of *n* distinct prime numbers alongside with a...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(x):\r\n a = [1]\r\n for i in range(1, pow2[len(x)]):\r\n y = []\r\n u = 1\r\n for j in range(len(x)):\r\n if i & pow2[j]:\r\n y.append(x[j])\r\n u *= x...
{"inputs": ["3\n2 3 5\n7", "5\n3 7 11 13 31\n17", "2\n41 61\n66", "1\n2\n55", "7\n2 3 5 7 11 13 17\n2666471", "16\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53\n755104793", "8\n3 7 13 17 19 29 31 37\n68830", "8\n3 7 11 17 19 23 37 43\n528714", "8\n3 7 13 17 29 41 43 47\n430196", "8\n2 5 7 19 29 31 37 41\n912071", "9\n2 ...
UNKNOWN
PYTHON3
CODEFORCES
1
4b846aa0277bb4b4c287ebc625fd544d
Interactive Bulls and Cows (Hard)
The only difference from the previous problem is the constraint on the number of requests. In this problem your program should guess the answer doing at most 7 requests. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get re...
[ "import random\r\n\r\nall = []\r\nfor i in range(123, 9876 + 1):\r\n s = str(i)\r\n if len(s) == 3:\r\n s = \"0\" + s\r\n if len(set(s)) == 4:\r\n all.append(s)\r\n\r\nn = len(all)\r\nrest = set(all)\r\n\r\nmove = random.choice(list(rest))\r\n\r\nfirst = 0\r\nwhile len(rest) > 1:\r\n print...
{"inputs": ["0123", "1234", "9876", "7158", "7590", "7325", "7524", "7269", "7802", "7436", "7190", "7390", "2548", "2193", "2491", "2469", "2659", "2405", "2058", "2580", "2316", "2516", "8796", "8534", "9067", "8712", "9023", "8645", "8623", "8923", "8567", "8756", "0351", "9863", "0518", "0263", "0462", "0429", "062...
UNKNOWN
PYTHON3
CODEFORCES
1
4b8bf6a7e20682853f8d4eb7977979bc
Kefa and Park
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v...
[ "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nadjlist = [[] for _ in range(n)]\r\nfor i in range(n-1):\r\n\tx, y = map(int, input().split())\r\n\tadjlist[x-1] += [y-1]\r\n\tadjlist[y-1] += [x-1]\r\n\r\ndef dfs(node: int) ->int:\r\n\tseen = [0]*n\r\n\tret = 0\r\n\ts = [(node, 0)]\r\...
{"inputs": ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "3 2\n1 1 1\n1 2\n2 3", "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5", "6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6", "7 3\n1 1 1 1 1 0 1\n1 2\n1 3\n2 4\n3 5\n5 6\n6 7", "15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7...
UNKNOWN
PYTHON3
CODEFORCES
44
4b9a92245483f4058b4f0cb60081df9b
XOR Equation
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)? The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectivel...
[ "def func(S,X):\r\n\r\n if S - X < 0 :\r\n return 0\r\n\r\n elif (S - X) % 2:\r\n return 0\r\n\r\n nd = (S - X) // 2\r\n c = 0\r\n\r\n while X:\r\n\r\n if X & 1:\r\n\r\n if nd & 1:\r\n return 0\r\n\r\n c += 1\r\n\r\n X >>= 1\r\n ...
{"inputs": ["9 5", "3 3", "5 2", "6 0", "549755813887 549755813887", "2 0", "2 2", "433864631347 597596794426", "80 12", "549755813888 549755813886", "643057379466 24429729346", "735465350041 356516240229", "608032203317 318063018433", "185407964720 148793115916", "322414792152 285840263184", "547616456703 547599679487...
UNKNOWN
PYTHON3
CODEFORCES
22
4b9efbe937a1036c33df235b8132dfe0
Invariance of Tree
A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles. Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by a...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\ndef process(A):\r\n n = len(A)\r\n answer = []\r\n for i in range(n):\r\n ai = A[i]\r\n if ai==i+1:\r\n for j in range(n):\r\n if j != i:\r\n answer.append([j+1, i+1])\r\n return ['...
{"inputs": ["4\n4 3 2 1", "3\n3 1 2", "3\n3 2 1", "4\n3 4 1 2", "5\n5 3 2 1 4", "8\n1 2 6 4 5 7 8 3", "11\n7 3 5 2 10 1 9 6 8 4 11", "1\n1", "2\n1 2", "2\n2 1", "6\n2 1 6 5 3 4", "6\n2 1 4 5 6 3", "4\n2 3 4 1", "6\n2 3 4 1 6 5", "6\n4 1 2 3 6 5"], "outputs": ["YES\n4 1\n4 2\n1 3", "NO", "YES\n2 1\n2 3", "YES\n4 2\n4 1\...
UNKNOWN
PYTHON3
CODEFORCES
5
4bf42ec96ffd1342873f59118733cee4
Full Binary Tree Queries
You have a full binary tree having infinite levels. Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1. The value of the root is 1. You need to answer *Q* queries. There are 3 types of queries: 1. Cyclically shift the values of...
[ "import sys\r\ninput = sys.stdin.readline\r\n \r\nshift = [0]*60\r\n \r\n \r\ndef find(x):\r\n lvl = 0\r\n while (1 << (lvl + 1)) <= x:\r\n lvl += 1\r\n return lvl\r\n \r\n \r\nfor _ in range(int(input())):\r\n q = [int(i) for i in input().split()]\r\n x = q[1]\r\n lvl = find(x)\r\n ln =...
{"inputs": ["5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8", "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14", "6\n3 1\n2 1 0\n3 10\n2 1 -4\n3 10\n2 10 -5", "3\n3 1000000000000000000\n1 12345 13\n3 1000000000000000000", "10\n3 999\n3 822\n2 339 -75\n2 924 -56\n3 863\n3 311\n1 269 84\n2 604 9\n2 788 -98\n1 233 60", "10\n2 64324170 413214447865...
UNKNOWN
PYTHON3
CODEFORCES
1
4bfe1e0069a303c77dfd34af728b3070
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th ...
[ "from sys import stdin,stdout\r\ninput = lambda : stdin.readline().rstrip()\r\nprint =lambda x : stdout.write(str(x))\r\n\r\nn, m = map(int,input().split())\r\nb, *hb = [int(x) for x in input().split()]\r\ng, *hg = [int(x) for x in input().split()]\r\n\r\nfor i in range(2*n*m):\r\n\t\tif (i%n) in hb and (i%m) not i...
{"inputs": ["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1", "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82", "52 91\n13 26 1 3 43 17 19 32 46 33 48 23 37 50\n25 78 26 1 40 2 67 42 4 56 30 70 84 32 20 85 59 8 86 34 73 23 10 88 24 11", "26 52\n8 0 14 16...
UNKNOWN
PYTHON3
CODEFORCES
28
4c06a1bab8e7d9a2924976ed686dc364
Find Amir
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an...
[ "r = int(input())\r\nif r%2 == 1:\r\n print (r//2)\r\nelse:\r\n print(r//2-1)\r\n", "from math import ceil\r\nn = int(input())\r\nprint(ceil(max(0, n/2-1)))", "import math\n\n\ndef solve(a):\n a = int(a)\n print(math.ceil(a / 2) - 1)\n\n\nuser = input()\n\nsolve(user)\n \t \t \t \t \t\t \t\t\...
{"inputs": ["2", "10", "43670", "4217", "17879", "31809", "40873", "77859", "53022", "79227", "100000", "82801", "5188", "86539", "12802", "20289", "32866", "33377", "31775", "60397", "100000", "99999", "99998", "99997", "99996", "1", "2", "3", "4", "1", "3"], "outputs": ["0", "4", "21834", "2108", "8939", "15904", "20...
UNKNOWN
PYTHON3
CODEFORCES
170
4c0d2851e8af707dd834cb7304166c2a
Young Physicist
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
[ "n=int(input())\na_1=[]\nb_1=[]\nc_1=[]\nfor i in range(n):\n a,b,c=map(int,input().split())\n a_1.append(a)\n b_1.append(b)\n c_1.append(c)\n\n\nif sum(a_1)==0 and sum(b_1)==0 and sum(c_1)==0:\n print(\"YES\")\nelse:\n print(\"NO\")\n \n", "n=int(input())\r\na=0\r\nb=0\r\nc=0\r\nfor i in ran...
{"inputs": ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "10\n-6 21 18\n20 -...
UNKNOWN
PYTHON3
CODEFORCES
3,146
4c5d9381944990813e0c5b4985ad0cc7
Table Tennis
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of t...
[ "n, k = map(int, input().split())\r\nv = list(map(int, input().split()))\r\ncount = 0\r\nprevious = v[0]\r\nfor i in range(1, n):\r\n\tif previous>v[i]:\r\n\t\tcount+=1\r\n\telse:\r\n\t\tprevious = v[i]\r\n\t\tcount = 1\r\n\tif count==k:\r\n\t\tbreak\r\nprint(previous)", "n, k = [int(x) for x in input().split()]\...
{"inputs": ["2 2\n1 2", "4 2\n3 1 2 4", "6 2\n6 5 3 1 2 4", "2 10000000000\n2 1", "4 4\n1 3 4 2", "2 2147483648\n2 1", "3 2\n1 3 2", "3 3\n1 2 3", "5 2\n2 1 3 4 5", "10 2\n7 10 5 8 9 3 4 6 1 2", "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90...
UNKNOWN
PYTHON3
CODEFORCES
206
4c5e4af36646b7431328b73207d396aa
Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
[ "n=int(input())\r\ns=input()\r\nc=[]\r\nfor i in range(n):\r\n c.append(s[i])\r\nfor i in range(n-1):\r\n if c[i]==\"U\" and c[i+1]==\"R\":\r\n c[i]=\"D\"\r\n c[i+1]=\"D\"\r\n if c[i]==\"R\" and c[i+1]==\"U\":\r\n c[i]=\"D\"\r\n c[i+1]=\"D\"\r\nprint(n-((c.count(\"D\"))//2)) ...
{"inputs": ["5\nRUURU", "17\nUUURRRRRUUURURUUU", "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
UNKNOWN
PYTHON3
CODEFORCES
249
4c628953952ca885e9bdfe1f8d432e5f
Points
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000...
[ "\"\"\"**************************************************************\\\r\n BISMILLAHIR RAHMANIR RAHIM\r\n****************************************************************\r\n AUTHOR NAME: MD. TAHURUZZOHA TUHIN\r\n\\**************************************************************\"\"\"\...
{"inputs": ["4\n1 1\n-1 -1\n1 -1\n-1 1", "1\n6 3", "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1\n-13 -9\n13 17\n-14 -8\n2 5\n18 5"], "outputs": ["32", "0", "265705"]}
UNKNOWN
PYTHON3
CODEFORCES
19
4c6f3c4cf65608d51f3e8cb2edb582fa
Summarize to the Power of Two
A sequence $a_1, a_2, \dots, a_n$ is called good if, for each element $a_i$, there exists an element $a_j$ ($i \ne j$) such that $a_i+a_j$ is a power of two (that is, $2^d$ for some non-negative integer $d$). For example, the following sequences are good: - $[5, 3, 11]$ (for example, for $a_1=5$ we can choose $a_2=3...
[ "def f(x):\r\n i = 0\r\n while x >= 2**i:\r\n i += 1\r\n return i\r\n\r\n\r\n# with open('test.txt') as file:\r\n# n = file.readline()\r\n# l = list(map(int, file.readline().split()))\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nif not l:\r\n print(0)\r\nelse:\r\n uniq...
{"inputs": ["6\n4 7 1 5 4 9", "5\n1 2 3 4 5", "1\n16", "4\n1 1 1 1023", "10\n2 10 9 1 10 4 7 8 5 4", "2\n1 1", "2\n1 6", "6\n1 7 7 7 7 7", "3\n1 2 3", "3\n1 3 3", "2\n3 3", "2\n3 1", "3\n1 2 2", "2\n2 2", "2\n2 1", "3\n1 1 3", "3\n1 3 2", "3\n1 1 2", "1\n1"], "outputs": ["1", "2", "1", "0", "5", "0", "2", "0", "1", "0"...
UNKNOWN
PYTHON3
CODEFORCES
25
4c73f2082dd47092f72be6e744d64e2a
Pursuit For Artifacts
Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience. In that country there are *n* islands and *m* bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerfu...
[ "if True:\r\n from io import BytesIO, IOBase\r\n import math\r\n\r\n import random\r\n import sys\r\n import os\r\n\r\n import bisect\r\n import typing\r\n from collections import Counter, defaultdict, deque\r\n from copy import deepcopy\r\n from functools import cmp_to_key, lru_cache,...
{"inputs": ["6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6", "5 4\n1 2 0\n2 3 0\n3 4 0\n2 5 1\n1 4", "5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2", "1 0\n1 1", "2 1\n1 2 1\n1 2", "2 1\n1 2 1\n1 1", "3 2\n1 2 1\n2 3 0\n3 1", "3 2\n1 2 1\n2 3 0\n2 3", "3 3\n1 2 0\n2 3 0\n3 1 1\n2 2", "4 4\n1 2 0\n2 3 0...
UNKNOWN
PYTHON3
CODEFORCES
1
4c89c41cf6f52dd1d44ab9210465e0d0
Codeforces World Finals
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a...
[ "import itertools as it\n\nmonth_to_days_non_leap = {\n 1: 31,\n 2: 28,\n 3: 31,\n 4: 30,\n 5: 31,\n 6: 30,\n 7: 31,\n 8: 31,\n 9: 30,\n 10: 31,\n 11: 30,\n 12: 31,\n}\n\ndef month_year_to_day(month, year):\n if year % 4 == 0 and month == 2:\n return 29\n else:\n ...
{"inputs": ["01.01.98\n01.01.80", "20.10.20\n10.02.30", "28.02.74\n28.02.64", "05.05.25\n06.02.71", "19.11.54\n29.11.53", "01.06.84\n24.04.87", "30.06.43\n14.09.27", "09.05.55\n25.09.42", "14.05.21\n02.01.88", "27.12.51\n26.06.22", "12.10.81\n18.11.04", "26.04.11\n11.07.38", "17.01.94\n17.03.58", "15.01.93\n23.04.97", ...
UNKNOWN
PYTHON3
CODEFORCES
9
4c9a939d342fd4c12a76fa302d4e427b
Sorting by Subsequences
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a sub...
[ "import bisect\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nsorted_a = sorted(a)\r\n\r\nnum_list = [bisect.bisect_left(sorted_a, i) for i in a]\r\n\r\nval_list = [False] * n\r\nans = []\r\n\r\nfor i in range(n):\r\n if not val_list[i]:\r\n val_list[i] = True\r\n que = [i + 1]\r...
{"inputs": ["6\n3 2 1 6 5 4", "6\n83 -75 -49 11 37 62", "1\n1", "2\n1 2", "2\n2 1", "3\n1 2 3", "3\n3 2 1", "3\n3 1 2", "10\n3 7 10 1 9 5 4 8 6 2", "20\n363756450 -204491568 95834122 -840249197 -49687658 470958158 -445130206 189801569 802780784 -790013317 -192321079 586260100 -751917965 -354684803 418379342 -253230108 ...
UNKNOWN
PYTHON3
CODEFORCES
43
4c9bcbb129bcfcac01bafaf31161d591
ucyhf
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. jxu ydfkj sediyiji ev q iydwbu ydjuwuh *d* (1<=≤<=*d*<=≤<=11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt. ekjfkj q iydwbu dkcruh. Sample Input 1 Sample Output 13
[ "import sys\n\n#input functions\nreadint = lambda: int(sys.stdin.readline())\nreadints = lambda: map(int,sys.stdin.readline().split())\nreadar = lambda: list(map(int,sys.stdin.readline().split()))\nflush = lambda: sys.stdout.flush()\n\nfrom math import sqrt, floor\n\ndef sieve(n: int) -> list[bool]:\n ar = [True...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "8216", "119", "10618", "6692", "10962", "6848", "4859", "8653", "6826", "10526", "9819", "10844", "7779", "1340", "4020", "2279", "5581", "11107", "7397", "5273", "10476", "7161", "4168", "1438", "6327", "10107", "6399", "11182", "11183", "11184"], "output...
UNKNOWN
PYTHON3
CODEFORCES
11
4cb7aba01159e7079d9d6d1b8549c5e8
Elimination
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list....
[ "import math \nc,d = map(int,input().split())\nn,m = map(int,input().split())\nk = int(input())\nx = n*m - k \nq,r = divmod(x,n)\nif (x<=0):\n print(0)\n quit()\n\nans = min(c*math.ceil(x/n),d*x)\nans = min(ans,c*math.floor(x/n) + r*d)\nprint(ans)\n\n ", "# Made By Mostafa_Khaled \nbot = True \nc, d = li...
{"inputs": ["1 10\n7 2\n1", "2 2\n2 1\n2", "8 9\n2 2\n3", "5 5\n8 8\n7", "1 8\n8 10\n8", "5 7\n9 1\n8", "35 28\n35 60\n44", "19 76\n91 91\n87", "20 38\n38 70\n58", "2 81\n3 39\n45", "7 63\n18 69\n30", "89 69\n57 38\n15", "3 30\n10 83\n57", "100 3\n93 23\n98", "2 78\n21 24\n88", "40 80\n4 31\n63", "1 48\n89 76\n24", "5 ...
UNKNOWN
PYTHON3
CODEFORCES
21
4cc15ba1bf48baf470e3df7be87f7edc
none
Есть *n*-подъездный дом, в каждом подъезде по *m* этажей, и на каждом этаже каждого подъезда ровно *k* квартир. Таким образом, в доме всего *n*·*m*·*k* квартир. Они пронумерованы естественным образом от 1 до *n*·*m*·*k*, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором ...
[ "n, m, k=map(int, input().split())\r\na, b = map(int, input().split())\r\na-=1\r\nb-=1\r\nan=a//(m*k)\r\nam=(a%(m*k))//k\r\nbn=b//(m*k)\r\nbm=(b%(m*k))//k\r\nres=0\r\nn-=1\r\nif an!=bn:\r\n res=res+min(10+bm,bm*5)+min(10+am,am*5)\r\n if an < bn:\r\n res=res+(min(bn-an, n-bn+an+1))*15\r\n else:\r\n ...
{"inputs": ["4 10 5\n200 6", "3 1 5\n7 2", "100 100 100\n1 1000000", "1000 1000 1000\n1 1000000000", "125 577 124\n7716799 6501425", "624 919 789\n436620192 451753897", "314 156 453\n9938757 14172410", "301 497 118\n11874825 13582548", "491 980 907\n253658701 421137262", "35 296 7\n70033 65728", "186 312 492\n19512588 ...
UNKNOWN
PYTHON3
CODEFORCES
9
4cc989015af2251b0ec9feb79fcb0189
The Union of k-Segments
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. The first line contains two integers *n* and ...
[ "from collections import defaultdict\r\nfrom sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,k=map(int,input().split())\r\nplus=[]\r\nminus=[]\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n plus.append(l)\r\n minus.append(r)\r\n\r\nplus.sort()\r\nminus.sort()\r\n\r\ndef calc(a):\r\n ...
{"inputs": ["3 2\n0 5\n-3 2\n3 8", "3 2\n0 5\n-3 3\n3 8", "1 1\n-1 1", "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78", "10 1\n3 60\n-73 -37\n59 69\n-56 1\n-84 -24\n-14 46\n-65 -23\n-66 -57\n-87 -80\n-21 20", "10 10\n-92 87\n-100 -67\n-88 80\n-82 -59\n-72 81\n-50 30\n30 77\n65 92\n-76...
UNKNOWN
PYTHON3
CODEFORCES
5
4d20c7698eadee9d13c983381c5be7d6
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time p...
[ "n,x=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nimport math as m\r\nprint(m.ceil(abs(sum(l))/x))", "s = [int(i) for i in input().split()]\r\nd = [int(i) for i in input().split()]\r\na = abs(sum(d))\r\nanswer = int(a/s[1])\r\nif a%s[1] > 0:\r\n answer+=1\r\nprint(answer)", "n,x = map(int,...
{"inputs": ["3 2\n-1 1 2", "2 3\n-2 -2", "4 4\n1 2 3 4", "2 2\n-1 -1", "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15", "1 4\n-3", "10 7\n6 4 6 6 -3 4 -1 2 3 3", "2 1\n1 -1", "1 1\n0", "8 13\n-11 -1 -11 12 -2 -2 -10 -11", "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7...
UNKNOWN
PYTHON3
CODEFORCES
229
4d2e7d38f23a5531f3d391346ad788ae
Journey
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially I...
[ "import sys\r\ninput = sys.stdin.readline\r\nn,m,Mx = map(int,input().split())\r\ng = [[] for _ in range(n)]\r\nfor _ in range(m):\r\n u,v,w = map(int,input().split())\r\n g[u-1].append((v-1,w))\r\nprev = [[-1] * (m + 1) for _ in range(n)]\r\ndp0 = [10 ** 18] * n\r\ndp0[0] = 0\r\nans = []\r\nfor c in range(m)...
{"inputs": ["4 3 13\n1 2 5\n2 3 7\n2 4 8", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4", "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9", "4 4 3\n1 2...
UNKNOWN
PYTHON3
CODEFORCES
7
4d315db31337800f8068a03044a6854a
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<...
[ "n, c = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\n\r\ncurr = 0\r\nfor i in range(len(lst)):\r\n if i == 0:\r\n curr += 1\r\n elif abs(lst[i-1] - lst[i]) > c:\r\n curr = 1\r\n else:\r\n curr += 1\r\n\r\nprint(curr)", "n,c=map(int,input().split())\r\ns=1\r\n...
{"inputs": ["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10", "1 1\n1000000000", "5 5\n1 7 12 13 14", "2 1000000000\n1 1000000000", "3 5\n1 10 20", "3 10\n1 2 3", "2 1\n1 100", "3 1\n1 2 10", "2 1\n1 2"], "outputs": ["3", "2", "1", "4", "2", "1", "3", "1", "1", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
455
4d461faa69703d521ca3e9d5400fb27e
Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so...
[ "import math\r\nimport sys\r\nimport collections\r\n\r\n\r\ndef In():\r\n return map(int, sys.stdin.readline().split())\r\n\r\n\r\ndef omnompark():\r\n n = int(input())\r\n l = list(In())\r\n ans = 0\r\n for i in range(len(l) - 1, -1, -1):\r\n if i % 2: # that means the second one\r\n ...
{"inputs": ["2\n1 2 3 4 5 6", "2\n1 2 3 3 2 2", "1\n39 52", "2\n59 96 34 48 8 72", "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89", "5\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82 91 20 64 52 70 6 88 53 47 30 47 34 14 11 22 42 15 28 54 37 48 29 3 14 13 18 77 90 58 54 38 94 49 45 66 13 74 11 14 64 72 95 54 73 79 41 35", ...
UNKNOWN
PYTHON3
CODEFORCES
48
4d4743cbbd6fab36d93393b725364698
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ...
[ "n=int(input())\r\nmatrix=[]\r\nrowsum=0\r\ncolsum=0\r\nk=0\r\nr=[]\r\nc=[]\r\nfor i in range(n):\r\n matrix.append(list(map(int,input().split())))\r\nfor i in range(n):\r\n rowsum=0\r\n colsum=0\r\n for j in range(n):\r\n rowsum+=matrix[i][j]\r\n colsum+=matrix[j][i]\r\n\r\n r.append(r...
{"inputs": ["1\n1", "2\n1 2\n3 4", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "2\n1 1\n1 1", "3\n1 2 3\n4 5 6\n7 8 9", "3\n1 2 3\n3 1 2\n2 3 1", "4\n1 2 3 4\n8 7 6 5\n9 10 11 12\n16 15 14 13", "1\n53", "5\n1 98 22 9 39\n10 9 44 49 66\n79 17 23 8 47\n59 69 72 47 14\n94 91 98 19 54", "1\n31", "1\n92", "5\n61 45 70 19 48\n5...
UNKNOWN
PYTHON3
CODEFORCES
139
4d5a50f021c4770a7b23556a5ad893bf
String
You are given a string *s*. Each pair of numbers *l* and *r* that fulfill the condition 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|, correspond to a substring of the string *s*, starting in the position *l* and ending in the position *r* (inclusive). Let's define the function of two strings *F*(*x*,<=*y*) like this. We'll find a list...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef suffix_array(s):\r\n l = len(s)\r\n x = [[] for _ in range(222)]\r\n for i in range(l):\r\n x[s[i]].append(i)\r\n y = []\r\n z = [0]\r\n for x0 in x:\r\n for i in x0:\r\n y.appen...
{"inputs": ["aaaa", "abcdef", "abacabadabacaba", "tkth", "eqkrqe", "cwuiax", "hhhhqhqh", "gmxfmcgp", "eleellleeee", "usussubuubbbbs", "lhmpaugvnqzrfxke", "xkkkkkkkkkkkkkkkkxkkkk", "pprppppriiriiiirprppprriir", "jsoxkutcvyshsinfmtrpujedcbmyqlojzco", "emcegmekgnlefkeguqkfffnduqhfhhhndlfhlfdqdncefnn", "ffffdjfddffdjdfffdd...
UNKNOWN
PYTHON3
CODEFORCES
1
4d5a544372c1f78904b64c235df052b3
Maximum Submatrix 2
You are given a matrix consisting of digits zero and one, its size is *n*<=×<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations? Let's assume that the rows of matrix *a* are numbered from...
[ "n, m = map(int, input().split())\r\nc = [input() for _ in range(n)]\r\ncnt = [0] * (m + 1)\r\nh = [0] * n\r\nres = 0\r\n\r\nfor j in range(m):\r\n for i in range(n):\r\n if c[i][j] == '1':\r\n h[i] += 1\r\n else:\r\n h[i] = 0\r\n cnt = [0] * (m + 1)\r\n for i in range(n...
{"inputs": ["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101", "11 16\n0111110101100011\n1000101100010000\n0010110110010101\n0110110010110010\n0011101101110000\n1001100011010111\n0010011111111000\n0100100100111110\n1001000000100111\n0110000011001000\n1011111011010000", "19 12\n110001100110\n100100000000\n101011001111\...
UNKNOWN
PYTHON3
CODEFORCES
2
4d7ccba00f2546ab87348b15d1ccaedd
Palindrome Transformation
Nam is playing with a string on his computer. The string consists of *n* lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that...
[ "import sys\r\ninput = sys.stdin.readline\r\n \r\n# from math import gcd, isqrt, ceil\r\n# from collections import deque\r\n# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound\r\n \r\nt = 1\r\n# t = int(input())\r\nfor _ in range(t):\r\n n, p = map(int, input().split())\r\n p -...
{"inputs": ["8 3\naeabcaez", "8 3\nabcddcbb", "4 4\nrkoa", "39 30\nyehuqwaffoiyxhkmdipxroolhahbhzprioobxfy", "40 23\nvwjzsgpdsopsrpsyccavfkyyahdgkmdxrquhcplw", "10 5\nabcdeedcba", "5 5\npjfjb", "57 9\nibkypcbtpdlhhpmghwrmuwaqoqxxexxqoqawumrwhgmphhldixezvfpqh", "10 6\nabcdefdcba", "167 152\nvqgjxbuxevpqbpnuyxktgpwdgyebn...
UNKNOWN
PYTHON3
CODEFORCES
2
4d80ebfc6443ce589574ba07fc4ccc26
Lucky Permutation Triple
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=...
[ "\r\nn=int(input())\r\nif n%2:\r\n a=[i for i in range(n)]\r\n b=[i for i in range(n)]\r\n c=[(a[i]+b[i])%n for i in range(n)]\r\n print(*a)\r\n print(*b)\r\n print(*c)\r\nelse:\r\n print(-1)", "n=int(input());\r\nif n%2:\r\n print(*[int(i) for i in range(0,n)])\r\n print(*[int(j) for j...
{"inputs": ["5", "2", "8", "9", "2", "77", "6", "87", "72", "1", "23", "52", "32", "25", "54", "39", "20", "53", "34", "23", "37123", "41904", "46684", "67817", "72598", "85891", "74320", "11805", "16586", "5014", "73268", "61697", "99182", "79771", "68199", "5684", "10465", "31598", "36379", "16968", "93061", "73650",...
UNKNOWN
PYTHON3
CODEFORCES
112
4d8d291a20665d34f57ee85c1c0b09e5
Nuts
You have *a* nuts and lots of boxes. The boxes have a wonderful feature: if you put *x* (*x*<=≥<=0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into *x*<=+<=1 sections. You are minimalist. Therefore, on the one hand, you are against dividing some box into more than *k* sections. On ...
[ "from sys import stdin\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\ndef read_next_line():\r\n return list(map(int, stdin.readline().strip().split()))\r\n\r\n\r\ndef ceildiv(a, b):\r\n return -(-a // b)\r\n\r\n\r\nk, a, b, v = read_next_line()\r\ns = ceildiv(a, v)\r\nt = k - 1\r\nd = (b // t) * k + b % t + 1\r\npri...
{"inputs": ["3 10 3 3", "3 10 1 3", "100 100 1 1000", "5 347 20 1", "6 978 10 5", "6 856 50 35", "8 399 13 36", "4 787 48 4", "4 714 7 6", "7 915 12 24", "8 995 3 28", "10 267 4 48", "10 697 1 34", "7 897 49 42", "10 849 3 28", "477 492 438 690", "461 790 518 105", "510 996 830 417", "763 193 388 346", "958 380 405 434...
UNKNOWN
PYTHON3
CODEFORCES
66
4d968990515143126bf1c953554bd7af
Bottles
Nick has *n* bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda *a**i* and bottle volume *b**i* (*a**i*<=≤<=*b**i*). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends *x* seconds t...
[ "if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n sa = sum(a)\r\n z = list(zip(a, b))\r\n z.sort(key=lambda a : a[1])\r\n z.reverse()\r\n\r\n sb, m = 0, 0\r\n for i, (a, b) in enumerate(z):\r\n sb +=...
{"inputs": ["4\n3 3 4 3\n4 7 6 5", "2\n1 1\n100 100", "5\n10 30 5 6 24\n10 41 7 8 24", "1\n1\n100", "1\n100\n100", "1\n50\n100", "10\n18 42 5 1 26 8 40 34 8 29\n18 71 21 67 38 13 99 37 47 76", "20\n24 22 4 34 76 13 78 1 81 51 72 11 25 46 22 33 60 42 25 19\n40 81 10 34 84 16 90 38 99 81 100 19 79 65 26 80 62 47 76 47", ...
UNKNOWN
PYTHON3
CODEFORCES
16
4d9ab805a078033afdc5d734124742b1
Bank Hacking
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are *n* banks, numbered from 1 to *n*. There are also *n*<=-<=1 wires connecting the b...
[ "# 答案好像就只有3种情况\r\nimport sys\r\nn = int(sys.stdin.readline())\r\na = list(map(int, sys.stdin.readline().split()))\r\ng = [[] for _ in range(n)]\r\nfor _ in range(n - 1):\r\n u, v = map(int, sys.stdin.readline().split())\r\n g[u - 1].append(v - 1)\r\n g[v - 1].append(u - 1)\r\ndef check(x):\r\n root = No...
{"inputs": ["5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "3\n2 2 2\n3 2\n1 2", "3\n999397 999397 999397\n2 3\n2 1", "5\n1000000000 0 1000000000 0 1000000000\n1 2\n2 3\n3 4\n4 5", "10\n-1000000000 -1000000000 -1000000000 -1000000000 -1...
UNKNOWN
PYTHON3
CODEFORCES
7
4dc3104dd6c4d9f7b9c8e2f32e3e753a
Letters Cyclic Shift
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is ...
[ "s = input()\r\ni = 0\r\nif set(s)=={'a'}:\r\n print('a'*(len(s)-1)+'z')\r\n exit()\r\n\r\nwhile i<len(s) and s[i]=='a':\r\n print('a',end='')\r\n i+=1\r\nwhile i<len(s) and s[i]!='a':\r\n print(chr(ord(s[i])-1),end=\"\")\r\n i+=1\r\nwhile i<len(s):\r\n print(s[i],end=\"\")\r\n i+=1\r\nprint...
{"inputs": ["codeforces", "abacaba", "babbbabaababbaa", "bcbacaabcababaccccaaaabacbbcbbaa", "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda", "a", "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec", "fddfbabadaadaddfbfecad...
UNKNOWN
PYTHON3
CODEFORCES
56
4e08ca09a438f1950115137022731cbe
Pens And Days Of Week
Stepan has *n* pens. Every day he uses them, and on the *i*-th day he uses the pen number *i*. On the (*n*<=+<=1)-th day again he uses the pen number 1, on the (*n*<=+<=2)-th — he uses the pen number 2 and so on. On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the...
[ "import sys\r\n \r\ndef Min(x, y):\r\n if x > y:\r\n return y\r\n else:\r\n return x\r\n \r\ndef Gcd(x, y):\r\n if x == 0:\r\n return y\r\n else:\r\n return Gcd(y % x, x)\r\n \r\ndef Lcm(x, y):\r\n return x * y // Gcd(x, y)\r\n \r\nn = int(input())\r\na = [int(i) for i in ...
{"inputs": ["3\n3 3 3", "5\n5 4 5 4 4", "28\n2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033", "7\n10 10 10 10 10 10 10", "28\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...
UNKNOWN
PYTHON3
CODEFORCES
1
4e1001b37563a9d7ff5a7f598df7bd5e
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills: For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, ...
[ "n = int(input())\r\n\r\na = sorted(list(map(int, input().split(' '))))\r\n\r\nif n == 1:\r\n\tprint(-1)\r\n\texit()\r\n\r\nif n == 2 and (a[1] - a[0]) % 2 == 0 and a[0] != a[1]:\r\n\tprint(3)\r\n\tprint(a[0] * 2 - a[1], (a[0] + a[1]) // 2, 2 * a[1] - a[0])\r\n\texit()\r\n\r\nb = sorted([a[i] - a[i - 1] for i in ra...
{"inputs": ["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4", "4\n1 3 4 5", "2\n3 3", "2\n13 2", "5\n2 2 2 2 2", "6\n11 1 7 9 5 13", "2\n100000000 1", "5\n2 3 1 4 6", "5\n1 2 2 3 4", "3\n1 4 2", "3\n8 8 8", "5\n2 2 2 2 3", "1\n100000000", "20\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45", "40\n100...
UNKNOWN
PYTHON3
CODEFORCES
14
4e13badfe8593ea28f7db56aa201e76c
Median on Segments (General Case Edition)
You are given an integer sequence $a_1, a_2, \dots, a_n$. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. The median of a sequence is the value of an element which is in the middle of the sequence after s...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nfrom typing import List, Union\r\n\r\n\r\nclass FenwickTree:\r\n\r\n '''Build a new FenwickTree. / O(N)'''\r\n def __init__(self, _n_or_a: Union[List[int], int]):\r\n if isinstance(_n_or_a, int):\r\n self._size = _n_or_a\r\n self._tr...
{"inputs": ["5 4\n1 4 5 60 4", "3 1\n1 1 1", "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3", "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", "2 2\n1 1", "3 2\n1 1 2", "2 1\n1 1", "1 1\n2", "2 2\n4 1", "3 3\n5 5 3", "4 3\n3 5 2 3", "5 2...
UNKNOWN
PYTHON3
CODEFORCES
4
4e1984b93f1c4fa1a4de130e3bd4e45c
Bipartite Checking
You are given an undirected graph consisting of *n* vertices. Initially there are no edges in the graph. Also you are given *q* queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of t...
[ "from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v, w):\r\n return (u * n2 + v) * n2 + w\r\n\r\ndef g(u, v):\r\n return u * n2 + v\r\n\r\ndef get_root(s):\r\n while s ^ root[s]:\r\n s = root[s]\r\n return s\...
{"inputs": ["3 5\n2 3\n1 3\n1 2\n1 2\n1 2", "5 10\n1 5\n2 5\n2 4\n1 4\n4 5\n2 4\n2 5\n1 4\n2 3\n1 2", "10 20\n1 10\n5 7\n1 2\n3 5\n3 6\n4 9\n3 4\n6 9\n4 8\n6 9\n7 8\n3 8\n7 10\n2 7\n3 7\n5 9\n6 7\n4 6\n2 10\n8 10", "10 30\n5 6\n5 9\n4 9\n6 7\n7 9\n3 10\n5 6\n5 7\n6 10\n2 4\n2 6\n2 5\n3 7\n1 8\n8 9\n3 4\n3 5\n1 9\n6 7\n...
UNKNOWN
PYTHON3
CODEFORCES
1
4e220ac1005c900d81bf721ad9ab46cb
Devu and his Brother
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother. As Devu is really a naughty kid, he wants the minimum value of his array *a* should be at least as much...
[ "from bisect import bisect_left as lower_bound, bisect_right as upper_bound\r\nn,m = map(int,input().split())\r\nA = [int(x) for x in input().split()]\r\nB = [int(x) for x in input().split()]\r\nA.sort()\r\nB.sort(reverse = True)\r\nans =0\r\nfor i in range(min(n, m)):\r\n if(A[i]>=B[i]):\r\n break\r\n ...
{"inputs": ["2 2\n2 3\n3 5", "3 2\n1 2 3\n3 4", "3 2\n4 5 6\n1 2", "10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100", "1 1\n401114\n998223974", "1 1\n100\n4", "1 1\n100\n183299", "1 1\n999999999\n1000000000", "1 1\n1000000000\n1000000000", "1 1\n1\n2", "1 1\n1\n1", "1 1\n2\n1", "1 1\n1\n2...
UNKNOWN
PYTHON3
CODEFORCES
24