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 |
|---|---|---|---|---|---|---|---|---|---|
08db6a75d49bfd251c8032e15206044e | Soldier and Badges | Colonel has *n* badges. He wants to give one badge to every of his *n* soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the s... | [
"# import sys\r\n# input=sys.stdin.readline\r\nimport math\r\nimport bisect\r\n\r\nn=int(input())\r\nl=[int(i) for i in input().split(\" \")]\r\nl.sort()\r\nd={}\r\nans=0\r\nfor i in l:\r\n if i in d:\r\n while(i in d):\r\n i+=1\r\n ans+=1\r\n d[i]=1\r\n else:\r\n d[... | {"inputs": ["4\n1 3 1 4", "5\n1 2 3 2 5", "5\n1 5 3 2 4", "10\n1 1 2 3 4 5 6 7 8 9", "11\n9 2 10 3 1 5 7 1 4 8 6", "4\n4 3 2 2", "1\n1", "50\n49 37 30 2 18 48 14 48 50 27 1 43 46 5 21 28 44 2 24 17 41 38 25 18 43 28 25 21 28 23 26 27 4 31 50 18 23 11 13 28 44 47 1 26 43 25 22 46 32 45", "50\n37 31 19 46 45 1 9 37 15 19... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
08e9079042b97f8649aeb560cccf9ea4 | Plug-in | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | [
"n = input()\r\nst = []\r\nfor i in range(len(n)):\r\n st.append(n[i])\r\n while len(st) > 1 and st[-1] == st[-2]:\r\n st.pop()\r\n st.pop()\r\nprint(''.join(st))\r\n \r\n",
"# LUOGU_RID: 131046759\nimport sys\r\ninput = lambda:sys.stdin.readline().strip()\r\narc = []\r\nfor i in input():\r... | {"inputs": ["hhoowaaaareyyoouu", "reallazy", "abacabaabacabaa", "xraccabccbry", "a", "b", "il", "gfj", "babbbbbababa", "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa", "aab", "abb", "aba", "ab"], "outputs": ["wre", "rezy", "a", "xy", "a", "b", "il", "gfj", "bababab... | UNKNOWN | PYTHON3 | CODEFORCES | 193 | |
09028546725df22927fed193057b8579 | Interesting Array | We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) meaning that value should be equal to *q**i*.
Your task is to find any inte... | [
"import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\... | {"inputs": ["3 1\n1 3 3", "3 2\n1 3 3\n1 3 2", "3 2\n1 2 536870912\n2 3 536870911", "1 1\n1 1 10", "1 2\n1 1 10\n1 1 5", "1 2\n1 1 1\n1 1 3"], "outputs": ["YES\n3 3 3", "NO", "YES\n536870912 1073741823 536870911", "YES\n10", "NO", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
093473bbf5193af87dcc821da582c09a | Mice problem | Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.
The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i... | [
"# In the name of Allah\r\n\r\ndef main() :\r\n\r\n n = int(input())\r\n x1, y1, x2, y2 = map(int, input().split())\r\n\r\n st = [0]\r\n ed = [1e11]\r\n\r\n if x1 == x2 or y1 == y2 :\r\n print(-1)\r\n exit()\r\n for i in range(n) :\r\n a, b, c, d = map(int, input().split())\r\... | {"inputs": ["4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "4\n8 42 60 54\n9 54 -58 -62\n46 47 52 -76\n15 50 -37 -40\n54 51 78 64", "4\n17501 63318 51967 74514\n1305 84026 79493 -78504\n41159 81000 -44104 -42722\n31063 65435 25578 33487\n18330 79949 83467 -745... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
0934a086c394bd534e3de5e39e4d2d6d | none | Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.
Though Ryouko is forgetful, she is also bo... | [
"n,m = [int(x) for x in input().split()]\r\na = [int(x)-1 for x in input().split()]\r\nassert len(a) == m\r\n\r\ntot = 0\r\nfor i in range(m-1):\r\n tot += abs(a[i+1]-a[i])\r\n\r\narr = [[] for i in range(n)]\r\n\r\nfor i in range(m-1):\r\n if a[i] == a[i+1]: continue\r\n arr[a[i]].append(a[i+1])\r\n ar... | {"inputs": ["4 6\n1 2 3 4 3 2", "10 5\n9 4 3 8 8", "5 10\n2 5 2 2 3 5 3 2 1 3", "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2", "100 100\n28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
09461ae3143b37d74a6e1f5d636239d7 | F1 Champions | Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the cha... | [
"t, q = {}, [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]\r\nfor i in range(int(input())):\r\n for j in range(int(input())):\r\n p = input()\r\n if not p in t: t[p] = [0] * 52\r\n if j < 10: t[p][0] += q[j]\r\n t[p][j + 1] += 1\r\nprint(max(t.items(), key = lambda x: x[1])[0])\r\nfor p in t: t[... | {"inputs": ["3\n3\nHamilton\nVettel\nWebber\n2\nWebber\nVettel\n2\nHamilton\nVettel", "2\n7\nProst\nSurtees\nNakajima\nSchumacher\nButton\nDeLaRosa\nBuemi\n8\nAlonso\nProst\nNinoFarina\nJimClark\nDeLaRosa\nNakajima\nPatrese\nSurtees", "5\n3\nWebber\nTrulli\nJones\n9\nVilleneuve\nBerger\nJimClark\nReneArnoux\nKubica\nJo... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
09721cc3e0498b7c44b09aaff2a73aec | Fibonacci-ish | Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=2<==<=*f**n*<=+<=1<=+<=*f**n* for all *n*<=≥<=0.
You are given some sequence of integers *a*1,<=*a... | [
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nD = {}\r\nfor x in a:\r\n if x in D:\r\n D[x] += 1\r\n else:\r\n D[x] = 1\r\nmaxans = 0\r\ndef check(x, y):\r\n num = 2\r\n D[x] -= 1\r\n D[y] -= 1\r\n while x+y in D and D[x+y] > 0:\r\n D[x+y] -= 1\r\n x, y ... | {"inputs": ["3\n1 2 -1", "5\n28 35 7 14 21", "11\n-9 -1 -10 9 7 -4 0 -8 -3 3 5", "10\n-4 -8 -8 8 -9 0 -7 9 1 0", "2\n2 2", "4\n1 -1 0 -2", "2\n1000000000 1000000000", "3\n1 1 2", "5\n0 0 0 0 0", "6\n1 -1 0 -1 -1 -2", "5\n-7 0 -7 -7 -14", "3\n0 -44 -49", "5\n-1 1 0 0 0", "2\n0 0", "3\n0 0 0", "4\n0 0 0 0", "5\n0 0 0 0 0... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
0997d5cbc678eb115b8bcdbbc2972483 | OR in Matrix | Let's define logical *OR* as an operation on two logical values (i. e. values that belong to the set {0,<=1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical *OR* of three or more logical values in the same manner:
where is equal to 1 if some *a**i*<==... | [
"import sys, collections, bisect, heapq, functools, itertools, math\r\ninput = sys.stdin.readline\r\n\r\nm, n = [int(x) for x in input().split()]\r\n\r\ng = []\r\nfor _ in range(m):\r\n g.append([int(x) for x in input().split()])\r\n\r\ng2 = [[1]*n for _ in range(m)]\r\n\r\nfor i in range(m):\r\n for j in ran... | {"inputs": ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1", "5 5\n1 1 1 1 1\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0", "5 5\n1 1 1 0 1\n1 1 0 0 1\n0 0 1 1 1\n1 1 1 1 0\n1 0 1 1 1", "5 6\n1 0 0 0 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 0 0 0 1 1\n1 0 0 0 1 1", "5 6\n1 1 1 1 0 1\n1 1 1 1 0 1\n1 1 1 0 1 1\n1 1 0 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
09d000220511dfbd7fd7cc548757d59f | Cinema Line | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | [
"n = int(input())\nbills = list(map(int, input().split()))\n\nchange_25 = 0\nchange_50 = 0\n\nfor bill in bills:\n if bill == 25:\n change_25 += 1\n elif bill == 50:\n if change_25 >= 1:\n change_25 -= 1\n change_50 += 1\n else:\n print(\"NO\")\n ... | {"inputs": ["4\n25 25 50 50", "2\n25 100", "4\n50 50 25 25", "3\n25 50 100", "10\n25 25 25 25 25 25 25 25 25 25", "10\n50 50 50 50 50 50 50 50 50 50", "10\n100 100 100 100 100 100 100 100 100 100", "7\n25 25 25 25 50 100 50", "2\n25 25", "3\n50 100 100", "3\n25 50 50", "2\n50 25", "14\n25 25 25 25 25 25 25 50 50 50 100... | UNKNOWN | PYTHON3 | CODEFORCES | 231 | |
09d40e2bc0055c8680e6d11af183944d | Chocolate | Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a se... | [
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nw, h, n = map(int, input().split())\r\nmat = [[0] * (2 * w) for _ in range(2 * h)]\r\n\r\nfor x1, y1, x2, y2 in (map(int, input().split()) for _ in range(n)):\r\n if x... | {"inputs": ["2 2 2\n1 0 1 2\n0 1 1 1", "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "2 4 2\n0 1 2 1\n0 3 2 3", "5 5 3\n2 1 2 5\n0 1 5 1\n4 0 4 1", "10 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4", "9 8 5\n4 3 4 4\n0 4 9 4\n5 4 5 8\n0 3 9 3\n1 4 1 8", "100 100 1\n0 14 100 14"], "outputs": ["1 1 2 ", "1 1 1 1 ", "2 2 4 ", "1 4 8 ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
09f17070acfce7ef738cea733b9580cc | Guard Duty (easy) | The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign *R* Rebel spaceships to guard *B* bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching).... | [
"def ccw(A, B, C):\n return (C[1] - A[1]) * (B[0] - A[0]) > (B[1] - A[1]) * (C[0] - A[0])\n\n\ndef intersect(A, B, C, D):\n return ccw(A, C, D) != ccw(B, C, D) and ccw(A, B, C) != ccw(A, B, D)\n\n\nR, B = map(int, input().split())\n\nrs = []\nbs = []\nfor r in range(R):\n rs.append(list(map(int, input().sp... | {"inputs": ["3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2", "2 1\n1 0\n2 2\n3 1", "1 1\n3686 4362\n-7485 5112", "1 2\n1152 -7324\n-5137 -35\n-6045 -5271", "1 3\n-8824 -9306\n-5646 -9767\n8123 9355\n-6203 -1643", "1 5\n-8775 6730\n-3806 -6906\n-9256 -8240\n-1320 6849\n8155 746\n8284 -7317", "1 8\n8741 3638\n381 -9191\n7534 8792\n... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
0a0588ca9a3a9fe73cf3652e5a256608 | Counting Sticks | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add... | [
"n = input()\r\nlth = len(n)\r\na = n.find('+')\r\nb = n.find('=') - a - 1\r\nc = len(n) - n.find('=') - 1\r\nif a + b == c:\r\n print(n)\r\nelif a + b == c - 2:\r\n print('|',n[:lth-1],sep=\"\")\r\nelif a + b == c + 2:\r\n if a >= 2:\r\n print(n[1:],'|',sep=\"\")\r\n else:\r\n print(n[:a+... | {"inputs": ["||+|=|||||", "|||||+||=||", "|+|=||||||", "||||+||=||||||", "||||||||||||+|||||||||||=||||||||||||||||||||||", "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||", "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||", "||||||... | UNKNOWN | PYTHON3 | CODEFORCES | 66 | |
0a48bba8bf70b092497deaa39818e3b3 | Replacement | Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace thi... | [
"import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\nfrom functools import lru_cache\r\nfrom heapq import heapify,heappop,heappush\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\n#def input(): return sys.stdin.readli... | {"inputs": ["10 3\n.b..bz....\n1 h\n3 c\n9 f", "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a", "3 3\n...\n1 .\n2 a\n3 b", "5 1\n.....\n5 z", "1 5\n.\n1 .\n1 w\n1 w\n1 .\n1 .", "2 7\nab\n1 w\n2 w\n1 c\n2 .\n2 .\n1 .\n2 b"], "outputs": ["4\n3\n1", "1\n3\n1\n1", "2\n0\n0", "3", "0\n0\n0\n0\n0", "0\n0\n0\n0\n0\n1\n0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
0a6472dce2494a2e91dfd077f9e702f5 | Ksusha and Square | Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles.
Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integer points (points with integer coordinates) inside or on the border of the ... | [
"import math\r\nclass Data:\r\n def __init__(self, x, y):\r\n self.x = x\r\n self.y = y\r\nn = int(input())\r\nd = [Data(0, 0) for _ in range(100005)]\r\nU = [0.0] * 2000005\r\nD = [2000005.0] * 2000005\r\nresult = 0.0\r\nmaxx = maxy = 0x7fffffff\r\nfor i in range(n):\r\n x, y = map(int, input()... | {"inputs": ["3\n0 0\n5 5\n5 0", "4\n-1 3\n4 5\n6 2\n3 -5", "3\n17 136\n859 937\n16 641", "6\n-29 6\n-28 27\n-2 18\n13 9\n20 -18\n19 -27", "7\n-29 5\n-20 13\n-4 22\n8 20\n21 9\n16 -29\n-23 -30", "8\n-18 -20\n16 -28\n29 -29\n29 25\n15 27\n-19 30\n-28 18\n-30 -16", "6\n13 -22\n26 -11\n30 12\n22 19\n-10 24\n-29 6", "6\n13 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0a77299d877452686d821dfc2e1a59db | Kingdom and its Cities | Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.
The kingdom curren... | [
"from io import BytesIO, IOBase\r\nimport math\r\n\r\nimport random\r\nimport sys\r\nimport os\r\n\r\nimport bisect\r\nimport typing\r\nfrom collections import Counter, defaultdict, deque\r\nfrom copy import deepcopy\r\nfrom functools import cmp_to_key, lru_cache, reduce\r\nfrom heapq import heapify, heappop, heapp... | {"inputs": ["4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7", "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 5 7\n3 2 4 6\n2 1 7\n2 3 4\n3 1 6 7", "30\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n4 8\n4 9\n6 10\n6 11\n11 30\n11 23\n30 24\n30 25\n25 26\n25 27\n27 29\n27 28\n23 20\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0a8a38ebf3e78262dba34af1e7e92873 | LCS Again | You are given a string *S* of length *n* with each character being one of the first *m* lowercase English letters.
Calculate how many different strings *T* of length *n* composed from the first *m* lowercase English letters exist such that the length of LCS (longest common subsequence) between *S* and *T* is *n*<=-<=... | [
"n, m = map(int, input().split())\r\ns = input()\r\np = c = 0\r\nfor i in range(1, n):\r\n if s[i] == s[i - 1]:\r\n c += n * (m - 1)\r\n p = i\r\n elif s[i] != s[i - 2]:\r\n p = i - 1\r\n c += i - p\r\nans = n * n * (m - 1) - c\r\nprint(ans)\r\n",
"line = list(map(int,input().split()... | {"inputs": ["3 3\naaa", "3 3\naab", "1 2\na", "10 9\nabacadefgh", "15 3\nabababababababa", "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf", "1 26\nz"], "outputs": ["6", "11", "1", "789", "345", "237400", "25"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
0a939d1c828a3ea1733a4fa8264770f0 | Sereja and Bottles | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use... | [
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n p=[]\r\n a,b=map(int,input().split())\r\n p.append(a)\r\n p.append(b)\r\n l.append(p)\r\nans=0\r\nfor i in range(n):\r\n for j in range(n):\r\n if(i!=j and l[i][0]==l[j][1]):\r\n ans=ans+1\r\n break\r\nprint(n-ans) ",
... | {"inputs": ["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1", "3\n2 828\n4 392\n4 903", "4\n2 3\n1 772\n3 870\n3 668", "5\n1 4\n6 6\n4 3\n3 4\n4 758", "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\... | UNKNOWN | PYTHON3 | CODEFORCES | 152 | |
0a95eeba755158f174d4cf94db15d536 | Playing on Graph | Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.
Vova has a non-directed graph consisting of *n* vertices and *m* edges without loops and multiple edges. Let's define the operation of contraction two vertices *a* and *b* that are not connected by an edge. ... | [
"n, m = map(int, input().split())\ng = [[] for _ in range(n)]\nfor i in range(m):\n p, q = map(int, input().split())\n g[p - 1].append(q - 1)\n g[q - 1].append(p - 1)\n\ncomp = [-1] * n\ndef shortest(root):\n dist = [-1] * n\n q = [0] * n\n left, right = 0, 1\n q[left] = root\n dist[root] = ... | {"inputs": ["5 4\n1 2\n2 3\n3 4\n3 5", "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4", "4 2\n1 3\n2 4", "1 0", "1000 0", "1000 4\n100 200\n200 300\n300 400\n400 100", "14 30\n12 10\n1 7\n12 13\n7 3\n14 10\n3 12\n11 1\n2 12\n2 5\n14 3\n14 1\n14 4\n6 7\n12 6\n9 5\n7 10\n8 5\n6 14\n13 7\n4 12\n9 10\n1 9\n14 5\n1 8\n2 13\n5 11\n8 6\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
0aafc953e4cb8c334f377fa3d8dade25 | Mike and Cellphone | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and ... | [
"n = input()\r\ns = set(map(int,input()))\r\nif all(map(lambda x: x&s!=set(),({1,4,7,0},{3,6,9,0},{7,0,9},{1,2,3}))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"input()\r\na = list(map(int, str(input())))\r\n\r\nd = {\r\n 1: (0, 0),\r\n 2: (1, 0),\r\n 3: (2, 0),\r\n 4: (0, 1),\r\n 5: (1... | {"inputs": ["3\n586", "2\n09", "9\n123456789", "3\n911", "3\n089", "3\n159", "9\n000000000", "4\n0874", "6\n235689", "2\n10", "3\n358", "6\n123456", "1\n0", "4\n0068", "6\n021149", "5\n04918", "2\n05", "4\n0585", "4\n0755", "2\n08", "4\n0840", "9\n103481226", "4\n1468", "7\n1588216", "9\n188758557", "1\n2", "2\n22", "8... | UNKNOWN | PYTHON3 | CODEFORCES | 74 | |
0ac572944c18ff62cd4cdee0e5b6d977 | Prefix Sums | Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*).
You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input... | [
"import sys\r\nfrom collections import deque\r\ninput = sys.stdin.readline\r\ndef fgh():\r\n return [int(xx) for xx in input().split()]\r\ndef fg():\r\n return int(input())\r\nn, ok = fgh()\r\na = fgh()\r\nif max(a) >= ok:\r\n print(0)\r\n quit()\r\nif n == 2:\r\n print((ok - a[1] + a[0] - 1) // a[0]... | {"inputs": ["2 2\n1 1", "3 6\n1 1 1", "3 1\n1 0 1", "3 1000000000000000000\n5 4 5", "4 1000000000000000000\n0 4 4 5", "5 1000000000000000000\n5 7 4 2 5", "3 999999999000999944\n7 2 6", "4 999999999000531216\n8 7 4 6", "5 152742477016321721\n0 0 2 6 2", "6 1000000000000000000\n1 1 0 1 0 1", "7 1000000000000000000\n77 94... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
0accdcf59f157331ff148bce81f9c08f | The Child and Binary Tree | Our child likes computer science very much, especially he likes binary trees.
Consider the sequence of *n* distinct positive integers: *c*1,<=*c*2,<=...,<=*c**n*. The child calls a vertex-weighted rooted binary tree good if and only if for every vertex *v*, the weight of *v* is in the set {*c*1,<=*c*2,<=...,<=*c**n*}.... | [
"standard_input, packages, dfs, hashing = 1, 1, 0, 0\r\n\r\nif standard_input:\r\n import sys\r\n input = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n \r\n def I():\r\n return input()\r\n\r\n def II():\r\n return int(input())\r\n\r\n def MII():\r\n return map(int, input... | {"inputs": ["2 3\n1 2", "3 10\n9 4 3", "5 10\n13 10 6 4 15", "1 1\n1", "10 100\n9 95 37 56 39 86 59 5 68 82", "10 100\n7 9 8 6 4 10 1 3 5 2", "50 1000\n10 93 11 34 85 17 61 87 58 38 56 83 55 52 70 18 47 82 36 67 53 98 81 41 23 39 13 99 64 16 91 48 22 12 92 78 86 1 65 46 21 57 7 72 31 71 90 68 35 45", "100 1000\n302 622... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0adb4a5d61e65a02984cf51e149b2854 | Hongcow Builds A Nation | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | [
"def dfs(vertice, soma, temCapital,aux, used, capitais, am):\r\n soma += len(aux[vertice])\r\n am += 1\r\n if vertice in capitais:\r\n temCapital = True\r\n used[vertice] = True\r\n for i in aux[vertice]:\r\n if not used[i]:\r\n tmpC, am, soma = dfs(i, soma, temCapital, aux, used, ca... | {"inputs": ["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3", "10 3 2\n1 10\n1 2\n1 3\n4 5", "1 0 1\n1", "1000 0 1\n72", "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n... | UNKNOWN | PYTHON3 | CODEFORCES | 70 | |
0ae8a5a7b4f9d9d1a43757a5dda02216 | Three States | The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that on... | [
"# lista doble enlazada o(1) operaciones en los bordes es mejor que si se implementa en el propio lenguaje\nfrom collections import deque\nn, m = input().split()\nn = int(n)\nm = int(m)\n\n\ndef idx(i, j):\n return i*m + j\n\n\nmax = n*m*2\ngraph = \"\"\nvirtDist = [[], [], []]\nvirtVertex = [deque(), deque(), d... | {"inputs": ["4 5\n11..2\n#..22\n#.323\n.#333", "1 5\n1#2#3", "3 4\n.2..\n...3\n.1#.", "10 10\n##.#..#.#2\n...###....\n#..#....##\n.....#....\n.#........\n.....#####\n...#..#...\n....###...\n###.##...#\n.#...1#.3.", "4 3\n..#\n.3.\n..2\n..1", "5 5\n.2...\n#2.3.\n.#..#\n.#.11\n#..#.", "1 3\n231", "3 1\n3\n1\n2", "1 4\n12... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
0af3b1bc78e71d52499dca72feb7585a | Matrix | You have a string of decimal digits *s*. Let's define *b**ij*<==<=*s**i*·*s**j*. Find in matrix *b* the number of such rectangles that the sum *b**ij* for all cells (*i*,<=*j*) that are the elements of the rectangle equals *a* in each rectangle.
A rectangle in a matrix is a group of four integers (*x*,<=*y*,<=*z*,<=*t... | [
"a = int(input())\r\ns = input()\r\n\r\nsm ={}\r\nfor i in range(len(s)):\r\n for j in range(i,len(s)):\r\n if j== i:\r\n t = int(s[j])\r\n else:\r\n t += int(s[j])\r\n if t in sm:\r\n sm[t] += 1\r\n else:\r\n sm[t] = 1\r\nif a==0:\r\n if... | {"inputs": ["10\n12345", "16\n439873893693495623498263984765", "0\n1230", "8398\n67950927224842887617892831243606761170908507858527", "2\n11", "4\n111", "0\n0", "1\n0", "0\n1", "0\n0000", "1\n00", "1\n000", "1\n11111", "700\n10010101101100110011110110010100010000000001100111100011111000101101110001011000000000010010000... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
0afab2f715e57b35f1e1aec2cc5c45c4 | Mike and Feet | Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high.
A group of bears is a non-empty contiguous segment of the line. The size of... | [
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nl = [-1 for _ in range(n)]\r\nr = [n for _ in range(n)]\r\nanswer = [0 for _ in range(n+1)] \r\ns = []\r\nfor i in range(n):\r\n while s and a[s[-1]] >= a[i]:\r\n s.pop()\r\n if s:\r\n l[i] = s[-1]\r\n s.append(i)\r\nwhile s:\r\n s.pop()\r\... | {"inputs": ["10\n1 2 3 4 5 4 3 2 1 6", "3\n524125987 923264237 374288891", "5\n585325539 365329221 412106895 291882089 564718673", "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 7178028... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
0afd39c0566d0ee67cbd847e8bb6ed43 | Chess | Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board b... | [
"import sys\ninput = sys.stdin.readline\n\nimport math\nfrom collections import defaultdict,deque\nml=lambda:map(int,input().split())\nll=lambda:list(map(int,input().split()))\nii=lambda:int(input())\nip=lambda:list(input())\nips=lambda:input().split()\n\n\"\"\"========main code===============\"\"\"\n\nr=ip()\nk=ip... | {"inputs": ["a1\nb2", "a8\nd4", "a8\nf1", "f8\nh3", "g8\nb7", "h1\ng5", "c6\nb5", "c1\nd2", "g3\nh4", "e3\ng5", "f8\na3", "a2\nh8", "a3\nc5", "g1\ne6", "e1\na7", "b5\nc1", "b2\ne1", "h8\ng2", "a3\nd6", "g6\nb7", "c8\ne6", "e6\nf2", "b6\nd8", "a4\nd1", "b5\nh8", "h6\na1", "c3\na8", "g5\nd2", "b6\ng7", "h6\na8", "a8\nb7"... | UNKNOWN | PYTHON3 | CODEFORCES | 63 | |
0b127ebd2dca7cee059e0809b100c238 | Forgotten Episode | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | [
"n = int(input())\r\n\r\ns = n * (n + 1) // 2\r\nfor x in input().split():\r\n s -= int(x)\r\n\r\nprint(s)",
"n = int(input())\nL = set(map(int, input().split())) # Use a set for O(1) membership check\nmissing = set(range(1, n+1)) - L # Calculate the missing elements\nprint(min(missing)) # P... | {"inputs": ["10\n3 8 10 1 7 9 6 5 2", "5\n4 3 2 1", "2\n1", "2\n2", "3\n1 2", "3\n1 3", "3\n2 3", "3\n2 1", "3\n3 1", "3\n3 2", "5\n2 3 4 5", "5\n5 4 3 2", "5\n5 2 4 3", "5\n1 2 3 4", "5\n2 1 3 4", "5\n1 5 3 4", "5\n1 4 5 2", "5\n2 1 5 3", "5\n2 3 4 5"], "outputs": ["4", "5", "2", "1", "3", "2", "1", "3", "2", "1", "1"... | UNKNOWN | PYTHON3 | CODEFORCES | 226 | |
0b317f93ef6e52490255f4b48d43b09a | Tickets | As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for t... | [
"import sys\r\nfrom array import array # noqa: F401\r\nfrom math import log, e\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, m, k = map(int, input().split())\r\n\r\nif m <= k:\r\n print(1)\r\n exit()\r\nif n + k < m:\r\n print(0)\r\n exit()\r\n\r\nprob1... | {"inputs": ["5 3 1", "0 5 5", "0 1 0", "95105 76851 10", "60503 53620 1", "25902 30390 2", "53475 7159 4", "18874 21756 8", "84273 98526 10", "49672 75296 0", "15071 89892 4", "80471 66661 6", "39377 94889 10", "15566 15472 0", "91756 73882 2", "67945 32292 4", "44133 52876 8", "100000 100000 10", "100000 50000 10", "1... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
0b43e528e6abeac53cf533a31aa42623 | Old Peykan | There are *n* cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as *c*1,<=*c*2,<=...,<=*c**n*. The Old Peykan wants to travel from city *c*1 to *c**n* using roads. There are (*n*<=-<=1) one way roads, the *i*-th road goes from city *c**i*... | [
"a,b=map(int,input().split())\r\nd=list(map(int,input().split()))\r\np=list(map(int,input().split()))\r\nt=0;d1=0;i=0\r\nwhile i<a:\r\n if t+sum(p[i::])-sum(d[i::])<0:\r\n j=i;pr=p[i]\r\n while j<a and pr>=p[j]:j+=1\r\n k=(-t-sum(p[i:j])-1+sum(d[i:j])+pr)//pr\r\n d1+=b*k\r\n t=... | {"inputs": ["4 6\n1 2 5 2\n2 3 3 4", "2 3\n5 6\n5 5", "24 3\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3", "43 5\n6 7 15 12 15 7 22 33 38 15 7 23 31 21 26 41 25 14 26 33 5 28 22 6 35 17 19 32 41 27 20 25 5 32 37 19 40 9 25 22 10 24 9\n3 5 3 6 5 4 5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
0b492da43be959fece6400df5847d362 | Greg and Array | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | [
"n, m, k = map(int, input().split())\n\narray = list(map(int, input().split()))\n\nL = []\nR = []\nD = []\n\nfor i in range(m):\n\n l, r, d = map(int, input().split())\n L.append(l)\n R.append(r)\n D.append(d)\n\n L[i] -= 1\n\nU = [0 for _ in range(m+1)]\n\n\nfor i in range(k):\n x, y = map(int, i... | {"inputs": ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3", "1 1 1\n0\n1 1 0\n1 1"], "outputs": ["9 18 17", "2", "5 18 31 20", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 126 | |
0b99387d2eff332b59651e06fd553dc0 | none | Jeff loves regular bracket sequences.
Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of *nm* brackets. Let's number all brackets of this sequence from 0 to *nm* - 1 from left to right. Jeff knows that he is going to spend *a**i* *mod* *n* liters of ink on the *i*-th... | [
"MAX = 333333\r\nn, m = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nmat = [[MAX] * (n * 100 + 1) for _ in range(n * 100 + 1)]\r\nfor i in range(n):\r\n mat[0][0] = 0\r\nsmall_mat = min(4, m) * n\r\nfor i in range(small_mat):\r\n for j in range... | {"inputs": ["2 6\n1 2\n2 1", "1 10000000\n2\n3", "3 184\n3 2 8\n3 9 2", "4 26\n10 2 5 9\n5 4 2 5", "3 76\n4 7 9\n10 1 1", "3 98\n6 1 9\n10 2 4", "5 114\n7 5 8 10 10\n2 7 9 4 5", "1 14\n7\n6", "5 142\n8 7 6 2 2\n8 2 6 1 7", "1 184\n8\n8", "2 1900670\n10 3\n9 6", "6 17656\n2 7 4 7 7 3\n3 5 3 6 9 10", "16 3273408\n3 2 8 8... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0bd6a065baad38a3fd4c209f4a95f13b | LCIS | This problem differs from one which was on the online contest.
The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=<<=*a**i*<=+<=1 for *i*<=<<=*n*.
The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of inde... | [
"n1=int(input())\r\narr1=list(map(int,input().split()))\r\nn2=int(input())\r\narr2=list(map(int,input().split()))\r\n\r\nif(n1>n2):\r\n temp=n1\r\n n1=n2\r\n n2=temp\r\n temp1=arr1.copy()\r\n arr1=arr2.copy()\r\n arr2=temp1\r\n\r\ntable=[]\r\ncount=[0]*n2\r\ntable1=[]\r\nfor i in range(n2):\r\n ... | {"inputs": ["7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "5\n1 2 0 2 1\n3\n1 0 1", "2\n6 10\n3\n6 3 3", "1\n7\n2\n7 9", "3\n37 49 24\n3\n33 5 70", "10\n7 10 1 2 1 7 1 5 9 9\n9\n6 2 5 6 7 7 5 5 2", "9\n7 0 1 2 6 0 10 3 5\n4\n8 4 0 3", "9\n7 4 4 5 0 6 5 4 10\n4\n5 2 10 9", "8\n7 8 6 6 8 10 3 3\n5\n7 4 10 8 7", "7\n4 2 4 3 10 3 6\n9\n... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
0bdec0206f2e8377cd892fe5698579c4 | Sinking Ship | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | [
"from functools import cmp_to_key\r\n\r\nclass Info:\r\n def __init__(self, _id: int, _name: str, _status: str):\r\n self.id = _id\r\n self.name = _name\r\n self.status = _status\r\n\r\n def __str__(self):\r\n return f'id: {self.id}, name: {self.name}, status: {self.status}'\r\n\r\... | {"inputs": ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "1\nA captain", "1\nAbcdefjhij captain", "5\nA captain\nB man\nD woman\nC child\nE rat", "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat", "5\nJoyxnkypf captain\nDxssgr woman\nK... | UNKNOWN | PYTHON3 | CODEFORCES | 380 | |
0c154754b5d73543126f0c6904d0f27a | HQ9+ | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | [
"s=input()\r\nl=['H','Q','9']\r\nflag=0\r\nfor i in l:\r\n if i in s:\r\n flag=1\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"a=input()\r\nc=[]\r\nfor i in a:\r\n if i==\"H\":\r\n c.append(\"yes\")\r\n \r\n elif i==\"Q\":\r\n c.append(\"yes\")\r\n ... | {"inputs": ["Hi!", "Codeforces", "a+b=c", "hq-lowercase", "Q", "9", "H", "+", "~", "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "@F%K2=%RyL/", "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "6G_\"Fq#<AWyHG=R... | UNKNOWN | PYTHON3 | CODEFORCES | 281 | |
0c30ee035d1be2789b81861987cb9945 | Okabe and El Psy Kongroo | Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (*x*,<=*y*) such that *x* and *y* are non-negative. Okabe starts at the origin (point (0,<=0)), and n... | [
"from functools import lru_cache\r\n\r\nmod = 10**9+7\r\nmaxc = 16\r\n\r\ndef solve(n, k, abc):\r\n v = [0]*maxc\r\n v[0] = 1\r\n for a,b,c in abc:\r\n b = min(b,k)\r\n d = b-a\r\n p2 = 0\r\n while d:\r\n d,r = divmod(d,2)\r\n if r:\r\n v = v... | {"inputs": ["1 3\n0 3 3", "2 6\n0 3 0\n3 10 2", "2 3\n0 2 13\n2 3 11", "2 9\n0 8 0\n8 10 10", "1 1\n0 3 9", "3 8\n0 7 3\n7 8 5\n8 9 13", "2 10\n0 9 6\n9 10 5", "2 6\n0 3 3\n3 8 13", "1 5\n0 6 15", "2 6\n0 5 8\n5 8 4", "2 10\n0 9 13\n9 10 1", "3 100\n0 94 4\n94 99 5\n99 100 2", "4 100\n0 51 3\n51 98 2\n98 99 1\n99 100 1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
0c34bbbc2306102aab4c7b97a203e0e5 | Disposition | Vasya bought the collected works of a well-known Berland poet Petya in *n* volumes. The volumes are numbered from 1 to *n*. He thinks that it does not do to arrange the book simply according to their order. Vasya wants to minimize the number of the disposition’s divisors — the positive integers *i* such that for at lea... | [
"n=int(input())\r\nl=[]\r\ns=0\r\nif n%2:\r\n l=[1]\r\n s=1\r\nwhile s<n:\r\n l.append(s+2)\r\n l.append(s+1)\r\n s+=2\r\nprint(*l)",
"a = int(input())\nfor x in range(2, a+1):\n print(x, end=\" \")\nprint(1)\n \t\t \t\t \t \t \t\t \t \t\t\t\t \t \t\t",
"import sys\r\nfrom array import arra... | {"inputs": ["2", "3", "4", "5", "6", "1", "7", "8", "9", "10", "96", "97", "98", "99", "100", "9996", "9997", "9998", "9999", "10000", "99996", "99997", "99998", "99999", "100000", "9149", "72877", "52956", "33035", "13114", "93193", "73273", "37000", "17079", "84653", "27251", "53496", "96093", "22338", "64935"], "out... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
0c45b94028303ef4fffe2d2c090237ad | Minimize the error | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | [
"n, k1, k2 = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = [0]*n\r\nfor i in range(n):\r\n c[i] = abs(a[i] - b[i])\r\nk = k1 + k2\r\nwhile k != 0:\r\n max_value = c[0]\r\n max_index = 0\r\n for i, v in enumerate(c):\r\n if v > max_v... | {"inputs": ["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4", "2 0 1\n1 2\n2 2", "2 1 1\n0 0\n1 1", "5 5 5\n0 0 0 0 0\n0 0 0 0 0", "3 4 5\n1 2 3\n3 2 1", "3 1000 0\n1 2 3\n-1000 -1000 -1000", "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3", "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 2... | UNKNOWN | PYTHON3 | CODEFORCES | 87 | |
0c4fbb69ea6a8fda6a0507a8c111bb9a | Unary | Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following alg... | [
"a = input()\r\nmassiv=[]\r\nmassiv+=a\r\nans = 0\r\nfor i in range(len(massiv)):\r\n if massiv[i] == \">\":\r\n massiv[i] = \"1000\"\r\n elif massiv[i] == \"<\":\r\n massiv[i] = \"1001\"\r\n elif massiv[i] == \"+\":\r\n massiv[i] = \"1010\"\r\n elif massiv[i] == \"-\":\r\n m... | {"inputs": [",.", "++++[>,.<-]", "[-],<],<<,<[,>,+>[[<>.,[>-[-[<><>><<<<]>,.-].>-[[>+,>,[,-,.-,-[[]>..<>,<[+,-<]-++.<+.]<,[[.<<-><<<],", "+", "-", "<", ">", ".", ",", "[", "]", ",]+>.],,+->+>-[]][><,-]><]++<.,-[.>.<+.[.<,[-,,[<]+>]->>]>]-+-+<][].,.]+][[<,-.+][+<<-+.],,,<,.]-].-", "][-+>,>[,<[<+-,[+[-.<+,<[.,<+<,>+],.]>... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
0c57b0428a882e021b4f692a3e535189 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset.
*k* experienced teams are participating in the contest. Some of these teams already know some of the prob... | [
"n,k=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n a.append(l)\r\na=list(set(tuple(i) for i in a))\r\nfor i in range(len(a)):\r\n flag=False\r\n for j in range(len(a)):\r\n cnt=0\r\n for x in range(k):\r\n if a[i][x]==1 and a[j][... | {"inputs": ["5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "3 2\n1 0\n1 1\n0 1", "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1\n1 0 0\n1 1 0\n0 0 0", "10 4\n1 0 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 0 1\n1 0 1 0\n0 0 0 0\n0 0 1 0\n1 0 1 0\n0 0 1 1", "2 2\n0 0\... | UNKNOWN | PYTHON3 | CODEFORCES | 48 | |
0c6e3e4e843b406632384caa2fbb3749 | Burglar and Matches | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | [
"n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(m):\r\n\ta,b=map(int,input().split())\r\n\tl.append([b,a])\r\nl.sort(reverse=True)\r\ni=c=0\r\nwhile n>0 and i<len(l):\r\n\tif l[i][1]<n:\r\n\t\tn-=l[i][1]\r\n\t\tc+=l[i][0]*l[i][1]\r\n\t\ti+=1\r\n\telse:\r\n\t\t# print(n)\r\n\t\td=n\r\n\t\tn-=d\r\n\t\tc+=l[i]... | {"inputs": ["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1", "1 1\n1 2", "1 2\n1 9\n1 6", "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "2 1\n2 1", "2 2\n2 4\n1 4", "2 3\n1 7\n1 2\n1 5", "4 1\n2 2", "4 2\n1 10\n4 4", "4 3\n1 4\n6 4\n1 7", "5 1\n10 5", "5 2\n3 9\n2 2", "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "5 10\n1 3... | UNKNOWN | PYTHON3 | CODEFORCES | 244 | |
0c70c1730bd895feea2883bb012782b2 | none | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | [
"n, m = map(int, input().split())\r\na = [[0] * (n + 1) for _ in range(n + 1)]\r\n\r\nfor _ in range(m):\r\n u, v = map(int, input().split())\r\n a[u][v] = 1\r\n a[v][u] = 1\r\n\r\n\r\ndef bfs(x):\r\n fila = [(1, 0)]\r\n visitados = [0] * (n + 1)\r\n\r\n while fila:\r\n u, v = fila.pop(0)\r... | {"inputs": ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "5 4\n1 2\n3 2\n3 4\n5 4", "3 1\n1 2", "2 1\n1 2", "2 0", "20 0", "381 0", "3 3\n1 2\n2 3\n3 1", "3 0", "3 1\n1 3", "3 2\n2 3\n3 1", "4 1\n1 4", "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "20 1\n20 1", "21 1\n21 1", "100 1\n100 1", "... | UNKNOWN | PYTHON3 | CODEFORCES | 164 | |
0c7952f2ca39ae21d131031bba678184 | Vanya and Scales | Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scale... | [
"w,m=map(int,input().split())\r\nfor i in range(33): m=min(m,abs(w**(32-i)-m))\r\nprint(\"NO\" if m else \"YES\")",
"import sys\r\ninput=sys.stdin.readline\r\nw,m=map(int,input().split())\r\nfor i in range(33):\r\n m=min(m,abs(m-w**(32-i)))\r\nif m==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"w... | {"inputs": ["3 7", "100 99", "100 50", "1000000000 1", "100 10002", "4 7", "4 11", "5 781", "7 9", "5077 5988", "2 9596", "4 1069", "4 7134", "4 9083", "4 7927", "4 6772", "5 782", "4 1000000000", "4 357913941", "4 357918037", "5 12207031", "5 41503906", "5 90332031", "11 1786324", "10 999", "8 28087", "8 28598", "32 3... | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
0c84e48381cf6190a9397d86d6c3b7de | Blackjack | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | [
"#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nprint([0,4,4,4,4,4,4,4,4,4,15,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0][readln()[0] - 10])\n",
"def main():\n original_points = 10\n needed = int(input())\n dict = {1: 4, 11: 4, 10: 15, 2: 4, 3: 4, 4: 4, 5: 4, 6: 4, 7: 4, 8: 4, 9: 4}\... | {"inputs": ["12", "20", "10", "11", "15", "18", "25", "22", "1", "2", "3", "4", "5", "6", "7", "8", "9", "13", "14", "16", "17", "19", "21", "23", "24"], "outputs": ["4", "15", "0", "4", "4", "4", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "4", "4", "4", "4", "4", "4", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 329 | |
0c8b321b7154ef0e7847a58958a4c5f3 | Beautiful Road | A long time ago in some country in Asia were civil wars.
Each of *n* cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city.
Road making was difficult, so the country had few roads, exactly *n*<=-<=1. Also you could reach any city from any other city ... | [
"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 get_root(s):\r\n v = []\r\n while not s == root[s]:\r\n v.append(s)\r\n s = root[s]\r\n for i in v:\r\n root[i] = s\r\n return s\r\n\r\ndef unite(s, ... | {"inputs": ["2\n2 1 5", "6\n1 2 1\n1 3 5\n3 4 2\n3 5 3\n3 6 4", "10\n10 6 43981\n4 2 6730\n1 2 35174\n5 3 61951\n8 7 43981\n7 1 6730\n5 8 6730\n9 3 52479\n6 4 18138", "9\n6 4 72697\n9 6 72697\n1 6 38220\n2 6 38220\n6 7 72697\n6 5 72697\n8 6 72697\n3 6 38220", "10\n9 2 18232\n3 4 45701\n3 9 13895\n8 9 18232\n7 6 56122\n... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0cd13038b6b1d8af20a4bfe259f65af7 | Pages | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | [
"n, p, k = map(int, input().split())\r\nstring = ''\r\nif p != 1 and p != n:\r\n if p - k <= 1:\r\n string += ' '.join(map(str, [i for i in range(1, p)]))\r\n string += ' ({}) '.format(p)\r\n else:\r\n string += '<< '\r\n string += ' '.join(map(str, [i for i in range(p - k, p)]))\r... | {"inputs": ["17 5 2", "6 5 2", "6 1 2", "6 2 2", "9 6 3", "10 6 3", "8 5 4", "100 10 20", "100 25 11", "5 2 1", "5 3 1", "79 35 12", "100 99 5", "100 99 15", "100 100 17", "100 35 28", "100 46 38", "100 46 48", "100 10 100", "3 1 1", "3 2 1", "17 5 3", "3 1 3", "7 5 1", "5 5 5", "5 3 5"], "outputs": ["<< 3 4 (5) 6 7 >>... | UNKNOWN | PYTHON3 | CODEFORCES | 196 | |
0cd16fcabb7afbcb633d4e2d16d8330b | none | This is an interactive problem.
Bob lives in a square grid of size $n \times n$, with rows numbered $1$ through $n$ from top to bottom, and columns numbered $1$ through $n$ from left to right. Every cell is either allowed or blocked, but you don't know the exact description of the grid. You are given only an integer $... | [
"from sys import stdout\r\ndef Q(r1, c1, r2, c2):\r\n print('?', r1, c1, r2, c2)\r\n stdout.flush()\r\n return input() == \"YES\"\r\n\r\nn = int(input())\r\nans = [' '] * (2 * n - 2)\r\nr = c = 1\r\nfor i in range(n - 1):\r\n if Q(r + 1, c, n, n):\r\n ans[i] = 'D'\r\n r += 1\r\n else:\r... | {"inputs": ["5\n.....\n.###.\n.###.\n.###.\n...#.", "7\n.......\n.......\n.......\n.......\n......#\n.......\n....#..", "2\n..\n..", "2\n.#\n..", "2\n..\n#.", "5\n.....\n.....\n.....\n.....\n.#.#.", "10\n..#.......\n..#......#\n......###.\n.#......#.\n.......#.#\n.##....#.#\n.....#....\n#...####..\n.#....##..\n##..#...... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0ce006c0eb78b2ee3e77330642120204 | none | Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally:
Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomi... | [
"def polynomials(n, k, A):\n L = [0]\n s = 0\n for i in range(n):\n s += A[i]\n if s & 1:\n break\n s >>= 1\n L.append(s)\n\n R = [0]\n s = 0\n for i in reversed(range(1, n+1)):\n s += A[i]\n if abs(s) > k:\n break\n s *= 2\n ... | {"inputs": ["3 1000000000\n10 -9 -3 5", "3 12\n10 -9 -3 5", "2 20\n14 -7 19", "5 5\n0 -4 -2 -2 0 5", "6 10\n-2 -1 7 -3 2 7 -6", "7 100\n2 21 11 45 58 85 -59 38", "100 1000\n-62 57 -27 -67 49 -10 66 -64 -36 -78 62 -75 -39 75 -47 -36 41 -88 62 -43 22 29 -20 58 40 16 71 -2 -87 12 86 -90 -92 67 -12 -48 -10 -26 78 68 22 -3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0ce04c7522161634da17dd0a350180e7 | Juicer | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | [
"cont = 0\r\nc = 0\r\nn,b,d = [int(i) for i in input().split()]\r\nlis = [int(i) for i in input().split()]\r\nfor x in range(len(lis)):\r\n if lis[x] <= b:\r\n cont += lis[x]\r\n if cont > d:\r\n cont = 0\r\n c+=1\r\nprint(c)",
"def getNumOfTimes(b, d, oranges):\r\n num =... | {"inputs": ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1", "2 951637 951638\n44069 951637", "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126", "100 1000 1083\n992 616 818 359 609 ... | UNKNOWN | PYTHON3 | CODEFORCES | 419 | |
0d78606b1f006c98a437599329ad938e | Volleyball | Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has *n* junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads c... | [
"import sys\r\n\r\ndef input():\r\n return sys.stdin.readline()[:-1]\r\n\r\nN,M = list(map(int,input().split()))\r\ne_list = [[] for i in range(N)]\r\n\r\nX,Y = list(map(int,input().split()))\r\nX-=1\r\nY-=1\r\n\r\nfor i in range(M):\r\n u,v,w = list(map(int,input().split()))\r\n u-=1\r\n v-=1\r\n e_... | {"inputs": ["4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "3 3\n1 3\n1 2 2\n1 3 3\n3 2 1\n2 7\n2 7\n3 6", "3 1\n1 3\n1 2 2\n2 7\n2 7\n3 6", "3 2\n3 3\n1 2 2\n1 3 3\n2 7\n2 7\n3 7", "2 2\n1 2\n1 2 3\n1 2 2\n2 7\n3 2", "1 0\n1 1\n74 47", "5 5\n1 3\n1 3 3\n5 1 6\n4 3 8\n1 3 3\n5 2 4\n1 2\n4 1\n2 5\n5 2\n1 2"... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
0d902b95505260c05a57bdc1eeca9891 | Warrior and Archer | In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.
V... | [
"# LUOGU_RID: 99814317\nans=0x3f3f3f3f\r\nn=int(input())\r\na=list(map(int,input().split()))#输入n个点的位置坐标\r\nb=n//2\r\na.sort()#给n个点的位置坐标从小到大排序\r\nfor i in range(b):#找出最后剩下的两个点的位置坐标的最小值\r\n ans=min(ans,a[b+i]-a[i])#a[b+i]为剩下右侧的点的位置坐标,a[i]为剩下左侧的点的位置坐标\r\nprint(ans)",
"# LUOGU_RID: 99814222\nans=0x3f3f3f3f\r\nn=in... | {"inputs": ["6\n0 1 3 7 15 31", "2\n73 37", "2\n0 1000000000", "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782", "2\n0 1", "8\n552283832 997699491 89302459 301640204 288141798 31112026 710831619 862166501", "4\n0 500000000 500000001 1000000000", "18\n515925896 832652240 279975694 5709... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
0d91bb06eb67c4ce2c2a089bdde1617d | Petr and Book | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | [
"pages = int(input())\r\ndays = list(map(int, input().split()))\r\ncurrent = -1\r\nwhile pages > 0:\r\n current += 1\r\n if current == 7:\r\n current = 0\r\n pages -= days[current]\r\n \r\nprint(current + 1)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ni = 0\r\nwhile n>a[i]... | {"inputs": ["100\n15 20 20 15 10 30 45", "2\n1 0 0 0 0 0 0", "100\n100 200 100 200 300 400 500", "3\n1 1 1 1 1 1 1", "1\n1 1 1 1 1 1 1", "20\n5 3 7 2 1 6 4", "10\n5 1 1 1 1 1 5", "50\n10 1 10 1 10 1 10", "77\n11 11 11 11 11 11 10", "1\n1000 1000 1000 1000 1000 1000 1000", "1000\n100 100 100 100 100 100 100", "999\n10 2... | UNKNOWN | PYTHON3 | CODEFORCES | 402 | |
0d96290ec1b71abbe19125d7e7eb6517 | Seat Arrangements | Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied.
The classroom contains $n$ rows of seat... | [
"from sys import stdin\r\n\r\nn, m, k = [int(i) for i in input().split()]\r\ns = stdin.read().splitlines()\r\nresult = 0\r\nif k == 1:\r\n result = sum(elem.count('.') for elem in s)\r\n print(result)\r\n exit()\r\ns += map(''.join, zip(*s))\r\nfor elem in s:\r\n for i in map(len, filter(None, elem.spli... | {"inputs": ["1 2 2\n..", "3 3 4\n.*.\n*.*\n.*.", "1 1 1\n.", "1 1 1\n*", "2 2 2\n.*\n*.", "1 1 1000\n.", "1 1 2000\n*", "3 3 1\n.*.\n.*.\n.*.", "2 2 1\n..\n.."], "outputs": ["1", "0", "1", "0", "0", "0", "0", "6", "4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
0debd0e39e8f9597e4e1a057bfdb4df9 | Места в самолёте | В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ... | [
"n, k = [int(i) for i in input().split()]\r\n\r\nmas = []\r\n\r\nfor i in range(n):\r\n mas.append([j for j in input()])\r\n#print(mas)\r\n#print(k)\r\n\r\nif k != 0:\r\n for i in range(n):\r\n for j in range(12):\r\n if mas[i][j] == '.':\r\n if j > 0 and j < 11:\r\n ... | {"inputs": ["1 2\nSP.-SS.S-S.S", "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP", "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP", "5 6\nPP.-PS.P-P..\nPPS-SP..-P.P\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP", "1 1\n..S-PS..-.PP", "2 2\nPP.-S.SS-.S.\nSSP-SSSS-S.S", "30 1\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPP... | UNKNOWN | PYTHON3 | CODEFORCES | 85 | |
0df75644338ab2c4b5718e93078c22e0 | Game | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | [
"\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nl.sort()\r\nfor i in range(n-1):\r\n\tif i % 2 == 0:\r\n\t\tl.pop()\r\n\telse:\r\n\t\tl.pop(0)\r\n\r\nfor i in l:\r\n\tprint(i)",
"t_moves=int(input())\r\nmoves=t_moves-1\r\n\r\na=list(map(int, input().split()))\r\na.sort()\r\n\r\ni=0;j=t_moves-1\... | {"inputs": ["3\n2 1 3", "3\n2 2 2", "9\n44 53 51 80 5 27 74 79 94", "10\n38 82 23 37 96 4 81 60 67 86", "10\n58 26 77 15 53 81 68 48 22 65", "1\n124", "2\n2 1", "3\n1 1 1000", "2\n322 322", "3\n9 92 12", "3\n1 2 2"], "outputs": ["2", "2", "53", "60", "53", "124", "1", "1", "322", "12", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 391 | |
0e157a547fc5207bba32733c03b0e7fa | Dark Assembly | Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed.
The Dark Assembly consists of *n* senators. Each ... | [
"from itertools import *\r\n\r\ndef read(fn=int):\r\n\treturn map(fn,input().split())\r\n\r\nn,k,A = read()\r\nbl = [[*read()] for _ in range(n)]\r\nb,l = map(list,zip(*bl))\r\n\r\nans = 0\r\nfor p in combinations_with_replacement(range(n),k):\r\n\tfor i in p:\r\n\t\tl[i] += 10\r\n\r\n\ts = 0\r\n\tfor p2 in product... | {"inputs": ["5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70", "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70", "1 3 20\n20 20", "4 3 40\n10 40\n11 50\n10 50\n9 50", "4 4 60\n10 40\n11 50\n10 50\n12 30", "2 7 20\n10 40\n10 50", "2 1 25\n10 40\n12 50", "3 3 31\n10 40\n12 50\n15 0", "1 3 40\n10 0", "1 4 30\n10 20", "1 7 10\n40... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0e3294f49387c2acfaea24e248588750 | Before an Exam | Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. ... | [
"d, time = map(int, input().split())\r\nminTime = []\r\nmaxTime = []\r\nfor i in range(d):\r\n mn, mx = map(int, input().split())\r\n minTime.append(mn)\r\n maxTime.append(mx)\r\nminSum = sum(minTime)\r\nmaxSum = sum(maxTime)\r\nif minSum <= time <= maxSum:\r\n print(\"YES\")\r\n for i in range(d):\r... | {"inputs": ["1 48\n5 7", "2 5\n0 1\n3 5", "1 1\n5 6", "1 4\n2 4", "2 5\n4 6\n0 0", "27 97\n2 8\n0 5\n5 6\n3 6\n5 5\n1 2\n3 5\n1 8\n0 4\n3 3\n0 2\n0 0\n4 8\n5 6\n5 8\n0 7\n1 4\n0 4\n1 5\n3 7\n2 5\n5 6\n4 7\n3 8\n0 1\n3 4\n5 7", "30 92\n4 5\n4 7\n2 6\n8 8\n7 8\n4 5\n1 5\n7 8\n1 2\n6 8\n2 7\n2 4\n0 0\n1 3\n4 5\n1 1\n0 7\n... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
0e34ebe5fef7204f2fe932a215b89c7f | Domino Principle | Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put *n* dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The *i*-th domino ... | [
"import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef update(i, x, tree):\r\n i += l1\r\n tree[i] = x\r\n i //= 2\r\n while i:\r\n tree[i] = max(tree[2 * i], tree[2 * i + 1])\r\n i //= 2\r\n return\r\n\r\ndef get_max(s, t, tree):... | {"inputs": ["4\n16 5\n20 5\n10 10\n18 2", "4\n0 10\n1 5\n9 10\n15 10", "3\n6 7\n2 9\n-6 10", "4\n-6 9\n9 5\n-7 4\n0 9", "5\n-47 19\n-43 14\n83 27\n-67 46\n-58 98", "6\n20 39\n38 13\n-25 48\n-22 38\n13 39\n90 54", "10\n34 9\n-41 26\n-62 32\n1 10\n77 14\n92 7\n-45 35\n75 19\n-23 2\n-46 8"], "outputs": ["3 1 4 1 ", "4 1 2... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
0e3feaf5ee19e176f276c89f80d998d6 | Interactive Bulls and Cows (Easy) | 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 responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For exa... | [
"num = []\r\nfor i in range(10):\r\n print(str(i) * 4)\r\n n, m = map(int, input().split())\r\n for j in range(n):\r\n num.append(i)\r\npas = False\r\nfor i1 in range(4):\r\n for i2 in range(4):\r\n for i3 in range(4):\r\n for i4 in range(4):\r\n if i1 != i2 and i... | {"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 | 15 | |
0e82cefa01c6997641a42ae83143b95c | Arpa's weak amphitheater and Mehrdad's valuable Hoses | Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if... | [
"def g(x):\r\n if x == t[x]: return x\r\n t[x] = g(t[x])\r\n return t[x]\r\n\r\nf = lambda: map(int, input().split())\r\nhoses, pairOfFriends, weight = f()\r\nweightsAndBeauties = [(0, 0)] + list(zip(f(), f()))\r\nt = list(range(hoses + 1))\r\n\r\n\r\nfor i in range(pairOfFriends):\r\n f1, f2 = f()\r\n ... | {"inputs": ["3 1 5\n3 2 5\n2 4 2\n1 2", "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3", "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5", "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 69... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
0ea22e7ee558ec693ca7ade63f2070c0 | none | Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water... | [
"n = int(input())\nl = [int(x) for x in input().split()]\ndistinct = []\ncur = 0\nfor i in l:\n cur = max(cur, i + 1)\n distinct.append(cur)\n\nfor i in range(n - 1, 0, -1):\n distinct[i - 1] = max(distinct[i - 1], distinct[i] - 1)\n\nans = sum([a - b - 1 for a, b in zip(distinct, l)])\nprint(ans)",
"imp... | {"inputs": ["6\n0 1 0 3 0 2", "5\n0 1 2 1 2", "5\n0 1 1 2 2", "1\n0", "100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15 19 15 7 17 17 18 19 9 10 21 0 22 9 2 24 24 4 24 7 25 14 5 8 28 29 30 31 31 31 0 3 15 31 8 33 6 35 35 35 36 36 37 37 38 39 28 0 2 23 41 9 9 0 6 25 41 41 12 42 43 43 36... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
0ea603ee7629911d0ced82f19b960bfe | none | Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are *n* objects numbered from 1 to *n* arranged in a circle (in clockwise order). Object number 1 is a black hole and the... | [
"import queue\n\nn = int(input())\n\nsR = list(map(int, input().split()[1:]))\nsM = list(map(int, input().split()[1:]))\ns = [sR, sM]\n\nUNK = -1\nWIN = 2\nLOSE = 3\n\nA = [[UNK] * n for i in range(2)]\nCNT = [[0] * n for i in range(2)]\nV = [[False] * n for i in range(2)]\n# ricky turn 0\n# morty turn 1\nA[0][0] =... | {"inputs": ["5\n2 3 2\n3 1 2 3", "8\n4 6 2 3 4\n2 3 6", "10\n3 4 7 5\n2 8 5", "17\n1 10\n1 12", "23\n1 20\n3 9 2 12", "85\n12 76 7 75 51 43 41 66 13 59 48 81 73\n3 65 60 25", "100\n84 80 73 28 76 21 44 97 63 59 6 77 41 2 8 71 57 19 33 46 92 5 61 88 53 68 94 56 14 35 4 47 17 79 84 10 67 58 45 38 13 12 87 3 91 30 15 11 2... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
0ebc1719d1f245ede35d95c7bd681e06 | Taxes | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo... | [
"from math import sqrt\r\n\r\n\r\ndef prime(n):\r\n for d in range(3, int(sqrt(n)) + 1, 2):\r\n if n % d == 0:\r\n return 0\r\n return 1\r\n\r\n\r\nn = int(input())\r\nif n == 2:\r\n print(1)\r\nelif n % 2 == 0:\r\n print(2)\r\nelif prime(n):\r\n print(1)\r\nelif prime(n - 2):\r\n ... | {"inputs": ["4", "27", "3", "5", "10", "2000000000", "26", "7", "2", "11", "1000000007", "1000000009", "1999999999", "1000000011", "101", "103", "1001", "1003", "10001", "10003", "129401294", "234911024", "192483501", "1234567890", "719241201", "9", "33", "25", "15", "147", "60119912", "45", "21", "9975", "17", "99", "... | UNKNOWN | PYTHON3 | CODEFORCES | 101 | |
0ec70b522b9282b4d80872c39c9db3fb | Berland Square | Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1,<=2,<=...,<=*K* and the cen... | [
"def readGen(trans):\r\n\twhile 1:\r\n\t\tfor x in input().split():\r\n\t\t\tyield(trans(x))\r\n\t\r\nreadint=readGen(int)\r\n\r\n[N,x,M,y]=(next(readint) for i in range(4))\r\n\r\nd=abs(y-x)\r\n\r\ndef interval(a,b): return range(a,b+1)\r\n\r\ndef case1(N,M,d): # d>=N\r\n\tans=0\r\n\tfor r in interval(1, min(M,d-N... | {"inputs": ["1 0 1 1", "1 0 1 2", "3 3 4 7", "2 2 2 3", "1 100000 1 99999", "4 7 3 3", "1 0 1 100", "1 0 2 3", "2 2 4 4", "4 4 2 2", "1 -1 5 -10", "5 2 1 -5", "5 4 3 -2", "3 7 4 1", "3 -9 3 4", "2 -6 4 6", "2 -4 1 9", "2 1 4 -7", "2 4 5 -4", "5 7 1 2", "94925 5648 96389 1799", "94244 7010 97753 -7757", "93564 8371 9911... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0ee88c557025d4dd9e3747078da8071a | Long Path | One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider roo... | [
"def f(s):\r\n return int(s)-1\r\n\r\nn = int(input())\r\nmod = 10**9+7\r\narr = list(map(f,input().split()))\r\ndp=[0]*(n+1)\r\nfor i in range(n):\r\n dp[i+1] = dp[i]+2+dp[i]-dp[arr[i]]\r\n dp[i+1]%=mod\r\nprint(dp[-1])\r\n",
"n = int(input())\r\np = [0]+list(map(int,input().split()))\r\ndp= [0 for _ in... | {"inputs": ["2\n1 2", "4\n1 1 2 3", "5\n1 1 1 1 1", "7\n1 2 1 3 1 2 1", "1\n1", "3\n1 1 3", "10\n1 1 3 2 2 1 3 4 7 5", "20\n1 2 2 2 2 1 4 7 8 6 5 3 5 3 8 11 5 10 16 10", "32\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\n1 1 3 2 2 1 3 4 7 5", "30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 ... | UNKNOWN | PYTHON3 | CODEFORCES | 54 | |
0f0ab0ca68d9693bfdba9ec3a78d7157 | Royal Questions | In a medieval kingdom, the economic crisis is raging. Milk drops fall, Economic indicators are deteriorating every day, money from the treasury disappear. To remedy the situation, King Charles Sunnyface decided make his *n* sons-princes marry the brides with as big dowry as possible.
In search of candidates, the king ... | [
"import io, os, sys\r\n\r\nfrom heapq import heappush, heappop\r\nfrom operator import itemgetter\r\n\r\n\r\nclass UnionSet:\r\n def __init__(self, n: int):\r\n self.parent = [*range(n)]\r\n self.rank = [1] * n\r\n self.is_circle = [False] * n\r\n\r\n def __len__(self):\r\n return ... | {"inputs": ["2 3\n1 2 5\n1 2 1\n2 1 10", "3 2\n1 2 10\n3 2 20", "2 2\n1 2 1\n1 2 2", "3 3\n1 3 4\n1 3 2\n1 3 8", "2 1\n1 2 6", "4 3\n1 2 1\n2 3 2\n3 4 1", "4 2\n1 2 4\n1 2 5", "4 2\n1 2 3\n1 3 4", "4 4\n1 2 6971\n1 2 4379\n3 4 1092\n3 2 9449", "7 6\n3 5 4229\n2 7 7116\n3 4 2492\n7 3 3742\n7 3 2996\n3 4 8359", "7 15\n5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0f282b1f9ea8de06a0b9a6c9266ff534 | Cards | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | [
"n=int(input())\nl=list(map(int,input().split()))\na=[]\nfor q in range(n):\n a.append([l[q],q])\na.sort()\nfor q in range(n//2):\n print(a[q][1]+1,a[n-q-1][1]+1)",
"n = int(input())\na = list(map(int, input().split()))\nb = [0]*n\nk = sum(a)/n*2\nfor j in range(len(a)):\n for i in range(j+1, len(a)):\n ... | {"inputs": ["6\n1 5 7 4 4 3", "4\n10 10 10 10", "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "4\n82 46 8 44", "2\n35 50", "8\n24 39 49 38 44 64 44 50", "100\... | UNKNOWN | PYTHON3 | CODEFORCES | 354 | |
0f2fcfff4d971d95c3358fe7ecd570c7 | Collecting Beats is Fun | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | [
"# https://codeforces.com/problemset/problem/373/A\n# 900\n\nn = int(input())\nn2 = n * 2\n\n\nx = {}\no = \"YES\"\nfor _ in range(4):\n r = input()\n\n for c in r:\n if c == \".\":\n continue\n\n x.setdefault(c, 0)\n x[c] += 1\n\n if x[c] > n2:\n o = \"NO\"\n... | {"inputs": ["1\n.135\n1247\n3468\n5789", "5\n..1.\n1111\n..1.\n..1.", "1\n....\n12.1\n.2..\n.2..", "1\n6981\n.527\n4163\n2345", "5\n9999\n9999\n9999\n9999", "2\n4444\n3333\n2222\n1111", "3\n2123\n1232\n2321\n3213", "2\n1...\n.1..\n..1.\n...1", "2\n1.1.\n.1.1\n2.2.\n.222", "1\n1..2\n.3.4\n567.\n.89.", "1\n1122\n3344\n55... | UNKNOWN | PYTHON3 | CODEFORCES | 224 | |
0f42dc2a3032e100f108c4a739f07748 | Treasure Island | Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle *n*<=×<=*m* in size. Each cell stands for an islands' square (the square's side length ... | [
"import sys\r\ninput = sys.stdin.readline\r\nn, m = map(int, input().split())\r\na, pos = [], []\r\nfor i in range(n):\r\n a.append(input().rstrip())\r\n for j in range(m):\r\n if a[i][j] != '.' and a[i][j] != '#':\r\n pos.append((i, j))\r\nW = [[0]*(m+3) for i in range(n+3)]\r\nfor i in ran... | {"inputs": ["6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2", "3 4\n####\n#.A#\n####\n2\nW 1\nN 2", "10 10\n##########\n#K#..##..#\n##...ZB..#\n##.......#\n#D..#....#\n##...Y..##\n#...N...J#\n#.G...#.##\n#.S.I....#\n##########\n4\nE 2\nW 4\nS 3\nN 4", "17 19\n#######... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
0f58d81163a401fa15ec625c5344c8cd | Geometry Horse | Vasya plays the Geometry Horse.
The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.
There are *n* types of geometric figures. The number of figures of type *k**i* and figure cost *c*... | [
"n = int(input())\r\narr = []\r\nfor i in range(n):\r\n arr.append(list(map(int, input().split())))\r\narr.sort(key=lambda x: x[1])\r\nt = int(input())\r\np = list(map(int, input().split()))\r\np.insert(0, 0)\r\np.append(1e12+1)\r\nrate = 1\r\nret = 0\r\nfor i in range(1, len(p)):\r\n diff = p[i]-p[i-1]\r\n ... | {"inputs": ["1\n5 10\n2\n3 6", "2\n3 8\n5 10\n1\n20", "3\n10 3\n20 2\n30 1\n3\n30 50 60", "1\n100 1000\n1\n1", "1\n1 1000\n1\n1", "1\n1 1000\n1\n2", "2\n1000000000 1000\n1 1\n1\n10", "6\n5 9\n63 3\n30 4\n25 6\n48 2\n29 9\n8\n105 137 172 192 632 722 972 981", "7\n9902 9\n5809 6\n2358 0\n6868 7\n9630 2\n8302 10\n9422 3\n... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
0f711255a3be0db0ebe92759ed87ff6c | Stadium and Games | Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages... | [
"def cc(res):\r\n l = 1\r\n r = res\r\n while l<=r:\r\n mid = l+r >>1\r\n if mid*mid==res:\r\n return mid\r\n elif mid*mid>res:\r\n r = mid-1\r\n else:\r\n l = mid+1\r\n return -1\r\n\r\n\r\ndef solve(a,b,c):\r\n if b*b-4*a*c<0:\r\n ... | {"inputs": ["3", "25", "2", "1", "15", "314", "524800", "5149487579894806", "249999998807430810", "1000000000000000000", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "21", "28", "36", "45", "55", "78", "105", "120", "136", "171", "210", "255", "5460", "16383", "391170", "1906128", "576460752303423487", "... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
0f7b0ee4cd52ba5f602dd8c53867f494 | Multicolored Marbles | Polycarpus plays with red and blue marbles. He put *n* marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are ze... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nMOD = 10**9+7\r\nN = int(input())\r\ndp = [[0,0] for _ in range(N+1)]\r\n\r\nfor i in range(N):\r\n dp[i+1][0]=dp[i][0]\r\n dp[i+1][1]=dp[i][1]\r\n if i%2:\r\n dp[i+1][1]+=dp[i][0]+1\r\n else:\r\n dp[i+1][0]+=dp[i][1]+1\r\... | {"inputs": ["3", "4", "1", "2", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "30", "40", "35", "747", "811", "523", "939", "7218", "6578", "4994", "3410", "9122", "11500", "37212", "95628", "21341", "63405", "670293", "12357", "838069", "696485", "1000000", "999... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
0fa262b62ad1fc05fa98a73f6cec7828 | Complicated GCD | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | [
"a, b = list(input().split())\n\nif a == b:\n\tprint(a)\nelse:\n\tprint(\"1\")\n\t \t \t\t \t \t\t \t \t\t \t",
"a, b = input().split()\r\nprint(a if a == b else 1)\r\n",
"a ,b = list(map(int , input().split()))\r\n\r\n\r\ndef GCD(a , b):\r\n\r\n if b == 0 :\r\n return a\r\n return GCD(b ... | {"inputs": ["1 2", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "1 100", "100 100000", "12345 67890123456789123457", "1 1", "2 2", "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 839273915883927391588392739... | UNKNOWN | PYTHON3 | CODEFORCES | 374 | |
0fafdabf58fdb7b9bc79f12cceb407f3 | Airplane Arrangements | There is an airplane which has *n* rows from front to back. There will be *m* people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the... | [
"MOD = 10 ** 9 + 7\nn, m = input().split(' ')\nn = int(n)\nm = int(m)\nans = pow(2 * (n + 1), m, MOD)\nans = (ans * (n + 1 - m)) % MOD\nans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD\nprint(ans)\n",
"mod = 1000000007\r\ndef power(a, p):\r\n res = 1\r\n while p > 0:\r\n if p % 2 == 1:\r\n res... | {"inputs": ["3 3", "1000000 1000000", "1000000 500000", "1 1", "10 1", "285042 201091", "896437 604720", "284114 73851", "541826 316395", "353093 96536", "540898 158491", "858309 773589", "56322 42432", "461466 56468", "29102 1503", "42800 41731", "235175 92933", "921643 744360", "619924 583916", "43657 852", "4672 308... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
0fce72ef3ce162bced800165e0d75fe4 | Interesting Sequence | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | [
"import heapq\nimport sys\n\nlim = 1000\n\na = int(input())\n\ndef gen_pow():\n ans = {}\n pw_x = 1\n x = 0\n while pw_x <= a:\n ans[pw_x] = x\n pw_x *= 12\n x += 1\n return ans\n\npow_map = gen_pow()\n\nyear_list = set()\n \nfor pw_x, x in pow_map.items():\n pw_y = a - pw_... | {"inputs": ["2", "3", "13", "1729", "1", "156", "144", "15407021574586369", "1283918464548876", "106993205379216", "8916100449984", "743008391424", "61917613056", "5162766336", "465813504", "749018868196746805223329946373352590959663287279411259311764529219426154819446575772163700626968045411915608325823147333921760188... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
0fd3c9bddbe0ccc202f9c7c24aea01d3 | King Moves | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | [
"from sys import stdin, stdout\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n\ndef read_ints():\n\treturn list(map(int, read().split()))\n\ndef solve():\n\ta=read()\n\tc=0\n\tif a[0]=='a' or a[0]=='h':\n\t\tc+=1\n\tif a[1]=='1' or a[1]=='8':\n\t\tc+=1\n\tif c==0:\n\t\tpr... | {"inputs": ["e4", "a1", "h8", "a4", "g7", "e1", "b2", "c7", "h6", "c8", "h2", "h5", "a8", "f8", "h1", "f2", "e8", "h3", "b8", "g8", "d8", "h4", "b1", "a2"], "outputs": ["8", "3", "3", "5", "8", "5", "8", "8", "5", "5", "5", "5", "3", "5", "3", "8", "5", "5", "5", "5", "5", "5", "5", "5"]} | UNKNOWN | PYTHON3 | CODEFORCES | 324 | |
0fd712709f42f0903bd59203c4ea71f4 | Beaver Game | Two beavers, Timur and Marsel, play the following game.
There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than *k* meter... | [
"n, m, k = map(int, input().split())\r\n\r\nif n % 2 == 0:\r\n print('Marsel')\r\nelse:\r\n divisors = set()\r\n i = 1\r\n while i * i <= m:\r\n if m % i == 0:\r\n divisors.add(i)\r\n divisors.add(m // i)\r\n i += 1\r\n ans = 10 ** 18\r\n for x in divisors:\r\n ... | {"inputs": ["1 15 4", "4 9 5", "14 30 9", "81 180 53", "225 187 20", "501 840 11", "3 11 6", "1 2 1", "1 1 2", "1 1 1", "1 2 2", "2 1 1", "2 1 2", "2 2 1", "2 2 2", "1000000000 1000000000 1000000000", "999999999 735134400 1", "999999999 735134400 100", "787965358 999999986 2", "588462355 999999986 2", "994427144 999999... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
0ff293f9b8bd79037a2e24a7751fb766 | Constellation | A star map in Berland is a checked field *n*<=×<=*m* squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer *x* (radius of the constellation) the follow... | [
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, m, k = map(int, input().split())\r\na = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)]\r\ncnt = [0] * 400\r\n\r\nfor i in range(1, n - 1):\r\n ... | {"inputs": ["5 6 1\n....*.\n...***\n....*.\n..*...\n.***..", "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..", "5 5 1\n.....\n.....\n.*..*\n*.*..\n....*", "5 5 3\n*.***\n.****\n..***\n*.***\n.**.*", "10 10 6\n.*..**.**.\n**********\n****.*****\n**.***....\n***.******\n****.**..*\n**.**.****\n****.**..*\n..**.**.*.\n.*.*... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
10283a6443b1aa148146d9713d2ec662 | none | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | [
"c=0\r\nv=[2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49]\r\nfor j in v:\r\n print(j,flush=True)\r\n if input()==\"yes\":\r\n c+=1\r\n if c>=2:\r\n break\r\n\r\nif c >=2:\r\n print(\"composite\")\r\nelse:\r\n print(\"prime\")\r\n\r\n",
"print(\"composite\" if sum(input()=='yes' f... | {"inputs": ["30", "59", "2", "7", "9", "13", "55", "89", "3", "4", "6", "8", "11", "12", "25", "36", "46", "47", "49", "51", "53", "59", "64", "81", "91", "93", "94", "95", "96", "97", "99", "100", "26", "94", "25", "46", "49", "82", "87", "85", "74", "86", "93", "58", "47", "22", "23", "62", "38", "91", "34", "95", "4... | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
102e033fa305ffe7eb4ac9cd64298025 | Towers | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | [
"n=int(input())\r\nx=list(map(int, input().split()))\r\ny=set(x)\r\nmaxx=[]\r\nfor i in y:\r\n maxx.append(x.count(i))\r\nprint(max(maxx), len(y))",
"n = int(input())\r\na = [int(a) for a in input().split()]\r\ncount = 1\r\nc = []\r\nm = []\r\n\r\nfor i in range(0,n):\r\n\tb = a.count(a[i])\r\n\tif a[i] not in m... | {"inputs": ["3\n1 2 3", "4\n6 5 6 7", "4\n3 2 1 1", "4\n1 2 3 3", "3\n20 22 36", "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 2... | UNKNOWN | PYTHON3 | CODEFORCES | 790 | |
1040a7cfb73d4e95e9ff68875b67993c | Two Buttons | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | [
"from collections import deque\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nqueue = deque([(n, 0)])\r\n\r\nvisited = set()\r\n\r\n\r\nwhile queue:\r\n current, clicks = queue.popleft()\r\n if current == m:\r\n print(clicks)\r\n break\r\n\r\n if current * 2 not in visited and current * 2... | {"inputs": ["4 6", "10 1", "1 2", "2 1", "1 3", "3 1", "2 10", "100 99", "99 100", "10 17", "666 6666", "6666 666", "1 8192", "1 8193", "9999 10000", "10000 9999", "10000 1", "1234 5678", "9102 9103", "8192 1", "9912 1023", "100 500", "9997 9999", "5000 10000", "4000 7997", "1 10000", "1 8191", "9999 10000", "9097 9998... | UNKNOWN | PYTHON3 | CODEFORCES | 68 | |
1047525a13a957e0b64cc5b18b0b5e81 | Candies | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | [
"n,m=map(int,input().split())\r\na=[n//m]*m\r\nn=n%m\r\nfor i in range(m-n,m):\r\n a[i]+=1\r\nprint(*a)\r\n ",
"n, m = map(int, input().split())\nmydiv = n // m\nmymod = n % m\nmylist = [ mydiv for _ in range(m) ]\nif mymod == 0 :\n out = ' '.join(str(i) for i in mylist)\nelse :\n for i in mylist :\n... | {"inputs": ["12 4", "15 6", "18 8", "1 1", "2 1", "100 1", "100 100", "100 10", "64 8", "81 27", "100 99", "100 51", "100 49", "100 13", "97 11", "19 3", "99 10", "88 5", "87 34", "97 55"], "outputs": ["3 3 3 3 ", "2 2 2 3 3 3 ", "2 2 2 2 2 2 3 3 ", "1 ", "2 ", "100 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 355 | |
105128009fdb4d359d3d6d3777c9553b | Students in Railway Carriage | There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carri... | [
"def main():\r\n n, a, b = map(int, input().split())\r\n line = input()\r\n spaces = [len(e) for e in line.split('*') if e]\r\n ca, cb = a, b\r\n for e in spaces:\r\n if e % 2 != 0:\r\n if ca > cb:\r\n cb -= e // 2\r\n ca -= e - e // 2\r\n el... | {"inputs": ["5 1 1\n*...*", "6 2 3\n*...*.", "11 3 10\n.*....**.*.", "3 2 3\n***", "9 5 3\n*...*...*", "9 2 4\n*...*...*", "9 2 200000\n*...*...*", "1 0 1\n.", "14 3 7\n.*.......*..*.", "6 1 3\n*....*", "5 1 2\n...*.", "2 2 0\n..", "2 0 2\n..", "5 3 3\n...**", "3 0 1\n.*.", "13 3 3\n*...*...*...*", "7 0 4\n...*..*", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 75 | |
1057717c0867a122f0a8018ba7fd151e | Lizard Era: Beginning | In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has *n* mandatory quests. To perform each of them, you need to take exactly two companions.
The attitude of each of the companions to the hero is an integer. Initially, the attitude of each... | [
"n = int(input())\r\nans = (-10 ** 8, [\"Impossible\"])\r\ns = []\r\nd = {}\r\nfl = True\r\na = [list(map(int, input().split())) for i in range(n)]\r\ndef job(nom, l, m, w):\r\n\tglobal s, ans\t\r\n\tif nom == n // 2 and fl:\r\n\t\tsu, ss = d.get((m - l, w - l), (-10 ** 10, []))\r\n\t\tif l > su:\r\n\t\t\td[(m - l,... | {"inputs": ["3\n1 0 0\n0 1 0\n0 0 1", "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7", "2\n1 0 0\n1 1 0", "25\n26668 10412 12658\n25216 11939 10247\n28514 22515 5833\n4955 19029 22405\n12552 6903 19634\n12315 1671 505\n20848 9175 6060\n12990 5827 16433\n9184 30621 25596\n31818 7826 11221\n18090 4476 30078\... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
105e3758d5f44e0c1bef1b8e45b47ba2 | Rectangle Puzzle II | You are given a rectangle grid. That grid's size is *n*<=×<=*m*. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (*x*,<=*y*) (0<=≤<=*x*<=≤<=*n*,<=0<=≤<=*y*<=≤<=*m*).
Your task is to find a maximum sub-rectangle on the grid (*x*1,<=*y*1,<=*x*2,<=*y*2... | [
"from fractions import gcd\nn, m, x, y, a, b = map(int, input().split())\nk = gcd(a, b)\na //= k\nb //= k\ntimes = min(n // a, m // b)\na *= times\nb *= times\nx1 = x - (a + 1) // 2\ny1 = y - (b + 1) // 2\nif x1 < 0:\n x1 = 0\nif y1 < 0:\n y1 = 0\nif x1 + a > n:\n x1 -= (x1 + a - n)\nif y1 + b > m:\n y1... | {"inputs": ["9 9 5 5 2 1", "100 100 52 50 46 56", "100 100 16 60 42 75", "100 100 28 22 47 50", "100 100 44 36 96 21", "100 100 56 46 1 47", "100 100 20 53 6 22", "100 100 32 63 2 41", "100 100 48 73 63 16", "100 100 13 59 14 20", "36830763 28058366 30827357 20792295 11047103 20670351", "87453374 60940601 74141787 3214... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
1072a16321aa47d4398947c1354d3c62 | Games on a CD | Several years ago Tolya had *n* computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to *k*. The names didn't overlap.
Thus, there is... | [
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\np = 24738041398529 \r\n\r\ndef process(n, k, S, G):\r\n g = len(G)\r\n matrix = [[0 for j in range(k)] for i in range(g)]\r\n sums = [0 for i in range(k)]\r\n word_dict = {}\r\n for i in range(g):\r\n word = 0\r\n for j in range(k... | {"inputs": ["3 1\nabc\n4\nb\na\nc\nd", "4 2\naabbccdd\n4\ndd\nab\nbc\ncd", "2 2\nkdcj\n4\ncj\nkd\njk\ndc", "10 10\nlgfrjgityzwtmfyygmpsmokiwphewhpoelsvnctwxmpimqvblgrisozncsidqlqzovrzlgvneovgvkjoxvprlqhlgokaooflsiih\n20\ngvkjoxvprl\nihlgfrjgit\nygmpsmokiw\nphewhpoels\nqhlgokaoof\nrzlgvneovg\ngityzwtmfy\nvnctwxmpim\nmqv... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
1085303f1d6a1301030c5bec6cc8f050 | Race | The Old City is a rectangular city represented as an *m*<=×<=*n* grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one block and are either vertical or horizontal. There is a junction on both sid... | [
"def main():\r\n n, m, k = map(int, input().split())\r\n a = [input().strip() for _ in range(n)]\r\n pp = [None] * 26\r\n di = [1, 0, -1, 0]\r\n dj = [0, 1, 0, -1]\r\n\r\n for i in range(n):\r\n for j in range(m):\r\n if 'a' <= a[i][j] <= 'z':\r\n pp[ord(a[i][j]) -... | {"inputs": ["3 10 12\n##########\n#z1a1111b#\n##########\n2 3 ab 2 8", "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababababababab 6 2", "3 10 6\n##########\n#z1a1311b#\n##########\n2 3 ab 2 8", "14 14 187\n##############\n##############\n##############\n##############\n#####a5284b7c#\n#####1####7#7... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
10b1b7f6e837f3a28641aed3a8d8cfd6 | Washer, Dryer, Folder | You have *k* pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has *n*1 washing machines, *n*2 drying machines and *n*3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it ... | [
"k,n1,n2,n3,t1,t2,t3 = map(int, input().split())\r\na = [0] * n1\r\nb = [0] * n2\r\nc = [0] * n3\r\nfor i in range(k):\r\n finish = max(a[i%n1] + t1 + t2 + t3, b[i%n2] + t2 + t3, c[i%n3] + t3)\r\n a[i%n1] = finish - t2 - t3\r\n b[i%n2] = finish - t3\r\n c[i%n3] = finish\r\nprint(finish)",
"\r\nif __na... | {"inputs": ["1 1 1 1 5 5 5", "8 4 3 2 10 5 2", "10000 1000 1000 1000 1000 1000 1000", "8 3 4 3 10 9 4", "5 2 4 5 9 9 6", "4 5 1 2 4 6 2", "11 5 5 1 9 6 8", "1 3 2 2 5 2 8", "2933 578 144 393 710 699 874", "2460 502 99 260 659 409 586", "1444 75 246 287 64 416 2", "4076 135 200 961 469 286 418", "7251 708 347 932 65 292... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
10cc24a3b490499bfd4553c68f068241 | Local Extrema | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | [
"a = int(input())\nlocal = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(1, a - 1):\n if local[i] > local[i - 1] and local[i] > local[i + 1]:\n ans += 1\n if local[i] < local[i - 1] and local[i] < local[i + 1]:\n ans += 1\n\n\n\n\n\n\n\nprint(ans)",
"n = int(input())\r\na = list... | {"inputs": ["3\n1 2 3", "4\n1 5 2 5", "1\n1", "1\n548", "2\n1 1", "3\n3 2 3", "2\n1 1000", "3\n1 2 1"], "outputs": ["0", "2", "0", "0", "0", "1", "0", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 250 | |
1110f42e88d5749b1b194cda75112c7e | Cosmic Tables | The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of mete... | [
"n,m,k=map(int, input().split())\r\n\r\nl1=[]\r\nfirst={}\r\nsecond={}\r\n\r\nfor i in range(0,n):\r\n first[str(i+1)]=i\r\n\r\nfor i in range(0,m):\r\n second[str(i+1)]=i\r\n\r\nfor i in range(0,n):\r\n l1.append(input().split())\r\n\r\nfinal=[]\r\n\r\nfor i in range(0,k):\r\n q, row,col=input().split(... | {"inputs": ["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3", "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2", "2 2 6\n1 2\n3 4\nc 1 2\nr 1 2\ng 1 1\ng 1 2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
1117c37e54f15529eba3946a452af50b | 123-sequence | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a... | [
"n = int(input())\r\ns = input().split()\r\nmax_ = 0\r\nfor el in range(1,4):\r\n if s.count(str(el)) > max_:\r\n max_ = s.count(str(el))\r\nprint(len(s) - max_)",
"from collections import Counter\n\nn, a = int(input()), (int(i) for i in input().split())\ncnt = Counter(a)\nres = min(cnt[1] + cnt[2], cnt... | {"inputs": ["9\n1 3 2 2 2 1 1 2 3", "6\n3 3 2 2 1 3", "12\n3 1 3 1 2 1 3 2 2 1 2 1", "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "2\n2 1", "2\n3 2", "2\n3 1", "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2", "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1", "1\n1", "1\n2", "1\n3"], "outputs": ["5", "3", "7", "10", ... | UNKNOWN | PYTHON3 | CODEFORCES | 327 | |
11378dd44866f43b807db4d6e54786f9 | Game | Allen and Bessie are playing a simple number game. They both know a function $f: \{0, 1\}^n \to \mathbb{R}$, i. e. the function takes $n$ binary arguments and returns a real value. At the start of the game, the variables $x_1, x_2, \dots, x_n$ are all set to $-1$. Each round, with equal probability, one of Allen or Bes... | [
"n, r = [int(x) for x in input().split()]\r\n\r\nn = 2 ** n\r\n\r\nxs = [int(x) for x in input().split()]\r\n\r\ns = sum(xs)\r\n\r\nres = [0 for _ in range(r+1)]\r\nfor i in range(r):\r\n res[i] = s / n\r\n i, val = [int(x) for x in input().split()]\r\n s += val - xs[i]\r\n xs[i] = val\r\nres[r] = s / n... | {"inputs": ["2 2\n0 1 2 3\n2 5\n0 4", "1 0\n2 3", "2 0\n1 1 1 1"], "outputs": ["1.500000\n2.250000\n3.250000", "2.500000", "1.000000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
113eb2e2363de9dd2354a2f80ef3e77c | The Great Julya Calendar | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | [
"n=int(input())\r\nl=list(str(n))\r\nn=int(n)\r\nc=0\r\nwhile n!=0:\r\n m=max(list(str(n)))\r\n n-=int(m)\r\n c+=1\r\n\r\nprint(c)",
"import sys\r\n\r\n#rrange = lambda mi, ma: range(ma-1, mi-1, -1)\r\n\r\ndp = {}\r\n\r\ndef one_step(n):\r\n val = max(int(c) for c in str(n))\r\n return n - val\r\n\... | {"inputs": ["24", "0", "3", "8", "9", "10", "31", "701", "222", "156", "12343", "7984", "1000000", "1", "3", "5", "11", "77", "216", "1468", "1995", "11010", "47320", "258634"], "outputs": ["5", "0", "1", "1", "1", "2", "6", "116", "39", "28", "1778", "1178", "128207", "1", "1", "1", "3", "14", "37", "233", "305", "156... | UNKNOWN | PYTHON3 | CODEFORCES | 236 | |
113ec2417613db6fa12611d3704da165 | Anton and currency you all know | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | [
"import math\r\nimport copy\r\nimport itertools\r\nimport bisect\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef ilst():\r\n return list(map(int,input().split()))\r\n \r\ndef islst():\r\n return list(map(str,input().split()))\r\n \r\ndef inum():\r\n return map(int,input().split())\r\n \... | {"inputs": ["527", "4573", "1357997531", "444443", "22227", "24683", "11", "1435678543", "4250769", "4052769", "5685341", "1111111111111111231", "333333332379", "85", "7700016673", "35451519805848712272404365322858764249299938505103", "431475227769199162773068613469229242215575346594802589770170386244583704592998475909... | UNKNOWN | PYTHON3 | CODEFORCES | 83 | |
1151407dedf0eca70322463ffde4a040 | Arpa and an exam about geometry | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ... | [
"def main():\n\tax, ay, bx, by, cx, cy = [int(i) for i in input().split()]\n\tif ax*by + bx*cy + cx*ay - bx*ay - cx*by - ax*cy == 0:\n\t\tprint(\"No\")\n\telif (bx - ax)**2 + (by - ay)**2 == (cx - bx)**2 + (cy - by)**2:\n\t\tprint(\"Yes\")\n\telse:\n\t\tprint(\"No\")\n\n\nmain()\n\n# 1508530390696\n",
"def vector... | {"inputs": ["0 1 1 1 1 0", "1 1 0 0 1000 1000", "1 0 2 0 3 0", "3 4 0 0 4 3", "-1000000000 1 0 0 1000000000 1", "49152 0 0 0 0 81920", "1 -1 4 4 2 -3", "-2 -2 1 4 -2 0", "5 0 4 -2 0 1", "-4 -3 2 -1 -3 4", "-3 -3 5 2 3 -1", "-1000000000 -1000000000 0 0 1000000000 999999999", "-1000000000 -1000000000 0 0 1000000000 10000... | UNKNOWN | PYTHON3 | CODEFORCES | 84 | |
115825905aae4a75d5ae8efd5fd5deda | Network Topology | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | [
"n, m = map(int, input().split())\r\nd = [0]*(n+1)\r\n\r\nfor i in range(m):\r\n x, y = map(int, input().split())\r\n d[x] += 1\r\n d[y] += 1\r\n\r\nif d.count(1) == 2 and d.count(2) == n-2:\r\n print(\"bus topology\")\r\nelif d.count(2) == n:\r\n print(\"ring topology\")\r\nelif d.count(1) == n-1 an... | {"inputs": ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n2 3\n3 1\n1 4", "5 4\n1 2\n3 5\n1 4\n5 4", "5 5\n3 4\n5 2\n2 1\n5 4\n3 1", "5 4\n4 2\n5 2\n1 2\n2 3", "5 9\n5 3\n4 5\n3 1\n3 2\n2 1\n2 5\n1 5\n1 4\n4 2", "4 3\n2 4\n1 3\n4 1", "4 4\n2 4\n4 1\n1 3\n2 3", "4 3\n1 2\n2 4\n3 2", "... | UNKNOWN | PYTHON3 | CODEFORCES | 131 | |
1161687473cc8d5e3083ca002aaaffda | Array Queries | *a* is an array of *n* positive integers, all of which are not greater than *n*.
You have to process *q* queries to this array. Each query is represented by two numbers *p* and *k*. Several operations are performed in each query; each operation changes *p* to *p*<=+<=*a**p*<=+<=*k*. There operations are applied until ... | [
"from heapq import heappush, heappop, heapify\r\nfrom collections import defaultdict, Counter, deque\r\nfrom functools import lru_cache\r\nimport threading\r\nimport sys\r\nimport bisect\r\ninput = sys.stdin.readline\r\ndef ri(): return int(input())\r\ndef rs(): return input()\r\ndef rl(): return list(map(int, inpu... | {"inputs": ["3\n1 1 1\n3\n1 1\n2 1\n3 1", "10\n3 5 4 3 7 10 6 7 2 3\n10\n4 5\n2 10\n4 6\n9 9\n9 2\n5 1\n6 4\n1 1\n5 6\n6 4", "50\n6 2 5 6 10 2 5 8 9 2 9 5 10 4 3 6 10 6 1 1 3 7 2 1 7 8 5 9 6 2 7 6 1 7 2 10 10 2 4 2 8 4 3 10 7 1 7 8 6 3\n50\n23 8\n12 8\n3 3\n46 3\n21 6\n7 4\n26 4\n12 1\n25 4\n18 7\n29 8\n27 5\n47 1\n50 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
116948838e1fa56269475f9485f3b01d | Shake It! | A never-ending, fast-changing and dream-like world unfolds, as the secret door opens.
A world is an unordered graph *G*, in whose vertex set *V*(*G*) there are two special vertices *s*(*G*) and *t*(*G*). An initial world has vertex set {*s*(*G*),<=*t*(*G*)} and an edge between them.
A total of *n* changes took place ... | [
"mod = int(1e9 + 7)\r\nn, m = map(int, input().split())\r\nf = [ [0 for i in range(60)] for j in range(60) ]\r\ng = [ [0 for i in range(60)] for j in range(60) ]\r\ns = [ [0 for i in range(60)] for j in range(60) ]\r\ninv = [ 1 ]\r\nf[0][0] = s[0][0] = 1\r\n\r\ndef pow(x, exp) :\r\n res = 1\r\n for i in range... | {"inputs": ["3 2", "4 4", "7 3", "31 8", "1 1", "10 2", "33 22", "50 50", "1 2", "1 3", "2 1", "2 2", "2 3", "3 1", "3 3", "3 4", "4 1", "4 2", "4 3", "4 5", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "6 7", "7 1", "7 2", "7 4", "7 5", "7 6", "7 7", "7 8", "8 5", "9 2", "10 4", ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
11baceb65703f5fa83aa13b9e1e98724 | Free Ice Cream | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | [
"def solve(test):\r\n ans = 0\r\n n, x = map(int, input().split())\r\n for i in range(n):\r\n c = input().split()\r\n if c[0] == '+':\r\n x += int(c[1])\r\n elif int(c[1]) > x:\r\n ans += 1\r\n else:\r\n x -= int(c[1])\r\n print(x, ans)\r\nt =... | {"inputs": ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "1 0\n- 526... | UNKNOWN | PYTHON3 | CODEFORCES | 1,058 | |
11bd126ec7b33ec1ee8b4f3a44b88d55 | Devu and Flowers | Devu wants to decorate his garden with flowers. He has purchased *n* boxes, where the *i*-th box contains *f**i* flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same color.
Now Devu wants to select exactly *s* flowers from the boxes ... | [
"from sys import exit\r\nM=10**9+7\r\nn,s=[int(e) for e in input().split()]\r\na=sorted(int(e) for e in input().split() if e!=\"0\")\r\nn=len(a)\r\nif s==0:\r\n print(1)\r\n exit()\r\nif len(a)==0:\r\n print(0)\r\n exit()\r\nR=20\r\nFact=[1]*(R+1)\r\nfor i in range(2, R+1):\r\n Fact[i]=(Fact[i-1]*i)%... | {"inputs": ["2 3\n1 3", "2 4\n2 2", "3 5\n1 3 2", "2 270030023747\n891135146290 437305641972", "20 4385085334307\n273634411136 208521328637 450482376435 844118010709 197241285878 472126475472 2414038897 672334205413 809269727018 409013884362 739986692075 953956651947 462216461906 388007176838 245504550965 527140291750 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
11bfc921b8411694b749730a04000c16 | Game | Vasya and Petya have invented a new game. Vasya takes a stripe consisting of 1<=×<=*n* square and paints the squares black and white. After that Petya can start moves — during a move he may choose any two neighboring squares of one color and repaint these two squares any way he wants, perhaps in different colors. Petya... | [
"n=int(input())\r\n\r\ndef hamming(a,b):\r\n\tglobal n\r\n\tret=0\r\n\tfor i in range(n):\r\n\t\tret+=int(a[i]!=b[i])\r\n\treturn ret\r\n\r\ns=input()\r\na=['0' if q%2==0 else '1' for q in range(n)]\r\nb=['0' if q%2==1 else '1' for q in range(n)]\r\nprint(min(hamming(s,a),hamming(s,b)))",
"import sys\r\ninput = s... | {"inputs": ["6\n111010", "5\n10001", "7\n1100010", "5\n00100", "3\n101", "6\n111111", "6\n000000", "10\n1000101001", "100\n1001001000011010001101000011100101101110101001110110010001110011011100111000010010011011101000011101", "100\n0000000000100000000000000000000000000000000000000000000000000000000000000000000000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 31 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.