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 |
|---|---|---|---|---|---|---|---|---|---|
2983f24ee4b182c38ef2d076e55954d6 | Road Problem | The Berland capital (as you very well know) contains *n* junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.
The city administr... | [
"def dfs1(v):\r\n mark[v]=1\r\n st.append(v)\r\n dp[v]=d[v]\r\n for u in adj[v]:\r\n if not mark[u]:\r\n d[u]=d[v]+1\r\n dfs1(u)\r\n dp[v]=min(dp[u],dp[v])\r\n elif d[u]<d[v]-1:\r\n dp[v]=min(dp[v],d[u])\r\n if dp[v]==d[v]:\r\n ver[cnt[... | {"inputs": ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n2 4\n3 4", "10 18\n6 4\n3 7\n4 9\n8 4\n3 4\n3 6\n7 5\n3 9\n10 9\n10 5\n1 2\n1 8\n8 2\n5 6\n6 9\n5 9\n3 10\n7 10", "10 13\n2 9\n9 5\n5 10\n4 8\n5 7\n6 1\n5 8\n9 7\n10 3\n7 1\n7 10\n2 1\n3 1", "10 16\n1 3\n4 3\n6 4\n5 3\n5 4\n1 2\n9 8\n10 5\n2 6\n7 9\n7 8\n1 4\n2 3\n10 7\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2985deca1c5256464afb41fab7fce20a | Numbers | One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her youn... | [
"n= int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\nmm=a[0]\r\nb=list(map(lambda x: x-mm, a))\r\nif b[-1]>n or n%2==1:\r\n print('NO')\r\nelse:\r\n c=[0]*(b[-1]+1)\r\n for el in b:\r\n c[el]+=1\r\n for i in range(1,len(c)):\r\n c[i] = c[i]-c[i-1] \r\n c[i-1]=0\r... | {"inputs": ["4\n1 2 3 2", "6\n1 1 2 2 2 3", "6\n2 4 1 1 2 2", "4\n999999998 1000000000 999999999 999999999", "5\n6 7 6 7 6", "8\n3 5 8 4 7 6 4 7", "10\n10 11 10 11 10 11 10 11 10 11", "6\n1 2 3 4 5 6", "4\n294368194 294368194 294368194 294368195", "5\n637256245 637256246 637256248 637256247 637256247", "5\n473416369 47... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
298842cf255460074457de672e78bc2b | Restoring Increasing Sequence | Peter wrote on the board a strictly increasing sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the b... | [
"def check(a,b,n):\r\n for i in range(n):\r\n if not ((b[i] == '?') or (a[i] == b[i])): \r\n return False\r\n return True\r\n\r\ndef process(a,b):\r\n for i in range(len(a)-1,-1,-1):\r\n if ((b[i] == '?' and a[i] != '9') or (b[i] != '?' and a[i] < b[i])) and check(a,b,i):\r\n ... | {"inputs": ["3\n?\n18\n1?", "2\n??\n?", "5\n12224\n12??5\n12226\n?0000\n?00000", "10\n473883\n3499005\n4?74792\n58146??\n8?90593\n9203?71\n?39055?\n1?692641\n11451902\n?22126?2", "8\n?\n2\n3\n4\n?\n?\n?\n9", "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5?\n?5?\n27... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
29bd0490fe176e76bac1e031211a7544 | Amity Assessment | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the ... | [
"def main():\n res = []\n for _ in 0, 1:\n a, b = input()\n d, c = input()\n res.append([x for x in (a, b, c, d) if x != 'X'])\n a, b = res\n print((\"NO\", \"YES\")[b[b.index(a[0]) - 1] == a[2]])\n\n\nif __name__ == '__main__':\n main()\n",
"l1=str()\r\ns=str(input())\r\nl1=s.... | {"inputs": ["AB\nXC\nXB\nAC", "AB\nXC\nAC\nBX", "XC\nBA\nCB\nAX", "AB\nXC\nAX\nCB", "CB\nAX\nXA\nBC", "BC\nXA\nBA\nXC", "CA\nXB\nBA\nCX", "CA\nXB\nAC\nBX", "CB\nAX\nCX\nAB", "AX\nCB\nBC\nXA", "CA\nXB\nBA\nXC", "CX\nAB\nAX\nCB", "AB\nXC\nAB\nCX", "XC\nBA\nXC\nAB", "BA\nXC\nAC\nXB", "AX\nBC\nAC\nBX", "XC\nBA\nCB\nXA", "C... | UNKNOWN | PYTHON3 | CODEFORCES | 95 | |
29ecd093ea72b0b060198f59c4a18db5 | Three Sons | Three sons inherited from their father a rectangular corn fiend divided into *n*<=×<=*m* squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, which is why he bequeathed to divide his field into three parts containing *A*, *B* and *C* tons of ... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom itertools import permutations\r\n\r\nf = open('input.txt', 'r')\r\nn, m = map(int, f.readline().split())\r\ng = [list(map(int, f.readline().split())) for _ in range(n)]\r\nw = list(zip(*g))\r\ng = [sum(i) for i in g]\r\nw = [sum(i) for i in w]\r\ns = set(permutation... | {"inputs": ["3 3\n1 1 1\n1 1 1\n1 1 1\n3 3 3", "2 5\n1 1 1 1 1\n2 2 2 2 2\n3 6 6", "3 3\n1 2 3\n3 1 2\n2 3 1\n5 6 7", "3 3\n0 0 0\n0 0 1\n1 1 0\n2 1 0", "3 3\n0 0 0\n0 1 0\n0 0 0\n1 0 0", "3 2\n0 0\n0 2\n0 0\n2 0 0", "3 2\n0 1\n2 1\n0 1\n3 1 1", "5 10\n0 1 4 4 4 1 4 0 0 4\n1 1 2 0 4 4 2 2 0 3\n3 2 4 0 3 0 1 3 1 0\n4 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
29f9d8a3d36ed0108307535ffacebc46 | Find Maximum | Valera has array *a*, consisting of *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1, and function *f*(*x*), taking an integer from 0 to 2*n*<=-<=1 as its single argument. Value *f*(*x*) is calculated by formula , where value *bit*(*i*) equals one if the binary representation of number *x* contains a 1 on the *i*-th posit... | [
"n = int(input())\na = list(map(int, input().split()))\nk = input()\npref = [a[0]]\nfor i in range(1, n):\n pref.append(pref[-1] + a[i])\ncur = 0\nans = 0\nfor i in range(n - 1, -1, -1):\n if k[i] == '0':\n continue\n if cur + (pref[i - 1] if i > 0 else 0) > ans:\n ans = cur + (pref[i - 1] if... | {"inputs": ["2\n3 8\n10", "5\n17 0 10 2 1\n11010", "18\n4382 3975 9055 7554 8395 204 5313 5739 1555 2306 5423 828 8108 9736 2683 7940 1249 5495\n110001100101110111", "43\n475 2165 8771 7146 8980 7209 9170 9006 6278 6661 4740 6321 7532 6869 3788 7918 1707 5070 3809 5189 2494 8255 1123 3197 190 5712 9873 3286 9997 133 90... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
2a130954f3cc1e321e7e8e7593c5ef5a | Milking cows | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | [
"from math import inf\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nsm = [0]\r\nfor x in a: sm.append(sm[-1]+x)\r\n\r\nans1 = ans2 = 0\r\nfor i in range(1, n+1):\r\n if a[i-1] == 0:\r\n ans1 += sm[i-1]\r\n\r\nfor i in range(1, n+... | {"inputs": ["4\n0 0 1 0", "5\n1 0 1 0 1", "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0", "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 66 | |
2a30f64e79901e0b36893401ae12ce7a | Chessboard | Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size *n* by *n*, *n* is always odd. And what's even worse, some squares were of wrong color. *j*-th square of the *i*-th row of *k*-th piece of the board has color *a**k*... | [
"n = int(input())\n\npieces = []\nrecolors = []\nfor i in range(4):\n piece = []\n for j in range(n):\n line = input().strip()\n piece.append(line)\n if i != 3:\n input()\n pieces.append(piece)\n cur1 = 0\n for x in range(n):\n for y in range(n):\n cur1 += (x... | {"inputs": ["1\n0\n\n0\n\n1\n\n0", "3\n101\n010\n101\n\n101\n000\n101\n\n010\n101\n011\n\n010\n101\n010", "3\n000\n000\n000\n\n111\n111\n111\n\n111\n111\n111\n\n000\n000\n000", "3\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101", "1\n1\n\n0\n\n1\n\n0", "1\n0\n\n0\n\n1\n\n1", "1\n1\n\n1\n\n0\n\n1", "1\... | UNKNOWN | PYTHON3 | CODEFORCES | 34 | |
2a338b07cfffe109bf58c7f0c5113a13 | Misha and Changing Handles | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | [
"n=int(input())\r\na=[]\r\n\r\nfor i in range(n):\r\n b=input().split()\r\n if b[0] in a:\r\n ind=a.index(b[0])\r\n a.insert(ind,b[1])\r\n a.pop(ind+1)\r\n else:\r\n a.append(b[0])\r\n a.append(b[1])\r\nprint(len(a)//2)\r\nfor i in range(len(a)//2):\r\n print(*a[:2])\r... | {"inputs": ["5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "1\nMisha Vasya", "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k", "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha", "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e", "17\nn5WhQ VCc... | UNKNOWN | PYTHON3 | CODEFORCES | 334 | |
2a36302b6d7ee6e2e5069592a4d07e84 | The Art of Dealing with ATM | ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most *k* bills from it, and the ... | [
"n,k = [int(s) for s in input().split()]\r\n\r\nbills = [int(s) for s in input().split()]\r\npairs = {}\r\nfor bill in bills:\r\n for i in range(k):\r\n possible = (i+1)*bill\r\n if possible not in pairs or i+1 < pairs[possible]:\r\n pairs[possible] = i+1\r\nq = int(input())\r\n\r\nmymax... | {"inputs": ["6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950", "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15", "5 5\n1 2 3 6 102\n10\n1\n4\n30\n1\n76\n114\n10\n13\n13\n4", "3 5\n1 36 95\n10\n3\n1\n4212\n144\n4\n109\n6\n5\n2\n24", "4 5\n1 11 50 203\n10\n5\n5\n150\n53\n56\n5\n12304\... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
2a66bad0fc0565adc9835909ce2b06c6 | Vanya and Computer Game | Vanya and his friend Vova play a computer game where they need to destroy *n* monsters to pass a level. Vanya's character performs attack with frequency *x* hits per second and Vova's character performs attack with frequency *y* hits per second. Each character spends fixed time to raise a weapon and then he hits (the t... | [
"n,x,y=map(int,input().split())\r\ndef f(a,x,y):return(a*x+x+y-1)//(x+y)\r\nfor _ in[0]*n:n=int(input());r=f(n,x,y)*y-f(n,y,x)*x;print(['Both','Vova','Vanya'][(r>0)+(r<0)*2])"
] | {"inputs": ["4 3 2\n1\n2\n3\n4", "2 1 1\n1\n2", "7 5 20\n26\n27\n28\n29\n30\n31\n32", "10 10 1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10 1 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "1 999999 1000000\n1000000000", "5 5 6\n999999999\n999999998\n999999997\n999999996\n999999995", "10 13 27\n3\n21\n23\n17\n15\n23\n16\n7\n24\n20", "1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2aabae6e92b6532ec48754a161b83180 | White, Black and White Again | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next *n* days. Polycarpus knows that he is in for *w* good events and *b* not-so-good events. At least one event is going... | [
"import sys\r\n\r\nMOD = int(1e9) + 9\r\n\r\ndef inv(n):\r\n return pow(n, MOD - 2, MOD)\r\n\r\ndef combo(n):\r\n rv = [0 for __ in range(n + 1)]\r\n rv[0] = 1\r\n for k in range(n):\r\n rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD\r\n return rv\r\n\r\nwith sys.stdin as fin, sys.stdou... | {"inputs": ["3 2 1", "4 2 2", "3 2 2", "3 3 1", "3 2 2", "3 3 3", "4 2 3", "4 3 2", "10 10 10", "10 7 5", "10 4 9", "100 200 300", "200 100 300", "239 300 231", "300 300 300", "300 2 300", "300 300 1", "3 300 300", "3 2 300", "3 300 1", "4000 1000 3000", "4000 2000 2000", "4000 100 3900", "4000 2 3998", "3 2 4000", "3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2b14359cdb47916fbca3f80ffe7e2333 | Treasure Hunt | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | [
"n = int(input())\r\ns1, s2, s3 = input(), input(), input()\r\nl = len(s1)\r\n\r\nflag = 0\r\n\r\nif n>=l:\r\n\tprint(\"Draw\")\r\n\tflag = 1\r\n\r\n\r\nif flag == 0:\r\n\r\n\tans = []\r\n\tm1 = m2 = m3 = 0\r\n\ts01 = s02 = s03 = ''\r\n\tli = [chr(x) for x in range(ord('a'), ord('z') + 1)] \r\n\tli += [chr(x) for x... | {"inputs": ["3\nKuroo\nShiro\nKatie", "7\ntreasurehunt\nthreefriends\nhiCodeforces", "1\nabcabc\ncbabac\nababca", "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb", "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\nXaZXbbdcX... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
2b1d53828b5f8636bf0f7bf04797d798 | Queries on a String | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | [
"import sys\r\nimport math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\n\r\ndef solve(): # 123456\r\n s=input().rstrip()\r\n for _ in range(int(input())):\r\n l,r,k=map(int,input().split())\r\n l-=1\r\n r-=1\r\n length=r-l+1\r\n k%=length\r\n s=s[:l]+s[r-k+1:r+1]+... | {"inputs": ["abacaba\n2\n3 6 1\n1 4 2", "u\n1\n1 1 1", "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4", "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6", "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8", "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 61 | |
2b29fa76601c100b41a167c1605ef5fb | SMSC | Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.
For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In... | [
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n t,c=(int(i) for i in input().split())\r\n l.append([t,c])\r\nt1=-1\r\nk=0\r\nm=0\r\ns=0\r\nfor i in range(1000002):\r\n m=max(m,s)\r\n if(k==... | {"inputs": ["2\n1 1\n2 1", "1\n1000000 10", "3\n3 3\n4 3\n5 3", "1\n1 1", "2\n1 11\n100 10", "4\n1 10\n2 9\n3 8\n40 3", "5\n2 1\n5 2\n6 1\n7 1\n8 1", "4\n10 1000\n99998 20\n99999 10\n1000000 100", "6\n10 10\n100 500\n200 500\n500 1\n999995 4\n999996 15", "10\n1 5\n2 5\n3 10\n4 8\n5 5\n6 4\n7 8\n8 9\n9 2\n10 10", "10\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
2b6a04c9aeb28e5e0278b8ff88b2a9b6 | Big Maximum Sum | Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.
This problem is similar to a standard problem but it has a different format and constraints.
In the stand... | [
"def get_best(arr):\r\n ans, now = -(1 << 64), 0\r\n for i in arr:\r\n now += i\r\n ans = max(ans, now)\r\n if (now < 0): now = 0\r\n return ans\r\n\r\n\r\ndef compute(arr):\r\n ans, now = -(1 << 64), 0\r\n for i in arr:\r\n now += i\r\n ans = max(ans, now)\r\n r... | {"inputs": ["3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3", "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1", "4 3\n6 6 8 -5 4 10 -2\n1 -2\n1 -10\n5 -10 10 8 -7 -10\n2 4 1", "7 7\n2 -8 -7\n5 2 -10 10 -2 4\n7 10 -8 9 8 9 -10 -3\n6 0 6 -9 9 -6 -9\n4 -6 -9 10 -6\n3 -8 4 10\n7 -1 -3 10 -8 -6 -3 6\n4 5 4... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
2b6f2bf3f26bc64383b9036248b68a90 | A Student's Dream | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess... | [
"al, ar = list(map(int, input().split()))\r\nbl, br = list(map(int, input().split()))\r\n\r\nif (br >= al-1 and br <= (al+1)*2) or (bl <= (ar+1)*2 and bl >= ar-1):\r\n print('YES')\r\nelse:\r\n print('NO')",
"A1,A2=map(int,input().split())\r\nB1,B2=map(int,input().split())\r\nprint(\"YES\" if A2-1<=B1<=(A2... | {"inputs": ["5 1\n10 5", "4 5\n3 3", "1 2\n11 6", "1 1\n1 1", "2 2\n1 1", "3 3\n1 1", "4 4\n1 1", "100 100\n50 50", "100 3\n4 1", "100 5\n1 1", "100 4\n1 1", "100 1\n4 1", "1 100\n1 4", "1 100\n5 4", "1 100\n1 5", "43 100\n65 24", "4 2\n12 1", "6 11\n13 11", "2 6\n12 12", "14 7\n2 9", "1 14\n7 14", "6 11\n2 10", "5 12\... | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
2b7a88a8b2f2498416289bb61345d762 | Problem About Equation | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the... | [
"# import sys\r\n# sys.stdin = open(\"test.txt\", 'r')\r\n\r\nn, b = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nans = []\r\nt = sum(a) + b\r\np = t/n\r\nfor v in a:\r\n s = p-v\r\n if s < 0:\r\n print(-1)\r\n break\r\n else:\r\n ans.append(s)\r\nelse:... | {"inputs": ["5 50\n1 2 3 4 5", "2 2\n1 100", "2 2\n1 1", "3 2\n1 2 1", "3 5\n1 2 1", "10 95\n0 0 0 0 0 1 1 1 1 1", "3 5\n1 2 3", "3 5\n1 3 2", "3 5\n2 1 3", "3 5\n2 3 1", "3 5\n3 1 2", "3 5\n3 2 1", "2 1\n1 1", "2 1\n2 2", "3 2\n2 1 2", "3 3\n2 2 1", "3 3\n3 1 2", "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 ... | UNKNOWN | PYTHON3 | CODEFORCES | 60 | |
2b7abc2a0c81c17cc233bb6a548d4284 | Petya and Spiders | Little Petya loves training spiders. Petya has a board *n*<=×<=*m* in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell ... | [
"maxn = 7\r\nd = [[-1 for _ in range(1 << (2 * maxn))] for _ in range(57)]\r\nnbits = [0] * 100500\r\ndef ok(x, x3):\r\n x2 = (x & ((1 << m) - 1))\r\n x >>= m\r\n x1 = x\r\n x = 0\r\n x |= x1\r\n x |= x2\r\n x |= (x2 << 1)\r\n x |= (x2 >> 1)\r\n x |= x3\r\n return (x & ((1 << m) - 1)) ... | {"inputs": ["1 1", "2 3", "4 1", "4 2", "4 3", "4 4", "1 40", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "1 11", "1 12", "1 13", "1 14", "1 15", "1 16", "1 17", "1 18", "1 19", "1 20", "1 21", "1 22", "1 23", "1 24", "1 25", "1 26", "1 27", "1 28", "1 29", "1 30", "1 31", "1 32", "1 33", "1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2b86cf8aaf86f541b96b91d680b154cb | Help Shrek and Donkey | Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds *m* cards and the Donkey holds *n* cards (the players do not see each other's cards), and one more card lies on the table face down so that both pla... | [
"N, M = map(int, input().split())\r\nK = max(N, M)\r\ndp = [[-1e8 for j in range(K + 1)] for i in range(K + 1)]\r\n\r\nfor i in range(K + 1):\r\n\tdp[0][i] = 1 / (1 + i)\r\n\tdp[i][0] = 1\r\nfor s in range(2, 2 * K + 1):\r\n\tn, m = 1, s - 1\r\n\twhile n < s:\r\n\t\tif not (K < n or K < m):\r\n\t\t\tassert dp[m - 1... | {"inputs": ["0 3", "1 0", "1 1", "0 0", "2 0", "0 1", "0 2", "1 2", "2 1", "2 2", "863 814", "593 676", "124 830", "582 865", "458 81", "969 527", "886 340", "869 326", "292 760", "999 929", "528 716", "290 221", "863 620", "797 754", "915 183", "8 145", "176 38", "945 457", "997 971", "44 932", "230 840", "995 646", "... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2bc3804437ac327173e6ef757e083bb1 | Mike and strings | Mike has *n* strings *s*1,<=*s*2,<=...,<=*s**n* each consisting of lowercase English letters. In one move he can choose a string *s**i*, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike a... | [
"l = []\r\nfor _ in range(int(input())):\r\n s = input()\r\n l.append({s[i:] + s[:i]: i for i in range(len(s))[::-1]})\r\nr = min(sum(d.get(s, 9999) for d in l) for s in l[0])\r\nprint(r if r < 9999 else -1)\r\n",
"s = []\r\nfor _ in range(int(input())) :\r\n s.append(str(input()))\r\n\r\nans = 10**9\r\n... | {"inputs": ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab", "3\nkwkb\nkbkw\nbkwk", "1\na", "2\nnjtazaab\nabnjtaza", "38\nkmlzdcnm\nmlzdcnmk\nlzdcnmkm\nkmlzdcnm\nlzdcnmkm\nzdcnmkml\nzdcnmkml\nmlzdcnmk\nzdcnmkml\nmlzdcnmk\nlzdcnmkm\nzdcnmkml\nkmlzdcnm\nlzdcnmkm\nzdcnmkml\nmlzdcnmk\nk... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
2bdc40552d3c516afc25977c351a847a | Messenger | Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ... | [
"#!/usr/bin/env python3\r\n\r\ndef cal_last(s):\r\n n = len(s)\r\n last = [-1]*(n+1)\r\n i,j = 0,-1\r\n while i<n:\r\n while j!=-1 and s[i]!=s[j]:\r\n j=last[j]\r\n i,j = i+1,j+1\r\n last[i] = j\r\n return last\r\n\r\ndef kmp(p,t,last):\r\n m = len(p)\r\n n =... | {"inputs": ["5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c", "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a", "5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d", "9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\n2-l 1-o 1-w", "5 3\n1-m 1-i 2-r 1-o 1-r\n1-m 1-i 1-r", "9 2\n1-a 2-b 1-o 1-k 1-l 1-m 1-a 3-b 3-z\n1-a 2-b", "10 3\n1-b 1-a 2-b 1-a 1-b 1-a... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2bec4379a795a2f285822a1a74be9293 | none | Once Vasya and Petya assembled a figure of *m* cubes, each of them is associated with a number between 0 and *m*<=-<=1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the *OX* is the ground, and the *OY* is directed upwards. Each cube is associated with the coordinates of it... | [
"import heapq\n\ndef coor_neighbor(coor, dxs, dys):\n x, y = coor\n for dx in dxs:\n for dy in dys:\n yield x + dx, y + dy\n\n\ndef coor_bottoms(coor):\n return coor_neighbor(coor, (-1, 0, 1), (-1, ))\n\n\ndef coor_tops(coor):\n return coor_neighbor(coor, (-1, 0, 1), (1, ))\n\n\ndef co... | {"inputs": ["3\n2 1\n1 0\n0 1", "5\n0 0\n0 1\n0 2\n0 3\n0 4", "10\n-1 2\n-3 0\n5 5\n4 4\n-2 1\n1 1\n3 3\n2 2\n0 0\n-1000000000 0", "10\n-678318184 2\n-678318182 3\n580731357 2\n-678318182 1\n-678318184 1\n-678318183 0\n-678318181 2\n580731357 1\n580731358 0\n-678318183 2", "15\n-491189818 2\n-491189821 6\n-491189823 4\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2becae75cadf2898f188dd0410a44eb1 | Safe | Vasya tries to break in a safe. He knows that a code consists of *n* numbers, and every number is a 0 or a 1. Vasya has made *m* attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so u... | [
"import sys\r\nreadline=sys.stdin.readline\r\n\r\ndef Pop_Count(N):\r\n r=(N&0x5555555555555555)+((N>>1)&0x5555555555555555)\r\n r=(r&0x3333333333333333)+((r>>2)&0x3333333333333333)\r\n r=(r&0x0f0f0f0f0f0f0f0f)+((r>>4)&0x0f0f0f0f0f0f0f0f)\r\n r=(r&0x00ff00ff00ff00ff)+((r>>8)&0x00ff00ff00ff00ff)\r\n r... | {"inputs": ["6 2\n000000 2\n010100 4", "6 3\n000000 2\n010100 4\n111100 0", "6 3\n000000 2\n010100 4\n111100 2", "6 1\n101011 2", "7 2\n1011111 2\n1001111 1", "6 4\n000110 2\n010001 2\n001111 2\n001100 2", "8 3\n00111100 5\n10100111 2\n10110101 2", "35 10\n10010111001010111001011111000111111 1\n101001110010101000011111... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2bfb5015a753c9976a410730dcd8bc2e | Square Root of Permutation | A permutation of length *n* is an array containing each integer from 1 to *n* exactly once. For example, *q*<==<=[4,<=5,<=1,<=2,<=3] is a permutation. For the permutation *q* the square of permutation is the permutation *p* that *p*[*i*]<==<=*q*[*q*[*i*]] for each *i*<==<=1... *n*. For example, the square of *q*<==<=[4... | [
"import sys\r\nfrom collections import defaultdict\r\nreadline=sys.stdin.readline\r\n\r\nN=int(readline())\r\nP=list(map(int,readline().split()))\r\nfor x in range(N):\r\n P[x]-=1\r\nperm=[]\r\nseen=[False]*N\r\nfor x in range(N):\r\n if seen[x]:\r\n continue\r\n perm.append([])\r\n perm[-1].appe... | {"inputs": ["4\n2 1 4 3", "4\n2 1 3 4", "5\n2 3 4 5 1", "1\n1", "1\n1", "10\n8 2 10 3 4 6 1 7 9 5", "10\n3 5 1 2 10 8 7 6 4 9", "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
2c194e8d15f692a3b9c94af7a2f3a338 | Stripe | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | [
"n = int(input())\n\nsq = [int(i) for i in input().split(\" \")]\n\nways = 0\n\nsoma1anterior = 0\nsoma2anterior = sum(sq[1:n]) + sq[0]\ncount = 0\n\nfor i in range(0, n - 1):\n\n s1 = soma1anterior + sq[i]\n s2 = soma2anterior - sq[i]\n\n if s1 == s2:\n ways += 1\n\n soma1anterior = s1\n soma... | {"inputs": ["9\n1 5 -6 7 9 -16 0 -2 2", "3\n1 1 1", "2\n0 0", "4\n100 1 10 111", "10\n0 4 -3 0 -2 2 -3 -3 2 5", "10\n0 -1 2 2 -1 1 0 0 0 2", "10\n-1 -1 1 -1 0 1 0 1 1 1", "10\n0 0 0 0 0 0 0 0 0 0", "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -... | UNKNOWN | PYTHON3 | CODEFORCES | 253 | |
2c3e5f11a0cecba2139f42a28820c14f | Replacement | Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that a... | [
"input()\r\np = list(map(int, input().split()))\r\nx = max(p)\r\nif p[p.index(x)] == 1:\r\n p[p.index(x)] = 2\r\nelse:\r\n p[p.index(x)] = 1\r\np.sort()\r\nprint(' '.join(str(i) for i in p))",
"n=int(input())\r\nar=list(map(int,input().split()))\r\nar=sorted(ar)\r\nif(ar[-1]==1):\r\n ar[-1]=2\r\nelse:\r\... | {"inputs": ["5\n1 2 3 4 5", "5\n2 3 4 5 6", "3\n2 2 2", "4\n1 1 2 3", "3\n1 1 1", "10\n5 6 1 2 3 1 3 45 7 1000000000", "4\n1000000000 234765 3485636 385634876", "1\n1", "25\n1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 1 2", "2\n2 1", "3\n1 2 1", "1\n2", "1\n4", "3\n1 1 2", "2\n1 2", "2\n1 3", "2\n1 1", "2\n5 5", "1\n... | UNKNOWN | PYTHON3 | CODEFORCES | 48 | |
2c4ee4399f143ea9b2870f8e4b4d7336 | Vanya and Exams | Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya mu... | [
"def solve(a, b, r, avg):\r\n diff = max(0, len(a) * avg - sum(a))\r\n \r\n sorted_indices = sorted(range(len(a)), key=lambda i: b[i])\r\n \r\n result = 0\r\n index = 0\r\n while diff != 0:\r\n raise_num = min(diff, r - a[sorted_indices[index]])\r\n result += raise_num * b[sorted_... | {"inputs": ["5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "2 5 4\n5 2\n5 2", "6 5 5\n1 7\n2 4\n3 5\n4 6\n5 6\n4 7", "1 1000000000 1000000\n1 1000000", "10 10 7\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1", "3 5 2\n1 10\n1 7\n1 4", "10 10 10\n9 8\n3 9\n3 6\n10 5\n5 5\n6 10\n10 3\n6 7\n2 3\n9 8", "1 1 1\n1 1", "1 100 10\n8 2... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
2cb60d83414775ebf40f496074fdbc75 | Statues | In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8<=×<=8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contai... | [
"r, s = [63], ''.join(input() + 'T' for i in range(8)) + 'T' * 9\nfor i in range(0, 72, 9):\n t = set()\n for x in r:\n for y in (x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8):\n if s[y] == 'T': continue\n if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9]... | {"inputs": [".SSSSSSA\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\nMSSSSSSS", "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "SSSSSSSA\n......SS\n.......S\n.......S\n.......S\n.......S\n.......S\nM......S", ".......A\nS.S.S.S.\n........\n.S.S.S.S\n........\nS.S.S.S.\n.... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
2cebca1bd851b6b5e931ae824f9d6d35 | Almost Increasing Array | We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it).
You are given an array *a* consisting of *n* elements. You are allowed to replace any element with any integer nu... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef segment_tree(n):\r\n tree = [0] * pow(2, n.bit_length() + 1)\r\n return tree\r\n\r\ndef update(i, x, tree):\r\n i += len(tree) // 2\r\n tree[i] = x\r\n i //= 2\r\n while True:\r\n if i == 0:\r\n ... | {"inputs": ["5\n5 4 3 2 1", "5\n1 2 8 9 5", "15\n1013 8003 4947 359 17360 21594 25180 25764 22357 22357 16649 12544 23382 10579 25937", "8\n1 1 1 1 1 1 1 1", "7\n100 105 108 108 107 108 109", "7\n1 5 6 2 3 4 5", "5\n3 4 1 2 5", "8\n53 8 4 6 4 3 8 5", "6\n13 7 4 3 1 4", "6\n6 1 6 2 1 5", "4\n1 2 1 2", "8\n1 5 2 3 4 7 5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2cfe1a7284c39fbf0b07946174ad81ad | Biathlon | Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. I... | [
"'''input\n3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2\n'''\nfrom sys import stdin\nfrom bisect import bisect_left\nfrom collections import OrderedDict\n\n\ndef check(c, r, x, y):\n\tif x**2 + y**2 - 2*x*c + c**2 <= r**2:\n\t\treturn True\n\telse:\n\t\treturn False\n\n\n# main starts\nn = int(stdin.readline().strip()... | {"inputs": ["3\n2 1\n5 2\n10 1\n5\n0 1\n1 3\n3 0\n4 0\n4 0", "3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2", "2\n0 5\n10 5\n2\n7 2\n6 1", "3\n-3 3\n-10 2\n10 2\n4\n10 2\n2 -2\n-11 -1\n10 0", "5\n3 2\n-1 2\n6 1\n-6 1\n20 5\n6\n1 -2\n5 0\n5 1\n1 0\n-4 0\n3 2", "4\n2 1\n5 1\n-6 1\n10 2\n3\n-6 0\n-6 1\n-5 0", "2\n10 10\n-20 2... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
2d0d04fdf064776c1cdb48fe19f15fc2 | Text Document Analysis | Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of:
- uppercase and lowercase English ... | [
"def check(a):\r\n if a!='(' and a!=')' and a!='_':\r\n return True\r\n return False\r\n\r\nn=int(input())\r\ns=input()\r\ncnt,wcnt=0,0\r\ni=0\r\nwhile(i<n):\r\n if s[i]=='_':\r\n i+=1;continue\r\n if s[i]=='(':\r\n i+=1\r\n while(i<n and s[i]!=')'):\r\n if s[i]=='_':\r\n i+=1;continue\r... | {"inputs": ["37\n_Hello_Vasya(and_Petya)__bye_(and_OK)", "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__", "27\n(LoooonG)__shOrt__(LoooonG)", "5\n(___)", "254\n()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
2d12baac1920921d796b1d8793614adc | Rock-paper-scissors | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | [
"F=input()\nM=input()\nS=input()\n \nBeater={\"paper\":\"scissors\",\"scissors\":\"rock\",\"rock\":\"paper\"}\n \nif S==Beater[F] and F==M:\n print(\"S\")\n \nelif F==Beater[S] and S==M:\n print(\"F\")\n \nelif M==Beater[F] and F==S:\n print(\"M\")\n \nelse:\n print(\"?\")\n \t \t\t\t \t ... | {"inputs": ["rock\nrock\nrock", "paper\nrock\nrock", "scissors\nrock\nrock", "scissors\npaper\nrock", "paper\npaper\nrock", "rock\npaper\nrock", "rock\nscissors\nrock", "paper\nscissors\nrock", "scissors\nscissors\nrock", "rock\nrock\npaper", "paper\nrock\npaper", "scissors\nrock\npaper", "rock\npaper\npaper", "paper\n... | UNKNOWN | PYTHON3 | CODEFORCES | 212 | |
2d13ff2f926ab901a329406d9816deef | Sereja and Contests | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: *Div*1 (for advanced coders) and *Div*2 (for beginner coders). Two rounds, *Div*1 and *Div*2, can go simultaneously, (*Div*1 ro... | [
"k, n = map(int, input().split())\r\nli = [0 for i in range(k-1)]\r\nfor i in range(n):\r\n x = input()\r\n if x.count(' ') == 1:\r\n a, b=map(int, x.split())\r\n li[b-1] = 1\r\n else:\r\n a, b, c= map(int, x.split())\r\n li[b-1] = 1\r\n li[c-1] = 1\r\nconsecutive = 0\r\n... | {"inputs": ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0", "10 2\n1 1 2\n1 8 9", "9 3\n1 4 5\n1 1 2\n1 6 7", "7 2\n2 3\n1 5 6", "81 28\n1 77 78\n1 50 51\n2 9\n1 66 67\n1 12 13\n1 20 21\n1 28 29\n1 34 35\n1 54 55\n2 19\n1 70 71\n1 45 46\n1 36 37\n2 47\n2 7\n2 76\n2 6\n2 31\n1 16 17\n1 4 5\n1 73 74\n1 64 65\n2 62\n2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
2d14cbaed2e88019a8850c627c775f85 | Analysis of Pathes in Functional Graph | You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to *n*<=-<=1.
Graph is given as the array *f*0,<=*f*1,<=...,<=*f**n*<=-<=1, where *f**i* — the number of vertex to which goes the only arc from the vertex *i*. Besides you are giv... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nw = list(map(int, input().split()))\r\npow_pos = a[:]\r\npow_mi = w[:]\r\npow_s = w[:]\r\npos = list(range(n))\r\nmi = [10 ** 18] * n\r\ns = [0] * n\r\nfor i in range(35):\r\n if k & (1 << i... | {"inputs": ["7 3\n1 2 3 4 3 2 6\n6 3 1 4 2 2 3", "4 4\n0 1 2 3\n0 1 2 3", "5 3\n1 2 3 4 0\n4 1 2 14 3", "1 1\n0\n10000", "1 2\n0\n10000", "1 10000000000\n0\n10000", "2 3\n0 0\n4 7", "2 3\n0 1\n4 7", "2 3\n1 0\n4 7", "2 3\n1 1\n4 7", "3 10\n0 1 2\n9240 5331 6721", "4 10\n2 1 2 1\n960 2596 3752 8303", "5 10\n0 2 2 0 2\n8... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
2d174b69461e55ae9529cf4af4ca99b1 | Area of Two Circles' Intersection | You are given two circles. Find the area of their intersection.
The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) — the position of the center and the radius of the first circle.
The second line contains three integers *x*2,<=*y*2,<=*r*2 (<=-<=109<=≤<=*x*... | [
"from math import pi, sqrt\r\nfrom decimal import *\r\n\r\ngetcontext().prec = 100\r\ndef cos(x):\r\n getcontext().prec += 2\r\n i, lasts, s, fact, num, sign = 0, 0, 1, 1, 1, 1\r\n while s != lasts:\r\n lasts = s\r\n i += 2\r\n fact *= i * (i-1)\r\n num *= x * x\r\n sign ... | {"inputs": ["0 0 4\n6 0 4", "0 0 5\n11 0 5", "0 0 10\n9 0 1", "0 0 2\n2 2 2", "0 0 10\n5 0 5", "-9 8 7\n-9 8 5", "-60 -85 95\n-69 -94 95", "159 111 998\n161 121 1023", "6008 8591 6693\n5310 8351 7192", "-13563 -6901 22958\n-19316 -16534 18514", "-875463 79216 524620\n-891344 76571 536598", "-8907963 -8149654 8808560\n-... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2d1c15eaa6b2e5c07888d4cc3cc6634d | Tree | Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can... | [
"n=int(input())\r\nw=[[] for i in range(n+1)]\r\nsz=[0]*(n+1)\r\np=[0]*(n+1)\r\nf=[[0]*(n+1) for i in range(n+1)]\r\ndef dfs(u,p):\r\n\tf[u][1]=sz[u]=1\r\n\tfor v in w[u]:\r\n\t\tif v!=p:\r\n\t\t\tdfs(v,u)\r\n\t\t\tfor j in range(sz[u],-1,-1):\r\n\t\t\t\tfor k in range(sz[v],-1,-1):\r\n\t\t\t\t\tf[u][j+k]=max(f[u][... | {"inputs": ["5\n1 2\n2 3\n3 4\n4 5", "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8", "3\n1 2\n1 3", "5\n3 2\n1 5\n4 5\n5 3", "5\n2 1\n3 4\n3 5\n5 2", "5\n1 4\n4 5\n4 3\n4 2", "5\n2 3\n3 4\n3 5\n3 1", "10\n4 8\n10 2\n6 3\n10 9\n2 3\n4 1\n7 10\n2 1\n5 1", "15\n4 6\n15 1\n3 8\n15 2\n13 11\n9 10\n14 4\n9 12\n11 6\n8 10\n4 5\n2 11\... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
2d40ef94f714e4d7728707c478647ad9 | Parliament of Berland | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chair... | [
"n, a, b = map(int, input().split())\nans = [[0] * b for _ in range(a)]\nif n > a * b:\n print(-1)\nelse:\n for i in range(n):\n ans[i // b][i % b] = i + 1\n for i in range(a):\n if b % 2 == 0 and i % 2 == 1:\n ans[i] = ans[i][1:] + [ans[i][0]]\n print(*ans[i])",
"n, a, b = (int(s) for s in input... | {"inputs": ["3 2 2", "8 4 3", "10 2 2", "1 1 1", "8 3 3", "1 1 100", "1 100 1", "12 4 3", "64 8 9", "13 2 6", "41 6 7", "9999 100 100", "10000 100 100", "2099 70 30", "2098 30 70", "10000 1 1", "1583 49 36", "4825 77 88", "26 1 33", "274 25 77", "694 49 22", "3585 77 62", "3 1 6", "352 25 59", "150 53 3", "4227 91 80",... | UNKNOWN | PYTHON3 | CODEFORCES | 86 | |
2d41028b2f20a6fa7a921b8da75abb0f | Constructing Tests | Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero.
Consider the following problem:
You are given two integers *n* and *m*. You have to construct an *m*-free square matrix of size *... | [
"def main():\r\n\tt = int(input())\r\n\tfor _ in range(t):\r\n\t\tnum = int(input())\r\n\t\tif num == 0:\r\n\t\t\tprint(1, 1)\r\n\t\telse:\r\n\t\t\tok = False\r\n\t\t\tdiv = 1\r\n\t\t\twhile div * div <= num:\r\n\t\t\t\tif num % div == 0:\r\n\t\t\t\t\tadd = max(num // div, div)\r\n\t\t\t\t\tsub = min(num // div, di... | {"inputs": ["3\n21\n0\n1", "1\n420441920", "1\n4", "1\n297540", "1\n9", "1\n144", "1\n16", "1\n25", "1\n999944", "1\n6", "1\n14", "1\n81", "1\n2", "1\n36", "1\n2925", "1\n5704", "1\n4104", "1\n1980", "1\n10", "1\n4860", "1\n2601", "1\n28", "1\n56"], "outputs": ["5 2\n1 1\n-1", "-1", "-1", "546 22", "-1", "-1", "-1", "-... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
2d4b95f543aaa58b6d6b05cdb200b4f4 | Alternating Sum | You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative ... | [
"def power(x, y):\r\n return pow(x, y, M)\r\ndef inv(y):\r\n return pow(y, M-2, M)\r\nn, a, b, k = map(int,input().split())\r\nM = 10**9 + 9\r\n\r\ns = [1 if c == \"+\" else -1 for c in input()]\r\n\r\n# Period k-1\r\nperiod = sum(s[i] * power(a, n-i) * power(b, i) for i in range(k))%M\r\n\r\n# Ratio (b/a)^k\... | {"inputs": ["2 2 3 3\n+-+", "4 1 5 1\n-", "1 1 4 2\n-+", "3 1 4 4\n+--+", "5 1 1 6\n++---+", "5 2 2 6\n+--++-", "686653196 115381398 884618610 3\n+-+", "608663287 430477711 172252358 8\n-+--+-+-", "904132655 827386249 118827660 334\n+++-+++++--+++----+-+-+-+-+--+-+---++--++--++--+-+-+++-+++--+-+-+----+-+-++++-----+--++... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
2d58be359632795d42ddf9dc59da7fee | MYSTERIOUS LANGUAGE | You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language.
This program has only one test, and it's empty (it doesn't give your program anything to read).
Outp... | [
"print(\"INTERCAL\");",
"print(\"INTERCAL\")\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1\n \t\t \t\t\t\t\t\t\t \t \t\t \t\t \t\t\t\t\t\t \t\t",
"print(\"INTERCAL\") ... | {"inputs": ["1"], "outputs": ["INTERCAL"]} | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
2d5b514c88c7afb88eed33428014607a | Efim and Strange Grade | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | [
"n,t = map(int,input().split())\r\nnum = input()\r\nidx = num.index(\".\")\r\ncnt=1\r\nfor i in range(idx+1,n):\r\n if num[i]<\"5\":\r\n if 5-int(num[i])==1:cnt+=1\r\n else:cnt=1\r\n if num[i]>=\"5\":\r\n j = min(cnt,t)\r\n if num[i-j]!=\".\":\r\n num = num[:i-j]+str(int... | {"inputs": ["6 1\n10.245", "6 2\n10.245", "3 100\n9.2", "12 5\n872.04488525", "35 8\n984227318.2031144444444444494637612", "320 142\n2704701300865535.43222331223343411413001111322010242013132301034414420112430314444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
2d6458ca956b28b24231b7eba658436d | z-sort | A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=><=1.
For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2... | [
"n = int(input())\na = [int(x) for x in input().split()]\na = sorted(a)\nsaida = []\nfor i in range(n):\n if i%2 == 0:\n saida.append(a[i//2])\n else:\n saida.append(a[n-1-i//2])\nprint(*saida)\n\t\t\t\t\t\t \t \t\t\t\t\t\t \t \t \t \t \t",
"n = int(input())\r\nxs = sorted([int(x) for x i... | {"inputs": ["4\n1 2 2 1", "5\n1 3 2 2 5", "1\n1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 9 7 6 2 4 7 8 1 3", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 3... | UNKNOWN | PYTHON3 | CODEFORCES | 185 | |
2d6ce72a85e606a5171c5872b40f1b6b | Image Preview | Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo *n*. Similarly, by swiping right from the last photo you reach photo 1. It takes *... | [
"read = lambda: map(int, input().split())\r\nper = lambda L, R: R - L - 1 + min(R - n - 1, n - L)\r\nn, a, b, T = read()\r\nf = [1 + (i == 'w') * b for i in input()] * 2\r\nL, R = 0, n\r\nans = 0\r\ncur = sum(f) // 2\r\nwhile L <= n and R < n * 2:\r\n cur += f[R]; R += 1\r\n while R - L > n or cur + per(L, R)... | {"inputs": ["4 2 3 10\nwwhw", "5 2 4 13\nhhwhh", "5 2 4 1000\nhhwhh", "3 1 100 10\nwhw", "10 2 3 32\nhhwwhwhwwh", "1 2 3 3\nw", "100 20 100 10202\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwww", "20 10 10 1\nhwhwhwhwhwhwhwhwhhhw", "12 10 10 1\nwhwhwhwhwhwh", "2 5 5... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2d807654d96829234b558af3cc2ac5d3 | Our Tanya is Crying Out Loud | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | [
"n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nres = 0\nwhile n!=1:\n\tif k==1 or k>n:\n\t\tres+=a*(n-1)\n\t\tbreak\n\tif n%k!=0:\n\t\tres+=a*(n%k)\n\t\tn = n-n%k\n\telse:\n\t\ttemp = n//k\n\t\tres+=min(b,a*(n-temp))\n\t\tn = temp\nprint(res)\n\t\t\t \t\t\t \t \t\t\t\t \t\t \t\t \... | {"inputs": ["9\n2\n3\n1", "5\n5\n2\n20", "19\n3\n4\n2", "1845999546\n999435865\n1234234\n2323423", "1604353664\n1604353665\n9993432\n1", "777888456\n1\n98\n43", "1162261467\n3\n1\n2000000000", "1000000000\n1999999999\n789987\n184569875", "2000000000\n2\n1\n2000000000", "1999888325\n3\n2\n2000000000", "1897546487\n687\n... | UNKNOWN | PYTHON3 | CODEFORCES | 69 | |
2dfa063f0f70a652c3e61aa500d3bd6d | none | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j... | [
"from heapq import *\n \nl=input()\nkill=int(input())\nn=len(l) \nif kill>n*(n+1)/2: \n print(\"No such line.\") \n quit()\nss=[(l[i],i) for i in range(n)]\nheapify(ss)\nwhile kill:\n kill-=1\n t=heappop(ss)\n if kill==0:\n print(t[0])\n else: \n if t[1]<n-1:\n heappush(ss... | {"inputs": ["aa\n2", "abc\n5", "abab\n7", "codeforces\n1", "cccc\n8", "abcdefghijklmnopqrstuvwxyz\n27", "cba\n6", "z\n100000", "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
2dfeeee0e26e0696e414b354a207adb8 | Polycarp's Pockets | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | [
"n= int(input())\r\na= list(map(int, input().split()))\r\n\r\nx= [a.count(i) for i in a]\r\nx.sort()\r\nprint(x[n-1])",
"n= int(input())\r\narr = list(map(int, input().split()))\r\na = []\r\nfor i in arr:\r\n a.append(arr.count(i))\r\nprint(max(a))",
"n = int(input())\r\na=[int(d) for d in input().split()]\r... | {"inputs": ["6\n1 2 4 3 3 2", "1\n100", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 10... | UNKNOWN | PYTHON3 | CODEFORCES | 468 | |
2e0e65d582aa86344f25fa47e856073f | Valued Keys | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | [
"x = [i for i in input()]\ny = [i for i in input()]\n\nz = []\n\npossible = True\n\nfor i in range(len(x)):\n if x[i] == y[i]:\n z.append('z')\n elif x[i] > y[i]:\n z.append(y[i])\n else:\n possible = False\n break\n\nif possible:\n print(\"\".join(z))\nelse:\n print(-1)\n... | {"inputs": ["ab\naa", "nzwzl\nniwel", "ab\nba", "r\nl", "d\ny", "yvowz\ncajav", "lwzjp\ninjit", "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccr... | UNKNOWN | PYTHON3 | CODEFORCES | 287 | |
2e1370625bc74674d7dc606d54188d02 | Almost Arithmetic Progression | Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $[3, 2, 1, 0]$ are arithmetic progressions, but $[1, 0, 1]$, $[1... | [
"n = int(input())\r\nsequence = list(map(int, input().split()))\r\nsequences = list()\r\nif(n < 3):\r\n print(0)\r\nelse:\r\n bigFlag = True\r\n minCount = float('inf')\r\n for i in [0,1,-1]:\r\n for j in [0,1,-1]:\r\n seq = sequence.copy()\r\n seq[0] = seq[0] + i\r\n ... | {"inputs": ["4\n24 21 14 10", "2\n500 500", "3\n14 5 1", "5\n1 3 6 9 12", "1\n1000000000", "2\n1000000000 1", "3\n34 70 52", "3\n1 2 1", "6\n1 1 3 5 6 5", "3\n2 1 2", "10\n9 5 3 4 7 1 2 8 10 6", "4\n20 15 20 15", "4\n10 21 14 24", "3\n5 9 5", "10\n10 9 8 7 6 1 2 3 4 5", "4\n2 6 3 1", "5\n1 3 6 8 10", "4\n1 3 1 3", "3\n... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
2e3e8778fe44cc6b2615f3f2a5de5634 | Roma and Poker | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than *k* virtual bou... | [
"N,k=list(map(int,input().strip().split(' ')))\r\nS=input()\r\n# num of W-num of L=j, j>k means k-j\r\ndp=[[0 for j in range(2*k+1)]for i in range(N)]\r\n#print(dp) \r\nfor i in range(len(S)):\r\n if i==0:\r\n if S[0]=='W':\r\n dp[0][1]='W'\r\n elif S[0]=='L':\r\n dp[0][-1]='L... | {"inputs": ["3 2\nL??", "3 1\nW??", "20 5\n?LLLLLWWWWW?????????", "5 5\n?WDDD", "5 3\n??D??", "10 1\nD??W?WL?DW", "10 3\nDWD?DL??LL", "10 2\nLWL?WWDDW?", "1 1\n?"], "outputs": ["LDL", "NO", "WLLLLLWWWWWWWWLWLWDW", "NO", "WWDDW", "NO", "DWDWDLLLLL", "NO", "W"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
2e858831c5d5ca3e65edb181f56bc650 | Ancient Prophesy | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha... | [
"import sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush\r\nfrom math import *\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\nfrom itertools import combinations as comb, permutations as perm\r\nfrom bisect import bisect_left as bl, bisec... | {"inputs": ["777-444---21-12-2013-12-2013-12-2013---444-777", "30-12-201429-15-208830-12-2014", "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013", "15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014", "19-07-201419-07-2014... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
2ed4f6b0ea75c25b51bae97215bfef0b | none | A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print th... | [
"l,r=map(int,input().split())\r\nans=0\r\nfor i in range(31):\r\n for j in range(20):\r\n if l <= 2**i * 3**j <= r:\r\n ans+=1\r\nprint(ans)\r\n",
"def rec(x):\r\n s=0\r\n t=1\r\n u=1\r\n while(x>=(2**t)):\r\n s+=1\r\n t+=1\r\n while(x>=(3**u)):\r\n s+=1\r\n u+=1\r\n t=1\r\n u=1\r\n while... | {"inputs": ["1 10", "100 200", "1 2000000000", "1088391168 1934917632", "1088391167 1934917632", "1088391169 1934917632", "1088391168 1934917631", "1088391168 1934917633", "4 134217728", "209952 43046722", "25165825 43046719", "5183 25165825", "388645 455910", "472069 972050", "1 1", "2 2", "12 1999999931", "1999999999... | UNKNOWN | PYTHON3 | CODEFORCES | 169 | |
2ed76b685dc12befd8dabe6097fb961b | Sheldon and Ice Pieces | Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to... | [
"# https://codeforces.com/problemset/problem/328/B\n\nfrom collections import Counter\n\nt = Counter(input().replace('6', '9').replace('2', '5'))\ndigits = Counter(input().replace('6', '9').replace('2', '5'))\nprint(min(digits[d] // cnt for d, cnt in t.items()))",
"import sys\n\n\nt = int(sys.stdin.readline().str... | {"inputs": ["42\n23454", "169\n12118999", "1\n1", "7\n777", "18\n8118", "33\n33333333", "1780\n8170880870810081711018110878070777078711", "2\n5255", "5\n22252", "9\n666969", "6\n9669969", "25\n52", "2591\n5291", "9697\n979966799976", "5518\n22882121", "533\n355233333332", "2569\n9592525295556669222269569596622566529699... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
2ed9ecb5353cf9c74167e9d3a4305f94 | Bear and String Distance | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of di... | [
"n, k = map(int, input().split())\r\ns = input()\r\nans = ''\r\nfor j in range(n):\r\n a = ord(s[j]) - 97\r\n z = 25 - a\r\n if a > z:\r\n v = min(a, k)\r\n ans += chr(ord(s[j]) - v)\r\n k -= v\r\n else:\r\n v = min(z, k)\r\n ans += chr(ord(s[j]) + v)\r\n k -= v... | {"inputs": ["4 26\nbear", "2 7\naf", "3 1000\nhey", "5 50\nkzsij", "5 500\nvsdxg", "1 0\na", "1 1\ng", "1 25\nr", "1 15\no", "10 100\naddaiyssyp", "50 100\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb", "2 1\nzz", "8 8\nabcdefgh", "1 25\nz", "1 24\nz", "1 24\ny", "2 49\nzz", "1 26\na", "1 25\na", "4 17\nrzsq", "6... | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
2edeeac50e31bc716f0e02afb027d0d3 | Days of Floral Colours | The Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.
On the rim of the Floral Clock are 2*n* flowers, numbered from 1 to 2*n* clockwise, each of which has a colour among all *n* possible ones. For each colou... | [
"f = [0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1]\r\njly = 998244353\r\nt = 0\r\nx = [0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404]\r\nn = int(input())\r\nfor i in range(16, n + 1):\r\n t = 0\r\n for j in range(0, 16):\r\n t = (t + f[(i... | {"inputs": ["3", "4", "7", "15", "10", "99", "1317", "50000", "5", "6", "8", "9", "11", "12", "13", "14", "16", "17", "18", "19", "20", "33", "39", "89", "144", "233", "396", "418", "431", "831", "985", "998", "1000", "2017", "3939", "5000", "8081", "10000", "10001", "10492", "20178", "23333", "25252", "30000", "35000"... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2f2d711ae79c779f5d447f7d9a907eb7 | Kefa and First Steps | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | [
"n=int(input())\r\nr=input()\r\ns=r.split(\" \")\r\na=[]\r\nfor i in s:\r\n a.append(int(i))\r\ni=0;maxi=1;num=1\r\nwhile i<n-1:\r\n if a[i]<=a[i+1]:\r\n num+=1\r\n if num>maxi:\r\n maxi=num\r\n else:\r\n num=1\r\n i+=1\r\nprint(maxi)",
"n=int(input())\r\na1=list(map(in... | {"inputs": ["6\n2 2 1 3 4 1", "3\n2 2 9", "5\n10 100 111 1 2", "10\n1 2 3 4 1 2 3 4 5 6", "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | UNKNOWN | PYTHON3 | CODEFORCES | 250 | |
2f3f7b94851f56f96e4ed58c3ab91d6f | Greg's Workout | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | [
"n = int(input())\r\n\r\nl_n = list(map(int, input().split()))\r\na_t = [0]*3\r\n\r\nfor i in range(n):\r\n a_t[i % 3] += l_n[i]\r\n\r\nif a_t[0] > a_t[1] and a_t[0] > a_t[2]:\r\n print(\"chest\")\r\nelif a_t[1] > a_t[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"total = [0,0,0]\nn = int(i... | {"inputs": ["2\n2 8", "3\n5 1 10", "7\n3 3 2 7 9 6 8", "4\n5 6 6 2", "5\n8 2 2 6 3", "6\n8 7 2 5 3 4", "8\n7 2 9 10 3 8 10 6", "9\n5 4 2 3 4 4 5 2 2", "10\n4 9 8 5 3 8 8 10 4 2", "11\n10 9 7 6 1 3 9 7 1 3 5", "12\n24 22 6 16 5 21 1 7 2 19 24 5", "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "14\n13 14 19 8 5 17 9 16 15 9 5 6... | UNKNOWN | PYTHON3 | CODEFORCES | 802 | |
2f7db9cb6c84ba4b95dc8cedb622e240 | Fox and Number Game | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | [
"import fractions\n\n\nN = int(input())\nX = list(map(int, input().split()))\nnow = fractions.gcd(X[0], X[1])\nfor i in range(2, N):\n now = fractions.gcd(now, X[i])\n\nans = now * N\nprint(ans)\n",
"import math\r\n\r\nn = int(input())\r\narr = list(map(int, input().strip().split()))\r\nans = arr[0]\r\nfor i i... | {"inputs": ["2\n1 2", "3\n2 4 6", "2\n12 18", "5\n45 12 27 30 18", "2\n1 1", "2\n100 100", "2\n87 58", "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52", "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 9... | UNKNOWN | PYTHON3 | CODEFORCES | 315 | |
2f824162334d023d3a67d940eb317f6c | Anton and Classes | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has *n* variants when he will attend chess classes, *i*-th variant is given by a period of time (*l*1,<=*i*,<=*r*1,<=*i*). Also he has *m* variants when he will attend programmin... | [
"# full logic before coding\r\n\r\n# test_cases = int(input())\r\n\r\n# for test_case in range(test_cases):\r\nn = int(input())\r\nmax_l1 = 0\r\nmin_r1 = 10**9 + 1\r\nfor i in range(n):\r\n l1, r1 = map(int, input().split())\r\n if l1 > max_l1:\r\n max_l1 = l1\r\n if r1 < min_r1:\r\n min_r1 =... | {"inputs": ["3\n1 5\n2 6\n2 3\n2\n2 4\n6 8", "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4", "20\n13 141\n57 144\n82 124\n16 23\n18 44\n64 65\n117 133\n84 117\n77 142\n40 119\n105 120\n71 92\n5 142\n48 132\n106 121\n5 80\n45 92\n66 81\n7 93\n27 71\n3\n75 96\n127 140\n54 74", "10\n16 16\n20 20\n13 13\n31 31\n42 42\n70 70\n64 64\n63 63... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
2fcaec95ca0fe52784f2e76a62c1e938 | Soldier and Bananas | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The f... | [
"k,n,w=map(int,input().split())\r\ntotal = k*(w*(w+1) // 2)\r\nborrow=max(0,total - n)\r\nprint(borrow)",
"k, n, w = (int(i) for i in input().split())\r\nsum = 0\r\nfor i in range(w):sum += (i+1)*k\r\nprint(sum - n if sum >= n else 0)",
"\r\nk,n,w = map(int, input().split())\r\n\r\ncost = 0\r\nfor i in range(1,... | {"inputs": ["3 17 4", "1 2 1", "1 1 1", "1 5 6", "1 1000000000 1", "1000 0 1000", "859 453892 543", "1000 1000000000 1000", "1000 500500000 1000", "1000 500500001 1000", "1000 500499999 1000", "634 87973 214", "432 10000 241", "111 111111111 111", "20 43 3"], "outputs": ["13", "0", "0", "16", "0", "500500000", "1264169... | UNKNOWN | PYTHON3 | CODEFORCES | 620 | |
2ff5a19d85e28f8e54918a2087001c0c | Space mines | Once upon a time in the galaxy of far, far away...
Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.
When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — sp... | [
"import sys, math\r\ndef dist(a,b):\r\n return pow((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2,0.5)\r\n\r\ndef vxv(v1,v2):\r\n x = -v1[2] * v2[1] + v1[1] * v2[2]\r\n y = -v1[0] * v2[2] + v1[2] * v2[0]\r\n z = -v1[1] * v2[0] + v1[0] * v2[1]\r\n return (x,y,z)\r\nreadline = sys.stdin.readlin... | {"inputs": ["0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0", "8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0", "30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0", "100 99 30 -1 -5 -3 100\n1\n100 -90 -50 5 4\n0 6 0\n7 0 0\n6 1 1\n0 -6 -1", "0 0 0 5 5 5 20\n1\n-20 0 -30 10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
301e737070363b274b194f0490596d1d | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's orde... | [
"number = int(input().split()[0])\r\n#orders = int(input())\r\narray = input().split()\r\n\r\nsum = 0\r\n\r\nfor i in range(0,number):\r\n items = input().split()\r\n for j in items:\r\n buffer = []\r\n sum = sum + int(array.index(j)) +1\r\n buffer.append(j) \r\n array.remove(j)\r\... | {"inputs": ["2 2 5\n3 4 1 2 5\n1 5\n3 1", "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3", "1 1 1\n1\n1", "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99 65 20 52 35 85 16 12 94 100 59 56 18 33 47 46 71 8 38 57 2 92 3 95 6 4 87 22 48 80 15 29 11 45 72 76 44 60 91 90 39 74 41 36... | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
30494f7ac1c5ba89c23a40068f7d26fe | Exams | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a st... | [
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n a, b= map(int, input().split())\r\n l.append([a,b])\r\nl.sort()\r\nprev=0\r\nfor a, b in l:\r\n if b>= prev:\r\n prev=b\r\n else:\r\n prev=a\r\nprint(prev)",
"d = {}\r\nfor i in range(int(input())):\r\n t = [int(i) for i in input().spl... | {"inputs": ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3", "1\n1000000000 999999999", "1\n2 1", "2\n3 2\n3 2", "5\n4 3\n4 2\n4 1\n4 1\n4 1", "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1", "2\n3 1\n3 2", "2\n4 2\n4 1", "2\n5 2\n5 1", "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4", "3\n3 2\n4 1\n100 10", "3\n4 3\n5 2\n10 8", "5\n6 5\n6 4\n6 3\n6 2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
308f31764bb3b87376289f22975af96f | Amr and Pins | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | [
"from math import *\r\nr,x,y,a,b=map(int,input().split())\r\nprint(ceil((((x-a)**2+(y-b)**2)**0.5)/(r*2)))\r\n",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nprint(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))\r\n",
"import math\r\nr, x, y, nx, ny = map(int,input().split())\r\nstep = 2*r\... | {"inputs": ["2 0 0 0 4", "1 1 1 4 4", "4 5 6 5 6", "10 20 0 40 0", "9 20 0 40 0", "5 -1 -6 -5 1", "99125 26876 -21414 14176 17443", "8066 7339 19155 -90534 -60666", "100000 -100000 -100000 100000 100000", "10 20 0 41 0", "25 -64 -6 -56 64", "125 455 450 439 721", "5 6 3 7 2", "24 130 14786 3147 2140", "125 -363 176 93 ... | UNKNOWN | PYTHON3 | CODEFORCES | 469 | |
309df1bdd3f15ef54a7d1d973fe42330 | Fence | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | [
"from sys import stdin, stdout\n\n\ndef input():\n return stdin.readline().strip()\n\n\ndef print(string):\n return stdout.write(str(string) + \"\\n\")\n\n\ndef main():\n n, k = map(int, input().split())\n h = [int(x) for x in input().split()]\n dp = [None] * n\n dp[0] = sum(h[:k])\n smallest_i... | {"inputs": ["7 3\n1 2 6 1 1 7 1", "1 1\n100", "2 1\n10 20", "10 5\n1 2 3 1 2 2 3 1 4 5", "10 2\n3 1 4 1 4 6 2 1 4 6", "2 2\n20 10", "2 1\n20 1", "3 1\n1 2 3", "3 1\n2 1 3", "3 1\n3 2 1", "3 2\n1 2 3", "3 2\n3 2 1", "3 3\n1 2 3", "4 2\n9 8 11 7", "4 2\n10 1 2 3", "6 3\n56 56 56 2 1 2", "8 3\n1 1 1 1 2 60 90 1", "4 1\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 209 | |
30a248252fde97fb2547f74417918dcc | The Big Race | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | [
"def gcd(a, b):\r\n if (b == 0):\r\n return a\r\n return gcd(b, a % b)\r\n\r\n\r\ns = input()\r\ns = s.split()\r\nt = int(s[0])\r\nw = int(s[1])\r\nb = int(s[2])\r\ng = gcd(w, b)\r\nw = w // g\r\nr = w * b\r\nw = w * g\r\nk = (t // r) + 1\r\nans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w,... | {"inputs": ["10 3 2", "7 1 2", "1 1 1", "5814 31 7", "94268 813 766", "262610 5583 4717", "3898439 96326 71937", "257593781689876390 32561717 4411677", "111319886766128339 7862842484895022 3003994959686829", "413850294331656955 570110918058849723 409853735661743839", "3000000000000000000 2999999999999999873 29999999999... | UNKNOWN | PYTHON3 | CODEFORCES | 146 | |
30b0da6da608e9e1c0bcfb1c6a77658e | Xenia and Tree | Xenia the programmer has a tree consisting of *n* nodes. We will consider the tree nodes indexed from 1 to *n*. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.
The distance between two tree nodes *v* and *u* is the number of edges in the shortest path between... | [
"class CentroidDecomposition():\r\n def __init__(self, g):\r\n self.g = g\r\n self.n = len(g)\r\n\r\n self.parent = [-1]*self.n\r\n self.size = [1]*self.n\r\n self.cdparent = [-1]*self.n\r\n self.cddepth = [0]*self.n\r\n self.cdorder = [-1]*self.n\r\n self.... | {"inputs": ["5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5"], "outputs": ["0\n3\n2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
30cbb8e50f856c890357da22cf574c69 | Cyclic Components | You are given an undirected graph consisting of $n$ vertices and $m$ edges. Your task is to find the number of connected components which are cycles.
Here are some definitions of graph theory.
An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of verti... | [
"n, m = map(int, input().split())\r\ngrafo = [[] for i in range(n + 1)]\r\n\r\nfor i in range(m):\r\n v_i, u_i = map(int, input().split())\r\n grafo[v_i].append(u_i)\r\n grafo[u_i].append(v_i)\r\n\r\nconjunto = set(i for i in range(n + 1) if len(grafo[i]) == 2)\r\n\r\nres = 0\r\nwhile conjunto:\r\n i = ... | {"inputs": ["5 4\n1 2\n3 4\n5 4\n3 5", "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6", "4 4\n1 2\n2 3\n1 3\n1 4", "5 5\n1 2\n2 3\n3 4\n4 1\n3 5", "200000 0", "1 0", "5 10\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n2 4\n3 5\n3 1\n2 5", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
30db901d2974d16a3492d3335b4eb28f | Collective Mindsets (medium) | Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The ... | [
"n = int(input())\r\nif n & 1:\r\n print(n//2)\r\nelse:\r\n k = 1\r\n while k <= n:\r\n k *= 2\r\n print((n - k//2)//2)\r\n",
"import math \r\na = int(input())\r\nif a%2==1:\r\n print(math.ceil((a-1)/2))\r\nelse:\r\n z = 1\r\n while z*2<=a:\r\n z*=2\r\n print((a-z)//2)",
"f... | {"inputs": ["1", "3", "2", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "99", "100", "9999", "21736", "873467", "4124980", "536870910", "536870912", "876543210", "987654321", "1000000000"], "outputs": ["0", "1", "0", "0", "2", "1", "3", "0", "4", "1", "5", "2", "6", "3... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
30de59f08fe3576a3c3ef0138a341c0f | Gabriel and Caterpillar | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when ... | [
"def solve(h1, h2, a, b):\r\n d = max(h2 - a * 8 - h1, 0)\r\n if d and a <= b:\r\n return -1\r\n x = max(1, (a - b) * 12)\r\n return (d + x - 1) // x\r\n\r\n\r\nh1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nprint(solve(h1, h2, a, b))\r\n",
"h1, h2 = map(int, input().... | {"inputs": ["10 30\n2 1", "10 13\n1 1", "10 19\n1 2", "1 50\n5 4", "1 1000\n2 1", "999 1000\n1 1", "999 1000\n1 1000", "1 1000\n999 1", "1 1000\n100 99", "500 509\n1 1", "500 555\n6 1", "1 100000\n2 1", "99990 100000\n1 1", "90000 100000\n2 1", "10 100000\n1 100000", "1 41\n5 6", "1 100000\n1 100000", "1 9\n1 1", "8 16... | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
30de7ee740a6e995d73e72689e102fa6 | Four Melodies | Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, and recently she had recorded two tracks that became very popular. Now she has got a lot of fans who are waiting for new tracks.
This t... | [
"import heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef add_edge(u, v, cost, f):\r\n G[u].append([v, cost, f, len(R[v])])\r\n R[v].append([u, -cost, 0, len(G[u]) - 1])\r\n\r\ndef dijkstra(s):\r\n inf = pow(10, 9) + 1\r\n dist = [inf] * l\r\n dist... | {"inputs": ["5\n1 3 5 7 9", "5\n1 3 5 7 2", "4\n1 3 5 7", "4\n1 1 1 1", "4\n1 1 2 1", "4\n3 2 3 1", "4\n3 4 2 2", "4\n5 3 4 3", "4\n5 3 1 4", "4\n3 5 2 4", "4\n8 6 8 1", "4\n6 3 6 4", "5\n8 1 4 8 2", "6\n2 7 8 6 5 7", "7\n9 12 12 1 8 12 12", "8\n16 1 8 13 14 5 4 4", "9\n5 4 10 10 13 17 15 15 12", "10\n19 18 20 1 7 1 3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
30f04343d73228a109494c7b3fd6aa52 | Maximum Increase | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains s... | [
"n = int (input())\r\ncurrent = 1\r\nmax = 1\r\n\r\nx = list(map(int,input().split()))\r\nfor i in range(n-1): # 0 1 2 3 4 \r\n if x[i+1] > x[i]: # 1 7 2 11 15\r\n current = current +1\r\n else:\r\n current=1\r\n\r\n if max<current:max=current\r\n\r\n\r\nprint (max)",
"from sys import s... | {"inputs": ["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3", "1\n1000000000", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754", "2\n2 1", "5\n1 2 3 3 4", "4\n1 2 2 3", "3\n2 1 1", "3\n1 2 1", "1\n1", "2\n1 2", "3\n1 1 2", "11\n1 2 3 1 2 3 2 1 2 3 4", "9\... | UNKNOWN | PYTHON3 | CODEFORCES | 389 | |
310156f005df4f13b9a0d5cafd315f04 | Andryusha and Colored Balloons | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a c... | [
"import sys\r\ninput = sys.stdin.readline\r\ndef dfs():\r\n stack = [(0,0)]\r\n d[0].append(1)\r\n while stack:\r\n i,p = stack.pop()\r\n c = 1\r\n for j in d[i]:\r\n if j != p:\r\n stack.append((j,i))\r\n while c in {color[i],color[p]}:\r\n ... | {"inputs": ["3\n2 3\n1 3", "5\n2 3\n5 3\n4 3\n1 3", "5\n2 1\n3 2\n4 3\n5 4", "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2", "3\n2 1\n3 2", "10\n2 7\n8 2\n9 8\n1 9\n4 1\n3 4\n6 3\n10 6\n5 10", "5\n4 2\n3 1\n3 4\n3 5", "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7", "10\n8 6\n10 5\n8 4\n2 7\n3 8\n10 3\n3 9\n2 1\n3 2", "50\n45 2\... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
3109c0e4b05b3087bcfdcb8b1ca095d3 | Heidi and Library (medium) | Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Same as the easy version, but the limits have changed: 1<=≤<=*n*,<=*k*<=≤<=400<=000.
Same as the easy version.
Sample Input
4 100
1 2 2 1
4 1... | [
"# https://codeforces.com/problemset/problem/802/B\r\nimport heapq\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nd = {}\r\npos = {}\r\nQ = []\r\ncnt = 0\r\n\r\nfor i, x in enumerate(a):\r\n if x not in pos:\r\n pos[x] = []\r\n pos[x].append(i)\r\n ... | {"inputs": ["4 100\n1 2 2 1", "4 1\n1 2 2 1", "4 2\n1 2 3 1", "11 1\n1 2 3 5 1 10 10 1 1 3 5", "5 2\n1 2 3 1 2", "4 2\n1 2 3 2", "1 1\n1"], "outputs": ["2", "3", "3", "9", "4", "3", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
311321b9f47985d2496064b27ba62fd1 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | [
"n,m=map(int,input().split())\r\nfor i in range(n):\r\n k=input()\r\nf=1\r\nans=0\r\nfor i in k:\r\n if i=='B' and f:\r\n ans+=1\r\n f=0\r\n if i=='.':\r\n f=1\r\nprint(ans)",
"y, x = [int(each) for each in input().split(\" \")]\nfor _ in range(y-1):\n input()\nsegments = 0\nprev_... | {"inputs": ["3 7\n.......\n.......\n.BB.B..", "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "1 1\nB", "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.", "8 8\n........\n........\n........\n........\n.B......\n.B.....B\n.B.....B\n.BB...BB"], "out... | UNKNOWN | PYTHON3 | CODEFORCES | 37 | |
311a06f18b45f0869a1d65aeb21bc2eb | Mausoleum | King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructed from 2*n* blocks, each of them has the shape of a cuboid. Each block has ... | [
"N, K = map(int, input().split())\r\nrel = [[0] * 75 for _ in range(75)]\r\ndp = [[-1] * 40 for _ in range(75)]\r\nsign = [\"=\", \"<\", \">\", \"<=\", \">=\"]\r\nrev = [0, 2, 1, 4, 3]\r\nrs = [[] for _ in range(75)]\r\ndef solve(st, pos):\r\n if pos >= N:\r\n if rel[st][st + 1] == 1 or rel[st][st + 1] ==... | {"inputs": ["3 0", "3 1\n2 > 3", "4 1\n3 = 6", "5 2\n1 < 2\n9 > 10", "35 0", "10 5\n17 <= 10\n16 >= 18\n9 > 18\n8 = 8\n6 >= 13", "5 2\n1 = 10\n2 = 9", "3 3\n1 = 2\n3 = 4\n5 = 6", "4 3\n2 > 3\n4 > 5\n6 > 7", "1 1\n1 > 2", "1 1\n1 <= 2", "5 3\n2 > 10\n4 > 8\n3 = 6", "5 3\n2 <= 4\n6 <= 7\n5 > 6", "8 5\n2 <= 4\n5 > 10\n3 <... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
313572d7684606e9ef8c0c75910331c7 | Wet Shark and Odd and Even | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the inpu... | [
"def isOdd (x):\r\n\treturn x%2==1\r\ndef isEven (x):\r\n\treturn x%2==0\r\ninput()\r\narr = [int(z) for z in input().split()]\r\noddA = list(filter(isOdd,arr))\r\noddA.sort()\r\nevenSum = sum(filter(isEven,arr))\r\nif(isOdd(len(oddA))):\r\n\tprint(evenSum+sum(oddA[1:]))\r\nelse:\r\n\tprint(evenSum+sum(oddA))\r\n\r... | {"inputs": ["3\n1 2 3", "5\n999999999 999999999 999999999 999999999 999999999", "1\n1", "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "15\n39 21 95 89 73 90 9 55 8... | UNKNOWN | PYTHON3 | CODEFORCES | 423 | |
315d11810d627ff4e0a6a72ba8f9720f | New Year Letter | Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
... | [
"def solve(k, x, m, n):\r\n for l1, r1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:\r\n for l2, r2 in [(0, 0), (0, 1), (1, 0), (1, 1)]:\r\n for a1 in range((m - l1 - r1) // 2 + 1):\r\n for a2 in range((n - l2 - r2) // 2 + 1):\r\n ta1, ta2, tl1, tl2, tr1, tr2 = a1, a2, ... | {"inputs": ["3 2 2 2", "3 3 2 2", "3 0 2 2", "4 3 2 1", "4 2 2 1", "3 0 1 1", "50 0 100 100", "50 1 100 100", "4 32 23 32", "5 45 23 32", "6 54 23 32", "7 120 23 32", "8 664 100 100", "8 661 100 99", "8 704 99 100", "10 189 44 100", "3 1 1 6", "3 1 6 1", "50 1000000000 100 100", "6 4 3 2", "5 4 3 2", "3 3 3 3", "48 512... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
315da27429573e9d68899fd06513f3c6 | Equator | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | [
"\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\nimport sys\r\n\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\nimport math\r\n\r\n\r\nn=int(input())\r\n\r\na=list(map(int,input().split()))\r\nss=sum(a);\r\n\r\ns=0\r\nfor i in range(n):\r\n s+=a[i]\r\n\r\n if(2*s>=... | {"inputs": ["4\n1 3 2 1", "6\n2 2 2 2 2 2", "1\n10000", "3\n2 1 1", "2\n1 3", "4\n2 1 1 3", "3\n1 1 3", "3\n1 1 1", "2\n1 2", "3\n2 1 2", "5\n1 2 4 3 5", "5\n2 2 2 4 3", "4\n1 2 3 1", "6\n7 3 10 7 3 11", "2\n3 4", "5\n1 1 1 1 1", "4\n1 3 2 3", "2\n2 3", "3\n32 10 23", "7\n1 1 1 1 1 1 1", "3\n1 2 4", "6\n3 3 3 2 4 4", "... | UNKNOWN | PYTHON3 | CODEFORCES | 255 | |
316f0e162d83207ee04cbb016580e7bf | Code obfuscation | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | [
"import string\n\nobf = [x for x in input()]\nobf = [x for i, x in enumerate(obf) if x not in obf[:i]]\nn = len(obf)\n\nletters = list(string.ascii_lowercase)\nletters = letters[:n]\n\nif obf == letters:\n\tprint('Yes')\nelse:\n\tprint('No')\n\n",
"alphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nprogramm = input()\r\n... | {"inputs": ["abacaba", "jinotega", "aaaaaaaaaaa", "aba", "bab", "a", "abcdefghijklmnopqrstuvwxyz", "fihyxmbnzq", "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | UNKNOWN | PYTHON3 | CODEFORCES | 115 | |
3180e2f8457950e4376b77f29145be1f | none | Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of *n* vertices and *m* edges. Vertices are numbered from 1 to *n*. Vertices 1 and *n* being the source and the sink respectively.
Howe... | [
"import sys\n\nONLINE_JUDGE = True\n\nif not ONLINE_JUDGE:\n sys.stdin = open(\"input.text\", \"r\")\n\n############ ---- Input Functions ---- ############\n\n\ndef inp(): # integer\n return int(input())\n\n\ndef inlt(): # lists\n return list(map(int, input().split()))\n\n\ndef insr(): # list of charact... | {"inputs": ["3 3\n3 2 10\n1 2 10\n3 1 5", "4 5\n1 2 10\n1 3 10\n2 3 5\n4 2 15\n3 4 5", "10 17\n8 1 1\n4 8 2\n7 10 8\n1 4 1\n5 4 3\n6 9 6\n3 5 4\n1 9 1\n3 9 5\n7 1 1\n1 2 1\n1 3 1\n6 7 7\n8 2 1\n1 10 1\n1 5 1\n6 1 1", "10 20\n3 8 41\n1 2 21\n9 1 31\n1 3 53\n5 9 67\n10 1 8\n6 1 16\n5 2 21\n1 7 50\n5 4 38\n6 4 16\n4 8 16\... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
318a48f1fb2864089f31d5bec97f167e | DZY Loves Physics | DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:
Once DZY got a graph *G*, now he wants to find a connected induced subgraph *G*' of the graph, such that the den... | [
"n,m = [int(x) for x in input().split()]\r\n\r\nl = [int(x) for x in input().split()]\r\n\r\nx = 0;\r\nfor i in range(m):\r\n a,b,c = [int(x) for x in input().split()]\r\n cur = (l[a-1]+l[b-1])/c\r\n #print(a,b,c,cur)\r\n if cur > x: x = cur\r\nprint(\"%0.15f\"%x)\r\n",
"a = input().split(' ')\r\nn = ... | {"inputs": ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63", "1 0\n734135", "10 10\n132402 148489 472187 403302 657890 205188 750668 276911 372190 828796\n8 10 162\n1 8 489\n6 7 279\n1 10 740\n5 6 721\n3 6 862\n2 3 194\n7 10 601\n2 10 658\n1 5 930", "20 20\n265918 7442... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
31b2068c4127a3a6df25dd29749cbb94 | Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing *n* characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not lik... | [
"# /*******************************************************************************\r\n# * Author : Quantum Of Excellence\r\n# * email : quantumofexcellence (at) gmail (dot) com\r\n# * copyright : 2014 - 2015\r\n# * date : 6 - 11 - 2015\r\n# * Judge Status : \r\n# * Problem Category : \r\n# ... | {"inputs": ["25\nHello. I am a little walrus.", "2\nHow are you?", "19\nHello! Do you like fish? Why?", "4\na. A.", "191\nEvx vnxZtUSgtzH yDNXCsTaxCKQus gVZLHppOplkGGekIK xbme. krbusMqUs YEnBBTJpjNicZPlx TqEtBPcbejZMzvn fFTub CHYWLmiOFkDdzR! LoQmXPfHJ KVnfrbrFooVSkj xwAZwrRr DdILZ kpco cLoRmJbVKhnbOEhnHKpci. PgYhxFPXdl... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
31d742885e0896f01ad4f25eb86abb43 | Magic Odd Square | Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both ma... | [
"n = int(input())\r\nc, o, e = n // 2, 1, 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if abs(i - c) + abs(j - c) <= c:\r\n print(o, end=\" \")\r\n o += 2\r\n else:\r\n print(e, end=\" \")\r\n e += 2\r\n print(\"\")\r\n",
"import bisect\r\nimpo... | {"inputs": ["1", "3", "5", "7", "9", "11", "13", "15", "17", "19", "21", "23", "25", "27", "29", "31", "33", "35", "37", "39", "41", "43", "45", "47", "49"], "outputs": ["1", "2 1 4\n3 5 7\n6 9 8", "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24", "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 1... | UNKNOWN | PYTHON3 | CODEFORCES | 52 | |
31f82a93c86ffaf724da238d322c7f70 | Periodical Numbers | A non-empty string *s* is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string *s* from 1 to the string's length and let's denote the *i*-th character in string *s* as *s**i*.
Binary string *s* with length *n* is periodical, if there is an integer 1<=≤<=*k*<=<<=... | [
"from itertools import combinations\r\nfrom fractions import gcd\r\n\r\n#Numeros primos hasta el 59\r\nprimos = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59]\r\n\r\n#Para obtener la cadena binaria de x.\r\ndef ToBinary(x):\r\n if x == 0:\r\n return \"0\"\r\n if x == 1:\r\n return \"1\"\r\n ... | {"inputs": ["1 10", "25 38", "7 9", "12 20", "7 49", "28 97", "65 72", "49 116", "883 947", "1 1000000000000000000", "6967967 165556564", "74 99", "883 947", "3165 7131", "31958 81314", "134285 645597", "7404389 8927556", "29906716 35911991", "168183636 812682195", "856218974 3052460231", "29374454626 62592774235", "28... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
32006bbd8168b03e94f8db7f3234053e | Nested Segments | You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of segments on a line.
Each of the next *n* lines contains two integers *l**i* and *r**i* (<=... | [
"'''\r\nDescripttion: your project\r\nversion: 1.0\r\nAuthor: ElysiaRealme\r\nDate: 2023-10-23 16:56:58\r\nLastEditors: ElysiaRealme\r\nLanguage: Python\r\n'''\r\nfrom io import BytesIO, IOBase\r\nimport sys\r\nimport os\r\n\r\n# import time\r\nimport bisect\r\n# import functools\r\nimport math\r\nimport random\r\n... | {"inputs": ["4\n1 8\n2 3\n4 7\n5 6", "3\n3 4\n1 5\n2 6", "1\n-1000000000 1000000000", "2\n-1000000000 999999999\n-999999999 1000000000", "2\n-1000000000 1000000000\n-999999999 999999999", "3\n-999999997 999999997\n-999999998 999999998\n-999999999 999999999", "3\n-999999999 999999997\n-999999998 999999998\n-999999997 99... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
3204a88d5f3940fd5744f4629c906e37 | Land Lot | Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving ... | [
"\r\ndef calcTrees(cont, startRow, startCol, a, b):\r\n trees = 0\r\n for i in range(a):\r\n for j in range(b):\r\n if cont[startRow + i][startCol + j] == 1:\r\n trees += 1\r\n return trees\r\n\r\n\r\n\r\nn, m = list(map(int, input().split(' ')))\r\ncont = []\r\nfor i in ra... | {"inputs": ["2 2\n1 0\n1 1\n1 1", "4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3", "3 3\n0 0 0\n0 0 0\n0 0 0\n1 2", "3 3\n1 1 1\n1 1 1\n1 1 1\n2 1", "3 2\n1 1\n1 1\n1 0\n2 1", "2 3\n1 0 1\n0 1 0\n3 2", "1 1\n0\n1 1", "1 1\n1\n1 1", "3 4\n1 0 1 0\n0 1 0 1\n1 0 1 0\n2 2", "3 4\n1 1 1 1\n1 0 0 1\n1 1 1 1\n3 1", "10... | UNKNOWN | PYTHON3 | CODEFORCES | 32 | |
322ce5c93133c4b042488dad39f21d9a | Magnets | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | [
"n=int(input())\r\nm_o=[input() for _ in range(n)]\r\ngrp=1\r\nfor i in range(1,n):\r\n if m_o[i]!=m_o[i-1]:\r\n grp+=1\r\nprint(grp)\r\n \r\n ",
"def count_groups(n, magnets):\r\n groups = 1\r\n for i in range(1, n):\r\n if magnets[i] != magnets[i-1]:\r\n groups += 1\r\n ... | {"inputs": ["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10", "1\n10", "2\n01\n10", "2\n10\n10", "3\n10\n01\n10", "1\n01", "2\n01\n01", "2\n10\n01", "3\n01\n01\n01", "3\n10\n10\n01", "3\n01\n10\n10", "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01... | UNKNOWN | PYTHON3 | CODEFORCES | 484 | |
322e8db062139940fd3ce280df4450dd | Guess Your Way Out! | Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left t... | [
"from collections import defaultdict, deque, Counter\r\nfrom sys import stdin, stdout\r\nfrom heapq import heappush, heappop\r\nimport math\r\nimport io\r\nimport os\r\nimport math\r\nimport bisect\r\n\r\n#?############################################################\r\n\r\n\r\ndef isPrime(x):\r\n for i in range... | {"inputs": ["1 2", "2 3", "3 6", "10 1024", "10 577", "11 550", "19 12783", "28 72803174", "39 457181784666", "12 955", "13 154", "14 2334", "15 15512", "16 21395", "17 80239", "18 153276", "20 589266", "21 1687606", "24 14428281", "29 113463931", "1 1", "3 8", "31 1819651953", "33 2599588275", "38 262402936512", "4 13... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
322e969544dec25cdee4270be8cac5b7 | Parking Lot | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of ... | [
"def binpow(a, b):\r\n res = 1\r\n while b > 0:\r\n if b & 1:\r\n res = res * a\r\n a = a * a\r\n b >>= 1\r\n return res\r\n\r\n\r\ndef ans(n):\r\n return binpow(4,n-3)*(9*n-3)\r\n\r\nn = int(input())\r\n\r\nprint(ans(n))\r\n",
"n=int(input())\r\nC=24*(4**(n-3))+36*(4**... | {"inputs": ["3", "4", "5", "6", "7", "12", "15", "28", "29", "30"], "outputs": ["24", "132", "672", "3264", "15360", "27525120", "2214592512", "280349076803813376", "1161928703861587968", "4809844402031689728"]} | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
323c38bee176928e348c80e88e4daf6f | Calendar | Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap yea... | [
"import datetime\r\nd1=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nd2=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((d2-d1).days))",
"\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().... | {"inputs": ["1900:01:01\n2038:12:31", "1996:03:09\n1991:11:12", "1999:12:31\n2000:02:29", "1903:09:27\n1988:06:15", "1913:11:14\n1901:05:11", "1915:01:01\n2007:07:01", "1925:07:15\n2010:06:22", "1935:10:08\n1923:01:07", "1986:08:24\n1926:04:13", "1932:11:18\n2028:09:25", "1942:06:04\n1982:12:29", "1993:08:25\n1985:02:1... | UNKNOWN | PYTHON3 | CODEFORCES | 90 | |
324634a6d5274599dbfc95cf907a3d09 | Bus Game | After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen ... | [
"import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom operator import add\r\nfrom itertools import accumulate\r\n\r\ninf = float('inf')\r\n# input = sys.stdin.readline\r\nflush = lambda : sys.stdout.flush\r\ncomb = lambda x , y ... | {"inputs": ["2 2", "3 22", "0 22", "1000 1000", "0 0", "0 21", "1 11", "1 12", "2 1", "2 23", "2 24", "3 1", "3 2", "3 13", "3 14", "4 1", "4 2", "4 25", "4 26", "5 1", "5 2", "5 15", "5 16", "5 23", "5 24", "6 1", "6 2", "6 13", "6 14", "6 23", "6 24", "7 1", "7 2", "7 13", "7 14", "7 25", "7 26", "8 1", "8 2", "8 15"... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
326a73695d6ab2a8c0ceb3ffa601d027 | Dragons | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | [
"s, n = map(int, input().split())\r\ndata = []\r\nfor i in range(n):\r\n dragonStrength, gain = map(int, input().split())\r\n data.append((dragonStrength, gain))\r\ndata = sorted(data)\r\nWon = True\r\nfor i in data:\r\n if s > i[0]:\r\n s += i[1]\r\n else:\r\n print(\"NO\")\r\n Won... | {"inputs": ["2 2\n1 99\n100 0", "10 1\n100 100", "123 2\n78 10\n130 0", "999 2\n1010 10\n67 89", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "2 2\n3 5\n1 2", "1 2\n1 0\n1 0", "5 10\n20 1\n4 3\n5 1\n100 1\n4 2\n101 1\n10 0\n10 2\n17 3\n12 84", "2 2\n1 98\n100 0", "2 2\n1 2\n3 5", "5 3\n13 20\n3 10\n15 5", "2 5\n1 1\n2 1\n3 1\n4 1\n... | UNKNOWN | PYTHON3 | CODEFORCES | 57 | |
326c9cfa4b463c80581756abe06cf25f | Vasya's Function | Vasya is studying number theory. He has denoted a function *f*(*a*,<=*b*) such that:
- *f*(*a*,<=0)<==<=0; - *f*(*a*,<=*b*)<==<=1<=+<=*f*(*a*,<=*b*<=-<=*gcd*(*a*,<=*b*)), where *gcd*(*a*,<=*b*) is the greatest common divisor of *a* and *b*.
Vasya has two numbers *x* and *y*, and he wants to calculate *f*(*x*,<=*y*)... | [
"'''\n Python3(PyPy3) Template for Programming-Contest.\n'''\n\nimport math\nimport sys\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\nmod = 998244353\ninf = 1 << 64\n\n\ndef fact(n: int):\n res = []\n for p in range(2, n + 1):\n if... | {"inputs": ["3 5", "6 3", "1000000009 1000000008", "1000000007 1000000006", "2000000018 2000000017", "1000000000000 1", "1000000000000 1000000000000", "1 1000000000000", "100000000000 100000000000", "1 100000000000", "100000000000 1", "1000000009 1000000000000", "1000000000000 1000000007", "124556361363 136616361", "15... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
32713f0e3bc63c4144e2655dda3099c3 | Case of the Zeros and Ones | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | [
"n=int(input())\r\nstr1=str(input())\r\na=str1.count('0')\r\nb=str1.count('1')\r\nprint(abs(a-b))\r\n",
"n = int(input())\r\ns = input()\r\nans = 0\r\nfor i in s:\r\n ans = ans + int(i)*2 - 1\r\nprint(abs(ans))",
"n = int(input())\r\na = input()\r\nx = []\r\n\r\nfor i in a:\r\n if len(x) == 0 or x[-1] == ... | {"inputs": ["4\n1100", "5\n01010", "8\n11101111", "1\n0", "1\n1", "2\n00", "2\n01", "2\n10", "2\n11", "3\n001", "6\n110110", "7\n0000011", "6\n110010", "6\n110100", "3\n100", "6\n010111", "8\n01011100", "6\n001011", "7\n1110000", "9\n011111101"], "outputs": ["0", "1", "6", "1", "1", "2", "0", "0", "2", "1", "2", "3", "... | UNKNOWN | PYTHON3 | CODEFORCES | 684 | |
3276d7d8749b698eee6a4ed34e59647f | BF Calculator | In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, whe... | [
"a = input()\r\nb = int(eval(a))\r\nres = '+' * 48;\r\nif b >= 200:\r\n res += \"++.--\";\r\n b -= 200;\r\nelif b >= 100:\r\n res += \"+.-\";\r\n b -= 100;\r\nk = b // 10\r\nb %= 10\r\nif k > 0:\r\n res += (\"+\" * k + '.' + '-' * k)\r\nres += ('+' * b + '.')\r\n \r\nprint(res)",
"#By: Luogu@rui... | {"inputs": ["2+3", "9-7", "1+1+1", "1+11+111", "111-11-1", "1+1-1+1-1+1-1+1-1+1", "9+1", "10-1", "31+49+49+71-51-61+59-111+51", "255+255+255+255+255-255-255-255-255-255", "100+100+10+10+10+10+10+5", "255-255+255-255+255-255+255-255+255", "0-255-255-255-255+255+255+255+255+255", "34+45+29-49+52-111-4+4+2+9", "0+0+0+0+0+... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
3278bb2a3c74f0b3ae56cb0cb81379c1 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | [
"__author__ = 'Utena'\r\nimport math\r\nn,a,b=map(int,input().split())\r\nm=[]\r\ns=[]\r\nfor i in range(n):\r\n m.append(list(map(int,input().split())))\r\nfor i in range(n):\r\n a1,b1=m[i]\r\n s.append((a1-a)**2+(b1-b)**2)\r\nfor i in range(n-1):\r\n a1,b1=m[i]\r\n a2,b2=m[i+1]\r\n if ((a2-a1)*(... | {"inputs": ["3 0 0\n0 1\n-1 2\n1 2", "4 1 -1\n0 0\n1 2\n2 0\n1 1", "3 0 0\n-1 1\n0 3\n1 1", "3 -4 2\n-3 2\n5 -5\n5 3", "3 -84 8\n-83 8\n21 -62\n3 53", "6 -94 -51\n-93 -51\n48 -25\n61 27\n73 76\n-10 87\n-48 38", "5 -94 52\n-93 52\n-78 -56\n-54 -81\n56 -87\n97 85", "10 -100 90\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
327dbb40ce764338d44efe10a6b74c17 | none | Appleman has a tree with *n* vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of *k* (0<=≤<=*k*<=<<=*n*) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (*k*<=+<=1) parts. Note, that each ... | [
"n = int(input())\nedges = [int(x) for x in input().split()]\ncolor = [int(x) for x in input().split()]\ngraph = [[] for _ in range(n)]\n\nfor a,b in enumerate(edges):\n graph[a+1].append(b)\n graph[b].append(a+1)\ndp = [[0]*2 for _ in range(n)]\nvisited = [0]*n\n\nstack = [0]\nwhile stack:\n v = stack[-1]... | {"inputs": ["3\n0 0\n0 1 1", "6\n0 1 1 0 4\n1 1 0 0 1 0", "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "5\n0 1 1 3\n0 0 0 1 1", "10\n0 1 1 2 4 3 3 3 2\n1 0 1 1 1 0 0 1 1 0", "100\n0 0 2 2 0 3 5 0 6 2 0 4 0 2 3 7 8 3 15 19 13 8 18 19 3 14 23 9 6 3 6 17 26 24 20 6 4 27 8 5 14 5 35 31 27 3 41 25 20 14 25 31 49 40 0 1 10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
328f6c972f176799aaf085e6e87dbdad | Love Triangles | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other ... | [
"class DisjointSet(object):\r\n def __init__(self, n):\r\n self.parent = list(range(n))\r\n self.rank = [0] * n\r\n self.num = n # number of disjoint sets\r\n\r\n def union(self, x, y):\r\n self._link(self.find_set(x), self.find_set(y))\r\n\r\n def _link(self, x, y):\r\n ... | {"inputs": ["3 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1", "100000 0", "100 3\n1 2 0\n2 3 0\n3 1 0", "9 2\n1 2 0\n2 3 0", "28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\n10019 28444 1\n6574 28053 1\n5036 16610 1\n... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
32affc2f5bd9de0f7bc25972e4d32d68 | Game of Robots | In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. A... | [
"n, k = map(int, input().split())\nrobos = list(input().split())\nfor i in range(n):\n if k <= i + 1:\n print(robos[k - 1])\n break\n else:\n k -= i + 1\n \t\t \t \t\t\t\t \t\t \t \t \t\t",
"n,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nk1=in... | {"inputs": ["2 2\n1 2", "4 5\n10 4 18 3", "1 1\n4", "2 1\n5 1", "2 2\n1 4", "2 3\n6 7", "3 1\n4 5 6", "3 2\n4 5 6", "3 3\n4 5 6", "3 4\n4 5 6", "3 5\n4 5 6", "3 6\n4 5 6", "4 1\n5 1000000000 999999999 12", "4 2\n5 1000000000 999999999 12", "4 3\n5 1000000000 999999999 12", "4 4\n5 1000000000 999999999 12", "4 5\n5 1000... | UNKNOWN | PYTHON3 | CODEFORCES | 108 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.