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 |
|---|---|---|---|---|---|---|---|---|---|
32b593c62c436e6641f62fa3556c9ea8 | Splitting in Teams | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | [
"n = int(input())\r\nlist_ = list(map(int,input().split()))\r\nnof_2 = list_.count(2)\r\nnof_1 = list_.count(1)\r\nsum = 0\r\n#print(nof_1,nof_2)\r\nif nof_2<=nof_1:\r\n sum+=nof_2\r\n nof_1-=nof_2\r\n sum+=(nof_1//3)\r\nelse:\r\n sum+=nof_1\r\n\r\nprint(sum)",
"n=int(input())\r\na=list(map(int,input(... | {"inputs": ["4\n1 1 2 1", "2\n2 2", "7\n2 2 2 1 1 1 1", "3\n1 1 1", "3\n2 2 2", "3\n1 2 1", "5\n2 2 1 1 1", "7\n1 1 2 2 1 2 1", "10\n1 2 2 1 2 2 1 2 1 1", "5\n2 2 2 1 2", "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2", "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 293 | |
32c40fe5862f7157a9677fdcb855a752 | Copying Data | We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.
More formally, you've got two arrays of integers *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=... | [
"import sys\r\n'''\r\nSEGMENT TREE\r\nAssign\r\n'''\r\nclass SegmTree():\r\n '''\r\n - modify elements on interval\r\n - get single element\r\n '''\r\n def __init__(self, size):\r\n N = 1\r\n while N < size:\r\n N <<= 1\r\n self.N = N\r\n self.tree = [0] * (2*N)... | {"inputs": ["5 10\n1 2 0 -1 3\n3 1 5 -2 0\n2 5\n1 3 3 3\n2 5\n2 4\n2 1\n1 2 1 4\n2 1\n2 4\n1 4 2 1\n2 2", "1 4\n-2\n1\n1 1 1 1\n2 1\n1 1 1 1\n1 1 1 1", "2 5\n-3 2\n3 -4\n1 1 1 2\n2 1\n2 1\n1 2 2 1\n2 1", "3 6\n4 -3 0\n1 3 -5\n2 2\n2 3\n1 2 1 2\n1 2 1 2\n2 2\n2 2", "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4", "10 10\n-1 1 -1 2 -2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
33553ad9c3a573ef7247b41c1bf0ebf7 | Kolya and Tanya | Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3*n* gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ... | [
"n = int(input())\r\nprint((3**(3*n)-7**n) % (int(1e9)+7))",
"def small(a, x):\r\n if x<10:\r\n return (a**x)%(10**9+7)\r\n if x%2==0:\r\n return (small(a, x//2)*small(a, x//2))%(10**9+7)\r\n else:\r\n return (a*small(a, x//2)*small(a, x//2))%(10**9+7)\r\n\r\ndef rec(a, b, x):\r\n ... | {"inputs": ["1", "2", "3", "4", "5", "7", "10", "14", "58000", "6", "8", "9", "15", "20", "22", "48", "74", "100", "866", "1673", "555", "2000", "9877", "5984", "2091", "10000", "10868", "66115", "62212", "100000", "2441", "18569", "69289", "85417", "68841", "10000", "4343", "12312", "5462", "100", "11", "100000"], "ou... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
337896c5b273e41731e70fbabf4b27e5 | none | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | [
"import re\ndef solve(s):\n return re.sub(r'ogo(?:go)*','***',s)\n \n\n \n\n \ndef main() :\n n = input()\n s = input()\n # arr = list(map(int, input().split(' ')))\n # arr = []\n # for _ in range(4):\n # i = input()\n # arr.append(i)\n print(solve(s))\nmain()\n",
"import sys, io, os\r\nimpo... | {"inputs": ["7\naogogob", "13\nogogmgogogogo", "9\nogoogoogo", "32\nabcdefogoghijklmnogoopqrstuvwxyz", "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo", "10\nogooggoggo", "20\nooggooogooogooogooog", "30\ngoggogoooggooggggoggoggoogoggo", "40\nogggogooggoogoogggo... | UNKNOWN | PYTHON3 | CODEFORCES | 285 | |
3399ed59347105551d7d5cb871498172 | Save Energy! | Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on.
During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. T... | [
"def give(n,d):\r\n if n%d:\r\n return n//d+1\r\n else:\r\n return n//d\r\n \r\nk,d,t=list(map(int,input().split()))\r\np=give(k,d)*d\r\nif d>=k: a=k\r\nelse: a=p-p%k\r\nq=(p-a)/2\r\nans=t//(a+q)*p\r\nr=t-t//(a+q)*(a+q)\r\nif r<=a:\r\n\tans+=r\r\nelse:\r\n\tans+=a\r\n\tr-=a\r\n\tans+=r*2\... | {"inputs": ["3 2 6", "4 2 20", "8 10 9", "43 50 140", "251 79 76", "892 67 1000", "1000 1000 1000", "87 4 1000", "1 629 384378949109878497", "2124 6621 12695", "27548 68747 111", "74974 46016 1000000000", "223 844 704", "1 558 743", "43 387 402", "972 2 763", "330 167 15", "387 43 650", "1 314 824", "2 4 18", "3 5 127"... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
33e5305fc23a3704e1479f3760b06f6f | Sum | Vasya has found a piece of paper with an array written on it. The array consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Vasya noticed that the following condition holds for the array *a**i*<=≤<=*a**i*<=+<=1<=≤<=2·*a**i* for any positive integer *i* (*i*<=<<=*n*).
Vasya wants to add either a "+" or a "-" before... | [
"n = int(input())\r\narr = list(map(int, input().split()))\r\nif n == 1:\r\n print('+')\r\nelif n == 2:\r\n print('-+')\r\nelse:\r\n ans = ['+']\r\n cur = arr[-1]\r\n for i in range(n - 2, -1, -1):\r\n if cur > 0:\r\n cur -= arr[i]\r\n ans.append('-')\r\n else:\r\n... | {"inputs": ["4\n1 2 3 5", "3\n3 3 5", "4\n2 4 5 6", "6\n3 5 10 11 12 20", "10\n10 14 17 22 43 72 74 84 88 93", "11\n3 6 7 11 13 16 26 52 63 97 97", "12\n3 3 4 7 14 26 51 65 72 72 85 92", "40\n3 3 3 6 10 10 18 19 34 66 107 150 191 286 346 661 1061 1620 2123 3679 5030 8736 10539 19659 38608 47853 53095 71391 135905 25521... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
33edfc25c7487cb0fc1143c0b9e271e8 | Anton and School - 2 | As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).
On the last lesson Anton learned about the regular simple bracket s... | [
"t = input()\r\nn, m = len(t) + 1, 1000000007\r\na, b = 0, t.count(')') - 1\r\nf = [1] * n\r\nfor i in range(2, n): f[i] = i * f[i - 1] % m\r\ng = [pow(q, m - 2, m) for q in f]\r\ns = 0\r\nfor q in t:\r\n if b < 0: break\r\n if q == '(':\r\n a += 1\r\n s += f[a + b] * g[a] * g[b]\r\n else: b ... | {"inputs": [")(()()", "()()()", ")))", ")())((((((()))()((()))()((()()()((()()()))", "(", ")", "((", "))", "()", ")(", "(()", "()(", ")()", ")((", "))(", "((((()())))())((((((()(()())(()())()((()()))(((())()()()(())))))()())())))(()()(()))))()(((()(((())()))())())))))(()()()((((((())(()())())()())(()))))()(()))(((()()(... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
34044ef3c5d0a272db7c2f9cd0dc4889 | Series of Crimes | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | [
"r,c = map(int,input().split())\r\nind_c =[]\r\nind = None\r\nfor i in range(r):\r\n s = input()\r\n if s.count('*') == 1:\r\n ind = [i,s.index('*')]\r\n elif s.count('*')>1:\r\n for j in range(c):\r\n if s[j] == '*':\r\n ind_c.append(j)\r\n \r\nif in... | {"inputs": ["3 2\n.*\n..\n**", "2 5\n*....\n*...*", "7 2\n..\n**\n..\n..\n..\n..\n.*", "7 2\n*.\n..\n..\n..\n..\n..\n**", "2 10\n*......*..\n.......*..", "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.", "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n... | UNKNOWN | PYTHON3 | CODEFORCES | 341 | |
3407ececc577e52f945b352b83675903 | Petya and Countryside | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | [
"n = int(input())\r\nheights = [int(x) for x in input().split()]\r\nleftCounter = [0] * n\r\nrightCounter = [0] * n\r\nfor i in range(1,n):\r\n if heights[i-1] <= heights[i]:\r\n leftCounter[i] = leftCounter[i-1] + 1\r\n if heights[n-i-1] >= heights[n-i]:\r\n rightCounter[n-i-1] = rightCounter[n... | {"inputs": ["1\n2", "5\n1 2 1 2 1", "8\n1 2 1 1 1 3 3 4", "10\n1 2 3 4 5 6 7 8 9 10", "10\n10 9 8 7 6 5 4 3 2 1", "2\n100 100", "3\n100 100 100", "11\n1 2 3 4 5 6 5 4 3 2 1", "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 5... | UNKNOWN | PYTHON3 | CODEFORCES | 409 | |
340c87239d4362efcde1f0ab2cb806df | Sereja and Brackets | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | [
"import io, os, sys\r\n\r\npypyin = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\ncpyin = sys.stdin.readline\r\ninput = pypyin if 'PyPy' in sys.version else cpyin\r\n\r\ndef strput():\r\n return input().decode() if 'PyPy' in sys.version else input()\r\n\r\n# code starts here\r\n\r\nclass SegmentTree:\r... | {"inputs": ["())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10", "(((((()((((((((((()((()(((((\n1\n8 15", "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n1 70\n1 19\n10 22\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
3417e3d9a9ea16b13582c2fc739d1b21 | Fish Weight | It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i*, then 0<=<<=*w*1<=≤<=*w*2<=≤<=...<=≤<=*w**k* holds.
Polar bears Alice and Bob each have cau... | [
"from collections import Counter\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\nn, m, k = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\n\r\na = Counter(a)\r\nfor x in b: a[x] -= 1\r\n\r\ncnt = 0\r\nfor x in sorted(a, reverse=True):\... | {"inputs": ["3 3 3\n2 2 2\n1 1 3", "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7", "5 5 10\n8 2 8 5 9\n9 1 7 5 1", "7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5", "15 15 10\n4 5 9 1 4 6 4 1 4 3 7 9 9 2 6\n6 6 7 7 2 9 1 6 10 9 7 10 7 10 9", "25 25 10\n10 6 2 1 9 7 2 5 6 9 2 3 2 8 5 8 2 9 10 8 9 7 7 4 8\n6 2 10 4 7 9 3 2 4 5 1 8 6 9 8 6 9 8 ... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
342e643c0d0a6a9c822577ccc2a5c0d8 | Splits | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
Th... | [
"# from dust i have come, dust i will be\r\n\r\nn=int(input())\r\nprint(n//2+1)",
"def code3(n):\r\n print(n//2+1)\r\ncode3(int(input()))\r\n",
"n=int(input())\nif n==1:\n print (1)\nelif n==2:\n print (2)\nelse:\n print (n//2+1)\n",
"n = int(input()) \r\nprint(1+n//2) \r\n",
"N = int(input())... | {"inputs": ["7", "8", "9", "1", "286", "48", "941", "45154", "60324", "91840", "41909", "58288", "91641", "62258", "79811", "88740", "12351", "1960", "29239", "85801", "43255", "13439", "35668", "19122", "60169", "50588", "2467", "39315", "29950", "17286", "7359066", "1016391", "7928871", "3968891", "2636452", "5076901... | UNKNOWN | PYTHON3 | CODEFORCES | 167 | |
344fab95a62f2e223e567ae427805ecc | Synchrophasotron | For some experiments little Petya needs a synchrophasotron. He has already got the device, all that's left is to set the fuel supply. Fuel comes through a system of nodes numbered from 1 to *n* and connected by pipes. Pipes go from every node with smaller number to every node with greater number. Fuel can only flow thr... | [
"import sys\nfrom functools import cache\n\n# input \nN, graph = 0, []\n# output\nflow, total_cost = -1, -1\n\ndef read_input():\n global N, graph, in_degree, out_degree\n readline = sys.stdin.readline\n N = int(readline().rstrip())\n graph = [[] for _ in range(N + 1)]\n m = N * (N - 1) // 2\n for... | {"inputs": ["2\n1 2 1 2 3", "3\n1 2 1 2 3\n1 3 0 0 0\n2 3 3 4 5", "4\n1 2 0 2 1\n2 3 0 2 1\n1 3 0 2 6\n1 4 0 0 1\n2 4 0 0 0\n3 4 2 3 0", "3\n1 2 0 2 1\n1 3 1 2 1\n2 3 1 2 1", "4\n3 4 2 2 6\n2 3 1 1 6\n1 2 1 3 1\n1 4 2 3 4\n2 4 0 3 2\n1 3 1 2 5", "6\n1 2 5 5 0\n1 3 0 5 0\n1 4 0 5 0\n1 5 0 5 0\n1 6 5 5 0\n2 3 0 5 0\n2 4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
34558fb2ad23f2817beb36abd1ad784f | Thief in a Shop | A thief made his way to a shop.
As usual he has his lucky knapsack with him. The knapsack can contain *k* objects. There are *n* kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind *i* is *a**i*.
The thief is greedy, so he will take exactly *k* products (it's... | [
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nMOD = 998244353\r\nIMAG = 911660635\r\nIIMAG = 86583718\r\nrate2 = (0, 911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601, 842657263, 730768835, 942482514, 806263778, 151565301, ... | {"inputs": ["3 2\n1 2 3", "5 5\n1 1 1 1 1", "3 3\n3 5 11", "10 3\n3 4 12 5 7 13 5 6 1 6", "10 3\n1 2 3 4 5 6 7 8 9 10", "10 1000\n630 764 679 16 34 691 778 366 982 30", "3 1000\n674 751 563", "13 1000\n494 391 821 980 716 237 801 893 765 946 338 656 698", "4 973\n40 32 21 21", "100 100\n6 7 100 8 5 61 5 75 59 65 51 47 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
347dc5817edcdfb675a5ae884dd312b4 | Accounting | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | [
"import sys\r\nq,w,num = map(int,input().split())\r\n \r\nfor p in range(-1000,1001):\r\n if q*(p**num)== w:\r\n print(p)\r\n sys.exit()\r\nprint(\"No solution\")",
"a, b, n = map(int, input().split())\r\ncheck = False\r\nfor i in range(-1000, 1001):\r\n if a * i ** n == b:\r\n print(i)... | {"inputs": ["2 18 2", "-1 8 3", "0 0 10", "1 16 5", "0 1 2", "3 0 4", "1 1000 1", "7 896 7", "4 972 1", "-1 -1 5", "-1 0 4", "-7 0 1", "-5 -5 3", "-5 -5 9", "-5 -5 6", "-4 0 1", "-5 0 3", "-4 4 9", "10 0 6", "-5 3 4", "0 3 6", "3 6 10", "-3 7 5", "-526 526 1", "-373 373 3", "-141 0 8", "7 175 1", "-5 -560 1", "-1 -512 ... | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
34da494efdcd2edb25622a0a0d9ff23f | Removing Columns | You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
we obtain the table:
A table is called... | [
"n, m = map(int, input().split())\r\ns = list(input() for _ in range(n)) \r\nres, t = 0, [0] * n\r\nfor i in range(m):\r\n for j in range(n-1):\r\n if not t[j] and s[j][i] > s[j+1][i]:\r\n res += 1\r\n break\r\n else:\r\n for j in range(n-1):\r\n t[j] = t[j] or s... | {"inputs": ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces", "2 2\nfb\nye", "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrzh", "10 10\nddorannorz\nmdrnzqvqgo\ngdtdjmlsuf\neoxbrntqdp\nhribwlslgo\newlqrontvk\nnxibmnawnh\nvxiwdjvdom\nhyhhewmzmp\niysgvzayst", "9 7\nygqartj\nlgwxlqv\nancjjpr\nw... | UNKNOWN | PYTHON3 | CODEFORCES | 70 | |
34daa3e2403efa872cf4d014beb68904 | 1-2-3 | Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice".
... | [
"k,a,b = map(int,input().split())\r\nA = []\r\nB = []\r\ncheck = {}\r\nfor i in range(3):\r\n A.append(list(map(int,input().split())))\r\nfor i in range(3):\r\n B.append(list(map(int, input().split())))\r\ncountA = 0\r\ncountB = 0\r\nbeen = True\r\ni = 0\r\nwhile(i<k):\r\n if (a, b) in check and been:\r\n ... | {"inputs": ["10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2", "8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3", "5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2", "1 1 1\n3 3 1\n1 1 1\n3 2 2\n2 2 2\n1 3 1\n3 3 2", "1 3 1\n1 3 3\n2 3 2\n2 1 3\n1 3 2\n3 3 2\n3 1 1", "10 2 1\n2 2 1\n3 2 2\n3 1 3\n3 1 3\n1 2 2\n3 3 2", ... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
34dbf16cc55730780ff1f7789f263b4d | Picking Strings | Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:
- A BC - B AC - C AB - AAA empty string
Note that a substring is one or more consecutive characters. For given queries, determine whether it is ... | [
"a = input()\r\nb = input()\r\n\r\nw = [0]\r\nx = [0]\r\nfor i in a:\r\n if i == 'A':\r\n w.append(w[-1]+1)\r\n x.append(x[-1])\r\n else:\r\n w.append(0)\r\n x.append(x[-1]+1)\r\ny = [0]\r\nz = [0]\r\nfor i in b:\r\n if i == 'A':\r\n y.append(y[-1]+1)\r\n z.append(... | {"inputs": ["AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3", "AAAAAA\nAAAAAA\n30\n3 4 1 2\n3 3 4 4\n5 6 3 4\n3 3 2 3\n6 6 1 5\n2 4 4 6\n1 6 2 5\n6 6 3 4\n3 5 1 4\n4 5 3 6\n2 3 2 4\n3 4 4 4\n6 6 4 6\n3 3 2 5\n1 5 3 3\n4 6 1 2\n6 6 6 6\n3 3 3 4\n6 6 6 6\n5 6 4 4\n6 6 5 5\n2 3 1 4\n3 6 4 5\n3 5 6 6\n4 5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
3515fc2a1fbcc6446b9110ce2fe061c5 | none | On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
... | [
"n,m=map(int,input().split())\r\na=[];row=[];col=[]\r\nfor i in range(n):\r\n a.append(list(map(int,input().split())))\r\nif m>n:\r\n for i in range(n):\r\n row.append(min(a[i]))\r\n for i in range(m):\r\n col.append(a[0][i]-row[0])\r\nelse:\r\n for i in range(m):\r\n r=1000\r\n ... | {"inputs": ["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1", "3 5\n2 4 2 2 3\n0 2 0 0 1\n1 3 1 1 2", "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "9 10\n14 5 6 4 8 9 4 14 14 13\n13 4 5 3 7 8 3 13 13 12\n16 7 8 6 10 11 6 16 16 15\n10 1 2 0 4 5 0 10 10 9\n11 2 3 1 5 6 1 11 11 10\... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
351bdba27ec36bf894c8f6e8f3d2d4f6 | Link/Cut Tree | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | [
"def x():\n l, r, k = [int(s) for s in input().split()]\n res = k\n if l == 1:\n yield 1\n while k<=r:\n if l <= k <= r:\n yield k\n k*=res\n if k>r:\n break\nd = [i for i in x()]\nif len(d):\n print(*d)\nelse:\n print(-1)\n",
"l,r,k=map(int,inpu... | {"inputs": ["1 10 2", "2 4 5", "18102 43332383920 28554", "19562 31702689720 17701", "11729 55221128400 313", "5482 100347128000 342", "3680 37745933600 10", "17098 191120104800 43", "10462 418807699200 2", "30061 641846400000 3", "1 1000000000000000000 2", "32 2498039712000 4", "1 2576683920000 2", "5 25 5", "1 90 90"... | UNKNOWN | PYTHON3 | CODEFORCES | 291 | |
351d38b093b038b4adf2014310a08cf4 | Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph with *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you tw... | [
"import io , os , sys\r\n\r\ninput = io . BytesIO ( os . read ( 0 , os . fstat ( 0 ) . st_size ) ) . readline\r\n\r\ndef print ( *values , sep = \" \" , end = \"\\n\" ) :\r\n sep = str ( sep )\r\n end = str ( end )\r\n for i in range ( len ( values ) -1 ) :\r\n sys.stdout.write( str( values[i] ) )\r... | {"inputs": ["4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "2 1\n1 2 1\n1\n1 2", "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2"], "outputs": ["2\n1\n0", "1\n1\n1\n1\n2", "1", "3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3537031fc4532bfb7e6075640be51fb9 | Sockets | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | [
"n, m, k = map(int, input().split())\r\nv = list(map(int, input().split()))\r\n\r\navailable = 0\r\nv.sort(reverse = True)\r\nans = -1\r\n\r\nif k >= m:\r\n ans = 0\r\nelse:\r\n for i in range(n):\r\n if i < k:\r\n available += v[i]\r\n else:\r\n available += v[i]-1\r\n ... | {"inputs": ["3 5 3\n3 1 2", "4 7 2\n3 3 2 4", "5 5 1\n1 3 1 2 1", "4 5 8\n3 2 4 3", "5 10 1\n4 3 4 2 4", "7 13 2\n5 3 4 1 2 1 2", "7 17 5\n1 6 2 1 1 4 3", "10 25 7\n5 7 4 8 3 3 5 4 5 5", "10 8 4\n1 1 2 1 3 1 3 1 4 2", "13 20 9\n2 9 2 2 5 11 10 10 13 4 6 11 14", "9 30 8\n3 6 10 8 1 5 3 9 3", "15 26 4\n3 6 7 1 5 2 4 4 7 ... | UNKNOWN | PYTHON3 | CODEFORCES | 86 | |
3553127609b2c2c91915f8e356fcb797 | Parquet | Once Bob decided to lay a parquet floor in his living room. The living room is of size *n*<=×<=*m* metres. Bob had planks of three types: *a* planks 1<=×<=2 meters, *b* planks 2<=×<=1 meters, and *c* planks 2<=×<=2 meters. Help Bob find out, if it is possible to parquet the living room with such a set of planks, and if... | [
"n, m, a, b, c = map(int, input().split())\r\nmat = [0]*n\r\nfor i in range(n):\r\n mat[i] = [0] * m\r\nn1 = [min(n*m//4, c), min(m//2 * n, a), min(n//2 * m, b)]\r\np = ['c', 'a', 'b']\r\nz = ['d', 'e', 'f', 'g']\r\nz1 = ['m', 'n', 'u', 'o']\r\nz2 = ['p', 'q', 'r', 'w']\r\n#print(n1)\r\ndef fill(h, w):\r\n if... | {"inputs": ["2 6 2 2 1", "1 1 100 100 100", "4 4 10 10 10", "2 2 0 0 1", "2 3 2 1 0", "3 2 1 0 1", "7 7 9 7 4", "8 10 2 2 18", "29 10 89 28 14", "56 59 982 294 188", "80 80 668 62 1235", "100 100 2208 1898 447", "100 100 2474 270 1128", "100 100 570 808 1811", "99 100 1146 3732 36", "95 100 2574 1056 560", "97 100 58 1... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
355c9baf71d3c5cab2adeb90c9135a4f | Proper Nutrition | Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* bu... | [
"import sys\r\n\r\nn = int(input())\r\na = int(input())\r\nb = int(input())\r\n\r\nfor i in range((n // a) + 1):\r\n if (n - (i * a)) % b == 0:\r\n print(\"YES\")\r\n print(i, (n - (i * a)) // b)\r\n sys.exit()\r\nprint(\"NO\")\r\n",
"n = int(input())\r\na = int(input())\r\nb = int(input()... | {"inputs": ["7\n2\n3", "100\n25\n10", "15\n4\n8", "9960594\n2551\n2557", "10000000\n1\n1", "9999999\n9999\n9999", "9963629\n2591\n2593", "1\n7\n8", "9963630\n2591\n2593", "7516066\n1601\n4793", "6509546\n1607\n6221", "2756250\n8783\n29", "7817510\n2377\n743", "6087210\n1583\n1997", "4\n2\n2", "7996960\n4457\n5387", "79... | UNKNOWN | PYTHON3 | CODEFORCES | 55 | |
35755a4888abe3b1581d52fd89d4a9aa | Zbazi in Zeydabad | A tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).
The country Zeydabad is a rectangular table consisting of *n* rows and *m* columns. Each cell on the country is either 'z' or '.'.
The tourist knows this country is named Zeydabad because there are lots of ''Z-pattern"s in the country. A ... | [
"import sys\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n#################################################... | {"inputs": ["4 4\nzzzz\nzzz.\n.z..\nzzzz", "1 4\nz.z.", "2 2\nzz\nzz"], "outputs": ["16", "2", "5"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
359e28c8ab146c95acd465504924699d | none | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — *a* and *b*. The order of the numbers is not important. Let's consider *a*<=≤<=*b* for the sake of definiteness. The players can cast one of the two spells in turns:
- Replace *b* with *b*<=-<=*a**k*. Number... | [
"\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict, deque, Counter\r\nfrom heapq import heappop, heappush\r\nfrom bisect import bisect_left, bisect_right\r\nfrom math import gcd\r\n\r\ndef sol():\r\n n,m = map(int,input().split())\r\n if m > n:\r\n n,m = m,n\r\n ord... | {"inputs": ["4\n10 21\n31 10\n0 1\n10 30", "66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n3 3\n100000000000 1000000000000000000\n0 1\n4 1\n2 6\n5 5\n4 3\n0 3\n3 7\n3 1\n1 0\n4 4\n1000000000000000000 100000000000\n7 6\n4 2\n7 5\... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
35a0480187633dd2e1d868bcfd998504 | Adding Digits | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | [
"a,b,n = map(int,input().split())\r\ncheck = 1\r\nif a%b==0:\r\n print(a*(10**n))\r\nelse:\r\n check = 0\r\n for y in range(10):\r\n if (a*10+y)%b==0:\r\n a = a*10+y\r\n check = 1\r\n break\r\n else:\r\n pass\r\n if check==0:\r\n print(-1)... | {"inputs": ["5 4 5", "12 11 1", "260 150 10", "78843 5684 42717", "93248 91435 1133", "100000 10 64479", "99999 21 73839", "99991 623 36438", "99999 334 94854", "99252 9827 84849", "99313 9833 10561", "94885 55815 11417", "99492 58525 53481", "99858 28531 79193", "99136 47208 42607", "63270 19953 5555", "10240 128 1000... | UNKNOWN | PYTHON3 | CODEFORCES | 265 | |
35a50ea38e4221ed5865e1c798e31f70 | Queue | During the lunch break all *n* Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID ... | [
"n = int(input())\ncd = set()\ntrace = {}\nnodes = set()\n\nfor _ in range(n):\n a, b = input().split()\n if a == '0':\n a = 'start'\n if b == '0':\n b = 'end'\n cd.add(b)\n nodes.add(a)\n nodes.add(b)\n trace[a] = b\n\nfirst, second = -1, trace.get('start')\nfor nd in nodes:\n ... | {"inputs": ["4\n92 31\n0 7\n31 0\n7 141", "2\n0 1\n2 0", "3\n0 2\n1 3\n2 0", "4\n101 0\n0 102\n102 100\n103 101", "5\n0 1\n1 4\n4 0\n3 2\n5 3", "6\n10001 0\n0 10005\n10003 10001\n10002 10000\n10005 10002\n10004 10003", "3\n0 743259\n72866 70294\n743259 0", "4\n263750 0\n513707 263750\n0 718595\n718595 148112", "5\n6458... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
35bbecc566196fcd74d783f982cc2af3 | Fuzzy Search | Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings consisting of letters 'A', 'T', 'G' and 'C'.
Let's consider the following scenario. There is a fragment of a human DNA chain, recorded as a st... | [
"if True:\r\n from io import BytesIO, IOBase\r\n import math\r\n\r\n import random\r\n import sys\r\n import os\r\n\r\n import bisect\r\n import typing\r\n from collections import Counter, defaultdict, deque\r\n from copy import deepcopy\r\n from functools import cmp_to_key, lru_cache,... | {"inputs": ["10 4 1\nAGCAATTCAT\nACAT", "1 1 0\nA\nA", "1 1 0\nA\nT", "1 1 1\nA\nT", "5 3 0\nATATA\nATA", "5 3 1\nATATA\nATA", "7 1 2\nATGCGTA\nA", "7 1 3\nATGCGTA\nA", "4 4 0\nATGC\nGCTA", "4 4 1\nATGC\nGCTA", "4 4 2\nATGC\nGCTA"], "outputs": ["3", "1", "0", "0", "2", "3", "6", "7", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
35f59990d3bb3ade5fa8445f532d08bd | Mike and Shortcuts | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Wal... | [
"import sys\n\ninput = sys.stdin.readline\nn = int(input())\na = list(map(int, input().split()))\ndp = [-1] * n\ndp[0] = 0\nque = [0]\n\nwhile que:\n k = que.pop(0)\n for v in [k - 1, k + 1, a[k] - 1]:\n if 0 <= v < n and dp[v] == -1:\n dp[v] = dp[k] + 1\n que.append(v)\n\nprint(*... | {"inputs": ["3\n2 2 3", "5\n1 2 3 4 5", "7\n4 4 4 4 7 7 7", "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 90 90 90 90 90 90 90 90 90 90 90 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 ... | UNKNOWN | PYTHON3 | CODEFORCES | 112 | |
360d5ca53c21826c3cdfaeaf31bc161f | Degree Set | You are given a sequence of *n* positive integers *d*1,<=*d*2,<=...,<=*d**n* (*d*1<=<<=*d*2<=<<=...<=<<=*d**n*). Your task is to construct an undirected graph such that:
- there are exactly *d**n*<=+<=1 vertices; - there are no self-loops; - there are no multiple edges; - there are no more than 106 edges;... | [
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\ndef solve(d):\r\n if len(d)==0:\r\n return []\r\n if len(d)==1:\r\n edge=[]\r\n m=d[0]\r\n for i in range(1,m+2):\r\n for j in range(i+1,m+2):\r\n edge.append((i,j))\r\n return edge\r\n \r\n e=[]\r\n m=len(d)\r\n d0=d[0]\r\n... | {"inputs": ["3\n2 3 4", "3\n1 2 3", "4\n1 3 4 6", "1\n1", "1\n1000", "2\n1 2", "2\n999 1000", "2\n1 1000", "3\n1 500 1000", "10\n1 2 3 4 5 6 7 8 9 10", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
361c65a707055feadf945f9300058ab5 | Game of the Rows | Daenerys Targaryen has an army consisting of *k* groups of soldiers, the *i*-th group contains *a**i* soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has *n* rows, each of them has 8 seats. We ... | [
"from sys import stdin\r\n\r\nn,k = [int(x) for x in stdin.readline().split()]\r\na = [int(x) for x in stdin.readline().split()]\r\n\r\nfour = n\r\ntwo = 2*n\r\none = 0\r\n\r\nfor i,x in enumerate(a):\r\n f = min(four,x//4)\r\n four -= f\r\n a[i] -= f*4\r\n\r\nif four:\r\n a.sort(reverse=True)\r\n v = True\r\n... | {"inputs": ["2 2\n5 8", "1 2\n7 1", "1 2\n4 4", "1 4\n2 2 1 2", "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 1... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
362156831077fb306342d4c49eb233dc | Socks | Arseniy is already grown-up and independent. His mother decided to leave him alone for *m* days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.
Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular c... | [
"n, m, k = map(int, input().split())\n\nlst = list(input().split())\nlsta = [[] for i in range(n)]\n\nfor i in range(m):\n li, ri = map(int, input().split())\n lsta[li - 1].append(ri - 1)\n lsta[ri - 1].append(li - 1)\nvisited = [False for i in range(n)]\nans = 0\n\nfor i in range(n):\n if visited[i]:\n... | {"inputs": ["3 2 3\n1 2 3\n1 2\n2 3", "3 2 2\n1 1 2\n1 2\n2 1", "3 3 3\n1 2 3\n1 2\n2 3\n3 1", "4 2 4\n1 2 3 4\n1 2\n3 4", "10 3 2\n2 1 1 2 1 1 2 1 2 2\n4 10\n9 3\n5 7", "10 3 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n8 10", "4 3 2\n1 1 2 2\n1 2\n3 4\n2 3", "4 3 4\n1 2 3 4\n1 2\n3 4\n4 1"], "outputs": ["2", "0", "2", "2", "2"... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
362feba21c62cb2d514cc00014d0d4ca | Road Widening | Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!
The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o... | [
"n = int(input())\r\ns = [0]*n\r\ng = [0]*n\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n s[i] = a\r\n g[i] = a+b\r\n\r\nfor i in range(1,n):\r\n g[i] = min(g[i],g[i-1]+1)\r\nfor i in range(n-2,-1,-1):\r\n g[i] = min(g[i],g[i+1]+1)\r\n\r\nans = 0\r\nfor i in range(n):\r\n if s[i] <=... | {"inputs": ["3\n4 5\n4 5\n4 10", "4\n1 100\n100 1\n1 100\n100 1", "3\n1 1\n100 100\n1 1", "10\n21005 10850\n27020 13372\n28183 3724\n22874 13564\n27446 11493\n22522 10012\n24819 11529\n24166 11084\n24539 9211\n24152 9235", "1\n1 0", "1\n1 1000000", "1\n1000000 1000000", "1\n1 0", "1\n1 0", "1\n1 1", "2\n2 2\n1 1", "2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
363712d886c67d89c4774c1ab80e1323 | Vanya and Lanterns | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | [
"n, l = map(int, input().split())\r\nlanterns = list(map(int, input().split()))\r\n\r\nlanterns.sort()\r\n\r\nmax_gap = 0\r\nfor i in range(1, n):\r\n max_gap = max(max_gap, lanterns[i] - lanterns[i - 1])\r\n\r\nradius = max(max(lanterns[0], l - lanterns[-1]), max_gap / 2)\r\n\r\nprint(\"{:.10f}\".format(radius)... | {"inputs": ["7 15\n15 5 3 7 9 14 0", "2 5\n2 5", "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 ... | UNKNOWN | PYTHON3 | CODEFORCES | 247 | |
365b239ca6df2157eeed016988a58111 | String Manipulation 1.0 | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can... | [
"from collections import defaultdict\r\nk = int(input())\r\ns = input()\r\nd = defaultdict(list)\r\nword = list(s*k)\r\nfor i in range(len(word)):\r\n d[word[i]].append(i)\r\nn = int(input())\r\nfor _ in range(n):\r\n a,b = input().split()\r\n a = int(a)\r\n change = d[b].pop(a-1)\r\n word[change] = ... | {"inputs": ["2\nbac\n3\n2 a\n1 b\n2 c", "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b", "1\naabbabbb\n7\n2 a\n1 a\n1 a\n2 b\n1 b\n3 b\n1 b", "1\na\n0", "4\ndb\n5\n1 d\n2 d\n2 b\n1 d\n2 b", "10\nbabcbcbcba\n40\n24 b\n14 a\n19 b\n25 b\n26 c\n7 c\n5 c\n2 a\n4 c\n7 a\n46 b\n14 a\n28 b\n4 c\n5 a\n10 c\n4 c\n4 b\n12 a\n4 a\n30 b\n4 a\n... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
36647db424d1b4e3c8cb6f7a5bff699e | Run For Your Prize | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these tw... | [
"import sys,math,itertools\r\nfrom collections import Counter,deque,defaultdict\r\nfrom bisect import bisect_left,bisect_right \r\nfrom heapq import heappop,heappush,heapify, nlargest\r\nfrom copy import deepcopy\r\nmod = 10**9+7\r\nINF = float('inf')\r\ndef inp(): return int(sys.stdin.readline())\r\ndef inpl(): re... | {"inputs": ["3\n2 3 9", "2\n2 999995", "1\n20", "6\n2 3 500000 999997 999998 999999", "1\n999999", "1\n510000", "3\n2 5 27", "2\n600000 800000", "5\n2 5 6 27 29", "1\n500001", "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "1\n900000", "1\n500000", "1\n999998", "3\n999997 999998 999999", "2\n999997 9... | UNKNOWN | PYTHON3 | CODEFORCES | 139 | |
366f6a376c67748485aab11d0553e116 | One Bomb | You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls ... | [
"n, lines = int(input().split(' ')[0]), []\r\nfor i in range(0, n):\r\n line = input()\r\n lines.append(line)\r\nrc, cc, total = [0]*n, [0]*len(lines[0]), 0\r\nfor i, line in enumerate(lines):\r\n for j, ch in enumerate(line):\r\n if ch == \"*\":\r\n rc[i] += 1\r\n cc[j] += 1\r... | {"inputs": ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..", "1 10\n**********", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*", "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*", "10 10\n.........*\n........ | UNKNOWN | PYTHON3 | CODEFORCES | 44 | |
37208f991037cb5e2d4dcaa11439e2a7 | Stack Sorting | Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty).
You may perform the following operations until both *a* and *s* are empty:
- Take the first element of *a*, push it into *s* and remove it from *a* (if *a* is not empty); - Take the top element from *s*, appe... | [
"import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**15\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().spli... | {"inputs": ["5 3\n3 2 1", "5 3\n2 3 1", "5 1\n3", "5 2\n3 4", "100000 1\n98419", "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3", "10 1\n6", "100000 2\n64398 63673", "20 18\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16", "10 2\n3 7", "100000 3\n43791 91790 34124", "20 17\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 1... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
3779847abee2f9fe6408a04982f8ab8c | Magic Formulas | People in the Tomskaya region like magic formulas very much. You can see some of them below.
Imagine you are given a sequence of positive integer numbers *p*1, *p*2, ..., *p**n*. Lets write down some magic formulas:
Here, "mod" means the operation of taking the residue after dividing.
The expression means applying ... | [
"# eople in the Tomskaya region like magic formulas very much. You can see some of them below.\n\n# Imagine you are given a sequence of positive integer numbers p1, p2, ..., pn. Lets write down some magic formulas:\n\n\n\n# Here, \"mod\" means the operation of taking the residue after dividing.\n\n# The expression ... | {"inputs": ["3\n1 2 3", "1\n0", "2\n65535 0", "10\n1356106972 165139648 978829595 410669403 873711167 287346624 117863440 228957745 835903650 1575323015", "20\n1999581813 313463235 1733614990 662007911 1789348031 1120800519 196972430 1579897311 191001928 241720485 1426288783 1103088596 839698523 1974815116 77040208 904... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
378178d27a3bda3a7b1f7222ba920c1a | Generate a String | zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of *n* letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him *x* seconds to insert or delete a letter... | [
"n,x,y=map(int,input().split())\r\nm=2*10**7+100\r\ndp=[1<<60]*m\r\ndp[1]=x\r\ndp[2]=min(2*x,x+y)\r\nfor i in range(2,m//2):\r\n dp[2*i-1]=dp[2*i-2]+x\r\n dp[2*i]=dp[2*i-1]+x\r\n dp[2*i]=min(dp[2*i],dp[i]+y)\r\n dp[2*i-1]=min(dp[2*i-1],dp[2*i]+x)\r\n\r\nprint(dp[n])",
"n,x,y = map(int,input().split())\r\ndp =... | {"inputs": ["8 1 1", "8 1 10", "10 62 99", "88 417 591", "57 5289 8444", "382 81437847 324871127", "244 575154303 436759189", "85 902510038 553915152", "1926 84641582 820814219", "3768 561740421 232937477", "2313 184063453 204869248", "35896 278270961 253614967", "483867 138842067 556741142", "4528217 187553422 9567316... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
37bdb804b3a8f89ec2cce9cc72ad2faf | Vladik and fractions | Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer *n* he can represent fraction as a sum of three distinct positive fractions in form .
Help Vladik with that, i.e for a given *n* find three distinct positive integers *x*, *y* and *z* such that . Because ... | [
"# link: https://codeforces.com/problemset/problem/743/C\r\n\r\nfor _ in range(1):\r\n n = int(input())\r\n ans = -1\r\n if n != 1:\r\n a = n \r\n b = n + 1\r\n c = b * a\r\n if a!=b and b!=c and a!=c:\r\n print(a,b,c)\r\n else: print(ans)\r\n else: ... | {"inputs": ["3", "7", "2", "5", "4", "7", "82", "56", "30", "79", "28", "4116", "1", "6491", "8865", "1239", "3614", "5988", "8363", "737", "3112", "9562", "1936", "4311", "6685", "9060", "1434", "3809", "6183", "8558", "932", "7274", "9648", "2023", "4397", "6772", "9146", "1521", "4938", "6143", "6230", "10000", "1",... | UNKNOWN | PYTHON3 | CODEFORCES | 87 | |
37d4336f42407eff62c58aca172c1ac5 | Two Problems | A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.
He knows that the c... | [
"x, t, a, b, da, db = map(int, input().split())\r\nA = [0] + [a-i*da for i in range(t)]\r\nB = {0} | {b-i*db for i in range(t)}\r\n\r\nprint('YES' if any(x-a in B for a in A) else 'NO')",
"def main():\r\n x, t, a, b, da, db = map(int, input().split())\r\n\r\n possible_a = [0]\r\n possible_b = [0]\r\n ... | {"inputs": ["30 5 20 20 3 5", "10 4 100 5 5 1", "0 7 30 50 3 4", "50 10 30 20 1 2", "40 1 40 5 11 2", "35 8 20 20 1 2", "10 2 27 4 11 1", "64 12 258 141 10 7", "5 3 11 100 2 4", "5 4 11 80 2 4", "28 3 16 20 3 10", "6 2 11 1 11 1", "15 5 230 213 32 25", "223 92 123 118 1 1", "375 6 133 267 19 36", "80 5 39 40 1 1", "543... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
37e42fdcd1037129a1f34ce83dd72e75 | Problem of offices | Earlier, when there was no Internet, each bank had a lot of offices all around Bankopolis, and it caused a lot of problems. Namely, each day the bank had to collect cash from all the offices.
Once Oleg the bank client heard a dialogue of two cash collectors. Each day they traveled through all the departments and offic... | [
"n=int(input())\r\nnum=input().split(' ')\r\nl=[0]*4\r\nfor i in range(4):\r\n l[i]=int(num[i])\r\nt=tuple(l)\r\na,b,c,d=t\r\np=[0]*(n+1)\r\nnum=input().split(' ')\r\nmp=[list() for _ in range(n+1)]\r\nfor i in range(2,n+1):\r\n p[i]=int(num[i-2])\r\n \r\n mp[p[i]].append(i)\r\ns=[0]*(n+1)\r\ndef sof(i)... | {"inputs": ["5\n2 3 4 5\n1 1 1 1", "10\n3 8 9 10\n1 2 2 2 2 2 1 1 1", "13\n13 12 9 7\n1 1 1 1 5 5 2 2 2 3 3 4", "11\n2 4 9 11\n1 1 3 3 3 3 3 1 1 10", "11\n4 2 9 11\n1 1 3 3 3 3 3 1 1 10", "6\n2 3 4 5\n1 1 1 1 1", "15\n3 9 15 13\n1 2 2 1 5 5 1 8 1 10 1 12 1 14", "15\n8 13 5 10\n1 2 1 4 1 6 6 1 9 1 11 12 1 14", "15\n15 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
37eadde8522bad99e820e7f5d7ae04d2 | Partition | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | [
"n = int(input())\nb, c = 0, 0\nfor i in map(int, input().split()):\n if i < 0:\n c += i\n else:\n b += i\n\nprint(b - c)\n\n \t \t\t \t \t \t \t \t\t \t \t \t",
"n=int(input())\r\nA=input().split()\r\nB,C=[],[]\r\nfor i in range(n):\r\n A[i]=int(A[i])\r\n if A[i]>0:\r\n ... | {"inputs": ["3\n1 -2 0", "6\n16 23 16 15 42 8", "1\n-1", "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -1... | UNKNOWN | PYTHON3 | CODEFORCES | 390 | |
37f46064990b21a89a9ebaabdcaa6116 | Little Elephant and Bits | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | [
"s=str(int(input()))\r\nflag=False\r\nfor i in range(0,len(s)):\r\n if(s[i]=='0' and flag==False):\r\n flag=True\r\n elif(flag==False and i==len(s)-1):\r\n flag=True\r\n else:\r\n print(s[i],end='')\r\n \r\n",
"s = input() \r\nfor idx in range(len(s)):\r\n if s[idx] == \"0\":\r... | {"inputs": ["101", "110010", "10000", "1111111110", "10100101011110101", "111010010111", "11110111011100000000", "11110010010100001110110101110011110110100111101", "1001011111010010100111111", "1111111111", "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "11010110... | UNKNOWN | PYTHON3 | CODEFORCES | 540 | |
37f844d788fd8dae07bad399725a4218 | Vasily the Bear and Fly | One beautiful day Vasily the bear painted 2*m* circles of the same radius *R* on a coordinate plane. Circles with numbers from 1 to *m* had centers at points (2*R*<=-<=*R*,<=0), (4*R*<=-<=*R*,<=0), ..., (2*Rm*<=-<=*R*,<=0), respectively. Circles with numbers from *m*<=+<=1 to 2*m* had centers at points (2*R*<=-<=*R*,<=... | [
"import math\n\nm,R = map (int,input().split())\n\nD = math.sqrt (2) * R\nresult = 0\n\ndef sum_dist (n):\n return n*(n+1)*R + 2*D*n\n\nfor i in range (1,m+1):\n result += 2*R\n if i-1 > 0: result += 2*R + D\n if m-i > 0: result += 2*R + D\n if i-2 > 0: result += sum_dist (i-2)\n if m-i-1 > 0: result +=... | {"inputs": ["1 1", "2 2", "100000 3", "2344 5", "999 10", "6 1", "43 4", "3333 3", "4444 4", "100000 10", "3134 9", "9 9", "32 9", "33333 9", "99999 1", "99999 9", "99999 7", "4234 4", "66666 6", "66666 9", "67676 7", "7777 7", "7656 2", "2 8", "2 10", "2 4", "8 1", "8 8", "92399 1", "1 10", "3 1"], "outputs": ["2.0000... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
38108be8e55699235894cccfaad42904 | Berland Federalization | Recently, Berland faces federalization requests more and more often. The proponents propose to divide the country into separate states. Moreover, they demand that there is a state which includes exactly *k* towns.
Currently, Berland has *n* towns, some pairs of them are connected by bilateral roads. Berland has only *... | [
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nclass Graph:\r\n def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float(\"inf\")):\r\n self.V=V\r\n self.directed=directed\r\n self.weighted=weighted\r\n self.inf=inf\r\n if graph:\r\n sel... | {"inputs": ["5 2\n1 2\n2 3\n3 4\n4 5", "5 3\n1 2\n1 3\n1 4\n1 5", "1 1", "11 4\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11", "11 10\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11", "12 3\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11\n11 12", "12 6\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11\n... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
386d4f4859cedad536c80392fb1a9f57 | none | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | [
"import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().spli... | {"inputs": ["5\n01 0\n2 1\n2extra 0\n3 1\n99 0", "2\n1 0\n2 1", "5\n1 0\n11 1\n111 0\n1111 1\n11111 0", "4\nir7oz8 1\nvj4v5t 1\nkwkahb 1\nj5s8o1 0", "4\n3 1\n1o0bp2 0\n9tn379 0\nv04v6j 1", "4\n1 0\nsc7czx 0\nfr4033 1\n3 0", "4\n4 0\n1 0\n2 0\nizfotg 1", "4\n2 0\n3 0\n1 1\n4 1", "5\npuusew 1\npvoy4h 0\nwdzx4r 0\n1z84cx ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
38761594b2560cef7c16e6b89aea0872 | Parquet Re-laying | Peter decided to lay a parquet in the room of size *n*<=×<=*m*, the parquet consists of tiles of size 1<=×<=2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter likes, and workers will have to re-lay it.
The workers decided that removing entire parquet and then laying it ag... | [
"#!/usr/bin/env python3\n\nboard = []\nn, m = 0, 0\n\ndef rotate(x, y):\n if board[x][y] == 'L':\n board[x][y] = board[x][y+1] = 'U'\n board[x+1][y] = board[x+1][y+1] = 'D'\n else:\n board[x][y] = board[x+1][y] = 'L'\n board[x][y+1] = board[x+1][y+1] = 'R'\n\ndef fix(x, y, moves):\... | {"inputs": ["2 3\nULR\nDLR\nLRU\nLRD", "4 3\nULR\nDLR\nLRU\nLRD\nULR\nDUU\nUDD\nDLR", "2 5\nLRUUU\nLRDDD\nLRLRU\nLRLRD", "3 8\nLRULRLRU\nUUDLRLRD\nDDLRLRLR\nULRLRLRU\nDLRLRLRD\nLRLRLRLR", "7 6\nULRULR\nDLRDLR\nUUULRU\nDDDLRD\nLRUULR\nLRDDUU\nLRLRDD\nULRLRU\nDUUUUD\nUDDDDU\nDLRLRD\nULRULR\nDLRDUU\nLRLRDD", "10 9\nLRLRLR... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
38845cbb3505f416bccfeb0211eb9e98 | Rock-Paper-Scissors | Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!).
Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independently from each other. They show the items with their hands: a rock, scisso... | [
"n = int(input())\r\na = input()\r\nb = input()\r\nai = 0\r\nalen = len(a)\r\nbi = 0\r\nblen = len(b)\r\nnik = 0\r\npol = 0\r\nif alen == blen: rnd = alen\r\nelse: rnd = alen*blen\r\nnumofrounds = 0\r\nfor i in range(n):\r\n #print(i,rnd)\r\n if i == rnd:\r\n numofrounds = n//rnd\r\n # print(num... | {"inputs": ["7\nRPS\nRSPP", "5\nRRRRRRRR\nR", "23\nRSP\nRPSS", "52\nRRPSS\nRSSPRPRPPP", "1293\nRRPSSRSSPRPRPPPRPPPRPPPPPRPSPRSSRPSPPRPRR\nSSPSSSSRPPSSSSRPRPRPPSRSRRSPPSPPRPSRSPSRR", "103948\nRRPSSRSSPRPRPPPRPPPRPPPPPRPSPRSSRPSPPRPRRSSPSSSSRPPSSSSRPRPRPPSRSRRSPPSPPRPSRSPSRRPSRSRSRPRPRSSPSPRPRSSPRPSPPRPRRRPRRPRPSPRPRSSRR... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
388ebdc52277ab7440b7e20c3040e284 | Which floor? | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | [
"n, m = map(int, input().split())\r\nlist1 = []\r\nans = set()\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for i in range(m):\r\n list1.append(list(map(int, input().split())))\r\n for i in range(1, 101):\r\n if len(ans) > 1:\r\n print(-1)\r\n break\r\n for j in range(... | {"inputs": ["10 3\n6 2\n2 1\n7 3", "8 4\n3 1\n6 2\n5 2\n2 1", "8 3\n7 2\n6 2\n1 1", "4 2\n8 3\n3 1", "11 4\n16 4\n11 3\n10 3\n15 4", "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "1 0", "1 1\n1 1", "1 1\n1 1", "1 2\n1 1\n2 2", "2 2\n2 1\n1 1", "2 0", "2 1\n3 3", "3 2\n1 1\n3 3", "3 3\n1 1\n3 3\n2 2", "3 0", "1 1\n2 1", "2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 50 | |
38a0572f7ab04f490a1b64127c32ee44 | Text Editor | Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, b... | [
"import sys\r\n \r\nsys.stdin = open('input.txt')\r\nsys.stdout = open('output.txt', 'w')\r\n \r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n[r1, c1, r2, c2] = [int(x) for x in input().split()]\r\n \r\nr1 -= 1\r\nr2 -= 1\r\nc1 -= 1\r\nc2 -= 1\r\n \r\ndr = r2 - r1\r\nddr = dr // abs(dr) if dr != 0 ... | {"inputs": ["4\n2 1 6 4\n3 4 4 2", "4\n10 5 6 4\n1 11 4 2", "3\n10 1 10\n1 10 1 1", "4\n2 1 6 4\n4 2 3 5", "3\n20 3 20\n1 20 1 1", "2\n10 1\n1 3 2 1", "20\n3 1 9 9 6 1 3 4 5 6 7 3 1 9 9 1 9 1 5 7\n17 7 19 5", "20\n81 90 11 68 23 18 78 75 45 86 58 37 21 15 98 40 53 100 10 70\n11 55 8 19", "25\n55 47 5 63 55 11 8 32 0 62... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
38a77f9b1565bb7b2f12271aa22b060e | Dead Ends | Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are *n* junctions and *m* two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to *n*<=-<=1 roads and i... | [
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, m, k = map(int, input().split())\r\nadj = [[] for _ in range(n)]\r\ndp = [[0] * (1 << n) for _ in range(1 << n)]\r\n\r\nfor u, v in (map(int, input().split()) for _ in... | {"inputs": ["3 3 2\n1 2\n2 3\n1 3", "4 6 2\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4", "4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4", "5 4 3\n2 1\n5 3\n3 2\n1 4", "5 10 2\n2 4\n1 5\n2 5\n3 5\n4 3\n1 4\n3 1\n5 4\n3 2\n2 1", "6 6 2\n6 3\n5 2\n5 1\n3 5\n6 2\n4 3", "7 7 5\n2 1\n4 2\n7 1\n4 5\n7 6\n2 6\n2 3", "5 5 2\n1 2\n2 3\n3 4\n4 2\n4 5", ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
38b21dffaeb42cac1f2f9489c6203f5b | Karen and Morning | Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palin... | [
"hh, mm = [str(x) for x in input().split(':')]\r\nih = int(hh)\r\nim = int(mm)\r\ncnt = 0\r\nwhile True:\r\n sh = str(ih)\r\n sm = str(im)\r\n if len(sh) == 1:\r\n sh = '0'+sh\r\n if len(sm) == 1:\r\n sm = '0'+sm\r\n if sh == sm[::-1]:\r\n print(cnt)\r\n break\r\n im +=... | {"inputs": ["05:39", "13:31", "23:59", "13:32", "14:40", "14:00", "05:50", "12:22", "12:34", "05:30", "14:14", "01:10", "02:20", "03:30", "04:40", "10:01", "11:11", "12:21", "14:41", "15:51", "20:02", "21:12", "22:22", "23:32", "01:11", "02:21", "03:31", "04:41", "05:51", "10:02", "11:12", "14:42", "15:52", "20:03", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 133 | |
38bbe6896f63d0ca66f3881b65296b14 | Hacking Cypher | Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long inte... | [
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nS = [int(x) f... | {"inputs": ["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1", "604\n6 4", "2108\n7 8", "7208\n10 1", "97502821\n25 91", "803405634\n309 313", "15203400\n38 129", "8552104774\n973 76", "2368009434\n320 106", "425392502895812\n4363 2452", "142222201649130\n4854 7853", "137871307228140\n9375 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
38bddbbfe2d04819082a90ef67615560 | Sum the Fibonacci | You are given an array *s* of *n* non-negative integers.
A 5-tuple of integers (*a*,<=*b*,<=*c*,<=*d*,<=*e*) is said to be valid if it satisfies the following conditions:
- 1<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*<=≤<=*n* - (*s**a* | *s**b*) & *s**c* & (*s**d* ^ *s**e*)<==<=2*i* for some integer *i* - *s**a* &am... | [
"P = 1000000007\n\ndef subset_zeta_transform(a):\n n = len(a)\n assert((n & (n - 1)) == 0)\n step = 1\n while step < n:\n for i in range(n):\n if (i & step) == 0:\n a[i + step] += a[i]\n a[i + step] %= P\n step <<= 1\n\ndef subset_mobius_transform(a):\n n = len(a)\n assert((n & (n - 1... | {"inputs": ["2\n1 2", "3\n7 4 1", "10\n1 3 0 7 3 7 6 5 7 5", "10\n50 9 11 44 39 40 5 39 23 7", "10\n4 4 3 1 5 1 3 6 4 4", "10\n5 6 3 2 6 4 3 0 2 7", "10\n7 0 4 3 7 6 2 1 0 2", "10\n1 2 4 4 7 1 1 2 7 5", "10\n3 5 5 4 0 4 1 4 5 1", "10\n6826 5946 9767 38900 11942 58422 45007 53023 3656 41010", "10\n53002 36454 23921 1410... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
38cc59de94bca64c6c7c4f4eb9abdbc9 | Permutation Sum | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
Pety... | [
"import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(n):\r\n A = [1, 3, 15, 133, 2025, 37851, 1030367, 36362925, 1606008513, 87656896891, 5778121715415, 452794797220965, 41609568918940625]\r\n if n % 2==0:\r\n sys.stdout.write('0\\n')\r\n else:\r\n p = 10**9+7\r\n A1 =... | {"inputs": ["3", "5", "13", "1", "2", "4", "6", "15", "16", "7", "8", "9", "10", "11", "12", "14"], "outputs": ["18", "1800", "695720788", "1", "0", "0", "0", "150347555", "0", "670320", "0", "734832000", "0", "890786230", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
38e555730668a446d73aaad7b3fe78f0 | Roads in Berland | There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance ... | [
"from sys import stdin\ninput = stdin.readline\nn = int(input())\nm = []\nfor ni in range(n): m.append([int(x) for x in input().strip().split()])\nq = int(input())\nans = []\nfor qi in range(q):\n s, e, v = [int(x) for x in input().strip().split()]\n s-=1\n e-=1\n for i in range(n):\n for j in ra... | {"inputs": ["2\n0 5\n5 0\n1\n1 2 3", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1", "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763", "4\n0 537 1064 656\n537 0 527 119\n1064 527 0 408\n656 119 408 0\n4\n1 4 123\n1 4 344\n3 2 982\n3 2 587", "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
3903f48dfec315a3660b8c5081fb87be | Letter | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | [
"s=input()\nmina=c=0\nfor i in range(len(s)):\n if ord(s[i])>=97:\n mina=min(c+1,mina)\n c+=1\n else:\n mina=min(mina+1,c)\nprint(mina)\n",
"def min_count(q: str) -> int:\n w = len(q)\n lower = [0] * (w + 1)\n upper = [0] * (w + 1)\n for n in range(1, w + 1):\n lower[... | {"inputs": ["PRuvetSTAaYA", "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "helloworld", "P", "t", "XdJ", "FSFlNEelYY", "lgtyasficu", "WYKUDTDDBT", "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd", "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHd... | UNKNOWN | PYTHON3 | CODEFORCES | 188 | |
392ed5caa360e1dc63110f061175dd82 | Thor | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are ... | [
"import sys\r\nn,m=map(int,input().split())\r\nk=0\r\npos=0\r\nL=[]\r\nL1=[]\r\nd={i:[0,-1] for i in range(1,n+1)}\r\nfor i in range(m) :\r\n a,b=map(int,input().split())\r\n if a==1 :\r\n d[b][0]+=1\r\n \r\n k+=1\r\n L.append(b)\r\n elif a==2 :\r\n k-=d[b][0]\r\n ... | {"inputs": ["3 4\n1 3\n1 1\n1 2\n2 3", "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3", "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n1 1\n1 7\n... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
39309ddd3f632f4dfef8be76b7678c4c | Paths in a Complete Binary Tree | *T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So *n* is a number such t... | [
"#Bhargey Mehta (Sophomore)\r\n#DA-IICT, Gandhinagar\r\nimport sys, math, queue\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\nMOD = 10**9+7\r\nsys.setrecursionlimit(1000000)\r\n\r\ndef hgt(x):\r\n if x == 0: return -1\r\n h = 0\r\n while x&1 != 1:\r\n h += 1\r\n x = x>>1\r\n return h\r\n\r... | {"inputs": ["15 2\n4\nUURL\n8\nLRLLLLLLLL", "1 1\n1\nL", "1 1\n1\nR", "1 1\n1\nU", "1 10\n1\nURLRLULUR\n1\nLRRRURULULL\n1\nLURURRUUUU\n1\nRRULLLRRUL\n1\nUULLUURL\n1\nRLRRULUL\n1\nLURRLRUULRR\n1\nLULLULUUUL\n1\nURULLULL\n1\nLRRLRUUUURRLRRL", "3 10\n2\nRUUUULULULUU\n1\nULLLURLU\n3\nLLURLULU\n2\nRRLURLURLLR\n3\nLRURURLRLL... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
394d35313163682fb593a583a299c398 | none | There are *n* types of coins in Byteland. Conveniently, the denomination of the coin type *k* divides the denomination of the coin type *k*<=+<=1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types *k*<=+<=1 and *k* equals *a**k*. It is known that for each *x* there are a... | [
"import sys\r\ninput = sys.stdin.readline\r\nMOD = 1000000007\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.append(1)\r\nb = list(map(int, input().split()))\r\nm = int(input())\r\ndp = [1]\r\nfor x, y in zip(b, a):\r\n dp.extend([0] * x)\r\n for i in range(len(dp) - 1):\r\n dp[i +... | {"inputs": ["1\n\n4\n2", "2\n1\n4 4\n2", "3\n3 3\n10 10 10\n17", "2\n2\n200000 100000\n34567", "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 299981\n1234567890", "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n299981 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1034567", "10\n1 1 1 1 1 1 1 1 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
39544f28821bb5aa59b8dec97a4e1e49 | Error Correct System | Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings *S* and *T* of equal length to be "similar". After a brief search on th... | [
"n = int(input())\r\ns = input()\r\nt = input()\r\na = []\r\nx = y = -2\r\nh = 0\r\nfor i in range(26):\r\n\ta.append([])\r\n\tfor j in range(26):\r\n\t\ta[i].append(-1)\r\nfor i in range(n):\r\n\tif(s[i] != t[i]):\r\n\t\th+=1\r\n\t\ta[ord(s[i])-ord('a')][ord(t[i])-ord('a')] = i\r\n\t\tif(a[ord(t[i])-ord('a')][ord(... | {"inputs": ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle", "1\na\na", "1\na\nb", "2\naa\naa", "2\nzz\nzz", "2\nzx\nzz", "2\nzz\nzx", "2\nxy\nzz", "2\nzz\nxy", "2\nzx\nxz", "2\nab\nbc", "2\nab\ncb", "2\nxx\nyy", "10\ncdcddbacdb\naababacabc", "2\nab\ncd", "2\naa\nab", "3\nabc\nbca",... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
3958501202101ff6b2ac1fdd5918475d | Buggy Robot | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | [
"input()\nk=input()\nprint((min(k.count(\"R\"),k.count(\"L\"))+min(k.count(\"D\"),k.count(\"U\")))*2)\n \t \t\t \t \t \t \t \t\t\t \t \t\t",
"n=int(input())\r\ns=input()\r\nV=['U','D','L','R']\r\nC=[0,0,0,0]\r\nfor l in s:\r\n C[V.index(l)]+=1\r\nprint(2*min(C[0],C[1])+2*min(C[2],C[3]))\r\n ",
"n=... | {"inputs": ["4\nLDUR", "5\nRRRUU", "6\nLLRRRR", "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDU... | UNKNOWN | PYTHON3 | CODEFORCES | 226 | |
3988deb311c9bfcfc4ac5c195612dbd0 | Far Relative’s Birthday Cake | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | [
"import math\r\n\r\nsize = int(input())\r\n\r\nmatrix = []\r\n\r\ndef ncr(x):\r\n if x>=2:\r\n y = math.factorial(x)\r\n y = y/((math.factorial(x-2))*2)\r\n return y\r\n else:\r\n return 0\r\n\r\n\r\nfor i in range(0,size):\r\n array = list(str(input()))\r\n matrix.append(arr... | {"inputs": ["3\n.CC\nC..\nC.C", "4\nCC..\nC..C\n.CC.\n.CC.", "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.C... | UNKNOWN | PYTHON3 | CODEFORCES | 430 | |
39bbee704fc84a224ebeb5084d155b4f | Make a Square | You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently ... | [
"n = int(input())\r\nd = []\r\ni = 1\r\nns =str(n)\r\nwhile i*i<=n:\r\n d.append(i*i)\r\n i+=1 \r\nfor j in d[::-1]:\r\n if j==n:\r\n print(0)\r\n exit()\r\n else:\r\n c=0\r\n for k in range(len(ns)):\r\n if ns[k]==str(j)[c]:\r\n c+=1\r\n ... | {"inputs": ["8314", "625", "333", "1881388645", "1059472069", "1354124829", "149723943", "101", "1999967841", "2000000000", "1999431225", "30", "1000", "3081", "10", "2003064", "701", "1234567891", "10625", "13579", "1999999999", "150000", "8010902", "20100", "40404", "70000729", "1899933124", "1999999081", "326700", "... | UNKNOWN | PYTHON3 | CODEFORCES | 76 | |
39d7d73ee8bf7fb917707a725fcecbc3 | Potions Homework | Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ... | [
"n = int(input())\r\na = [int(input()) for i in range(n)]\r\nmod = 10007\r\n\r\na.sort()\r\nans = 0\r\nfor i in range(n):\r\n ans += a[i] * a[n - 1 - i] % mod\r\n if ans >= mod:\r\n ans -= mod\r\n \r\nprint(ans)",
"n = int(input())\ns = sorted([int(input()) for i in range(n)])\n#print(s)\na = ... | {"inputs": ["2\n1\n3"], "outputs": ["6"]} | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
39e33fe03d8030b451d146fb78f7dab7 | Point on Spiral | Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0,<=0),<=(1,<=0)], [(1,<=0),<=(1,<=1)], [(1,<=1),<=(<=-<=1,<=1)], [(<=-<=1,<=1),<=(<=-<=1,<=<=-<=1)], [(<=-<=1,<=<=-<=1),<=(2,<=<=-<=1)], [(2,<... | [
"l = input().split(' ')\nx, y = int(l[0]), int(l[1])\nif y <= 0 and x >= 1 + y and x <= 1 - y:\n print((-y) * 4)\nelif x > 0 and y >= 2 - x and y <= x:\n print(x * 4 - 3)\nelif y > 0 and x >= -y and x <= y - 1:\n print(y * 4 - 2)\nelif x < 0 and y >= x and y <= -1 - x:\n print((-x) * 4 - 1)\nelse:\n ... | {"inputs": ["0 0", "1 0", "0 1", "-1 -1", "10 10", "0 6", "-7 -13", "37 -100", "99 100", "16 -32", "1 1", "-1 1", "-1 0", "3 -5", "0 -1", "1 -1", "100 100", "0 99", "-98 98", "-97 0", "-96 -96", "0 -95", "94 -94", "93 0", "17 25", "1 -84", "-5 44", "11 -15", "42 9", "-81 3", "100 99", "2 -1"], "outputs": ["0", "0", "2"... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
39e8800931f696ffb8fdfc41c39b18dd | Valera and Contest | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valer... | [
"from sys import stdin, stdout\r\ninp = stdin.readline\r\npr = stdout.write\r\ndef f(sk, k):\r\n q, m = divmod(sk, k)\r\n for i in range(m):\r\n pr(str(q + 1) + ' ')\r\n for i in range(k - m):\r\n pr(str(q) + ' ')\r\nn, k, l, r, sa, sk = map(int, inp().split())\r\nf(sk, k)\r\nif n != k:\r\n ... | {"inputs": ["5 3 1 3 13 9", "5 3 1 3 15 9", "50 25 1 1 50 25", "1000 700 782 1000 892330 648282", "1000 999 500 503 501513 501013", "999 998 500 501 500009 499509", "999 998 500 500 499500 499000", "999 997 500 502 500516 499516", "1000 300 50 500 269795 127658", "50 25 1000 1000 50000 25000", "100 100 500 1000 75589 7... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
3a2ed3d0ddf1e89b171a443e3b293e3c | The number of positions | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* an... | [
"# cook your dish here\r\nn,a,b = input().split()\r\nn = int(n)\r\na = int(a)\r\nb = int(b)\r\ncount = 0\r\nfor i in range(1,n+1):\r\n if i>a and n-i<=b:\r\n count = count + 1\r\nprint(count)",
"def pos(n,f,d):\r\n return n-max(f+1,n-b)+1;\r\nn,f,b=map(int,input().split(' '))\r\nprint(pos(n,f,b))",
... | {"inputs": ["3 1 1", "5 2 3", "5 4 0", "6 5 5", "9 4 3", "11 4 6", "13 8 7", "14 5 5", "16 6 9", "20 13 17", "22 4 8", "23 8 14", "26 18 22", "28 6 1", "29 5 23", "32 27 15", "33 11 5", "37 21 15", "39 34 33", "41 27 11", "42 25 16", "45 7 43", "47 16 17", "49 11 37", "51 38 39", "52 29 7", "56 43 12", "58 57 28", "59 ... | UNKNOWN | PYTHON3 | CODEFORCES | 466 | |
3a34b87fc366a4d65f122e24216aa3f8 | Tell Your World | Connect the countless points with lines, till we reach the faraway yonder.
There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of the... | [
"input()\ny = list(map(int, input().split()))\n\n\ndef check(d):\n return len(set(j - d * i for i, j in enumerate(y))) == 2\n\n\nd = (y[2] - y[0]) / 2, y[1] - y[0], y[2] - y[1]\n\nprint('yes' if any(check(dx) for dx in d) else 'no')\n",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nslope= (l[n-1]-l... | {"inputs": ["5\n7 5 8 6 9", "5\n-1 -2 0 0 -5", "5\n5 4 3 2 1", "5\n1000000000 0 0 0 0", "5\n1000000000 1 0 -999999999 -1000000000", "3\n998 244 353", "3\n-1000000000 0 1000000000", "5\n-1 -1 -1 -1 1", "4\n-9763 530 3595 6660", "4\n-253090305 36298498 374072642 711846786", "5\n-186772848 -235864239 -191561068 -193955178... | UNKNOWN | PYTHON3 | CODEFORCES | 29 | |
3a4944a4a61a49529d73e0c3ffb1252b | Bag of mice | The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc... | [
"def Prob(w, b, memo={}):\r\n if w == 0:\r\n return 0\r\n elif b == 0:\r\n return 1\r\n elif (w, b) in memo:\r\n return memo[(w, b)]\r\n else:\r\n k = w / (b + w)\r\n if b == 1:\r\n result = k\r\n elif b == 2:\r\n result = k + (1 - k) * ((b... | {"inputs": ["1 3", "5 5", "100 100", "100 1", "1 100", "67 420", "0 1000", "1000 0", "0 0", "1000 1000", "32 1000", "581 406", "459 52", "900 853", "778 218", "219 20", "815 665", "773 467", "215 269", "93 633", "267 270", "226 72", "666 436", "544 519", "141 883", "581 685", "459 487", "980 133", "858 934", "455 299",... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
3a7496dc01395a64dcd10c9444286d53 | Guess a number! | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that *y* is st... | [
"\"\"\"\n██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗\n██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗\n██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║\n██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║\n██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝\n╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝\n██████╗ █... | {"inputs": ["4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "2\n> 100 Y\n< -100 Y", "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N", "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y", "4\n< 10 Y\n> -6 Y\n< 10 Y\n< -10 N", "1\n< 1 N", "1\n<= 1 Y", "1\n> 1 N", "1\n>= 1 Y", "4\n< 1 N\n< 1 N\n< 1 N\n<= 1 Y", "4\n< 1 N\n>= 1 Y\n< 1 N\n< 1 N", "4\n> 1 N\n<= 1 Y\n<=... | UNKNOWN | PYTHON3 | CODEFORCES | 61 | |
3a77f3f4e5388497e5271357cd5d6a2b | Path Counting | You are given a rooted tree. Let's denote *d*(*x*) as depth of node *x*: depth of the root is 1, depth of any other node *x* is *d*(*y*)<=+<=1, where *y* is a parent of *x*.
The tree has the following property: every node *x* with *d*(*x*)<==<=*i* has exactly *a**i* children. Maximum possible depth of a node is *n*, a... | [
"mod=10**9+7\r\n\r\nn=int(input())\r\na=[1]+list(map(int,input().split()))+[1]\r\nans=[0]*(2*n)\r\ncnt=[1]\r\nfor i in a[1:]:\r\n cnt.append(cnt[-1]*i%mod)\r\n\r\ndp=[0]*2*n\r\nfor i in range(n):\r\n for j in range(1,2*n):\r\n ans[j]+=cnt[i]*dp[j]\r\n ans[j]%=mod\r\n ndp=[0]*2*n\r\n for j in range(2*n-1):... | {"inputs": ["4\n2 2 2", "3\n2 3", "2\n2", "6\n2 2 4 2 4"], "outputs": ["14 19 20 20 16 16 ", "8 13 6 9 ", "2 1 ", "182 415 420 980 1216 2432 1536 3328 2048 4096 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
3a9926b5ae6c5e1afb1e2414cad41a5d | Vasya the Architect | Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart.
Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides ... | [
"n = int(input())\r\nl = []\r\nm = []\r\nfor i in range(n):\r\n X1, Y1, X2, Y2 = map(int, input().split())\r\n m1 = (abs(X2 - X1)) ** 3\r\n l.append([X1, Y1, X2, Y2])\r\n m.append(m1)\r\nX1, Y1, X2, Y2 = l[0][0], l[0][1], l[0][2], l[0][3]\r\nif X1 > X2: X2, X1 = X1, X2\r\nif Y1 > Y2: Y1, Y2 = Y2, Y1\r\n... | {"inputs": ["2\n0 0 3 3\n1 0 4 3", "2\n0 0 3 3\n2 0 5 3", "3\n0 0 3 3\n1 0 4 3\n2 0 5 3", "5\n7 -10 -8 5\n4 -7 -5 2\n2 -5 -3 0\n-9 48 50 -11\n50 -4 -2 48", "5\n6 -2 13 -9\n17 2 2 -13\n13 -2 6 -9\n4 0 15 -11\n8 -7 11 -4", "7\n4 6 1 9\n-1 4 6 11\n8 13 -3 2\n-5 0 45 50\n-2 50 45 3\n45 50 -4 1\n45 50 -1 4", "7\n24 6 11 -7\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3add68635ce4d4c3e1958fcf25655fc7 | Browser | Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong ... | [
"n,pos,l,r=[int(i) for i in input().split()]\r\nif l==1 and r==n:\r\n print(0)\r\nelif l==1 and r!=n:\r\n print(abs(pos-r)+1)\r\nelif l!=1 and r==n:\r\n print(abs(pos-l)+1)\r\nelse:\r\n print(r-l+min(abs(pos-l),abs(pos-r))+2)\r\n",
"n, p, l, r = map(int, input().split())\r\nres = 0\r\nif p <= l:\r\n ... | {"inputs": ["6 3 2 4", "6 3 1 3", "5 2 1 5", "100 1 1 99", "100 50 1 99", "100 99 1 99", "100 100 1 99", "100 50 2 100", "100 1 100 100", "100 50 50 50", "6 4 2 5", "100 5 2 50", "10 7 3 9", "7 4 2 5", "43 16 2 18", "100 50 2 51", "6 5 2 4", "10 5 2 7", "10 10 2 9", "10 7 3 7", "64 64 8 44", "5 4 2 4", "6 6 3 5", "10 6... | UNKNOWN | PYTHON3 | CODEFORCES | 94 | |
3aedbea91125683b6bcdb3225a3a9a4b | Team | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | [
"# -*- coding: utf-8 -*-\n\"\"\"Untitled68.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1yvZY7V0Q83TMsZCyMfFGv331MUmhHXMr\n\"\"\"\n\nn0,n1=map(int,input().split())\nif n1==n0:\n str=\"10\"*n0\nelif n1>n0 and n1<=n0*2+2:\n if n1<=n0*2... | {"inputs": ["1 2", "4 8", "4 10", "1 5", "3 4", "3 10", "74 99", "19 30", "33 77", "3830 6966", "1000000 1000000", "1027 2030", "4610 4609", "3342 3339", "7757 7755", "10 8", "4247 8495", "7101 14204", "9801 19605", "4025 6858", "7129 13245", "8826 12432", "6322 9256", "8097 14682", "6196 6197", "1709 2902", "455 512",... | UNKNOWN | PYTHON3 | CODEFORCES | 106 | |
3b240e3783c43aa47c25b9f1274195ff | Xenia and Bit Operations | Xenia the beginner programmer has a sequence *a*, consisting of 2*n* non-negative integers: *a*1,<=*a*2,<=...,<=*a*2*n*. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value *v* for *a*.
Namely, it takes several iterations to calculate value *v*. At the ... | [
"import sys;input=sys.stdin.readline\r\nn,m=map(int,input().split())\r\na=[*map(int,input().split())]\r\nn=2**n\r\ntree=[0]*4*n\r\n\r\ndef build(v,tl,tr):\r\n if tl==tr:tree[v]=a[tl];return 0\r\n tm=tl+tr>>1\r\n t=build(v*2,tl,tm)^1\r\n build(v*2+1,tm+1,tr)\r\n if t:tree[v]=tree[v*2]|tree[v*2+1]\r\n ... | {"inputs": ["2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2", "1 1\n1 1\n1 1", "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31", "1 10\n22 17\n2 15\n2 12\n1 6\n1 16\n2 24\n1 21\n2 19\n2 25\n2 19\n2 1", "2 10\n15 27 17 18\n2 12\n4 19\n2 3\n4 1\n3 15\n3 11\n2 5\n1 26\n1 17\n3 18", "2 10\n31 17 22 5\n2 15\n2 26\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
3b5282f8f5542b87becd68ad6319772f | Representative Sampling | The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.
There is a collection of *n* proteins (not necessarily distinct). Each protein is a string consisting of lowerc... | [
"from collections import defaultdict\r\nimport sys\r\nreadline=sys.stdin.readline\r\nimport random\r\n\r\nclass Rolling_Hash:\r\n def __init__(self,lst,base,mod):\r\n self.len=len(lst)\r\n self.base=base\r\n self.mod=mod\r\n self.rolling_hash=[None]*(self.len+1)\r\n self.rollin... | {"inputs": ["3 2\naba\nbzd\nabq", "4 3\neee\nrrr\nttt\nqqq", "4 3\naaa\nabba\nabbc\nabbd", "1 1\nhelloeveryonethisisjustaverylongstringwouldyoueverexpectthisyesthisstringisveryverylongidonothaveenoughimaginationsohereyougohelloeveryonethisisjustaverylongstringwouldyoueverexpectthisyesthisstringisveryverylongidonothavee... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
3b61de978dbfc1b20b9f022753ecc871 | 4-point polyline | You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of... | [
"n, m = map(int, input().split())\n\na = ([[0, 1], [0, m], [0, 0], [0, m - 1]], [[1, 0], [n, 0], [0, 0], [n - 1, 0]], \\\n\n [[0, 1], [n, m], [0, 0], [n, m - 1]], [[1, 0], [n, m], [0, 0], [n - 1, m]], \\\n\n [[0, 0], [n, m], [0, m], [n, 0]], [[0, 0], [n, m], [n, 0], [0, m]])\n\nfor x in max(a, key = lambda ... | {"inputs": ["1 1", "0 10", "10 10", "100 100", "10 100", "20 1000", "1000 20", "100 10", "2 2", "3 3", "2 15", "15 2", "1000 1000", "1000 999", "999 1000", "987 567", "555 555", "555 1", "1 4", "955 956", "4 0", "0 3", "3 0", "2 3", "3 2", "3 4", "4 3", "3 5", "5 3", "3 6", "6 3", "4 4", "4 5", "5 4", "4 6", "6 4", "4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
3b63b03c271256ddd7519d874f49bf6d | Ciel the Commander | Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26... | [
"import bisect\r\nimport heapq\r\nimport sys\r\nfrom types import GeneratorType\r\nfrom functools import cmp_to_key\r\nfrom collections import defaultdict, Counter, deque\r\nimport math\r\nfrom functools import lru_cache\r\nfrom heapq import nlargest\r\nfrom functools import reduce\r\nimport random\r\nfrom itertool... | {"inputs": ["4\n1 2\n1 3\n1 4", "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "6\n1 2\n2 4\n4 5\n6 4\n3 2", "2\n2 1", "15\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15", "30\n23 13\n10 23\n21 10\n17 21\n2 17\n4 2\n14 4\n1 14\n19 1\n26 19\n11 26\n15 11\n25 15\n3 25\n28 3\n5 28\n18 5\n... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
3b7679613a34b5a0390fc195fff3af71 | IT Restaurants | Сity N. has a huge problem with roads, food and IT-infrastructure. In total the city has *n* junctions, some pairs of them are connected by bidirectional roads. The road network consists of *n*<=-<=1 roads, you can get from any junction to any other one by these roads. Yes, you're right — the road network forms an undi... | [
"from collections import defaultdict,deque\r\nimport sys\r\nimport bisect\r\ninput=sys.stdin.readline\r\nmod=1000000007\r\n\r\ngraph=defaultdict(list)\r\nn=int(input())\r\nfor i in range(n-1):\r\n x,y=map(int,input().split())\r\n graph[x].append(y)\r\n graph[y].append(x)\r\nvis=set()\r\nCHECK,OBSERVE=1,0\r... | {"inputs": ["5\n1 2\n2 3\n3 4\n4 5", "10\n1 2\n2 3\n3 4\n5 6\n6 7\n7 4\n8 9\n9 10\n10 4", "3\n3 1\n2 1", "4\n4 3\n4 1\n4 2", "5\n5 4\n4 1\n5 2\n3 2", "5\n1 4\n2 1\n5 1\n1 3", "6\n1 5\n3 4\n6 1\n3 2\n3 1", "6\n5 1\n1 2\n1 3\n6 1\n4 1", "6\n5 4\n2 1\n2 5\n3 4\n3 6", "18\n7 12\n14 8\n11 4\n6 3\n2 3\n15 10\n8 16\n6 16\n15 ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
3b8a51ebdac11b1f7888e126253f4c09 | Bets | In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends... | [
"n, m = map(int, input().split())\r\ntab = []\r\nfor _ in range(m):\r\n l = list(map(int, input().split()))\r\n tab.append(l)\r\n\r\np = 0\r\nfor i in range(1, n+1):\r\n s = 0\r\n t = 1001\r\n for j in range(m):\r\n if i in range(tab[j][0], tab[j][1]+1):\r\n if tab[j][2] < t:\r\n s = tab[j][3]\r... | {"inputs": ["4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20", "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20", "2 2\n1 2 3 1\n2 2 3 10", "20 30\n15 17 54 46\n4 18 26 18\n18 20 49 94\n12 12 83 12\n11 13 88 47\n8 8 8 12\n18 18 94 2\n14 17 88 96\n19 19 62 97\n1 12 81 67\n10 12 78 26\n19 20 63 93\n9 20 38 32\n7 9 90 17\n9 10... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
3b8efefac394b48855026af6e68d01ea | Anton and Letters | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | [
"a = input()\r\np=[]\r\nfor i in a:\r\n if(i.isalpha()==True):\r\n p.append(i)\r\ns=list(set(p))\r\nprint(len(s))",
"s = input()\r\n\r\nif len(s) == 2:\r\n print(0)\r\nelse:\r\n print(len(set(s[1:-1].split(', '))))\r\n",
"s = input()\r\nprint(len(set(s.lstrip(\"{\").rstrip(\"}\").split(\", \")))... | {"inputs": ["{a, b, c}", "{b, a, b, a}", "{}", "{a, a, c, b, b, b, c, c, c, c}", "{a, c, b, b}", "{a, b}", "{a}", "{b, a, b, a, b, c, c, b, c, b}", "{e, g, c, e}", "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a... | UNKNOWN | PYTHON3 | CODEFORCES | 771 | |
3b9d861c71dcfb2461f6d7a5f9309258 | Tree Constructing | You are given three integers $n$, $d$ and $k$.
Your task is to construct an undirected tree on $n$ vertices with diameter $d$ and degree of each vertex at most $k$, or say that it is impossible.
An undirected tree is a connected undirected graph with $n - 1$ edges.
Diameter of a tree is the maximum length of a simpl... | [
"n,d,k=map(int,input().strip().split())\r\nans=[]\r\nif (d>n-1):\r\n\tprint (\"NO\")\r\n\texit(0)\r\nif (k<2 and n>2):\r\n\tprint (\"NO\")\r\n\texit(0)\r\nl1=[0 for i in range(d+2)]\r\ncount=d\r\ncnt=d+2\r\ndef insert(par,v,r,e):\r\n\tglobal count\r\n\tglobal cnt\r\n\tif count==n-1:\r\n\t\tprint (\"YES\")\r\n\t\tfo... | {"inputs": ["6 3 3", "6 2 3", "10 4 3", "8 5 3", "8 3 3", "5 4 2", "5 4 3", "5 5 2", "5 5 3", "6 4 2", "6 4 3", "6 5 2", "6 5 3", "7 4 2", "7 4 3", "7 5 2", "7 5 3", "1 1 1", "400000 400000 400000", "400000 399999 400000", "400000 399999 2", "200000 100000 3", "200000 100000 2", "400000 2 399999", "400000 100 399999", ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
3ba660d87505352bc671bca512dd542a | Little Elephant and Inversions | The Little Elephant has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
The Little Elephant wants to count, how many pairs of integers *l* and *r* are there, such that 1<=≤<=*l*<=<<=*r*<=≤<=*n* and sequence *b*<==<=*a*1*a*2... *a**l**a**r**a**... | [
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nclass Graph:\r\n def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float(\"inf\")):\r\n self.V=V\r\n self.directed=directed\r\n self.weighted=weighted\r\n self.inf=inf\r\n if graph:\r\n sel... | {"inputs": ["3 1\n1 3 2", "5 2\n1 3 2 1 7", "7 3\n1 7 6 4 9 5 3", "5 0\n1 2 3 4 5", "2 1\n2 1", "3 1000000000000\n3 2 1", "10 5\n1 4 4 2 3 7 6 5 1 2", "10 10\n7 5 5 5 9 10 9 8 7 5", "7 1\n10 38 46 40 88 5 94", "20 7\n5 10 23 7 24 7 15 11 13 18 18 18 8 20 5 16 7 25 2 22", "40 1000000000000000000\n83 35 47 18 96 63 24 91... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3bf5c3e48c7b053e6aa8fc1ca6730f73 | Han Solo and Lazer Gun | There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot... | [
"from collections import defaultdict\r\nn, x, y = map(int, input().split())\r\ndic = defaultdict(int)\r\ncnt = ok = 0\r\nwhile n:\r\n n -= 1\r\n a, b = map(int, input().split())\r\n if x == a: ok = 1\r\n else: dic[(b - y) / (a - x)] += 1\r\nfor i in dic: \r\n cnt += dic[i] != 0\r\nprint(cnt + ok) \r\... | {"inputs": ["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0", "1 1 1\n0 0", "2 0 0\n10000 -10000\n-10000 10000", "2 0 0\n10000 -10000\n10000 10000", "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4", "10 5 -3\n1 1\n2 -1\n2 2\n1 -2\n4 -5\n1 4\n0 1\n1 -4\n-2 0\n-4 -5", "10 -3 3\n3 -5\n4 3\n0 -2\n0 0\n3... | UNKNOWN | PYTHON3 | CODEFORCES | 49 | |
3c01c47c4140ffb5cc3d12303aab46b6 | Radio Station | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | [
"n,m=map(int,input().split())\nd={}\nfor i in range(n):\n name,ip=input().split()\n d[ip]=name\nfor i in range(m):\n cmd,ip=input().split()\n print(cmd+\" \"+ip+\" \"+\"#\"+d[ip[:len(ip)-1]])\n \t\t\t\t\t \t\t \t \t\t \t\t\t \t\t \t\t\t",
"n,m=map(int, input().split())\r\nname=[]\r\nip1=[]\r\nco... | {"inputs": ["2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\n... | UNKNOWN | PYTHON3 | CODEFORCES | 318 | |
3c179f3122e0ce363e5ca25b758760cf | Yet Another Array Queries Problem | You are given an array *a* of size *n*, and *q* queries to it. There are queries of two types:
- 1 *l**i* *r**i* — perform a cyclic shift of the segment [*l**i*,<=*r**i*] to the right. That is, for every *x* such that *l**i*<=≤<=*x*<=<<=*r**i* new value of *a**x*<=+<=1 becomes equal to old value of *a**x*, and ne... | [
"import sys\n\n#Library Info(ACL for Python/Pypy) -> https://github.com/not522/ac-library-python\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # L,D,R,Uの順番\n\n\ndef main():\n n, q, m = map(int, input().split())\n a = list(map(int, input().split()))\... | {"inputs": ["6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5", "1 1 1\n474812122\n2 1 1\n1"], "outputs": ["3 3 1 5 2 ", "2 665 3 64 4 ", "474812122 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
3c222ec7bff9ab0113db8765e93d9bcc | The least round way | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | [
"n=int(input());\r\nma=[[] for x in range(n)];\r\nzflag=0;\r\nzindex=[0,0];\r\n\r\n#reading the input\r\nfor i in range(n):\r\n j=0;\r\n inp=input().split();\r\n for x in inp:\r\n if x=='0':\r\n ma[i].append(10);\r\n zflag=1;\r\n zindex=[i,j];\r\n else:\r\n ... | {"inputs": ["3\n1 2 3\n4 5 6\n7 8 9", "2\n7 6\n3 8", "3\n4 10 5\n10 9 4\n6 5 3", "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4", "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4", "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
3c32c34ac5004228f7041da8bc753e4d | Cows and Primitive Roots | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | [
"p=int(input())\r\ng=0\r\nfor x in range(1,p):\r\n i=x\r\n u=1\r\n o=0\r\n while u<p-1:\r\n x%=p\r\n if (x-1)%p==0:\r\n break\r\n x*=i\r\n u+=1\r\n else:\r\n if (x-1)%p==0:\r\n g+=1\r\nprint(g)",
"p = int(input())\r\ndef gcd(a,b): \r\n \... | {"inputs": ["3", "5", "7", "11", "17", "19", "1583", "997", "2", "1987", "1993", "1997", "1999", "1297", "163", "1259", "821", "29", "43", "1949", "1879", "1759", "1597", "1619", "1277", "1097", "953", "751", "607", "509", "431", "317", "211", "127", "101", "31"], "outputs": ["1", "2", "2", "4", "8", "6", "672", "328",... | UNKNOWN | PYTHON3 | CODEFORCES | 51 | |
3c5efa15dc96e7b2f9d279fa7af33f0a | Design Tutorial: Make It Nondeterministic | A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.
Let's try to make a new task. Firstly we will use the following task. There are *n* people, sort them by their name. It is just an ordi... | [
"import sys\n\n\ndef main():\n toks = (tok for tok in sys.stdin.read().split())\n names = [\"\"]\n n = int(next(toks))\n\n for _ in range(n): \n names.append([next(toks), next(toks)])\n\n i = int(next(toks))\n prev = min(names[i][0], names[i][1])\n for _ in range(1, n):\n i = int(... | {"inputs": ["3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3", "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2", "2\ngalileo galilei\nnicolaus copernicus\n2 1", "10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma mil... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
3cb7da3f6aa21d20c10d29e847128545 | Squares and not squares | Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this can... | [
"n=int(input())\r\na=list(map(int, input().split()))\r\nc=0\r\nt=0\r\nx=[]\r\ny=[]\r\nq=[]\r\nd=0\r\nw=0\r\nfor i in range(n):\r\n if a[i]**0.5==int(a[i]**0.5):\r\n c+=1\r\n x.append(a[i])\r\n else:\r\n t+=1\r\n y.append(a[i])\r\nif c==t:\r\n print(0)\r\nelif t>c:\r\n for i in range(t):\r\n q.app... | {"inputs": ["4\n12 14 30 4", "6\n0 0 0 0 0 0", "6\n120 110 23 34 25 45", "10\n121 56 78 81 45 100 1 0 54 78", "10\n0 675178538 310440616 608075179 0 0 0 0 0 0", "10\n49727640 89440577 0 957792200 0 0 0 0 623726477 0", "20\n4 595258838 0 305922562 0 471450344 1 1 29794053 307197649 0 32960227 1 0 0 1 1 0 0 1", "100\n444... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
3cb7e99c1a5ccde8a994db6ed8ab3f38 | A Prosperous Lot | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | [
"n = int(input())\r\nif n>36:\r\n print(-1)\r\nelse:\r\n ans = []\r\n i = 0\r\n while n >= 2:\r\n ans.append(\"8\") \r\n n -= 2\r\n if n == 1:\r\n ans.append(\"4\")\r\n n -= 1\r\n x = \"\".join(ans) \r\n print(int(x)) ",
"k=int(input())\nif k==1:\n pri... | {"inputs": ["2", "6", "3", "4", "5", "1000000", "1", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "462", "1317", "88", "87"], "outputs": ["8", "888", "86", "88", "8... | UNKNOWN | PYTHON3 | CODEFORCES | 103 | |
3cbd09c654179a180514a5cac06fafc4 | Scissors | Jenya has recently acquired quite a useful tool — *k*-scissors for cutting strings. They are generally used for cutting out two non-intersecting substrings of length *k* from an arbitrary string *s* (its length should be at least 2·*k* in order to perform this operation) and concatenating them afterwards (preserving th... | [
"MOD = int(1e9 + 7)\r\nBASE = 32107\r\nN = int(5e5 + 10)\r\npw, ml, mr = [0]*N, [0]*N, [0]*N\r\ns, t = ['']*N, ['']*N\r\n\r\nclass Hash:\r\n def __init__(self):\r\n self.a = [0]*N\r\n def JS(self, s):\r\n lenn = len(s) - 1\r\n for i in range(1, lenn+1):\r\n self.a[i] = (self.a[i - 1] * BASE % MOD + ... | {"inputs": ["7 4 3\nbaabaab\naaaa", "6 3 2\ncbcbcb\nbcc", "7 5 3\naabbaaa\naaaaa", "16 6 4\nabcdcadbbbcacdca\ndcadbc", "81 5 3\nacbbcccbcbcbbbabaabbbcbacbaabbabaacccaaaaaabbbaacbaabcbcacbbacacbaaaaccbbcacbbcba\ncbbab", "12 3 4\ndbcbabbbdcbb\nbba", "18 3 4\ndcdbdbadddbddbbccc\nbba", "7 3 3\naaabbaa\naaa", "8 3 4\nbcbaaa... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3cc5285df504e353dace9de67bd01859 | Mahmoud and Ehab and the xor-MST | Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of *n* vertices numbered from 0 to *n*<=-<=1. For all 0<=≤<=*u*<=<<=*v*<=<<=*n*, vertex *u* and vertex *v* are connected with an undirected edge that has weight... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nans = 0\r\np = 1\r\nfor _ in range(n.bit_length() + 2):\r\n x = (n - 1 - p) // (2 * p) + 1\r\n ans += x * p\r\n p *= 2\r\nprint(ans)",
"n = int(input())\r\ndp = [[0,0],[0,1],[1,3]]\r\nfor i in r... | {"inputs": ["4", "10", "2", "1000000000000", "999999999999", "23131234", "100000", "1024", "536870912", "536870911", "536870913", "123456789", "200", "3", "5", "6", "7", "1000", "12000", "65536", "1048576", "8", "549755813888", "549755813887", "549755813889"], "outputs": ["4", "21", "1", "20140978692096", "201409786920... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
3ccb12ebf4d2df622e19e5477742fdb5 | none | Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero.
A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0.
Limak wants to choose some nice rectangles a... | [
"N = int(input())\r\nin_data = {i: [0] * (N + 1) for i in range(3)}\r\nprv = [[0] * (N + 1) for _ in range(3)]\r\nfor i in range(2):\r\n input_line = input().split()\r\n for j in range(1, N + 1):\r\n in_data[i][j] = int(input_line[j - 1])\r\nfor i in range(1, N + 1):\r\n in_data[2][i] = in_data[0][i... | {"inputs": ["6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15", "4\n0 -1 0 0\n0 0 1 0", "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998", "1\n0\n0", "1\n20\n-20", "2\n-1 0\n0 0", "3\n-2 -1 1\n0 1 0", "5\n-1 -2 2 0 -2\n-1 2 -2 2 2", "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "10\n2 1 -2 -1 2 2 -2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
3ce0692ddab193d819e892b99a92e440 | Divisibility by Eight | You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no... | [
"# ﷽\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\nmod=7+10**9\r\n\r\ndef solve():\r\n s=input()\r\n n=len(s)\r\n \r\n for i in range(n):\r\n for j in range(i+1,n):\r\n for k in range(j+1,n):\r\n if int(s[i]+s[j]+s[k])%8==0:\r\n return... | {"inputs": ["3454", "10", "111111", "8996988892", "5555555555", "1", "8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188", "8", "14", "2363", "3554", "312", "7674", "126", "344", "976", "3144", "1492", "1000", "303", "1111111111111111111111711111111111111111111111111111... | UNKNOWN | PYTHON3 | CODEFORCES | 72 | |
3cf407119513b751bc463ccedd2359a7 | Letter | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ... | [
"from collections import Counter\ns1=list(input())\ns2=list(input())\nc1=Counter(s1)\nc2=Counter(s2)\nflag=1\nfor ele in c2.keys():\n if ele==' ':\n continue\n if c2[ele]>c1[ele]:\n print(\"NO\")\n flag=0\n break\nif flag:\n print(\"YES\")",
"newsP = input()\r\ns = input()\r\n... | {"inputs": ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcd... | UNKNOWN | PYTHON3 | CODEFORCES | 248 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.