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 |
|---|---|---|---|---|---|---|---|---|---|
cecc17339e00c6d82bab06b3a807d63d | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pat... | [
"n,m=map(int,input().split())\r\n\r\na=[]\r\nb=[]\r\nfor i in range(n):\r\n\ta.append(input())\r\n\t\r\nt=list(map(int,input().split()))\r\nflag=0\r\nx=len(a[t[0]-1])\r\nfor i in t:\r\n\tb.append(a[i-1])\r\n\tif len(a[i-1])!=x:\r\n\t\tflag=1\r\n\t\tbreak\r\n\r\ns=''\r\nif flag!=1:\r\n\tfor i in range(x):\r\n\t\tl=b... | {"inputs": ["3 2\nab\nac\ncd\n1 2", "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "4 4\na\nb\nc\ndd\n1 2 3 4", "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "4 2\n.b\n.c\ndbt\ne.\n2 4", "27 27\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
cedb194ead074bf927d95693dde3edb3 | none | Edo has got a collection of *n* refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be pos... | [
"from math import ceil\n\n\ndef add(c, k, s, i0, di):\n i = i0\n while len(s) < k:\n s.add(c[i])\n i += di\n\n\ndef fst(c, s, i0, di):\n i = i0\n while c[i] in s:\n i += di\n return c[i]\n\n\ndef doors(ms, k):\n cs = [((m[2]+m[0])/2, (m[3]+m[1])/2, i) for i, m in enumerate(ms)... | {"inputs": ["3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4", "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2", "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12", "11 8\n9 1 11 5\n2 2 8 12\n3 8 23 10\n2 1 10 5\n7 1 19 5\n1 8 3 10\n1 5 3 9\n1 2 3 4\n1 2 3 4\n4 2 12 16\n8 5 12 9", "20 5\n1 12 21 22\n9 10 15 20\n10 12 12 20\n1 1 25 29\n5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cedf23f9cd9f0334094c4c443a3b28cd | Sum | Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the... | [
"import math\n\n# For some reason, wrong answer... F*CKING EPSILON log(1000, 10) = 2.9999999...\n# Intuition: The lowest base will produce the longest number\n\nEPSILON = 0.00000001\n\na, b = [int(i) for i in input().split()]\n\n# Assuming no wacky letters\ndef highest_digit(number):\n return max([int(c) for c i... | {"inputs": ["78 87", "1 1", "9 7", "11 11", "43 21", "84 89", "12 34", "99 11", "11 99", "99 99", "1 2", "1 3", "2 1", "2 2", "2 3", "3 1", "3 2", "3 3", "1 466", "1 1000", "1 999", "149 1", "999 1", "1000 1", "998 998", "998 999", "998 1000", "999 998", "999 999", "999 1000", "1000 998", "1000 999", "1000 1000", "1000... | UNKNOWN | PYTHON3 | CODEFORCES | 52 | |
cee4791929f0bd6034bfc5e68fc4deda | Vanya and Label | While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string *s* and wants to know the number of pairs of words of length |*s*| (length of *s*), such ... | [
"print(3**sum(6-bin({'-':62,'_':63}.get(c,ord(c)-7*(c>'9')-6*(c>'Z')-48)).count('1') for c in input())%1000000007)",
"import string\r\nfrom itertools import chain\r\nfrom os import path\r\nfrom sys import stdin, stdout\r\n\r\n\r\nfilename = \"../templates/input.txt\"\r\nif path.exists(filename):\r\n stdin = op... | {"inputs": ["z", "V_V", "Codeforces", "zHsIINYjVtU71kmM9E", "fRRNAdMvLFTX21T0FG5gyn7NG0SaIvzGG_g_SO", "Lb1T3sA4BcTx4KAgLIsl-dNOGDvimpxZOxJfMz6VC3nQkB3Y780qqX_1dnjjb59H9X", "2kdYy5-G2-TL5dtLRKcp0ScPGQMrEjwsXuxJHZb4EOd7g7NSQYiAuX2O40PKVyMGEQ1WzW6TvQqbrM1O6e3TdduRsk", "kuCerLoRuMSm6wa_YM", "_", "0123456789ABCDEFGHIJKLMNOP... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
ceedf38faa444936a913b20e9cd7d9c4 | Connected Components | We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with *n* nodes and *m* edges. Let's inde... | [
"import os,sys,collections,heapq,itertools,functools\r\nfrom functools import reduce , lru_cache\r\nfrom itertools import accumulate,chain,combinations,count \r\nfrom itertools import groupby,permutations,product,zip_longest\r\nfrom heapq import heapify,heappush,heappop,heapreplace,merge,nlargest,nsmallest\r\nfrom ... | {"inputs": ["6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3", "2 1\n2 1\n2\n1 1\n1 1", "3 2\n3 2\n3 1\n4\n1 1\n1 2\n2 2\n2 2", "3 3\n2 3\n3 1\n2 1\n5\n2 3\n3 3\n2 2\n2 2\n2 2", "4 5\n1 4\n2 1\n4 3\n2 1\n3 4\n5\n4 5\n2 4\n4 4\n1 3\n4 4", "5 4\n3 2\n5 2\n5 3\n2 3\n8\n4 4\n1 1\n3 4\n1 1\n3 3\n3 4\n3 4\n4 4"... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cefd9888a7d526cca46b7a86b3deefbb | Hot Days | The official capital and the cultural capital of Berland are connected by a single road running through *n* regions. Each region has a unique climate, so the *i*-th (1<=≤<=*i*<=≤<=*n*) region has a stable temperature of *t**i* degrees in summer.
This summer a group of *m* schoolchildren wants to get from the official ... | [
"import sys\n\n\nn, m = map(int, sys.stdin.readline().split())\n\nans = 0\n\nfor _ in range(n):\n ti, Ti, xi, ci = map(int, sys.stdin.readline().split())\n cost = xi * m * (ti + m > Ti) + ci\n if ti < Ti:\n cost2 = ci * ((m - 1) // (Ti - ti) + 1)\n cost = min(cost, cost2)\n \n ans += co... | {"inputs": ["2 10\n30 35 1 100\n20 35 10 10", "3 100\n10 30 1000 1\n5 10 1000 3\n10 40 1000 100000", "10 1\n8 6 3 4\n9 10 7 7\n1 3 9 5\n10 9 4 2\n1 10 2 10\n1 1 8 5\n5 5 9 2\n5 8 4 3\n4 4 9 7\n5 7 5 10", "5 5\n100 29 49 77\n34 74 41 8\n32 21 24 91\n45 52 16 51\n50 87 90 94", "1 1000000\n4 4 6 2", "20 102\n73 79 75 27\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cf1cc557666d64e45d88d252152147db | Restore Graph | Valera had an undirected connected graph without self-loops and multiple edges consisting of *n* vertices. The graph had an interesting property: there were at most *k* edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to *n*.
One day Valera... | [
"import sys\r\nn, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\ng = [k] * n\r\nmaxi = max(a)\r\nans = []\r\nif a.count(0) != 1:\r\n print(-1)\r\n sys.exit()\r\ni = 1\r\nf = a.index(0)\r\nres = [f]\r\nx = [[] for y in range(maxi + 1)]\r\nfor v in range(n):\r\n x[a[v]].append(v)\r... | {"inputs": ["3 2\n0 1 1", "4 2\n2 0 1 3", "3 1\n0 0 0", "5 3\n0 2 1 2 1", "7 3\n2 2 0 1 3 2 1", "9 4\n2 1 1 3 1 2 2 1 0", "3 1\n0 1 2", "2 1\n1 0", "2 1\n1 1", "2 1\n0 0", "4 2\n0 1 0 1", "5 3\n3 1 4 2 1", "5 4\n1 2 2 2 3", "4 3\n1 1 1 2", "4 3\n1 2 2 3", "4 3\n1 2 3 3", "7 6\n1 1 2 2 3 3 3", "10 5\n0 1 1 1 1 1 1 2 2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
cf438485b6500f7040d2da54b017d318 | The Queue | Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He know... | [
"begin, end, time = list(map(int, input().split()))\r\nn = int(input())\r\nif n == 1:\r\n print(begin)\r\nelif n > 0:\r\n ar = list(map(int, input().split()))\r\n ar.sort()\r\n i = 0\r\n ar.append(end - time + 1)\r\n n += 1\r\n\r\n num = begin\r\n ans = begin - ar[0] + 1\r\n fin_ans = ar[... | {"inputs": ["10 15 2\n2\n10 13", "8 17 3\n4\n3 4 5 8", "7 14 3\n2\n1 2", "30 70 10\n3\n30 32 35", "21 56 7\n5\n1 2 3 4 5", "10 1000000000 25\n20\n1 1 5 7 8 10 12 22 44 47 73 77 82 83 89 141 142 168 195 199", "30 60 3\n10\n1 5 6 10 12 13 18 23 24 25", "61 1000000000 13\n55\n29 72 85 94 103 123 125 144 147 153 154 184 18... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
cf4da4092ec76b45e3e4ddde8e8a0056 | Infinite Sequence | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | [
"a, b, c = map(int, input().split())\r\nd = b - a\r\nif a == b:\r\n print(\"YES\")\r\nelif d > 0 and c > 0 and float(d / c).is_integer():\r\n print(\"YES\")\r\nelif d < 0 and c < 0 and float(d / c).is_integer():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"a,b,c = map(int, input().split())\r\nif(c... | {"inputs": ["1 7 3", "10 10 0", "1 -4 5", "0 60 50", "1 -4 -5", "0 1 0", "10 10 42", "-1000000000 1000000000 -1", "10 16 4", "-1000000000 1000000000 5", "1000000000 -1000000000 5", "1000000000 -1000000000 0", "1000000000 1000000000 0", "115078364 -899474523 -1", "-245436499 416383245 992", "-719636354 536952440 2", "-1... | UNKNOWN | PYTHON3 | CODEFORCES | 136 | |
cf4fdddf06155690a7e8cf32013d2821 | Set of Points | Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of *n* points with the convexity of exactly *m*. Your set of points should not contain three points that lie on a straight line.
The single line contains two integers *n* and *m*... | [
"n, m = map(int, input().split())\r\n\r\n\r\nif m == 3:\r\n if n >= 5:\r\n print(-1)\r\n exit(0)\r\n print(0, 0)\r\n print(2, 0)\r\n print(1, 1)\r\n if n >= 4:\r\n print(1, 2)\r\n exit(0)\r\n\r\n\r\nfor i in range(m):\r\n print(i, 10**7 + i**2)\r\n\r\nfor i in range(n - m):... | {"inputs": ["4 3", "6 3", "6 6", "7 4", "3 3", "5 3", "4 4", "5 4", "6 4", "8 4", "8 6", "10 5", "5 5", "10 6", "11 7", "16 8", "9 5", "200 100", "199 100", "198 100", "102 100", "101 100", "100 100", "198 99", "197 99", "100 99", "99 99", "50 37", "150 100", "181 95", "100 50", "101 99", "6 5", "7 5", "8 5", "43 24", ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
cf61c7272e1736a69a692641b0e542a9 | Okabe and Future Gadget Laboratory | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | [
"n=int(input())\r\nl=[list(map(int,input().split())) for _ in range(n)]\r\nflag=0\r\nfor i in range(n):\r\n for j in range(n):\r\n if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)):\r\n continue\r\n else:\r\n print('No')\r\n flag=1\r\n bre... | {"inputs": ["3\n1 1 2\n2 3 1\n6 4 1", "3\n1 5 2\n1 1 1\n1 2 3", "1\n1", "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1", "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2 6 3 1", "4\n1 1 1 1\n1 12 1 2\n4 4 1 3\n5 10 6 1", "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n5 11 6 1", "4\n1 1 1 1\n1 13 1 2\n4 5 1 3\n7 11 6 1", "4\n1 1 1 1\n1 14 1 6\n4 5 1 5\n3 8 ... | UNKNOWN | PYTHON3 | CODEFORCES | 171 | |
cf630697f1a656cbd30ea39d80be45d2 | Orchestra | Paul is at the orchestra. The string section is arranged in an *r*<=×<=*c* rectangular grid and is filled with violinists with the exception of *n* violists. Paul really likes violas, so he would like to take a picture including at least *k* of them. Paul can take a picture of any axis-parallel rectangle in the orchest... | [
"f = lambda: map(int, input().split())\r\nr, c, n, k = f()\r\nt = [list(f()) for i in range(n)]\r\ns = 0\r\nfor i in range(1, r + 1):\r\n for j in range(i, r + 1):\r\n for u in range(1, c + 1):\r\n for v in range(u, c + 1):\r\n s += sum([i <= x <= j and u <= y <= v for x, y in t]... | {"inputs": ["2 2 1 1\n1 2", "3 2 3 3\n1 1\n3 1\n2 2", "3 2 3 2\n1 1\n3 1\n2 2", "1 1 1 1\n1 1", "10 10 10 10\n6 1\n3 8\n10 6\n10 3\n10 4\n8 9\n2 3\n5 7\n5 9\n5 1", "10 10 10 1\n8 2\n9 10\n6 8\n10 7\n1 8\n4 4\n6 3\n2 3\n8 8\n7 2", "5 9 2 2\n4 6\n1 5", "6 4 10 2\n2 3\n2 1\n1 2\n6 1\n1 4\n4 4\n2 4\n1 1\n6 3\n4 2", "8 2 4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 54 | |
cf63babc63476bee39388e4e1d25d2b4 | Trees | On Bertown's main street *n* trees are growing, the tree number *i* has the height of *a**i* meters (1<=≤<=*i*<=≤<=*n*). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the ... | [
"n=int(input())\r\na= list(map(int, input().split()))\r\n \r\nx=[n]*100001\r\nfor i in range(n):\r\n x[a[i]-min(n-i-1,i)]-=1\r\nprint (min(x[1:]))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nx = [n]*100001\r\n\r\nfor i in range(n):\r\n x[a[i]-min(n-i-1, i)]-=1\r\nprint(min(x[1:]))",
"n=i... | {"inputs": ["3\n2 2 2", "4\n1 2 2 1", "3\n61452 50974 73849", "4\n86002 1199 86003 86002", "5\n92605 92606 41969 98774 92605", "10\n1 1 2 3 4 4 3 2 1 10", "10\n73905 73906 73907 85732 73909 73909 73908 73907 73906 73905", "10\n60718 99414 65042 65043 65044 38495 95782 65042 65041 65040", "7\n1 2 3 7 6 5 4", "5\n4 5 6 5... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
cf6b0edd29a966dde1de8aa4a4467b6b | Mike and Geometry Problem | Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define *f*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1 to be the number of integer points in the segment [*l*,<=*r*] with *l*<=≤<=*r* (say that ). You are given two integers *n* and *k* and *n* closed inter... | [
"from collections import defaultdict\r\n\r\nmod=10**9+7\r\nMAXN=300001\r\n\r\ndef power(a,b):\r\n\r\n res=1\r\n while b>0:\r\n if b&1:\r\n res=(res*a)%mod\r\n b>>=1\r\n a=(a*a)%mod\r\n \r\n return res\r\n\r\nfact=[1 for _ in range(MAXN)]\r\ninv_fact=[1 for _ in range(MAXN... | {"inputs": ["3 2\n1 2\n1 3\n2 3", "3 3\n1 3\n1 3\n1 3", "3 1\n1 2\n2 3\n3 4", "1 1\n45 70", "1 1\n-35 -8", "1 1\n-79 -51", "2 2\n26 99\n-56 40", "9 6\n-44 -29\n-11 85\n11 84\n-63 1\n75 89\n-37 61\n14 73\n78 88\n-22 -18", "2 2\n-93 -22\n12 72"], "outputs": ["5", "3", "6", "26", "28", "29", "15", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
cf86a8bbd6a48bb925bc9ed62354e875 | World Cup | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | [
"x=input().split()\nx=[int(i) for i in x]\nx.sort()\nturn = 1\nwhile(not(x[0]%2==1 and x[1]%2==0 and (x[1]-x[0])==1)):\n\t#print(x[0],x[1])\n\tx[0]=(x[0])//2 + x[0]%2\n\tx[1]=(x[1])//2 + x[1]%2\n\tturn+=1\ncount = 1\nprod=2\nwhile(prod != x[2]):\n\tprod=prod*2\n\tcount+=1\nif(count==turn):\n\tprint(\"Final!\")\nels... | {"inputs": ["4 1 2", "8 2 6", "8 7 5", "128 30 98", "256 128 256", "256 2 127", "2 1 2", "2 2 1", "4 1 3", "4 1 4", "4 2 1", "4 2 3", "4 2 4", "4 3 1", "4 3 2", "4 3 4", "4 4 1", "4 4 2", "4 4 3", "8 8 7", "8 8 5", "8 8 1", "16 4 3", "16 2 4", "16 14 11", "16 3 11", "32 10 9", "32 25 28", "32 22 18", "32 17 25", "32 18... | UNKNOWN | PYTHON3 | CODEFORCES | 173 | |
cf9bfbf389d9d8bdc2c282638d92b467 | Dasha and Very Difficult Problem | Dasha logged into the system and began to solve problems. One of them is as follows:
Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*.
About sequences *a* and *b* we know that their ele... | [
"n,l,r = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nP = list(map(int,input().split()))\r\ns = [0] * n\r\nper=0\r\nfor j in range(n):\r\n s[P[j] - 1] = j\r\nb = [0] * n\r\nb[s[0]] = l\r\nfor j in range(1,n):\r\n last = b[s[j-1]] - A[s[j-1]]\r\n nexs = last+1\r\n \r\n if r - A[s... | {"inputs": ["5 1 5\n1 1 1 1 1\n3 1 5 4 2", "4 2 9\n3 4 8 9\n3 2 1 4", "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "5 1 7\n1 4 4 6 5\n5 2 1 4 3", "5 10 100\n12 14 15 11 13\n4 2 1 5 3", "2 1 1000000000\n1000000000 1\n2 1", "2 1 1000000000\n1000000000 1\n1 2", "5 1 5\n1 1 1 1 1\n1 2 3 4 5", "5 1 5\n1 1 1 1 1\n2 3 1 5 4", "1 100000... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
cfa14502e4800d652733f9b4ec565760 | Permutation | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | [
"n = int(input())\r\na = input().split()\r\nd = {}\r\nfor i in a:\r\n t = int(i)\r\n if t in d:\r\n d[t] += 1\r\n else:\r\n d[t] = 1\r\nres = 0\r\nfor i in range(1, n+1):\r\n if i not in d:\r\n res += 1\r\nprint(res)\r\n",
"n=int(input())\r\na={*map(int,input().split())}\r\nk=0\r\... | {"inputs": ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1", "5\n6 6 6 6 6", "10\n1 1 2 2 8 8 7 7 9 9", "8\n9 8 7 6 5 4 3 2", "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "1\n1", "1\n5000", "4\n5000 5000 5000 5000", "5\n3366 3461 4 5 4370", "10\n8 2 10 3 4 6 1 7 9 5", "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "15\n4 1459 12 4281 32... | UNKNOWN | PYTHON3 | CODEFORCES | 245 | |
d0040d13ef457ac6407a514ec877584c | Arpa's loud Owf and Mehrdad's evil plan | As you have noticed, there are lovely girls in Arpa’s land.
People in Arpa's land are numbered from 1 to *n*. Everyone has exactly one crush, *i*-th person's crush is person with the number *crush**i*.
Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as... | [
"input()\ncrush = [0] + [int(x) for x in input().split()]\nvisited = set()\n\ncircle_sizes = []\n\ndef gcd(a, b):\n return a if b == 0 else gcd(b, a%b)\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef solve():\n for i in range(len(crush)):\n if i not in visited:\n start, cur, count = ... | {"inputs": ["4\n2 3 1 4", "4\n4 4 4 4", "4\n2 1 4 3", "5\n2 4 3 1 2", "5\n2 2 4 4 5", "5\n2 4 5 4 2", "10\n8 10 4 3 2 1 9 6 5 7", "10\n10 1 4 8 5 2 3 7 9 6", "10\n6 4 3 9 5 2 1 10 8 7", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46... | UNKNOWN | PYTHON3 | CODEFORCES | 29 | |
d01820987d411523356abffd769f2c7f | Vasily the Bear and Triangle | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | [
"n=input().split()\r\nx,y=int(n[0]),int(n[1])\r\nif x>0 and y>0:\r\n print(0,x+y,x+y,0)\r\nelif x>0 and y<0:\r\n print(0,y-x,x-y,0)\r\nelif x<0 and y>0:\r\n print(x-y,0,0,y-x)\r\nelse:\r\n print(x+y,0,0,x+y)",
"x,y=[int(x) for x in input().split(\" \")]\r\nif(x>=0 and y>=0):\r\n s=x+y\r\n print(... | {"inputs": ["10 5", "-10 5", "20 -10", "-10 -1000000000", "-1000000000 -1000000000", "1000000000 1000000000", "-123131 3123141", "-23423 -243242423", "123112 4560954", "1321 -23131", "1000000000 999999999", "54543 432423", "1 1", "-1 -1", "-1 1", "1 -1", "42 -2", "2 -435", "76 -76", "1000000000 1", "1000000000 -1", "-1... | UNKNOWN | PYTHON3 | CODEFORCES | 183 | |
d02c5691f75073b585c6a0d403fb8188 | Martian Dollar | One day Vasya got hold of information on the Martian dollar course in bourles for the next *n* days. The buying prices and the selling prices for one dollar on day *i* are the same and are equal to *a**i*. Vasya has *b* bourles. He can buy a certain number of dollars and then sell it no more than once in *n* days. Acco... | [
"n, b = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(n):\r\n for j in range(i, n):\r\n ans = max(ans, (b//a[i])*a[j] + b%a[i])\r\nprint(ans)",
"n, am=map(int, input().split())\na=list(map(int, input().split()))\nmaxd=0\nx=0\ny=0\nprofit=0\nb=[0]*n\nb[n-1]... | {"inputs": ["2 4\n3 7", "4 10\n4 3 2 1", "4 10\n4 2 3 1", "2 755\n51 160", "3 385\n978 1604 1888", "4 1663\n1904 1049 1622 472", "5 1293\n1183 142 1356 889 134", "1 1472\n784", "1 478\n1955", "1 1483\n1126", "10 595\n881 832 1159 171 230 750 361 1800 516 567", "93 867\n97 1270 616 1027 1685 27 1662 947 1480 20 1394 152... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
d08494093811abd7a4cbf604871ae8f9 | Network Configuration | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | [
"n,k=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\na.sort(reverse=True)\r\nprint(min(a[:k]))",
"a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nl.reverse()\r\nprint(l[b-1])\r\n\r\n",
"[n, k], speed = map(int, input().split()), sorted(map(int, input().split())... | {"inputs": ["3 2\n40 20 30", "6 4\n100 20 40 20 50 50", "1 1\n16", "2 1\n10000 17", "2 2\n200 300", "3 1\n21 25 16", "3 2\n23 20 26", "3 3\n19 29 28", "100 2\n82 37 88 28 98 30 38 76 90 68 79 29 67 93 19 71 122 103 110 79 20 75 68 101 16 120 114 68 73 71 103 114 99 70 73 18 36 31 32 87 32 79 44 72 58 25 44 72 106 38 47... | UNKNOWN | PYTHON3 | CODEFORCES | 179 | |
d09e0f1b9d617f27cfe3d68024706ed8 | Single-use Stones | A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.
The stones are located at integer distances from the banks. The... | [
"def ok(cnt):\r\n for i in range(l, w):\r\n if pref[i] - pref[i - l] < cnt:\r\n return False\r\n return True\r\nw, l = map(int, input().split())\r\na = list(map(int, input().split()))\r\npref = [0] * w\r\nfor i in range(1, w):\r\n pref[i] = pref[i - 1] + a[i - 1]\r\nli, ri = 1, pref[-1]\r... | {"inputs": ["10 5\n0 0 1 0 2 0 0 1 0", "10 3\n1 1 1 1 2 1 1 1 1", "2 1\n0", "2 1\n5", "10 4\n0 0 6 2 7 1 6 4 0", "100 15\n0 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0"... | UNKNOWN | PYTHON3 | CODEFORCES | 51 | |
d0ae2caa308c79b1dd056ce059c51365 | Trace | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | [
"# Description of the problem can be found at http://codeforces.com/problemset/problem/157/B\r\n\r\nimport math\r\n\r\nn = int(input())\r\nl_s = list(map(int, input().split()))\r\nl_s.sort(reverse = True)\r\n\r\nt = 0\r\nfor index in range(n):\r\n t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2\r\n\r\nprint... | {"inputs": ["1\n1", "3\n1 4 2", "4\n4 1 3 2", "4\n100 10 2 1", "10\n10 9 8 7 6 5 4 3 2 1", "1\n1000", "8\n8 1 7 2 6 3 5 4", "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 9... | UNKNOWN | PYTHON3 | CODEFORCES | 314 | |
d0af4a8c1ee35c1950cff7a2dcfd802f | Felicity's Big Secret Revealed | The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon.
The organizers of the camp gave the gym leaders a PokeBlock, a sequence of *n* ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gy... | [
"mo = 10**9+7\r\ndef calc(l, r, si):\r\n res = 0\r\n for i in range(l, r + 1):\r\n res = res * 2 + int(si[i])\r\n return res\r\n \r\ndef main():\r\n n, si = int(input()), input()\r\n si = chr(0)+si\r\n f = [[0]*(1<<20) for i in range(6)]\r\n res, r, f[0][0]= 0, 0, 1\r\n for i in range... | {"inputs": ["4\n1011", "2\n10", "7\n0110011", "10\n0100011101", "12\n010010101011", "31\n1000000010111001111000111001110", "62\n00010011000110010011110110011001110110010011110110111100100010", "51\n100010110000000110000101100110111110001001011000000", "75\n011001100010010010100010011010001000110010011010100111110110100... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d0b4203b9ff07c161d2aaec568cce045 | Chess For Three | Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- ... | [
"n=int(input())\r\nlst=[]\r\nres=[1,2]\r\nfor i in range(n):\r\n lst.append(int(input()))\r\ncheck=1\r\nfor i in lst:\r\n if i not in res:\r\n check=0\r\n break\r\n else:\r\n if i==1:\r\n if sum(res)==3:\r\n res.remove(2)\r\n res.append(3)\r\n else:\r\n res.remove(3)\r\n ... | {"inputs": ["3\n1\n1\n2", "2\n1\n2", "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n2\n2\n2\n3\n1\n2\n2\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 76 | |
d0d6dc4057d27406033bbafafb50a4ec | If at first you don't succeed... | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | [
"a, b, c, n = map(int, input().split())\r\ntmp = n - (a + b - c)\r\nif tmp < 1 or a < c or b < c:\r\n print(-1)\r\nelse:\r\n print(tmp)",
"A,B,C,N=map(int,input().split())\r\nAUB=A+B-C\r\nif AUB>=N:\r\n print(-1)\r\nelif AUB<0:\r\n print(-1)\r\nelif A<C:\r\n print(-1)\r\nelif B<C:\r\n print(-1)\... | {"inputs": ["10 10 5 20", "2 2 0 4", "2 2 2 1", "98 98 97 100", "1 5 2 10", "5 1 2 10", "6 7 5 8", "6 7 5 9", "6 7 5 7", "50 50 1 100", "8 3 2 12", "10 19 6 25", "1 0 0 99", "0 1 0 98", "1 1 0 97", "1 1 1 96", "0 0 0 0", "100 0 0 0", "0 100 0 0", "100 100 0 0", "0 0 100 0", "100 0 100 0", "0 100 100 0", "100 100 100 0"... | UNKNOWN | PYTHON3 | CODEFORCES | 93 | |
d0e23c6e96b781e15b7393a41c955eb8 | Chores | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | [
"n,a,b= map(int,input().split())\r\nx = list(map(int,input().split()))\r\nx.sort()\r\nprint(x[b]-x[b-1])",
"#Antonio Hernandez Monsalvo\r\nmiLista = []\r\nenter = input().split()\r\nn = int(enter[0])\r\na = int(enter[1])\r\nb = int(enter[2])\r\n2<=n<=2000\r\n\r\ndef bubbleSort(tareas):\r\n\tfor long in range (len... | {"inputs": ["5 2 3\n6 2 3 100 1", "7 3 4\n1 1 9 1 1 1 1", "2 1 1\n10 2", "2 1 1\n7 7", "2 1 1\n1 1000000000", "3 1 2\n6 5 5", "3 2 1\n10 10 8", "8 3 5\n42 55 61 72 83 10 22 33", "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995", "4 1 3\n10 8 7 3", "4 2 2\n402 10 10 402", "4 1 3\n10 402 402 10", "4 3... | UNKNOWN | PYTHON3 | CODEFORCES | 282 | |
d0eadd1af5500f9da5e84a894556b641 | Table Tennis Game 2 | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | [
"'''\r\nCreated on 21 feb. 2017\r\n\r\n@author: Mirela\r\n'''\r\n\r\n\r\ndef calc(a, b, k):\r\n rez=a//k + b//k\r\n print(rez)\r\n\r\n\r\ndef solve():\r\n k,a,b=input().split(\" \")\r\n k=int(k)\r\n a=int(a)\r\n b=int(b)\r\n if a<k and b<k:\r\n print(-1)\r\n ... | {"inputs": ["11 11 5", "11 2 3", "1 5 9", "2 3 3", "1 1000000000 1000000000", "2 3 5", "1000000000 1000000000 1000000000", "1 0 1", "101 99 97", "1000000000 0 1", "137 137 136", "255 255 255", "1 0 1000000000", "123 456 789", "666666 6666666 666665", "1000000000 999999999 999999999", "100000000 100000001 99999999", "3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 85 | |
d10c82725280342c8fff8d5450f16947 | To Add or Not to Add | A piece of paper contains an array of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a number that occurs the maximum number of times in this array.
However, before looking for such number, you are allowed to perform not more than *k* following operations — choose an arbitrary element from the array and... | [
"n,k = map(int,input().split())\r\ns = sorted([int(i) for i in input().split()])\r\n\r\n\r\ndef search(n,k,s,x):\r\n if x==1:\r\n return 1,s[0]\r\n z = sum(s[0:x-1])\r\n for i in range(x-1,n):\r\n z+=s[i]\r\n if (z+k)//x>=s[i]:\r\n return x,s[i]\r\n z-=s[i-x+1]\r\n\r\... | {"inputs": ["5 3\n6 3 4 0 2", "3 4\n5 5 5", "5 3\n3 1 2 2 1", "6 0\n3 2 3 2 3 2", "10 15\n1 1 1 4 4 1 4 4 1 4", "5 100000\n0 5 5 4 3", "20 10\n-12 28 0 -27 16 25 -17 -25 9 -15 -38 19 33 20 -18 22 14 36 33 29", "100 100\n92 -6 67 92 65 -32 67 -31 91 -63 52 -81 -98 -12 48 86 -72 95 -50 66 79 89 -1 0 -33 -27 -23 -71 1 19 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d111139ff1607a1c8f702d05c3344b7a | Vasya and Polynomial | Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function *P*(*x*)<==<=*a*0<=+<=*a*1*x*1<=+<=...<=+<=*a**n**x**n*. Numbers *a**i* are called coefficients of a polynomial, non-negative integer *n* is called a degree of a polynomial.
Vasya has ma... | [
"t,a,b=map(int,input().split())\r\nif t==2 and a==3 and b>10000: res=0\r\nelif a==t: res=('inf' if a==1 else 2) if a==b else 0\r\nelse: res=0 if (a-b)%(t-a) else (1 if t != b else 0)\r\nprint(res)"
] | {"inputs": ["2 2 2", "2 3 3", "1 1 1", "3 5 10", "2 3 1000000000000000000", "7 8 9", "8 10 11", "5 30 930", "3 3 3", "1 5 5", "1 2 2", "1 2 5", "1 2 4", "1000000000000000000 1000000000000000000 1000000000000000000", "1 125 15625", "1000000000000 1000000000000000 1000000000000000000", "5 2 2", "1 3 6561", "3 6 5", "1 5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d11a14b8d0336ac43a0a902e5921aa27 | BerSU Ball | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | [
"n=int(input())\r\narr1=list(map(int,input().split()))\r\nm=int(input())\r\narr2=list(map(int,input().split()))\r\narr1=sorted(arr1)\r\narr2=sorted(arr2)\r\nans=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if(arr1[i]==arr2[j] or arr1[i]+1==arr2[j] or arr1[i]-1==arr2[j]):\r\n ans=ans+1 \r\... | {"inputs": ["4\n1 4 6 2\n5\n5 1 5 7 9", "4\n1 2 3 4\n4\n10 11 12 13", "5\n1 1 1 1 1\n3\n1 2 3", "1\n1\n1\n1", "2\n1 10\n1\n9", "4\n4 5 4 4\n5\n5 3 4 2 4", "1\n2\n1\n1", "1\n3\n2\n3 2", "1\n4\n3\n4 4 4", "1\n2\n4\n3 1 4 2", "1\n4\n5\n2 5 5 3 1", "2\n2 2\n1\n2", "2\n4 2\n2\n4 4", "2\n4 1\n3\n2 3 2", "2\n4 3\n4\n5 5 5 6",... | UNKNOWN | PYTHON3 | CODEFORCES | 173 | |
d14d76ed6f3fbd0cf793d69b8bbffa64 | Growing Mushrooms | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ... | [
"def main():\r\n\r\n n, t1, t2, k = [int(i) for i in input().split()]\r\n\r\n v = []\r\n for i in range(n):\r\n a, b = [int(i) for i in input().split()]\r\n v.append([a, b])\r\n\r\n res = []\r\n for i in range(n):\r\n a, b = v[i]\r\n\r\n h1 = a * t1 * (1 - k / 100) + b * t... | {"inputs": ["2 3 3 50\n2 4\n4 2", "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737", "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978", "8 1 4 55\n507 82\n681 492\n602 849\n3... | UNKNOWN | PYTHON3 | CODEFORCES | 60 | |
d154b5f96fbc09054a93df0a65532334 | Prefixes and Suffixes | You have a string *s*<==<=*s*1*s*2...*s*|*s*|, where |*s*| is the length of string *s*, and *s**i* its *i*-th character.
Let's introduce several definitions:
- A substring *s*[*i*..*j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* is string *s**i**s**i*<=+<=1...*s**j*. - The prefix of string *s* of length *l* (1<=≤... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque\r\n\r\nS=input().strip()\r\n\r\n\r\nLEN=len(S)\r\ni=1\r\nj=0\r\nA=[0]*LEN\r\nA[0]=LEN\r\n\r\nwhile i<LEN:\r\n while i+j<LEN and S[j]==S[i+j]:\r\n j+=1\r\n A[i]=j\r\n \r\n if j==0:\r\n i+=1\r\n continue\r\n ... | {"inputs": ["ABACABA", "AAA", "A", "AAAAAAAAAAAAAAAAXAAAAAAAAAAAAAAAAAAAAAAA", "AB", "AXAXA", "CODEFORCES", "GERALDPAVELGERALDPAVEL", "ZZ"], "outputs": ["3\n1 4\n3 2\n7 1", "3\n1 3\n2 2\n3 1", "1\n1 1", "17\n1 39\n2 37\n3 35\n4 33\n5 31\n6 29\n7 27\n8 25\n9 23\n10 21\n11 19\n12 17\n13 15\n14 13\n15 11\n16 9\n40 1", "1\... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
d15b551ae8fabd1bdc627749b5d8d626 | Lucky String | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i... | [
"print(('abcd'*100000)[:int(input())])",
"n = int(input())\r\ns = \"abcd\"\r\ns1 = \"\"\r\n\r\nk = n // 4\r\n\r\ns1 += s * k\r\n\r\nk = n % 4\r\ns1 += s[:k]\r\n\r\nprint(s1)\r\n",
"print(('abcd'*25001)[:int(input())])",
"n=int(input())\ns=(n//4+1)*\"abcd\"\nprint(s[:n])",
"c,q= \"\",\"abcd\"\r\nn= int(input... | {"inputs": ["5", "3", "8", "10", "16", "64", "128", "100", "47", "74", "477", "1000", "1024", "512", "747", "2075", "9475", "10000", "47589", "9999", "85475", "77777", "100000", "99994", "785", "1", "2", "7", "4", "99", "6", "9"], "outputs": ["abcda", "abc", "abcdabcd", "abcdabcdab", "abcdabcdabcdabcd", "abcdabcdabcdab... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
d15d1f4a8fbfb34fdfd3b6f396e66f1a | Find Pair | You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing *n* (not necessarily different) integers *a*1, *a*2, ..., *a**n*. We are interested in all possible pairs of numbers (*a**i*, *a**j*), (1<=≤<=*i*,<=*j*<=≤<=*n*). In other words, let's consider all *n*2 pairs of numbers, pick... | [
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nN,K = map(int... | {"inputs": ["2 4\n2 1", "3 2\n3 1 5", "3 3\n1 1 2", "1 1\n-4", "3 7\n5 4 3", "3 6\n10 1 3", "4 12\n-1 -2 -3 -4", "5 10\n1 2 2 1 3", "5 13\n3 3 3 4 5", "8 26\n4 4 1 1 1 3 3 5", "10 90\n2 1 1 1 1 1 2 1 2 2", "10 6\n3 1 1 3 2 2 2 3 3 3", "10 18\n1 1 1 3 4 4 4 1 2 3", "50 622\n4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d16620d13a8ade89313bb0547f8d9d8d | none | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is *l* centimeters. The ruler already has *n* marks, with which he can make mea... | [
"import itertools\nimport math\n\ndef can_measure(a, d):\n\treturn any(i + d in a for i in a)\n\ndef main():\n\tn, l, x, y = map(int, input().split())\n\ta = set(map(int, input().split()))\n\t\n\tcan_x = can_measure(a, x)\n\tcan_y = can_measure(a, y)\n\tif can_x and can_y:\n\t\tprint(0)\n\telif can_x:\n\t\tprint(1)... | {"inputs": ["3 250 185 230\n0 185 250", "4 250 185 230\n0 20 185 250", "2 300 185 230\n0 300", "4 300 4 5\n0 6 7 300", "2 100 30 70\n0 100", "2 300 140 160\n0 300", "4 300 1 2\n0 298 299 300", "3 350 150 160\n0 310 350", "4 300 4 5\n0 298 299 300", "19 180 117 148\n0 1 19 20 21 28 57 65 68 70 78 88 100 116 154 157 173 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d172ac41a846604f1c877ea449cf1b55 | Buy Low Sell High | You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when y... | [
"\n\nfrom heapq import *\nn=int(input())\np=list(map(int,input().split()))\nans=0\nhp=[]\nfor i in range(n):\n if hp and hp[0]<p[i]:\n ans+=p[i]-hp[0]\n heappop(hp)\n heappush(hp,p[i])\n heappush(hp,p[i])\n else:heappush(hp,p[i])\n\nprint(ans)\n\n\n",
"import sys\nfrom heapq impo... | {"inputs": ["9\n10 5 4 7 9 12 6 2 10", "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4", "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19", "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 ... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
d175d48a79770638f1ab5c9a7b472225 | Broken Monitor | Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.
Innocentius is touch-typing a program that pain... | [
"from itertools import chain\ndef draw_square(ans, square_a, ymin, xmin) -> list:\n for i in range(square_a + 1):\n if(ans[ymin][xmin + i] != 'w'):\n ans[ymin] = ans[ymin][:xmin + i] + '+' + ans[ymin][xmin + i + 1:]\n if(ans[ymin + square_a][xmin + i] != 'w'):\n ans[ymin + squ... | {"inputs": ["4 8\n..w..w..\n........\n........\n..w..w..", "2 4\n....\n.w..", "2 6\nw..w.w\n...w..", "9 4\n....\n....\n....\n....\n....\n..w.\n....\n....\n.w..", "1 1\nw", "2 1\nw\n.", "2 1\nw\nw", "1 2\nww", "2 2\nww\n..", "2 2\n.w\n.w", "2 2\n..\nww", "2 2\nw.\nw.", "2 2\nw.\n.w", "2 2\n..\nw.", "3 3\n...\n..w\nw..",... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d184fb3f320d8dcb999611f7b0d120ec | none | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | [
"ins = list(map(int, input().split()))\r\nn = ins[0]\r\nm = ins[1]\r\nk = ins[2]\r\nkoln = 1\r\nkolm = 1\r\nwhile k > 2*m:\r\n k -= 2*m\r\n koln+=1\r\nwhile k > 2:\r\n k-=2\r\n kolm += 1\r\nif k == 1:\r\n print(koln,kolm,\"L\")\r\nelse:\r\n print(koln, kolm, \"R\")",
"n,m,k = map(int,input().spl... | {"inputs": ["4 3 9", "4 3 24", "2 4 4", "3 10 24", "10 3 59", "10000 10000 160845880", "1 1 1", "1 1 2", "1 10000 1", "1 10000 20000", "10000 1 1", "10000 1 10000", "10000 1 20000", "3 2 1", "3 2 2", "3 2 3", "3 2 4", "3 2 5", "3 2 6", "3 2 7", "3 2 8", "3 2 9", "3 2 10", "3 2 11", "3 2 12", "300 2000 1068628", "300 20... | UNKNOWN | PYTHON3 | CODEFORCES | 336 | |
d1852fd6497c284277904fff7cf01797 | Weak Subsequence | Little Petya very much likes strings. Recently he has received a voucher to purchase a string as a gift from his mother. The string can be bought in the local shop. One can consider that the shop has all sorts of strings over the alphabet of fixed size. The size of the alphabet is equal to *k*. However, the voucher has... | [
"from sys import stdin #Bibliotecas para optimizar la entrada/salida\r\nfrom sys import stdout\r\n\r\nMOD = 1000000007 #Modulo\r\n\r\ndef qp(a,p): #Exponenciacion binaria O(log p)\r\n a = int(a)\r\n p = int(p)\r\n if p == 0:\r\n return 1\r\n x = qp(a,p//2)\r\n x = (x*x)%MOD\r\n if p%2 == 1:... | {"inputs": ["2 2", "3 5", "2 139", "5 6", "1000 1002", "131 132", "4 4", "3 2", "1 1000000000", "666 888888888", "1000000 1000000000", "1000000 1000000", "1000000 2", "2 1000000000", "1000000 500000", "12345 543210123", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "3 3", "3... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d1946a1f3c70a6557cd0eba06be837de | The Red Button | Piegirl found the red button. You have one last chance to change the inevitable end.
The circuit under the button consists of *n* nodes, numbered from 0 to *n* - 1. In order to deactivate the button, the *n* nodes must be disarmed in a particular order. Node 0 must be disarmed first. After disarming node *i*, the next... | [
"n=int(input())\r\nif n&1:\r\n\tprint(-1)\r\nelse:\r\n\tD,R=[False]*(10**6),[0]*(10**6)\r\n\ti,j=0,0\r\n\twhile True:\r\n\t\tD[j]=True\r\n\t\tR[i]=j\r\n\t\ti+=1\r\n\t\tif not D[(j+n)>>1]:\r\n\t\t\tj=(j+n)>>1\r\n\t\telif not D[j>>1]:\r\n\t\t\tj=j>>1\r\n\t\telse:\r\n\t\t\tbreak\r\n\tprint(\" \".join(str(R[i]) for i i... | {"inputs": ["2", "3", "4", "16", "5", "7", "32", "255", "65536", "99999", "9", "6", "8", "10", "12", "20", "25", "30", "32", "45", "50", "100", "126", "513", "514", "800", "1000", "2500", "6400", "23105", "24002", "29024", "36002", "55555", "65534", "77776", "88888", "99494", "99998", "90248", "99994", "100000", "98300... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d19a5d2d40c3191166b3cebf9ec2503a | The penguin's game | Pay attention: this problem is interactive.
Penguin Xoriy came up with a new game recently. He has *n* icicles numbered from 1 to *n*. Each icicle has a temperature — an integer from 1 to 109. Exactly two of these icicles are special: their temperature is *y*, while a temperature of all the others is *x*<=≠<=*y*. You ... | [
"import sys\r\n\r\nn, x, y = (int(x) for x in input().split())\r\nys = [y, x ^ y]\r\n\r\ndef ask(*bits):\r\n arr = [x for x in range(1, n + 1) if all(x & i == i for i in bits)]\r\n if len(arr) == 0:\r\n return 0\r\n print('?', len(arr), *arr)\r\n sys.stdout.flush()\r\n return int(input())\r\n\... | {"inputs": ["4 2 1 1 3", "6 1 2 5 6", "2 4523 4235 1 2", "511 42 1000000000 255 511", "666 536870911 268435455 13 133", "999 536870912 536870911 1 999", "1000 123 321 1 513", "1000 1000000000 1 36 1000", "1000 15 16 511 512", "1000 16 15 511 512", "50 276891238 128284616 2 28", "100 745880634 179094068 84 99", "150 481... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
d1a4489d4ae1ae49f2006c2a331b20f2 | Palindromic Cut | Kolya has a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits.
He wants to rearrange the symbols in *s* and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forw... | [
"n = int(input())\r\nstring = input()\r\nchar = []\r\ncharPair = []\r\ncharImpair = []\r\nfor car in string:\r\n\tif car not in char:\r\n\t\tz = string.count(car)\r\n\t\twhile z>1:\r\n\t\t\tcharPair.append(car)\r\n\t\t\tz-=2\r\n\t\tif(z==1):\r\n\t\t\tcharImpair.append(car)\r\n\t\tchar.append(car)\r\nif len(charImpa... | {"inputs": ["6\naabaac", "8\n0rTrT022", "2\naA", "1\ns", "10\n6IIC6CCIIC", "20\nqqqoqqoqMoqMMMqqMMqM", "45\nf3409ufEFU32rfsFJSKDFJ234234ASkjffjsdfsdfsj33", "30\n8M8MMMMMlrMlMMrMMllMMrllMMrMrl", "40\nTddTddddTddddddTdddTdddddddddddddddddddd", "45\nRRNRRRRRRRRRNRRRRRRRRRRRRRRNRRRRRRRRRRRNRRRRR", "115\nz9c2f5fxz9z999c9z99... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
d1a4bc4ff7233cca17c240867693a8ff | Slime Combining | Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of... | [
"N = int(input())\r\nans = []\r\ni = 0\r\n\r\nwhile N >> i:\r\n if (N >> i) & 1:\r\n ans.append(i + 1)\r\n i += 1\r\n \r\nprint(*ans[::-1])",
"n = int(input())\r\n\r\nslimes = [1] * n\r\ni = 0\r\n\r\nwhile i < len(slimes)-1:\r\n if slimes[i] == slimes[i+1]:\r\n slimes[i] += 1\r\n ... | {"inputs": ["1", "2", "3", "8", "100000", "12345", "32", "70958", "97593", "91706", "85371", "97205", "34768", "12705", "30151", "4974", "32728", "8192", "65536", "32", "256", "4096", "33301", "16725", "149", "16277", "99701"], "outputs": ["1", "2", "2 1", "4", "17 16 11 10 8 6", "14 13 6 5 4 1", "6", "17 13 11 9 6 4 3... | UNKNOWN | PYTHON3 | CODEFORCES | 215 | |
d1b115caf00a7ad2e19bbdbf6e96df46 | Book Reading | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | [
"n, t = map(int, input().split())\ndaftar_waktu_kerja = list(map(int, input().split()))\nhari = 1\n\nfor waktu_kerja in daftar_waktu_kerja:\n waktu_kosong = 86400 - waktu_kerja\n t -= waktu_kosong\n\n if t <= 0:\n print(hari)\n break\n \n hari += 1\n\t \t\t \t\t\t\t\t \t \t \t\t \t",
"a=input... | {"inputs": ["2 2\n86400 86398", "2 86400\n0 86400", "2 86400\n1 86399", "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1 1\n86399", "6 1200\n86400 864... | UNKNOWN | PYTHON3 | CODEFORCES | 396 | |
d1cb8e128dce4bdba12b0eb1c2f27fc2 | k-Factorization | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a produ... | [
"from math import sqrt\r\n\r\n\r\ndef eratosfen(x):\r\n arr = [True] * (x + 1)\r\n result = []\r\n for i in range(2, x + 1):\r\n if arr[i]:\r\n result.append(i)\r\n for j in range(2 * i, x + 1, i):\r\n arr[j] = False\r\n return result\r\n\r\nn, k = map(int, in... | {"inputs": ["100000 2", "100000 20", "1024 5", "100000 10", "99999 3", "99999 4", "99999 5", "1024 10", "1024 11", "2048 11", "2 1", "2 2", "2 3", "2 4", "2 5", "2 1", "3 1", "3 2", "349 2", "8 1", "66049 2", "6557 2", "9 2", "4 2", "2 2", "4 4", "12 1", "17 1", "8 2", "14 2", "99991 1", "30 2", "97 1", "92 2", "4 1", ... | UNKNOWN | PYTHON3 | CODEFORCES | 96 | |
d1f7ca2f5bc4490ad9a2954490f49833 | Tidying Up | Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side. But by the end of the week because of his very active lifestyle in his dre... | [
"import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,... | {"inputs": ["2 3\n1 1 2\n2 3 3", "3 4\n1 3 2 6\n2 1 5 6\n4 4 5 3", "2 2\n1 2\n1 2", "2 2\n1 1\n2 2", "2 2\n2 1\n1 2", "3 4\n1 1 6 6\n2 2 4 4\n3 3 5 5", "3 4\n5 3 3 2\n6 1 4 2\n6 1 5 4", "5 4\n9 9 10 10\n7 7 5 5\n2 2 3 3\n1 1 8 8\n4 4 6 6", "4 5\n7 9 9 10 10\n7 5 5 3 3\n8 1 1 2 2\n8 6 6 4 4", "5 4\n6 4 4 3\n10 8 5 1\n10... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d21e0b3207ee3c755958cfc2ee170922 | Leha and another game about graph | Leha plays a computer game, where is on each level is given a connected graph with *n* vertices and *m* edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer *d**i*, which can be equal to 0, 1 or <=-<=1. To pass the level, he needs to find a «good» subset of edges of the gr... | [
"import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nimport time\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpo... | {"inputs": ["1 0\n1", "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4", "2 1\n1 1\n1 2", "3 3\n0 -1 1\n1 2\n2 3\n1 3", "10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2", "3 2\n1 0 1\n1 2\n2 3"], "outputs": ["-1", "0", "1\n1", "1\n2", "0", "2\n2\n1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d2370e5d51e7c7104ac917dd0c1ee297 | Home Numbers | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur... | [
"n, a = [int(x) for x in input().split()]\r\nans = 1\r\nif a % 2 == 0:\r\n while n != a:\r\n n -= 2\r\n ans += 1\r\nelse:\r\n t = 1\r\n while t != a:\r\n t += 2\r\n ans += 1\r\nprint(ans)",
"import string\r\n\r\nx = input()\r\ny = x.split(' ')\r\nn, a = list(map(lambda x: int(... | {"inputs": ["4 2", "8 5", "2 1", "2 2", "10 1", "10 10", "100000 100000", "100000 2", "100000 3", "100000 99999", "100 100", "3000 34", "2000 1", "100000 1", "24842 1038", "1628 274", "16186 337", "24562 2009", "9456 3443", "5610 332", "1764 1288", "28588 13902", "92480 43074", "40022 26492", "85766 64050", "67808 6180... | UNKNOWN | PYTHON3 | CODEFORCES | 120 | |
d24e0144ab5b191851e3d3b0c9dc7679 | Three displays | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ... | [
"n=int(input())\r\na=[int(x) for x in input().split(\" \")]\r\nc=[int(x) for x in input().split(\" \")]\r\n\r\nans=int(1e18)\r\nfor j in range(1, n-1):\r\n cost=0\r\n pos=-1; mn=int(1e18)\r\n for i in range(0, j): \r\n if a[i]<a[j] and c[i]<mn:\r\n mn=c[i]\r\n pos=i\r\n if p... | {"inputs": ["5\n2 4 5 4 10\n40 30 20 10 40", "3\n100 101 100\n2 4 5", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "3\n1 2 3\n100000000 100000000 100000000", "3\n999999998 999999999 1000000000\n100000000 100000000 99999999", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 44617360... | UNKNOWN | PYTHON3 | CODEFORCES | 104 | |
d29152b2c4baf0df2caf31c9d71faa80 | Sums of Digits | Vasya had a strictly increasing sequence of positive integers *a*1, ..., *a**n*. Vasya used it to build a new sequence *b*1, ..., *b**n*, where *b**i* is the sum of digits of *a**i*'s decimal representation. Then sequence *a**i* got lost and all that remained is sequence *b**i*.
Vasya wonders what the numbers *a**i* c... | [
"import sys\r\n\r\n\r\ndef get_max(su, le):\r\n div, mod = divmod(su, 9)\r\n ret = ['9'] * div\r\n if mod:\r\n ret = [str(mod)] + ret\r\n\r\n if le - len(ret) > 0:\r\n x = str(int(ret.pop(0)) - 1)\r\n ret = ['1', x] + ret\r\n\r\n if le - len(ret) > 0:\r\n ret = [re... | {"inputs": ["3\n1\n2\n3", "3\n3\n2\n1", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1", "10\n8\n8\n5\n1\n2\n7\n3\n8\n9\n4", "10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n5\n6\n7\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
d2b5986193f7609c75ca4859225eff13 | Mahmoud and a Dictionary | Mahmoud wants to write a new dictionary that contains *n* words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.
He know that if two words hav... | [
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef find_root(root_dict, x):\r\n L = []\r\n while x != root_dict[x]:\r\n L.append(x)\r\n x = root_dict[x]\r\n for y in L:\r\n root_dict[y] = x \r\n return x \r\n \r\ndef process(A, X, Queries):\r\n n = len(A)\r\n roo... | {"inputs": ["3 3 4\nhate love like\n1 love like\n2 love hate\n1 hate like\nlove like\nlove hate\nlike hate\nhate like", "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\ndog hi\nhi hello\nihateyou goaway\nwelcome ihatey... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
d3197ae780b3073cca1cf30089f232ea | Pacifist frogs | Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.
One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to *... | [
"n, m, k = map(int, input().split())\r\nx, y = n, []\r\na = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nfor i, d in enumerate(a):\r\n c = 0\r\n for t in b:\r\n if 0 == t % d:\r\n c += 1\r\n if c < x:\r\n x = c\r\n y = [i + 1]\r\n elif c == x:\r\n ... | {"inputs": ["5 3 5\n2 3 4\n1 2 3 4 5", "1000000000 2 3\n2 5\n999999995 999999998 999999996", "1 1 1\n1\n1", "2 2 1\n2 1\n1", "3 2 2\n2 4\n3 2", "10 3 6\n5 2 8\n5 6 7 8 9 10", "10 10 9\n10 9 8 7 6 5 4 3 2 1\n10 9 8 7 5 4 3 2 1", "20 3 5\n2 3 5\n2 5 6 10 15", "20 4 8\n1 2 3 4\n2 4 6 8 10 12 14 16", "10 5 5\n1 5 3 5 1\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 39 | |
d33ed0a7470768868bc662f77d990f03 | Three matrices | Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an *n*<=×<=*n* matrix *W*, consisting of integers, and you should find two *n*<=×<=*n* matrices *A* and *B*, all the following conditions must hold:
- *A**ij*<==<=*A**ji*, for all *i*,<=*j* (1<=≤<=*i*,<=*... | [
"n = int(input())\r\nW = []\r\nfor i in range(0, n):\r\n s = input().split(' ')\r\n w = list(map(int, s))\r\n W.append(w)\r\na = []\r\nb = []\r\nA = []\r\nB = []\r\ni = 0\r\n#while (i < n - 1):\r\n# for j in range(i+1, n):\r\n# a.append((W[i][j]+W[j][i])/2)\r\n# b.append((W[i][j]-W[j][i])/... | {"inputs": ["2\n1 4\n3 2", "3\n1 2 3\n4 5 6\n7 8 9", "8\n62 567 1382 1279 728 1267 1262 568\n77 827 717 1696 774 248 822 1266\n563 612 995 424 1643 1197 338 1141\n1579 806 1254 468 184 1571 716 772\n1087 182 1312 772 605 1674 720 1349\n1393 988 873 157 403 301 1519 1192\n1085 625 1395 1087 847 1360 1004 594\n1368 1056 ... | UNKNOWN | PYTHON3 | CODEFORCES | 34 | |
d34fce590c9ab5f1c4b730f672fac6e8 | Friends Meeting | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | [
"import math\r\na = int(input())\r\nb = int(input())\r\nz = math.fabs(a-b)//2\r\nn = 0\r\nfor i in range(int((math.fabs(a-b)-z))+1):\r\n n+=i\r\nfor i in range(int(z)+1):\r\n n+=i\r\nprint(n)",
"def arithm_sum(a, n, d):\r\n return int(n/2 * (2*a+(n-1)*d))\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\n\r\n... | {"inputs": ["3\n4", "101\n99", "5\n10", "1\n2", "1\n1000", "999\n1000", "1000\n999", "1000\n1", "2\n1", "2\n999", "2\n998", "999\n2", "998\n2", "2\n1000", "1000\n2", "1\n999", "999\n1", "188\n762", "596\n777", "773\n70", "825\n729", "944\n348", "352\n445", "529\n656", "19\n315", "138\n370", "546\n593", "285\n242", "773... | UNKNOWN | PYTHON3 | CODEFORCES | 607 | |
d35468d66b47dffb57a8ada4ba7221e5 | Vanya and Fence | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | [
"friends_num, fence_height = map(int, input().split())\nfriends_heights = [int(height) for height in input().split()]\n\nroad_width = sum(\n 1\n if height <= fence_height\n else 2\n for height in friends_heights\n)\n\nprint(road_width)\n",
"\r\nn,h=map(int, input().split())\r\na= list(map(int, input()... | {"inputs": ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5", "10 420\n214 614 297 675 82 740 174 23 255 15", "10 561\n657 23 1096 487 785 66 481 554 1000 821", "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 ... | UNKNOWN | PYTHON3 | CODEFORCES | 889 | |
d3765fa3113a54c91060c293e49d86cc | Strange Calculation and Cats | Gosha's universe is a table consisting of *n* rows and *m* columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (*r*,<=*c*) to denote a cell located in the row *r* and column *c*.
Gosha is often invited somewhere. Every time he gets an invitation, he first calculates t... | [
"import sys\nfrom contextlib import contextmanager\nfrom io import StringIO\n\n\nM = 10**9 + 7\n\n\ndef smvmul(d, m, v):\n return [sum(m[r][k] * v[k] for k in range(d)) % M for r in range(d)]\n\n\ndef smmul(d, m1, m2):\n return [[sum(m1[r][k] * m2[k][c] for k in range(d)) % M\n for c in range(d)] f... | {"inputs": ["1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7", "3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7", "4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15", "1 1 1\n1 1 1 2", "3 3 1\n1 3 3 5", "2 2 5\n2 1 1 8\n3 1 1 12345\n2 1 2 22345\n3 1 2 31243\n1 2 2 111115", "1 2 3\n1 1 1 2\n1 1 2 5\n1 1 1 19", "1 1 4\n2 1 1 2\n3 1 1 5\n1 1 1 7\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d377f3b3aaa38b4a7edac7027b9c009a | Selling Souvenirs | After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | [
"#Bhargey Mehta (Sophomore)\r\n#DA-IICT, Gandhinagar\r\nimport sys, math, queue, bisect\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\nMOD = 10**9+7\r\nsys.setrecursionlimit(1000000)\r\n\r\nn, m = map(int, input().split())\r\nc1, c2, c3 = [0], [0], [0]\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\... | {"inputs": ["1 1\n2 1", "2 2\n1 3\n2 2", "4 3\n3 10\n2 7\n2 8\n1 1", "5 5\n3 5\n2 6\n3 2\n1 1\n1 6", "6 6\n1 6\n1 4\n1 8\n3 2\n3 2\n2 8", "6 12\n1 7\n1 10\n2 8\n1 2\n2 9\n3 5", "6 18\n3 3\n1 10\n2 10\n3 6\n1 3\n2 3", "20 25\n2 13\n3 11\n1 32\n1 43\n3 85\n1 14\n2 57\n1 54\n1 38\n2 96\n2 89\n3 64\n1 79\n2 73\n1 73\n2 34\... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
d37c153e46473b00ba4e801f4917d3d7 | Bulbs | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | [
"a,b=map(int,input().split())\r\ng=set()\r\nfor i in range(a):\r\n n=list(map(int,input().split()))\r\n n.pop(0)\r\n g.update(n)\r\nprint(['NO','YES'][len(g) == b])",
"n,m=map(int,input().split())\r\np=[]\r\npo=[]\r\nfor i in range(m):\r\n p.append('0')\r\n po.append('1')\r\nfor i in range(1,n+1):\... | {"inputs": ["3 4\n2 1 4\n3 1 3 1\n1 2", "3 3\n1 1\n1 2\n1 1", "3 4\n1 1\n1 2\n1 3", "1 5\n5 1 2 3 4 5", "1 5\n5 4 4 1 2 3", "1 5\n5 1 1 1 1 5", "2 5\n4 3 1 4 2\n4 2 3 4 5", "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n... | UNKNOWN | PYTHON3 | CODEFORCES | 439 | |
d3891b505ee7f8ab84e9bc52c21e7b57 | none | Manao is taking part in a quiz. The quiz consists of *n* consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectl... | [
"n,m,k=map(int,input().split())\n\nMOD=1000000009\n\nx=m-(n//k*(k-1)+(n%k))\n\nif (x<=0):exit(print(m%MOD))\n\nprint(((m-x)+((pow(2,x+1, MOD)+2*MOD)-2)*k-x*(k-1))%MOD)",
"MOD = 1000000009\nn, m, k = map(int, input().split())\nx = m - (n // k * (k - 1) + n % k)\n\nif x <= 0:\n print(m)\nelse:\n print(((m - x... | {"inputs": ["5 3 2", "5 4 2", "300 300 3", "300 282 7", "1000000000 1000000000 1000000000", "1000000000 800000000 2", "2 0 2", "2 1 2", "2 2 2", "3 2 2", "3 3 2", "10 7 3", "10 8 3", "10 8 5", "10 9 5", "972 100 2", "972 600 2", "972 900 2", "972 900 4", "972 900 5", "12345 11292 3", "120009 70955 2", "120009 100955 2"... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
d38fb1c489d4cbf930b0337c192c450b | Interactive LowerBound | This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to *x*.
More formally, there is a singly liked list built on an array of *n* elements. Element with index *i* contains two integers: *value**i* ... | [
"from random import sample\nfrom sys import stdout\n\nread=lambda :map(int,input().split())\n\ndef ask(x):\n\tprint('? {}'.format(x))\n\tstdout.flush()\n\treturn tuple(read())\n\ndef answer(x):\n\tprint('! {}'.format(x))\n\tstdout.flush()\n\texit(0)\n\nn,st,x=read()\n\na=[ask(st)]\nif a[0][0]>=x: answer(a[0][0])\n\... | {"inputs": ["5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4", "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1", "1 1 0\n0 -1", "1 1 2\n0 -1", "1 1 1000000000\n0 -1", "5 3 3\n3 5\n2 1\n0 4\n1 2\n4 -1", "5 3 145337745\n619347297 5\n344132479 1\n122841322 4\n169280018 2\n740666615 -1", "5 3 315433300\n411188472 5\n316581280 1\n200698791 4\n31488... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
d39d202a68a2cf02ae6f18f45fddeaca | Renting Bikes | A group of *n* schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.
The renting site offered them *m* bikes. The renting price is different for different bikes, renting the *j*-th bike costs *p**j* rubles.
In total, the boys' shared budget is *a* rubles. Besides, each of them ha... | [
"n, m, a = map(int, input().split())\nB = [int(x) for x in input().split()]\nP = [int(x) for x in input().split()]\nB.sort()\nP.sort()\n\ndef f(a):\n need = 0\n for i in range(a):\n need += max(0, P[i] - B[n - a + i])\n return need\n\nl = 0\nr = min(n + 1, m + 1)\nwhile r - l > 1:\n mid = (l + r)... | {"inputs": ["2 2 10\n5 5\n7 6", "4 5 2\n8 1 1 2\n6 3 7 5 2", "1 1 2\n1\n2", "4 1 1\n3 2 3 2\n3", "1 4 1\n3\n2 4 5 5", "3 3 3\n1 1 2\n3 5 6", "4 5 6\n5 1 7 2\n8 7 3 9 8", "4 8 10\n2 1 2 2\n10 12 10 8 7 9 10 9", "8 4 18\n9 4 2 2 7 5 1 1\n11 12 8 9", "6 6 2\n6 1 5 3 10 1\n11 4 7 8 11 7", "10 10 7\n6 7 15 1 3 1 14 6 7 4\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
d39f143028f8d494421257e9610a63a2 | Inna and Choose Options | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | [
"T=int(input())\n\nwhile T>=1:\n T-=1\n a=input()\n list=[]\n for i in range(1,13):\n if 12 % i==0:\n l=12//i\n for j in range(0,l):\n for k in range(0,i):\n if a[k*l+j]!='X':\n break\n else:\n ... | {"inputs": ["4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX", "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX"], "outputs": ["3 1x12 2x6 4... | UNKNOWN | PYTHON3 | CODEFORCES | 92 | |
d3cc84d8a4738925b046a983cf21b4b1 | Left-handers, Right-handers and Ambidexters | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | [
"def li():\r\n return list(map(int,input().split()))\r\ndef gi(n):\r\n return [list(map(int,input().split())) for _ in range(n)]\r\n\r\n# File input\r\n\r\n# import sys\r\n# sys.stdin = open('user.txt','r')\r\n\r\nl,r,a = li()\r\n\r\nif max(l,r) - min(l,r) > a:\r\n print((min(l,r)+a) * 2)\r\nelse:\r\n p... | {"inputs": ["1 4 2", "5 5 5", "0 2 0", "30 70 34", "89 32 24", "89 44 77", "0 0 0", "100 100 100", "1 1 1", "30 70 35", "89 44 76", "0 100 100", "100 0 100", "100 1 100", "1 100 100", "100 100 0", "100 100 1", "1 2 1", "0 0 100", "0 100 0", "100 0 0", "10 8 7", "45 47 16", "59 43 100", "34 1 30", "14 81 1", "53 96 94",... | UNKNOWN | PYTHON3 | CODEFORCES | 404 | |
d3d3a53758643400bf3241186c9e43bb | Regular Bridge | An undirected graph is called *k*-regular, if the degrees of all its vertices are equal *k*. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.
Build a connected undirected *k*-regular graph containing at least one bridge, or else state that su... | [
"import math\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nk = int(input())\r\nif k == 1:\r\n ans = [\"YES\", \"2 1\", \"1 2\"]\r\nelif not k % 2:\r\n ans = [\"NO\"]\r\nelse:\r\n ans = [\"YES\"]\r\n n = 2002\r\n e = [\"1 1001\", \"1002 2002\", \"1001 200... | {"inputs": ["1", "3", "11", "10", "2", "4", "5", "6", "7", "8", "9", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
d3de88c38870d2f1361cde69bf370df5 | Partial Teacher | A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same mar... | [
"import math\r\nfrom collections import Counter, defaultdict\r\nfrom itertools import accumulate\r\n\r\nR = lambda: map(int, input().split())\r\nn = int(input())\r\ns = input()\r\ndp = [[0] * 1005 for i in range(n + 1)]\r\nfor i in range(1, 1001):\r\n dp[0][i] = i\r\ndp[0][1001] = math.inf\r\nfor i in range(n):\... | {"inputs": ["5\nLRLR", "5\n=RRR", "6\nRLRL=", "3\nR=", "7\nRR==RR", "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==", "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
d3e51e02198078824b0169caf85d97d6 | Till I Collapse | Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*.
Rick and Morty are gathering their army and they want to divide Mr. Meese... | [
"import sys\r\nbase = 1 << 17\r\ndef get(x, v=1, cl=0, cr=base):\r\n if x >= t[v]:\r\n return cr\r\n if cl + 1 == cr:\r\n return cl\r\n cc = (cl + cr) // 2\r\n if x >= t[v * 2]:\r\n return get(x - t[v * 2], v * 2 + 1, cc, cr)\r\n else:\r\n return get(x, v * 2, cl, cc)\r\nd... | {"inputs": ["5\n1 3 4 3 3", "8\n1 5 7 8 1 7 6 1", "10\n4 1 2 6 8 5 3 9 3 9", "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28 27 5 6 79 43 78 45 64 61 56 12 40 54 52 24 14 26 65 75 72 30 46 67 80 38 70 25 60 50 8 17 84 41 71 58 76 19 47 73 29 3 48 82 33 39 63 15 37 83 36 9 32 16 57 68 53 21 77 2... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
d3e540e3910727f7dcf520e39d57d44d | Irrational problem | Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*.
It is a pity that Petya forgot the order in which the remainders should be taken and wr... | [
"import sys,math,string,bisect\ninput=sys.stdin.readline\nfrom collections import deque\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\np1,p2,p3,p4,b,a=M()\nk=min(p1,p2,p3,p4)\nc=0\nfor i in range(b,min(k,a+1)):\n c+=1\np... | {"inputs": ["2 7 1 8 2 8", "20 30 40 50 0 100", "31 41 59 26 17 43", "1 2 3 4 0 0", "1 2 3 4 1 1", "1 2 999 1000 30 40", "17 18 19 20 17 20", "17 18 19 20 16 20", "41 449 328 474 150 709", "467 329 936 440 117 700", "258 811 952 491 931 993", "823 431 359 590 153 899", "292 370 404 698 699 876", "442 705 757 527 868 89... | UNKNOWN | PYTHON3 | CODEFORCES | 63 | |
d41eccdddbe3022c0a46f60c8badcf60 | Abbreviation | You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co... | [
"# https://codeforces.com/contest/1003\n\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\nn = int(input())\ns = input()\n\n# word list\nw = s.split()\n\n# dict: word to index\nwd = {}\nfor x in w:\n if x not in wd:\n wd[x] = len(wd)\n\n# number of distinct words\nnw = len(wd)\n\n... | {"inputs": ["6\nto be or not to be", "10\na ab a a b ab a a b c", "6\naa bb aa aa bb bb", "45\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of", "250\nf r s d b f f k d e k v m b t k k j t t a o m m s n d w l v g e k x d w k v a j h c a g x s d e t z z w q z ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
d44b54a5c176b8db281df28c230f992d | Beautiful Numbers | Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite dig... | [
"import sys, threading\nimport math\nfrom os import path\nfrom collections import deque, defaultdict, Counter\nfrom bisect import *\nfrom string import ascii_lowercase\nfrom functools import cmp_to_key\nfrom random import randint\nfrom heapq import *\nfrom array import array\nfrom types import GeneratorType\n \n \n... | {"inputs": ["1 3 3", "2 3 10", "6 8 14215", "4 9 104671", "6 7 78755", "1 8 265", "3 9 37413", "1 7 49055", "3 4 11028", "2 6 32377", "3 5 80791", "4 8 11857", "1 3 10785", "4 6 11808", "1 2 11857", "2 4 88193", "1 4 37226", "2 5 53049", "3 6 1000000", "7 9 999999", "8 9 999999", "3 8 1000000", "2 8 999999", "1 6 99769... | UNKNOWN | PYTHON3 | CODEFORCES | 54 | |
d45fb32c9fa52c71f3024a033629d604 | Shift It! | There is a square box 6<=×<=6 in size. It contains 36 chips 1<=×<=1 in size. Those chips contain 36 different characters — "0"-"9" and "A"-"Z". There is exactly one chip with each character.
You are allowed to make the following operations: you may choose one of 6 rows or one of 6 columns and cyclically shift the chip... | [
"ls=\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\ns,cnt,a1,a2=[],0,[],[]\nfor i in range(6):\n\ts.append(list(input()))\n\ndef add(c,i):\n\tglobal cnt\n\tcnt+=1\n\ta1.append(c)\n\ta2.append(i)\n\ndef right(i):\n\tadd('R',i+1)\n\ttmp=s[i][5]\n\tfor j in range(5,0,-1):\n\t\ts[i][j]=s[i][j-1]\n\ts[i][0]=tmp\n\ndef left(i)... | {"inputs": ["01W345\n729AB6\nCD8FGH\nIJELMN\nOPKRST\nUVQXYZ", "012345\n6789AB\nCDEFGH\nIJKLMN\nOPQRST\nUVWXYZ", "102345\n6789AB\nCDEFGH\nIJKLMN\nOPQRST\nUVWXYZ", "234501\n789AB6\nGHCDEF\nIJKLMN\nRSTOPQ\nZUVWXY", "2X4501\n6783AB\nDE9GHC\nIJKFMN\nOPQLST\nZUVWRY", "0123A5\n67894B\nCDEFGH\nIKJLMN\nOPQRST\nUVWXZY", "ZYXWVU\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d4606777a789a26895f0e249ec9f7499 | Kyoya and Permutation | Let's define the permutation of length *n* as an array *p*<==<=[*p*1,<=*p*2,<=...,<=*p**n*] consisting of *n* distinct integers from range from 1 to *n*. We say that this permutation maps value 1 into the value *p*1, value 2 into the value *p*2 and so on.
Kyota Ootori has just learned about cyclic representation of a ... | [
"#!/usr/bin/python3\n\narr = [1] * 51\n\nfor i in range(2, 51):\n arr[i] = arr[i - 1] + arr[i - 2]\n\nans = []\n\n\ndef generate(i, n, to):\n if i == n:\n assert to == 1\n print(\" \".join(map(str, ans)))\n return\n if i + 1 == n:\n ans.append(n)\n generate(i + 1, n, to)\... | {"inputs": ["4 3", "10 1", "1 1", "50 1", "10 57", "50 20365011074", "20 9999", "49 12586269025", "49 1", "10 89", "10 1", "5 8", "5 1", "25 121393", "25 1", "1 1", "2 2", "3 3", "4 2", "5 8", "6 10", "7 20", "8 24", "9 1", "10 24", "11 77", "12 101", "13 240", "14 356", "15 463", "16 747", "17 734", "18 1809", "19 859... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
d462df4068f05173ec26a6fb99d24783 | Right Triangles | You are given a *n*<=×<=*m* field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).
... | [
"n,m=map(int,input().split())\r\nc,r=[0]*n,[0]*m\r\nvals=[]\r\nfor i in range(n):\r\n s=input()\r\n vals.append(s)\r\n for j in range(m):\r\n if(s[j]=='*'):\r\n c[i]+=1\r\n r[j]+=1\r\nans=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if(vals[i][j]=='*'):\r\n ... | {"inputs": ["2 2\n**\n*.", "3 4\n*..*\n.**.\n*.**", "3 2\n..\n..\n*.", "1 2\n**", "1 3\n*.*", "5 2\n*.\n**\n.*\n..\n.*", "2 3\n...\n..*", "10 9\n..*..**..\n*.*...**.\n.*...*.*.\n.*****.*.\n.*.*.**.*\n.**.*....\n**.......\n**..*.*.*\n*.*.**.*.\n*.*.*.*.*", "2 3\n.*.\n**.", "5 3\n**.\n..*\n*.*\n*.*\n*..", "4 2\n**\n**\n.... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
d4718bd75cf416c1554ff23d9d429005 | About Bacteria | Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tub... | [
"def mikroby(k, b, n, t):\r\n z = 1\r\n while z <= t:\r\n z = k * z + b\r\n n -= 1\r\n return max(n + 1, 0)\r\n\r\n\r\nK, B, N, T = [int(i) for i in input().split()]\r\nprint(mikroby(K, B, N, T))\r\n",
"entrada=input().split(\" \")\r\nlistae = list(map(int, entrada))#Convertir strs a int\r\... | {"inputs": ["3 1 3 5", "1 4 4 7", "2 2 4 100", "1 2 3 100", "10 10 10 123456", "847 374 283 485756", "37 1 283475 8347", "1 1 1 1", "1 1 1 1000000", "1 1 1000000 1", "1 1 1000000 1000000", "1 1000000 1 1", "1 1000000 1 1000000", "1 1000000 1000000 1", "1 1000000 1000000 1000000", "1000000 1 1 1", "1000000 1 1 1000000",... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
d475b1db315b445f2e098c807d2d52c1 | New Skateboard | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | [
"a= input()\nans = 0\nfor i in range(len(a)-1,-1,-1):\n\tif(not int(a[i])%4):\n\t\tans+=1\n\tif ( i>0 and not int(a[i-1:i+1])%4):\n\t\tans+= i\n\nprint(ans)\n\t \t\t \t\t \t\t \t \t \t \t\t \t\t",
"s = input()\r\nres = 0\r\n\r\nfor i in range(1, len(s)) :\r\n if int(s[i-1 : i+1]) % 4 == 0 :\r\n res... | {"inputs": ["124", "04", "5810438174", "1", "039", "97247", "5810438174", "12883340691714056185860211260984431382156326935244", "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "801246490140549710812136081378174660462546524926277418604782585582063971131982328238598... | UNKNOWN | PYTHON3 | CODEFORCES | 270 | |
d484895805b8041afab5927ffdb460e2 | New Year Candles | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | [
"a,b=map(int,input().split())\r\nc=int(a-1)/(b-1)\r\nprint(int(a+c))\r\n",
"a, b = map(int, input().split())\r\nres = 0\r\nwhile a >= b:\r\n a += 1 - b\r\n res += b\r\nres += a\r\nprint(res)",
"a, b = tuple(int(i) for i in input().split())\r\nc = 0\r\ntotal = 0\r\nflag = True\r\n\r\nwhile flag:\r\n tot... | {"inputs": ["4 2", "6 3", "1000 1000", "123 5", "1000 2", "1 2", "1 3", "1 4", "2 2", "3 2", "3 3", "999 2", "1000 3", "1000 4", "1 1000", "80 970", "80 970", "80 970", "80 970", "80 970", "80 970", "10 4", "4 3", "91 5", "777 17", "100 4", "5 3", "6 4", "26 8", "9 4", "20 3", "17 3"], "outputs": ["7", "8", "1001", "15... | UNKNOWN | PYTHON3 | CODEFORCES | 472 | |
d499e64d29c12399b541b19d5ace8193 | Chat | There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to... | [
"n, k = (int(s) for s in input().split())\r\na = [0] + [int(s) for s in input().split()]\r\nans = [0,]\r\n\r\nfor i in range(1, n + 1):\r\n if not a[i]:\r\n ans.append( min(i - 1, k) + 1 + min(n - i, k) )\r\n else:\r\n if a[i] + k < i - k:\r\n ans.append( min(i - 1, k) + 1 + min(n - i... | {"inputs": ["6 0\n0 1 1 2 3 2", "10 1\n0 1 0 3 4 5 2 3 7 0", "2 2\n0 1", "1 1\n0", "5 2\n0 1 2 3 1", "30 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 0 0 0 0 0 2 1 0", "100 5\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33... | UNKNOWN | PYTHON3 | CODEFORCES | 52 | |
d4adf413afcc5e9f6dbc13ec73736099 | Vowels | Iahubina is tired of so many complicated languages, so she decided to invent a new, simple language. She already made a dictionary consisting of *n* 3-words. A 3-word is a sequence of exactly 3 lowercase letters of the first 24 letters of the English alphabet (*a* to *x*). She decided that some of the letters are vowel... | [
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nN=int(readline())\r\ndp=[0]*(1<<24)\r\ndp[-1]=N\r\nfor _ in range(N):\r\n bit=(1<<24)-1\r\n for a in readline().rstrip():\r\n a=ord(a)-97\r\n if bit&1<<a:\r\n bit^=1<<a\r\n dp[bit]-=1\r\nfor i in range(24):\r\n for bit in range((... | {"inputs": ["5\nabc\naaa\nada\nbcd\ndef", "100\namd\namj\natr\nbcp\nbjm\ncna\ncpj\ncse\ndij\ndjp\ndlv\nebk\nedf\nelw\nfbr\nfcl\nfhs\nflo\nfmj\ngcg\ngen\nghg\ngvb\ngxx\nhbe\nhbf\nhgu\nhlv\nhqa\nibg\nifp\nima\nitt\nivl\nixu\njle\njli\nket\nkit\nkws\nlep\nles\nleu\nmbp\nmci\nmdv\nmhf\nmih\nmll\nmop\nndp\nnfs\nngl\nnng\noi... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d4bcfbf18441008f1ac0b108ef216426 | Cow Program | Farmer John has just given the cows a program to play with! The program contains two integer variables, *x* and *y*, and performs the following operations on a sequence *a*1,<=*a*2,<=...,<=*a**n* of positive integers:
1. Initially, *x*<==<=1 and *y*<==<=0. If, after any step, *x*<=≤<=0 or *x*<=><=*n*, the program ... | [
"n = int(input())\r\nt = [0, 0] + list(map(int, input().split()))\r\na, b = [0] * (n + 1), [0] * (n + 1)\r\na[1] = b[1] = -1\r\n \r\ndef f(s, a, b, l):\r\n global t\r\n l.reverse()\r\n j, n = 0, len(l)\r\n while True:\r\n s += t[l[j]]\r\n a[l[j]] = s\r\n j += 1\r\n if j ==... | {"inputs": ["4\n2 4 1", "3\n1 2", "5\n2 2 1 3", "2\n1", "8\n7 6 2 6 2 6 6", "8\n4 5 3 2 3 3 3", "3\n1 1", "5\n3 2 4 2", "92\n79 52 17 45 47 64 48 49 650617238 32 9 74 12 80 39 41 73 22 25 73 79 51 85 21 3 56 255371563 2 986959075 17 30 70 577324422 84 7 39 85 18 6 63 44 52 37 5 36 9 12 34 9 60 56 1 491072951 57 7 91 76... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
d4c9f2251593a3c8a9c4136b405c21e0 | Runner's Problem | You are running through a rectangular field. This field can be represented as a matrix with 3 rows and *m* columns. (*i*,<=*j*) denotes a cell belonging to *i*-th row and *j*-th column.
You start in (2,<=1) and have to end your path in (2,<=*m*). From the cell (*i*,<=*j*) you may advance to:
- (*i*<=-<=1,<=*j*<=+<=1... | [
"L = 3\r\nM = 10**9 + 7\r\niden = [[0] * L for _ in range(L)]\r\nfor i in range(L):\r\n iden[i][i] = 1\r\ndef mat_multiply(a, b):\r\n n = len(a)\r\n ret = [[0] * n for _ in range(n)]\r\n for i in range(n):\r\n for j in range(n):\r\n for k in range(n):\r\n ret[i][j] = (re... | {"inputs": ["2 5\n1 3 4\n2 2 3", "50 100\n3 24 49\n2 10 12\n1 87 92\n2 19 60\n2 53 79\n3 65 82\n3 10 46\n1 46 86\n2 55 84\n1 50 53\n3 80 81\n3 66 70\n2 35 52\n1 63 69\n2 65 87\n3 68 75\n1 33 42\n1 56 90\n3 73 93\n2 20 26\n2 42 80\n2 83 87\n3 99 99\n1 14 79\n2 94 97\n1 66 85\n1 7 73\n1 50 50\n2 16 40\n2 76 94\n1 71 98\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
d4e0927d80d36c92d3c5e2af89871259 | Forming Teams | One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then stud... | [
"import sys\r\nfrom typing import Callable\r\nfrom collections import defaultdict, deque\r\nfrom enum import Enum\r\n\r\nAlGraph = dict[int, list[int]]\r\n\r\n\r\nclass Flags(Enum):\r\n UNVISITED = -1\r\n VISITED = - 2\r\n\r\n\r\ndef flood_fill(graph: AlGraph, node: int, state: list[int], n: int) -> int:\r\n ... | {"inputs": ["5 4\n1 2\n2 4\n5 3\n1 4", "6 2\n1 4\n3 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "5 1\n1 2", "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1", "28 3\n15 3\n10 19\n17 25", "2 1\n1 2", "3 1\n2 3", "3 2\n1 2\n3 2", "3 3\n1 2\n1 3\n2 3", "4 1\n1 4", "4 2\n4 1\n2 1", "4 3\n1 3\n3 2\n2 4", "4 3\n3 2\n4 2\n4 3", "5 3... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
d4eccfcdc4a1ce493b2358cdc4f24618 | Cableway | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | [
"import math\r\n\r\nm = 0\r\np = 0\r\nfor pos, i in enumerate(map(int, input().split())):\r\n if math.ceil(i/2) >= m:\r\n m = math.ceil(i/2)\r\n p = pos\r\n\r\nres = 0\r\nm -= 1\r\nwhile m > 0:\r\n res += 3\r\n m -= 1\r\n\r\nprint(res + p + 30)",
"\r\nl = [int(s) + 1 for s in input().split(... | {"inputs": ["1 3 2", "3 2 1", "3 5 2", "10 10 10", "29 7 24", "28 94 13", "90 89 73", "0 0 1", "0 0 2", "0 1 0", "0 1 1", "0 1 2", "0 2 0", "0 2 1", "0 2 2", "1 0 0", "1 0 1", "1 0 2", "1 1 0", "1 1 1", "1 1 2", "1 2 0", "1 2 1", "1 2 2", "2 0 0", "2 0 1", "2 0 2", "2 1 0", "2 1 1", "2 1 2", "2 2 0", "2 2 1", "2 2 2", ... | UNKNOWN | PYTHON3 | CODEFORCES | 133 | |
d4f238414fd52248994773b270d7e1bb | Routine Problem | Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio *a*:*b*. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio *c*:*d*. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on ... | [
"from math import gcd\r\nn=input().split()\r\nmovie_ratio=int(n[2])/int(n[3])\r\nscreen_ratio=int(n[0])/int(n[1])\r\nif movie_ratio>screen_ratio:\r\n i=0\r\nelse:\r\n i=1\r\ny=int(n[1-i])*int(n[i+2])-int(n[i])*int(n[3-i])\r\nif y!=0:\r\n z=int(n[i+2])*int(n[1-i])\r\n g=gcd(y,z)\r\n print(str(int(y/g)... | {"inputs": ["1 1 3 2", "4 3 2 2", "3 4 2 3", "4 4 5 5", "1 1 1 1", "1000 1000 1000 1000", "125 992 14 25", "999 998 997 996", "984 286 976 284", "999 1000 1000 999", "999 1000 998 999", "1 1000 1000 1", "1 999 1000 1", "50 80 6 3", "114 891 20 3", "10 13 75 57", "21 35 34 51", "41 95 82 30", "123 150 82 60", "100 175 1... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
d4f7e1eed1a5f669bc061ada8368101c | Merge Equals | You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two... | [
"\nn = int(input())\nnumbers = list(map(int,input().split()))\npos = {}\ni=0\nremoved = 0\nwhile i<n:\n\n if numbers[i] not in pos or pos[numbers[i]] == -1:\n pos[numbers[i]] = i\n i+=1\n else:\n numbers[pos[numbers[i]]] = -1\n pos[numbers[i]] = -1\n numbers[i] *= 2\n ... | {"inputs": ["7\n3 4 1 2 2 1 1", "5\n1 1 3 1 1", "5\n10 40 20 50 30", "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 11 14 14 14 15 10 10 15 15 13 13 15 10 12 14 10 12 13 11 15 11 13 14 12 10 12 11 14 13 15 13 15 13 14 14 11 12 13 11 14 10 10 15 10 15 12 15 12 13 10... | UNKNOWN | PYTHON3 | CODEFORCES | 44 | |
d4fcaa5a12e174eeb47b6b1519863b94 | Initial Bet | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program ... | [
"def main():\r\n v = [int(i) for i in input().split()]\r\n s = sum(v)\r\n if s % 5 == 0 and s != 0:\r\n print(s // 5)\r\n else:\r\n print(-1)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"a, b, c, d, e=map(int, input().split())\r\nsum=a+b+c+d+e\r\nif(sum%5==0 and sum!=0):\r\n ... | {"inputs": ["2 5 4 0 4", "4 5 9 2 1", "0 0 0 0 0", "1 2 1 2 3", "100 0 0 0 0", "2 3 4 5 6", "1 1 1 1 1", "0 1 2 3 4", "100 100 100 100 100", "93 100 99 90 98", "99 99 99 99 99", "99 98 98 99 100", "43 83 1 0 23", "43 83 1 100 23", "57 83 11 4 93", "87 38 19 33 100", "56 0 0 0 4", "0 0 0 0 1", "99 100 100 100 100"], "ou... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
d505dd4a88f3b77f441d522c3490d39d | Well played! | Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also ha... | [
"from sys import stdin,exit\n\n#Parsea una línea\ndef parser():\n return map(int, stdin.readline().split())\n\n#Recibiendo los valores de n, a y b\nn,a,b=parser()\n\n#Máximo de hechizos de tipo 2 que tiene sentido utilizar\nb=min(b,n)\n\n#Inicializando las listas de vida y daño\nhp=[]\ndmg=[]\n\n#Recibiendo los ... | {"inputs": ["2 1 1\n10 15\n6 1", "3 0 3\n10 8\n7 11\n5 2", "1 0 0\n2 1", "1 0 200000\n1 2", "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88", "7 6 7\n11 75\n61 90\n22 14\n100 36\n29 48\n69 52\n16 3", "7 8 7\n88 29\n30 44\n14 1\n83 95\n73 88\n10 42\n29 26", "12 7 7\n78 189\n614 271\n981 510\n37 762\n803 106\n78 3... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
d50bdeed886902a60096918dfa119f35 | Order Book | In this task you need to process a set of stock exchange orders and use them to create order book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ... | [
"n, s = map(int, input().split())\r\npricesell = dict()\r\npricebuy = dict()\r\nsellp = set()\r\nbuyp = set()\r\nfor i in range(n):\r\n tmp = input().split()\r\n if tmp[0] == \"B\":\r\n if int(tmp[1]) in buyp:\r\n pricebuy[int(tmp[1])] += int(tmp[2])\r\n else:\r\n pricebuy[... | {"inputs": ["6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "2 1\nB 7523 5589\nS 69799 1711", "1 1\nB 48259 991", "1 50\nB 47828 7726", "1 1\nS 95992 7257", "1 50\nS 72218 8095", "2 50\nB 758 9290\nS 86168 3367", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905", "6 2\nB 0 1\nS 1 1\nS 1 1\nS 1 1\nB 0 1\nB 0 1", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 30 | |
d51744512d657fc8c49daa2a291bf799 | Property | Bill is a famous mathematician in BubbleLand. Thanks to his revolutionary math discoveries he was able to make enough money to build a beautiful house. Unfortunately, for not paying property tax on time, court decided to punish Bill by making him lose a part of his property.
Bill’s property can be observed as a convex... | [
"n = int(input())\r\na = input().split()\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\nb = []\r\nfor i in range(0, n-1):\r\n b.append((a[i]-(n-a[i+1]), i))\r\nb.append((a[n-1]-(n-a[0]), n-1))\r\nb = sorted(b)\r\nans = n*[0]\r\nfor i in range(n):\r\n # the line segment at index b[i][1]\r\n ans[b[i][1]] =... | {"inputs": ["3\n0 1 2", "10\n0 1 2 3 4 5 6 7 8 9", "10\n1 7 3 6 8 2 4 5 0 9", "10\n4 9 7 2 3 5 6 1 8 0", "5\n1 2 3 0 4", "5\n3 0 2 1 4", "5\n2 4 3 0 1", "17\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "17\n5 13 12 8 4 7 15 6 0 1 2 10 9 14 3 16 11", "17\n7 10 12 11 13 0 9 6 4 2 15 3 5 8 14 16 1", "50\n15 14 37 47 44 7 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d536f2dd4edadb347b7f5b76e5bebc9f | Shower Line | Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory... | [
"from itertools import permutations\r\nfrom sys import stdin,stdout\r\ninput=stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\na=[1,2,3,4,5] ; arr=[] ; ans=0 ; pet=list(permutations(a,5))\r\nfor i in range(5):\r\n arr.append(list(map(int,input(... | {"inputs": ["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0", "0 4 2 4 9\n6 0 2 5 0\n2 5 0 6 3\n6 3 3 0 10\n0 3 1 3 0", "0 65 90 2 32\n69 0 9 97 67\n77 97 0 16 84\n18 50 94 0 63\n69 12 82 16 0", "0 70 10 0 0\n70 0 50 90 0\n10 50 0 80 0\n0 90 ... | UNKNOWN | PYTHON3 | CODEFORCES | 44 | |
d58e0be64698471a23413eaf7d77d0a6 | Subway Innovation | Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only *k* of the currently existing *n* subway stations.
The subway stations are located on a straight... | [
"from sys import stdin\r\n\r\nn = int(stdin.readline())\r\na = [int(x) for x in stdin.readline().split()]\r\na = sorted([(a[x],str(x+1)) for x in range(n)])\r\nk = int(stdin.readline())\r\n\r\nsums = [0]\r\nfor x in a:\r\n sums.append(sums[-1]+x[0])\r\n\r\ntotal = 0\r\ns = 0\r\n\r\nfor x in range(k):\r\n tota... | {"inputs": ["3\n1 100 101\n2", "5\n11 21 30 40 50\n3", "3\n0 -4 -3\n2", "4\n5 -7 8 1\n2", "5\n-4 -2 10 -9 -10\n2", "6\n9 8 4 -4 -6 -8\n2", "7\n10 -6 0 -5 -2 -8 7\n2", "5\n-10 -5 3 4 -3\n3", "6\n8 -7 1 5 -8 4\n3", "7\n-5 1 3 2 -9 -1 -4\n3", "100\n237 -708 796 -645 75 387 992 343 -219 -696 777 -722 844 -409 6 989 39 -151... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d5a66051eeab79f22b63335aaf627de6 | Pocket Book | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | [
"if __name__ == \"__main__\":\r\n modulo=10**9+7\r\n n,m=map(int,input().split())\r\n names=[]\r\n\r\n for i in range(n):\r\n names.append(input().strip())\r\n \r\n res=1\r\n for j in range(m):\r\n unique_col_char_count=0\r\n tmp_arr=[]\r\n for i in range(n):\r\n ... | {"inputs": ["2 3\nAAB\nBAA", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "1 1\nE", "2 2\nNS\nPD", "3 4\nPJKD\nNFJX\nFGFK", "4 5\nSXFMY\nATHLM\nKDDQW\nZWGDS", "20 14\nJNFKBBBJYZHWQE\nLBOKZCPFNKDBJY\nXKNWGHQHIOXUPF\nDDNRUKVUGHWMXW\nMTIZFNAAFEAPHX\nIXBQOOHEULZYHU\nMRCSREUEOOMUUN\nHJTSQWKUFYZDQU\nGMCMUZCOPRVEIQ\nXBKKGGJECOBLTH\nXXH... | UNKNOWN | PYTHON3 | CODEFORCES | 184 | |
d5a92f290c7eb0059d54b3a0e3c0ae3e | Ilya and Matrix | Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2*n*<=×<=2*n*-sized matrix and 4*n* integers. You need to arrange all these numbers in the matrix (put each number in a single i... | [
"n = int(input())\r\nA = list(map(int, input().split()))\r\nA.sort(reverse=True)\r\nif n == 1:\r\n print(A[0])\r\nelse:\r\n res = 0\r\n i = 1\r\n while(i <= n):\r\n res += sum(A[0: i])\r\n i *= 4\r\n print(res)"
] | {"inputs": ["1\n13", "4\n1 2 3 4", "16\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621", "16\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d5d2dd5f9cafc5c383631833e295d5a4 | Pasha and Tea | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | [
"n, w = map(int, input().split())\r\ncup = list(map(int, input().split()))\r\ncup.sort()\r\n\r\nif (cup[n] >= 2*cup[0]):\r\n ans = min(w, 3*cup[0]*n)\r\n print(ans)\r\nelse:\r\n ans = min(w, 3*(cup[n]/2)*n)\r\n print(ans)\r\n",
"n, w = map(int, input().split())\r\na = list(map(int, input().split()))\r... | {"inputs": ["2 4\n1 1 1 1", "3 18\n4 4 4 2 2 2", "1 5\n2 3", "1 1\n1000000000 1000000000", "4 1000000000\n1 1 1 1 1 1 1 1", "4 1000000000\n1 1 1 1 2 2 2 2", "4 1\n3 3 3 3 4 4 4 4", "2 19\n3 3 5 5", "3 31\n3 3 3 5 5 5", "5 15\n2 3 4 1 2 4 5 3 5 10", "5 14\n2 3 4 1 2 4 5 3 5 10", "5 16\n2 3 4 1 2 4 5 3 5 10", "1 100\n1 2... | UNKNOWN | PYTHON3 | CODEFORCES | 183 | |
d607231391bb9d0f6146c5ed8354c0e9 | Logical Expression | You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of:
- Operation AND ('&', ASCII code 38) - Operation OR ('|', ASCII code 124) - Operation NOT ('!', ASCII code 33) -... | [
"import zlib, base64\nexec(zlib.decompress(base64.b64decode(b'eJyFV8lu2zAQPTdfIenAUGhR9FygXxLk4MJu4SJwAscJSIEfX4nLzHtDpT0kGM6+j3w83IYfw8M0BhemL8M0+pBiWuYMBzdGtwjYgMUpWGRWtnFJq6Srkh7g4JqSjW9Jm3wKjdYohIzALkivfuX/m02nYBUJ2ZNVLjZPAM5hrFTR5BFGasLg/RbOvPniIsSU0AXAtMgMnanRShPVFx+QA+jRad5CyWhoMUbIqCBL0RII5jSZd+Fg+sLB7dpNWO... | {"inputs": ["4\n00110011\n00000111\n11110000\n00011111", "1\n11001110", "2\n11001110\n01001001", "3\n10001001\n10111011\n10111101", "4\n11000010\n11000010\n11001110\n10001001", "5\n01111000\n00110110\n00011100\n01110111\n01010011"], "outputs": ["y\n(y|z)&x\n!x\nx|y&z", "!y|!z&x", "!y|!z&x\n!(!x&!z|x&z|y)|x&y&z", "!y&!z... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
d6120d945ca2dd06ce7ce99e1cd247bb | Door Frames | Petya has equal wooden bars of length *n*. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length *a* and one top side of length *b*. A solid (i.e. continuous without breaks) piece of bar is needed for each side.
Determine a minimal number of wooden bars which are ne... | [
"import math\n\n[n,a,b],r,i,j=[int(input())for x in range(3)],6,4,5\n\nwhile i>=0:\n\n\tl,c,o=[b if x in[i,j]else a for x in range(6)],0,n\n\n\tfor k in l:\n\n\t\tif o<k:\n\n\t\t\to,c=n-k,c+1\n\n\t\telse:o-=k\n\n\tr=min(r,c if o==n else c+1)\n\n\tj-=1\n\n\tif i==j:i,j=i-1,5\n\nprint(r)\n\n\n\n# Made By Mostafa_Khal... | {"inputs": ["8\n1\n2", "5\n3\n4", "6\n4\n2", "20\n5\n6", "1\n1\n1", "3\n1\n2", "3\n2\n1", "1000\n1\n1", "1000\n1000\n1000", "1000\n1\n999", "1000\n1\n498", "1000\n1\n998", "31\n5\n6", "400\n100\n2", "399\n100\n2", "800\n401\n400", "141\n26\n11", "717\n40\n489", "293\n47\n30", "165\n59\n40", "404\n5\n183", "828\n468\n72... | UNKNOWN | PYTHON3 | CODEFORCES | 25 | |
d62618023e53f0985f2111be3942064e | Bayan Bus | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of *k* participants who should be picked up at the airport. When a... | [
"n = int(input())\nA = []\nA.append(list('+------------------------+'))\nA.append(list('|#.#.#.#.#.#.#.#.#.#.#.|D|)'))\nA.append(list('|#.#.#.#.#.#.#.#.#.#.#.|.|'))\nA.append(list('|#.......................|'))\nA.append(list('|#.#.#.#.#.#.#.#.#.#.#.|.|)'))\nA.append(list('+------------------------+'))\nfor k in ra... | {"inputs": ["9", "20", "30", "5", "0", "1", "2", "3", "4", "6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "21", "22", "23", "24", "25", "26", "27", "28", "29", "31", "32", "33", "34"], "outputs": ["+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......... | UNKNOWN | PYTHON3 | CODEFORCES | 63 | |
d63bc03ec2d750bf0a79a037180d8b83 | Yaroslav and Permutations | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the nu... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\nok = True\r\nfor val in a:\r\n if a.count(val) > (n+1)//2:\r\n ok = False\r\n break\r\n\r\nprint('YES' if ok else 'NO')",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\n\r\nfor i in a:\r\n if a.count(i)*2>n+1:\r\n pr... | {"inputs": ["1\n1", "3\n1 1 2", "4\n7 7 7 7", "4\n479 170 465 146", "5\n996 437 605 996 293", "6\n727 539 896 668 36 896", "7\n674 712 674 674 674 674 674", "8\n742 742 742 742 742 289 742 742", "9\n730 351 806 806 806 630 85 757 967", "10\n324 539 83 440 834 640 440 440 440 440", "7\n925 830 925 98 987 162 356", "68\n... | UNKNOWN | PYTHON3 | CODEFORCES | 440 | |
d6450d9766b2a425003aff887bf2eda8 | Pyramid of Glasses | Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is *n*. The top level consists of only 1 glass, that stands on 2 glasses on the second level (... | [
"#!/usr/bin/env python\n# coding: utf-8\n\n# In[24]:\n\n\nclass Solution:\n def fillCups(self, idx, array, level,volume):\n if(idx>=len(array) or volume == 0):\n return\n array[idx]+=volume\n if(array[idx]<1):\n return \n volume = array[idx]-1\n array[idx]... | {"inputs": ["3 5", "4 8", "1 1", "10 10000", "1 10000", "10 1", "1 0", "10 0", "10 1022", "10 1023", "10 1024", "1 2", "1 200", "7 128", "8 198", "2 2", "2 3", "2 4", "2 100", "2 10000", "3 7", "3 6", "3 8", "3 12", "3 1", "4 15", "4 14", "4 10", "4 16", "4 999", "4 9", "5 31", "5 30", "5 28", "5 25", "5 15", "5 32", "... | UNKNOWN | PYTHON3 | CODEFORCES | 39 | |
d6524006b988fe4a1c2e7fe334ad52cc | Jabber ID | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | [
"import re\r\n\r\ns = input()\r\nreg = re.compile(r'^\\w{1,16}@(\\w{1,16}\\.)*\\w{1,16}(/\\w{1,16})?$')\r\n \r\nif reg.match(s):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")",
"import re\r\n \r\nreg = re.match(r'^\\w{1,16}@(?P<host>(\\w{1,16}\\.)*\\w{1,16})(/\\w{1,16})?$', input())\r\nif reg and len(reg.group(... | {"inputs": ["mike@codeforces.com", "john.smith@codeforces.ru/contest.icpc/12", "test@test.ri/abacaba", "@ops", "this-is-the-test", "mike@codeforces.commike@codeforces.com", "oooop/oooop", "w@S8/XU.5._R7fHq.@../e.WP!54Ey1L\u007f.9jv", "lNC9D1L5U@.L!_!CcAOEEx.0z.aiW/S430sbQT", "@/YTd.K1@lD", "Fyi!d1l@.OesGopTnRn.81xdSb8q... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
d6a099aefd615f395445dd46e03cae87 | Noldbach problem | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | [
"import math\r\ndef isprime(k):\r\n for i in range (2, int(math.sqrt(k)+1)):\r\n if(k%i==0):\r\n return 0\r\n return 1\r\n\r\nn,k = map(int, input().split())\r\ncount = 0\r\nlis = []\r\nfor i in range(2, n+1):\r\n if(isprime(i)):\r\n lis.append(i)\r\nfor i in range (0, len(lis)-1):... | {"inputs": ["27 2", "45 7", "2 0", "15 1", "17 1", "34 5", "37 4", "43 5", "47 7", "50 5", "57 6", "60 8", "62 7", "76 9", "69 7", "113 10", "141 11", "207 16", "231 18", "296 19", "332 20", "378 24", "428 23", "497 27", "640 32", "798 35", "802 35", "864 40", "953 44", "995 44", "1000 44", "1000 0", "1000 1000", "2 10... | UNKNOWN | PYTHON3 | CODEFORCES | 238 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.