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
a27015427e5cc08931f5d8475ff1b770
Borze
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. The first line contains a number in ...
[ "p=0\r\nc=''\r\ns=input()\r\nfor i in range(len(s)):\r\n if p==0:\r\n if s[i]=='.':\r\n c+='0'\r\n elif s[i+1]=='.':\r\n c+='1'\r\n p=1\r\n else:\r\n c+='2'\r\n p=1\r\n else:\r\n p=0\r\nprint(c)", "n=input()\r\nindx = 0 \r\nw...
{"inputs": [".-.--", "--.", "-..-.--", "---..", "..--.---..", "-.....----.", ".", "-.", "--", "..", "--.", ".--.", ".-.-..", "----.-.", "-..--.-.", "..--..--.", "-.-.---.--..-..-.-.-..-..-.--.", "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-......
UNKNOWN
PYTHON3
CODEFORCES
1,391
a286165c7516c35e6956e6d47b0b42dd
A and B and Team Training
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
[ "from collections import deque,Counter\nfrom math import *\nimport sys\nimport random\nfrom bisect import *\nfrom functools import reduce\nfrom sys import stdin\nfrom heapq import *\nimport copy\ninput = lambda: sys.stdin.readline().rstrip()\n\na,b = map(int,input().split())\nans = 0\nwhile a>=1 or b>=1:\n if a<...
{"inputs": ["2 6", "4 5", "1 1", "3 3", "500000 500000", "70 100", "5 12525", "10 5", "5 10", "0 0", "0 1", "1 0", "0 21233", "12523 0", "1231 1253", "500000 0", "1 500000", "250000 500000", "500000 250000", "33333 77777", "30900 174529", "89979 57154", "231646 398487", "332019 281112", "473686 122443", "481245 86879",...
UNKNOWN
PYTHON3
CODEFORCES
84
a2b399b76ffe355dbbff668c36b53694
Restoring Painting
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*,...
[ "#!/usr/bin/env python3\n\n(n, a, b, c, d) = input().split()\nn = int(n)\na = int(a)\nb = int(b)\nc = int(c)\nd = int(d)\n\ndiff2 = b - c\ndiff4 = a - d\ndiff5 = a + b - c - d\n(lower, _, upper) = sorted((diff2, diff4, diff5))\n\nlower_bound = 1 - min(0, lower)\nupper_bound = n - max(0, upper)\n\nif lower_bound > u...
{"inputs": ["2 1 1 1 2", "3 3 1 2 3", "1 1 1 1 1", "1000 522 575 426 445", "99000 52853 14347 64237 88869", "100000 2 2 2 2", "2 1 1 2 2", "10 9 10 8 10", "100 19 16 35 83", "1000 102 583 606 929", "10000 1816 3333 6908 7766", "100000 80015 84290 50777 30497", "100000 64022 49026 55956 88430", "100000 10263 46628 10268...
UNKNOWN
PYTHON3
CODEFORCES
80
a2ba0f879682d8449601222a60c2fade
Chip 'n Dale Rescue Rangers
A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at poi...
[ "def f(T):\r\n t1 = min(t, T)\r\n t2 = max(T - t, 0)\r\n u = [v[0] * t1 + w[0] * t2, v[1] * t1 + w[1] * t2]\r\n C = [A[0] + u[0], A[1] + u[1]]\r\n dist = ((C[0] - B[0]) ** 2 + (C[1] - B[1]) ** 2) ** 0.5\r\n dist2 = Vmax * T\r\n return dist2 >= dist\r\n\r\nread = lambda: map(int, input().split()...
{"inputs": ["0 0 5 5\n3 2\n-1 -1\n-1 0", "0 0 0 1000\n100 1000\n-50 0\n50 0", "0 0 0 1000\n100 5\n0 -50\n0 50", "0 1000 0 0\n50 10\n-49 0\n49 0", "0 1000 0 0\n50 10\n0 -48\n0 -49", "0 0 0 -5000\n100 20\n-50 0\n50 0", "0 0 0 -350\n55 5\n0 -50\n0 50", "0 -1000 0 0\n11 10\n-10 0\n10 0", "0 -1000 0 0\n22 10\n0 -12\n0 -10",...
UNKNOWN
PYTHON3
CODEFORCES
8
a2bc2f7521976470d00bfaf50316f27e
none
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called inter...
[ "def main():\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n dpl = [1] * n\r\n dpr = [1] * n\r\n for i in range(1, n):\r\n dpl[i] = min(dpl[i - 1] + 1, a[i])\r\n for i in range(n - 2, -1, -1):\r\n dpr[i] = min(dpr[i + 1] + 1, a[i])\r\n ans = 0\r\n for i in ra...
{"inputs": ["6\n2 1 4 6 2 2", "7\n3 3 3 1 3 3 3", "7\n5128 5672 5805 5452 5882 5567 5032", "10\n1 2 2 3 5 5 5 4 2 1", "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20", "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4", "1\n1", "1\n1000000000", "2\n1 1", "2\n1049 109...
UNKNOWN
PYTHON3
CODEFORCES
35
a2bf2a16b17237429b68c7603aca7dd8
Counting Arrays
You are given two positive integer numbers *x* and *y*. An array *F* is called an *y*-factorization of *x* iff the following conditions are met: - There are *y* elements in *F*, and all of them are integer numbers; - . You have to count the number of pairwise distinct arrays that are *y*-factorizations of *x*. Two ...
[ "from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\ndef fast_prime_factorization(n):\r\n d = [(i + 1) % 2 * 2 for i in range(n + 1)]\r\n d[0], d[1] = 0, 1\r\n for i in range(3, n + 1):\r\n if d[i]:\r\n continue\r\n for j in range(i, n + 1, 2 * i)...
{"inputs": ["2\n6 3\n4 2", "1\n524288 1000000", "1\n65536 1000000", "1\n5612 11399"], "outputs": ["36\n6", "645043186", "928522471", "215664246"]}
UNKNOWN
PYTHON3
CODEFORCES
3
a31657a96754322c131cf30c5d872c0f
Vika and Segments
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew *n* black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neigh...
[ "# i'm from jasnah, do not ban me\r\nfrom sys import stdin\r\nfrom itertools import repeat\r\nfrom collections import defaultdict\r\n\r\nnum_rectangles = int(stdin.readline())\r\nhorizontal_segments = defaultdict(list)\r\nvertical_segments = defaultdict(list)\r\nunique_y_values = set()\r\nevents = defaultdict(list)...
{"inputs": ["3\n0 1 2 1\n1 4 1 2\n0 3 2 3", "4\n-2 -1 2 -1\n2 1 -2 1\n-1 -2 -1 2\n1 2 1 -2", "1\n1 1 1 1", "10\n-357884841 -999999905 -357884841 999999943\n-130177221 999999983 -130177221 -999999974\n627454332 999999936 627454332 -999999900\n999999986 366591992 -999999919 366591992\n488824292 999999952 488824292 -99999...
UNKNOWN
PYTHON3
CODEFORCES
1
a3281c31c3b5224aa9892ad964cb7901
Choosing Symbol Pairs
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that 1. 1<=≤<=*i*,<=*j*<=≤<=*N* 2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. The single input line contains *S*, consisting of lowercase Lat...
[ "a=input()\nb={}\nc=0\nfor i in a:\n b[i]=b.get(i,0)+1\nfor f in b.values():\n c+=f**2\nprint(c)", "s= input()\r\ns1 = list(set(s))\r\nd={}\r\nfor i in s1:\r\n d[i]=s.count(i)\r\nans=0\r\nfor i in s1:\r\n ans += d[i]**2\r\nprint(ans)\r\n", "a={}\ns=input()\nfor c in s:\n a[c]=a.get(c,0)+1\nans=0\...
{"inputs": ["great10", "aaaaaaaaaa", "great10", "aaaaaaaaaa", "aabb", "w", "129a", "233444", "abacaba", "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321", "zazaeeeeeeeq34443333444tttttt", "00000000000000000000000", "999000888775646453342311"], "outputs": ["7"...
UNKNOWN
PYTHON3
CODEFORCES
93
a36e01a2e880a8e0b0d446d29f8160bf
Bertown roads
Bertown has *n* junctions and *m* bidirectional roads. We know that one can get from any junction to any other one by the existing roads. As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them the government decided to make the traffic one-directional on all the ro...
[ "input = __import__('sys').stdin.readline\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nadj = [[] for _ in range(n)]\r\nfor _ in range(m):\r\n u, v = map(lambda x: int(x)-1, input().split())\r\n adj[u].append(v)\r\n adj[v].append(u)\r\n\r\n\r\nDFS_IN = 0\r\nDFS_OUT = 1\r\n\r\nspan_edges = []\r\nback_e...
{"inputs": ["6 8\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n3 5", "6 7\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4", "10 19\n6 8\n5 8\n8 3\n1 9\n3 6\n4 8\n10 8\n8 7\n5 3\n10 1\n5 10\n4 10\n2 1\n3 2\n7 6\n8 2\n1 6\n10 7\n2 10", "5 9\n5 4\n2 1\n3 4\n4 1\n5 2\n2 3\n4 2\n3 1\n5 1", "6 9\n4 1\n3 4\n5 6\n3 1\n4 2\n1 5\n6 1\n6 4\n5 4", "5 10...
UNKNOWN
PYTHON3
CODEFORCES
2
a375bb8bb85b5bb04c9e51f73ff57e19
Nearest vectors
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ...
[ "from math import atan2\r\n\r\ninner = lambda a, b: a[0] * b[0] + a[1] * b[1]\r\nouter = lambda a, b: a[0] * b[1] - a[1] * b[0]\r\n\r\nN = int(input())\r\nvectors = []\r\nfor i in range(N):\r\n x, y = map(int, input().split())\r\n vectors.append((atan2(y, x), (x, y), i + 1))\r\nvectors.sort()\r\n\r\ndiff = []...
{"inputs": ["4\n-1 0\n0 -1\n1 0\n1 1", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6", "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7", "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2", "2\n351 -4175\n-328 -657", "3\n620 -1189\n8101...
UNKNOWN
PYTHON3
CODEFORCES
6
a39d1af7355f30882262bbdc3bc1142b
Duff in Love
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
[ "import sys;import copy;\r\nimport math;\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\n \r\n#t = int(input());\r\nt=1;\r\nfor test in range(t):\r\n ...
{"inputs": ["10", "12", "1", "2", "4", "8", "3", "31", "97", "1000000000000", "15", "894", "271", "2457", "2829", "5000", "20", "68", "3096", "1024", "1048576", "413933789280", "817634153013", "56517269141", "30707328551", "279564127218", "491159577042", "734337660466", "808453785117", "55926835837", "294809951965", "5...
UNKNOWN
PYTHON3
CODEFORCES
149
a3a5585a3d9731038d11e4b6fdfc84f4
Soroban
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about ...
[ "n = input()\r\nl = [\"O-|-OOOO\" , \"O-|O-OOO\" ,\"O-|OO-OO\" ,\"O-|OOO-O\",\"O-|OOOO-\", \"-O|-OOOO\",\"-O|O-OOO\",\"-O|OO-OO\",\"-O|OOO-O\",\"-O|OOOO-\" ]\r\nfor i in n[::-1] : \r\n print(l[int(i)])", "# https://codeforces.com/problemset/problem/363/A\r\n\r\nn = input()\r\nfor i in range(len(n)-1,-1,-1):\r\...
{"inputs": ["2", "13", "720", "0", "1", "3", "4", "5", "6", "637", "7", "8", "9", "10", "11", "100", "99", "245", "118", "429", "555", "660", "331", "987", "123456789", "234567890", "100000000", "111111111", "90909090", "987654321", "45165125", "445511006", "999999999", "984218523", "19", "10000000"], "outputs": ["O-|O...
UNKNOWN
PYTHON3
CODEFORCES
27
a3e71338c9156c7480a89573f5f6404e
Prison Transfer
The prison of your city has *n* prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer *c* of the prisoners to a prison located in another city. For this reason, he made the *n* prisoners to stand in a line, with a number written on their chests. The number is the severity of th...
[ "import sys\r\n\r\nn, t, c = map(int, input().split())\r\nvec = [-1]\r\n\r\nfor i, temp in enumerate(map(int, sys.stdin.readline().split())):\r\n if temp > t:\r\n vec.append(i)\r\n\r\nvec.append(n)\r\nans = 0\r\n\r\nfor i in range(1, len(vec)):\r\n diff = vec[i] - vec[i - 1] - 1\r\n ans += max(diff ...
{"inputs": ["4 3 3\n2 3 1 1", "1 1 1\n2", "11 4 2\n2 2 0 7 3 2 2 4 9 1 4", "57 2 10\n7 5 2 7 4 1 0 5 2 9 2 9 8 6 6 5 9 6 8 1 0 1 0 3 2 6 5 2 8 8 8 8 0 9 4 3 6 6 2 4 5 1 2 0 1 7 1 1 5 4 5 0 7 5 1 9 6", "2 228885628 1\n90897004 258427916", "3 1 1\n1 2 1", "3 3 3\n3 2 3", "4 2 2\n1 3 3 2", "1 228 1\n1"], "outputs": ["2", ...
UNKNOWN
PYTHON3
CODEFORCES
33
a3f1a98e1d913a9a756aac7c1010239d
Matching Names
Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching ps...
[ "import sys\r\n\r\nclass Node:\r\n def __init__(self, d):\r\n global nodes\r\n self.ch = {}\r\n self.a = [[], []]\r\n self.d = d\r\n nodes += [self]\r\n\r\nnodes = []\r\npairs = []\r\nres = 0\r\n\r\nN = int(sys.stdin.readline())\r\n_input = sys.stdin.readlines()\r\n_input = [s[...
{"inputs": ["5\ngennady\ngalya\nboris\nbill\ntoshik\nbilbo\ntorin\ngendalf\nsmaug\ngaladriel", "1\na\na", "2\na\na\na\na", "2\na\nb\na\na", "2\nb\nb\na\na", "2\na\nb\na\nb", "10\nbaa\na\nba\naabab\naa\nbaab\nbb\nabbbb\na\na\na\nba\nba\nbaabbb\nba\na\naabb\nbaa\nab\nb", "10\nabaabbaaa\nacccccaacabc\nacbaabaaabbca\naaccc...
UNKNOWN
PYTHON3
CODEFORCES
1
a3f7d08d933ed661efd4b6e37e7599db
Minimum Difficulty
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,...
[ "n= int(input())\r\ns= [int(x) for x in input().split()]\r\na=[]\r\nb=[]\r\nfor i in range(0,len(s)-2):\r\n a.append(s[i+2]-s[i])\r\nm = a.index((min(a)))\r\ns.pop(m+1)\r\nfor i in range(len(s)-1):\r\n b.append(s[i+1]-s[i])\r\nprint(max(b))", "n, nums = int(input()), list(map(int, input().split()))\r\n\r\nm...
{"inputs": ["3\n1 4 6", "5\n1 2 3 4 5", "5\n1 2 3 7 8", "3\n1 500 1000", "10\n1 2 3 4 5 6 7 8 9 10", "10\n1 4 9 16 25 36 49 64 81 100", "10\n300 315 325 338 350 365 379 391 404 416", "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112", "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84...
UNKNOWN
PYTHON3
CODEFORCES
416
a402223ac225543c57f2056a5c75f84a
After Training
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly...
[ "#----------------------------\n# Matheus de Souza Oliveira |\n# RA: 203407 |\n#----------------------------\n\nn, m = list(map(int, input().split()))\n\nfor index in range(0, n):\n\n factor = m+index%m\n isFactorEven = not(bool(factor%2))\n\n if isFactorEven:\n result = int((m-(index...
{"inputs": ["4 3", "3 1", "10 3", "6 5", "2 6", "5 2", "85702 100000", "9 2", "45 88", "61 51", "21 57", "677 787", "37 849", "453 855", "165 374", "328 3", "8 80", "90 544", "85 60", "392 5", "8 87", "6 358", "501 70", "3834 1", "1 8828", "69230 89906", "27646 59913", "37006 54783", "1 100000", "100000 1", "100000 100...
UNKNOWN
PYTHON3
CODEFORCES
67
a4657b14d49366265fcbca7ce5474e37
Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number *n*, modulo *m*. Number *x* is considered close to number...
[ "n, mm = input().split(' ')\r\nm = int(mm)\r\ndp = [[0]*m for x in range((1<<len(n)))]\r\ndp[0][0]=1\r\nfor mask in range(1<<len(n)):\r\n for j in range(len(n)):\r\n if mask==0 and n[j]=='0': \r\n continue\r\n if(mask&(1<<j)):\r\n continue\r\n t = int(n[j])\r\n ...
{"inputs": ["104 2", "223 4", "7067678 8", "202 10", "1306432 9", "9653092 9", "600038 6", "4064044 4", "5899025 7", "2496234323687 2", "1 1", "123456789123456789 2", "123 1", "6328128 6", "8966261 5", "8900064 4", "576021249 86", "682459775 6", "458498549 4", "511736928 87", "275126649 81", "576279776452 33", "4504977...
UNKNOWN
PYTHON3
CODEFORCES
1
a475ab27993339a77c13dc5ef2a69e3c
Diverse Team
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"...
[ "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ns=set()\r\nfor i in range(len(l)):\r\n s.add(l[i])\r\nl1=[i for i in s]\r\nl2=[]\r\nif len(s)>=k:\r\n print(\"YES\")\r\n for i in range(k):\r\n if(l1[i] in l):\r\n l2.append(l.index(l1[i])+1)\r\n l2.sort()\r\n for ...
{"inputs": ["5 3\n15 13 15 15 12", "5 4\n15 13 15 15 12", "4 4\n20 10 40 30", "1 1\n1", "100 53\n16 17 1 2 27 5 9 9 53 24 17 33 35 24 20 48 56 73 12 14 39 55 58 13 59 73 29 26 40 33 22 29 34 22 55 38 63 66 36 13 60 42 10 15 21 9 11 5 23 37 79 47 26 3 79 53 44 8 71 75 42 11 34 39 79 33 10 26 23 23 17 14 54 41 60 31 83 5...
UNKNOWN
PYTHON3
CODEFORCES
184
a499959a0803fa0a29622b615c527e5b
Time to Raid Cowavans
As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space. Sometimes cows gather into cowavans. This seems to be seasonal. But at this time the cows become passive and ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nw = [0] + list(map(int, input().split()))\r\np = int(input())\r\nx, s = [], [0] * (n + 3)\r\nfor i in range(p):\r\n a, b = map(int, input().split())\r\n s[b + 2] += 1\r\n x.append(b)\r\n x.appe...
{"inputs": ["3\n1 2 3\n2\n1 1\n1 2", "4\n2 3 5 7\n3\n1 3\n2 3\n2 2", "5\n3 2 4 5 6\n8\n4 2\n3 1\n3 5\n3 4\n3 5\n5 5\n4 4\n5 3", "10\n10 10 7 10 2 8 9 6 4 9\n10\n10 9\n3 5\n4 3\n6 5\n3 10\n6 1\n6 3\n5 8\n2 6\n2 6", "15\n63 32 13 12 2 97 24 25 74 2 6 35 79 87 62\n15\n4 5\n4 4\n5 3\n4 3\n3 4\n4 5\n4 3\n5 4\n5 3\n5 5\n5 5\...
UNKNOWN
PYTHON3
CODEFORCES
1
a4b4af73658934c4778c19bf9970322b
Lecture
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
[ "a,b = (map(int,input().split()))\r\ndic = {}\r\nfor i in range(b):\r\n a = input().split(' ')\r\n if(len(a[0])>len(a[1])):\r\n dic[a[0]] = a[1]\r\n dic[a[1]] = a[1]\r\n else:\r\n dic[a[0]] = a[0]\r\n dic[a[1]] = a[0]\r\nt = input().split()\r\nfor i in range(len(t)):\r\n prin...
{"inputs": ["4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "10 22\nazbrll oen\ngh vdyayei\njphve...
UNKNOWN
PYTHON3
CODEFORCES
842
a4bd2375265606dcb3fc9755ddcf11e7
Wonder Room
The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a *a*<=×<=*b* square meter wonder room. The caretaker wants to accommodate exactly *n* students there. But the law says that there must be at least 6 square meters per student in a room (...
[ "import sys\r\n#import threading\r\n#sys.setrecursionlimit(10**8)\r\n#threading.stack_size(10**8)\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = ...
{"inputs": ["3 3 5", "2 4 4", "1 1 1", "1 1000000000 1000000000", "8 7 5", "1000000000 1 1", "1000000000 1000000000 1000000000", "800000003 7 7", "11 7 7", "1000000000 1 1", "100000 100 1000", "1000000000 6000 1000000", "1 1000000000 1000000000", "980000000 2 100000", "13 7 6", "16 19 5", "258180623 16000 16000", "9999...
UNKNOWN
PYTHON3
CODEFORCES
3
a4c73b1bebe0b753f5fd0adb2bd62c52
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence *p*1,<=*p*2,<=...,<=*p**n* for his birthday. Jeff hates inversions in sequences. An inversion in sequence *a*1,<=*a*2,<=...,<=*a**n* is a pair of indexes *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\ndef process(A):\r\n n = len(A)\r\n S = [1 for i in range(n)]\r\n d = {}\r\n for i in range(n):\r\n ai = abs(A[i])\r\n if ai not in d:\r\n d[ai] = []\r\n d[ai].append(i)\r\n L = sorted(d)\r\n answer = 0\r\n w...
{"inputs": ["2\n2 1", "9\n-2 0 -1 0 -1 2 1 0 -1", "9\n0 0 1 1 0 0 1 0 1", "8\n0 1 2 -1 -2 1 -2 2", "24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2", "1\n0", "31\n-2 2 -2 -1 0 0 1 2 1 1 -1 -2 1 -1 -2 2 0 1 -1 -2 -1 -2 -1 2 2 2 2 1 1 0 1", "9\n1 -1 -1 0 -1 0 1 1 1", "5\n1 0 1 -2 1", "31\n-5 -5 5 3 -1 3 1 -...
UNKNOWN
PYTHON3
CODEFORCES
1
a4cc49fca72a78529802e27c6dbba97f
Bracket Sequences Concatenation Problem
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
[ "n = int(input())\r\npos=[0]*(3*100001)\r\nneg=[0]*(3*100001)\r\nfor i in range(n):\r\n a=list(input())\r\n c1=c2=0\r\n th=1\r\n b1=b2=0\r\n for j in a:\r\n if j=='(':\r\n c1+=1\r\n else:\r\n c1-=1 \r\n if c1<0:\r\n b1=1\r\n break ...
{"inputs": ["3\n)\n()\n(", "2\n()\n()", "7\n()(\n)\n)(\n())\n(((\n()()()\n()", "6\n(\n((\n(((\n))))\n)))))\n))))))", "9\n(()\n((())\n(\n)\n(()()(()())))\n)\n)(()(\n)())(\n)()(", "2\n(((((((((()\n)))))))))", "1\n)(", "1\n()", "2\n(((\n)))", "10\n()()(\n)((\n)()(((()(\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(", ...
UNKNOWN
PYTHON3
CODEFORCES
44
a4d1149733c96e064b611faa2a965482
Useful Decomposition
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
[ "n = int(input())\norders = [0 for i in range(n)]\nfor i in range(n-1):\n a, b = [int(j) -1 for j in input().split()]\n orders[a] += 1\n orders[b] += 1\n\nroots = []\nleafs = []\n\nfor i, x in enumerate(orders):\n if x > 2:\n roots.append(i)\n elif x == 2:\n pass\n elif x == 1:\n ...
{"inputs": ["4\n1 2\n2 3\n3 4", "6\n1 2\n2 3\n3 4\n2 5\n3 6", "5\n1 2\n1 3\n1 4\n1 5", "2\n1 2", "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8", "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9", "3\n2 3\n1 2"], "outputs": ["Yes\n1\n1 4", "No", "Yes\n4\n1 2\n1 3\n1 4\n1 5", "Yes\n1\n1 2", "No", "No", "Yes\n1\n1 3"]}
UNKNOWN
PYTHON3
CODEFORCES
21
a4f83e70290499e2174902d149702f3e
Keyboard
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m...
[ "import sys\r\nfrom array import array # noqa: F401\r\nfrom math import hypot\r\nfrom collections import defaultdict\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, m, x = map(int, input().split())\r\nkeyboard = [input().rstrip() for _ in range(n)]\r\nkeys = set()\r\...
{"inputs": ["2 2 1\nab\ncd\n1\nA", "2 2 1\nab\ncd\n1\ne", "2 2 1\nab\ncS\n5\nabcBA", "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG", "10 9 3\noboxlgpey\nyxcuwkkmp\njuqeflhwq\nsfnxqtjqS\nkkudcnyjl\nhgjlcrkjq\njnofqksxn\nqbhsnuguv\nlvahnifao\nebwnnlrwe\n35\nCodeforcesBetaRoundproblemAte...
UNKNOWN
PYTHON3
CODEFORCES
32
a51153791f483833a64b7568e351adfb
Mishka and Contest
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ...
[ "n,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nl=0\r\nr=n-1\r\nprob=0\r\nwhile(l<=r):\r\n if((arr[l]==arr[r]) and (arr[l]<=k)):\r\n l+=1\r\n prob+=1\r\n elif((arr[l]>arr[r]) and (arr[r]<=k)):\r\n r-=1\r\n prob+=1\r\n elif((arr[l]<arr[r]) and (arr[l]<=k)):...
{"inputs": ["8 4\n4 2 3 1 5 1 6 4", "5 2\n3 1 2 1 3", "5 100\n12 34 55 43 21", "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71...
UNKNOWN
PYTHON3
CODEFORCES
265
a54faeb0d9470c4cfd362bc7fddfe085
Coloring Brackets
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain ...
[ "Mod = 10 ** 9 + 7\r\ns = input()\r\nn = len(s)\r\nfrom types import GeneratorType\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n ...
{"inputs": ["(())", "(()())", "()", "((()))", "()(())", "()()()", "(())(())", "()()()()()()()()()()()(())", "()(())()((()))", "()()(())()(())", "()()()()()()()()()()()()()()()()", "(()()())", "()(()())()", "(())()(())()", "()()(()())(())()()()", "()()()((((())))())()()()()()((()))()()(())()(((())))()(()())((())())((()(...
UNKNOWN
PYTHON3
CODEFORCES
5
a59b13d5653d4598ad0c3212f76b67ab
Mashmokh and ACM
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
[ "n,k=map(int,input().split())\ndp=[]\nmod=pow(10,9)+7\nfor i in range(n):\n\tt=[0]*k\n\tdp.append(t)\nfor i in range(n):\n\tdp[i][0]=1\nfor i in range(k-1):\n\tfor j in range(n):\n\t\tfor l in range(j,n,j+1):\n\t\t\tdp[l][i+1]=(dp[l][i+1]+dp[j][i])%mod\nans=0\nfor i in range(n):\n\tans=(ans+dp[i][k-1])%mod\nprint(a...
{"inputs": ["3 2", "6 4", "2 1", "1478 194", "1415 562", "1266 844", "680 1091", "1229 1315", "1766 1038", "1000 1", "2000 100", "1 1", "2000 1000", "1928 1504", "2000 2000", "29 99", "56 48", "209 370", "83 37", "49 110", "217 3", "162 161", "273 871", "43 1640", "1472 854", "1639 1056", "359 896", "1544 648", "436 13...
UNKNOWN
PYTHON3
CODEFORCES
79
a5a3bb978243d6aaa482cd809f293382
Ilya and Sticks
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way tha...
[ "def main():\r\n n = int(input())\r\n l = [int(i) for i in input().split()]\r\n l.sort()\r\n l.reverse()\r\n candidate = []\r\n i = 1\r\n while (i < n):\r\n if (l[i - 1] - l[i] <= 1):\r\n candidate.append(min(l[i - 1], l[i]))\r\n i += 2\r\n else:\r\n ...
{"inputs": ["4\n2 4 4 2", "4\n2 2 3 5", "4\n100003 100004 100005 100006", "8\n5 3 3 3 3 4 4 4", "10\n123 124 123 124 2 2 2 2 9 9", "8\n10 10 10 10 11 10 11 10", "1\n1000000", "10\n10519 10519 10520 10520 10520 10521 10521 10521 10522 10523", "100\n4116 4116 4117 4117 4117 4117 4118 4119 4119 4119 4119 4120 4120 4120 41...
UNKNOWN
PYTHON3
CODEFORCES
53
a5bae04f5bb19ba1e9501f2a8499e803
Number of Ways
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=...
[ "n=int(input())\r\na=[int(i) for i in input().split()]\r\ns=sum(a)\r\n\r\ns1=0\r\nai=[0]*500001\r\nfor i in range(n-1):\r\n s1+=a[i]\r\n if s1==s/3:\r\n ai[i]=1\r\n\r\ns2=0\r\naj=[]\r\nfor j in range(n-1):\r\n s2+=a[n-j-1]\r\n if s2==s/3:\r\n aj.append(n-j-2)\r\n\r\nfor i in range(1,n):\r\...
{"inputs": ["5\n1 2 3 0 3", "4\n0 1 -1 0", "2\n4 1", "9\n0 0 0 0 0 0 0 0 0", "10\n2 5 -2 2 -3 -2 3 5 -5 -2", "1\n1", "3\n1 2 3", "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
UNKNOWN
PYTHON3
CODEFORCES
103
a5e4fdeedafed69e2a72d16220c9c4f7
Inna and Pink Pony
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an *n*<=×<=*m* chessboard, a very tasty candy and two numbers *a* and *b*. Dima put the chessboard in front of Inna and placed the candy in position (*i*,<=*j*) on the board....
[ "n, m, i, j, a, b = map(int, input().split())\ndef f(x, y):\n dx, dy = abs(x - i), abs(y - j)\n if dx % a or dy % b:\n return -1\n elif dx // a % 2 != dy // b % 2:\n return -1\n elif dx == 0 and dy == 0:\n return 0\n elif (i - a < 1 and i + a > n) or (j - b < 1 and j + b > m):\n ...
{"inputs": ["5 7 1 3 2 2", "5 5 2 3 1 1", "1 1 1 1 1 1", "23000 15500 100 333 9 1", "33999 99333 33000 99000 3 9", "5 7 1 3 1 2", "1 100 1 50 1 50", "1000 1 1 1 1 500", "304 400 12 20 4 4", "1000000 1000000 1000000 1000000 1000000 1000000", "1000000 99999 12345 23456 23 54", "50000 100000 500 1000 500 1000", "50000 100...
UNKNOWN
PYTHON3
CODEFORCES
8
a605b693f3432e792d6baf61b184cb2d
Fish
*n* fish, numbered from 1 to *n*, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability *a**ij*, and the second will eat up the first with the probability *a**ji*<==<...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = [list(map(float, input().split())) for _ in range(n)]\r\npow2 = [1]\r\nfor _ in range(n):\r\n pow2.append(2 * pow2[-1])\r\nm = pow2[n]\r\ndp = [0] * m\r\ndp[-1] = 1\r\nfor i in range(m - 1, 0, -1):\...
{"inputs": ["2\n0 0.5\n0.5 0", "4\n0 0.5 0.5 0.5\n0.5 0 0.5 0.5\n0.5 0.5 0 0.5\n0.5 0.5 0.5 0", "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0", "1\n0.000", "2\n0.000 0.551\n0.449 0.000", "3\n0.000 0.817 0.584\n0.183 0.000 0.665\n0.416 0.335 0.000", "4\n0.000 0.083 0.548 0.503\n0.917 ...
UNKNOWN
PYTHON3
CODEFORCES
9
a619d42eed633f3050df62f94d10b7c1
King's Path
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the...
[ "import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef ge...
{"inputs": ["5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5", "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10", "1 1 2 10\n2\n1 1 3\n2 6 10", "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10 10", "6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15", "13 16 20 10\n18\n13 16 1...
UNKNOWN
PYTHON3
CODEFORCES
68
a645e12baf8641d60fc64287c60ce752
Trains
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,...
[ "import sys\r\n\r\ndef gcd(a, b):\r\n if(b == 0):\r\n return a\r\n r = a % b\r\n return gcd(b, r)\r\n\r\na, b = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nt = gcd(a, b)\r\na /= t\r\nb /= t\r\n\r\nif(a > b):\r\n if(a != b + 1):\r\n print(\"Masha\")\r\n else:\r\n p...
{"inputs": ["3 7", "5 3", "2 3", "31 88", "8 75", "32 99", "77 4", "27 1", "84 11", "4 6", "52 53", "397 568", "22 332", "419 430", "638 619", "393 325", "876 218", "552 551", "906 912", "999 996", "652 653", "3647 7698", "2661 8975", "251 9731", "9886 8671", "8545 7312", "4982 2927", "7660 7658", "9846 9844", "9632 96...
UNKNOWN
PYTHON3
CODEFORCES
91
a64bde11b9445dc1e39be04d2fceef00
Modified GCD
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task...
[ "def gcd(a,b):\r\n while a>0:\r\n x=a\r\n a=b%a\r\n b=x\r\n return(x)\r\ndef Bsearch1(L,x):\r\n beg=0\r\n last=len(L)-1\r\n while beg<=last:\r\n mid=(beg+last)//2\r\n if x==L[mid]:\r\n return(mid)\r\n elif(x>L[mid]):\r\n beg=mid+1\r\n ...
{"inputs": ["9 27\n3\n1 5\n10 11\n9 11", "48 72\n2\n8 29\n29 37", "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "84 36\n1\n18 32", "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36", "84 90\n18\n10 75\n2 40\n30 56\n49 62\...
UNKNOWN
PYTHON3
CODEFORCES
62
a65a8ddec22e98a4bdf4fef23ccebc2e
Animals
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once. Drav...
[ "with open(\"input.txt\") as f:\r\n\tn, X = map(int, f.readline().split())\r\n\t# print(n, X)\r\n\teatFood = []\r\n\tfor idx, eat in enumerate(f.readline().split()):\r\n\t\teatFood.append((n - idx) * int(eat)) # if save idx-th animal, it will `eat (n - idx) * eat` by the last day\r\n\teatFood.sort(reverse=True)\r\...
{"inputs": ["3 4\n1 1 1", "3 6\n1 1 1", "1 12\n1", "3 100\n1 1 1", "5 75\n1 1 1 1 1", "7 115\n1 1 1 1 1 1 1", "10 1055\n7 1 1 2 8 7 8 2 5 8", "7 3623\n20 14 24 4 14 14 24", "10 3234\n24 2 28 18 6 15 31 2 28 16", "15 402\n3 3 3 3 2 2 3 3 3 3 3 3 2 2 1", "25 5523\n24 29 6 35 11 7 24 10 17 43 2 25 15 36 31 8 22 40 23 23 7...
UNKNOWN
PYTHON3
CODEFORCES
23
a6681f6a24b6e413486938d1b52f3fae
Log Stream Analysis
You've got a list of program warning logs. Each record of a log stream is a string in this format: String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct t...
[ "# import atexit\r\n# import io\r\n# import sys\r\n#\r\n# _INPUT_LINES = sys.stdin.read().splitlines()\r\n# input = iter(_INPUT_LINES).__next__\r\n# _OUTPUT_BUFFER = io.StringIO()\r\n# sys.stdout = _OUTPUT_BUFFER\r\n#\r\n#\r\n# @atexit.register\r\n# def write():\r\n# sys.__stdout__.write(_OUTPUT_BUFFER.getvalue...
{"inputs": ["60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected", "1 2\n2012-03-16 23:59:59:Disk size\n2012-03-17 00:00:00:...
UNKNOWN
PYTHON3
CODEFORCES
1
a67247ddc642337fb665ffad33a5c619
Lunch Rush
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rab...
[ "#Keshika Patwari\r\n#Indian Institute Of Technology, Jodhpur\r\n# 2022\r\nimport sys\r\ninput=sys.stdin.readline\r\ndef exe():\r\n \r\n return max(l)\r\nn,k=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n f,t=map(int,input().split())\r\n if(t>k):\r\n a=f-(t-k)\r\n else:\r\n ...
{"inputs": ["2 5\n3 3\n4 5", "4 6\n5 8\n3 6\n2 3\n2 2", "1 5\n1 7", "4 9\n10 13\n4 18\n13 3\n10 6", "1 1\n1 1000000000", "1 1\n1000000000 1000000000", "1 1\n1000000000 1", "2 3\n1000000000 1\n2 2", "2 5\n1 7\n1 1000000000"], "outputs": ["4", "3", "-1", "13", "-999999998", "1", "1000000000", "1000000000", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
208
a67a70733c91214a0387239b6c5f3b0b
The Great Game
Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. The input contains two strings of equal length (between 2 and 20...
[ "s = input()\r\nt = input()\r\nn = len(s)\r\nd = {'([': [0, 1], '((': [0, 0], '[[': [0, 0], '88': [0, 0], '(8': [1, 0],\r\n '8(': [0, 1], '[8': [0, 1], '8[': [1, 0], '[(': [1, 0]}\r\np, q = 0, 0\r\nfor i in range(0, n, 2):\r\n p += d[s[i] + t[i]][0]\r\n q += d[s[i] + t[i]][1]\r\nif p == q:\r\n print('T...
{"inputs": ["[]()[]8<\n8<[]()8<", "8<8<()\n[]8<[]", "()\n[]", "()\n8<", "8<\n[]", "[]8<()()()()8<8<8<[]\n()()[][][]8<[]()8<8<", "()[]()()()\n[]()[][]8<", "()\n8<", "()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()", "()[][]8<\n8<()8<()", "8<()8<8<8<8<()8<\n[]()()8<()[][][]", "[][]8<8<8<8<\n8<[][]()8<()", "[]\n()", "8<8<8<[]\...
UNKNOWN
PYTHON3
CODEFORCES
18
a67ea2cda7f0cc20730deba2efa225e7
Chocolate
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is *a*1<=×<=*b*1 segments large and the second one is *a*2<=×<=*b*2 segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other...
[ "f = lambda: map(int, input().split())\r\na, b = f()\r\nc, d = f()\r\n\r\ng = lambda k: 0 if k % p else 1 + g(k // p)\r\nk = 0\r\n\r\nfor p in (3, 2):\r\n s = g(a) + g(b) - g(c) - g(d)\r\n q = p - 1\r\n\r\n for i in range(abs(s)):\r\n k += 1\r\n if s > 0:\r\n if g(a): a = a * q // ...
{"inputs": ["2 6\n2 3", "36 5\n10 16", "3 5\n2 1", "36 5\n10 12", "1 1\n1 1", "2 1\n1 2", "3 6\n2 1", "1 27\n1 1", "2 5\n20 2", "40 5\n150 36", "60 1080\n60 45", "2160 3240\n7200 384", "51840 900\n48 27000", "100 200\n7200 25", "112500 96\n375 2400", "432000 3000\n4800 10000", "7 1\n1 7", "12 39\n13 3", "906992640 5441...
UNKNOWN
PYTHON3
CODEFORCES
1
a6836333c0cd74c9f9fb81e34f53cab5
Testing Robots
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (*x*0,<=*y*0) of a rectangular squared field of size *x*<=×<=*y*, after that a min...
[ "x,y,x0,y0 = map(int,input().split())\r\ng = [[0 for i in range(y+1)] for j in range(x+1)]\r\ns = input()\r\nresult = [0]*len(s)\r\nsum = x*y \r\nfor i in range(len(s)):\r\n if g[x0][y0] == 0:\r\n g[x0][y0] = 1\r\n result[i] = 1\r\n sum -= 1\r\n if s[i] == \"U\":\r\n if x0 > 1:\r\n...
{"inputs": ["3 4 2 2\nUURDRDRL", "2 2 2 2\nULD", "1 1 1 1\nURDLUURRDDLLURDL", "15 17 8 9\nURRDLUULLDD", "15 17 8 9\nURRDLUULLDDDRRUR", "15 17 8 9\nURRDLUULLDDDRRURR", "1 2 1 1\nR", "2 1 1 1\nD", "1 2 1 2\nLR", "2 1 2 1\nUD", "4 4 2 2\nDRUL", "4 4 3 3\nLUDRUL", "15 17 8 9\nURRDLU", "15 17 8 9\nURRDLUULLDDR", "15 17 8 9\...
UNKNOWN
PYTHON3
CODEFORCES
31
a6be5c5b3f940ae34740357bd4512ea4
Petya and Strings
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
[ "s1 = input().lower()\r\ns2 = input().lower()\r\n\r\nif s1==s2:\r\n print(0)\r\nif s1<s2:\r\n print(-1)\r\nif s1>s2:\r\n print(1)\r\n", "a = input().lower()\r\nb = input().lower()\r\nabi = True\r\nfor i in range(len(a)):\r\n if a[i] > b[i]:\r\n print('1')\r\n abi = False\r\n break...
{"inputs": ["aaaa\naaaA", "abs\nAbz", "abcdefg\nAbCdEfF", "asadasdasd\nasdwasdawd", "aslkjlkasdd\nasdlkjdajwi", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuG...
UNKNOWN
PYTHON3
CODEFORCES
534
a6c0ec0f94b080801d3e32b45ed8ec9c
How Many Squares?
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2<=×<=2. We are only interested in two types of squares: 1. squares with each side parallel to a side of the matrix; 1. squares with each side...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef find(x):\r\n while Group[x] != x:\r\n x=Group[x]\r\n return x\r\n\r\ndef Union(x,y):\r\n if find(x) != find(y):\r\n if Nodes[find(x)] < Nodes[find(y)]:\r\n \r\n Nodes[find(y)] += Nodes[find(x)]\r\n Nodes[fin...
{"inputs": ["2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000", "1\n12 11\n11111111111\n10000000001\n10111111101\n10100000101\n10101100101\n10101100101\n10...
UNKNOWN
PYTHON3
CODEFORCES
1
a6c41ea9c9ce50b21113df8a612d7106
Nearest Minimums
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second l...
[ "\n\nn = int(input())\n\nA = [int(x) for x in input().split()]\n\nm = min(A)\n\nA = [i for i, x in enumerate(A) if x == m]\n\nprint(min([A[i + 1] - A[i] for i in range(len(A) - 1)]))\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nm=min(a)\r\ni=a.index(m)\r\nb=[]\r\n\r\nfor j in range(i+1,n):\r\n i...
{"inputs": ["2\n3 3", "3\n5 6 5", "9\n2 1 3 5 4 1 2 3 1", "6\n4 6 7 8 6 4", "2\n1000000000 1000000000", "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "2\n10000000 10000000", "5\n100000000 100000001 100000000 100000001 100000000", "9\n4 3 4 3 4 1 3 3 1", "3\n10000000 10000000...
UNKNOWN
PYTHON3
CODEFORCES
217
a6cab46b8ce1e78c5fa12073774b1b7d
Alyona and Strings
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar. Alyona has her favourite positive integer *k* and bec...
[ "n,m,kk=map(int,input().split())\r\ns=input()\r\nt=input()\r\ndp=[[[0]*11 for i in range(1001)] for j in range(1001)]\r\nconsecutive=[[0]*(1001) for i in range(1001)]\r\nfor i in range(1,n+1):\r\n for j in range(1,m+1):\r\n if s[i-1]==t[j-1]:\r\n consecutive[i][j]=consecutive[i-1][j-1]+1\r\nans...
{"inputs": ["3 2 2\nabc\nab", "9 12 4\nbbaaababb\nabbbabbaaaba", "11 11 4\naaababbabbb\nbbbaaaabaab", "15 9 4\nababaaabbaaaabb\nbbaababbb", "2 7 1\nbb\nbbaabaa", "13 4 3\nabbaababaaaab\naaab", "2 3 2\nab\naab", "13 9 1\noaflomxegekyv\nbgwwqizfo", "5 9 1\nbabcb\nabbcbaacb", "8 12 2\nbccbbaac\nabccbcaccaaa", "11 2 2\nbcb...
UNKNOWN
PYTHON3
CODEFORCES
2
a6dbb69f10ce63f83e7b2804af0bd856
The Golden Age
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers. For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the...
[ "def parser():\r\n while 1:\r\n data = list(input().split(' '))\r\n for number in data:\r\n if len(number) > 0:\r\n yield(number) \r\n\r\ninput_parser = parser()\r\n\r\ndef get_word():\r\n global input_parser\r\n return next(input_parser)\r\n\r\ndef get_number():\r...
{"inputs": ["2 3 1 10", "3 5 10 22", "2 3 3 5", "2 2 1 10", "2 2 1 1000000", "2 2 1 1000000000000000000", "2 3 1 1000000", "2 3 1 1000000000000000000", "12345 54321 1 1000000", "54321 12345 1 1000000000000000000", "2 3 100000000 1000000000000", "2 14 732028847861235712 732028847861235712", "14 2 732028847861235713 7320...
UNKNOWN
PYTHON3
CODEFORCES
93
a70764fb4fd16794e40aeac14235d364
Berland National Library
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed...
[ "n = int(input())\r\nroom = []\r\nfor i in range(n):\r\n reg = input()\r\n if reg[0] == '+':\r\n room.append(int(reg[2:]))\r\n else:\r\n room.append(-1*int(reg[2:]))\r\n# print(room)\r\n\r\nbefore = []\r\nfor i in range(n): \r\n if room[i] < 0 and -1 * int(room[i]) not in room[:i]:\r\n ...
{"inputs": ["6\n+ 12001\n- 12001\n- 1\n- 1200\n+ 1\n+ 7", "2\n- 1\n- 2", "2\n+ 1\n- 1", "5\n+ 1\n- 1\n+ 2\n+ 3\n- 4", "3\n- 1\n- 2\n- 3", "4\n+ 1\n+ 2\n- 1\n+ 3", "6\n+ 1\n+ 2\n- 1\n+ 3\n- 2\n+ 4", "3\n+ 1\n+ 2\n- 3", "3\n- 1\n+ 2\n- 2", "4\n- 1\n- 2\n+ 3\n+ 4", "1\n+ 1", "1\n- 1", "3\n- 1\n+ 1\n- 1", "10\n+ 1\n+ 2\n+ ...
UNKNOWN
PYTHON3
CODEFORCES
37
a7154105f6f9c9c7b051cbe3640e655a
Mobile Communications
A sum of *p* rubles is charged from Arkady's mobile phone account every day in the morning. Among the following *m* days, there are *n* days when Arkady will top up the account: in the day *d**i* he will deposit *t**i* rubles on his mobile phone account. Arkady will always top up the account before the daily payment wi...
[ "n, p, m = input().split()\r\nn = int(n)\r\np = int(p)\r\nm = int(m)\r\n\r\nans = 0\r\ncurb = 0\r\ncurd = 1\r\nfor i in range(0, n):\r\n #print(curb)\r\n tday, tplus = input().split()\r\n tday = int(tday)\r\n tplus = int(tplus)\r\n if curb < 0:\r\n ans += (tday - curd)\r\n curb -= p * (...
{"inputs": ["3 6 7\n2 13\n4 20\n7 9", "5 4 100\n10 70\n15 76\n21 12\n30 100\n67 85", "14 25 100\n1 209\n2 224\n3 58\n4 31\n5 135\n6 16\n7 130\n8 113\n9 230\n10 60\n11 209\n12 185\n13 118\n14 16", "1 1 1\n1 1", "1 2 1\n1 1", "1 2 1\n1 3", "1 1000000000 1\n1 1000000000", "1 100000000 1\n1 99999999", "10 1 10\n1 100000000...
UNKNOWN
PYTHON3
CODEFORCES
6
a7575a52a521f677485b619b19b3277a
Toy Army
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe...
[ "print((3 * 2 * int(input())) // 4)", "n=int(input())\r\nif n%4:\r\n print(2*n-n//4*2-1)\r\nelse:\r\n print(2*n-n//4*2)", "x=int(input())\r\nprint(3*x//2)", "n=int(input())\r\nr=2*n-(n//2)\r\nprint(r)", "# Wadea #\r\n\r\nn = int(input())\r\nprint(n+n//2)", "n = int(input())\nprint((2*n)-(n//2))#Sour...
{"inputs": ["2", "4", "6", "8", "10", "140", "500", "1000", "2000", "50000", "10000", "25460", "54646", "59790", "578456", "56798056", "8457980", "5687986", "10984932", "99999994", "99999996", "99999998", "100000000"], "outputs": ["3", "6", "9", "12", "15", "210", "750", "1500", "3000", "75000", "15000", "38190", "8196...
UNKNOWN
PYTHON3
CODEFORCES
270
a75c2796222c96034eb516cffb9cd766
Yet Another Number Game
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games. BitLGM and Bi...
[ "# LUOGU_RID: 133022591\n# pypy3\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nimport sys\r\nIN = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nPN = lambda x: sys.stdout.write(x)\r\nI = lambda: int(IN())\r\nS = lambda: IN()....
{"inputs": ["2\n1 1", "2\n1 2", "3\n1 2 1", "2\n1 3", "2\n3 5", "2\n9 10", "2\n6 8", "3\n0 0 0", "2\n223 58", "2\n106 227", "2\n125 123", "3\n31 132 7", "2\n41 29", "3\n103 286 100", "3\n9 183 275", "3\n19 88 202", "3\n234 44 69", "3\n244 241 295", "1\n6", "1\n231", "2\n241 289", "2\n200 185", "2\n218 142", "3\n124 47 ...
UNKNOWN
PYTHON3
CODEFORCES
1
a769601d5a0746ed3aedd5004fa7c43c
The Door Problem
Moriarty has trapped *n* people in *n* distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are *m* switches. Each switch control doors of some rooms, but each door is control...
[ "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 3\n1 0 1\n2 1 3\n2 1 2\n2 2 3", "3 3\n1 0 1\n3 1 2 3\n1 2\n2 1 3", "3 3\n1 0 1\n3 1 2 3\n2 1 2\n1 3", "11 10\n0 0 1 0 0 0 0 1 1 0 1\n3 2 3 11\n1 3\n2 6 7\n1 5\n1 11\n1 10\n5 4 6 8 9 10\n2 1 5\n1 7\n5 1 2 4 8 9", "10 9\n1 0 1 1 0 1 0 0 1 0\n4 2 3 9 10\n4 3 4 5 8\n2 1 6\n2 7 8\n1 7\n1 5\n1 10\n2 2 4\n3 1 6...
UNKNOWN
PYTHON3
CODEFORCES
13
a776432a650f3bf651bc2f3fd6206d17
Volatile Kite
You are given a convex polygon *P* with *n* distinct vertices *p*1,<=*p*2,<=...,<=*p**n*. Vertex *p**i* has coordinates (*x**i*,<=*y**i*) in the 2D plane. These vertices are listed in clockwise order. You can choose a real number *D* and move each vertex of the polygon a distance of at most *D* from their original pos...
[ "from math import inf\r\n\r\ndef vect(x, y):\r\n return abs(sum([x[i]*(y[(i+1)%3]-y[(i+2)%3]) for i in range(3)]))\r\ndef l(x, y):\r\n return ((x[0]-x[2])**2 + (y[0]-y[2])**2)**0.5\r\ndef h(x, y):\r\n return vect(x, y) / l(x, y)\r\n\r\nn = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n a, b ...
{"inputs": ["4\n0 0\n0 1\n1 1\n1 0", "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4", "19\n449447997 711296339\n530233434 692216537\n535464528 613140435\n535533467 100893188\n530498867 -265063956\n519107979 -271820709\n482156929 -287792333\n-303730271 -287970295\n-416935204 -263348201\n-443613873 -249980523\n-453444829 -17390...
UNKNOWN
PYTHON3
CODEFORCES
23
a797ac3b124c17d4c2c31ee0aba85c2c
The Way to Home
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
[ "#10010101\r\nn,e = map(int,input().split())\r\ns = input()\r\ni = 0\r\nd = e\r\nans = -1\r\nflag = 0\r\nwhile(i<n-1):\r\n if(n-i-1 < e):\r\n e = n - i - 1\r\n d = e\r\n if(d==0):\r\n flag = 1\r\n print(\"-1\")\r\n break\r\n if(s[i+d]=='1'):\r\n i = i + d\r\n ...
{"inputs": ["8 4\n10010101", "4 2\n1001", "8 4\n11100101", "12 3\n101111100101", "5 4\n11011", "5 4\n10001", "10 7\n1101111011", "10 9\n1110000101", "10 9\n1100000001", "20 5\n11111111110111101001", "20 11\n11100000111000011011", "20 19\n10100000000000000001", "50 13\n10011010100010100111010000010000000000010100000101"...
UNKNOWN
PYTHON3
CODEFORCES
553
a7ac01ff36356b6ef5d9d6b3571169af
Approximating a Constant Range
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
[ "if __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n cnt, l, ans = {}, 0, 0\r\n for r, v in enumerate(a):\r\n if v in cnt:\r\n cnt[v] += 1\r\n else:\r\n cnt[v] = 1\r\n while len(cnt) > 2:\r\n cnt[a[l]] -=...
{"inputs": ["5\n1 2 3 3 2", "11\n5 4 5 5 6 7 8 8 8 7 6", "2\n3 2", "4\n1001 1000 1000 1001", "4\n1 1 2 3", "3\n1 2 1", "3\n1 2 3", "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9", "3\n1 2 2", "4\n10 9 10 9", "4\n4 3 2 3", "4\n8 8 7 7", "3\n99998 99999 100000", "3\n100000 99999 99998", "3\n1 1 1", "2\n99999 100000", "2\n1000...
UNKNOWN
PYTHON3
CODEFORCES
188
a7b83f74c9b94bdf5a673fec7894c3ad
Down the Hatch!
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice! Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to pl...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input()[:-1]\r\nc = 0\r\n\r\nfor i in range(len(s))[n::n]:\r\n if s[i-1] == s[i-2] == s[i-3]:\r\n c += 1\r\nprint(c)", "s, n, t = 0, int(input()), input()\r\nprint(sum(t[i] == t[i + 1] == t[i + 2] for i in range((3 // n + 1) * n - ...
{"inputs": ["4\nabbba", "4\nabbab", "4\naaa", "4\naab", "4\naabaabbba", "6\naaaaaaaaaaaaaaaa", "7\nabbbaaabbbaaaab", "9\naaaabaaaaa", "4\na", "4\nb", "4\nab", "4\nbb", "4\naba", "4\nbbb", "4\nabab", "4\nabaa", "4\nabbbaaabba", "4\nababba", "4\naaaaaa", "5\nbbbbaabaaa", "2000\na", "2000\naabaaabaabababbbbbbabbbbb", "4\n...
UNKNOWN
PYTHON3
CODEFORCES
38
a7b9003851fc4cb8632f1823cb585985
Clear The Matrix
You are given a matrix *f* with 4 rows and *n* columns. Each element of the matrix is either an asterisk (*) or a dot (.). You may perform the following operation arbitrary number of times: choose a square submatrix of *f* with size *k*<=×<=*k* (where 1<=≤<=*k*<=≤<=4) and replace each element of the chosen submatrix w...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = [0] * (4 * n)\r\nfor i in range(4):\r\n f = list(input().rstrip())\r\n for j in range(n):\r\n b[i + 4 * j] = (46 - f[j]) // 4\r\nfor _ in range(4):\r...
{"inputs": ["4\n1 10 8 20\n***.\n***.\n***.\n...*", "7\n2 1 8 2\n.***...\n.***..*\n.***...\n....*..", "4\n10 10 1 10\n***.\n*..*\n*..*\n.***", "5\n4 3 4 4\n.....\n****.\n..***\n...**", "6\n15 3 18 16\n.*.***\n...**.\n*.....\n**..*.", "5\n2 1 2 1\n*.***\n***.*\n.*..*\n***..", "4\n2 23 19 1\n..**\n*...\n**.*\n.*.*", "4\n...
UNKNOWN
PYTHON3
CODEFORCES
1
a7ca291de9a1aed7fcf65c7aebaaddd9
Photographer
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and...
[ "n, d = map(int, input().split())\r\na, b = map(int, input().split())\r\n\r\nclients = []\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n cost = x * a + y * b\r\n clients.append((i + 1, cost))\r\n\r\nclients.sort(key=lambda x: x[1])\r\n\r\nres = []\r\nfor client in clients:\r\n if d - cli...
{"inputs": ["3 10\n2 3\n1 4\n2 1\n1 0", "3 6\n6 6\n1 1\n1 0\n1 0", "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "10 10\n1 1\n0 3\n6 4\n3 3\n6 3\n5 2\n6 4\n1 3\n5 5\n2 6\n6 4", "5 5\n1 1\n2 0\n3 2\n4 4\n10 0\n0 1", "4 10\n1 2\n1 0\n0 0\n2 0\n1 3", "1 22\n3 5\n1 3", "10 20\n3 5\n3 0\n0 3\n1 2\n1 3\n1...
UNKNOWN
PYTHON3
CODEFORCES
43
a7f405ddb27670ecb47318df840304fc
Bus Video System
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, th...
[ "n, w = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\n# Минимальное и максимальное количество пассажиров в автобусе до первой остановки\r\nmin_p = max_p = 0\r\ncur_p = 0 # Текущее количество пассажиров в автобусе\r\n\r\nfor i in range(n):\r\n cur_p += a[i]\r\n min_p = min(min_p, cur_...
{"inputs": ["3 5\n2 1 -3", "2 4\n-1 1", "4 10\n2 4 1 2", "2 10\n-1 2", "3 4\n-3 -4 4", "10 1\n-1 -1 3 -4 2 3 0 -3 3 2", "5 21\n-3 2 -4 -1 -5", "5 9\n-2 -1 2 -1 -2", "8 7\n-5 0 -3 1 -1 5 0 -6", "3 4\n-2 -1 0", "1 1000000000\n0", "2 1000000000\n-1000000 -1000000", "2 1000000000\n1000000 -1000000", "2 1000000000\n-1000000...
UNKNOWN
PYTHON3
CODEFORCES
20
a81e7d7125035b8f7bdaadf1cc9b1c92
ACM ICPC
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. ...
[ "a = [int(x) for x in input().split()]\r\n\r\nsa = sum(a)\r\n\r\nif sa % 2 != 0:\r\n print('NO')\r\n exit()\r\n\r\nfor i in range(64):\r\n total = 0\r\n c = 0\r\n\r\n for b in range(6):\r\n if ((i >> b) & 1) == 1:\r\n total += a[b]\r\n c += 1\r\n if c != 3:\r\n ...
{"inputs": ["1 3 2 1 2 1", "1 1 1 1 1 99", "1000 1000 1000 1000 1000 1000", "0 0 0 0 0 0", "633 609 369 704 573 416", "353 313 327 470 597 31", "835 638 673 624 232 266", "936 342 19 398 247 874", "417 666 978 553 271 488", "71 66 124 199 67 147", "54 26 0 171 239 12", "72 8 186 92 267 69", "180 179 188 50 75 214", "16...
UNKNOWN
PYTHON3
CODEFORCES
279
a83d76638f25ffd2fcd9c09cc652d2c2
Artem and Array
Artem has an array of *n* positive integers. Artem decided to play with it. The game consists of *n* moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets *min*(*a*,<=*b*) points, where *a* and *b* are numbers that were adjacent with the removed number. If the number...
[ "n = input()\n\ns = []\n\na = 0\n\nfor i in map(int, input().split()):\n\n while len(s) > 1 and min(s[-2], i)>=s[-1]:\n\n a += min(i, s[-2])\n\n del(s[-1])\n\n s.append(i)\n\ns.sort()\n\nprint(a + sum(s[0: -2]))\n\n\n\n# Made By Mostafa_Khaled", "n = int(input())\r\ncards = list(map(int,input(...
{"inputs": ["5\n3 1 5 2 6", "5\n1 2 3 4 5", "5\n1 100 101 100 1", "10\n96 66 8 18 30 48 34 11 37 42", "1\n87", "2\n93 51", "3\n31 19 5", "4\n86 21 58 60", "5\n21 6 54 69 32", "6\n46 30 38 9 65 23", "7\n82 60 92 4 2 13 15", "8\n77 84 26 34 17 56 76 3", "9\n72 49 39 50 68 35 75 94 56", "10\n4 2 2 4 1 2 2 4 2 1", "1\n4", ...
UNKNOWN
PYTHON3
CODEFORCES
3
a83f8b46df13927157fecc78b46a9e07
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f...
[ "n=int(input())\r\nd={}\r\nfor i in range(n) :\r\n a,*b=input().split()\r\n d[a]=d.get(a,[])+b[1:]\r\nprint(len(d))\r\nfor x in d :\r\n L=list(set(d[x]))\r\n l=[]\r\n for i in range(len(L)) :\r\n flaf=True\r\n for j in range(len(L)) :\r\n if i!=j and L[j].endswith(L[i]) :\r\n...
{"inputs": ["2\nivan 1 00123\nmasha 1 00123", "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 ...
UNKNOWN
PYTHON3
CODEFORCES
28
a84f6423a5d54508f5988f076c9607ab
Magical Array
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nc, x = 0, a[0]\r\nans = 0\r\nfor i in a:\r\n if not i ^ x:\r\n c += 1\r\n else:\r\n ans += c * (c + 1) // 2\r\n c, x = 1, i\r\nans += c * (...
{"inputs": ["4\n2 1 1 4", "5\n-2 -2 -2 0 1", "1\n10", "2\n5 6", "5\n5 5 4 5 5", "8\n1 2 0 0 0 0 3 3", "12\n-4 3 3 2 3 3 3 -4 2 -4 -4 -4", "10\n7 1 0 10 0 -5 -3 -2 0 0", "20\n6 0 0 -3 1 -3 0 -8 1 3 5 2 -1 -5 -1 9 0 6 -2 4", "100\n0 -18 -9 -15 3 16 -28 0 -28 0 28 -20 -9 9 -11 0 18 -15 -18 -26 0 -27 -25 -22 6 -5 8 14 -17 ...
UNKNOWN
PYTHON3
CODEFORCES
96
a850a1bcad64de860c139cea3c8ba010
Zoo
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has *n* observation binoculars located at the *OX* axis. For each *i* between 1 and *n*, inclusive, there exists a single binocular located at the point with coordinates (*i*,<=0). There are *m* flamingos in the Zoo, located at points with positive...
[ "from ctypes import c_int32\n\ndef gcd(a,b):\n\n if b == 0:\n\n return a\n\n return gcd(b, a % b)\n\n \n\ndef normalize_rational(num,den):\n\n #associate the -ve with the num or cancel -ve sign when both are -ve\n\n if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0:\n\n num = -n...
{"inputs": ["5 5\n2 1\n4 1\n3 2\n4 3\n4 4", "3 3\n1 1\n2 10\n3 100", "1 2\n450000001 500000000\n900000001 1000000000", "3 6\n1 1\n1 2\n1 3\n2 1\n2 2\n3 1", "3 3\n227495634 254204506\n454991267 508409012\n715803819 799841973", "3 3\n96684705 23204141\n193369409 46408282\n217792636 52269809", "1000000 2\n136395332 110293...
UNKNOWN
PYTHON3
CODEFORCES
1
a855c7679049814a0a06cbf78812c973
Greg and Caves
Greg has a pad. The pad's screen is an *n*<=×<=*m* rectangle, each cell can be either black or white. We'll consider the pad rows to be numbered with integers from 1 to *n* from top to bottom. Similarly, the pad's columns are numbered with integers from 1 to *m* from left to right. Greg thinks that the pad's screen di...
[ "M=10**9+7\r\nn,m=[int(e) for e in input().split()]\r\nif m<2:\r\n print(0)\r\nelse:\r\n F=[[0]*(m+1) for i in range(n+1)]\r\n Fsum=[[0]*(m+1) for i in range(n+1)]\r\n for j in range(2,m+1):\r\n F[1][j]=1\r\n Fsum[1][j]=Fsum[1][j-1]+F[1][j]\r\n for i in range(2,n+1):\r\n s=1\r\n ...
{"inputs": ["1 1", "4 4", "3 5", "5 3", "5 5", "7 8", "9 8", "10 10", "100 100", "100 110", "100 200", "1 1000", "1000 1", "1000 3", "3 1000", "10 1000", "10 500", "250 250", "500 1000", "1000 500", "1000 1000", "1 2", "2000 2000", "1500 2000", "2000 1777", "1999 1994", "1994 1995", "1 2000", "2000 1", "2 2000", "2000 ...
UNKNOWN
PYTHON3
CODEFORCES
1
a8695a151c7d1fee85c1c1e62cc8f6c1
Jeff and Furik
Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of *n* numbers: *p*1, *p*2, ..., *p**n*. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses ...
[ "from bisect import bisect_right\r\ninput()\r\nt = list(map(int, input().split()))\r\ns, p = 0, []\r\nfor i, j in enumerate(t):\r\n k = bisect_right(p, j)\r\n s += i - k\r\n p.insert(k, j)\r\nprint(2 * s - (s & 1))", "def count(a):\r\n n = len(a)\r\n cnt = 0\r\n for i in range(n):\r\n f...
{"inputs": ["2\n1 2", "5\n3 5 2 4 1", "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12", "9\n1 7 8 5 3 4 6 9 2", "5\n2 3 4 5 1", "9\n4 1 8 6 7 5 2 9 3", "10\n3 4 1 5 7 9 8 10 6 2", "13\n3 1 11 12 4 5 8 10 13 7 9 2 6", "10\n8 4 1 7 6 10 9 5 3 2", "2\n2 1", "95\n68 56 24 89 79 20 74 69 49 59 85 67 95 66 15 34 2 13 92 25 84 77...
UNKNOWN
PYTHON3
CODEFORCES
7
a875c5dded52170798e08effa7cb6695
Vasya and Socks
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
[ "a,b=map(int,input().split())\r\nc=0\r\nd=0\r\nwhile a>0:\r\n d+=1\r\n c+=1\r\n if c==b:\r\n a+=1\r\n c=0\r\n a-=1\r\nprint(d)", "tm = input().split()\r\nn, m = int(tm[0]), int(tm[1])\r\nit = n\r\np = 0\r\nwhile it // m - p > 0:\r\n l = p\r\n p = it // m\r\n it += it // m - l\r\...
{"inputs": ["2 2", "9 3", "1 2", "2 3", "1 99", "4 4", "10 2", "10 9", "100 100", "2 27", "99 100", "99 2", "100 3", "98 3", "4 4", "100 2", "62 4", "99 10", "100 5", "80 80", "95 16", "75 16", "99 74", "20 21", "52 96", "24 5"], "outputs": ["3", "13", "1", "2", "1", "5", "19", "11", "101", "2", "99", "197", "149", "14...
UNKNOWN
PYTHON3
CODEFORCES
468
a8970e2b436e94ec4bcc241534b45bd6
Tiling with Hexagons
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles. The hall also turned out hexagonal in its shape. The King walked along the perimeter of ...
[ "a, b, c = tuple(sorted(map(int, input().split())))\r\nprint((b + (a - 1)) * (c + (a - 1)) - (a * (a - 1)))\r\n", "a,b,c = map(int,input().split()); print((a+b-1)*(c-1)+a*b)", "a, b, c = map(int, input().split())\r\n\r\nprint((a+b-1)*(a+c-1) - a*(a-1))", "import sys\r\nimport collections \r\nsys.setrecursionl...
{"inputs": ["2 3 4", "2 2 2", "7 8 13", "14 7 75", "201 108 304", "999 998 996", "2 2 3", "2 3 2", "3 2 2", "2 3 3", "3 2 3", "3 3 2", "3 3 3", "4 5 3", "2 2 856", "2 986 2", "985 2 2", "2 958 983", "992 2 912", "789 894 2", "1000 1000 1000", "384 458 284", "709 14 290", "485 117 521", "849 333 102", "998 999 1000", "2...
UNKNOWN
PYTHON3
CODEFORCES
64
a89c8820cafbc7a9c6e3baacc9ad9840
Wilbur and Points
Wilbur is playing with a set of *n* points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (*x*, *y*) belongs to the set, then all points (*x*', *y*'), such that 0<=≤<=*x*'<=≤<=*x* and 0<=≤<=*y*'<=≤<=*y* also belong to this set. Now Wilbur wants to number the points i...
[ "from collections import deque\n\n\ndef ordering(s, ws):\n pbs = {}\n for p in sorted(s):\n pbs.setdefault(p[1]-p[0], deque()).append(p)\n\n o = []\n os = set()\n for w in ws:\n try:\n p = pbs[w].popleft()\n except (IndexError, KeyError):\n return None\n\n ...
{"inputs": ["5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0", "3\n1 0\n0 0\n2 0\n0 1 2", "9\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1\n1 2\n2 2\n0 2\n0 0 0 -1 -1 -2 1 1 2", "18\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n1 0\n0 1 2 3 4 5 6 7 8 9 -1 10 11 12 13 14 15 16", "1\n0 0\n0", "37\n...
UNKNOWN
PYTHON3
CODEFORCES
12
a8b1aab3a22f8405c79e530a2a79375e
Christmas Spruce
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ...
[ "n = int(input())\r\nnodes = {1: []}\r\nyes_or_no = \"Yes\"\r\nfor i in range(2,n+1):\r\n p = int(input())\r\n nodes[p].append(i)\r\n nodes[i] = []\r\n \r\nfor i in nodes:\r\n no_of_leaves = 0\r\n for child in nodes[i]:\r\n if len(nodes[child]) == 0:\r\n no_of_leaves += 1\r\n ...
{"inputs": ["4\n1\n1\n1", "7\n1\n1\n1\n2\n2\n2", "8\n1\n1\n1\n1\n3\n3\n3", "3\n1\n1", "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10", "7\n1\n2\n2\n1\n1\n1", "7\n1\n1\n1\n1\n2\n2", "8\n1\n1\n1\n1\n5\n5\n5", "9\n1\n1\n1\n1\n2\n6\n6\n6", "12\n1\n1\n1\n2\n5\n5\n5\n5\n1\n2\n2", "20\n1\n1\n1\n1\n2\n2\n2\n3\n3\n3\n4\n4\n4\n5\n5\...
UNKNOWN
PYTHON3
CODEFORCES
122
a8b9f0bb25f28f00fcfd1efbbfb86d8e
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ...
[ "days = int(input())\nsequence = input().split()\nfolder = 1\nbad_rep = 0\nrep = 0\nans = \"\"\nfor profit in sequence:\n rep += 1\n if int(profit) < 0:\n bad_rep += 1\n if bad_rep == 3:\n folder += 1\n ans = ans + str(rep - 1) + \" \"\n bad_rep = 1\n rep = 1\n\nans += st...
{"inputs": ["11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "5\n0 -1 100 -1 0", "1\n0", "1\n-1", "2\n0 0", "2\n-2 2", "2\n-2 -1", "12\n1 -12 -5 -8 0 -8 -1 -1 -6 12 -9 12", "4\n1 2 0 3", "4\n4 -3 3 3", "4\n0 -3 4 -3", "4\n-3 -2 4 -3", "4\n-3 -2 -1 -4", "5\n-2 -2 4 0 -1", "5\n-5 -3 -1 2 -1", "5\n-3 -2 -3 -2 -3", "10\n0 5 2 3 10 9 4 9...
UNKNOWN
PYTHON3
CODEFORCES
100
a8bdd009f7ce1f2f44c150ad8504bc9a
Lipshitz Sequence
A function is called Lipschitz continuous if there is a real constant *K* such that the inequality |*f*(*x*)<=-<=*f*(*y*)|<=≤<=*K*·|*x*<=-<=*y*| holds for all . We'll deal with a more... discrete version of this term. For an array , we define it's Lipschitz constant as follows: - if *n*<=&lt;<=2, - if *n*<=≥<=2,...
[ "f = lambda: map(int, input().split())\r\nn, m = f()\r\nt = list(f())\r\np = [1e9] + [abs(b - a) for a, b in zip(t, t[1:])] + [1e9]\r\nL, R = [0] * n, [0] * n\r\nfor i in range(1, n):\r\n j = n - i\r\n x, y = i - 1, j + 1\r\n a, b = p[i], p[j]\r\n while a > p[x]: x = L[x]\r\n while b >= p[y]: y = R[y...
{"inputs": ["10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9", "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5", "2 2\n0 0\n1 2\n1 2", "2 2\n0 100000000\n1 2\n1 2", "4 6\n1 2 3 2\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "3 6\n10 20 30\n1 2\n1 3\n2 3\n1 2\n2 3\n1 3", "3 6\n48261735 26888803 75904937\n1 2\n1 3\n2 3\n1 2\n2 3\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
a8d9c374dc35bbbb2575ed30d529d3b7
Little Elephant and Sorting
The Little Elephant loves sortings. He has an array *a* consisting of *n* integers. Let's number the array elements from 1 to *n*, then the *i*-th element will be denoted as *a**i*. The Little Elephant can make one move to choose an arbitrary pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and increase *a**i*...
[ "#rOkY\r\n#FuCk\r\n\r\n################################## kOpAl #####################################\r\n\r\nt=int(input())\r\nl=list(map(int,input().split()))\r\nt1=l[0]\r\nsum=0\r\nfor i in range(1,t,1):\r\n if(l[i]<t1):\r\n sum+=(t1-l[i])\r\n t1=l[i]\r\nprint(sum)\r\n", "#Khushal Sindhav\r\n#India...
{"inputs": ["3\n1 2 3", "3\n3 2 1", "4\n7 4 1 47", "10\n1 2 3 4 5 6 7 8 9 1000000000", "10\n1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1", "7\n47 47 47 47 47 47 48", "47\n479793446 951468508 89486286 338446715 32648506 624498057 608503040 669251062 922459299 753303599 15471514 633954104 726178809 25...
UNKNOWN
PYTHON3
CODEFORCES
54
a9142d7a0d07b86b7e2a3da2f1ed8549
Rumor
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
[ "def count_com(graph):\r\n def dfs(graph,node,visited):\r\n visited[node]=True\r\n mini=node[1]\r\n stack=[node]\r\n while stack:\r\n a=stack.pop()\r\n mini=min(mini,a[1])\r\n for nei in graph[a]:\r\n if not visited[nei]:stack+=nei,;visited[nei]=True\r\n return mini\r\n\r\n visited=dict();min_all=0\r\...
{"inputs": ["5 2\n2 5 3 4 8\n1 4\n4 5", "10 0\n1 2 3 4 5 6 7 8 9 10", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "1 0\n0", "1 0\n1000000000", "2 0\n0 0", "2 0\n1000000000 0", "2 0\n0 1000000000", "2 0\n1000000000 1000000000", "2 1\n0 0\n1 2"], "outputs": ["10", "55", "15", "0", "1000000000", "0", "10000000...
UNKNOWN
PYTHON3
CODEFORCES
104
a92dfe19131f642079f8c1857648c0f3
Warehouse
Once upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero DravDe worked. He couldn’t program or make up problems (in fact, few people saw a computer those days) bu...
[ "import itertools\r\nimport math\r\nimport time\r\nfrom builtins import input\r\nfrom math import gcd as gcd\r\nimport sys\r\nimport queue\r\nimport itertools\r\nimport collections\r\nfrom heapq import heappop, heappush\r\nimport random\r\nimport os\r\nfrom random import randint\r\nimport decimal\r\n\r\n# from sys ...
{"inputs": ["2 2 9\n+1 1 1 cola\n+1 1 1 fanta\n+1 1 1 sevenup\n+1 1 1 whitekey\n-1 cola\n-1 fanta\n-1 sevenup\n-1 whitekey\n-1 cola", "2 2 8\n+1 1 1 cola\n-1 cola\n+1 1 1 fanta\n-1 fanta\n+1 1 1 sevenup\n-1 sevenup\n+1 1 1 whitekey\n-1 whitekey", "2 2 5\n-1 ywesjzsdk\n-1 aaew\n+1 1 2 wk\n-1 wk\n-1 wk", "3 5 5\n-1 vpotl...
UNKNOWN
PYTHON3
CODEFORCES
6
a9334ecfe4eda493c86d67d26b117c09
Random Query
You are given an array *a* consisting of *n* positive integers. You pick two integer numbers *l* and *r* from 1 to *n*, inclusive (numbers are picked randomly, equiprobably and independently). If *l*<=&gt;<=*r*, then you swap values of *l* and *r*. You have to calculate the expected value of the number of unique elemen...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nl = pow(10, 6)\r\nc, c1, c2 = 0, 0, 0\r\ny = [-1] * (l + 1)\r\nmod = pow(10, 9) + 7\r\nfor i in range(n):\r\n ai = a[i]\r\n if y[ai] == -1:\r\n c += 1\r\n s = i - y[ai]\r\n t = (s - 1) * (s...
{"inputs": ["2\n1 2", "2\n2 2", "10\n9 6 8 5 5 2 8 9 2 2", "20\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21", "1\n1000000"], "outputs": ["1.500000", "1.000000", "3.100000", "7.010000", "1.000000"]}
UNKNOWN
PYTHON3
CODEFORCES
8
a954c9b3c7a84fd96eda0a8f7520b89c
Painting Eggs
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have *n* eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J....
[ "n = int(input())\r\neggs = []\r\n\r\nfor i in range(n):\r\n a, g = map(int, input().split())\r\n eggs.append((a, g))\r\n\r\nresult = []\r\n\r\ntotal_a_payment = 0\r\ntotal_g_payment = 0\r\n\r\nfor a, g in eggs:\r\n if total_a_payment + a - total_g_payment <= 500:\r\n result.append('A')\r\n t...
{"inputs": ["2\n1 999\n999 1", "3\n400 600\n400 600\n400 600", "2\n500 500\n500 500", "1\n1 999", "10\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999\n1 999", "2\n499 501\n501 499", "3\n500 500\n1 999\n400 600", "1\n0 1000", "1\n500 500", "1\n1000 0"], "outputs": ["AG", "AGA", "AG", "A", "AAAAAAAAAA", "A...
UNKNOWN
PYTHON3
CODEFORCES
3
a979154b5b2a8175788285841d9e28d3
Game With Sticks
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid show...
[ "line = list(map(int, input().strip().split()))\r\n\r\nif(min(line)%2 == 0):\r\n\tprint(\"Malvika\")\r\nelse:\r\n\tprint(\"Akshat\")", "n,m = map(int, input().split())\r\n\r\na = min(n,m)\r\n\r\nif a%2==0:\r\n print('Malvika')\r\nelse:\r\n print('Akshat')", "a = min(map(int,input().split()))\r\nif a % 2 =...
{"inputs": ["2 2", "2 3", "3 3", "20 68", "1 1", "1 2", "1 3", "2 1", "2 2", "3 1", "3 2", "68 42", "1 35", "25 70", "59 79", "65 63", "46 6", "28 82", "98 98", "98 99", "98 100", "99 98", "99 99", "99 100", "100 98", "100 99", "100 100", "3 4"], "outputs": ["Malvika", "Malvika", "Akshat", "Malvika", "Akshat", "Akshat"...
UNKNOWN
PYTHON3
CODEFORCES
254
a98bb4e313d9676809393673a356aec7
Deletion of Repeats
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of length *x* is such a substring of length 2*x*, that its first half ...
[ "import sys\nn=int(input())\na=list(map(int,input().split()))\nM=10**9+1\ng={}\nfor i in range(n):\n g[a[i]]=g.get(a[i],[])+[i]\np=[1]\nfor i in range(n):\n p+=[hash(M*p[-1])]\nh=[0]*(n+1)\nfor i in range(n):\n h[i+1]=hash(h[i]*M+a[i])\ngh=lambda k,l:hash(h[k+l]-h[k]*p[l])%sys.hash_info.modulus\ni,t=0,0\nw...
{"inputs": ["6\n1 2 3 1 2 3", "7\n4 5 6 5 6 7 7", "10\n5 7 2 1 8 8 5 10 2 5", "10\n0 1 1 1 0 3 0 1 4 0", "10\n0 1 0 2 0 0 1 1 1 0", "30\n17 17 2 4 13 21 17 11 15 0 9 2 23 10 24 21 23 17 5 11 25 1 16 6 11 22 19 2 12 16", "100\n8 43 55 27 70 81 66 10 49 67 24 61 53 0 2 76 96 16 16 1 78 1 69 69 4 59 6 87 98 14 98 20 12 48...
UNKNOWN
PYTHON3
CODEFORCES
1
a9b139efa7de061f69403d9289843020
Happy Farm 5
The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them. For that a young player Vasya decided to make the shepherd run round the cows a...
[ "n=int(input())\r\nmh=sh=-10**7\r\nml=sl=10**7\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n m=a+b\r\n s=a-b\r\n mh=max(mh,m)\r\n ml=min(ml,m)\r\n sh=max(sh,s)\r\n sl=min(sl,s)\r\nprint(mh-ml+sh-sl+4)\r\n" ]
{"inputs": ["4\n1 1\n5 1\n5 3\n1 3", "3\n0 0\n5 0\n0 5", "5\n0 0\n7 7\n7 5\n5 7\n1 1", "5\n1 0\n-1 0\n1 0\n-1 0\n0 0", "9\n1 0\n-1 0\n1 0\n-1 0\n0 0\n1 1\n-1 -1\n1 -1\n-1 1", "5\n-10 10\n-10 -10\n10 -10\n9 8\n1 2", "1\n7 -10", "3\n7 -10\n7 -10\n7 -10", "2\n-10 0\n-10 7", "5\n-10 0\n-10 7\n-10 0\n-10 7\n-10 0", "11\n0 0...
UNKNOWN
PYTHON3
CODEFORCES
1
a9e7f39b20cf005323eea47e365c2890
Encrypting Messages
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Encryption uses a key which is a sequence ...
[ "n,m,c=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nfor i in range(n-m+1):\r\n for j in range(m):\r\n a[j+i]+=b[j]\r\n a[j+i]%=c\r\nprint(*a)", "n, m, c = map(int, input().split())\r\ndata = list(map(int, input().split()))\r\nkeys = tup...
{"inputs": ["4 3 2\n1 1 1 1\n1 1 1", "3 1 5\n1 2 3\n4", "5 2 7\n0 0 1 2 4\n3 5", "20 15 17\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\n6 3 14 8 8 11 16 4 5 9 2 13 6 14 15", "80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 4...
UNKNOWN
PYTHON3
CODEFORCES
32
a9ec43cedd74ecc2200cd993ccce7067
Generate Login
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and ...
[ "def getprfx(s):\r\n\ttab = [s[0]]\r\n\tfor i in range(1, len(s)):\r\n\t\tx = tab[i-1] + s[i]\r\n\t\ttab.append(x)\r\n\treturn tab\r\n\t\r\nn, m = input().split()\r\n\r\na, b = getprfx(n), getprfx(m)\r\nmn = a[0] + b[0]\r\nfor i in a:\r\n\tfor j in b:\r\n\t\tif i+j < mn:\r\n\t\t\tmn = i+j\r\nprint(mn)\t\t\t", "tr...
{"inputs": ["harry potter", "tom riddle", "a qdpinbmcrf", "wixjzniiub ssdfodfgap", "z z", "ertuyivhfg v", "asdfghjkli ware", "udggmyop ze", "fapkdme rtzxovx", "mybiqxmnqq l", "dtbqya fyyymv", "fyclu zokbxiahao", "qngatnviv rdych", "ttvnhrnng lqkfulhrn", "fya fgx", "nuis zvjjqlre", "ly qtsmze", "d kgfpjsurfw", "lwli ewr...
UNKNOWN
PYTHON3
CODEFORCES
253
a9edd7e23c7a56dec735305f3eb667a2
Cyclic Cipher
You are given *n* sequences. Each sequence consists of positive integers, not exceeding *m*. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the *i*-th sequence is *k**i*. Each second integers in each of the sequences are shifted by one to the left, i.e. ...
[ "import sys, random\r\ninput = lambda : sys.stdin.readline().rstrip()\r\n\r\n\r\nwrite = lambda x: sys.stdout.write(x+\"\\n\"); writef = lambda x: print(\"{:.12f}\".format(x))\r\ndebug = lambda x: sys.stderr.write(x+\"\\n\")\r\nYES=\"Yes\"; NO=\"No\"; pans = lambda v: print(YES if v else NO); INF=10**18\r\nLI = lam...
{"inputs": ["3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4", "5 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3", "4 6\n3 4 5 3\n2 6 3\n2 3 6\n3 3 6 5", "10 5\n2 2 4\n2 4 5\n2 1 2\n4 3 1 5 2\n4 1 3 2 5\n5 3 4 5 2 1\n3 3 5 4\n1 1\n2 4 1\n1 5", "10 10\n2 1 5\n2 3 4\n4 7 1 10 4\n4 6 3 9 7\n2 3 5\n3 4 9 7\n3 6 5 9\n5 8 5 4 10 6\n3 5 7 1\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
a9f1db41bf78794ebd59fce0b08f9ad0
Expression
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
[ "x = int(input())\r\ny = int(input())\r\nz = int(input())\r\nlist_1 = []\r\n\r\nlist_1.append((x+y)*z)\r\nlist_1.append(x*(y+z))\r\nlist_1.append(x+y+z)\r\nlist_1.append(x*y*z)\r\n\r\nprint(max(list_1))", "a=int(input())\nb=int(input())\nc=int(input())\nz=[]\nz.append(a+b+c)\nz.append(a*b*c)\nz.append((a+b)*c)\nz...
{"inputs": ["1\n2\n3", "2\n10\n3", "1\n1\n1", "1\n2\n1", "10\n10\n10", "5\n1\n3", "3\n1\n5", "6\n7\n1", "1\n8\n3", "9\n7\n2", "1\n1\n10", "9\n1\n1", "10\n5\n6", "8\n9\n7", "4\n2\n10", "2\n8\n3", "3\n5\n7", "1\n10\n1", "2\n2\n2", "5\n6\n1", "10\n1\n1", "1\n6\n1", "1\n9\n1", "2\n1\n2", "2\n6\n1", "9\n2\n1", "1\n9\n2", "1...
UNKNOWN
PYTHON3
CODEFORCES
341
a9f7eb841627ede770d54ac50ad4486b
Collective Mindsets (easy)
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage. ...
[ "# LUOGU_RID: 101268054\nn = int(input())\nif n % 2:\n print(n // 2 +1)\nelse:\n print(n // 2)", "def zombi(n):\r\n return (n + 1) // 2\r\n\r\n\r\nprint(zombi(int(input())))\r\n", "import math\r\n\r\nn = int(input())\r\nprint(math.ceil(n/2))", "import math\r\nprint(math.ceil(int(input())/2))", "# L...
{"inputs": ["1", "4", "2", "3", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "100", "9999", "21736", "873467", "4124980", "536870910", "536870912", "876543210", "987654321", "1000000000"], "outputs": ["1", "2", "1", "2", "3", "3", "4", "4", "5", "5", "6", "6", "7", "7", "8"...
UNKNOWN
PYTHON3
CODEFORCES
41
aa0e79b94b0ba6e8643b2b44c935d9eb
Random Task
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer *n*, that among numbers *n*<=+<=1, *n*<=+<=2, ..., 2·*n* there are exactly *m* numbers which binary representation contains exactly *k* digits one". The girl got int...
[ "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": ["1 1", "3 2", "3 3", "1 11", "4 20", "45902564 24", "330 8", "10 10", "0 2", "1000000 55", "1 60", "1000000000 52", "101628400788615604 30", "101628400798615604 31", "55 55", "14240928 10", "1000000000 10", "1111111 11", "10000000000000000 35", "0 19", "768 10", "3691 6", "16 15", "427 4", "669 9", "0 16", ...
UNKNOWN
PYTHON3
CODEFORCES
2
aa3049696d389bffae6f06d2bf84bfeb
Liebig's Barrels
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel. Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it. ...
[ "from bisect import bisect_right\r\nn,k,l = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na.sort()\r\nif k==1:\r\n if a[-1]-a[0]<=l:\r\n print(sum(a))\r\n else:\r\n print(0)\r\nelif a[n-1]-a[0]>l:\r\n print(0)\r\nelif a[0]+l>a[-1]:\r\n print(sum(a[::k]))\r\nelse:\...
{"inputs": ["4 2 1\n2 2 1 2 3 2 2 3", "2 1 0\n10 10", "1 2 1\n5 2", "3 2 1\n1 2 3 4 5 6", "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71", "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834...
UNKNOWN
PYTHON3
CODEFORCES
63
aa38306070eb8e4093e1bf4283d68da4
Bubble Sort Graph
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with *n* elements *a*1, *a*2, ..., *a**n* in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it *G*) initially has *n* vertices and 0 edges. During Bubble Sort execution, ...
[ "from bisect import *\r\n\r\ns = [0]\r\nq = int(input())\r\nfor i in map(int, input().split()):\r\n if i > s[-1]:\r\n s.append(i)\r\n else:\r\n s[bisect_right(s, i)] = i\r\nprint(len(s) - 1)\r\n", "# Python program to find\r\n# length of longest\r\n# increasing subsequence\r\n# in O(n Log n) t...
{"inputs": ["3\n3 1 2", "5\n4 2 1 3 5", "10\n1 9 8 10 2 3 4 6 5 7", "50\n12 24 42 43 36 3 40 29 7 34 10 13 28 9 35 23 25 21 19 4 20 18 11 38 41 48 6 46 33 17 31 37 2 30 32 44 45 5 47 49 16 15 50 27 26 14 39 22 1 8", "100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 ...
UNKNOWN
PYTHON3
CODEFORCES
22
aa3c1b41277165391ffdeec88676f3de
Leaving Auction
There are *n* people taking part in auction today. The rules of auction are classical. There were *n* bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all. Each bid is define by two integers (*a**i*,<=*b**i*), where *a**i* is the index of the perso...
[ "import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef binary_search(c1, c2):\r\n m = (c1 + c2 + 1) // 2\r\n while abs(c1 - c2) > 1:\r\n m = (c1 + c2 + 1) // 2\r\n if ok(m):\r\n c2 = m\r\n else:\r\n c1 = m\r\n ...
{"inputs": ["6\n1 10\n2 100\n3 1000\n1 10000\n2 100000\n3 1000000\n3\n1 3\n2 2 3\n2 1 2", "3\n1 10\n2 100\n1 1000\n2\n2 1 2\n2 2 3", "1\n1 1\n1\n1 1", "2\n1 1\n2 2\n3\n1 1\n1 2\n2 1 2", "4\n1 3\n2 7\n1 8\n3 10\n15\n1 1\n1 2\n1 3\n1 4\n2 1 2\n2 1 3\n2 1 4\n2 2 3\n2 2 4\n2 3 4\n3 1 2 3\n3 1 2 4\n3 1 3 4\n3 2 3 4\n4 1 2 3...
UNKNOWN
PYTHON3
CODEFORCES
1
aa58cc23ec95ad4e4034fc6ce173c19c
Hamsters and Tigers
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
[ "n=int(input())\r\ns=input()\r\nq=s.count(\"H\")\r\nw=n-q\r\n\r\n\r\no=1001\r\nfor i in range(n-q+1):\r\n o=min(o,q-s[i:i+q].count(\"H\"))\r\nfor i in range(n-w+1):\r\n o=min(o,w-s[i:i+w].count(\"T\"))\r\nprint(o)", "n = int(input())\r\ns = input() * 2\r\ncount = s.count(\"H\") // 2\r\nprint(count - max(s[i...
{"inputs": ["3\nHTH", "9\nHTHTHTHHT", "2\nTH", "4\nHTTH", "4\nHTHT", "7\nTTTHTTT", "8\nHHTHHTHH", "13\nHTTTHHHTTTTHH", "20\nTTHTHTHHTHTTHHTTTHHH", "35\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT", "120\nTTTTTTTHTHTHTTTTTHTHTTTTHTTTTTTTTTTTTTTTTTTTTHTTHTTTTHTTHTTTTTTTTTTTTTTTHTTTTTTHTHTTHTTTTTTHTTTTTTTTTHTTHTTTTHTTTHTTTTTH", "...
UNKNOWN
PYTHON3
CODEFORCES
72
aa6ceb741b91e022653c4ce5b955f3ff
Bus
There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct). We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, tha...
[ "from collections import Counter\r\nn,m=map(int,input().split())\r\narr=[]\r\ntt=0\r\nlstx=[]\r\nwhile(n>0):\r\n\r\n if(tt!=0):\r\n tt+=lstx[-1]\r\n cap = 0\r\n lstt = []\r\n lstx = []\r\n while(cap<m and n>0):\r\n t,x=map(int,input().split())\r\n lstt.append(t)\r\n lstx.a...
{"inputs": ["1 10\n3 5", "2 1\n3 5\n4 5", "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2", "1 1\n109 15", "2 1\n43 5\n102 1", "4 2\n7 1\n12 14\n90 15\n176 1", "8 8\n48 14\n74 12\n94 4\n127 14\n151...
UNKNOWN
PYTHON3
CODEFORCES
4
aa87f34e616f70cb9788a76c5f75ea43
HDD is Outdated Technology
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s...
[ "n = int(input())\r\narr = [None] * n\r\nL = list(map(int, input().split()))\r\n\r\nfor k, v in enumerate(L):\r\n arr[v - 1] = k\r\n\r\nres = 0\r\nfor i in range(n - 1):\r\n res += abs(arr[i] - arr[i + 1])\r\nprint(res)\r\n", "# https://codeforces.com/contest/612/problem/B\r\n\r\nn = int(input())\r\nf = lis...
{"inputs": ["3\n3 1 2", "5\n1 3 5 4 2", "1\n1", "1\n1", "1\n1", "10\n8 2 10 3 4 6 1 7 9 5", "10\n1 2 3 4 5 6 7 8 9 10", "10\n1 3 5 7 9 10 8 6 4 2", "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 8...
UNKNOWN
PYTHON3
CODEFORCES
136
aa909528de85efa4b55581fd8e03c2e2
Kuro and Topological Parity
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games. Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot o...
[ "n,p=map(int,input().split())\r\nnums=[0]+list(map(int,input().split()))\r\nmod=10**9+7\r\n\r\nf=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]\r\n\r\n_2=[0]*(n+1)\r\n_2[0]=1\r\nfor i in range(1,n+1):\r\n _2[i]=(_2[i-1]<<1)%mod\r\n \r\nf[0][0][0][0]=1\r\nif nums[1]!=0:\r\n f[1][1][0][1...
{"inputs": ["3 1\n-1 0 1", "2 1\n1 0", "1 1\n-1", "1 0\n-1", "1 1\n0", "5 1\n-1 -1 -1 -1 -1", "5 0\n-1 -1 -1 -1 -1", "10 1\n1 1 1 1 0 0 0 1 0 0", "50 1\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1", "20 1\n0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
1
aa950f6569484d8c8e06d95a3f7aaf3a
Boxes Packing
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *...
[ "n = input()\r\ndic = {}\r\nl = list(input().split())\r\nfor x in l:\r\n if x in dic:\r\n dic[x]+=1\r\n else:\r\n dic[x]=1\r\nprint(max(dic.values()))", "n=int(input())\nbox_no=n\nbox=input()\nbox=[int(i) for i in box.split()]\ndic={}\nfor i in box:\n if i not in dic:\n dic[i]=box.count(i)\nm=ma...
{"inputs": ["3\n1 2 3", "4\n4 2 4 3", "10\n58 58 58 58 58 58 58 58 58 58", "10\n86 89 89 86 86 89 86 86 89 89", "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 90...
UNKNOWN
PYTHON3
CODEFORCES
197
aa95201684f692785e83233e7b14292e
Cycle
A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes *u* and *v* (*u*<=≠<=*v*) exists either an edge going from *u* to *v*, or an edge from *v* to *u*. You are given a tournament consisting of *n* vertexes. Your tas...
[ "def f():\n p, q, n = [0], [0], int(input())\n input()\n for i in range(1, n):\n t = input()[:i]\n if '0' in t:\n if '1' in t:\n for l, j in enumerate(p):\n if t[j] == '1':\n for r, j in enumerate(q):\n ...
{"inputs": ["5\n00100\n10000\n01001\n11101\n11000", "5\n01111\n00000\n01000\n01100\n01110", "5\n01000\n00101\n10010\n11001\n10100", "5\n00110\n10110\n00011\n00000\n11010", "10\n0011000010\n1011001101\n0000101100\n0010101010\n1100000100\n1111101100\n1000100000\n1001001011\n0110111001\n1011111000", "10\n0111001000\n00111...
UNKNOWN
PYTHON3
CODEFORCES
1
aaa6c5a197701f18e7cecda2a36fc449
Endless Roses Most Beautiful
Arkady decided to buy roses for his girlfriend. A flower shop has white, orange and red roses, and the total amount of them is *n*. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and white roses. Also, Arkady won't buy a bouquet where all roses have t...
[ "import sys\r\n\r\n\r\ndef solve(first_color, second_color, need):\r\n if need < 2 or min(len(first_color), len(second_color)) < 1 or len(first_color) + len(second_color) < need:\r\n return -1\r\n total = -first_color[0] - second_color[0]\r\n temp = []\r\n for cur_iter in range(1, len(first_color...
{"inputs": ["5 3\n4 3 4 1 6\nRROWW", "5 2\n10 20 14 20 11\nRRRRR", "11 5\n5 6 3 2 3 4 7 5 4 5 6\nRWOORWORROW", "15 10\n8560 6244 9607 5137 7187 3217 5527 9919 282 8748 3529 6110 5767 521 3393\nOWRWOORWRORWWRO", "10 4\n1208 5835 2637 5827 3722 6837 3499 6438 43 5333\nWRRWRWRWRW", "13 3\n9675 8988 5499 6356 5083 6067 558...
UNKNOWN
PYTHON3
CODEFORCES
4
aaab33deadf08632a19f4bb503f27565
none
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a let...
[ "from sys import stdin,stdout\r\ninput,print = stdin.readline,stdout.write\r\nx,y = list(map(int,input().split()))\r\nans = \"\"\r\npos = True\r\nwhile True:\r\n if x>y:\r\n cur = (x-1)//y\r\n ans+=str(cur)+\"A\"\r\n x-=cur*y\r\n elif y>x:\r\n cur = (y-1)//x\r\n ans+=str(cur...
{"inputs": ["1 4", "2 2", "3 2", "2 1", "5 3", "5 2", "8 5", "97 101", "1 3", "1000000000000000000 999999999999999999", "55 89", "610 987", "4181 6765", "46368 75025", "832040 514229", "5702887 9227465", "701408733 433494437", "956722026041 591286729879", "498454011879264 806515533049393", "420196140727489673 679891637...
UNKNOWN
PYTHON3
CODEFORCES
16
aaae939c861210fcad59ff469f432ee8
Bakery
Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different c...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m, k = map(int, input().split())\r\ne = [tuple(map(int, input().split())) for _ in range(m)]\r\na = list(map(int, input().split()))\r\nz = [0] * (n + 1)\r\nfor i in a:\r\n z[i] = 1\r\ninf = pow(10, 9) + 1\r\nans = inf\r...
{"inputs": ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3", "2 3 1\n1 2 3\n1 2 18\n1 2 13\n2", "3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8", "4 13 1\n1 4 10\n1 3 6\n1 4 3\n3 4 1\n1 3 2\n1 2 15\n1 4 21\n1 4 20\n2 4 13\n1 4 7\n2 4 2\n1 2 8\n1 3 17\n1", "5 7 3\n2 3 20\n1 2 10\n1 2 11\n4 5 15\...
UNKNOWN
PYTHON3
CODEFORCES
23
aaaffe668fb66d099e8688f0232544af
Vessels
There is a system of *n* vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to *n*, in the order from the highest to the lowest, the volume of the *i*-th vessel is *a**i* liters. Initially, all the vessels are empty. In some vessels water is poured. All the w...
[ "#kylin1993\r\nn=int(input());\r\nwater=(n+2)*[0];\r\nvol=[int(i) for i in input().split()];\r\ntrace=(n+2)*[0];\r\nnext = [i+1 for i in range(n+2)];\r\nm=int(input());\r\nout=[]\r\nfor i in range(m):\r\n\tc=[int(i) for i in input().split()];\r\n\tif c[0]==1 :\r\n\t\tw=c[2];\r\n\t\tk=c[1]-1;\r\n\t\tr=0;\r\n\t\twhil...
{"inputs": ["2\n5 10\n6\n1 1 4\n2 1\n1 2 5\n1 1 4\n2 1\n2 2", "3\n5 10 8\n6\n1 1 12\n2 2\n1 1 6\n1 3 2\n2 2\n2 3", "10\n71 59 88 55 18 98 38 73 53 58\n20\n1 5 93\n1 7 69\n2 3\n1 1 20\n2 10\n1 6 74\n1 7 100\n1 9 14\n2 3\n2 4\n2 7\n1 3 31\n2 4\n1 6 64\n2 2\n2 2\n1 3 54\n2 9\n2 1\n1 6 86", "10\n3 7 10 1 5 4 4 3 3 1\n20\n2...
UNKNOWN
PYTHON3
CODEFORCES
5
aac6bac239d06f0aeceefefe8a47c5e9
Let's Watch Football
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
[ "if __name__ == \"__main__\":\r\n a, b, c = map(int, input().split())\r\n res = ((a * c) - (b * c)) / b\r\n if res == int(res):\r\n print(int(res))\r\n else:\r\n print(int(res) + 1)\r\n\r\n", "tamanho_video_p_sg, tamanho_podem_baixar, duracao = input().split()\n\nb = (int(tamanho_video_p...
{"inputs": ["4 1 1", "10 3 2", "13 12 1", "2 1 3", "6 2 4", "5 2 1", "2 1 1", "2 1 4", "5 1 5", "2 1 2", "60 16 1", "64 12 8", "66 38 4", "70 32 1", "24 12 12", "24 19 9", "244 87 4", "305 203 421", "888 777 1", "888 777 1000", "888 777 888", "5 4 10", "1000 1 1", "1000 1 1000", "1000 999 1", "1000 999 1000", "945 812 ...
UNKNOWN
PYTHON3
CODEFORCES
196
aaf53c3223958d02a7990a2f62318615
Remove Extra One
You are given a permutation *p* of length *n*. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers *a*1,<=*a*2,<=...,<=*a**k* the element *a**i* is a record if for every integer *j* (1<=≤<=*j*<=&lt;<=*i*) the following holds: *a**j*<=&lt;<=*a*...
[ "def zero():\n return 0\nfrom collections import defaultdict\nn = int(input())\np = [int(i) for i in input().split()]\nc=defaultdict(zero)\na,b=0,0\nfor i in range(n):\n if(p[i]>a):\n b=a\n a=p[i]\n c[p[i]]-=1\n \n elif p[i]>b:\n b=p[i]\n c[a]+=1\nres=1\nfor i in r...
{"inputs": ["1\n1", "5\n5 1 2 3 4", "5\n4 3 5 1 2", "9\n9 5 8 6 3 2 4 1 7", "3\n3 2 1", "7\n1 6 7 4 2 5 3", "48\n38 6 31 19 45 28 27 43 11 35 36 20 9 16 42 48 14 22 39 18 12 10 34 25 13 26 40 29 17 8 33 46 24 30 37 44 1 15 2 21 3 5 4 47 32 23 41 7", "26\n23 14 15 19 9 22 20 12 5 4 21 1 16 8 6 11 3 17 2 10 24 26 13 18 2...
UNKNOWN
PYTHON3
CODEFORCES
12