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
21e1ee2d6df8c4908bb9a6d812841345
Word Folding
You will receive 5 points for solving this problem. Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t...
[ "import sys\n#sys.stdin = open(\"input.txt\", \"r\")\n\na = [-1]*91\nb = [0]*91\ni = 0\nfor c in input():\n c = ord(c)\n b[c] += a[c] < 0 or i != a[c]\n a[c] = i\n i ^= 1\nprint(max(b))\n ", "t = {}\nfor i, c in enumerate(input()):\n if c not in t: t[c] = (i, 1)\n elif (t[c][0] - i) & 1: t[c] = (i, t[c...
{"inputs": ["ABRACADABRA", "ABBBCBDB", "AB", "ABBCDEFB", "THISISATEST", "Z", "ZZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABACBCABACACB", "LEHLLLLLLHAFGEGLLHAFDLHHLLLLLDGGEHGGHLLLLLLLLDFLCBLLEFLLCBLLCGLEDLGGLECLDGLEHLLLGELLLEGLLLLGDLLLDALD", "THISISTHELASTTEST"], "outputs": ["3", "3", "1", "3", "3", "1", "2", "1", "4", "49", "...
UNKNOWN
PYTHON3
CODEFORCES
2
21fc26573a8d903daa076191d191a0f5
Unbearable Controversy of Being
Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different! Tomash has noticed that even simple cases of...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef f(a):\r\n return a*(a-1)//2\r\n\r\n\r\nn, m = map(int, input().split())\r\nd = [[] for _ in range(n+1)]\r\nc = 0\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n d[a].append(b)\r\nfor i in range(1, n+1):\r\n q = dict()\r\n for j i...
{"inputs": ["5 4\n1 2\n2 3\n1 4\n4 3", "4 12\n1 2\n1 3\n1 4\n2 1\n2 3\n2 4\n3 1\n3 2\n3 4\n4 1\n4 2\n4 3", "1 0", "10 20\n6 10\n4 2\n1 5\n6 1\n8 9\n1 3\n2 6\n9 7\n4 5\n3 7\n9 2\n3 9\n4 8\n1 10\n6 9\n8 5\n7 6\n1 8\n8 10\n5 6", "3000 0", "1 0", "2 0", "2 1\n1 2", "2 2\n1 2\n2 1", "3 0", "3 6\n1 2\n1 3\n2 1\n2 3\n3 1\n3 2...
UNKNOWN
PYTHON3
CODEFORCES
2
21fddb423e53f4d61cb410a6f5bbb7a7
Sleep in Class
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs. The stairs consists of *n* steps. The steps are numbered from bottom to top, it means that the lowest s...
[ "n=int(input())\r\nstring = input()\r\nq1,q2,B,C=[],[],[],[]\r\nA=0\r\nfor i in range(n):\r\n if string[i] == \"D\":\r\n q1.append(i)\r\n else:\r\n q2.append(n-1-i)\r\n\r\nfor i in range(len(q1)):\r\n A+=(q1[i]-i)*2+1\r\n B.append(A)\r\n\r\nA=0\r\ntemp = []\r\nfor i in range(len(q2)):\r\n ...
{"inputs": ["3\nUUD", "10\nUUDUDUUDDU", "10\nDUDDUUDUDD", "1\nD", "2\nDU", "3\nDUU", "4\nDDDU", "5\nDDDUD", "50\nDDDDDDDDDDDDDDDDDDDDDDDDDUUUUUUUUUUUUUUUUUUUUUUUUU", "50\nUUUUUUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDDDDDD", "1\nD", "1\nU"], "outputs": ["5 6 3 ", "5 12 23 34 36 27 18 11 6 1 ", "1 4 7 14 23 32 30 19 12 5...
UNKNOWN
PYTHON3
CODEFORCES
1
22091ef7481b60323c746ca6fbc97fc7
Vitya in the Countryside
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units...
[ "n=int(input())\r\nl=list(map(int,input().split()))\r\nif n==1 and l[0]!=15 and l[0]!=0 :\r\n print(-1)\r\nelse :\r\n if l[n-1]==15 :\r\n print('DOWN')\r\n if l[n-1]==0 :\r\n print('UP')\r\n if l[n-1]!=15 and l[n-1]!=0 and n!=1 :\r\n if l[n-1]-l[n-2]>0 :\r\n print('UP')\r...
{"inputs": ["5\n3 4 5 6 7", "7\n12 13 14 15 14 13 12", "1\n8", "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10", "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1...
UNKNOWN
PYTHON3
CODEFORCES
123
22198e3a7c0abd019255159882cb5048
Eevee
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl...
[ "from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt, log\r\nfrom collections import defaultdict, Counter\r\ndef IA(sep=' '): return list(map(int, inp().split(sep)))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp()...
{"inputs": ["7\n...feon", "7\n.l.r.o.", "6\n.s..o.", "7\nglaceon", "8\n.a.o.e.n", "7\n.laceon", "7\n..lveon", "7\n.l.ceon", "7\n..areon"], "outputs": ["leafeon", "flareon", "espeon", "glaceon", "vaporeon", "glaceon", "sylveon", "glaceon", "flareon"]}
UNKNOWN
PYTHON3
CODEFORCES
172
221a624387ca6d14359b006a62613cd2
Pyramids
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of co...
[ "from sys import stdin, stdout\r\n\r\n\r\ndef solve():\r\n l3, l4, l5 = (int(s) for s in stdin.readline().split())\r\n v1 = l3*l3*l3*(2**0.5)*2\r\n v2 = l4*l4*l4*(2**0.5)*4\r\n v3 = l5*l5*l5*(2**0.5)*((15+5*(5**0.5))**0.5)\r\n ans = (v1+v2+v3)/24\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__'...
{"inputs": ["2 5 3", "3 4 5", "1 1 1", "1000 1000 1000", "999 997 998", "1 999 1000", "709 328 709", "982 948 879", "99 23 530", "1 2 998"], "outputs": ["38.546168065709", "55.954779230131", "0.655056222989", "655056222.989098310000", "650782658.915145640000", "536498692.999083940000", "157775455.683012100000", "517178...
UNKNOWN
PYTHON3
CODEFORCES
1
2233068987c95f8e6f31d0648e88a1bb
Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not en...
[ "n = int(input())\r\nlis = input().split()\r\n#print(lis)\r\nans=1\r\nzer=0\r\nfor i in lis:\r\n l=len(i)\r\n k=i.count('1')\r\n j=i.count('0')\r\n if k+j==l:\r\n if k>1:\r\n ans*=int(i)\r\n else:\r\n if j==l:\r\n print('0')\r\n exit()\r\...
{"inputs": ["3\n5 10 1", "4\n1 1 10 11", "5\n0 3 1 100 1", "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100", "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 10000000000000000000000...
UNKNOWN
PYTHON3
CODEFORCES
81
22c337ec8ce9b0fba407e3224879d095
Consecutive Subsequence
You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$. Su...
[ "n = int(input())\r\nnums = list(map(int, input().split()))\r\n# 存储以每个数字结尾的最长连续序列长度\r\nseq_len = {}\r\n# 构建连续序列长度的字典\r\nfor num in nums:\r\n seq_len[num] = seq_len.get(num - 1, 0) + 1\r\n# 寻找最长序列的结束数字和长度\r\nend, max_len = max(seq_len, key=seq_len.get), max(seq_len.values())\r\n# 回溯找到序列索引\r\nindices = []\r\nwhile...
{"inputs": ["7\n3 3 4 7 5 6 8", "6\n1 3 5 2 4 6", "4\n10 9 8 7", "9\n6 7 8 3 4 5 9 10 11", "1\n1337", "2\n456 123", "7\n100 3 4 7 5 6 8", "7\n3 3 4 5 6 7 8", "12\n1 2 3 4 5 6 7 8 9 10 11 12"], "outputs": ["4\n2 3 5 6 ", "2\n1 4 ", "1\n1 ", "6\n1 2 3 7 8 9 ", "1\n1 ", "1\n1 ", "4\n2 3 5 6 ", "6\n2 3 4 5 6 7 ", "12\n1 2 ...
UNKNOWN
PYTHON3
CODEFORCES
5
22e73f576e0a29ac8f1acaad7b95ca42
Kuriyama Mirai's Stones
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*...
[ "import sys\r\nimport threading\r\nfrom sys import stdin, stdout\r\nfrom itertools import accumulate\r\ninput = stdin.readline\r\nprint = stdout.write\r\n\r\nif __name__ == \"__main__\":\r\n\r\n n = int(input().strip())\r\n\r\n arr = list(map(int, input().strip().split()))\r\n arr_sort = sorted(arr) #this ...
{"inputs": ["6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2", "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2...
UNKNOWN
PYTHON3
CODEFORCES
467
23300678e886bea71fe9a35c71bc04e8
R2D2 and Droid Army
An army of *n* droids is lined up in one row. Each droid is described by *m* integers *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of details of the *i*-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has *m* weapons, the *i*-th weapon can aff...
[ "def rl():\r\n return list(map(int,input().split()))\r\ndef ri():\r\n return int(input())\r\ndef rs():\r\n return input()\r\ndef rm():\r\n return map(int,input().split())\r\nfrom math import log2,floor\r\ndef main():\r\n n,l,k=rm()\r\n rb=[]\r\n for i in range(n):\r\n rb.append(rl())\r\n...
{"inputs": ["5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3", "3 2 4\n1 2\n1 3\n2 2", "1 1 0\n0", "1 1 0\n1", "1 1 1\n0", "4 5 33\n2 10 2 3 2\n10 6 4 5 0\n3 1 7 3 2\n4 4 2 1 5", "4 5 40\n0 10 9 0 4\n10 5 5 7 4\n9 9 5 5 2\n6 7 9 4 3", "31 2 1913\n845 576\n862 325\n914 283\n431 837\n193 171\n30 248\n290 488\n810 552\n463 74\n765 469\n78...
UNKNOWN
PYTHON3
CODEFORCES
1
233f32c704219a8929d73e179f9d4a8f
Little Pony and Crystal Mine
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot...
[ "n=int(input())\r\nx=int(n/2)\r\nfor i in range(1,n+1):\r\n\tprint(\"*\"*x+'D'*(n-(2*x))+'*'*x)\r\n\tif i <=int(n/2) :\r\n\t\tx-=1\r\n\telse :\t\r\n\t\tx+=1\r\n\t# print(x,i)", "q=lambda:map(int,input().split())\r\nqi=lambda:int(input())\r\nqs=lambda:input().split()\r\nn=qi()\r\nstar=n//2\r\nd=1\r\nfor i in range...
{"inputs": ["3", "5", "7", "11", "15", "21", "33", "57", "69", "81", "91", "101"], "outputs": ["*D*\nDDD\n*D*", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***", "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n*...
UNKNOWN
PYTHON3
CODEFORCES
308
23522805b8d87a2adfb4a95b8c4ba94f
Functions On The Segments
You have an array *f* of *n* functions.The function *f**i*(*x*) (1<=≤<=*i*<=≤<=*n*) is characterized by parameters: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 and take values: - *y*1, if *x*<=≤<=*x*1. - *a*·*x*<=+<=*b*, if *x*1<=&lt;<=*x*<=≤<=*x*2. - *y*2, if *x*<=&gt;<=*x*2. There are *m* queries. Each query is deter...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef get_segment(s, t):\r\n s, t = s + l1, t + l1\r\n ans = []\r\n while s <= t:\r\n if s & 1:\r\n ans.append(s)\r\n s += 1\r\n s >>= 1\r\n if not t & 1:\r\n ans.a...
{"inputs": ["1\n1 2 1 4 5 10\n1\n1 1 2", "3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5", "7\n4 8 562244866 6 8 140807945\n5 7 415374420 7 6 596093578\n3 4 766370993 3 7 973128805\n4 6 841321398 3 2 893107667\n4 9 968214628 5 8 329310838\n0 10 64315145 9 4 716996081\n1 6 568407659 3 0 22184171\n15\n...
UNKNOWN
PYTHON3
CODEFORCES
1
23782452cf5313c2d3b5626ea74e0e61
Water Taps
Consider a system of *n* water taps all pouring water into the same container. The *i*-th water tap can be set to deliver any amount of water from 0 to *a**i* ml per second (this amount may be a real number). The water delivered by *i*-th tap has temperature *t**i*. If for every you set *i*-th tap to deliver exactly ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, t0 = map(int, input().split())\r\na = list(map(int, input().split()))\r\nt = list(map(int, input().split()))\r\nl = pow(10, 6) + 1\r\nc = [0] * l\r\ns = 0\r\nfor i, j in zip(a, t):\r\n c[j] += i\r\n s += (j - t0) * i...
{"inputs": ["2 100\n3 10\n50 150", "3 9\n5 5 30\n6 6 10", "2 12\n1 3\n10 15", "20 30\n70 97 14 31 83 22 83 56 19 87 59 7 7 89 24 82 34 40 6 24\n10 4 47 46 11 18 32 55 16 32 53 37 43 32 41 46 57 14 60 44", "1 1\n1000000\n1", "1 200\n1000000\n100", "1 1000000\n1000000\n1000000"], "outputs": ["6.000000000000000", "40.0000...
UNKNOWN
PYTHON3
CODEFORCES
3
237ca36d287733e0a58c9626c31d87aa
Businessmen Problems
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies. In order to avoid this representatives of both companies decided to make an agreement on the ...
[ "n = int(input())\n\nelements = {}\nelements = dict(elements)\nfor i in range(n): \n a, b = map(int, input().split())\n elements[a] = b\nm = int(input())\nfor i in range(m): \n a, b = map(int, input().split())\n if elements.get(a): \n elements[a] = max(elements[a], b)\n else: \n element...
{"inputs": ["3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4", "1\n1000000000 239\n3\n14 15\n92 65\n35 89", "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n8...
UNKNOWN
PYTHON3
CODEFORCES
212
2397732f27101ac11fd5369b72448274
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monste...
[ "R = lambda: map(int, input().split())\nn = int(input())\na = list(R())\nm = int(input())\nb = list(R())\nst = i = j = 0\nres = ''\nwhile i < m:\n psum = 0\n while j < n and psum < b[i]:\n psum += a[j]\n j += 1\n if psum != b[i]:\n print('NO')\n exit(0)\n mi = st if a[st] > a...
{"inputs": ["6\n1 2 2 2 1 2\n2\n5 5", "5\n1 2 3 4 5\n1\n15", "5\n1 1 1 3 3\n3\n2 1 6", "5\n1 1 1 1 2\n3\n1 1 4", "5\n1 1 1 1 1\n4\n1 1 2 1", "6\n2 1 2 2 1 2\n2\n5 5", "8\n2 5 3 1 4 2 3 4\n3\n10 6 8", "1\n959139\n1\n470888", "3\n2 2 1\n1\n5", "3\n1 2 2\n1\n5", "5\n1 2 3 4 5\n1\n10", "5\n325539 329221 106895 882089 71867...
UNKNOWN
PYTHON3
CODEFORCES
3
239a5762998495b0fe4bf42d3952fd48
Tea Queue
Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th s...
[ "#!/usr/bin/env python3\nfrom sys import stdin, stdout\n\ndef rint():\n return map(int, stdin.readline().split())\n#lines = stdin.readlines()\n\n\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n lb, rb = 0, 0\n ct = 0\n ans = []\n for __ in range(n):\n lc, rc = rint()\n i...
{"inputs": ["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3", "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000", "1\n11\n1 1\n1 1\n1 1\n1 1\n1...
UNKNOWN
PYTHON3
CODEFORCES
72
23c012a6f7008cf0064bf7ecf55b2fd3
Antichain
You have a directed acyclic graph *G*, consisting of *n* vertexes, numbered from 0 to *n*<=-<=1. The graph contains *n* edges numbered from 0 to *n*<=-<=1. An edge with number *i* connects vertexes *i* and (*i*<=+<=1) *mod* *n*, and it can be directed in either direction (from *i* to (*i*<=+<=1) *mod* *n*, or vise vers...
[ "# i'm from jasnah, do not ban me\r\ns = input()\r\nn = len(s)\r\na = 0\r\ni = 0\r\n\r\nwhile i < n:\r\n if s[i] != s[(i + 1) % n]:\r\n if s[i] != s[(i + 2) % n]:\r\n a += 1\r\n elif s[i] != s[(i + 3) % n]:\r\n i += 1\r\n a += 1\r\n i += 1\r\n\r\nprint(a)\r\n" ]
{"inputs": ["001", "110010", "0010011110", "0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110", "0110101100", "0111110110", "0001011111", "0000011010101001001100101111111011100000011000101001011001000111110000010000100011011011101101100110", "00001000001100101000100101...
UNKNOWN
PYTHON3
CODEFORCES
1
23c3c1aedb4a37389c4a191f8443ae42
Interesting drink
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite ...
[ "import bisect\r\nN=int(input())\r\nx=sorted(list(map(int,input().split())))\r\nfor i in range(int(input())):\r\n print(bisect.bisect(x,int(input())))", "n = int(input())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nfor _ in range(int(input())):\r\n c = int(input())\r\n low, high = 0, n - 1\r\n ...
{"inputs": ["5\n3 10 8 6 11\n4\n1\n10\n3\n11", "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\...
UNKNOWN
PYTHON3
CODEFORCES
284
23ebcca15bd46dead8f1b185628d3dc9
Packmen
A game field is a strip of 1<=×<=*n* square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial ...
[ "'''\r\npacman->food\r\npacman->food->food :hmmge:\r\nlarges smaller val\r\nsmallest larger val\r\n'''\r\ndef check(mid,p,f):\r\n\tu=0\r\n\tfor i in range(len(p)):\r\n\t\tleft=p[i]-f[u]\r\n\t\tleft=max(0,left)\r\n\t\tif mid<left:\r\n\t\t\treturn 0\r\n\t\tright=max(mid-2*left,0)\r\n\t\tright=max(right,(mid-left)//2)...
{"inputs": ["7\n*..P*P*", "10\n.**PP.*P.*", "19\n**P.*..*..P..*.*P**", "12\nP**.*P*P*P**", "58\n..P.P*.P*.P...PPP...P*....*..*.**......*P.*P.....**P...*P*", "10\n..P*.P.*.*", "10\n***.*.*..P", "15\nP***..PPP..P*.P", "20\n.P**P**P**PP.PP**PP*", "20\n.....*.**..........P", "25\n...*..**..*.....*..*...P.", "30\n*P.*...*.*...
UNKNOWN
PYTHON3
CODEFORCES
7
23eee3079293ce0dc454eed8b1e186ab
Let's Play Osu!
You're playing a game called Osu! Here's a simplified version of it. There are *n* clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of *n* characters "O" and "X". Using the play sequence you can calculate...
[ "n = int(input())\r\np = list(map(float, input().split()))\r\nif n == 1:\r\n print(p[0])\r\n quit()\r\nM = [0.0] * n\r\nf = [0.0] * n\r\nf[0] = 1.0\r\nfor i in range(1, n):\r\n f[i] = p[i] * f[i - 1] + 1 - p[i]\r\nres = p[0] * p[1]\r\nans = res\r\nfor i in range(2, n):\r\n temp = (1 - p[i - 1]) + p[i - ...
{"inputs": ["3\n0.5 0.5 0.5", "4\n0.7 0.2 0.1 0.9", "5\n1 1 1 1 1", "10\n0.684846 0.156794 0.153696 0.714526 0.281868 0.628256 0.745339 0.123854 0.748936 0.856333", "10\n0.684488 0.834971 0.834886 0.643646 0.162710 0.119851 0.659401 0.743950 0.220986 0.839665", "10\n0.684416 0.170607 0.491124 0.469470 0.458879 0.658170...
UNKNOWN
PYTHON3
CODEFORCES
14
23f7e534541a11b5794fceedb3aa1919
Road Map
There are *n* cities in Berland. Each city has its index — an integer number from 1 to *n*. The capital has index *r*1. All the roads in Berland are two-way. The road system is such that there is exactly one path from the capital to each city, i.e. the road map looks like a tree. In Berland's chronicles the road map is...
[ "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, r1, r2 = map(int, input().split())\r\nadj = [[] for _ in range(n + 1)]\r\nv = 1\r\nfor u in map(int, input().split()):\r\n if v == r1:\r\n v += 1\r\n adj[...
{"inputs": ["3 2 3\n2 2", "6 2 4\n6 1 2 4 2", "7 7 6\n7 7 5 5 7 7", "4 2 3\n2 1 3", "5 5 4\n5 4 1 5", "6 2 1\n4 1 2 2 2", "2 1 2\n1", "2 2 1\n2", "3 1 3\n1 2", "10 4 3\n5 6 9 10 1 9 6 8 4", "100 62 42\n45 66 13 18 93 47 83 19 41 66 5 70 16 29 54 28 65 91 92 24 90 54 7 40 77 53 68 58 70 65 68 30 94 80 16 18 69 21 94 1 9...
UNKNOWN
PYTHON3
CODEFORCES
12
241db9c5a973ea82a73166583a928c0d
Mahmoud and Ehab and another array construction task
Mahmoud has an array *a* consisting of *n* integers. He asked Ehab to find another array *b* of the same length such that: - *b* is lexicographically greater than or equal to *a*. - *b**i*<=≥<=2. - *b* is pairwise coprime: for every 1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*, *b**i* and *b**j* are coprime, i. e. *GCD*(*b**i*,<=*...
[ "# https://codeforces.com/contest/959\n\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\n\nclass PrimesUtil:\n def __init__(self, mx):\n assert 1 <= mx\n self.mx = mx\n self.prime_numbers = []\n self.prime = [False] * 2 + [True] * (mx - 1)\n self.facto...
{"inputs": ["5\n2 3 5 4 13", "3\n10 3 7", "5\n7 10 2 5 5", "7\n20 9 7 6 7 9 15", "10\n5 3 2 2 3 3 3 4 2 5", "3\n3 18 2"], "outputs": ["2 3 5 7 11 ", "10 3 7 ", "7 10 3 11 13 ", "20 9 7 11 13 17 19 ", "5 3 2 7 11 13 17 19 23 29 ", "3 19 2 "]}
UNKNOWN
PYTHON3
CODEFORCES
4
2429f322b7cc404abce8166b8b9136a5
Caisa and Sugar
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just *s* dollars for sugar. But that's not a reason to be sad, because there are *n* types of sugar in the supermarket, maybe he able to buy one. B...
[ "n,m=map(int,input().split())\r\ncounter=-1\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n if(m*100>=(x*100)+y):\r\n counter=max(counter,(100-y)%100)\r\n\r\nprint(counter)", "a,b=map(int,input().split())\r\nsum=-1\r\nb=b*100\r\nwhile a:\r\n a-=1\r\n s,t=map(int,input().split())\r\n ...
{"inputs": ["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50", "1 2\n1 0", "2 10\n20 99\n30 99", "15 21\n16 51\n33 44\n32 92\n19 91\n67 81\n94 94\n40 67\n77 38\n42 22\n48 19\n9 35\n90 36\n57 80\n58 97\n13 15", "1 2\n5 0", "37 10\n57 61\n78 79\n59 60\n48 17\n39 22\n11 87\n19 55\n56 78\n25 12\...
UNKNOWN
PYTHON3
CODEFORCES
36
242feae3e5b6572f61ecbafac4a4cf6f
Berland Local Positioning System
In Berland a bus travels along the main street of the capital. The street begins from the main square and looks like a very long segment. There are *n* bus stops located along the street, the *i*-th of them is located at the distance *a**i* from the central square, all distances are distinct, the stops are numbered in ...
[ "r = lambda: list(map(int, input().split()))\r\nri = lambda: int(input())\r\nn, a, m, b = ri(), r(), ri(), r()\r\nc = [0] * n\r\nfor e in b: c[e - 1] += 1\r\nc[0] *= 2; c[-1] *= 2\r\nd = 0\r\ndf= 0\r\nr = max(e // 2 for e in c)\r\nc = [e - r * 2 for e in c]\r\nif any(c):\r\n for i in range(n - 1):\r\n de ...
{"inputs": ["6\n2 3 5 7 11 13\n5\n3 4 5 5 6", "6\n2 3 5 7 11 13\n9\n1 2 2 3 3 4 5 5 6", "3\n10 200 300\n4\n1 2 2 3", "3\n1 2 3\n4\n1 2 2 3", "2\n1 1000000000\n1\n1", "2\n1 1000000000\n1\n2", "2\n1 1000000000\n2\n1 2", "2\n1 1000000000\n3\n1 1 2", "2\n1 1000000000\n3\n1 2 2", "2\n1 1000000000\n4\n1 1 2 2", "3\n1 3 11\n2...
UNKNOWN
PYTHON3
CODEFORCES
1
245edba82711e93fa3c7b2d0769daac0
none
Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, *f*0... ∞. *f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? ...
[ "sln = [75]\r\nfor i in range(80):\r\n\tsln.append(min(10**18 + 10, 68 + 2 * sln[-1]))\r\n\r\nf0 = 'What are you doing at the end of the world? Are you busy? Will you save us?'\r\nf1_1 = 'What are you doing while sending \"'\r\nf1_2 = '\"? Are you busy? Will you send \"'\r\nf1_3 = '\"?'\r\n\r\ndef getAns(n, k):\r\n...
{"inputs": ["3\n1 1\n1 2\n1 111111111111", "5\n0 69\n1 194\n1 139\n0 47\n1 66", "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474", "1\n0 1", "1\n999 1000000000000000000", "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4", "10\n5 235941360876088213\n10 65160787148797531\n0 531970131175601...
UNKNOWN
PYTHON3
CODEFORCES
11
2461eb7af104edc7e4dc97240eba293c
Tanya and Password
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the pas...
[ "from collections import defaultdict, deque\r\n\r\ndef find_eulerian_path(graph):\r\n in_degree = defaultdict(int)\r\n out_degree = defaultdict(int)\r\n for u in graph:\r\n for v in graph[u]:\r\n out_degree[u] += 1\r\n in_degree[v] += 1\r\n\r\n start = None\r\n end = None...
{"inputs": ["5\naca\naba\naba\ncab\nbac", "4\nabc\nbCb\ncb1\nb13", "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa", "1\nabc", "2\nbba\nabb", "3\naaa\naaa\naab", "2\naba\nbab", "2\nabc\nbga", "4\naba\nbab\ncdc\ndcd", "4\nbaa\ncaa\naax\naay", "2\naba\naba", "5\n123\n234\n345\n456\n567", "3\n42y\n2ya\nya6", "8\nzHW\ncwx\nxmo\nWcw\...
UNKNOWN
PYTHON3
CODEFORCES
2
24727c565c8de8d98b5f7525b92f4188
Plumber
Little John aspires to become a plumber! Today he has drawn a grid consisting of *n* rows and *m* columns, consisting of *n*<=×<=*m* square cells. In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows: Each pipe segment has two ends, illustrated...
[ "import sys \r\nn, m = map(int, sys.stdin.readline().split())\r\nstr = [sys.stdin.readline() for _ in range(n)]\r\nqw = [[0, 0] for _ in range(m)]\r\nasd = [[0, 0] for _ in range(n)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if str[i][j] != '.':\r\n x = int(str[i][j]) - 1\r\n ...
{"inputs": ["2 2\n13\n..", "3 1\n1\n4\n.", "2 2\n3.\n.1", "2 2\n..\n..", "2 2\n32\n41", "4 4\n....\n.3.3\n....\n.3.3", "1 3\n12.", "1 1\n4", "2 2\n..\n1.", "1 1\n."], "outputs": ["2", "0", "1", "16", "1", "16", "0", "1", "4", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
1
249f6787700af82291a3ea226be0f68f
Soft Drinking
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each frie...
[ "n,k,l,c,d,p,nl,np = tuple(map(int,input().split()))\r\ndrink = (k*l)//(nl)\r\nslice = c*d\r\nsalt = p//np\r\nprint(min(drink,slice,salt)//n)", "a = list(map(int, input().split()))\r\ntotal_drink = a[1] * a[2]\r\ntotal_slice = a[3] * a[4]\r\ntotal_salt = a[5] // a[7]\r\nprint(min(total_drink//a[6], total_slice, t...
{"inputs": ["3 4 5 10 8 100 3 1", "5 100 10 1 19 90 4 3", "10 1000 1000 25 23 1 50 1", "1 7 4 5 5 8 3 2", "2 3 3 5 5 10 1 3", "2 6 4 5 6 5 1 3", "1 7 3 5 3 6 2 1", "2 4 5 4 5 7 3 2", "2 3 6 5 7 8 2 1", "1 4 5 5 3 10 3 1", "1 4 6 7 3 5 1 3", "1 6 5 5 5 8 3 1", "1 7 5 3 3 9 2 1", "3 5 3 7 6 10 3 1", "3 6 3 5 3 6 3 1", "1...
UNKNOWN
PYTHON3
CODEFORCES
713
24a5265e9508929ff7aba46a658ca400
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x...
[ "n = int(input())\r\na = input().split()\r\nb = input().split()\r\n\r\nor_a = 0\r\nor_b = 0\r\nfor i in range(n):\r\n or_a |= int(a[i])\r\n or_b |= int(b[i])\r\n\r\nprint(or_a + or_b)\r\n", "import sys\r\nimport math\r\n\r\n#to read string\r\nget_string = lambda: sys.stdin.readline().strip()\r\n#to read lis...
{"inputs": ["5\n1 2 4 3 2\n2 3 3 12 1", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116", "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 6...
UNKNOWN
PYTHON3
CODEFORCES
187
24c217d715fb4fddc13a3e2389631c73
Tree Queries
You are given a tree consisting of *n* vertices (numbered from 1 to *n*). Initially all vertices are white. You have to process *q* queries of two different types: 1. 1 *x* — change the color of vertex *x* to black. It is guaranteed that the first query will be of this type. 1. 2 *x* — for the vertex *x*, find the m...
[ "from collections import deque\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef bfs(s):\r\n q = deque()\r\n q.append(s)\r\n dp = [inf] * (n + 1)\r\n dp[s] = s\r\n while q:\r\n i = q.popleft()\r\n for j in G[i]:\r\n if dp[j] ^ in...
{"inputs": ["4 6\n1 2\n2 3\n3 4\n1 2\n1 2\n2 2\n1 3\n2 2\n2 2", "10 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 3\n2 10\n1 8\n1 7\n1 6\n1 4\n2 9\n2 7\n1 5\n1 5", "10 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n1 10\n1 4\n1 1\n2 7\n2 4\n1 2\n2 6\n2 4\n2 3\n1 3", "10 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8...
UNKNOWN
PYTHON3
CODEFORCES
2
24d955e00035d7cf0cc67a95de0b508b
Vasya and the Bus
One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had *n* grown-ups and *m* kids..." The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers cou...
[ "n,m=map(int,input().split())\r\nif n==0:\r\n if m==0:\r\n print(0,0)\r\n else:\r\n print('Impossible')\r\nelse:\r\n if m==0:\r\n print(n,n)\r\n else:\r\n best=m+n-min(m,n)\r\n worst=m+(n-1)\r\n print(best,worst)", "n,m=map(int,input().split())\r\nif(n==0 and ...
{"inputs": ["1 2", "0 5", "2 2", "2 7", "4 10", "6 0", "7 1", "0 0", "71 24", "16 70", "0 1", "1 0", "1 1", "63 82", "8 26", "21 27", "0 38", "46 84", "59 96", "63028 0", "9458 0", "80236 0", "26666 0", "59617 0", "0 6048", "63028 28217", "9458 39163", "80236 14868", "26666 52747", "59617 28452", "6048 4158", "76826 42...
UNKNOWN
PYTHON3
CODEFORCES
41
24d9f8e55c368c2af7b5d03bbea4d3f5
none
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size *n*<=×<=*m*. T...
[ "#!/usr/bin/env python3\r\n\r\ntry:\r\n while True:\r\n n, m, q = map(int, input().split())\r\n cmds = [tuple(map(int, input().split())) for i in range(q)]\r\n a = [[0] * m for i in range(n)]\r\n for t in reversed(cmds):\r\n if t[0] == 1:\r\n i = t[1] - 1\r\n...
{"inputs": ["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5", "5 5 1\n1 5", "1 1 3\n1 1\n2 1\n3 1 1 1000000000", "1 1 3\n1 1\n2 1\n3 1 1 -1000000000", "2 2 6\n2 1\n2 2\n3 1 1 -1\n3 2 2 -1\n3 1 2 -1\n3 2 1 -1", "1 4 5\n1 1\n3 1 1 1\n3 1 2 2\n3 1 3 3\n3 1 4 4", "4 2 5\n2 1\n3 1 1 5\n3 2 1 6\n3...
UNKNOWN
PYTHON3
CODEFORCES
25
24dbe8f3cdc00759382e9f0f0b4eccc4
Choose Place
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the p...
[ "l = [[],[],[],[],[],[]];\r\ny = [[3, 3, 4, 4, 3, 3],\r\n [3, 3, 4, 4, 3, 3],\r\n [2, 2, 3, 3, 2, 2],\r\n [2, 2, 3, 3, 2, 2],\r\n [1, 1, 2, 2, 1, 1],\r\n [1, 1, 2, 2, 1, 1]]\r\nfor i in range(6):\r\n s = input()\r\n for j in s:\r\n if (j != '-'):\r\n l[i].append(j)\r\nmax...
{"inputs": ["..-**-..\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
38
24e150d8c5f260671cf9203c5ee1e940
Equivalent Strings
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
[ "memo = {}\r\ndef solve(a, b):\r\n if (a,b) in memo:\r\n return memo[a,b]\r\n if len(a)%2 == 1:\r\n return a == b\r\n \r\n half = len(a)//2\r\n a1, a2 = a[:half], a[half:]\r\n b1, b2 = b[:half], b[half:]\r\n\r\n memo[a,b] = (solve(a1, b1) and solve(a2, b2)) or (solve(a1, b2) and ...
{"inputs": ["aaba\nabaa", "aabb\nabab", "a\na", "a\nb", "ab\nab", "ab\nba", "ab\nbb", "zzaa\naazz", "azza\nzaaz", "abc\nabc", "abc\nacb", "azzz\nzzaz", "abcd\ndcab", "abcd\ncdab", "abcd\ndcba", "abcd\nacbd", "oloaxgddgujq\noloaxgujqddg", "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta", "hagnzomowtledfdotnll\nledfdotnllomowthagnz"...
UNKNOWN
PYTHON3
CODEFORCES
236
24f19bdb6be07ff0093e1444727f095f
New Year and Buggy Bot
Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex...
[ "import itertools\n\nn, m = map(int, input().rstrip().split())\nmas = []\nstart = [0, 0]\nend = [0, 0]\nfor i in range(n):\n s = input()\n for j in range(len(s)):\n if s[j] == 'S':\n start = [i, j]\n elif s[j] == 'E':\n end = [i, j]\n mas.append(s)\nk = input()\n\ncou = ...
{"inputs": ["5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "5 3\n...\n.S.\n###\n.E.\n...\n3", "10 10\n.#......#.\n#.........\n#.........\n....#.#..E\n.......#..\n....##....\n....S.....\n....#.....\n.........#\n...##...#.\n2332333231...
UNKNOWN
PYTHON3
CODEFORCES
73
24f4d21c263435dc34ebb0ec7f3d03a5
Vladik and Courtesy
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving eac...
[ "import math\nwhile True:\n try:\n a,b=map(int,input().split())\n except:\n break\n n=math.sqrt(a)\n n=int(n)\n bt=(n+1)*n\n if b>=bt:\n print(\"Vladik\")\n else:\n print(\"Valera\")\n", "def main():\r\n\ta , b = map(int,input().split())\r\n\ti = 1\r\n\twhile 1:\r\...
{"inputs": ["1 1", "7 6", "25 38", "8311 2468", "250708 857756", "957985574 24997558", "999963734 999994456", "1000000000 1000000000", "946 879", "10819 45238", "101357 236928", "1033090 7376359", "9754309 9525494", "90706344 99960537", "965161805 908862070", "9 11", "3 2", "6 6", "4 4", "5 5", "5 4", "12345680 1", "9 ...
UNKNOWN
PYTHON3
CODEFORCES
283
250fe4a733401a84274fcd5e4cc507cb
Flag Day
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: - overall, there must be *m* dances;- exactly three people must take part in each dance;- each d...
[ "n , m = list(map (int, input().split()))\r\n\r\ncList = [0]*n\r\n\r\nfor i in range(m) :\r\n x, y, z = list(map (int, input().split()))\r\n\r\n r, s, t = cList[x -1], cList[y -1], cList[z -1]\r\n if r > 0 :\r\n s = (r + 1) % 3\r\n t = (r + 2) % 3\r\n if s == 0:\r\n s = 3\r\...
{"inputs": ["7 3\n1 2 3\n1 4 5\n4 6 7", "9 3\n3 6 9\n2 5 8\n1 4 7", "5 2\n4 1 5\n3 1 2", "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12", "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9", "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5", "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6", "14 6\n5 4 8\n5 7 1...
UNKNOWN
PYTHON3
CODEFORCES
113
2517406285090844d7d7115b9128e8f9
Petya and Inequiations
Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=≥<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=*y* The first line contains three space-separated integers *n*, *x* and *y* (1<=≤<=*...
[ "\r\nn,x,y=map(int,input().split())\r\nimport math\r\nan=n-1\r\nif(x<=n-1):\r\n if(y>=n):\r\n for i in range(n):\r\n print(1)\r\n else:\r\n print(-1)\r\nelse:\r\n me=math.sqrt(x-an)\r\n if(me==int(me)):\r\n me=int(me)\r\n if(me+an<=y):\r\n for i in range...
{"inputs": ["5 15 15", "2 3 2", "1 99 11", "100000 810000099998 1000000", "3 254 18", "4 324 77", "5 315 90", "6 225 59", "7 351 29", "100 913723780421 955988", "200 894176381082 945808", "300 923251939897 961159", "1000 824905348050 909242", "10000 795416053320 901860", "31000 819461299082 936240", "44000 772772899626...
UNKNOWN
PYTHON3
CODEFORCES
26
2526cb35c0d93ebb38fe1749da75e883
Number of Triplets
You are given *n* points on a plane. All points are different. Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*. The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C...
[ "N = 1000\nn = int(input())\nx = []\ny = []\nf = [[0 for x in range(3*N)] for y in range(3*N)]\ns = 0\nfor i in range(n):\n\tu, v = map(int, input().split())\n\tx.append(u)\n\ty.append(v)\n\tf[u+N][v+N] = 1\nfor i in range(n):\n\tfor j in range(i+1, n):\n\t\tu = x[i]+x[j]\n\t\tv = y[i]+y[j]\n\t\ts += not(u % 2 or v...
{"inputs": ["3\n1 1\n2 2\n3 3", "3\n0 0\n-1 0\n0 1", "4\n0 0\n1 0\n2 0\n3 0", "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5", "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 0", "9\n1 1\n1 0\n0 1\n0 0\n-1 0\n-1 1\n-1 -1\n1 -1\n0 -1", "10\n2 1\n-1 0\n-2 -1\n-1 1\n0 2\n2 -2\n0 0\n-2 -2\n0 -2\n-2 1", "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2...
UNKNOWN
PYTHON3
CODEFORCES
23
2552869b7f8bc189f2c0c77a04453143
INTERCALC
DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I M...
[ "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-30 23:20:25\nLastEditTime: 2021-11-30 23:22:04\nDescription: INTERCALC\nFilePath: CF784C.py\n'''\n\n\ndef func():\n n = int(input())\n lst = list(map(int, input().strip().split()))\n print(max(lst) ^ lst[-1])\n\n\nif __name__ == '__m...
{"inputs": ["4\n2 5 3 1", "2\n1 5", "1\n8", "6\n1 1 1 3 2 9", "5\n8 9 3 1 9", "6\n1 5 2 1 7 11", "8\n1 6 11 8 5 10 7 8", "3\n4 9 6", "2\n4 8", "3\n1 1 5", "5\n4 5 5 2 11", "6\n1 7 2 8 8 2", "5\n3 9 3 2 3", "7\n6 6 1 1 1 2 3", "7\n11 1 2 8 10 5 9", "7\n4 5 1 10 10 4 1", "10\n5 5 10 10 10 2 4 3 4 10", "8\n4 7 11 3 11 3 1...
UNKNOWN
PYTHON3
CODEFORCES
16
2554309042d9ec24d87c896f7ba99482
Command Line Arguments
The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document. In the Pindows operating system a strings ...
[ "import shlex\r\nfor s in shlex.split(input()):\r\n print('<' + s + '>')", "def main():\r\n string = input()\r\n\r\n answer_arr = []\r\n temp_string = \"\"\r\n open_quote = False\r\n for character in string:\r\n if character == '\"':\r\n if open_quote:\r\n open_q...
{"inputs": ["\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"", " firstarg second \"\" ", " \" \" ", " a \" \" a \"\" a ", "A", "\"\"", "\" \"", "\" \" \"wu\" \"\" \" \" \"\" \"\" \"\" ", "\"7\" \"W \" \"\" \"\" \"a \" \"\" \"\" \"\" y ", "\"\" \"\" \". \" \"A\" \"\" \"\" \"\" k \"...
UNKNOWN
PYTHON3
CODEFORCES
13
2556101bcb9b00b841fbeb612b2d3950
Cinema
Moscow is hosting a major international conference, which is attended by *n* scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109. In the evening after the conference, all *n* scientists decided to g...
[ "from collections import Counter\r\ninp= lambda:list(map(int, input().split()))\r\nn,scientist, i,audio,sbt = int(input()), inp(), int(input()), inp(), inp()\r\ncounter = Counter(scientist)\r\nmovies = list(zip(audio,sbt))\r\nresult = sorted(movies, key=lambda x: (counter[x[0]], counter[x[1]]), reverse= True)[0]\r\...
{"inputs": ["3\n2 3 2\n2\n3 2\n2 3", "6\n6 3 1 1 3 7\n5\n1 2 3 4 5\n2 3 4 5 1", "1\n10\n1\n10\n3", "2\n1 6\n1\n6\n1", "1\n5\n2\n2 2\n5 5", "2\n4 4\n2\n4 7\n7 5", "10\n3 1 8 8 1 1 5 1 3 5\n2\n1 4\n3 1", "10\n7 6 1 2 7 3 9 7 7 9\n10\n2 9 6 5 9 3 10 3 1 6\n4 6 7 9 7 4 1 9 2 5", "20\n2 2 1 6 6 5 10 2 5 5 4 8 6 8 8 10 2 1 5...
UNKNOWN
PYTHON3
CODEFORCES
19
25677e811c8ecc52c1ee71b93c80a7fd
Game
In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle...
[ "import sys\r\nfrom array import array # noqa: F401\r\nfrom collections import defaultdict\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nk, n, m, q = map(int, input().split())\r\nbasic = [input().rstrip() for _ in range(n)]\r\ncomposite = defaultdict(list)\r\nfor _ in...
{"inputs": ["2 3 2 5\ndesolator\nrefresher\nperseverance\nvanguard: desolator 1, refresher 1\nmaelstorm: perseverance 2\n1 desolator\n2 perseverance\n1 refresher\n2 desolator\n2 perseverance", "2 3 2 5\na\nb\nc\nd: a 1, b 1\ne: c 2\n1 a\n2 c\n1 b\n2 c\n2 c", "10 1 1 3\na\nb: a 2\n1 a\n1 a\n1 a", "2 3 2 5\ndesolator\nre...
UNKNOWN
PYTHON3
CODEFORCES
2
256f1073ba43640c9ceff83143a93081
Sonya and Hotels
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
[ "n, d = map(int, input().split())\r\nli = list(map(int, input().split()))\r\nc = 2\r\nfor i in range(1, n):\r\n if (li[i] - li[i-1]) == 2*d:\r\n c = c + 1\r\n if (li[i] - li[i-1]) > 2*d:\r\n c = c + 2\r\nprint(c)", "n,k = map(int, input().split())\r\nk *= 2\r\nl = input().split()\r\nsumi = 2\r...
{"inputs": ["4 3\n-3 2 9 16", "5 2\n4 8 11 18 19", "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "10 10\n0 20 48 58 81 95 111 137 147 159", "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96...
UNKNOWN
PYTHON3
CODEFORCES
383
257624b63116c5dfb1ba7d3521e72bed
Checkout Assistant
Bob came to a cash &amp; carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c**i* and time *t**i* in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from...
[ "n = int(input())\nt, c = [], []\n\nfor _ in range(n):\n ti, ci = map(int, input().split())\n t.append(ti + 1)\n c.append(ci)\n\ndp = [[float('inf') for _ in range(n + 1)] for _ in range(n + 1)]\n\nfor i in range(n + 1):\n dp[i][0] = 0\n\nfor i in range(1, n + 1):\n for j in range(1, n + 1):\n ...
{"inputs": ["4\n2 10\n0 20\n1 5\n1 3", "3\n0 1\n0 10\n0 100", "2\n0 635254032\n0 75159864", "2\n0 861438648\n1 469893784", "2\n2 87623264\n0 864627704", "5\n0 51690939\n0 62436494\n0 39009053\n0 70426298\n0 631569476", "5\n0 968804136\n0 736567537\n2 343136264\n0 259899572\n1 425744418", "5\n4 33400980\n2 410698581\n4 ...
UNKNOWN
PYTHON3
CODEFORCES
10
2596f17ff730075940d9426f2b8b66e2
Rectangular Game
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has *n* pebbles. He arranges them in *a* equal rows, each row has *b* pebbles (*a*<=&gt;<=1). Note that the Beaver must use all the pebble...
[ "import math\r\nn = int(input())\r\nsum=n\r\nx = n\r\nwhile (x!=1):\r\n f = True\r\n for i in range(2,int(math.sqrt(x))+1):\r\n if x%i==0:\r\n x=x//i\r\n f = False\r\n break\r\n if f:\r\n x = 1\r\n sum+=x\r\nprint(sum)", "def min_div(num):\r\n\tfor i in r...
{"inputs": ["10", "8", "4", "36", "32", "46", "6", "13", "9", "18", "20", "37", "42", "50", "48", "33", "49", "34", "35", "37", "39", "42", "14", "2", "3", "5"], "outputs": ["16", "15", "7", "67", "63", "70", "10", "14", "13", "31", "36", "38", "71", "81", "94", "45", "57", "52", "43", "38", "53", "71", "22", "3", "4",...
UNKNOWN
PYTHON3
CODEFORCES
137
2603a61557410075552cd451e048e3de
New Problem
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Yo...
[ "# from dust i have come, dust i will be\r\n\r\nn = int(input())\r\na = []\r\n\r\nfor i in range(n):\r\n x = input()\r\n a.append(x)\r\n\r\narr = []\r\nfor i in range(26):\r\n arr.append(chr(i + ord('a')))\r\n\r\nfor i in range(26):\r\n for j in range(26):\r\n arr.append(arr[i] + chr(j + ord('a')...
{"inputs": ["5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear", "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc", "1\na", "1\nb", "1\nz", "5\nsplt\nohqykk\nxqpz\nknojbur\npmfm", "2\nrxscdzkkezud\nwjehahqgouqvjienq", "2\nxlaxwpjabtpwddc\ntxwdjmohrrszorrnomc", "1\nepkotfpkkrhhmuipmtdk", "2\nhk\nobsp", "3\nrjnflsb...
UNKNOWN
PYTHON3
CODEFORCES
36
26074f95ee047bcf97707736dcd359a6
Star sky
The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*). Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at mom...
[ "input=__import__('sys').stdin.readline\r\nn,q,c=map(int,input().split())\r\ndp= [[[0 for i in range(101)] for j in range(101)]for k in range(c+1)]\r\nfor i in range(n):\r\n x,y,s = map(int,input().split())\r\n dp[s][x][y]+=1\r\nfor i in range(c+1):\r\n for j in range(1,101):\r\n for k in range(1,10...
{"inputs": ["2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5", "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51"], "outputs": ["3\n0\n3", "3\n3\n5\n0"]}
UNKNOWN
PYTHON3
CODEFORCES
17
2608bd8a990c81e43e433d7209973bfb
New Year Transportation
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0...
[ "n,t=map(int,input().split())\r\nai=list(map(int,input().split()))\r\nai.insert(0,0)\r\nvisited=False\r\ncurrentcell=1\r\nwhile currentcell<=t:\r\n currentcell=currentcell+ai[currentcell]\r\n if currentcell==t:\r\n visited=True\r\n break\r\nif visited:\r\n print(\"YES\")\r\nelse:\r\n print...
{"inputs": ["8 4\n1 2 1 2 1 2 1", "8 5\n1 2 1 2 1 1 1", "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1", "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 2...
UNKNOWN
PYTHON3
CODEFORCES
479
260b30fbb2bc2ccd461fce570369a337
High School: Become Human
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl...
[ "x, y = map(int, input().split())\r\nif ((x == y) or ((x == 2) and (y == 4)) or ((x == 4) and (y == 2))) : print('=')\r\nelse :\r\n if (((x == 2) and (y == 3)) or (x == 1)) : print('<')\r\n else :\r\n if (((x == 3) and (y == 2)) or (y == 1)) : print('>')\r\n else :\r\n if (x < y) : pr...
{"inputs": ["5 8", "10 3", "6 6", "14 1", "2 4", "987654321 123456987", "1 10", "9 1", "1 1", "2 2", "3 3", "4 4", "5 5", "2 3", "2 5", "3 2", "3 4", "3 5", "4 2", "4 3", "4 5", "5 2", "5 3", "5 4", "100 101", "876543 372647", "1000000000 999999999", "1000000000 2", "1000000000 1", "987654321 123456789", "1000000000 10...
UNKNOWN
PYTHON3
CODEFORCES
126
263dec96d78bc29b65ddd53d4e793a14
Ciel and Dancing
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: - either the boy in the dancing pair must dance for the first time ...
[ "m, n = map(int, input().split())\r\nls = []\r\nfor i in range(m):\r\n ls1 = (str(i + 1), '1')\r\n ls.append(ls1)\r\nfor j in range(1, n):\r\n ls1 = ('1', str(j + 1))\r\n ls.append(ls1)\r\n\r\nprint(len(ls))\r\nfor i in ls:\r\n print(' '.join(i))", "b,g=map(int,input().split());g-=1\r\nprint(b+g)\r...
{"inputs": ["2 1", "2 2", "1 1", "2 3", "4 4", "1 12", "12 1", "100 100", "24 6", "7 59", "26 75", "32 87", "42 51", "4 63", "10 79", "20 95", "35 55", "45 71", "7 83", "32 100", "42 17", "1 77", "19 93", "25 5", "35 21", "99 99", "99 100", "100 99"], "outputs": ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2", "1\n1 1", "4\n1 1\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
131
264ce6a14a5e091a72fd750eb279c9d1
Business trip
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water...
[ "from sys import exit\r\nreqhi = int(input())\r\nlst = list(map(int,input().split()))\r\ngrohi,count = 0,0\r\nwhile grohi<reqhi:\r\n if len(lst)==0:\r\n print(-1)\r\n exit()\r\n x = max(lst)\r\n grohi += x\r\n lst.pop(lst.index(x))\r\n count+=1\r\nprint(count)\r\n", "k = int(input())\...
{"inputs": ["5\n1 1 1 1 2 2 3 2 2 1 1 1", "0\n0 0 0 0 0 0 0 1 1 2 3 0", "11\n1 1 4 1 1 5 1 1 4 1 1 1", "15\n20 1 1 1 1 2 2 1 2 2 1 1", "7\n8 9 100 12 14 17 21 10 11 100 23 10", "52\n1 12 3 11 4 5 10 6 9 7 8 2", "50\n2 2 3 4 5 4 4 5 7 3 2 7", "0\n55 81 28 48 99 20 67 95 6 19 10 93", "93\n85 40 93 66 92 43 61 3 64 51 90 ...
UNKNOWN
PYTHON3
CODEFORCES
316
265643648e982d50113fd040d81d878e
What is for dinner?
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
[ "n, m, k = map(int, input().split())\r\nd = [-1 for i in range(m)]\r\n \r\nfor i in range(n):\r\n r, c = map(int, input().split())\r\n r -= 1\r\n d[r] = c if d[r] == -1 else min(d[r], c)\r\n \r\nans = 0\r\nfor i in d:\r\n ans += i\r\n \r\nprint(min(ans, k))", "n,m,k = map(int,input().split())\r\n\r\nv...
{"inputs": ["4 3 18\n2 3\n1 2\n3 6\n2 3", "2 2 13\n1 13\n2 12", "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "1 1 0\n1 3", "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16", "4 2 8\n1 9\n1 10\n1 4\n2 6", "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0", "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\...
UNKNOWN
PYTHON3
CODEFORCES
73
26590802eae1165c1ef752a1f65bc001
Lucky Numbers
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
[ "b=input()\r\na=[int(i) for i in b]\r\nl=len(a)\r\nflag=0\r\ns=0\r\nf=0\r\nif l%2==1:\r\n flag=1\r\n\r\nelse:\r\n for i in range(l):\r\n if a[i]>7:\r\n flag=1\r\n if(s==l//2 or s==i+1):\r\n break\r\n for j in range(i,-1,-1):\r\n if a[j]==4:...
{"inputs": ["4500", "47", "1", "12", "4587", "100", "1007", "99999999", "49102094540227023300", "1000000000", "777777", "99999999", "474", "85469", "7474747", "2145226", "5556585", "87584777", "77777777", "1000000000", "999999999", "74477744", "444444444", "467549754", "147474747", "555", "100000", "74777443", "4700007...
UNKNOWN
PYTHON3
CODEFORCES
4
266a1d7c803771117c8c2e3572000a36
Drazil and Factorial
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul...
[ "answer = {\n \"7\": [7],\n \"8\": [7, 2, 2, 2],\n \"9\": [7, 3, 3, 2],\n \"6\": [5, 3],\n \"5\": [5],\n \"4\": [3, 2, 2],\n \"3\": [3],\n \"2\": [2],\n \"1\": [],\n \"0\": []\n}\ndef main():\n _ = input()\n inp = str(input())\n ans = []\n for i in inp:\n ans += answ...
{"inputs": ["4\n1234", "3\n555", "15\n012345781234578", "1\n8", "10\n1413472614", "8\n68931246", "7\n4424368", "6\n576825", "5\n97715", "3\n915", "2\n26", "1\n4", "15\n028745260720699", "13\n5761790121605", "10\n3312667105", "1\n7", "15\n989898989898989", "15\n000000000000007", "15\n999999999999990", "1\n2", "1\n3", "1...
UNKNOWN
PYTHON3
CODEFORCES
264
267a0c5f52c91226c15d7f2b4ed743da
Simple Molecules
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one...
[ "a, b, c = [int(c) for c in input().split()]\n\n\nif ((b - c + a) % 2 == 1) or ((b - c + a) < 0) or ((b + c - a) < 0) or (((-b) + c + a) < 0):\n print(\"Impossible\")\nelse:\n x = (b - c + a) // 2\n y = (b + c - a) // 2\n z = ((-b) + c + a) // 2\n print(f\"{x} {y} {z}\")\n\n\t \t \t\t \t\t\t\t ...
{"inputs": ["1 1 2", "3 4 5", "4 1 1", "1 1 1", "1000000 1000000 1000000", "3 11 8", "8 5 12", "1000000 500000 1", "1000000 500000 2", "2 2 2", "3 3 3", "4 4 4", "2 4 2", "10 5 14", "10 5 15", "10 4 16", "3 3 6", "9 95 90", "3 5 8", "5 8 13", "6 1 5", "59 54 56", "246 137 940", "7357 3578 9123", "93952 49553 83405", "6...
UNKNOWN
PYTHON3
CODEFORCES
5
268367e01de0c640fb14121de2c71171
Mike and Fish
As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish. He has marked *n* distinct points in the plane. *i*-th point is point (*x**i*,<=*y**i*). He wants to put exactly one fish in each of these points such...
[ "from sys import stdin, stdout\r\nfrom collections import defaultdict\r\n\r\ntime = 0\r\nc = 2*10**5\r\nn = 4*10**5+2\r\ncol = 0\r\n\r\nfinished= [0]*n\r\nfor_node = [0]*n\r\n\r\nf_range=range\r\nf_len=len\r\n\r\ndef dfs_euler_tour(node: int, graph):\r\n\r\n stack = []\r\n global colour\r\n global col\r\n ...
{"inputs": ["4\n1 1\n1 2\n2 1\n2 2", "3\n1 1\n1 2\n2 1", "3\n157210 22861\n175396 39466\n40933 17093", "5\n55599 84144\n169207 98421\n1909 186625\n31525 147710\n7781 82078", "15\n44249 54630\n165741 91307\n49455 83026\n52521 88269\n39286 65158\n38282 73821\n96608 30032\n155832 122920\n22021 13546\n161556 192797\n168062...
UNKNOWN
PYTHON3
CODEFORCES
1
26931ae597cbb3891a79c3265e535a8d
none
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a tick...
[ "from sys import stdin\r\nfrom bisect import *\r\n\r\nrint = lambda: int(stdin.readline())\r\nrint_2d = lambda n: [rint() for _ in range(n)]\r\nn = int(input())\r\na, mem, out = rint_2d(n), [0] * (n + 1), []\r\n\r\nfor i in range(n):\r\n vals = [mem[i] + 20]\r\n ix1 = max(bisect_left(a, a[i] - 90 + 1), 0)\r\n...
{"inputs": ["3\n10\n20\n30", "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "7\n100\n138\n279\n308\n396\n412\n821", "8\n0\n2\n51\n63\n69\n75\n80\n90", "8\n0\n3\n5\n6\n7\n8\n9\n10", "1\n0"], "outputs": ["20\n20\n10", "20\n20\n10\n0\n20\n0\n0\n20\n20\n10", "20\n20\n20\n20\n20\n20\n0", "20\n20\n10\n0\n0\n0\n0\n20", "...
UNKNOWN
PYTHON3
CODEFORCES
29
269b7d25ead4791a23137dacc9b960b3
Fox and Minimal path
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with *n* vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2." Same with some writers, she wants to make an example with some certain outp...
[ "n, m, cnt = int(input()), 148, 0\nans = [['N'] * m for i in range(m)]\n\ndef edge(i, j):\n ans[i][j] = ans[j][i] = 'Y'\n\ndef node(*adj):\n global cnt\n i = cnt\n cnt += 1\n for j in adj:\n edge(i, j)\n return i\n\nstart, end, choice = node(), node(), node()\nif n&1:\n edge(choice, end)...
{"inputs": ["2", "9", "1", "7", "10", "16", "27", "29", "31", "1000000", "167959139", "641009859", "524125987", "702209411", "585325539", "58376259", "941492387", "824608515", "2691939", "802030518", "685146646", "863230070", "41313494", "219396918", "102513046", "985629174", "458679894", "341796022", "519879446", "452...
UNKNOWN
PYTHON3
CODEFORCES
5
26cc6aa4badbd062042813c0fab3d680
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his *n* students took part in the exam. The teach...
[ "import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353\r\n\r\nstrings = []\r\nfor i in range(3):\r\n s = S()\r\n letter = \"\"\r\n for j in range(len(s)):\r\n if 97<=ord(s[j])<=122:\r\n ...
{"inputs": ["Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "Shapur;;\nis___\na_genius\n3\nShapur__a_is___geniUs\nis___s...
UNKNOWN
PYTHON3
CODEFORCES
88
26da59ebb8bc79d0a2378b568f4e52c3
Divisors
Bizon the Champion isn't just friendly, he also is a rigorous coder. Let's define function *f*(*a*), where *a* is a sequence of integers. Function *f*(*a*) returns the following sequence: first all divisors of *a*1 go in the increasing order, then all divisors of *a*2 go in the increasing order, and so on till the las...
[ "import sys \r\nsolSaved = {} #diccionario donde se almacenan los divisores de un numero x, se toma como llave un string y se devuelve una lista\r\nsolSavedPropios = {} #diccionario donde se almacenan los divisores propios de un numero x, se toma como llave un string y se devuelve una lista\r\n\r\ndef DivisorsN(n):...
{"inputs": ["6 1", "4 2", "10 3", "10 0", "1 1", "1 1000000000000000000", "16 10", "963761198400 1", "963761198400 65535", "1000000000000 0", "963761198400 576460752303423487", "128 10", "8 50", "999999999989 1727", "999999999899 2816", "999999999989 99999", "999999999899 100000", "549755813888 4", "549755813888 13", "...
UNKNOWN
PYTHON3
CODEFORCES
1
26db7e114e5d76aa0dd20d2ef4c1bee6
Changing a String
There is a string *s*, consisting of capital Latin letters. Let's denote its current length as |*s*|. During one move it is allowed to apply one of the following operations to it: - INSERT *pos* *ch* — insert a letter *ch* in the string *s* in the position *pos* (1<=≤<=*pos*<=≤<=|*s*|<=+<=1,<=*A*<=≤<=*ch*<=≤<=*Z*). ...
[ "def editDistance(s, t):\r\n sl = len(s)\r\n tl = len(t)\r\n for i in range(tl + 1):\r\n dp[0][i] = i\r\n for i in range(sl + 1):\r\n dp[i][0] = i\r\n\r\n for i in range(1, sl + 1):\r\n for j in range(1, tl + 1):\r\n if s[i - 1] == t[j - 1]:\r\n dp[i][j] = dp[i - 1][j - 1]\...
{"inputs": ["ABA\nABBBA", "ACCEPTED\nWRONGANSWER", "V\nBNBNE", "UB\nPWL", "JOYXNKYPF\nGDV", "SZDAWSVGK\nUM", "TJHGFKKCDOHRNAXZROCWIYFF\nZBWUEHEVEOUATECAGLZIQMUDXEMHRSOZMAUJRWLQMPPZOUMXHAMWUGEDIKVKBLVMXWUOFMPAFDPRBCFTEWOULCZWRQHCTBTBXRHHODWBCXWIMNCNEXOSKSUJLISGCLLLXOKRSBNOZTHAJNNLILYFFMSYKOFPTXRNEFBSOUHFOLTIQAINRPXWRQ",...
UNKNOWN
PYTHON3
CODEFORCES
1
26e5e5661b2a18386dc068f0f49e66e4
Cutting Banner
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ...
[ "s=input()\r\ni=len(s)-1\r\n\r\nif(s.find(\"C\")==0 and s[i-8:]==(\"ODEFORCES\")):\r\n print(\"YES\")\r\nelif(s.find(\"CO\")==0 and s[i-7:]==(\"DEFORCES\")):\r\n print(\"YES\")\r\nelif(s.find(\"COD\")==0 and s[i-6:]==(\"EFORCES\")):\r\n print(\"YES\")\r\nelif(s.find(\"CODE\")==0 and s[i-5:]==(\"FORCES\")):...
{"inputs": ["CODEWAITFORITFORCES", "BOTTOMCODER", "DECODEFORCES", "DOGEFORCES", "ABACABA", "CODEFORCE", "C", "NQTSMZEBLY", "CODEFZORCES", "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF", "OCECFDSRDE", "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEW...
UNKNOWN
PYTHON3
CODEFORCES
72
26eb6a4362396e077c4834f617cf17c1
Covered Path
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constan...
[ "#sry...\r\n\r\nv1, v2 = map(int, input().split())\r\nt, d = map(int, input().split())\r\nL1 = [0]*t\r\nL2 = [0]*t\r\nL1[0] = v1\r\nfor i in range(1, t):\r\n L1[i] = L1[i-1]+d\r\nj = t-2\r\nL2[j+1] = v2\r\nwhile j >= 0:\r\n L2[j] = L2[j+1]+d\r\n j -= 1\r\nans = 0\r\nfor i in range(0, t):\r\n ans += min(...
{"inputs": ["5 6\n4 2", "10 10\n10 0", "87 87\n2 10", "1 11\n6 2", "100 10\n10 10", "1 1\n100 10", "1 1\n5 1", "1 1\n5 2", "100 100\n100 0", "100 100\n100 10", "1 100\n100 1", "1 100\n100 10", "100 1\n100 1", "100 1\n100 10", "1 10\n2 10", "1 1\n2 1", "1 1\n2 10", "1 2\n2 1", "1 2\n2 10", "1 5\n3 2", "2 1\n2 2", "2 1\n...
UNKNOWN
PYTHON3
CODEFORCES
117
26f13d75ab3cd66221e8975cb5136a05
Planning The Expedition
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t...
[ "n, m = map(int, input().split())\n\npackages = list(map(int, input().split()))\n\ncounts = dict()\n\nfor p in packages:\n\tif p in counts:\n\t\tcounts[p] += 1\n\telse:\n\t\tcounts[p] = 1\n\narrayCounts = []\nfor package, count in counts.items():\n\tarrayCounts.append(count)\n\narrayCounts.sort()\narrayCounts.rever...
{"inputs": ["4 10\n1 5 2 1 1 1 2 5 7 2", "100 1\n1", "2 5\n5 4 3 2 1", "3 9\n42 42 42 42 42 42 42 42 42", "1 1\n100", "4 100\n84 99 66 69 86 94 89 96 98 93 93 82 87 93 91 100 69 99 93 81 99 84 75 100 86 88 98 100 84 96 44 70 94 91 85 78 86 79 45 88 91 78 98 94 81 87 93 72 96 88 96 97 96 62 86 72 94 84 80 98 88 90 93 73...
UNKNOWN
PYTHON3
CODEFORCES
162
2700f76d05ed9d786799492f4c826085
Doctor
There are *n* animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number *i* in the queue will have to visit...
[ "from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nsa = sum(a)\r\nif sa <= k:\r\n ans = -1 if sa ^ k else \"\"\r\n print(ans)\r\n exit()\r\ncnt = default...
{"inputs": ["3 3\n1 2 1", "4 10\n3 3 2 1", "7 10\n1 3 3 1 2 3 1", "1 0\n1", "6 101\n9 78 54 62 2 91", "9 100\n11 11 11 11 11 11 11 11 11", "10 77\n7 45 10 10 9 8 1 2 3 1", "5 12\n1 3 4 1 5", "5 23\n7 1 4 7 9", "5 41\n19 19 19 15 20", "10 7\n5 1 2 5 4 3 5 2 2 4", "10 109\n5 5 4 4 8 10 9 10 9 8", "20 430\n25 27 25 24 24 ...
UNKNOWN
PYTHON3
CODEFORCES
5
273f86099d235ddb272017f24d54ff90
Giving Awards
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else. Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ...
[ "import sys\r\nn,m=map(int,sys.stdin.readline().split())\r\nP={}\r\nfor i in range(m):\r\n a,b=map(int,sys.stdin.readline().split())\r\n P[(a-1,b-1)]=1\r\n\r\nA=[-1]*n\r\nA[0]=0\r\nfor i in range(1,n):\r\n j=1\r\n A[i]=i\r\n x=i\r\n while(x>0 and (A[x-1],A[x]) in P):\r\n A[x-1],A[x]=A[x],A[...
{"inputs": ["2 1\n1 2", "3 3\n1 2\n2 3\n3 1", "10 45\n10 5\n10 7\n6 1\n5 8\n3 5\n6 5\n1 2\n6 10\n2 9\n9 5\n4 1\n7 5\n1 8\n6 8\n10 9\n7 2\n7 9\n4 10\n7 3\n4 8\n10 3\n10 8\n2 10\n8 2\n4 2\n5 2\n9 1\n4 5\n1 3\n9 6\n3 8\n5 1\n6 4\n4 7\n8 7\n7 1\n9 3\n3 4\n6 2\n3 2\n6 7\n6 3\n4 9\n8 9\n1 10", "4 6\n3 4\n4 1\n4 2\n2 1\n3 2\n...
UNKNOWN
PYTHON3
CODEFORCES
4
276e4a6596f5df558504926e8cb13609
Spongebob and Joke
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence *a*1,<=*a*2,<=...,<=*a**m* of length *m*, consisting of integers from 1 to *n*, not necessarily distinct. Then he picked some sequence *f*1,<=*f*2,<=....
[ "n, m = map(int, input().split())\r\nf, b = [int(e) for e in input().split()], [int(e) for e in input().split()]\r\nF, l = {}, []\r\nfor e, u in enumerate(f):\r\n if u in F:\r\n F[u] = 0\r\n else:\r\n F[u] = e+1\r\nfor e in b:\r\n if e in F:\r\n if F[e] > 0:\r\n l += [F[e]]\...
{"inputs": ["3 3\n3 2 1\n1 2 3", "3 3\n1 1 1\n1 1 1", "3 3\n1 2 1\n3 3 3", "2 100\n2 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "5 6\n5 2 4 3 5\n1 2 3 4 4 5",...
UNKNOWN
PYTHON3
CODEFORCES
8
277d4ef7196d95a0f81fc8d1062ce98d
Planets
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet. Overall the galaxy has *...
[ "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\nN,M = map(int...
{"inputs": ["4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n3 4 3\n0\n1 3\n2 3 4\n0", "3 1\n1 2 3\n0\n1 3\n0", "2 1\n1 2 3\n0\n1 3", "2 1\n1 2 3\n1 0\n0", "3 3\n1 2 5\n2 3 6\n1 3 7\n0\n0\n0", "3 3\n1 2 3\n2 3 2\n1 3 7\n0\n0\n0", "2 0\n0\n0", "3 1\n1 2 3\n1 1\n1 5\n0", "2 1\n1 2 3\n0\n2 2 4", "2 1\n1 2 1\n0\n0", "2 1\n2 1 1000...
UNKNOWN
PYTHON3
CODEFORCES
12
2780dc35f4b3d6b38846a3670b9c4d27
Given Length and Sum of Digits...
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. The single line of the input contains a pa...
[ "def Min(m, s):\r\n if s == 0:\r\n return 0 if m == 1 else -1\r\n a = [0] * m\r\n a[-1] = s - 1\r\n i = len(a) - 1\r\n while a[i] > 9:\r\n if i <= 0:\r\n return -1\r\n a[i - 1], a[i] = a[i] - 9, 9\r\n i -= 1\r\n a[0] += 1\r\n if a[0] > 9:\r\n return...
{"inputs": ["2 15", "3 0", "2 1", "3 10", "100 100", "1 900", "1 9", "1 0", "1 1", "1 2", "1 8", "1 10", "1 11", "2 0", "2 1", "2 2", "2 8", "2 10", "2 11", "2 16", "2 17", "2 18", "2 19", "2 20", "2 900", "3 1", "3 2", "3 3", "3 9", "3 10", "3 20", "3 21", "3 26", "3 27", "3 28", "3 100", "100 0", "100 1", "100 2", "1...
UNKNOWN
PYTHON3
CODEFORCES
60
27912b09315cd9d2d2025df33ade7e4b
Anya and Smartphone
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen contains *k* icons. The icons from the first to the *k*-th one are located on the first screen, from the (*k*<...
[ "from sys import stdin\r\nfrom collections import *\r\n\r\n\r\ndef arr_inp(n):\r\n if n == 1:\r\n return [int(x) for x in stdin.readline().split()]\r\n elif n == 2:\r\n return [float(x) for x in stdin.readline().split()]\r\n else:\r\n return list(stdin.readline()[:-1])\r\n\r\n\r\nn, m,...
{"inputs": ["8 3 3\n1 2 3 4 5 6 7 8\n7 8 1", "5 4 2\n3 1 5 2 4\n4 4 4 4", "10 10 3\n1 2 3 4 5 6 7 8 9 10\n2 3 4 5 6 7 8 9 10 1", "10 12 3\n6 1 2 9 3 10 8 5 7 4\n3 9 9 4 8 2 3 8 10 8 3 4", "16 12 8\n6 11 12 5 1 10 16 3 13 15 9 4 8 2 14 7\n6 13 8 12 8 15 12 16 8 11 3 16", "4 3 5\n3 1 4 2\n4 2 4", "4 2 15\n2 4 3 1\n1 2", ...
UNKNOWN
PYTHON3
CODEFORCES
26
27a77c2ab905683f7ad7df0fcd6084c9
XK Segments
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and...
[ "from bisect import bisect_left as b\r\nf = lambda: map(int, input().split())\r\nn, x, k = f()\r\ns, t = 0, sorted(f())\r\np = [(q, ((q - 1) // x + k) * x) for q in t]\r\nfor q, d in p: s += b(t, d + x) - b(t, max(q, d))\r\nprint(s)", "from bisect import bisect_left as b\r\nr=lambda:map(int,input().split())\r\nn,...
{"inputs": ["4 2 1\n1 3 5 7", "4 2 0\n5 3 1 7", "5 3 1\n3 3 3 3 3", "5 3 4\n24 13 1 24 24", "4 2 2\n1 3 5 7", "5 1 0\n10 12 14 20 30", "7 3 1\n3 3 6 9 12 15 18", "2 5 0\n3 4", "3 5 0\n4 4 4", "3 6 0\n3 4 5", "10 2 1\n2 2 2 2 2 2 2 1 2 1", "100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1...
UNKNOWN
PYTHON3
CODEFORCES
23
27af0c4bf25826baa2ff43d700aa6bb8
Jerry's Protest
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing *n* balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to...
[ "from sys import *\r\n\r\nn = int(input())\r\nm = int(5000)\r\n\r\nvls = sorted([int(t) for t in stdin.readline().split()])\r\nr1 = [0 for t in range(m)]\r\nfor i in range(n-1):\r\n for k in range(i+1, n):\r\n r1[vls[k] - vls[i]] += 1\r\n\r\nr2 = [0 for t in range(m*2)]\r\nfor i in range(m):\r\n for k ...
{"inputs": ["2\n1 2", "3\n1 2 10", "3\n1 2 3", "4\n2 4 1 3", "11\n1 2 4 8 16 32 64 128 256 512 1024", "18\n69 88 49 91 42 56 58 13 38 93 77 99 18 32 82 81 92 46", "16\n14 34 22 53 11 40 50 12 91 86 32 75 36 33 41 9", "11\n54 91 4 6 88 23 38 71 77 26 84", "20\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20", ...
UNKNOWN
PYTHON3
CODEFORCES
9
27b36ddbab25919f8d6f603219863b67
none
For an array $b$ of length $m$ we define the function $f$ as where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$ You are given an array $a$ and a few queri...
[ "n = int(input())\r\nA = list(map(int,input().split(\" \")))\r\n\r\nmatrix = []\r\nfor i in range(n):\r\n matrix.append([0]*n)\r\n\r\nfor i in range(n):\r\n matrix[i][i] = A[i]\r\n\r\nfor i in reversed(range(0,n)):\r\n for j in range(i+1,n):\r\n matrix[i][j] = matrix[i][j-1]^matrix[i+1][j]\r\n\r\nf...
{"inputs": ["3\n8 4 1\n2\n2 3\n1 2", "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2"], "outputs": ["5\n12", "60\n30\n12\n3"]}
UNKNOWN
PYTHON3
CODEFORCES
26
27d436a018d8df1f648fabd72efa16f7
Smart Boy
Once Petya and Vasya invented a new game and called it "Smart Boy". They located a certain set of words — the dictionary — for the game. It is admissible for the dictionary to contain similar words. The rules of the game are as follows: first the first player chooses any letter (a word as long as 1) from any word fro...
[ "import sys\nfrom collections import defaultdict\n\nreadline = sys.stdin.readline\n\ndef score_word(word: str, subs: dict, graph:defaultdict):\n tmp = {}\n for i in range(len(word)):\n v, m = 0, 0\n for j in range(i, len(word)):\n val = ord(word[j]) - ord('a') + 1\n v += va...
{"inputs": ["2\naba\nabac", "3\nartem\nnik\nmax", "1\njyi", "2\naz\nkagim", "3\nskz\nsauy\nrxu", "6\nrdxo\nvpe\npa\nlrlqy\nzj\nicbdch", "8\nvvdclj\nyvb\nhelty\nb\na\nzwyuvkl\nspqtnqmlx\nrghfmkbt", "10\nndqlxtrxiftvtji\naoblenbunumdge\nlgkmt\nx\nx\nbg\nds\nnlhdlxeh\nugxufipnaxvkxl\nk", "14\nym\nbi\nyu\nyb\nvwtb\nsemn\nb...
UNKNOWN
PYTHON3
CODEFORCES
1
27d894e4222e08d40735bc2a7f8ac2bf
Okabe and City
Okabe likes to be able to walk through his city on a path lit by street lamps. That way, he doesn't get beaten up by schoolchildren. Okabe's city is represented by a 2D grid of cells. Rows are numbered from 1 to *n* from top to bottom, and columns are numbered 1 to *m* from left to right. Exactly *k* cells in the city...
[ "import heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef dijkstra(s, n):\r\n dist = [inf] * n\r\n dist[s] = 0\r\n visit = [0] * n\r\n p = []\r\n heapq.heappush(p, (dist[s], s))\r\n while p:\r\n d, u = heapq.heappop(p)\r\n if dist[...
{"inputs": ["4 4 5\n1 1\n2 1\n2 3\n3 3\n4 3", "5 5 4\n1 1\n2 1\n3 1\n3 2", "2 2 4\n1 1\n1 2\n2 1\n2 2", "5 5 4\n1 1\n2 2\n3 3\n4 4", "7 10 53\n1 1\n7 5\n2 3\n5 3\n1 9\n2 10\n6 1\n7 6\n2 9\n3 3\n3 4\n5 1\n5 4\n1 10\n4 1\n3 10\n7 7\n7 8\n7 1\n1 8\n2 4\n6 5\n3 5\n6 3\n6 6\n2 8\n3 6\n5 2\n3 8\n3 9\n5 5\n7 2\n3 1\n4 8\n1 3\...
UNKNOWN
PYTHON3
CODEFORCES
1
2823db17c9eac312a30cd139d327c0b9
The Best Gift
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find th...
[ "n, m = map(int, input().split())\na = list(map(int, input().split()))\nd = {i:0 for i in range(1, m+1)}\n\nfor num in a:\n d[num] += 1\n\nn_sum = 0\nfor i in range(1, m+1):\n n_sum += d[i]*(d[i]-1)//2\n\nprint(int(n*(n-1)/2 - n_sum))", "import math\r\n\r\nn, m = map(int, input().split(' '))\r\na = list(map...
{"inputs": ["4 3\n2 1 3 1", "7 4\n4 2 3 1 2 4 3", "2 2\n1 2", "3 2\n1 2 2", "10 10\n1 2 3 4 5 6 7 8 9 10", "9 2\n1 1 1 1 2 1 1 1 1", "12 3\n1 2 3 1 2 3 1 2 3 1 2 3", "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 ...
UNKNOWN
PYTHON3
CODEFORCES
156
28246d079b86cc5aea0af5f8f33a5423
Lengthening Sticks
You are given three sticks with positive integer lengths of *a*,<=*b*, and *c* centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most *l* centimeters. In particular, it is allowed not to incre...
[ "#in the name of god\r\n#Mr_Rubick\r\na,b,c,l=map(int, input().split())\r\ncnt=(l+3)*(l+2)*(l+1)//3\r\nfor i in (a,b,c):\r\n s=2*i-a-b-c\r\n for x in range(max(0,-s),l+1):\r\n m = min(s+x,l-x)\r\n cnt-=(m+1)*(m+2)\r\nprint(cnt//2)\r\n", "def solve(a, b, c, sz):\r\n ret = 0\r\n for inc in ran...
{"inputs": ["1 1 1 2", "1 2 3 1", "10 2 1 7", "1 2 1 5", "10 15 17 10", "5 5 5 10000", "5 7 30 100", "5 5 5 300000", "4 2 5 28", "2 7 8 4", "85 50 17 89", "17 28 19 5558", "5276 8562 1074 8453", "9133 7818 3682 82004", "81780 54799 231699 808", "53553 262850 271957 182759", "300000 300000 300000 300000", "1 1 300000 30...
UNKNOWN
PYTHON3
CODEFORCES
9
283652cba8bc6649f1610093f8a997ab
Shortest Path Problem?
You are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). You have to find the minimum length of path betwe...
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nfrom collections import defaultdict\r\n\r\nclass UnionFind():\r\n def __init__(self,n):\r\n self.n=n\r\n self.parents=[-1]*n\r\n\r\n def find(self,x):\r\n if self.parents[x]<0:\r\n return x\r\n else:\r\n self.parents[x]=sel...
{"inputs": ["3 3\n1 2 3\n1 3 2\n3 2 0", "2 2\n1 1 3\n1 2 3", "10 20\n8 5 64\n5 6 48\n4 5 91\n10 1 2\n3 4 51\n8 2 74\n6 1 98\n3 10 24\n2 10 35\n8 7 52\n10 5 72\n5 9 25\n2 9 65\n7 4 69\n5 7 26\n7 2 44\n6 8 61\n3 5 43\n10 7 33\n4 2 28", "10 20\n1 8 2\n2 9 94\n9 5 43\n7 2 83\n9 7 42\n5 10 11\n3 10 48\n8 6 31\n3 4 57\n9 3 7...
UNKNOWN
PYTHON3
CODEFORCES
1
283e1019f37f86a0f8edcc07d12acadb
Bus to Udayland
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris a...
[ "n = int(input())\r\na = []\r\nchecker = True\r\nfor i in range(n):\r\n a.append(input().split('|'))\r\n if a[i][0] == 'OO' and checker:\r\n checker = False\r\n a[i][0] = \"++\"\r\n elif a[i][1] == \"OO\" and checker:\r\n checker = False\r\n a[i][1] = \"++\"\r\nif checker:\r\n ...
{"inputs": ["6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "1\nXO|OX", "1\nOO|OO", "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO", "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX", "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO...
UNKNOWN
PYTHON3
CODEFORCES
433
28411c5d29d114ba8323796db78ba7c8
Power Substring
You are given *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. For every *a**i* you need to find a positive integer *k**i* such that the decimal notation of 2*k**i* contains the decimal notation of *a**i* as a substring among its last *min*(100,<=*length*(2*k**i*)) digits. Here *length*(*m*) is the length of the deci...
[ "import sys\r\nimport math\r\nfrom decimal import *\r\n \r\nline = lambda: list(int(x) for x in input().split())\r\n \r\ndef pow(a, k, p):\r\n r = 1\r\n t = a\r\n while k > 0:\r\n if k % 2 == 1:\r\n r = r * t % p\r\n t = t * t % p\r\n k >>= 1\r\n return r\r\n \r\ntest = i...
{"inputs": ["2\n8\n2", "2\n3\n4857", "7\n1\n7\n9\n5\n6\n10\n4", "10\n384\n179\n982\n466\n646\n226\n759\n798\n291\n852", "10\n677\n958\n20\n169\n441\n752\n24\n809\n41\n96", "10\n31\n362\n396\n661\n314\n803\n366\n124\n748\n875", "50\n415546\n6493493\n5136540\n6965643\n8466744\n3329383\n9711334\n9543203\n4478668\n375580\n...
UNKNOWN
PYTHON3
CODEFORCES
2
2864da2c1b6bbbed5dd64a4f5a8f4888
Array Division
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ...
[ "n = int(input())\r\narr = list(map(int, input().split()))\r\ndef solve(n, a):\r\n s = sum(a)\r\n if n == 1 or s & 1:\r\n print('NO')\r\n return\r\n half = s // 2\r\n def judge(a):\r\n pre, st = 0, {0}\r\n for num in a:\r\n st.add(num)\r\n pre += num\r\n...
{"inputs": ["3\n1 3 2", "5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n72 32 17 46 82", "6\n26 10 70 11 69 57", "7\n4 7 10 7 5 5 1", "8\n9 5 5 10 4 9 5 8", "10\n9 6 8 5 5 2 8 9 2 2", "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8", "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13", "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 1...
UNKNOWN
PYTHON3
CODEFORCES
45
286a400f485c1c229063aea4feb0c7b6
Send the Fool Further! (easy)
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to d...
[ "n=int(input())\r\nal=[[] for j in range(n)]\r\nfor i in range(n-1):\r\n a,b,c=map(int,input().split())\r\n al[a].append([b,c])\r\n al[b].append([a,c])\r\n\r\nmc=0\r\nva=[0]*(n)\r\nca=[0]*(n)\r\ndef dfs(n,c):\r\n va[n]=1\r\n #print(c)\r\n ca[n]=ca[n]+c\r\n\r\n for e ...
{"inputs": ["4\n0 1 4\n0 2 2\n2 3 3", "3\n1 0 5987\n2 0 8891", "10\n1 0 518\n2 0 4071\n3 1 121\n4 2 3967\n5 3 9138\n6 2 9513\n7 3 3499\n8 2 2337\n9 4 7647", "11\n1 0 6646\n2 0 8816\n3 2 9375\n4 2 5950\n5 1 8702\n6 2 2657\n7 2 885\n8 7 2660\n9 2 5369\n10 6 3798", "10\n0 1 7171\n0 2 2280\n1 3 9126\n2 4 2598\n5 4 8320\n6 ...
UNKNOWN
PYTHON3
CODEFORCES
46
287397a481ede563607cff0a1ddf0ea0
Roadside Trees (Simplified Edition)
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol...
[ "n = int(input())\r\n\r\ntotal = 0\r\nh = int(input())\r\ntotal += h + 1\r\ncur = h\r\nfor i in range(n-1):\r\n hi = int(input())\r\n if h > hi:\r\n total += h-hi #d own\r\n total += 1 # jump\r\n total += 1 # eat\r\n else:\r\n total += 1 # jump\r\n diff = hi-h\r\n ...
{"inputs": ["2\n1\n2", "5\n2\n1\n2\n1\n1", "1\n1"], "outputs": ["5", "14", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
204
288b3bbc8ba7b9d6fe341a00d99b015b
Recursive Queries
Let us define two functions *f* and *g* on positive integer numbers. You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. The first line of the input contains an int...
[ "from sys import stdin, stdout\r\n\r\ndef main():\r\n R = stdin.readline\r\n #f = open('input.txt');R = f.readline\r\n W = stdout.write\r\n\r\n ans = []\r\n \r\n offline_k = {}\r\n for i in range(1, 10**6+1):\r\n if i > 9: \r\n n, product = i, 1\r\n while n:\r\n ...
{"inputs": ["4\n22 73 9\n45 64 6\n47 55 7\n2 62 4", "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4"], "outputs": ["1\n4\n0\n8", "3\n1\n1\n5"]}
UNKNOWN
PYTHON3
CODEFORCES
10
288c99b2fff6797baa38bd27fdb238e2
Fox And Travelling
Fox Ciel is going to travel to New Foxland during this summer. New Foxland has *n* attractions that are linked by *m* undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has *k* days to visit this city and each day she will visit exactly one attraction. There is one important ...
[ "from collections import deque\r\n\r\n\r\n# Find all the vertices inside a connected component.\r\ndef DFS(v):\r\n index = len(cc) - 1 # Obtain the index of this connected component.\r\n cc[index].append(v) # Add this vertex to the list of this connected component.\r\n visited[v] = True # Mark this vert...
{"inputs": ["3 2\n1 2\n2 3", "4 4\n1 2\n2 3\n3 4\n4 1", "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9", "13 0", "1 0", "2 0", "2 1\n1 2", "4 4\n1 2\n2 3\n3 1\n1 4", "10 9\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10", "5 10\n1 2\n2 3\n3 4\n4 5\n5 1\n1 3\n2 4\n3 5\n4 1\n5 2", "100 0", "100 2\n12 34\...
UNKNOWN
PYTHON3
CODEFORCES
2
28901a501e75b526313e1ccaf84d830d
Mammoth's Genome Decoding
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s...
[ "def solve(s):\r\n TYPES = ['A', 'C', 'G', 'T']\r\n\r\n letterToCount = {}\r\n for ch in s:\r\n if ch != '?':\r\n letterToCount[ch] = letterToCount.get(ch, 0) + 1\r\n\r\n if len(s) % 4 != 0 or any(count * 4 > len(s) for count in letterToCount.values()):\r\n return \"===\"\r\n\r\...
{"inputs": ["8\nAG?C??CT", "4\nAGCT", "6\n????G?", "4\nAA??", "4\n????", "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC?...
UNKNOWN
PYTHON3
CODEFORCES
163
289e0f64b860d6bf9e29d7d35a32f48a
none
The project of a data center of a Big Software Company consists of *n* computers connected by *m* cables. Simply speaking, each computer can be considered as a box with multiple cables going out of the box. Very Important Information is transmitted along each cable in one of the two directions. As the data center plan ...
[ "from collections import defaultdict\r\nimport random\r\nimport 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 ...
{"inputs": ["4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n1 3", "3 4\n1 2\n2 3\n1 1\n3 3", "1 1\n1 1", "1 2\n1 1\n1 1", "1 3\n1 1\n1 1\n1 1", "1 4\n1 1\n1 1\n1 1\n1 1", "2 1\n1 2", "2 2\n1 2\n1 2", "2 3\n1 2\n1 2\n1 2", "2 2\n1 1\n1 2", "2 3\n1 1\n1 2\n2 2", "3 4\n1 1\n2 2\n3 2\n2 1", "3 9\n1 2\n1 3\n3 1\n1 3\n1 3\n1 1\n1 1\n1 3\n3 2...
UNKNOWN
PYTHON3
CODEFORCES
1
28b963cddc578fef58c98986cc553cc1
New Year Contest
As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest. The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are *n* problems for the contest. The penalty time ...
[ "from bisect import bisect_right\r\nn = int(input())\r\nt = list(map(int, input().split()))\r\nt.sort()\r\nfor i in range(1, n):\r\n t[i] += t[i - 1]\r\ni = bisect_right(t, 350)\r\nj = bisect_right(t, 710)\r\nprint(j, sum(t[k] for k in range(i, j)) - 350 * (j - i))", "n = input()\r\na = sorted(map(int, input()...
{"inputs": ["3\n30 330 720", "1\n720", "5\n100 200 300 400 500", "7\n120 110 100 110 120 120 50", "3\n350 340 360", "8\n150 100 50 70 70 80 90 100", "100\n18 96 216 240 1 114 126 38 7 72 28 1 8 29 5 93 1 56 50 142 79 30 6 7 13 126 49 154 6 44 116 3 120 17 181 36 32 7 33 41 59 88 20 21 77 110 7 23 99 15 49 151 68 68 52 ...
UNKNOWN
PYTHON3
CODEFORCES
6
28c9a440c64ef30409a136d86be5bc53
Cycle in Graph
You've got a undirected graph *G*, consisting of *n* nodes. We will consider the nodes of the graph indexed by integers from 1 to *n*. We know that each node of graph *G* is connected by edges with at least *k* other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least *k*<=...
[ "f=200001;v=[0]*f;g=[[]for _ in[0]*f];s=[1];n,m,k=map(int,input().split())\r\nfor _ in range(m):a,b=map(int,input().split());g[b]+=a,;g[a]+=b,\r\nwhile 1:\r\n v[s[-1]]=1\r\n for i in g[s[-1]]:\r\n if v[i]<1:s+=i,;break\r\n else:\r\n t=set(g[s[-1]])\r\n for i in range(len(s)):\r\n ...
{"inputs": ["3 3 2\n1 2\n2 3\n3 1", "4 6 3\n4 3\n1 2\n1 3\n1 4\n2 3\n2 4", "9 9 2\n5 6\n6 7\n7 8\n8 9\n9 5\n1 2\n2 3\n3 4\n4 1", "5 10 4\n1 2\n2 3\n1 3\n1 5\n4 1\n2 5\n2 4\n5 3\n5 4\n3 4", "10 15 3\n9 4\n4 8\n4 2\n2 9\n9 6\n6 2\n6 5\n1 10\n1 7\n10 5\n10 7\n1 8\n8 3\n3 5\n3 7", "12 40 3\n6 11\n7 11\n9 2\n9 1\n9 3\n3 4\n...
UNKNOWN
PYTHON3
CODEFORCES
1
28d190993da0190a391548824cc06741
Two-gram
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters...
[ "n = int(input())\ns = input()\n\nans = 0\nFind = \"\"\n\nfor i in range(n - 1):\n c = 0\n for j in range(n - 1):\n if s[i] == s[j] and s[i + 1] == s[j + 1]:\n c += 1\n if ans < c:\n ans = max(ans, c)\n Find = s[i:i+2]\n\nprint(Find)\n\n \t\t\t\t\t \t\t \t \t\t\t \t \t ...
{"inputs": ["7\nABACABA", "5\nZZZAA", "26\nQWERTYUIOPASDFGHJKLZXCVBNM", "2\nQA", "2\nWW", "11\nGGRRAATTZZZ", "50\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA", "100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC", "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
UNKNOWN
PYTHON3
CODEFORCES
67
28d2c70f4674dc987c27d930ced3b8b5
none
Pupils decided to go to amusement park. Some of them were with parents. In total, *n* people came to the park and they all want to get to the most extreme attraction and roll on it exactly once. Tickets for group of *x* people are sold on the attraction, there should be at least one adult in each group (it is possible...
[ "# import sys\r\ni=lambda:map(int,input().split())\r\nn,c1,c2=i()\r\ns=input()\r\nco=0\r\nfor j in range(0 , n):\r\n\tif(s[j]=='1'):\r\n\t\tco=co+1\r\n# ans=sys.maxsize\r\nans = c1*1\r\nans += c2*(n-1)*(n-1)*1\r\nfor j in range(2,co+1):\r\n\ta=int(c1*j)\r\n\tb=int((n-j)/j)\r\n\tc=int((n-j)%j)\r\n\ta=int(a+(c2*(b*b)...
{"inputs": ["3 4 1\n011", "4 7 2\n1101", "1 2 2\n1", "2 3 10\n01", "5 10 3\n11100", "10 2 2\n1111101111", "20 3 13\n01111110011111010101", "50 13 44\n11101110100110111100010110001111001001110010111011", "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000"...
UNKNOWN
PYTHON3
CODEFORCES
6
28d8994423a75f615720682d6568e5bc
New Year and Original Order
Let *S*(*n*) denote the number that represents the digits of *n* in sorted order. For example, *S*(1)<==<=1,<=*S*(5)<==<=5,<=*S*(50394)<==<=3459,<=*S*(353535)<==<=333555. Given a number *X*, compute modulo 109<=+<=7. The first line of input will contain the integer *X* (1<=≤<=*X*<=≤<=10700). Print a single integer, t...
[ "# Problem G\n\nnum = input()\nnum_list = []\nfor i in range(len(num)):\n num_list.append(int(num[i]))\nmyMod = (10 ** 9) + 7\nlength = len(num_list)\nf = [0] * (length + 1)\nt = [1] * (length + 1)\nfor i in range(length):\n f[i+1] = (f[i] * 10 + 1) % myMod\n t[i+1] = (t[i] * 10) % myMod\nans = 0\nfor i in r...
{"inputs": ["21", "345342", "9438174368", "33340691714056185860211260984431382156326935244157", "60659389952427965488066632743799525603106037644498358605868947137979908494800892265261453803791510334840960342863677552781925982028425181448855359993703120262947850907075964314040305228976226486729250", "4464901405497108121...
UNKNOWN
PYTHON3
CODEFORCES
1
28ddc714cc47a07c865fe5ad1a7cafc8
Little Elephant and Retro Strings
The Little Elephant has found a ragged old black-and-white string *s* on the attic. The characters of string *s* are numbered from the left to the right from 1 to |*s*|, where |*s*| is the length of the string. Let's denote the *i*-th character of string *s* as *s**i*. As the string is black-and-white, each character ...
[ "Mod=1000000007\r\nn,k=map(int,input().split(' '))\r\ns=' '+input()\r\nf,fs,g,gs,w=[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005\r\nqx,qw,qb=[0]*1000005,[0]*1000005,[0]*1000005\r\nq=0\r\nf[0]=fs[0]=1\r\nfor i in range(1,n+1):\r\n\tlg=(i-k if i-k>=q else q)\r\n\tif s[i]!='B':\r\n\t\tf[i]=fs[i-1]-fs[lg-...
{"inputs": ["3 2\nXXX", "4 2\nXXXX", "10 2\nXXBXXWXXXX", "3 1\nXBX", "1 1\nX", "2 1\nXW", "2 1\nWX", "10 3\nXBXBXWXBXW", "10 1\nXXXWXBXBXX", "20 2\nXXXBXWBBBBWXWWWXWWXB", "20 1\nXBBBWBXXBWXWWWBWWXXW", "10 3\nBXBWBWWWWX", "10 3\nWWXBWXXWWW", "20 3\nBWWWWWXBWXXXXBBWBBWX", "20 4\nWWWWXWBXBBXWWXWXBWWW", "20 5\nXBBXXXXXXXBW...
UNKNOWN
PYTHON3
CODEFORCES
1
28ee68f16a520e48dfcd63f4a9b73c66
Airport
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
[ "n, m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\n\r\n\r\ndef g(f):\r\n\tA = l[:]; s = 0\r\n\tfor _ in range(n):\r\n\t\ti = A.index(f(A)); s += A[i]\r\n\r\n\t\tif A[i] > 1: A[i] -= 1;\r\n\t\telse:\r\n\t\t\tA.pop(i)\r\n\treturn s\r\nprint (g(max), g(min))", "n,m=map(int,input().split())\r\n...
{"inputs": ["4 3\n2 1 1", "4 3\n2 2 2", "10 5\n10 3 3 1 2", "10 1\n10", "10 1\n100", "10 2\n4 7", "40 10\n1 2 3 4 5 6 7 10 10 10", "1 1\n6", "1 2\n10 9", "2 1\n7", "2 2\n7 2", "3 2\n4 7", "3 3\n2 1 1", "3 3\n2 1 1", "10 10\n3 1 2 2 1 1 2 1 2 3", "10 2\n7 3", "10 1\n19", "100 3\n29 36 35", "100 5\n3 38 36 35 2", "510 13...
UNKNOWN
PYTHON3
CODEFORCES
351
28ff8cf17cbb44dad168383bfd558933
Little Elephant and Rozdil
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
[ "n=int(input())\r\nl=input().split(\" \")\r\nl=[int(x) for x in l]\r\nsquare_dict = {n: 1 for n in l}\r\ns={}\r\nminNum=min(l)\r\nfor i in l:\r\n # for j in range(len(l[i])):\r\n if i in s:\r\n key=i\r\n s[key]=s.setdefault(key, 0) + 1\r\n else:\r\n key=i\r\n s[key]=s.setdefault(key, 1)\r...
{"inputs": ["2\n7 4", "7\n7 4 47 100 4 9 12", "1\n47", "2\n1000000000 1000000000", "7\n7 6 5 4 3 2 1", "10\n1 1 1 1 1 1 1 1 1 1", "4\n1000000000 100000000 1000000 1000000", "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 ...
UNKNOWN
PYTHON3
CODEFORCES
536
290445341dfe78a9bbf77a0fbe373202
Cloning Toys
Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one origina...
[ "x,y=map(int,input().split())\r\nif y==0:\r\n\tprint('No')\r\nelif y==1:\r\n\tif x==0:\r\n\t\tprint('Yes')\r\n\telse:\r\n\t\tprint('No')\r\nelif x<y-1:\r\n\tprint(\"No\")\r\nelse:\r\n\tp=x-(y-1)\r\n\tif p%2==0:\r\n\t\tprint('Yes')\r\n\telse:\r\n\t\tprint('No')\r\n", "k = input().split()\r\nx = int(k[0])\r\ny = in...
{"inputs": ["6 3", "4 2", "1000 1001", "1000000000 999999999", "81452244 81452247", "188032448 86524683", "365289629 223844571", "247579518 361164458", "424836699 793451637", "602093880 930771525", "779351061 773124120", "661640950 836815080", "543930839 974134967", "16155311 406422145", "81601559 445618240", "96389144...
UNKNOWN
PYTHON3
CODEFORCES
70
2907018f6993427776ddcf7fb2788f22
Hit Ball
When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced ...
[ "# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\ndef main():\r\n a,b,m = map(int , input().split())\r\n v = [int(i) for i...
{"inputs": ["7 2 11\n3 -11 2", "7 2 11\n4 -3 3", "44 94 98\n-17 -64 9", "41 4 58\n81 -9 65", "98 11 74\n79 -66 76", "7 21 86\n1 -19 20", "4 27 2\n-52 -64 31", "8 89 62\n47 -18 53", "57 7 78\n-31 -63 98", "62 14 94\n-33 -20 8", "59 24 6\n65 -73 53", "28 7 59\n83 -44 80", "24 26 75\n80 -97 58", "33 32 87\n-22 -47 2", "30...
UNKNOWN
PYTHON3
CODEFORCES
9
293234b109a5f13075a7b508cf4f0a59
Neural Network country
Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point. There are exactly *L* layers, each having *N* cities. Let us loo...
[ "import sys\r\nfrom array import array\r\n\r\n\r\nclass Matrix:\r\n def __init__(self, r, c, mat=None, id=None):\r\n self.r, self.c = r, c\r\n\r\n if mat != None:\r\n self.mat = [[mat[i][j] for j in range(c)] for i in range(r)]\r\n else:\r\n self.mat = [[0 for i in rang...
{"inputs": ["2 3 13\n4 6\n2 1\n3 4", "2 4 5\n1 1\n1 1\n1 1", "1 1234 5\n1\n1\n1", "3 2 2\n0 1 0\n0 0 1\n1 1 0", "5 4 3\n2 1 0 1 2\n0 1 2 1 0\n1 2 1 0 2", "4 4 4\n0 1 3 2\n1 2 0 3\n2 3 1 0"], "outputs": ["2", "16", "1", "3", "209", "64"]}
UNKNOWN
PYTHON3
CODEFORCES
2
297437049d4e500bc445497b1d321b1e
Settlers' Training
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either i...
[ "from collections import Counter\r\nn,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\ndit = Counter(arr)\r\nans = 0\r\nwhile len(dit) != 1 or k not in dit:\r\n ans+=1\r\n new = {}\r\n for e in dit:\r\n if e != k:\r\n if e+1 in new:\r\n new[e+1] +=1\r...
{"inputs": ["4 4\n1 2 2 3", "4 3\n1 1 1 1", "3 3\n1 2 3", "1 1\n1", "1 5\n1", "1 5\n4", "2 6\n2 5", "6 10\n1 1 3 4 9 9", "7 7\n1 1 1 1 1 1 7", "10 10\n1 1 1 3 3 4 7 8 8 8", "10 13\n1 1 1 1 1 1 1 1 1 1", "10 13\n2 6 6 7 9 9 9 10 12 12", "17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8", "18 24\n3 3 3 4 5 7 8 8 9 9 9 9 10 10 11 ...
UNKNOWN
PYTHON3
CODEFORCES
69