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
11c1c0b65c6949532970769144a92a59
Idempotent functions
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*),...
[ "N =int(input())\r\ninp =input().split()\r\nF =[0 for i in range(N)]\r\nfor i in range(N): F[i] =int(inp[i])-1\r\n\r\nans_small =[0 for i in range(N+1)]\r\nfor i in range(N):\r\n\tx =i\r\n\ty =i\r\n\tfor j in range(N):\r\n\t\tx =F[x]\r\n\t\ty =F[F[y]]\r\n\t\tif x == y:\r\n\t\t\tans_small[j+1] +=1\r\n\r\nans =-1\r\n...
{"inputs": ["4\n1 2 2 4", "3\n2 3 3", "3\n2 3 1", "1\n1", "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "20\n11 14 2 10 17 5 9 6 18 3 17 7 4 15 17 1 4 14 10 11", "100\n46 7 63 48 75 82 85 90 65 23 36 96 96 29 76 67 26 2 72 76 18 30 48 98 100 61 55 74 18 28 36 89...
UNKNOWN
PYTHON3
CODEFORCES
12
11e1871581824dfb08ec542251c5ca25
Travel Cards
In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t...
[ "n, a, b, k, f = map(int, input().split())\r\n\r\nslov = dict()\r\ntemp = input().split()\r\nslov[frozenset(temp)] = a\r\n\r\nfor i in range(1, n):\r\n temp2 = input().split()\r\n try:\r\n if temp2[0] == temp[1]:\r\n slov[frozenset(temp2)] += b\r\n else:\r\n slov[frozenset(...
{"inputs": ["3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank", "4 2 1 300 1000\na A\nA aa\naa AA\nAA a", "2 2 1 0 1\naca BCBA\nBCBA aca", "2 2 1 2 1\nBDDB C\nC BDDB", "2 3 1 1 9\nbacAB aAdb\nbacAB aAdb", "2 3 1 4 6\nAaCdC CdD\naBACc CdD", "1 2 1 2 1\nC BA", "1 3 1 1 4\nbCCCC BC", "1 4 3 1 1\nC bC"...
UNKNOWN
PYTHON3
CODEFORCES
5
1227949a1bf9ddb09337a57819e135a2
Exams
Vasiliy has an exam period which will continue for *n* days. He has to pass exams on *m* subjects. Subjects are numbered from 1 to *m*. About every day we know exam for which one of *m* subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any da...
[ "n,m = map(int,input().split())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nsums = sum(B)+len(B)\nlast = [-1] * m\ncou = 0\nans = 0\nper = 0\nfor j in range(n):\n if A[j] == 0:\n cou +=1\n else:\n if last[A[j]-1] == -1:\n if j >= B[A[j]-1]: ...
{"inputs": ["7 2\n0 1 0 2 1 0 2\n2 1", "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "5 1\n1 1 1 1 1\n5", "100 10\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8 6 6 1 5 5 6 5 6 6 6 9 4 7 5 4 6 6 1 1 2 1 8 10 6 2 1 7 2 1 8 10 9 2 7 3 1 5 10 2 8 10 10 10 8 9 5 4 6 10 8 9 6 6\n2...
UNKNOWN
PYTHON3
CODEFORCES
7
1242b7a42964481d8e4bbc5e3d3435d6
Greenhouse Effect
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each p...
[ "n, m = map(int, input().split())\nt = [int(input().split()[0]) for i in range(n)]\np = [0] * (m + 1)\nfor i in t: p[i] = max(p[1:i+1])+1\nprint(n - max(p))\n", "'''n, m, k = [int(x) for x in input().split()]\n\ntrees = tuple([int(x) for x in input().split()])\n\ncosts = []\nfor x in range(n):\n costs.append([...
{"inputs": ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125", "1 1\n1 0", "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000", "15 5\n4 6.039627\n...
UNKNOWN
PYTHON3
CODEFORCES
28
1265110d8fb5c19020abe0903ee7b295
LLPS
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*...
[ "from itertools import combinations\r\ndef get_subsequences(input_str):\r\n for length in range(1, len(input_str)+1):\r\n for elems in combinations(input_str, length):\r\n yield ''.join(elems)\r\nprint(sorted([s for s in get_subsequences(input()) if s[::-1] == s])[-1])", "from sys import *\r\...
{"inputs": ["radar", "bowwowwow", "codeforces", "mississipp", "tourist", "romka", "helloworld", "zzzzzzzazz", "testcase", "hahahahaha", "abbbbbbbbb", "zaz", "aza", "dcbaedcba", "abcdeabcd", "edcbabcde", "aaaaaaaaab", "testzzzzzz", "zzzzzzwait", "rrrrrqponm", "zzyzyy", "aababb", "zanzibar", "hhgfedcbaa", "aabcdefghh", "...
UNKNOWN
PYTHON3
CODEFORCES
713
127271f32b49adfdbf73c1c5f1ee489a
Turn the Rectangles
There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the recta...
[ "import sys\r\n\r\nprev = sys.maxsize\r\nflag = True\r\n\r\nfor _ in range(int(input())):\r\n w, h = map(int, input().split())\r\n if prev >= max(w, h):\r\n prev = max(w, h)\r\n elif prev >= min(w, h):\r\n prev = min(w, h)\r\n else:\r\n flag = False\r\n break\r\n\r\nif flag:\...
{"inputs": ["3\n3 4\n4 6\n3 5", "2\n3 4\n5 5", "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1", "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685", "1...
UNKNOWN
PYTHON3
CODEFORCES
34
12785439f019574c6379b2557b4c2af2
Love Triangle
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation ...
[ "n = int(input())\r\nf = [int(i) for i in input().split()]\r\nD = {}\r\nfor i in range(1, n + 1):\r\n D[i] = f[i - 1]\r\nres = 'NO'\r\nfor ver in D.keys():\r\n chel = ver\r\n for _ in range(3):\r\n ver = D[ver]\r\n if ver == chel:\r\n res = 'YES'\r\nprint(res)", "n = int(input())\narrf =...
{"inputs": ["5\n2 4 5 1 3", "5\n5 5 5 5 1", "3\n3 1 2", "10\n4 10 9 5 3 1 5 10 6 4", "10\n5 5 4 9 10 9 9 5 3 1", "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 ...
UNKNOWN
PYTHON3
CODEFORCES
490
1290054e6b5f04220016c64ece88f5db
Boy or Girl
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
[ "d=dict()\r\nn=input()\r\nfor ch in n:\r\n if(ch in d):\r\n d[ch]=d[ch]+1 \r\n else:\r\n d[ch]=0\r\ncount=len(d)\r\nif(count%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\na=[]\r\nfor i in s:\r\n if i not in a:\r\n a.append(i)\r\nif len...
{"inputs": ["wjmzbmr", "xiaodao", "sevenkplus", "pezu", "wnemlgppy", "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxc...
UNKNOWN
PYTHON3
CODEFORCES
595
12ac6ee7b374eaba6ddb61a68ebddee3
Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
[ "t = input()\r\ns, d = set(), set()\r\np = {(len(t), 2)}\r\n\r\nwhile p:\r\n m, x = p.pop()\r\n r = m + x\r\n\r\n for y in [x, 5 - x]:\r\n l = m - y\r\n q = (l, y)\r\n\r\n if q in d or l < 5 or t[l:m] == t[m:r]: continue\r\n s.add(t[l:m])\r\n\r\n d.add(q)\r\n p.add...
{"inputs": ["abacabaca", "abaca", "gzqgchv", "iosdwvzerqfi", "oawtxikrpvfuzugjweki", "abcdexyzzzz", "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec", "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl", "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv", "caqmjjtwmqxytcsawfufvlofqcqdwnyvy...
UNKNOWN
PYTHON3
CODEFORCES
22
12be6f6b6f79389b9d1b141176a2b327
Unordered Subsequence
The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered. A subsequence is a sequence that can be...
[ "N = int(input())\r\nA = list(map(int,input().split()))\r\n\r\nB = [(A[0],1)]\r\nprev = A[0]\r\nfor i in range(N-1):\r\n if A[i+1]!=prev:\r\n B.append((A[i+1],i+2))\r\n prev = A[i+1]\r\n\r\nans = 0\r\nfor i in range(len(B)-2):\r\n if B[i][0]<B[i+1][0] and B[i+1][0]>B[i+2][0]:\r\n ans = (B[i][...
{"inputs": ["3\n3 1 2", "1\n-895376", "2\n166442 61629", "3\n-771740 -255752 -300809", "4\n-227347 -573134 -671045 11011", "5\n834472 -373089 441294 -633071 -957672", "2\n7 8"], "outputs": ["3\n1 2 3", "0", "0", "3\n1 2 3", "3\n2 3 4", "3\n1 2 3", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
20
12d93ca6906e39940b5ee321de7f9ae7
Postcards and photos
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not ...
[ "import sys\r\nimport math\r\n\r\ns=str(input())\r\nc,p,cona=0,0,0\r\nfor i in range(len(s)):\r\n if(s[i]=='C'):\r\n c+=1\r\n if(p!=0):\r\n cona+=p//5\r\n if(p%5!=0): cona+=1\r\n p=0\r\n else:\r\n p+=1\r\n if(c!=0):\r\n cona+=c//5\r\n ...
{"inputs": ["CPCPCPC", "CCCCCCPPPPPP", "CCCCCCPPCPPPPPPPPPP", "CCCCCCCCCC", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP", "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPP...
UNKNOWN
PYTHON3
CODEFORCES
133
13056962b3f1cb803ad09d79e4bde485
Primes on Interval
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\na,b,k = map(int, input().split())\r\nps = [1]*(b+1)\r\nps[0]=ps[1]=0\r\nfor i in range(2,b+1):\r\n if ps[i]==0:continue\r\n for j in range(i+i,b+1,i):\r\n ps[j] = 0\r\n\r\nA = []\r\nfor i in range(a,b+1):\r\n if ps[i]:\r\n A....
{"inputs": ["2 4 2", "6 13 1", "1 4 3", "5 8 2", "8 10 3", "1 5 2", "6 8 3", "21 29 2", "17 27 3", "1 1000000 10000", "690059 708971 10000", "12357 534133 2", "838069 936843 3", "339554 696485 4", "225912 522197 5", "404430 864261 6", "689973 807140 7", "177146 548389 8", "579857 857749 9", "35648 527231 10", "2 100000...
UNKNOWN
PYTHON3
CODEFORCES
27
1334299b4247da2d1bdae5974c6fcb0f
Red and Blue Balls
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls...
[ "input()\r\ncolor = input()\r\noperations = 0\r\nfor i in range(0, len(color)):\r\n if 'B' in color[i]:\r\n operations += pow(2, i)\r\nprint(operations)\r\n", "inp=int(input())\r\nballs=input()\r\ntms=1\r\nans=0\r\nfor i in range(inp):\r\n\tif balls[i]=='B':\r\n\t\tans+=tms\r\n\ttms*=2\r\nprint(ans)", ...
{"inputs": ["3\nRBR", "4\nRBBR", "5\nRBBRR", "5\nRBRBR", "10\nRRBRRBBRRR", "10\nBRBRRRRRRR", "10\nBRRRRRRRRR", "20\nBRBRRRRRRRRRRRRRRRRR", "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "20\nRRRBRBBBBBRRRRRRRRRR", "20\nRRBRBBBBBRRRRRRRRRRR", "1\nR", "1\nB", "2\nRR", "2\n...
UNKNOWN
PYTHON3
CODEFORCES
64
13448478d4e49c8e2d1caa3ff518b3c1
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec...
[ "a,b=map(int,input().split());k=[]\r\nfor i in range(1,a+1):\r\n\tc,*d=map(int,input().split())\r\n\tif min(d)<b:k+=[i]\r\nprint(len(k),\"\\n\",*k)\r\n\r\n\r\n\r\n", "t,v=map(int,input().split())\r\nans=[]\r\nfor i in range(1,t+1):\r\n a=list(map(int,input().split()))\r\n if(min(a[1:])<v):\r\n ans.append(i)\...
{"inputs": ["3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "2 100001\n1 895737\n1 541571", "1 1000000\n1 1000000", "1 1000000\n1 561774", "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 ...
UNKNOWN
PYTHON3
CODEFORCES
294
134adde1602a65ae3022bdcfbb7f3925
Life Without Zeros
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
[ "a = (input())\nb = (input())\n\nres = int(a)+int(b)\na = a.replace(\"0\",'')\nb = b.replace(\"0\",'')\nres = str(res)\nres = res.replace(\"0\",'')\nres = int(res)\n\na = int(a)\nb = int(b)\n\nif res == (a+b):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n\n\n", "num1=int(input())\r\nnum2=int(input())\r\nres...
{"inputs": ["101\n102", "105\n106", "544\n397", "822\n280", "101\n413", "309\n139", "693\n970", "981\n1", "352\n276", "164\n691", "110036\n43", "100\n1000", "1000000000\n1000000000", "999999999\n999999999", "6\n4", "123456\n876543", "1234567\n9876543", "1111111\n1119111", "10502405\n40403403", "1\n1", "5\n4", "1\n6", "...
UNKNOWN
PYTHON3
CODEFORCES
625
134e58b9e1ffbdb158576f17eed68543
Substring and Subsequence
One day Polycarpus got hold of two non-empty strings *s* and *t*, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "*x* *y*" are there, such that *x* is a substring of string *s*, *y* is a subsequence of string *t*, and the content of ...
[ "from sys import stdin\r\ns=[ord(i)-97 for i in stdin.readline().strip()]\r\ns1=[ord(i)-97 for i in stdin.readline().strip()]\r\nn=len(s)\r\nm=len(s1)\r\nans=0\r\nmod=10**9+7\r\ndp=[[0 for i in range(n)] for j in range(26)]\r\nfor i in range(m):\r\n arr=[0 for j in range(n)]\r\n for j in range(n):\r\n ...
{"inputs": ["aa\naa", "codeforces\nforceofcode", "coderscontest\ncodeforces", "a\nb", "ab\nbbbba", "abbbccbba\nabcabc", "zxzxzxzxzxzxzx\nd", "pfdempfohomnpgbeegikfmflnalbbajpnpgeacaicoehopgnabnklheepnlnflohjegcciflmfjhachnhekckfjgoffhkblncidn\nidlhklpclcghngeggpjdgefccihndpoikojdjnbkdfjgaanoolfmnifnmbpeeghpicehjdiipnlf...
UNKNOWN
PYTHON3
CODEFORCES
1
1354c407fb01914d81f781d3516fb837
Sleuth
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans...
[ "n=input()\r\nn=list(n)\r\nn=n[::-1]\r\nl=['A','E','I','O','U','Y','a','e','i','o','u','y']\r\ni=1\r\nwhile(n[i]==' '):\r\n i=i+1\r\n continue\r\n#print(n,i)\r\nif(n[i] not in l):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n\r\n", "n = input().lower()\r\nx = [97, 101, 105, 111, 117, 121]\r\ni = l...
{"inputs": ["Is it a melon?", "Is it an apple?", " Is it a banana ?", "Is it an apple and a banana simultaneouSLY?", "oHtSbDwzHb?", "sZecYdUvZHrXx?", "uMtXK?", "U?", "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?", "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlx...
UNKNOWN
PYTHON3
CODEFORCES
536
138d94919a947e94d844bc2c1441a473
Title
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first *k* Latin letters and not conta...
[ "def process(S, k):\r\n n = len(S)\r\n L = [x for x in S]\r\n needed = set([i for i in range(k)])\r\n question = []\r\n for i in range(n):\r\n if S[i] != '?' and S[n-1-i] != '?' and S[i] != S[n-1-i]:\r\n return 'IMPOSSIBLE'\r\n if i <= n-1-i and S[i] != '?':\r\n L[...
{"inputs": ["3\na?c", "2\na??a", "2\n?b?a", "3\n????", "2\n????", "1\n?", "2\n?", "6\nabcdeffcdfda", "1\n?a", "23\napfpbfgmiko?mno?qre??cv?wvjt?r?foqm??op?g?udcfa", "16\n?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?", "23\na??d??g?i????n????????wj?spqbfr?wp?ob?g??h??r?????orf?q?s??w?u?srqp?n?...
UNKNOWN
PYTHON3
CODEFORCES
10
138f4354a7cd017a0367d09d328aee4e
Another Sith Tournament
The rules of Sith Tournament are well known to everyone. *n* Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each...
[ "n = int(input())\r\ncnt = [0] * (1 << n)\r\np = [[0] * n for _ in range(n)]\r\nf = [[0] * (1 << n) for _ in range(n)]\r\nfor i in range(n):\r\n p[i] = list(map(float, input().split()))\r\nfor i in range(1, 1 << n):\r\n cnt[i] = cnt[i & (i - 1)] + 1\r\nf[0][1] = 1\r\nfor i in range(1, 1 << n):\r\n if cnt[i...
{"inputs": ["3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0", "1\n0.0", "2\n0.00 0.75\n0.25 0.00", "4\n0.0 0.6 0.5 0.4\n0.4 0.0 0.3 0.8\n0.5 0.7 0.0 0.5\n0.6 0.2 0.5 0.0", "4\n0.0 0.3 0.5 0.6\n0.7 0.0 0.1 0.4\n0.5 0.9 0.0 0.6\n0.4 0.6 0.4 0.0", "2\n0.0 0.0\n1.0 0.0", "2\n0.0 1.0\n0.0 0.0", "5\n0.0 0.3 0.4 0.5 0.6\n0.7 0.0 0....
UNKNOWN
PYTHON3
CODEFORCES
5
13b28296e941bf4b38a92e234423bc69
Resort
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each ...
[ "\ndef solve():\n\tn = int(input())\n\tarr = list(map(int,input().split()))\n\tparent = list(map(int,input().split()))\n\tdegree = [0]*n\n\tfor i in range(n):\n\t\tparent[i] -=1\n\t\tif parent[i]!=-1:\n\t\t\tdegree[parent[i]]+=1\n\tans = []\n\tvisited = [False]*n\n\tfor i in range(n):\n\t\tif arr[i]==1:\n\t\t\ts = ...
{"inputs": ["5\n0 0 0 0 1\n0 1 2 3 4", "5\n0 0 1 0 1\n0 1 2 2 4", "4\n1 0 0 0\n2 3 4 2", "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2", "50\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\n28 4 33 22 4 35 36 31 42 25 50 33 25 36 18 23 23 28 43 3 18 31 1 2 15 22 40 4...
UNKNOWN
PYTHON3
CODEFORCES
15
13b7ef974745d76a78439919a6ed01eb
Mike and gcd problem
Mike has a sequence *A*<==<=[*a*1,<=*a*2,<=...,<=*a**n*] of length *n*. He considers the sequence *B*<==<=[*b*1,<=*b*2,<=...,<=*b**n*] beautiful if the *gcd* of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index *i* (1<=≤<=*i*<...
[ "from math import gcd\nn = int(input())\na = list(map(int, input().split()))\nj, s, d = 0, 0, 0\nwhile j < n:\n if a[j] % 2:\n if j + 1 < n and a[j + 1] % 2:\n s += 1\n j += 2\n else:\n d += 1\n j += 1\n else:\n j += 1\ng = 0\nfor x in a:\n g...
{"inputs": ["2\n1 1", "3\n6 2 4", "2\n1 3", "9\n57 30 28 81 88 32 3 42 25", "2\n8 77", "4\n92 46 3 21", "2\n78 26", "2\n3 6", "2\n3 9", "2\n3 3", "3\n3 6 3", "3\n3 9 15", "3\n3 6 9", "3\n3 3 3", "3\n3 9 18", "5\n1 2 1 2 1", "2\n9 6", "4\n3 6 9 12", "3\n3 9 27", "3\n3 9 12", "5\n6 6 9 15 21", "2\n5 15", "4\n2 3 9 13", "...
UNKNOWN
PYTHON3
CODEFORCES
5
13bdb1f2506b952ef6004ba0c77808ec
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
[ "entrada = int(input())\ncartas = input()\nlista_cartas = cartas.split(\" \")\noperacoes = 0\nif '1' not in lista_cartas:\n print(0)\nelse:\n index = -1\n for i in range(len(lista_cartas)):\n\n if lista_cartas[i] == '1':\n if(index < 0 or index + 1 == i):\n operacoes +=1\n else:\n ...
{"inputs": ["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0", "9\n1 0 1 0 1 0 1 0 1", "5\n1 1 1 1 1", "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "27\n0 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 0", "10\n1 0 0 0 0 1 0 0 0 1", "10\n1 0 0 1 0 0 1 1 0 1", "27\n0 0 0 0 0 0 0 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
209
13cbed0d2f029102bb46ecec65fe6d8d
Switches and Lamps
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*...
[ "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon May 21 22:31:07 2018\n\n@author: thomas\n\"\"\"\nintegers=input()\n[n,m]=[int(x) for x in integers.split()]\na=[]\nfor i in range(n):\n row_i=input()\n a_i=[]\n for j in range(m):\n a_i.append(int(row_i[j]))\n a.append(a_i)\...
{"inputs": ["4 5\n10101\n01000\n00111\n10000", "4 5\n10100\n01000\n00110\n00101", "1 5\n11111", "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "1 1\n1", "3 4\n1010\n0100\n1101", "2 5\n10101\n11111", "5 5\n10000\n11000\n11100\n11110\n11111", "2 5\n10000\n11111", "4 5\n01000\n10100\n00010\n10101", "2 2\n10\n11", "2 5\n00100\n1111...
UNKNOWN
PYTHON3
CODEFORCES
99
13ced2a3d8b5a62401f7b011c2f5576b
Simba on the Circle
You are given a circular array with *n* elements. The elements are numbered from some element with values from 1 to *n* in clockwise order. The *i*-th cell contains the value *a**i*. The robot Simba is in cell *s*. Each moment of time the robot is in some of the *n* cells (at the begin he is in *s*). In one turn the r...
[ "import os\r\nfrom re import M\r\nimport sys \r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno() \r\n self.buffer = BytesIO() \r\n self.writable = \"x\" in file.mode or ...
{"inputs": ["9 1\n0 1 2 2 2 1 0 1 1", "8 1\n0 1 0 1 0 1 0 1", "8 1\n1 2 3 4 5 6 7 8", "8 1\n0 0 0 0 0 0 0 0", "8 1\n0 1 2 2 1 0 1 1", "1 1\n4", "10 1\n-1 0 1 0 -1 1 0 0 1 -1", "20 7\n0 6 0 0 0 -7 -8 9 -7 4 7 2 -4 4 -5 2 6 8 -2 -7", "30 13\n68 50 99 23 84 23 24 -42 82 36 -10 -51 -96 96 19 -4 4 -41 74 92 13 58 26 79 -11 ...
UNKNOWN
PYTHON3
CODEFORCES
1
13d695394072750e82992d500f1bcc2c
Garden
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
[ "def f():\r\n num,k=map(int,input().split())\r\n n=map(int, input().split())\r\n maxi=0\r\n ans=0\r\n for i in n:\r\n if(k%i==0 and i>maxi):\r\n maxi=i \r\n ans=int(k/i)\r\n \r\n print(ans)\r\nf()", "# LUOGU_RID: 101738100\nn, k, *a = map(int, open(0).read...
{"inputs": ["3 6\n2 3 5", "6 7\n1 2 3 4 5 6", "5 97\n1 10 50 97 2", "5 97\n1 10 50 100 2", "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 ...
UNKNOWN
PYTHON3
CODEFORCES
379
1406f44b358d0fb8fc59355a2bc1ea3e
Binary Table
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa. What is the minimum number of cells with value 1 you can get after applying some number ...
[ "from functools import reduce\r\n\r\nn, m = map(int, input().split())\r\na = [input() for _ in range(n)]\r\na = list(map(lambda x: reduce(lambda x, y: x * 2 + int(y), x, 0), zip(*a)))\r\n \r\nS = 1 << n\r\nf, g = [0] * S, [0] * S\r\nfor x in a:\r\n g[x] += 1\r\nfor mask in range(S):\r\n k = bin(mask).count('1')\...
{"inputs": ["3 4\n0110\n1010\n0111", "1 1\n0", "1 1\n1", "2 1\n0\n1", "1 2\n10", "2 2\n01\n10", "2 2\n11\n10", "2 2\n00\n00", "2 2\n00\n11", "3 3\n100\n010\n001", "3 9\n010100100\n101011011\n101011101", "8 3\n000\n001\n010\n100\n110\n011\n101\n111", "1 10\n0110010001", "9 1\n0\n1\n1\n0\n1\n0\n1\n0\n1", "4 5\n01010\n101...
UNKNOWN
PYTHON3
CODEFORCES
1
141fac17f61c95c45f5139058556a5cd
Four Segments
You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* holds 0<=≤<=*l*<=≤<=*r*<=≤<=*n*. Indices in array are numbered from 0. For example, if *a*<==<=[<...
[ "n = int(input())\nnums = [int(x) for x in input().split()]\n\nbest = [None for x in range(len(nums))]\nway = [None for x in range(len(nums))]\n\n\ndef find_best_way():\n global best, n, nums, way\n\n for j in range(n - 1, -1, -1):\n best[j] = dict()\n way[j] = dict()\n\n previous = {'s1'...
{"inputs": ["3\n-1 2 3", "4\n0 0 -1 0", "1\n10000", "1\n-1", "1\n0", "10\n0 0 0 0 0 0 0 0 0 0", "100\n-1 -1 0 1 -1 0 0 -1 -1 1 1 0 1 0 -1 1 0 0 -1 0 0 0 1 0 0 1 1 1 1 0 -1 -1 0 0 0 1 1 -1 0 0 1 1 1 0 -1 -1 0 -1 0 -1 -1 0 1 0 1 -1 1 -1 -1 -1 0 0 -1 0 -1 -1 0 -1 1 1 -1 1 0 1 -1 -1 1 1 -1 1 0 -1 1 -1 1 1 1 1 1 -1 0 1 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
15
14224c4b4244d0fe292621f678e1422f
none
From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times: - Remove any two elements *s...
[ "n = int(input())\ndef locos(n):\n cos = 0\n i = 1\n while cos + i <= n:\n cos += i\n i += 1\n return i , cos\n\n\nrtn = ''\nfor i in \"abcdefghijklmnopqrstuvwxyz\":\n #print(locos(n))\n num , cos = locos(n)\n #print(num)\n rtn += i * num\n n -= cos\n if(n == 0): break\np...
{"inputs": ["12", "3", "0", "2", "5", "10", "233", "418", "100000", "1", "4", "6", "7", "8", "9", "11", "1317", "1926", "14514", "25252", "99681", "99998", "82944", "831", "39393"], "outputs": ["abababab", "codeforces", "o", "aabb", "aaabbcc", "aaaaa", "ooououououououououooohhhhhhaaiiiiiibbjjjjjjcckkkkkkddlllllleemmmmm...
UNKNOWN
PYTHON3
CODEFORCES
35
142ca9504dab57200c552d5380ecc69f
Almost Acyclic Graph
You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you make this graph [acyclic](https://en.wikipedia.org/wiki/Directed_acy...
[ "\r\n\r\ndef my_solve(n, m, graph, mask):\r\n\tif do_dfs_bool(n,graph,mask.copy()):\r\n\t\tc = get_cyclic(n, graph, mask)\r\n\t\tfor u,v in c:\r\n\t\t\tgraph[u].remove(v)\r\n\t\t\tif not do_dfs_bool(n,graph,mask.copy()):\r\n\t\t\t\treturn 'YES'\r\n\t\t\tgraph[u].append(v)\r\n\t\treturn \"NO\"\r\n\treturn \"YES\"\r\...
{"inputs": ["3 4\n1 2\n2 3\n3 2\n3 1", "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5", "2 2\n1 2\n2 1", "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2", "500 50\n396 340\n47 341\n422 140\n492 209\n263 248\n461 300\n124 495\n33 6\n93 384\n389 182\n130 297\n217 329\n131 136\n355 94\n388 275\n115 368\n279 462\n126 285\n185 287\n223 221\n20...
UNKNOWN
PYTHON3
CODEFORCES
6
143975608b5342cde4acac925204f195
Little Elephant and Interval
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 4...
[ "def f(x):\n if x < 10:\n return x\n if str(x)[0] > str(x)[-1]:\n return x // 10 + 8\n else:\n return x // 10 + 9\nl, r = map(int, input().split())\nprint(f(r) - f(l - 1))", "def calc(r):\r\n if r<10:\r\n return r\r\n ret,l=r//10+9,len(str(r))\r\n if r%10 < r//10**(l-...
{"inputs": ["2 47", "47 1024", "1 1000", "1 10000", "47 8545", "1000 1000", "47547 4587554587754542", "1 1000000", "47 74", "10001 10000002", "10000 100000", "458754 4588754", "111 111", "110 147", "1 1000000000", "12 10000000000", "1000000000 1000000000", "1 1000000000000000000", "11 111111111111111100", "100000000000...
UNKNOWN
PYTHON3
CODEFORCES
52
143bfa7b8d53e4b19209a18df9563490
"Or" Game
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. The ...
[ "n, k, x = map(int, input().split())\r\nx = x**k\r\nleft_or = [None]*(n)\r\nright_or = [None]*(n)\r\na = list(map(int, input().split()))\r\ncurrent_or = 0\r\nfor i in range(n):\r\n current_or |= a[i]\r\n left_or[i] = current_or\r\ncurrent_or = 0\r\nfor i in range(n-1, -1, -1):\r\n current_or |= a[i]\r\n ...
{"inputs": ["3 1 2\n1 1 1", "4 2 3\n1 2 4 8", "2 1 2\n12 9", "2 1 2\n12 7", "3 1 3\n3 2 0", "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "1 2 3\n612635770", "3 2 5\n0 2 3", "2 1 8\n18 17", "5 10 8\n0 0 0 0 0", "1 1 2\n1", "1 1 2\n0", "3 2 6\n724148075 828984987 810015532", "3 1 2\n17 18 4", "3 1 2\...
UNKNOWN
PYTHON3
CODEFORCES
22
1450da53095949ecb270a669f433444e
Hopscotch
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks...
[ "import sys\r\nfrom typing import Callable\r\n\r\ndef get_quadrant_num(height, is_double, x) -> int:\r\n if height < 3:\r\n return height\r\n height -= 2\r\n # Calc number of row below\r\n height_row_below = height - 1\r\n r = 2 + 2 * (height_row_below // 2) + height_row_below // 2 + (2 if hei...
{"inputs": ["1 0 0", "3 1 1", "3 0 10", "3 0 7", "3 4 0", "9 3 2", "100 0 953748", "17 0 1000000", "17 15 99999", "55 -20 1000000", "1 154871 37516", "1 -1 0", "1 -1 1", "1 0 2", "1 0 552012", "1 1 293372", "1 -1 551084", "5 -744240 145890", "5 -4 2", "5 -5 7", "5 -3 14", "5 0 660386", "5 5 918098", "5 -5 659458", "10 ...
UNKNOWN
PYTHON3
CODEFORCES
2
1462cea6e0234917f31a0424b8da0329
none
Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all. Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the formula: It’s time to change the world and Levko is going to change his array for the bett...
[ "def f(x):\r\n for i in range(1, n + 1):\r\n t[i] = 1\r\n for j in range(1, i):\r\n if x * (i - j) >= abs(a[i] - a[j]):\r\n t[i] = max(t[i], t[j] + 1)\r\n ans = 0\r\n for i in range(1, n + 1):\r\n ans = max(t[i], ans)\r\n return ans >= n - k\r\nn, k = map(i...
{"inputs": ["5 2\n4 7 4 7 4", "3 1\n-100 0 100", "6 3\n1 2 3 7 8 9", "4 1\n-1000000000 -1000000000 1000000000 1000000000", "10 1\n-6 5 -7 -7 -7 -7 5 -9 4 7", "20 17\n-5 -9 11 -7 -17 -8 0 -14 -20 -15 7 -13 0 -3 -14 0 9 -10 6 -19", "5 1\n-1000000000 1000000000 -1000000000 1000000000 -1000000000", "16 13\n441427217 689669...
UNKNOWN
PYTHON3
CODEFORCES
1
14670758b684ab5678725d0901e35d73
Password
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the...
[ "def kmp():\n now = -1\n sub[0] = now\n\n for i in range(1, len(p)):\n while now != -1 and p[i] != p[now + 1]:\n now = sub[now]\n\n if p[i] == p[now + 1]:\n now += 1\n sub[i] = now\n else:\n sub[i] = -1\n\np = input()\nsub = [-1] * 1000001\nk...
{"inputs": ["fixprefixsuffix", "abcdabc", "qwertyqwertyqwerty", "papapapap", "aaaaaaaaaa", "ghbdtn", "a", "aa", "ab", "aaa", "aba", "aab", "abb", "abc", "aaabaabaaaaab", "aabaaabaaaaab", "aaabaaaabab", "abcabcabcabcabc", "aaaaabaaaa", "aaaabaaaaaaa", "ghghghgxghghghg", "kincenvizh", "amcksgurlgqzqizdauqminfzshiweejkevb...
UNKNOWN
PYTHON3
CODEFORCES
115
1470983329ca5e3a2c6705a82cd173d6
List Of Integers
Let's denote as *L*(*x*,<=*p*) an infinite sequence of integers *y* such that *gcd*(*p*,<=*y*)<==<=1 and *y*<=&gt;<=*x* (where *gcd* is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of *L*(*x*,<=*p*) are 1-indexed; for example, 9, 13 and 15 are the first, the second and th...
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nm=10**6+10\r\ndivs=[[1] for i in range(m)]\r\n\r\np=list(range(m))\r\np2=[1]*m\r\nmebius=[0]*m\r\nmebius[1]=1\r\nfor i in range(2,m):\r\n if p[i]==i:\r\n for j in range(i,m,i):\r\n p2[j]=i\r\n for j in range(i*i,m,i):\r\n p[j]=i\r...
{"inputs": ["3\n7 22 1\n7 22 2\n7 22 3", "5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46"], "outputs": ["9\n13\n15", "187\n87\n139\n128\n141"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1478c482a3296de529bb34c0e7e351e4
Ithea Plays With Chtholly
This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right. This game wil...
[ "import sys\n\nn, m, c=map(int, input().split())\na=[]\nfor i in range(n+1):\n a.append(0)\ncnt=0\nwhile cnt<n:\n i=0\n x=int(input())\n if x*2<=c:\n i=1\n while a[i] and a[i]<=x:\n i+=1\n else:\n i=n\n while a[i] and a[i]>=x:\n i-=1\n if a[i]==0:\...
{"inputs": ["2 4 4\n2\n1\n3\n4", "2 2 2\n1\n2", "3 6 3\n1\n2\n1\n3\n1\n3", "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4", "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11\n13\n5\n12\n11\n9\n3\n10\n9\n9\n13\n13\n5\n6\n11\n3\n15\n8\n8\n10\n13\n7\n6\n4\n14\n9\n10\n5\n13\n4\n1\n8\n6\n13\n1\n3\n4\n9\n12\n2\n7\n3\n3\n7\n2\n2\n9\n2\n4\...
UNKNOWN
PYTHON3
CODEFORCES
5
1488e9b4a9ebd590be12f7ea2251d7c8
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are *...
[ "#!/usr/bin/env pypy3\r\n\r\nimport math\r\n\r\ndef make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7):\r\n fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)\r\n fact[0] = 1\r\n for i in range(max_n):\r\n fact[i + 1] = fact[i] * (i + 1) % mod\r\n\r\n inv_fact[-1] = pow(fact[-1], mod - 2, mod)\r...
{"inputs": ["5\n3 6 9 12 15", "4\n3 7 5 2", "1\n1", "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082", "18\n341796022 486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 ...
UNKNOWN
PYTHON3
CODEFORCES
1
148e34843e6ea7ff1682255785649209
Dorm Water Supply
The German University in Cairo (GUC) dorm houses are numbered from 1 to *n*. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle). For each house, t...
[ "n, m = map(int, input().split())\r\nt, p = [], [[0, 0, 0] for i in range(n + 1)]\r\nfor i in range(m):\r\n a, b, d = map(int, input().split())\r\n p[b][1], p[a][0], p[a][2] = a, b, d\r\nfor a in range(1, n + 1):\r\n if p[a][1] == 0:\r\n b, c, d = a, p[a][0], p[a][2]\r\n if not c: continue\r\...
{"inputs": ["3 2\n1 2 10\n2 3 20", "3 3\n1 2 20\n2 3 10\n3 1 5", "4 2\n1 2 60\n3 4 50", "10 10\n10 3 70\n1 9 98\n9 10 67\n5 2 78\n8 6 71\n4 8 95\n7 1 10\n2 5 73\n6 7 94\n3 4 23", "7 5\n3 2 26\n4 6 84\n6 3 82\n5 1 57\n1 7 34", "9 6\n7 4 98\n5 9 72\n4 6 10\n2 8 22\n9 7 17\n3 1 66", "8 6\n1 3 84\n8 4 34\n7 2 10\n6 8 8\n3 ...
UNKNOWN
PYTHON3
CODEFORCES
15
149a65db8891987c69e12b3a698e18d4
Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has *n* cards in his collection. Each of these cards is characterised by its power *p**i*, magic number *c**i* and level *l**i*. Vova wants to build a deck with total power not less than *k*, but magic numbers m...
[ "from collections import deque\r\nclass mf_graph:\r\n n=1\r\n g=[[] for i in range(1)]\r\n pos=[]\r\n def __init__(self,N):\r\n self.n=N\r\n self.g=[[] for i in range(N)]\r\n self.pos=[]\r\n def add_edge(self,From,To,cap):\r\n assert 0<=From and From<self.n\r\n asse...
{"inputs": ["5 8\n5 5 1\n1 5 4\n4 6 3\n1 12 4\n3 12 1", "3 7\n4 4 1\n5 8 2\n5 3 3", "10 10\n3 3 6\n5 10 4\n4 7 9\n4 9 7\n1 9 4\n1 6 10\n4 10 1\n4 4 6\n2 7 2\n1 5 4", "10 20\n9 4 10\n2 8 9\n9 1 1\n8 10 10\n5 10 2\n1 2 10\n9 6 3\n2 10 5\n7 10 6\n6 3 1", "10 30\n23 83 9\n2 59 6\n10 6 4\n4 92 3\n19 13 6\n28 83 6\n25 58 4\n...
UNKNOWN
PYTHON3
CODEFORCES
3
14b287b107fd7520ff268970f124a5ce
Search for Pretty Integers
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the l...
[ "input();c=lambda: set(map(int,input().split()));k=c();k1=c();d=k.intersection(k1);z=min(k);z1=min(k1)\r\ntry:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))\r\nexcept:print(int(str(min(z,z1))+str(max(z,z1))))", "print((lambda a,x,y: sorted([i for i in x if i in y])[0] if len([i for i in x if i in...
{"inputs": ["2 3\n4 2\n5 7 6", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "1 1\n9\n1", "9 1\n5 4 2 3 6 1 7 9 8\n9", "5 3\n7 2 5 8 6\n3 1 9", "4 5\n5 2 6 4\n8 9 1 3 7", "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 ...
UNKNOWN
PYTHON3
CODEFORCES
355
14c08f41b8f7741fa46a3cff0a623a6c
Multiplication Table
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn...
[ "# Code by : Sam._.072\r\n\r\ndef dec_to_base(num,base): #Maximum base - 36\r\n base_num = \"\"\r\n while num>0:\r\n dig = int(num%base)\r\n if dig<10:\r\n base_num += str(dig)\r\n else:\r\n base_num += chr(ord('A')+dig-10) #Using uppercase letters\r\n num /...
{"inputs": ["10", "3", "2", "4", "5", "6", "7", "8", "9"], "outputs": ["1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7 14 21 28 35 42 49 56 63 \n8 16 24 32 40 48 56 64 72 \n9 18 27 36 45 54 63 72 81 ", "1 2 \n2 ...
UNKNOWN
PYTHON3
CODEFORCES
41
14c9740aff6f6fea9c424e0318ca8313
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
[ "n = int(input())\r\nu = []\r\ns = []\r\nok = True\r\nfor i in range(n):\r\n u.append(input())\r\n s.append(set(u[i]))\r\n if len(s[i]) != len(u[i]):\r\n print('NO')\r\n ok = False\r\n break\r\nif ok:\r\n i = 0\r\n ok = False\r\n while i < len(u):\r\n j = i + 1\r\n ...
{"inputs": ["4\nmail\nai\nlru\ncf", "3\nkek\npreceq\ncheburek", "1\nz", "2\nab\nba", "2\nac\nbc", "2\ncd\nce", "2\nca\ncb", "2\ndc\nec", "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\njt\ntm\nmq\nqf\nfk\nkn\nny\nyz\nzr\nrg\ngv\nvc\ncs\nsi\niu\nup\nph", "25\nsw\nwt\nc\nl\nyo\nag\nz\nof\np\nmz\nnm\nui\nzs\nj\nq\nk\ngd\nb\nen\n...
UNKNOWN
PYTHON3
CODEFORCES
8
14cb93780999f0be5745dc2133c5dcc5
Ability To Convert
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter *A* he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he ge...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nk = [0] + list(input().rstrip())\r\nl = len(k) - 1\r\nfor i in range(1, l + 1):\r\n k[i] -= 48\r\ninf = pow(10, 18) + 1\r\ndp = [inf] * (l + 1)\r\ndp[l] = 0\r\nb = 1\r\nfor _ in range(l + 5):\r\n dp0...
{"inputs": ["13\n12", "16\n11311", "20\n999", "17\n2016", "1000\n1001", "1000\n1000", "2\n110111100000101101101011001110100111011001000000000000000000", "500\n29460456244280453288", "1000000000\n17289468142098080", "123\n7719", "25\n2172214240", "2\n1110110101111000010001011110101001011001110000000010111010", "3\n12100...
UNKNOWN
PYTHON3
CODEFORCES
6
1504039ac7ea1dfc39679c660b5763cb
none
You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k*<=≤<=|*s*|) a subsequence of string *s*<==<=*s*1*s*2... *s*|*s*|. St...
[ "s = input()\ns = s[::-1]\nn = len(s)\n\n\n\nmaxi = s[0]\nfor i in range(1,n):\n \n \n if s[i]>=maxi[-1]:\n\n maxi += s[i]\n\n\nprint(maxi[::-1])\n\n", "w = input()\r\nres = ''\r\nwhile len(w) > 0:\r\n c = max(c for c in w)\r\n res += c * w.count(c)\r\n wr = w[::-1] \r\n wr = wr[:wr.in...
{"inputs": ["ababba", "abbcbccacbbcbaaba", "thankstosamarasauteddybearsforthiscontest", "cantouristsolveitlessthaninoneminute", "arepretestsstrongforthisproblem", "whyareyoulookingfortestsdoyouhavewa", "aa", "zz", "a", "z", "b", "y", "zaz", "aza", "dcbaedcba", "abcdeabcd", "abcdedcba", "zyxzxzwyxywxxwabcdabdacdbcacdbca...
UNKNOWN
PYTHON3
CODEFORCES
51
1505530295dbd2d4bc8823b29ba39a2d
Little Elephant and Function
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works...
[ "# Bismillahir Rahmanir Rahim\r\n# Abu Hurayra - Handle: HurayraIIT\r\nimport sys\r\nimport math\r\ndef mp(): return map(int, sys.stdin.readline().split())\r\ndef rs(): return sys.stdin.readline().rstrip()\r\ndef ri(): return int(sys.stdin.readline())\r\ndef ria(): return list(map(int, sys.stdin.readline().split())...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "1000", "999", "998", "997", "900", "101", "3", "67", "779", "195", "907", "971", "683", "99", "811", "875", "291", "3", "419", "779", "195", "907", "21", "22", "23", "24", "25"], "outputs": ["1 ", "2 1 ", "3 1 2 ", "4 1 2 3 ", "5 1 2 3 4 ", "6 1 2 3 4 5 ", "7 1 2 3 4 5 6 ...
UNKNOWN
PYTHON3
CODEFORCES
304
150b646344f8eb91459c57d85944dfc9
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
[ "n, m = map(int, input().split())\n \ncounted_words = set() \nrepeated = 0\nwords1 = 0\nwords2 = 0\n \nfor _ in range(n):\n word = input().strip()\n words1 += 1\n\n counted_words.add(word)\n \nfor _ in range(m):\n word = input().strip()\n words2 += 1\n\n if word in counted_words:\n repeated += 1\n \nif rep...
{"inputs": ["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb", "2 2\na\nb\nb\nc", "2 1\nc\na\na", "3 3\nab\nbc\ncd\ncd\ndf\nfg", "3 3\nc\na\nb\na\nd\ng", "1 1\naa\naa", "2 1\na\nb\na", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny", "3 2\na\nb\nc\nd\ne"], "outputs"...
UNKNOWN
PYTHON3
CODEFORCES
131
151f68a26da83524d8b82f40c7e8092c
Group Photo 2 (online mirror version)
Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be descr...
[ "n = int(input())\r\nw, h = [0]*n, [0]*n\r\nfor i in range(n):\r\n w[i], h[i] = map(int, input().split())\r\n\r\n\r\ndef dientich(Hmax):\r\n k = n//2\r\n a = []\r\n for i in range(n):\r\n if h[i] > Hmax:\r\n if k <= 0 or w[i] > Hmax:\r\n return 10**9\r\n else:...
{"inputs": ["3\n10 1\n20 2\n30 3", "3\n3 1\n2 2\n4 3", "1\n5 10", "1\n1 1", "1\n1000 1000", "1\n1 1000", "2\n1 1000\n1000 1", "2\n1 1\n1000 1000", "1\n1000 1", "5\n407 830\n12 199\n768 215\n668 28\n628 310", "3\n379 820\n923 407\n916 853", "3\n99 768\n477 885\n169 118", "3\n227 612\n223 259\n423 895", "3\n651 161\n480 ...
UNKNOWN
PYTHON3
CODEFORCES
2
1542f4a09d6ddea98267a3b58425bbd5
Robot Rapping Results Report
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o...
[ "def g(k):\r\n p = [[] for i in range(n)]\r\n d = [0] * n\r\n for u, v in t[:k]:\r\n p[u].append(v)\r\n d[v] += 1\r\n if d.count(0) > 2: return 0\r\n x = d.index(0, 1)\r\n while x:\r\n q, x = p[x], 0\r\n for y in q:\r\n d[y] -= 1\r\n if d[y] == 0:\...
{"inputs": ["4 5\n2 1\n1 3\n2 3\n4 2\n4 3", "3 2\n1 2\n3 2", "2 1\n1 2", "2 1\n2 1", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "3 3\n2 1\n3 1\n3 2", "4 6\n1 4\n4 2\n2 3\n1 2\n1 3\n4 3", "3 3\n3 1\n3 2\n1 2", "5 10\n2 1\n1 4\n2 5\n2 3\n5 4\n3 4\n3 1\n3 5\n2 4\n1 5", "3 3\n1 2\n3 2\n1 3", "3 3\n2 3\n1 3\n...
UNKNOWN
PYTHON3
CODEFORCES
6
1559308881797ee2f5f8be601e158dd4
Polycarp's phone book
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for w...
[ "\r\n\r\nfrom sys import stdin\r\ninput=stdin.readline\r\nimport heapq\r\nimport string\r\nrd=lambda: map(lambda s: int(s), input().strip().split())\r\nri=lambda: int(input())\r\nrs=lambda :input().strip()\r\nfrom collections import defaultdict,deque\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\nf...
{"inputs": ["3\n123456789\n100000000\n100123456", "4\n123456789\n193456789\n134567819\n934567891", "1\n167038488", "5\n115830748\n403459907\n556271610\n430358099\n413961410", "5\n139127034\n452751056\n193432721\n894001929\n426470953", "5\n343216531\n914073407\n420246472\n855857272\n801664978", "5\n567323818\n353474649\...
UNKNOWN
PYTHON3
CODEFORCES
24
156d2508c063ef36fdc1332ed8ab8e1e
Iterated Linear Function
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*...
[ "import sys,math\r\ndef power(x, y, p): \r\n res = 1;\r\n x = x % p; \r\n while (y > 0): \r\n if (y & 1): \r\n res = (res * x) % p; \r\n y = y >> 1; \r\n x = (x * x) % p; \r\n return res; \r\ndef modInverse(b,m): \r\n\tg = math.gcd(b, m) \r\n\tif (g != 1): \r\n\t\tre...
{"inputs": ["3 4 1 1", "3 4 2 1", "3 4 3 1", "1 1 1 1", "3 10 723 6", "14 81 51 82", "826504481 101791432 76 486624528", "475965351 844435993 96338 972382431", "528774798 650132512 6406119 36569714", "632656975 851906850 1 310973933", "1 1 352875518515340737 1", "978837295 606974665 846646545585165081 745145208", "2776...
UNKNOWN
PYTHON3
CODEFORCES
35
157a3165ac77cae8dc1878f04883493a
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have *n* questions, *m* of them are auction q...
[ "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nmm = list(map(int, input().split()))\r\ns = 0\r\na = []\r\nfor i in range(0, n):\r\n if (i+1) not in mm:\r\n s+=l[i]\r\nfor i in range(0, m):\r\n v = l[mm[i]-1]\r\n a.append(v)\r\na.sort(reverse = True)\r\nfor i in a:\r\n ...
{"inputs": ["4 1\n1 3 7 5\n3", "3 2\n10 3 8\n2 3", "2 2\n100 200\n1 2", "1 1\n1\n1", "2 2\n1 5\n1 2", "5 3\n5 8 7 1 9\n2 5 3", "5 5\n9 1 6 2 1\n3 1 4 5 2", "25 5\n66 41 91 33 86 67 38 79 49 7 77 54 29 19 22 48 63 37 11 100 8 6 47 27 26\n12 14 1 23 18", "50 10\n19098 20847 65754 94580 54808 57092 23130 15638 43645 52323...
UNKNOWN
PYTHON3
CODEFORCES
28
158444ebd70a822da08f95e3843ab7e3
Wizards and Demonstration
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city...
[ "import math\r\nn,x,y=map(int,input().split())\r\nk=math.ceil(y*n/100)\r\nif k>x:\r\n print(k-x)\r\nelse:\r\n print(0)\r\n", "n,x,y = map(int,input().split())\r\nimport math\r\nif((x/n)*100>=y):\r\n print(0)\r\nelse:\r\n z = math.ceil((y*n)/100)\r\n print(z-x)", "import math\r\nn,w,p=list(map(i...
{"inputs": ["10 1 14", "20 10 50", "1000 352 146", "68 65 20", "78 28 27", "78 73 58", "70 38 66", "54 4 38", "3 1 69", "11 9 60", "71 49 65", "78 55 96", "2765 768 9020", "3478 1728 9727", "9678 6173 5658", "1138 570 6666", "7754 204 9038", "8403 7401 4769", "4909 2111 8860", "6571 6449 8965", "9178 2255 7996", "6151 ...
UNKNOWN
PYTHON3
CODEFORCES
305
158ed5933ad363941eb78811545a4c1f
A Vital Problem
Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes u...
[ "n = int(input());\r\na = [];\r\nfor i in range(n):\r\n b = input().split(':');\r\n a.append(int(b[0]) * 60 + int(b[1]));\r\na.sort();\r\nt = a[0];\r\nfor i in range(n):\r\n a[i] -= t;\r\na.append(1440);\r\nu = -1;\r\nfor i in range(n):\r\n u = max(u, a[i+1] - a[i] - 1);\r\nh = u // 60;\r\nm = u - h * 6...
{"inputs": ["1\n05:43", "4\n22:00\n03:21\n16:03\n09:59", "20\n23:59\n00:00\n00:01\n00:02\n00:03\n00:04\n00:05\n00:06\n00:07\n00:08\n00:09\n00:10\n00:11\n00:12\n00:13\n00:14\n00:15\n00:16\n00:17\n00:18", "21\n23:28\n23:29\n23:30\n23:31\n23:32\n23:33\n23:34\n23:35\n23:36\n23:37\n23:38\n23:39\n23:40\n23:41\n23:42\n23:43\n...
UNKNOWN
PYTHON3
CODEFORCES
43
1591a073be244b2dc292fed6a4ee16c2
Inna and Huge Candy Matrix
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as...
[ "h, w, x, y, z, p = map(int, input().split())\r\nx, y, z = x % 4, y % 2, z % 4\r\n\r\ndef rotation(a, b):\r\n global h, w\r\n res = (b, h - a + 1)\r\n w, h = h, w\r\n return res\r\n\r\ndef flip(a, b):\r\n return a, w - b + 1\r\n\r\nres = []\r\nfor i in range(p):\r\n a, b = map(int, input().split()...
{"inputs": ["3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "5 5 0 0 0 1\n1 4", "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n13 75\n9 9\n3 63\n8 49\n5 1\n1 67\n13 31\n9 35\n3 53\n13 73\n5 71\n1 32\n5 49\n1 41\n14 69", "63 67 18046757 61758841 85367218 68\n2...
UNKNOWN
PYTHON3
CODEFORCES
12
15dc09ce785b1080b799acedace9411c
Okabe and Banana Trees
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ...
[ "def get2(n):\n\tres = n*(n+1)*(2*n+1)//6 + n*(n+1)//2\n\tres //= 2;\n\treturn res\n\ndef get(x,y):\n\treturn get2(x+y) - get2(x-1) - get2(y-1)\n\nm,b = input().split()\nm = int(m)\nb = int(b)\n\nmv = 0\nfor i in range(b+1):\n\tj = m*b-m*i\n\tcur = get(j,i)\n\tif cur > mv:\n\t\tmv = cur\n\nprint(mv)", "m,b=map(in...
{"inputs": ["1 5", "2 3", "4 6", "6 3", "1 1", "10 1", "20 10", "1000 10000", "139 9252", "859 8096", "987 4237", "411 3081", "539 9221", "259 770", "387 5422", "515 1563", "939 407", "518 6518", "646 1171", "70 7311", "494 6155", "918 7704", "46 3844", "174 2688", "894 4637", "22 3481", "446 5030", "440 8704", "569 75...
UNKNOWN
PYTHON3
CODEFORCES
72
15e263e85246dfd3aa917ff242354b00
Alyona and Spreadsheet
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab...
[ "import sys \r\ninput = sys.stdin.readline\r\nn, m = map(int,input().split())\r\narr=[]\r\nfor i in range(n):\r\n arr.append(list(map(int,input().split())))\r\nmp = []\r\nfor i in range(n):\r\n mp.append(i+1)\r\nfor i in range(m):\r\n pre=-1\r\n st=0\r\n for j in range(n):\r\n if arr[j][i]<pre...
{"inputs": ["5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "1 1\n1\n1\n1 1", "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10",...
UNKNOWN
PYTHON3
CODEFORCES
20
15f8e73bc9b0d7eb1a626278b62f9905
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
[ "import sys\r\nfrom itertools import product\r\nfrom collections import defaultdict\r\nr=sys.stdin.readline\r\nN,M=map(int,r().split())\r\nwords=defaultdict(int)\r\ntb=['a','b','c','d','e']\r\nst=set()\r\ncnt=0\r\nres=\"\"\r\ndef dfs(u):\r\n global res,cnt\r\n if u==l:\r\n if res in st:\r\n ...
{"inputs": ["3 1\nabc\naec\nac\na?c", "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d", "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n...
UNKNOWN
PYTHON3
CODEFORCES
1
160baf248c6c33b69df49066de5ff338
Inna and Alarm Clock
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square. The mornin...
[ "n = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n xt, yt = list(map(int, input().split()))\r\n x.append(xt)\r\n y.append(yt)\r\nx = list(set(x))\r\ny = list(set(y))\r\n\r\nprint(min(len(x), len(y)))\r\n", "h=set()\r\nv=set()\r\nfor i in range(int(input())):\r\n\tk = input().split()\r\n\tv.a...
{"inputs": ["4\n0 0\n0 1\n0 2\n1 0", "4\n0 0\n0 1\n1 0\n1 1", "4\n1 1\n1 2\n2 3\n3 3", "1\n0 0", "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n4...
UNKNOWN
PYTHON3
CODEFORCES
165
162e217540a33d9eb197e241489b3c61
Alice, Bob and Chocolate
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
[ "n = int(input())\r\nt = list(map(int,input().split()))\r\n\r\nAlice = 0\r\nBob = 0\r\n\r\ncA = 0\r\ncB = 0\r\n\r\ni = 0\r\nj = n-1\r\n\r\nwhile i<j:\r\n temp = min(Bob,Alice)\r\n Alice -= temp\r\n if Alice==0:\r\n Alice += t[i]\r\n cA += 1\r\n i += 1\r\n Bob -= temp\r\n if Bob==...
{"inputs": ["5\n2 9 8 2 7", "1\n1", "2\n1 1", "3\n1 1 1", "4\n1 1 1 1", "1\n6", "2\n8 2", "3\n6 8 4", "4\n4 3 2 8", "5\n1 9 8 2 7", "6\n1 4 7 3 2 1", "11\n7 9 1 8 7 1 7 1 4 8 1", "12\n4 2 7 1 9 5 6 2 7 8 5 7", "13\n9 9 9 9 9 9 9 9 9 9 9 9 9"], "outputs": ["2 3", "1 0", "1 1", "2 1", "2 2", "1 0", "1 1", "1 2", "3 1", "...
UNKNOWN
PYTHON3
CODEFORCES
138
16344fb7e2bc83409f14ef3f666a983c
King's Problem?
Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom. King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordina...
[ "from math import hypot, inf\n\n# input\nn, k = map(int, input().split())\ncities = list(map(int, input().split()))\ny_y = int(input())\n\n# input\n# n, k = 4, 1\n# cities = [0, 5, -1, -5, 2]\n# y_y = 3\n\nk = k - 1\nk_x = cities[k]\ncit = [cities[-1], y_y]\ncities.remove(cities[-1])\nans = inf\n\n# Calculo de la d...
{"inputs": ["3 1\n0 1 2 1\n1", "3 1\n1 0 2 1\n1", "4 5\n0 5 -1 -5 2\n3", "4 1\n0 5 -1 -5 2\n3", "10 5\n-231 598 312 -837 -711 553 -439 351 83 -605 -738\n791", "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 2...
UNKNOWN
PYTHON3
CODEFORCES
3
1655768ab04bba468899388061617449
Cowboys
A very tense moment: *n* cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western. The picture changes each second! Every second the cowboys analyse the s...
[ "'''\r\n字符串中A/B分别代表顺/逆时针指向邻居,如果两个人互相面对,那么下一个状态中这俩人都转身,\r\n求给定长度不超过100的字符串的可能前一个状态的种数。\r\n\r\n对于顺时针的s[i:i+2],若为'BA',那么前一个状态可以是AB和BA\r\n若为AB……;\r\n若为BA(不变),那么前一个状态中s[i-1]不能为‘A'、s[i+2]不能为'B'。\r\n'''\r\nG,s=range,input();n=len(s);s+=s[0];D={'A':0,'B':1}\r\ndef dp(j):\r\n f=[[0]*2 for _ in G(n+1)];f[0][j]=1\r\n for i ...
{"inputs": ["BABBBABBA", "ABABB", "ABABAB", "ABA", "AABB", "ABABBABBAABAB", "AAABAABABA", "ABABABABABABABABABAB", "BABABABABAAAABABAAAABAB", "ABABABBABA", "BBB", "AAAA", "ABBAB", "BBBABB", "BABBBBB", "ABABBAAB", "ABBBABBAB", "BAAABBBBBA", "AAAAAAAAAAA", "BABBAAAABAAA", "ABABBBABBBAAA", "BBBBBABBBBBABB", "AAAAAAAABAAAAA...
UNKNOWN
PYTHON3
CODEFORCES
1
166c3a794830622ff41a4fd1297a07d0
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
[ "n=int(input())\r\nserver1x = 0\r\nserver2x = 0\r\nserver1y = 0\r\nserver2y = 0\r\nfor _ in range(n):\r\n t, x, y = list(map(int, input().split()))\r\n\r\n if t == 1:\r\n server1x += x\r\n server1y += y\r\n else:\r\n server2x += x\r\n server2y += y\r\nif server1x >= server1y:\r\...
{"inputs": ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0", "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "13\n...
UNKNOWN
PYTHON3
CODEFORCES
300
167db4a35cf6f51b76cf83f7e8c141cf
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
[ "n,m=map(int, input().split())\r\ntemp=\"\"\r\nfor i in range(n):\r\n temp=temp+input()\r\nif temp.count('C')>0 or temp.count('M')>0 or temp.count('Y')>0:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "n,m = map(int,input().split())\r\nbw = '#Black&White'\r\nfor i in range(n):\r\n l = li...
{"inputs": ["2 2\nC M\nY Y", "3 2\nW W\nW W\nB B", "1 1\nW", "2 3\nW W W\nB G Y", "1 1\nW", "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "1 6\nC M Y W G B", "1 3\nW G B", "1 1\nW", "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "2 3\nW W W\nB G C", "2 3\nW W W\nB G M", "3 3\nC B W\nB Y M...
UNKNOWN
PYTHON3
CODEFORCES
531
16830fb49b20765e78781cea4be2a97f
The Contest
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking ab...
[ "import sys \r\n#import re\r\n#sys.stdin=open('.in','r')\r\n#sys.stdout=open('.out','w')\r\n#import math \r\n#import random\r\n#import time\r\n#sys.setrecursionlimit(int(1e6))\r\ninput = sys.stdin.readline\r\n \r\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\r\ndef inp():\r\n return(int(input...
{"inputs": ["2\n3 4\n2\n1 4\n7 9", "1\n5\n1\n1 4", "1\n5\n1\n1 5", "5\n100000 100000 100000 100000 100000\n0", "5\n886 524 128 4068 298\n3\n416 3755\n4496 11945\n17198 18039", "10\n575 3526 1144 1161 889 1038 790 19 765 357\n2\n4475 10787\n16364 21678", "1\n4\n1\n5 9", "1\n200\n4\n1 10\n20 40\n50 55\n190 210", "4\n643 ...
UNKNOWN
PYTHON3
CODEFORCES
85
168f6f1983f3160ebd9573e0d6a26d69
Display Size
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels o...
[ "a = int(input())\r\nb = int(a**0.5)\r\nwhile a%b:\r\n b -= 1\r\nprint(b, a//b)", "from math import sqrt\nnum = int(input())\nfor factor in range(int(sqrt(num)), 0, -1):\n\tif num % factor == 0:\n\t\tprint(factor, num//factor)\n\t\tbreak\n", "n = int(input())\r\ni = 1\r\nans = 1\r\nwhile i*i<=n:\r\n if n%...
{"inputs": ["8", "64", "5", "999999", "716539", "1", "2", "3", "4", "6", "7", "9", "10", "11", "12", "15", "100", "101", "169", "179", "190", "1000", "10000", "10001", "100000", "100001", "1000000", "999983", "524288", "954493", "966289", "944663", "912673", "732641", "232897", "16807", "999958", "990151", "997002", "2...
UNKNOWN
PYTHON3
CODEFORCES
236
16a03da19a666d6d16782abb48417091
Division into Teams
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the ...
[ "n = int(input())\r\na = list(map(int,input().split()))\r\nb = list(range(1,n+1))\r\nz = sorted(list(zip(a,b)))\r\nx = [] \r\ny = [] \r\nsx = 0 \r\nsy = 0 \r\nfor i,j in z:\r\n if sx<=sy:\r\n x.append(j)\r\n sx+=i\r\n else:\r\n y.append(j)\r\n sy+=i\r\nprint(len(x))\r\nprint(*x)\r\...
{"inputs": ["3\n1 2 1", "5\n2 3 3 1 1", "10\n2 2 2 2 2 2 2 1 2 2", "10\n2 3 3 1 3 1 1 1 2 2", "10\n2 3 2 3 3 1 1 3 1 1", "11\n1 3 1 2 1 2 2 2 1 1 1", "11\n54 83 96 75 33 27 36 35 26 22 77", "11\n1 1 1 1 1 1 1 1 1 1 1", "2\n1 1", "2\n35 36", "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1", "27\n2 1 1 3 1 2 1 1 3...
UNKNOWN
PYTHON3
CODEFORCES
13
16ccd5806786645d788c5a6d9bc85b1e
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co...
[ "from sys import stdin\nfrom collections import deque,Counter,defaultdict\nimport sys\nimport math\nimport operator\nimport random\nfrom fractions import Fraction\nimport functools\nimport bisect\nimport itertools\nfrom heapq import *\nimport time\n\nn = int(input())\narr = list(map(int,input().split()))\nc = 0\nfo...
{"inputs": ["2\n1 2", "3\n3 2 1", "4\n4 3 2 1", "3\n1 3 2", "2\n2 1", "9\n7 7 8 8 10 10 10 10 1000000000", "10\n1 2 9 4 5 6 7 8 3 10", "4\n2 2 2 1", "10\n1 2 4 4 4 5 5 7 7 10", "10\n4 5 11 12 13 14 16 16 16 18", "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 4944...
UNKNOWN
PYTHON3
CODEFORCES
183
16e2a8ba7b90c835d233f81974a1987e
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
[ "cnt = list(map(int, input().split()))\r\ns = input().strip()\r\nn = len(s)\r\nsum_val = [0] * (n + 1)\r\nans = 0\r\n\r\npos = [[] for _ in range(26)]\r\nfor i in range(1, n + 1):\r\n sum_val[i] = cnt[ord(s[i - 1]) - ord('a')]\r\n sum_val[i] += sum_val[i - 1]\r\n pos[ord(s[i - 1]) - ord('a')].append(i)\r\n...
{"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd", "-3 4 -4 -1 3 5 -5 -3 3 2 1 4 5 -3 -1 4 2 -2 1 -1 1 5 -4 0 -5 4\nolspxykjqr", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 ...
UNKNOWN
PYTHON3
CODEFORCES
19
16ea217382917bb89accb42f3a9c6795
Flag
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
[ "i = input().split(\" \")\r\nn = int(i[0])\r\nm = int(i[1])\r\nflag = [input() for x in range(n)]\r\nprevious = \"\"\r\nresult = True\r\nfor row in flag:\r\n if not row == row[0]*m:\r\n result = False\r\n if row == previous:\r\n result = False\r\n previous = row\r\nif result:\r\n print(\"Y...
{"inputs": ["3 3\n000\n111\n222", "3 3\n000\n000\n111", "3 3\n000\n111\n002", "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n...
UNKNOWN
PYTHON3
CODEFORCES
284
16ecf492d63595584a0ea1707994c224
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t...
[ "n = int(input())\r\n\r\npos = []\r\nneg = []\r\nfor _ in range(n):\r\n xi, ai = map(int,input().split())\r\n if xi > 0:\r\n pos.append((xi, ai))\r\n else:\r\n neg.append((xi, ai))\r\n\r\nlim = min(len(pos), len(neg))\r\n\r\nans = 0\r\n\r\nif len(pos) > len(neg):\r\n for x, a in sorted(pos...
{"inputs": ["2\n-1 5\n1 5", "3\n-2 2\n1 4\n-1 3", "3\n1 9\n3 5\n7 10", "1\n1 1", "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "1\n-1 1", "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 675...
UNKNOWN
PYTHON3
CODEFORCES
152
172d355f207b1c6d888955b4a88727e9
Mahmoud and Longest Uncommon Subsequence
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ...
[ "s1 = input()\r\ns2 = input()\r\n\r\nif s1 == s2:\r\n print(-1)\r\nelif len(s1) > len(s2):\r\n print(len(s1))\r\nelif len(s2) > len(s1):\r\n print(len(s2))\r\nelse:\r\n print(len(s1))", "def solve():\n a = input()\n b = input()\n print(-1 if a == b else max(len(a), len(b)))\n \nt = 1 #int(...
{"inputs": ["abcd\ndefgh", "a\na", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
184
175a9fbb6934af1423c16e2e891e9830
Pashmak and Buses
Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d* days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has t...
[ "from collections import defaultdict, deque, Counter\nfrom functools import lru_cache, reduce \nfrom heapq import heappush, heappop, heapify\nfrom bisect import bisect_right, bisect_left\nfrom random import randint\nimport math\nimport operator\nimport sys\nfrom itertools import accumulate \n#sys.stdin = open(\"sle...
{"inputs": ["3 2 2", "3 2 1", "7 2 3", "9 2 3", "2 1 1000", "512 2 9", "1000 1000000000 511", "1000 1000 1", "1000 3 1000", "1 1000000000 512", "1000 2 1000", "1000 3 1000", "1000 31 1000", "1000 32 1000", "1000 999 1000", "1000 1000 1000", "1000 536870912 1000", "1000 536870911 1000", "1000 1000000000 1000", "1000 2 8...
UNKNOWN
PYTHON3
CODEFORCES
7
1781dd23263cc5f4456420d34bd9eaa4
Pashmak and Parmida's problem
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence *a* that consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Let's denote *f*(*l*,<=*r*,<...
[ "import heapq\r\nimport math\r\nimport os\r\nfrom collections import Counter, deque, defaultdict\r\nfrom sys import stdout\r\nimport time\r\nfrom math import factorial, log, gcd\r\nimport sys\r\nfrom decimal import Decimal\r\nimport threading\r\nfrom heapq import *\r\nimport random\r\n\r\n\r\ndef S():\r\n return...
{"inputs": ["7\n1 2 1 1 2 2 1", "3\n1 1 1", "5\n1 2 3 4 5", "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4", "1\n1", "2\n1 2", "2\n1 1", "4\n1 1 2 2", "5\n1 1 2 2 2"], "outputs": ["8", "1", "0", "114", "0", "0", "0", "1", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
14
17d85a2526ca819f521a1a67dba02824
Restore Cube
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — c...
[ "from itertools import permutations as p\n\nd = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))\nf = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]\ng = lambda t: sorted(sorted(q) for q in t)\n\nv = [sorted(map(int, input().split())) for i in range(8)]\nq = v.pop()\n\nu = g(v)\nfor a, b, c in p(v, 3):\n ...
{"inputs": ["0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1", "6 -2 -2\n-5 1 -6\n6 -6 7\n6 3 4\n9 -7 8\n-9 -2 -6\n-9 1 6\n-9 -1 0", "-5 -3 -8\n-8 8 -5\n-3 3 6\n6 3 8\n-8 6 -3\n8 -8 6\n-3 -5 3\n-5 ...
UNKNOWN
PYTHON3
CODEFORCES
2
17ec4d515c12743261193390f42cb456
Mr. Bender and Square
Mr. Bender has a digital table of size *n*<=×<=*n*, each cell can be switched on or off. He wants the field to have at least *c* switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to *n*, and the columns — numbered from left ...
[ "# import math\nfrom collections import Counter, deque, defaultdict\n# from math import *\n\nfrom bisect import bisect_right\n\nMOD = 1000000007\n\n\n# from functools import reduce\n# from itertools import permutations\n# import queue\n\ndef solve():\n x, y, n, c = 0, 0, 0, 0\n\n def suma_impares(m):\n ...
{"inputs": ["6 4 3 1", "9 3 8 10", "9 4 3 10", "9 8 2 10", "1 1 1 1", "10 7 2 7", "8 2 6 10", "8 1 2 10", "6 1 4 10", "1000000 951981 612086 60277", "1000000 587964 232616 62357", "1000000 948438 69861 89178", "1000000000 504951981 646612086 602763371", "1000000000 81587964 595232616 623563697", "1000000000 55 60 71518...
UNKNOWN
PYTHON3
CODEFORCES
7
17ff19eef74317819cc833b0e6176d2b
Heidi and Library (hard)
The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in the previous versions each book could be bought for 1 CHF, now the price of ...
[ "import sys\r\nfrom heapq import heappop, heappush\r\n \r\nclass Edge:\r\n def __init__(self, u, v, cap, cost, rev):\r\n self.u = u\r\n self.v = v\r\n self.cap = cap\r\n self.flow = 0\r\n self.cost = cost\r\n self.rev = rev\r\n\r\ndef add_edge(adj, u, v, capv, costv):\r\...
{"inputs": ["4 80\n1 2 2 1\n1 1 1 1", "4 1\n1 2 2 1\n1 1 1 1", "4 2\n1 2 3 1\n1 1 1 1", "7 2\n1 2 3 1 1 1 2\n1 10 1 0 0 0 0", "11 1\n1 2 3 5 1 10 10 1 1 3 5\n1 1 2 3 4 5 6 7 8 9 10", "5 2\n1 2 3 1 2\n1 1 1 1 1", "4 2\n1 2 3 2\n1 1 1 1", "80 4\n2 6 10 4 7 8 2 8 9 10 6 2 5 3 2 10 5 9 1 3 4 8 6 1 9 3 9 4 7 7 4 6 4 8 1 2 5...
UNKNOWN
PYTHON3
CODEFORCES
1
183d5529b0961a41597819ab12cd61be
Voltage Keepsake
You have *n* devices that you want to use simultaneously. The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow...
[ "from math import inf\r\nn, p = [int(x) for x in input().split()]\r\nl = []\r\nfor i in range(n):\r\n a, b = [int(x) for x in input().split()]\r\n l.append((a, b, b/a))\r\nl.sort(key=lambda x: x[2])\r\nasum = 0\r\nbsum = 0\r\nsumt = 0\r\nfor i in range(n):\r\n a0, b0, _ = l[i]\r\n c1 = inf if i == n-1 e...
{"inputs": ["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1", "1 1\n1 87", "1 1\n100 77", "5 10\n3 81\n3 49\n1 20\n1 12\n1 30", "5 10\n4 3\n1 54\n2 57\n2 31\n1 99", "5 10\n2 81\n3 31\n4 49\n1 35\n1 67", "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92", "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n...
UNKNOWN
PYTHON3
CODEFORCES
22
18570e5f148ba4dbe6c04aea7fe63509
Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
[ "n = int(input())\r\ncomb1 = list(map(int, ' '.join(input()).split()))\r\ncomb2 = list(map(int, ' '.join(input()).split()))\r\ncount = 0\r\nfor i in range(n):\r\n a = abs(comb1[i] - comb2[i])\r\n b = 10 - a\r\n count += min(a, b)\r\nprint(count)", "def main():\n n = int(input())\n o = [int(c) for c...
{"inputs": ["5\n82195\n64723", "12\n102021090898\n010212908089", "1\n8\n1", "2\n83\n57", "10\n0728592530\n1362615763", "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n345991208492215450591028749987997565929823937151988986658547267442300883787812306710300534498...
UNKNOWN
PYTHON3
CODEFORCES
899
18574ec81ce029d7932890bfd5465160
Restoration of the Permutation
Let *A*<==<={*a*1,<=*a*2,<=...,<=*a**n*} be any permutation of the first *n* natural numbers {1,<=2,<=...,<=*n*}. You are given a positive integer *k* and another sequence *B*<==<={*b*1,<=*b*2,<=...,<=*b**n*}, where *b**i* is the number of elements *a**j* in *A* to the left of the element *a**t*<==<=*i* such that *a**j...
[ "s = input()\r\nl = s.split()\r\n\r\nn = int(l[0])\r\nk = int(l[1])\r\n\r\ns = input()\r\nl = s.split()\r\n\r\nb = [-1]\r\n\r\nfor i in range(1, n + 1):\r\n b.append(int(l[i - 1]))\r\n\r\nfor i in range(1, n + 1):\r\n\r\n j = 1\r\n while b[j] != 0:\r\n j += 1\r\n\r\n b[j] -= 1\r\n print(j, end...
{"inputs": ["5 2\n1 2 1 0 0", "4 2\n1 0 0 0", "10 3\n4 2 4 2 1 0 1 0 0 0", "15 3\n4 2 7 5 1 1 1 0 0 0 0 0 0 0 0", "5 1\n1 3 2 0 0", "8 3\n2 0 2 2 1 0 0 0", "1 1\n0", "10 10\n0 0 0 0 0 0 0 0 0 0", "10 9\n1 0 0 0 0 0 0 0 0 0", "10 1\n9 8 7 6 5 4 3 2 1 0", "10 1\n7 6 5 4 3 2 1 0 0 0", "13 2\n1 2 3 4 5 4 3 2 1 0 0 0 0", "2...
UNKNOWN
PYTHON3
CODEFORCES
6
1863b6f28ad0474a2c0dc6ef0e81a030
Megacity
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with ...
[ "import math\r\n \r\ndef solve():\r\n numLocation, totalPeople = map(int, input().split())\r\n location = dict()\r\n for i in range(numLocation):\r\n x, y, people = map(int, input().split())\r\n r = x * x + y * y\r\n if r in location:\r\n location[r] += people\r\n els...
{"inputs": ["4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "2 1\n1 1 999997\n2 2 1", "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10", "15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n...
UNKNOWN
PYTHON3
CODEFORCES
120
18676c03598b38db0d03c7b1d0fce954
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edg...
[ "import sys\nimport math\nimport heapq\ninput = sys.stdin.readline\n\nVC, EC = map(int, input().split())\nG = [[] for _ in range(VC+1)]\nfor _ in range(EC) :\n VA, VB, VW = map(int, input().split())\n G[VA].append((VB, VW))\n G[VB].append((VA, VW))\n\n\nv = [False]*(VC+1)\nd = [math.inf]*(VC+1)\nf = list(r...
{"inputs": ["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "2 1\n1 2 1", "3 1\n1 2 1", "3 3\n1 2 1\n1 3 2\n2 3 1", "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173", "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 17...
UNKNOWN
PYTHON3
CODEFORCES
147
18731b0885aaff022fbbdb83087c9a43
Lucky Ticket
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
[ "n = int(input())\r\ns = str(input())\r\na = 0\r\nb = 0\r\n\r\nfor i, num in enumerate(s):\r\n if num != '7' and num != '4':\r\n print(\"NO\")\r\n a=-1\r\n b=-2\r\n break\r\n else:\r\n if i+1<=n/2:\r\n a+=int(num)\r\n else:\r\n b+=int(num)\r\nels...
{"inputs": ["2\n47", "4\n4738", "4\n4774", "4\n4570", "6\n477477", "6\n777777", "20\n44444444444444444444", "2\n44", "10\n4745474547", "14\n77770004444444", "10\n4747777744", "10\n1234567890", "50\n44444444444444444444444444444444444444444444444444", "50\n44444444444444444444444444444444444444444444444447", "50\n744444...
UNKNOWN
PYTHON3
CODEFORCES
461
189d83c2d5a6b1b0f0bde452f2187d0a
Yaroslav and Time
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has *n* clock stations, station number *i* is at point (*x**i*,<=*y**i*) of the plane. As the player visits station number *i*, he ...
[ "from sys import stdin\r\nfrom math import inf\r\n\r\n\r\ndef readline():\r\n return map(int, stdin.readline().strip().split())\r\n\r\n\r\ndef main():\r\n n, d = readline()\r\n a = [0] + list(readline()) + [0]\r\n x = [0] * n\r\n y = [0] * n\r\n for i in range(n):\r\n x[i], y[i] = readline(...
{"inputs": ["3 1000\n1000\n0 0\n0 1\n0 3", "3 1000\n1000\n1 0\n1 1\n1 2", "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67", "6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n-7 93\n75 -45\n-80 -20", "7 1288\n943 265 649 447 806\n-4 -51\n-26 32\n47 -28\n31 32\n61 65\n-45 -37\n82 42", "8 1931\n440 627 324 538 539...
UNKNOWN
PYTHON3
CODEFORCES
9
18b11fdbe3798b0b5243958f3bf2e4ef
Dependency management
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with lengt...
[ "N=int(input())\r\nSlide=dict()\r\nSlideList=[list()]*N\r\nItogInformation=set()\r\nGoodNameTags=set()\r\n\r\nNewName,NewVer=input().split()\r\nNewVer=int(NewVer)\r\n\r\nGoodNameTags.add(NewName)\r\n\r\nSlide[0]=NewName+' '+str(NewVer)\r\nSlide[NewName+' '+str(NewVer)]=0\r\nNewNum=int(input())\r\nSlideList[0]=[0]*(...
{"inputs": ["4\na 3\n2\nb 1\nc 1\n\nb 2\n0\n\nb 1\n1\nb 2\n\nc 1\n1\nb 2", "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n\ncommons 2\n0\n\nmashadb 3\n0\n\nwebfrmk 6\n2\nmashadb 3\ncommons 2\n\nextra 4\n1\nextra 3\n\nextra 3\n0\n\nextra 1\n0\n\nmashadb 1\n1\nextra 3\n\nmashadb 2\n1\nextra 1", "3\nabc 1\n2\nabc 3...
UNKNOWN
PYTHON3
CODEFORCES
8
18b1871eff3e76fa481fabb660e7fa4a
Slava and tanks
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map. Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he ...
[ "def f(n):\r\n\tl=[]\r\n\tfor i in range(n//2*2,1,-2):\r\n\t\tl.append(i)\r\n\tmid=[]\r\n\tl=l[::-1]\r\n\tfor i in range(1,n+1):\r\n\t\tif i not in l:\r\n\t\t\tmid.append(i)\r\n\tans=l+mid+l\r\n\tprint(len(ans))\r\n\treturn ans\r\nprint(*f(int(input())))", "n = int(input())\r\neven = n // 2\r\nodd = n - even\r\n...
{"inputs": ["2", "3", "4", "6", "10", "15", "100", "100000", "55333", "42273", "29857", "27687", "25517", "23347", "10931", "98514", "6591", "94174", "92004", "59221", "46806", "54882", "42466", "40296", "27880", "25710", "23540", "11124", "8954", "85387", "72971", "81047", "5"], "outputs": ["3\n2 1 2 ", "4\n2 1 3 2 ",...
UNKNOWN
PYTHON3
CODEFORCES
57
18cd04f66c3a25d8ef9c84aaf20ac88c
Vicious Keyboard
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi...
[ "l=input()\r\ns=[]\r\nfor i in l:\r\n\tif(i=='V'):\r\n\t\ts.append(1)\r\n\telse:\r\n\t\ts.append(0)\r\nls=len(s)\r\ni=0\r\nmaxc = 0\r\nc = 0\r\nwhile i+1<ls:\r\n\tif(s[i]==1 and s[i+1]==0):\r\n\t\tc+=1\r\n\ti+=1\r\nmaxc = max(maxc,c)\r\nj=0\r\nwhile j<ls:\r\n\tif(s[j]==1):\r\n\t\ts[j]=0\r\n\telse:\r\n\t\ts[j]=1\r\n...
{"inputs": ["VK", "VV", "V", "VKKKKKKKKKVVVVVVVVVK", "KVKV", "VKKVVVKVKVK", "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV", "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK", "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK", "KVVV...
UNKNOWN
PYTHON3
CODEFORCES
142
18dfbace2937f92f8edc7f2509adeb06
Dishonest Sellers
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week...
[ "import sys\nfrom os import path\nif (path.exists('input.txt') and path.exists('output.txt')):\n sys.stdout = open('output.txt', 'w')\n sys.stdin = open('input.txt', 'r')\n\ndef main():\n n, k = (int(i) for i in input().split())\n a = [int(i) for i in input().split()]\n b = [int(i) for i in input().s...
{"inputs": ["3 1\n5 4 6\n3 1 5", "5 3\n3 4 7 10 3\n4 5 5 12 5", "1 0\n9\n8", "2 0\n4 10\n1 2", "4 2\n19 5 17 13\n3 18 8 10", "5 3\n28 17 20 45 45\n39 12 41 27 9", "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31", "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 1...
UNKNOWN
PYTHON3
CODEFORCES
213
19069faac761fefd3f5fae43dd32fd49
Tourist
Tourist walks along the *X* axis. He can choose either of two directions and any speed not exceeding *V*. He can also stand without moving anywhere. He knows from newspapers that at time *t*1 in the point with coordinate *x*1 an interesting event will occur, at time *t*2 in the point with coordinate *x*2 — another one,...
[ "from sys import stdin\ninput = stdin.buffer.readline\nfrom bisect import bisect\nfrom itertools import zip_longest\n\ndef main():\n n = int(input())\n events = [tuple(map(int,input().split())) for _ in range(n)]\n v = int(input())\n tot, zero = [], []\n for i, e in enumerate(events):\n pos, t...
{"inputs": ["3\n-1 1\n42 7\n40 8\n2", "5\n1 5\n6 7\n17127 17\n17072 42\n17042 77\n3", "7\n-976754 20479\n79929143 911181\n9598220 82517\n-51609349 810257\n67416551 266544\n-14170975 307690\n-15476178 491195\n352", "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-7161 729\n...
UNKNOWN
PYTHON3
CODEFORCES
1
190cc916df6e471a15c1895a240a728e
A Simple Task
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains tw...
[ "N, M = [int(w) for w in input().split()]\ngraph = [[] for _ in range(N)]\ndp = [[0] * (2 ** N) for _ in range(N)]\n\nself_circles = 0\n\nfor _ in range(M):\n a, b = [int(w) - 1 for w in input().split()]\n if a == b:\n self_circles += 1\n else:\n graph[a].append(b)\n graph[b].append(a)...
{"inputs": ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "10 3\n4 8\n9 4\n8 9", "8 28\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8", "12 10\n1 6\n4 5\n4 9\n5 10\n6 12\n7 9\n7 10\n8 10\n10 12\n11 12", "3 0", "6 0", "2 1\n1 2", "2 1\n1...
UNKNOWN
PYTHON3
CODEFORCES
1
1920af96049061e297fe0a7e0d5bea73
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that ...
[ "n = int(input())\n\nspeed_limits = []\nobgon = 0\n\ncurrent_speed = 0\n\ncount = 0\n\nfor i in range(n):\n event = list(input().split())\n if (len(event) == 2):\n type, x = map(int, event)\n if type == 1: # 1 изменил скорость на х\n current_speed = x\n while len(speed_li...
{"inputs": ["11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "5\n1 100\n3 200\n2\n4\n5", "7\n1 20\n2\n6\n4\n6\n6\n2", "1\n1 100", "2\n1 100\n2", "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2", "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1"], "outputs": ["2", "0", "2", "0", "0", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
17
193c184144e66d2a88598d7fa03827ac
Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of *n*·*m* square tiles forming a *n*<=×<=*m* rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Sha...
[ "n,m = (lambda x: (int(x[0]), int(x[1])))(input().split())\r\nx,y,dir = (lambda x: (int(x[0]), int(x[1]), x[2]))(input().split())\r\n\r\nres = 1\r\ndx = -1\r\ndy = -1\r\nif dir[0] == 'D':\r\n dx = 1\r\nif dir[1] == 'R':\r\n dy = 1\r\n\r\ncells = set()\r\ncells.add((x,y))\r\n\r\nfor _ in range(1,(n+m-2)*2):\r\...
{"inputs": ["3 4\n1 1 DR", "3 4\n3 3 DR", "3 3\n1 1 DR", "3 3\n1 2 DL", "2 5\n2 3 DR", "2 3\n2 3 DL", "3 2\n3 1 DL", "3 4\n1 1 DL", "2 2\n2 2 UR", "547 180\n96 1 UR", "657 213\n549 1 UL", "76 153\n1 74 UL", "80304 59860\n27585 59860 UR", "15954 45613\n15954 45142 UR", "66972 6779\n1 5667 UL", "2622 82284\n2540 1 UL", "...
UNKNOWN
PYTHON3
CODEFORCES
1
1954f4f3cff193e51aefea4a144bdfcb
Save Luke
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other ...
[ "d, L, v1, v2 = map(int, input().split())\r\nt = 1\r\ne = 10e-14\r\n\r\na = 0\r\nb = L\r\n\r\nresult = 0.0\r\nwhile True:\r\n if b-a > d:\r\n if (b-v2) - (a+v1) < d:\r\n v1 /= 2\r\n v2 /= 2\r\n t /= 2\r\n continue\r\n else:\r\n a += v1\r\n ...
{"inputs": ["2 6 2 2", "1 9 1 2", "1 10000 1 1", "9999 10000 10000 10000", "1023 2340 1029 3021", "2173 2176 10000 9989", "1 2 123 1", "123 1242 12 312", "2 9997 3 12", "1 10000 10000 10000", "3274 4728 888 4578", "4600 9696 5634 8248", "2255 7902 8891 429", "6745 9881 2149 9907", "4400 8021 6895 2089", "5726 9082 7448...
UNKNOWN
PYTHON3
CODEFORCES
241
195a674edfdb1beb7260a34b31fe41f6
Weird Game
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves f...
[ "ii=lambda:int(input())\r\nkk=lambda:map(int,input().split())\r\nll=lambda:list(kk())\r\nn,a1,a2=ii(),input(),input()\r\nlocs = [0]*4\r\nfor i in range(2*n):\r\n\tlocs[int(a1[i])+2*int(a2[i])]+=1\r\nrm = min(locs[1],locs[2])\r\nlocs[1]-=rm\r\nlocs[2]-=rm\r\nlocs[3]=locs[3]&1\r\nif locs[1]:\r\n\tprint(\"First\")\r\n...
{"inputs": ["2\n0111\n0001", "3\n110110\n001001", "3\n111000\n000111", "4\n01010110\n00101101", "4\n01100000\n10010011", "4\n10001001\n10101101", "3\n000000\n000100", "2\n0000\n1110", "4\n11111111\n10100110", "4\n10100111\n11011000", "4\n00101011\n11110100", "4\n11000011\n00111100", "4\n11101111\n01000110", "4\n0111011...
UNKNOWN
PYTHON3
CODEFORCES
8
19652a10a291705df6b35df2213433ea
Random Teams
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul...
[ "n,m = map(int,input().split())\r\ntemp = n-(m-1)\r\nkmax = (temp*(temp-1))//2 \r\na = n//m \r\ntemp1 = m*(a*(a-1))//2 + a*(n%m) \r\nprint(temp1,kmax)", "n,m=map(int,input().split())\r\nr=n//m\r\nprint(m*r*(r-1)//2+n%m*r,(n-m+1)*(n-m)//2)", "n, m = map(int, input().split())\na = n // m\nb = n % m\nprint((m * a ...
{"inputs": ["5 1", "3 2", "6 3", "5 3", "10 2", "10 6", "1000000000 1", "5000000 12", "1833 195", "1000000000 1000000000", "1000000000 1000000", "1000000000 32170", "1000000 1000", "1234 1123", "599222887 298488", "999999999 500000000", "1000000000 384842119", "1000000000 384842119", "1000000000 2", "1000000000 9999999...
UNKNOWN
PYTHON3
CODEFORCES
239
19822dd149e51b421976d336fb1fb4a8
Equal Sums
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$. You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals...
[ "from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nk = int(input())\r\nlst = []\r\n\r\nfor i in range(k):\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n s = sum(arr)\r\n for j, e in enumerate(arr):\r\n lst.append((s-e, i+1, j+1))\r\n\r\nlst...
{"inputs": ["2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1", "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2", "2\n2\n0 -10000\n2\n10000 0"], "outputs": ["YES\n2 1\n1 4", "NO", "YES\n4 1\n2 5", "YES\n2 1\n1 2"]}
UNKNOWN
PYTHON3
CODEFORCES
37
198410fd502067f83e7e63ffb6065693
Distance in Tree
A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices. You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex...
[ "# from collections import defaultdict\n# import sys\n# sys.setrecursionlimit(10**5)\n# input = sys.stdin.readline\n# ans = 0\n\n# def dfs(node, par):\n# global ans\n# counter = dict()\n\n# counter[0] = 1\n# for i in adj[node]:\n# if i == par:\n# continue\n# tmp = dfs(i, ...
{"inputs": ["5 2\n1 2\n2 3\n3 4\n2 5", "5 3\n1 2\n2 3\n3 4\n4 5", "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "50 3\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n16 1...
UNKNOWN
PYTHON3
CODEFORCES
12
19a6ec21c8071eaac811c5d886bdbcb5
Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
[ "def li(): return list(map(int,input().split())) \r\ndef ls(): return list(map(int,list(input())))\r\ndef i(): return int(input())\r\nfrom collections import defaultdict\r\ngraph = defaultdict(list)\r\nn,m = li()\r\nfor _ in range(m):\r\n x,y = li()\r\n graph[x].append(y)\r\n graph[y].append(x)\r\nvisited...
{"inputs": ["4 3\n1 3\n3 4\n1 4", "4 4\n3 1\n2 3\n3 4\n1 2", "10 4\n4 3\n5 10\n8 9\n1 2", "3 2\n1 2\n2 3", "3 0", "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\...
UNKNOWN
PYTHON3
CODEFORCES
79
19abaf75e3070d35d8add03d295b55c9
Romaji
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
[ "s=input()\r\nanswer='yes'\r\nif s[-1] not in \"naeiou\":\r\n answer='no'\r\nfor i in range(len(s)-1):\r\n if s[i] not in \"naeiou\" and s[i+1] not in \"aeiou\":\r\n answer='no'\r\nprint(answer)", "string=input().lower()\r\nconsonants=['b','c','d','f','g','h','j','k','l','m','p','q','r','s','t','v','...
{"inputs": ["sumimasen", "ninja", "codeforces", "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "n", "necnei", "nternn", "aucunuohja", "a", "b", "nn", "nnnzaaa", "zn", "ab", "aaaaaaaaaa", "aaaaaaaaab", "aaaaaaaaan", "baaaaaaaaa", "naaaaaaaaa", "nbaaaaaaaa", "bbaaa...
UNKNOWN
PYTHON3
CODEFORCES
159
19c0291bd1c79abe04f3ac01b584c1e5
Powerful array
An array of positive integers *a*1,<=*a*2,<=...,<=*a**n* is given. Let us consider its arbitrary subarray *a**l*,<=*a**l*<=+<=1...,<=*a**r*, where 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. For every positive integer *s* denote by *K**s* the number of occurrences of *s* into the subarray. We call the power of the subarray the sum of p...
[ "from collections import defaultdict\r\nfrom operator import itemgetter\r\nimport math\r\n\r\nclass Mo:\r\n def __init__(self, ls):\r\n self.ls = ls\r\n self.n = len(ls)\r\n self.m = max(ls)+1\r\n self.b = math.ceil(math.sqrt(self.n))\r\n\r\n def _init_states(self):\r\n self...
{"inputs": ["3 2\n1 2 1\n1 2\n1 3", "8 3\n1 1 2 2 1 3 1 1\n2 7\n1 6\n2 7", "20 8\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\n4 15\n1 2\n2 20\n7 7\n13 18\n7 7\n3 19\n3 8", "10 5\n10 9 8 7 6 5 4 3 2 1\n4 8\n1 10\n3 9\n2 2\n5 10", "8 10\n100 100 100 100 100 100 100 100\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n8 8\n1 1\n1 5", "1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
19d2ecccfa97f05d68273ed6f8fa0fd3
Permutations
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. The first line contains integers *n* and *k* — the number and digit capacity of numbers cor...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\nfrom heapq import heappush , heappop\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import *\r\nimport itertools\r\n\r\nMOD = 10**9+7\r\nN,K = map(int, input().split())\r\nS = []\r\nfor _ in range(N):\r\n S.append...
{"inputs": ["6 4\n5237\n2753\n7523\n5723\n5327\n2537", "3 3\n010\n909\n012", "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156", "5 5\n61374\n74304\n41924\n46010\n09118", "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116", "7 1\n1\n0\n8\n5\n4\n9\n8", "3 8\n34848224\n16307102\n2518...
UNKNOWN
PYTHON3
CODEFORCES
16