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 |
|---|---|---|---|---|---|---|---|---|---|
dfd3423b46d9ac875c40fdb6e3391bae | Vasya and Basketball | Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of *d* meters, and a throw is worth 3 points if the distance is larger t... | [
"def merge(l1,l2):\r\n p1 = 0\r\n p2 = 0\r\n l = []\r\n while ((p1 < len(l1)) and (p2 < len(l2))):\r\n if l1[p1] < l2[p2]:\r\n l.append(l1[p1])\r\n p1 += 1\r\n else:\r\n l.append(l2[p2])\r\n p2 += 1\r\n if p1 < len(l1):\r\n l.extend(l1[... | {"inputs": ["3\n1 2 3\n2\n5 6", "5\n6 7 8 9 10\n5\n1 2 3 4 5", "5\n1 2 3 4 5\n5\n6 7 8 9 10", "3\n1 2 3\n3\n6 4 5", "10\n1 2 3 4 5 6 7 8 9 10\n1\n11", "10\n1 2 3 4 5 6 7 8 9 11\n1\n10", "3\n1 2 3\n3\n1 2 3", "3\n1 2 3\n3\n3 4 5", "4\n2 5 3 2\n4\n1 5 6 2", "2\n3 3\n3\n1 3 3", "3\n1 1 1\n4\n1 3 1 1", "4\n4 2 1 1\n4\n3 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
dfdb6ca43f21c375705818cab533efac | Follow Traffic Rules | Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro... | [
"import math\r\ndef getdt():\r\n return map(int, input().split())\r\ndef calc(v0, v, a, x):\r\n t = (v - v0) / a\r\n x0 = v0 * t + 0.5 * a * t * t\r\n if x0 >= x:\r\n return (x, (math.sqrt(v0 * v0 + 2 * a * x) - v0) / a)\r\n return (x0, t)\r\ndef go(v0, v, a, x):\r\n x0, t = calc(v0, v, a, ... | {"inputs": ["1 1\n2 1 3", "5 70\n200 170 40", "6 80\n100 50 10", "7 80\n100 50 50", "8 80\n100 50 199", "200 1000\n3 2 1", "200 1000\n3 2 10000", "200 1000\n1000 500 1023", "200 1000\n1000 999 10", "20 40\n10000 1 30", "20 40\n10000 799 30", "20 40\n9958 9799 30", "9998 9999\n3 2 1", "9998 9999\n3 2 6580", "9998 9999\n... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
dff35cfccaed3049a7d8dbccfbbaef3d | Divisibility | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018).... | [
"print((lambda x : (x[2]//x[0])-((x[1]-1)//x[0]))(list(map(int,input().split()))))",
"k,a,b = list(map(int,input().split(\" \")))\r\na -= 1\r\nprint(b//k-a//k)",
"inD = str(input()).split()\r\ninD = [int(val) for val in inD]\r\nk = inD[0]\r\na = inD[1]\r\nb = inD[2]\r\nN = 0\r\na = a - k if a % k == 0 else a - ... | {"inputs": ["1 1 10", "2 -4 4", "1 1 1", "1 0 0", "1 0 1", "1 10181 10182", "1 10182 10183", "1 -191 1011", "2 0 0", "2 0 1", "2 1 2", "2 2 3", "2 -1 0", "2 -1 1", "2 -7 -6", "2 -7 -5", "2 -6 -6", "2 -6 -4", "2 -6 13", "2 -19171 1911", "3 123 456", "3 124 456", "3 125 456", "3 381 281911", "3 381 281912", "3 381 281913... | UNKNOWN | PYTHON3 | CODEFORCES | 89 | |
e002199dc05266707d905a6b35037cc1 | Multiplication Table | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | [
"n,x=map(int,input().split())\r\n\r\nans=0\r\n\r\nfor i in range(1,n+1):\r\n if x%i==0 and x//i<=n:\r\n ans+=1 \r\nprint(ans)",
"n,x=map(int,input().split())\r\ndem=0\r\nif x==1:\r\n print(\"1\")\r\n exit()\r\nfor i in range(1,n+1):\r\n if x%i==0 and int(x/i)<=n :\r\n dem=dem+1\r\nprint(dem)",
"... | {"inputs": ["10 5", "6 12", "5 13", "1 1", "2 1", "100000 1", "1 1000000000", "100000 1000000000", "100000 362880", "1 4", "9 12", "10 123", "9551 975275379", "17286 948615687", "58942 936593001", "50000 989460910", "22741 989460910", "22740 989460910", "100000 989460910", "100000 98280", "100000 997920", "100000 72072... | UNKNOWN | PYTHON3 | CODEFORCES | 257 | |
e01325cc3bb47d387ca422ff653548a6 | none | Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams!
Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe... | [
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, w, m = map(int, input().split())\r\nw = float(w)\r\neps = 1e-9\r\nreq = n * w / m\r\ncup = [req] * m\r\nans = [[] for _ in range(m)]\r\nj = 0\r\n\r\nfor i in range(n):... | {"inputs": ["2 500 3", "4 100 5", "4 100 7", "5 500 2", "4 100 8", "1 1000 2", "2 500 4", "2 500 5", "9 1000 12", "20 1000 30", "50 1000 50", "50 1000 49", "49 1000 50", "40 1000 50", "48 1000 50", "45 1000 50", "30 1000 40", "20 1000 25", "21 1000 27", "21 1000 28", "21 1000 29", "22 1000 30", "3 356 14", "9 120 13", ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
e01e94d3d663c0ea8272b045a34e994b | Post Lamps | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are bloc... | [
"n, m, k = map(int, input().split())\r\nfree = [True] * n\r\nfor i in list(map(int, input().split())):\r\n free[i] = False\r\na = list(map(int, input().split()))\r\nlast_lamp = [-1] * n\r\nfor i in range(n):\r\n if free[i]:\r\n last_lamp[i] = i\r\n if i > 0 and not free[i]:\r\n last_lamp[i] =... | {"inputs": ["6 2 3\n1 3\n1 2 3", "4 3 4\n1 2 3\n1 10 100 1000", "5 1 5\n0\n3 3 3 3 3", "7 4 3\n2 4 5 6\n3 14 15", "1 0 1\n\n1000000", "1 1 1\n0\n1000", "3 2 3\n1 2\n1 1 1000000", "3 0 3\n\n333 500 1001", "3 0 3\n\n334 500 1001", "6 2 3\n2 3\n1 1 3", "9 4 3\n3 4 7 8\n1 1 1", "11 4 6\n3 4 5 6\n1000000 1000000 1000000 100... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e0304ed0a9986c1e8d9720575bb720bb | Alena's Schedule | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it... | [
"n = int(input())\r\na = list(map(int,input().split()))\r\nif a.count(0)==len(a):\r\n print(0)\r\n quit()\r\nwhile a[0]==0:\r\n a.pop(0)\r\nwhile a[-1]==0:\r\n a.pop(-1)\r\nx = len(a)\r\nfor i in range(x):\r\n if a[i]==0:\r\n if a[i-1]==1 and a[i+1]==1:\r\n a[i]=1\r\nprint(sum(a))",... | {"inputs": ["5\n0 1 0 1 1", "7\n1 0 1 0 0 1 0", "1\n0", "1\n1", "2\n0 0", "2\n0 1", "2\n1 0", "2\n1 1", "10\n0 0 0 0 0 0 0 0 0 0", "9\n1 1 1 1 1 1 1 1 1", "11\n0 0 0 0 0 0 0 0 0 0 1", "12\n1 0 0 0 0 0 0 0 0 0 0 0", "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0", "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0... | UNKNOWN | PYTHON3 | CODEFORCES | 171 | |
e032edaee261e97dbb910310c3e107a9 | Ternary Logic | Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the *xor* operation is performed on this computer (and whether there is anything like ... | [
"a, c = list(map(int, input().split()))\r\nad = [0] * 20\r\nan = 0\r\ncd = [0] * 20\r\ncn = 0\r\n\r\nwhile a != 0:\r\n ad[an] = a % 3\r\n an += 1\r\n a //= 3\r\n\r\nwhile c != 0:\r\n cd[cn] = c % 3\r\n cn += 1\r\n c //= 3\r\n\r\ntor = 0\r\nfor i in range(max(an, cn) - 1, -1, -1):\r\n tor = tor ... | {"inputs": ["14 34", "50 34", "387420489 225159023", "5 5", "23476 23875625", "11111 10101010", "1 23865354", "0 0", "2376234 0", "1 0", "581130733 0", "581131733 1", "0 1000000000", "1000000000 0", "1000000000 100000000", "956747697 9487", "229485033 8860", "5341 813849430", "227927516 956217829", "390 380875228", "33... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
e0332eac78721837186baef3409b2d7d | Vile Grasshoppers | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh... | [
"\nfrom math import sqrt\np,y = map(int,input().split())\ndef is_prime(n, p):\n if n % 2 == 0 and n > 2:\n return False\n if p == 2: return True\n for x in range(3, min(p, int(sqrt(n))) + 1, 2):\n if n % x == 0:\n return False\n return True\n\nfor i in range(y, p,-1):\n if is... | {"inputs": ["3 6", "3 4", "2 2", "5 50", "944192806 944193066", "1000000000 1000000000", "2 1000000000", "28788 944193066", "49 52", "698964997 734575900", "287894773 723316271", "171837140 733094070", "37839169 350746807", "125764821 234689174", "413598841 430509920", "145320418 592508508", "155098216 476450875", "459... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
e047d6f8c864250517f98173e0289925 | Prairie Partition | It can be shown that any positive integer *x* can be uniquely represented as *x*<==<=1<=+<=2<=+<=4<=+<=...<=+<=2*k*<=-<=1<=+<=*r*, where *k* and *r* are integers, *k*<=≥<=0, 0<=<<=*r*<=≤<=2*k*. Let's call that representation prairie partition of *x*.
For example, the prairie partitions of 12, 17, 7 and 1 are:
17<... | [
"from collections import Counter\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndef get(cnt):\r\n c = Counter(a)\r\n last = []\r\n while c[1] and (cnt is None or len(last) < cnt):\r\n x = 1\r\n while c[x]:\r\n c[x] -= 1\r\n x *= 2\r\n last.appen... | {"inputs": ["8\n1 1 2 2 3 4 5 8", "6\n1 1 1 2 2 2", "5\n1 2 4 4 4", "20\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 8 8 10 10 11", "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2", "25\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 8 13 15 16 16 31 32 36 41 55", "25\n1 1 1 1 2 2 2 2 4 4 4 4 8 8 8 9 16 16 32 40 43 53 61 64 128", "45\n1 1 1 1 1 2 2 2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
e06260a867da74744d2211c1c54a8ad6 | Barcode | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | [
"inf = 9999999999\r\n\r\ndef f(ll,n,m,x,y):\r\n W = [0]*m #White\r\n for i in range(n):\r\n for j in range(m):\r\n if ll[i][j]=='.':\r\n W[j] += 1\r\n B = [n-c for c in W] #Black\r\n Bw = [inf]*(y+1)\r\n Ww = [inf]*(y+1)\r\n Bw[1] = B[0]\r\n Ww[1] =... | {"inputs": ["6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..", "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#", "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#", "5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#", "5 4 1 4\n####\n..##\n##..\n..#.\n#..#", "1 1 1 2\n.", "3 4... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
e066aeeb5f5b265ec4c40aa35e1d99b3 | Easy Tape Programming | There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.
- Current character pointer (CP);... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import defaultdict\r\n\r\nN,Q = map(int, input().split())\r\nS = input()\r\nfor _ in range(Q):\r\n l,r = map(int, input().split())\r\n l-=1;r-=1\r\n \r\n ans = [0]*10\r\n\r\n s = [c for c in S[l:r+1]]\r\n idx=0\r\n ... | {"inputs": ["7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "5 2\n>>>>>\n1 5\n1 2", "1 3\n9\n1 1\n1 1\n1 1", "7 1\n0101010\n1 7", "10 30\n306<<>4>04\n2 2\n6 6\n1 10\n1 8\n2 4\n9 10\n2 8\n3 5\n7 7\n2 6\n1 3\n3 7\n4 9\n3 10\n5 9\n7 10\n1 3\n5 7\n4 10\n6 10\n6 7\n4 5\n3 4\n4 6\n4 7\n7 9\n4 6\n2 8\n1 5\n2 6", "17 21\n187<9>82<818<4229... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
e070fa09a730ded5af470dfb1b5ddf32 | Almost Identity Permutations | A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity ... | [
"n,k=map(int,input().split())\r\ndp=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)]\r\ndp_c=[[[0]*(k+1) for i in range(n+1)] for j in range(k+1)]\r\nfor i in range(1,n):\r\n dp[1][i][1]=1\r\nstore=[0,1,1,2,9]\r\nans=0\r\nfor i in range(2,k+1):\r\n add=0\r\n for j in range(1,n+1):\r\n add += dp... | {"inputs": ["4 1", "4 2", "5 3", "5 4", "200 1", "200 2", "200 3", "200 4", "400 1", "400 2", "400 3", "400 4", "600 1", "600 2", "600 3", "600 4", "800 1", "800 2", "800 3", "800 4", "1000 1", "1000 2", "1000 3", "1000 4", "4 4"], "outputs": ["1", "7", "31", "76", "1", "19901", "2646701", "584811251", "1", "79801", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 118 | |
e081729c9849ecde07bd53798955d477 | Lorry | A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b... | [
"r=lambda:map(int,input().split())\r\n[n,v]=r()\r\nt=[]\r\no=[]\r\nfor i in range(n):\r\n\t[tp,p]=r()\r\n\tif tp==1: o+=[[p,i]]\r\n\telse: t+=[[p,i]]\r\nt.sort(reverse=True)\r\no.sort(reverse=True)\r\nnt=len(t)\r\nno=len(o)\r\nfor i in range(1,nt): t[i][0]+=t[i-1][0]\r\nfor i in range(1,no): o[i][0]+=o[i-1][0]\r\na... | {"inputs": ["3 2\n1 2\n2 7\n1 3", "5 3\n1 9\n2 9\n1 9\n2 10\n1 6", "10 10\n1 14\n2 15\n2 11\n2 12\n2 9\n1 14\n2 15\n1 9\n2 11\n2 6", "20 19\n2 47\n1 37\n1 48\n2 42\n2 48\n1 38\n2 47\n1 48\n2 47\n1 41\n2 46\n1 28\n1 49\n1 45\n2 34\n1 43\n2 29\n1 46\n2 45\n2 18", "50 27\n2 93\n1 98\n2 62\n1 56\n1 86\n1 42\n2 67\n2 97\n2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
e095fc0f2706652ae0c7e6370b7eedb8 | Timetable | Ivan is a student at Berland State University (BSU). There are *n* days in Berland week, and each of these days Ivan might have some classes at the university.
There are *m* working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during *i*... | [
"\r\n \r\nfrom heapq import heapify, heappop, heappush\r\nfrom itertools import cycle\r\nfrom math import sqrt,ceil\r\nimport os\r\n\r\nimport sys\r\nfrom collections import defaultdict,deque\r\nfrom io import BytesIO, IOBase\r\n \r\nfrom collections import Counter\r\nfrom functools import lru_cache\r\nfrom c... | {"inputs": ["2 5 1\n01001\n10110", "2 5 0\n01001\n10110", "3 4 0\n0000\n0000\n0000", "3 4 12\n1111\n1111\n1111", "3 4 6\n1111\n1111\n1111", "10 10 0\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001", "10 10 5\n1000000001\n1000000001\n1000000001\n100... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
e0978618e361da10f11b0837442672c5 | Game on Tree | Momiji has got a rooted tree, consisting of *n* nodes. The tree nodes are numbered by integers from 1 to *n*. The root has number 1. Momiji decided to play a game on this tree.
The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by *v*) and removes all the ... | [
"# https://codeforces.com/problemset/problem/280/C\nfrom collections import defaultdict, deque\nimport sys\n\nnodes = int(sys.stdin.readline())\nedges = defaultdict(list)\nfor line in sys.stdin:\n a, b = line.split()\n a = int(a)\n b = int(b)\n edges[a].append(b)\n edges[b].append(a)\nbfs = deque([(1... | {"inputs": ["2\n1 2", "3\n1 2\n1 3", "10\n1 2\n2 3\n3 4\n1 5\n2 6\n6 7\n4 8\n6 9\n9 10", "6\n1 3\n2 4\n5 6\n3 6\n5 4"], "outputs": ["1.50000000000000000000", "2.00000000000000000000", "3.81666666666666690000", "2.45000000000000020000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e0a25aa6735cc7bbb4f5284e0f982675 | Watching Fireworks is Fun | A festival will be held in a town's main street. There are *n* sections in the main street. The sections are numbered 1 through *n* from left to right. The distance between each adjacent sections is 1.
In the festival *m* fireworks will be launched. The *i*-th (1<=≤<=*i*<=≤<=*m*) launching is on time *t**i* at section... | [
"class SortedList(list):\n\n def add(self, other):\n left = -1\n right = len(self)\n while right - left > 1:\n mid = (right + left) >> 1\n if other < self[mid]:\n right = mid\n else:\n left = mid\n super().insert(right, ot... | {"inputs": ["50 3 1\n49 1 1\n26 1 4\n6 1 10", "10 2 1\n1 1000 4\n9 1000 4", "30 8 2\n15 97 3\n18 64 10\n20 14 20\n16 18 36\n10 23 45\n12 60 53\n17 93 71\n11 49 85", "100 20 5\n47 93 3\n61 49 10\n14 69 10\n88 2 14\n35 86 18\n63 16 20\n39 49 22\n32 45 23\n66 54 25\n77 2 36\n96 85 38\n33 28 45\n29 78 53\n78 13 60\n58 96 6... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e0a8066c3ffaf53d1423dd8bb7537fb4 | The Brand New Function | Polycarpus has a sequence, consisting of *n* non-negative integers: *a*1,<=*a*2,<=...,<=*a**n*.
Let's define function *f*(*l*,<=*r*) (*l*,<=*r* are integer, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) for sequence *a* as an operation of bitwise OR of all the sequence elements with indexes from *l* to *r*. Formally: *f*(*l*,<=*r*)<==<=... | [
"def subarrayBitwiseOR(A):\r\n\tres = set()\r\n\tpre = {0}\r\n\tfor x in A:\r\n\t\tpre = {x | y for y in pre} | {x}\r\n\t\tres |= pre\r\n\treturn len(res)\r\nn, A = int(input()), list(map(int, input().split()))\r\nprint(subarrayBitwiseOR(A))",
"n, p, q = input(), set(), set()\nfor i in map(int, input().split()):\... | {"inputs": ["3\n1 2 0", "10\n1 2 3 4 5 6 1 2 9 10", "1\n123", "10\n6 8 4 5 1 9 10 2 3 7", "7\n1 2 4 8 16 32 64", "10\n375813 659427 484038 348181 432640 368050 271089 721588 345312 630771", "5\n0 1 2 0 4", "1\n0", "1\n1000000"], "outputs": ["4", "11", "1", "15", "28", "29", "7", "1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
e0d0422a544145c98c802c1517bec7f7 | Industrial Nim | There are *n* stone quarries in Petrograd.
Each quarry owns *m**i* dumpers (1<=≤<=*i*<=≤<=*n*). It is known that the first dumper of the *i*-th quarry has *x**i* stones in it, the second dumper has *x**i*<=+<=1 stones in it, the third has *x**i*<=+<=2, and the *m**i*-th dumper (the last for the *i*-th quarry) has *x**... | [
"import math\r\nimport time\r\nfrom collections import defaultdict,deque,Counter\r\nfrom sys import stdin,stdout\r\nfrom bisect import bisect_left,bisect_right\r\nfrom queue import PriorityQueue \r\nimport sys\r\ndef xor(x):\r\n ch=x&3\r\n if(ch==1):\r\n return 1\r\n if(ch==2):\r\n return x+1... | {"inputs": ["2\n2 1\n3 2", "4\n1 1\n1 1\n1 1\n1 1", "10\n2 3\n1 4\n5 8\n4 10\n10 8\n7 2\n1 2\n1 7\n4 10\n5 3", "20\n8 6\n6 3\n2 9\n7 8\n9 1\n2 4\n3 6\n6 3\n5 6\n5 3\n6 5\n2 10\n2 9\n6 3\n10 6\n10 10\n10 7\n3 9\n16 1\n1 3", "30\n53 12\n13 98\n21 60\n76 58\n39 5\n62 58\n73 80\n13 75\n37 45\n44 86\n1 85\n13 33\n17 50\n12 ... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
e0d62a2e04817aababe97ea9ff251c84 | Dividing the numbers | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a... | [
"def generate_list_124(s, n):\r\n lst = []\r\n for i in range(s, int(n/2) + 1, 2):\r\n lst.append(i)\r\n lst.append(n-i+s)\r\n return lst\r\n\r\ndef generate_list_3(s, n):\r\n lst = []\r\n for i in range(s, int(n/2) - 1, 2):\r\n lst.append(i)\r\n lst.append(n-i+s)\r\n l... | {"inputs": ["4", "2", "3", "5", "59998", "60000", "59991", "59989", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "59999", "59997", "59996", "59995", "59994", "59993", "59992", "59990", "100", "1000", "10001", "103", "1002", "31724", "2032", "42620", "1807... | UNKNOWN | PYTHON3 | CODEFORCES | 144 | |
e0d9b47413ecdfc4e7b25dd15d254c2c | Two Strings Swaps | You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive.
You are allowed to do the following changes:
- Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; - Choose any index $... | [
"n=int(input())\r\na=input()\r\nb=input()\r\nans=0\r\nfor i in range(n//2):\r\n seen=set()\r\n if b[i]==b[n-i-1]:\r\n if a[i]==a[n-i-1]:\r\n ans+=0\r\n else:\r\n ans+=1\r\n else :\r\n seen.add(b[i])\r\n if b[n-i-1] in seen:\r\n seen.remove(b[n-i-... | {"inputs": ["7\nabacaba\nbacabaa", "5\nzcabd\ndbacz", "1\na\nb", "5\nahmad\nyogaa"], "outputs": ["4", "0", "1", "3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
e1034fbea68dca22768a04b14ad82878 | Booking System | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*... | [
"import sys\n\n\ndef readline():\n return sys.stdin.readline().strip()\n\n\ndef read(t=int):\n s = sys.stdin.readline()\n return list(map(t, s.strip().split(' ')))\n\n\ndef readint():\n return read()[0]\n\n\ndef go():\n n = readint()\n cplist = []\n for i in range(n):\n c, p = read()\n ... | {"inputs": ["3\n10 50\n2 100\n5 30\n3\n4 6 9", "1\n1 1\n1\n1", "1\n2 1\n1\n1", "2\n10 10\n5 5\n1\n5", "2\n10 10\n5 5\n1\n10", "2\n2 100\n10 10\n1\n10", "2\n10 100\n5 90\n2\n15 20", "3\n10 10\n3 5\n5 8\n3\n3 4 10", "10\n739 307\n523 658\n700 143\n373 577\n120 433\n353 833\n665 516\n988 101\n817 604\n800 551\n10\n431 425... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
e12509b906dd993ec3ead38d458dc7f9 | Maximize Sum of Digits | Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
The first line contains the positive integer *x* (1<=≤<=*... | [
"print((lambda s:max([(sum(map(int,s)),int(s))]+[(lambda t:(float(\"-inf\"),)if s[t]==\"0\" else(lambda x:(sum(map(int,str(x))),x))(int(s[:t]+str(int(s[t])-1)+\"9\"*(len(s)-1-i))))(i)for i in range(len(s))])[1])(input()))\r\n",
"a=input()\r\nans=[sum(map(int,a)),a]\r\nfor i in range(len(a)-1,-1,-1):\r\n b=... | {"inputs": ["100", "48", "521", "1", "2", "3", "39188", "5", "6", "7", "8", "9", "10", "59999154", "1000", "10000", "100000", "1000000", "10000000", "100000000", "1000000000", "10000000000", "100000000000", "1000000000000", "10000000000000", "100000000000000", "1000000000000000", "10000000000000000", "10000000000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
e130bca7c9717c52c141f6eb021a0626 | Delete from the Left | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | [
"string1 = input()\r\nstring2 = input()\r\nsame = 0\r\nminn = min(len(string1),len(string2))\r\nfor i in range(minn):\r\n if string1[-1-i]==string2[-1-i]:\r\n same += 2\r\n else:\r\n break\r\nprint((len(string1)+len(string2))-same)",
"s=input();s1=input()\r\nsl,s1l=len(s),len(s... | {"inputs": ["test\nwest", "codeforces\nyes", "test\nyes", "b\nab", "z\nz", "abacabadabacaba\nabacabadacaba", "z\na", "ama\nsama", "aaabc\nbc", "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "ahmedaly\naly", "aa\na", "aa\nba", "cccba\nba", "a\nab", "dadc\ndddc", "aacaaab\nb", "dddc\ncdcde", "bbdab\ndab", "a\naa", "aa\nab", "code... | UNKNOWN | PYTHON3 | CODEFORCES | 233 | |
e13a6e6f6d8c190168588e4e23f98439 | DZY Loves Strings | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | [
"s = input()\r\nk = int(input())\r\nw = list(map(int, input().split()))\r\n\r\nn = len(s)\r\ndlt = ord('a')\r\nans = 0\r\nfor i in range(n):\r\n #print((i + 1) * w[ord(s[i]) - dlt])\r\n ans += (i + 1) * w[ord(s[i]) - dlt]\r\nm = max(w)\r\nfor i in range(n + 1, n + k + 1):\r\n #print(m * i)\r\n ans += m ... | {"inputs": ["abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 69... | UNKNOWN | PYTHON3 | CODEFORCES | 420 | |
e1478fe113da588a61423b6304a9e4dc | Godsend | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | [
"n = int(input())\r\na = list(map(int,input().split()))\r\nk = sum(a)\r\nif k%2 == 1:\r\n print('First')\r\nelse:\r\n found = False\r\n for x in a:\r\n if x % 2 == 1:\r\n found = True\r\n break\r\n if found:\r\n print('First')\r\n else:\r\n print('Second')",... | {"inputs": ["4\n1 3 2 3", "2\n2 2", "4\n2 4 6 8", "5\n1 1 1 1 1", "4\n720074544 345031254 849487632 80870826", "1\n0", "1\n999999999", "2\n1 999999999", "4\n3 3 4 4", "2\n1 2", "8\n2 2 2 1 1 2 2 2", "5\n3 3 2 2 2", "4\n0 1 1 0", "3\n1 2 2", "6\n2 2 1 1 4 2", "8\n2 2 2 3 3 2 2 2", "4\n2 3 3 4", "10\n2 2 2 2 3 1 2 2 2 2"... | UNKNOWN | PYTHON3 | CODEFORCES | 223 | |
e14b7011b3fe8a743e826ee023646996 | Kitahara Haruki's Gift | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | [
"n = int(input())\nw = [int(x) for x in input().split()]\nones = sum([1 if x==100 else 0 for x in w])\ntwos = sum([1 if x==200 else 0 for x in w])\nif (ones*100+twos*200)%200 !=0:\n print(\"NO\")\nelse:\n need = (ones*100 + twos*200)//2\n ans = False\n for i in range(twos+1):\n if 200*i <= need a... | {"inputs": ["3\n100 200 100", "4\n100 100 100 200", "1\n100", "1\n200", "2\n100 100", "2\n200 200", "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 20... | UNKNOWN | PYTHON3 | CODEFORCES | 102 | |
e182ab5da357b6cd08d11902dd0b81d8 | Cats Transport | Zxr960115 is owner of a large farm. He feeds *m* cute cats and employs *p* feeders. There's a straight road across the farm and *n* hills along the road, numbered from 1 to *n* from left to right. The distance between hill *i* and (*i*<=-<=1) is *d**i* meters. The feeders live in hill 1.
One day, the cats went out to ... | [
"def solve(A, B, C):\r\n N = len(B) + 1\r\n M = len(C)\r\n \r\n a = [0] * N\r\n for i in range(1, N):\r\n a[i] += a[i - 1] + B[i - 1]\r\n \r\n b = [0] * M\r\n s = [0] * M\r\n dp = [0] * M\r\n k = [0] * M\r\n \r\n for i in range(M):\r\n b[i] = C[i][1] - a[C[i][0] - 1... | {"inputs": ["4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12"], "outputs": ["3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e186d5e1fd55287a9b94b5ef95540968 | Distances to Zero | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The secon... | [
"n = int(input())\r\nln = list(map(int, input().split()))\r\n\r\nzeros = []\r\nzeros.append(10**6)\r\nfor i, item in enumerate(ln):\r\n if item == 0:\r\n zeros.append(i)\r\nzeros.append(10**6)\r\n\r\n\r\n# 1 4 0 5\r\nj = 0\r\nres = [0]*n\r\nfor i in range(n):\r\n if ln[i] == 0:\r\n j += 1\r\n ... | {"inputs": ["9\n2 1 0 3 0 0 3 2 4", "5\n0 1 2 3 4", "7\n5 6 0 1 -2 3 4", "1\n0", "2\n0 0", "2\n0 1", "2\n1 0", "5\n0 1000000000 1000000000 1000000000 1000000000", "5\n-1000000000 -1000000000 0 1000000000 1000000000", "5\n-1000000000 1000000000 1000000000 1000000000 0", "15\n1000000000 -1000000000 -1000000000 1000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 109 | |
e1c5ad14b20dbf5c26e55715bcabf8fe | Blog Photo | One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the *height*<=/<=*width* quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2*x* for ... | [
"import math\r\nh,w = map(int,input().split())\r\nif h/w>=0.8 and h/w<=1.25 and ((math.log(h,2)%1==0) or (math.log(w,2)%1==0)):\r\n print(h,w)\r\nelse:\r\n w1 = 2**(math.log(w,2)//1)\r\n h1 = min(h,(w1*1.25)//1)\r\n h2 = 2**(math.log(h,2)//1)\r\n w2 = min(w,(h2*1.25)//1)\r\n if (h1/w1>=0.8 and h1/... | {"inputs": ["2 1", "2 2", "5 5", "9 10", "15 13", "47 46", "99 100", "939 887", "4774 4806", "39271 49032", "483242 484564", "4939191 4587461", "9909199 9945873", "49829224 49889315", "49728622 49605627", "49934587 49239195", "48298903 49928606", "49874820 49474021", "48945079 49798393", "99692141 99232337", "998557701... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
e1c6638094e6ffa59cfa504b3bf9c472 | Year of University Entrance | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | [
"n = int(input())\r\ng = list(map(int, input().split()))\r\nprint(sum(g) // n)\r\n",
"def main():\r\n groups = int(input())\r\n years = [int(x) for x in input().split()]\r\n years.sort()\r\n if groups == 1:\r\n print(years[0])\r\n elif groups == 3:\r\n print(years[1])\r\n elif grou... | {"inputs": ["3\n2014 2016 2015", "1\n2050", "1\n2010", "1\n2011", "3\n2010 2011 2012", "3\n2049 2047 2048", "5\n2043 2042 2041 2044 2040", "5\n2012 2013 2014 2015 2016", "1\n2045", "1\n2046", "1\n2099", "1\n2100", "3\n2011 2010 2012", "3\n2011 2012 2010", "3\n2012 2011 2010", "3\n2010 2012 2011", "3\n2012 2010 2011", "... | UNKNOWN | PYTHON3 | CODEFORCES | 202 | |
e1d1777c58d7782a80342ff92b03a1c9 | Zublicanes and Mumocrates | It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on *n* main squares of the capital of Berland. Each of the *n* squares certainly can have demonstrations of only one party, otherwise it could lead to r... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef make_graph(n, m):\r\n x, s = [0] * (2 * m), [0] * (n + 3)\r\n for i in range(0, 2 * m, 2):\r\n u, v = map(int, input().split())\r\n s[u + 2] += 1\r\n s[v + 2] += 1\r\n x[i], x[i + 1] = u,... | {"inputs": ["8\n1 4\n2 4\n3 4\n6 5\n7 5\n8 5\n4 5", "5\n1 2\n1 3\n1 4\n1 5", "11\n1 7\n2 1\n2 9\n6 2\n7 10\n1 3\n5 2\n3 8\n8 11\n2 4", "20\n2 18\n15 18\n18 4\n4 20\n20 6\n8 6\n1 8\n9 6\n11 9\n11 12\n19 4\n3 9\n9 7\n7 13\n10 3\n16 20\n1 5\n5 17\n10 14", "11\n9 2\n9 4\n8 9\n7 9\n3 9\n5 9\n6 9\n10 9\n1 9\n11 9", "15\n4 12... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e24711b2b5950e08097da53153bb27f7 | Curfew | Instructors of Some Informatics School make students go to bed.
The house contains *n* rooms, in each room exactly *b* students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to *n*. Init... | [
"read = lambda: map(int, input().split())\r\nn, d, b = read()\r\nd += 1\r\nt, a = 0, [0] * (n + 1)\r\nfor i, x in enumerate(read()):\r\n t += x\r\n a[i + 1] = t\r\nprint(max(i - min(a[min(n, i * d)], (a[n] - a[max(0, n - i * d)])) // b for i in range(n + 3 >> 1)))"
] | {"inputs": ["5 1 1\n1 0 0 0 4", "6 1 2\n3 8 0 1 0 0", "5 1 1\n1 1 0 3 0", "5 1 1\n4 0 0 1 0", "2 1 1\n0 2", "100 66 30\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 25 27 15 53 29 56 30 24 50 39 39 46 4 14 44 16 55 48 15 54 25 4 44 15 29 55 22 49 52 9 2 22 15 14 33 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e252f37a5a13caef34246bf269d2c655 | Broken BST | Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree *T*:
1. S... | [
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn=int(input())\r\npar=[-1]*n\r\nleft=[-1]*n\r\nright=[-1]*n\r\na=[0]*n\r\nfor i in range(n):\r\n v,l,r=map(int,input().split())\r\n a[i]=v\r\n l-=1\r\n r-=1\r\n if l!=-2:\r\n par[l]=i\r\n left[i]=l\r\n if r!=-2:\r\n par[r]=i\r\n ... | {"inputs": ["3\n15 -1 -1\n10 1 3\n5 -1 -1", "8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1", "1\n493041212 -1 -1", "10\n921294733 5 9\n341281094 -1 -1\n35060484 10 -1\n363363160 -1 -1\n771156014 6 8\n140806462 -1 -1\n118732846 4 2\n603229555 -1 -1\n359289513 3 7\n423237010 -1 -1", "10\n911605217 ... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
e2626de63784e9b7531e6074e35aabfc | k-Tree | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | [
"#author: sushmanth\r\n\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\ninp = lambda : list(map(int,input().split()))\r\n\r\nmod = (10 ** 9) + 7\r\ndef answer():\r\n\r\n dp = [[0 , 0] for i in range(n + 1)]\r\n dp[0][0] = 1\r\n\r\n for i in range(1 , n + 1):\r\n\r\n for j in range(k , 0 , ... | {"inputs": ["3 3 2", "3 3 3", "4 3 2", "4 5 2", "28 6 3", "5 100 1", "50 6 3", "10 13 6", "20 16 14", "1 10 1", "8 11 4", "16 5 4", "5 26 17", "35 47 42", "11 6 2", "54 60 16", "47 5 1", "70 6 1", "40 77 77", "96 9 6", "52 46 4", "74 41 28", "100 100 100", "99 99 5", "100 100 1", "98 98 64", "28 74 2", "86 69 62", "9 1... | UNKNOWN | PYTHON3 | CODEFORCES | 77 | |
e28053549a307d4c6f596921d5df6f25 | Homework | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of *n* small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to... | [
"from collections import Counter\r\n\r\ns = input()\r\nk = int(input())\r\nC = sorted(Counter(s).items(), key=lambda x: -x[1])\r\n\r\nwhile k and C:\r\n ch, n = C.pop()\r\n x = min(k,n)\r\n s = s.replace(ch, '', x)\r\n k -= x\r\n\r\nprint(len(set(s)))\r\nprint(s)",
"dic = {}\ns_str = input()\nfor c in... | {"inputs": ["aaaaa\n4", "abacaba\n4", "abcdefgh\n10", "aaaaaaaaaaaaaaaaaaaa\n19", "abcdefghijjihgedcba\n0", "aababcabcdabcde\n9", "xyzuvwxyz\n4", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n99", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n0", "abcdefghijklmnopqrstuvwxyz\n... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
e28950364eeabec68304f41b59baaf3a | Yaroslav and Two Strings | Yaroslav thinks that two strings *s* and *w*, consisting of digits and having length *n* are non-comparable if there are two numbers, *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*n*), such that *s**i*<=><=*w**i* and *s**j*<=<<=*w**j*. Here sign *s**i* represents the *i*-th digit of string *s*, similarly, *w**j* represents t... | [
"p = int(1e9+7)\r\n\r\ndef solv(A,B):\r\n global p\r\n n = len(A)\r\n A = [-1 if c=='?' else int(c) for c in A]\r\n B = [-1 if c=='?' else int(c) for c in B]\r\n s = [1,0,0,0]\r\n for i in range(n):\r\n if A[i]<0 and B[i]<0:\r\n si,ai,bi,ti=10,45,45,100\r\n el... | {"inputs": ["2\n90\n09", "2\n11\n55", "5\n?????\n?????", "10\n104?3?1??3\n?1755?1??7", "10\n6276405116\n6787?352?9", "10\n0844033584\n0031021311", "10\n???0?19?01\n957461????", "10\n8703870339\n994987934?", "10\n?8?528?91?\n45??06???1", "10\n8030456630\n83406?6890", "1\n?\n?", "2\n12\n?9", "3\n??1\n?12", "3\n?12\n??1",... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e29a81b722db7b430a0a5ff0aaf2aa1f | A Map of the Cat | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal... | [
"# coding: utf-8\r\n\r\nresponse = input('9\\n')\r\n\r\nprint('grumpy') if response in ['terrible', 'worse', 'are you serious?', \"don't even\", 'no way', 'go die in a hole'] else print('normal')",
"print(9)\r\ns=input()\r\nif 'go die in a hole'==s or 'are you serious?'==s or 'terrible'==s or 'worse'==s or 'no w... | {"inputs": ["5 0 1 2 5 3 5 4 5 5", "5 5 5 6 6 7 8 9 10 11", "10 6 5 7 5 6 11 5 8 9", "7 10 8 9 6 5 5 11 5 6", "5 5 4 5 2 5 5 0 1 3", "0 4 3 5 5 5 2 1 5 5", "3 5 5 0 5 5 2 5 4 1", "5 4 5 1 5 5 0 5 2 3", "5 5 1 2 5 5 4 3 0 5", "7 10 5 5 11 6 5 9 6 8", "6 5 10 5 5 7 8 11 9 6", "5 5 5 5 5 0 4 2 3 1", "11 5 6 5 9 5 10 8 7 6... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
e2bca028d9266e692bf63ce037440cc9 | Bath Queue | There are *n* students living in the campus. Every morning all students wake up at the same time and go to wash. There are *m* rooms with wash basins. The *i*-th of these rooms contains *a**i* wash basins. Every student independently select one the rooms with equal probability and goes to it. After all students selecte... | [
"import functools,math,itertools,time\nu=functools.lru_cache(maxsize=None)\nn,m=map(int,input().split())\ns=[*map(int,input().split())]\nt=u(lambda x:1 if x<2 else x*t(x-1))\nc=u(lambda r,n:t(n)/t(r)/t(n-r))\np=u(lambda n,k:n**k)\nw=u(lambda n,k:math.ceil(n/k))\nr=u(lambda k,n:max(k,n))\nh=u(lambda i,j,l:c(l,i)*p(j... | {"inputs": ["1 1\n2", "2 2\n1 1", "2 3\n1 1 1", "7 5\n1 1 2 3 1", "10 4\n8 4 7 6", "5 5\n5 5 5 5 5", "7 4\n1 2 3 4", "50 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "30 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 20\n1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e2c2354fd6b205a5686ab9e5bc4c2f43 | Easy Number Challenge | Let's denote *d*(*n*) as the number of divisors of a positive integer *n*. You are given three integers *a*, *b* and *c*. Your task is to calculate the following sum:
Find the sum modulo 1073741824 (230).
The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=100).
Print a s... | [
"a, b , c = map(int ,input().split())\r\n\r\nli = a*b*c +1\r\nfactor = [1]*li\r\nfor i in range(2,li):\r\n for j in range(i,li,i):\r\n factor[j]+=1\r\n\r\nsm = 0\r\nfor i in range(1,a+1):\r\n for j in range(1,(b+1)):\r\n for h in range(1,(c+1)//2+1):\r\n sm += factor[i * j * h ]\r\n ... | {"inputs": ["2 2 2", "5 6 7", "91 42 25", "38 47 5", "82 29 45", "40 15 33", "35 5 21", "71 2 1", "22 44 41", "73 19 29", "76 12 17", "16 10 49", "59 99 33", "17 34 25", "21 16 9", "31 51 29", "26 41 17", "85 19 5", "36 61 45", "76 58 25", "71 48 13", "29 34 53", "72 16 41", "8 21 21", "11 51 5", "70 38 49", "13 31 33"... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
e319d416e5dc2aab18120817702c6393 | Feed with Candy | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters ab... | [
"from copy import deepcopy\r\n\r\ndef getBetter(h, a):\r\n maxi = -1\r\n im = -1\r\n for i in range(len(a)):\r\n if (h >= a[i][0]):\r\n if (maxi < a[i][1]):\r\n im = i\r\n maxi = a[i][1]\r\n return(im, maxi)\r\n\r\nn, h0 = map(int, input().split())\r\n\r\n... | {"inputs": ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5", "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2", "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1", "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4 2\n0 3 1\n0 9 2", "8 2\n0 20 3\n1 5 2\n1 4 1\n1 7 1\n0 1 3\n1 5 3\n1 7 2\n1 3 1", "9 2\n0 1 1\n1 8 2\n1 11 1\n0 9 1\n1 18 2\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
e31d0e9399172420275ca466ad9e6e90 | Old Berland Language | Berland scientists know that the Old Berland language had exactly *n* words. Those words had lengths of *l*1,<=*l*2,<=...,<=*l**n* letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each ... | [
"class Node(object):\r\n\r\n\r\n def __init__(self, char: str):\r\n self.char = char\r\n self.left = None\r\n\r\n self.right=None\r\n\r\n self.done=0\r\n self.parent=None\r\n self.len=0\r\n\r\nze=Node(\"\")\r\na=Node(\"\")\r\na.parent=ze\r\ncurr=a\r\n\r\nn=int(input())\r... | {"inputs": ["3\n1 2 3", "3\n1 1 1", "10\n4 4 4 4 4 4 4 4 4 4", "20\n6 7 7 7 7 6 7 7 7 7 7 7 7 7 7 7 7 7 6 7", "30\n9 10 8 10 10 10 10 10 7 7 10 10 10 10 10 10 10 10 10 10 9 10 10 10 10 10 10 10 4 3", "50\n10 10 10 10 10 10 9 9 10 10 9 10 10 10 10 9 8 7 8 10 10 10 7 9 10 10 9 9 9 10 10 10 9 10 10 10 10 10 9 10 10 7 8 9 ... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
e32e231b443af9f76b845068a3b5735c | Dividing Orange | One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper... | [
"l=[int(l) for l in input().split()]\r\np=[int(n) for n in input().split()]\r\nnum=0\r\nif (l[0]==1):\r\n for index in p:\r\n print(index) \r\nelse: \r\n for index in range(l[1]):\r\n word=str(p[index])\r\n for x in range(1,l[0]):\r\n num+=1 \r\n if (num not in ... | {"inputs": ["2 2\n4 1", "3 1\n2", "5 5\n25 24 23 22 21", "1 30\n8 22 13 25 10 30 12 27 6 4 7 2 20 16 26 14 15 17 23 3 24 9 5 11 29 1 19 28 21 18", "30 1\n29", "10 10\n13 39 6 75 84 94 96 21 85 71", "10 15\n106 109 94 50 3 143 147 10 89 145 29 28 87 126 110", "15 10\n126 111 12 6 28 47 51 116 53 35", "30 30\n455 723 796... | UNKNOWN | PYTHON3 | CODEFORCES | 151 | |
e34659897384fdf431133167ef516793 | Dungeons and Candies | During the loading of the game "Dungeons and Candies" you are required to get descriptions of *k* levels from the server. Each description is a map of an *n*<=×<=*m* checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if... | [
"def put():\r\n return map(int, input().split())\r\ndef diff(x,y):\r\n ans = 0\r\n for i in range(n*m):\r\n if s[x][i]!= s[y][i]:\r\n ans+=1\r\n return ans\r\ndef find(i):\r\n if i==p[i]:\r\n return i\r\n p[i] = find(p[i])\r\n return p[i]\r\ndef union(i,j):\r\n if ra... | {"inputs": ["1 1 4 1\nA\n.\nB\n.", "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "2 2 5 1\n..\nBA\n.A\nB.\n..\nA.\nAB\n.B\n..\n..", "3 3 10 2\nBA.\n..A\n.BB\nB..\n..B\n.AA\nB..\nAB.\n..A\nBAB\n.A.\n.B.\n..B\nA..\n...\n...\n.B.\nBA.\n..B\n.AB\n.B.\nB.A\n.A.\n.BA\n..B\n...\n.A.\n.AA\n..A\n.B.", "3 1 5 1\nB\nA\nB\nA\nA\nB\nA\nA\nA\... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
e34b47ed73a79f95085318930434821b | Special Olympics | A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine.
Let us remind you that a ring is a region located between two... | [
"def okay(xc, yc, rc, xr, yr, rr, Rr):\n d = ((xc-xr) ** 2 + (yc-yr) ** 2) ** 0.5\n if d + rc <= rr:\n return True\n if d >= rc + Rr:\n return True\n if d + Rr <= rc:\n return True\n return False\n\nx1, y1, r1, R1 = map(float, input().split())\nx2, y2, r2, R2 = map(float, input()... | {"inputs": ["60 60 45 55\n80 80 8 32", "60 60 45 55\n80 60 15 25", "50 50 35 45\n90 50 35 45", "0 0 50 70\n1 0 60 80", "0 0 1 2\n10 0 2 20", "31 13 22 95\n48 63 21 98", "31 40 37 76\n48 65 66 98", "-65 -81 37 76\n48 65 66 98", "41 -14 37 76\n48 65 66 98", "41 -14 16 100\n48 17 37 66", "-75 -9 20 40\n25 55 99 100", "-45... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
e3545ed51cba0620cc82f0844cfe967d | Fifa and Fafa | Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of *r* meters (this range can be chosen ... | [
"import math\r\n\r\nR, x1, y1, x2, y2 = map(int, input().split(' '))\r\ndistance = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))\r\nif distance >= R:\r\n print(x1, y1, R, sep=' ')\r\nelif x1 == x2 and y1 == y2:\r\n r = R / 2\r\n x = x1 + R / 2\r\n y = y1\r\n print(x, y, r, sep=' ')\r\nelse... | {"inputs": ["5 3 3 1 1", "10 5 5 5 15", "5 0 0 0 7", "10 0 0 0 0", "100000 100000 100000 10000 10000", "100000 -100000 100000 -10000 100000", "1 0 0 0 -1", "100000 83094 84316 63590 53480", "1 0 0 0 0", "1 0 0 -2 -2", "10 0 0 4 0", "82 1928 -30264 2004 -30294", "75 -66998 89495 -66988 89506", "11 9899 34570 9895 34565"... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
e359e5399b15238079e2f37af9c7990d | Petya and File System | Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided to calculate what folder contains most subfolders (including nested folders, nested folders of nested fo... | [
"from collections import *\nfrom sys import *\n\ntxt = stdin.readlines()\nfor i in range(len(txt)):\n txt[i] = txt[i][:-1].replace(':\\\\', ':').split('\\\\')\nfile = Counter([s[0] for s in txt])\nfolder = defaultdict(set)\nfor i in txt:\n for j in range(2, len(i)):\n folder[i[0]].add('\\\\'.join(i[1:j... | {"inputs": ["C:\\folder1\\file1.txt", "C:\\folder1\\folder2\\folder3\\file1.txt\nC:\\folder1\\folder2\\folder4\\file1.txt\nD:\\folder1\\file1.txt", "C:\\file\\file\\file\\file\\file.txt\nC:\\file\\file\\file\\file2\\file.txt", "C:\\file\\file.txt\nD:\\file\\file.txt\nE:\\file\\file.txt\nF:\\file\\file.txt\nG:\\file\\fi... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
e35b59696236a1f3116b78369f8d714a | Petya and Catacombs | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | [
"n = int(input())\ntmp = list(map(int, input().split()))\n\nt = [0] * (n + 1)\nfor x in tmp:\n t[x] = 1\n\ncount = 1\nfor i in range(n):\n if not t[i]:\n count += 1\n\nprint(count)\n",
"# _\r\n############################################################################################################... | {"inputs": ["2\n0 0", "5\n0 1 0 1 3", "7\n0 1 0 0 0 0 0", "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13", "100\... | UNKNOWN | PYTHON3 | CODEFORCES | 111 | |
e35e610ac148cf150660bb1f42980765 | Boys and Girls | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | [
"f = open('input.txt', 'r')\r\nline = f.readline()\r\nn, m = map(int, line.split())\r\nf.close()\r\n\r\nans = ''\r\ncur = 'B' if n > m else 'G'\r\n\r\nwhile n and m:\r\n ans += cur\r\n if cur == 'B':\r\n n -= 1\r\n cur = 'G'\r\n else:\r\n m -= 1\r\n cur = 'B'\r\n\r\nwhile n:\r\n... | {"inputs": ["3 3", "4 2", "5 5", "6 4", "100 1", "76 48", "100 90", "90 100", "1 98", "1 100", "56 98", "89 89", "18 94", "84 27", "1 1", "1 2", "2 1", "1 34", "46 2", "99 3", "10 100", "100 100", "1 4"], "outputs": ["GBGBGB", "BGBGBB", "GBGBGBGBGB", "BGBGBGBGBB", "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | UNKNOWN | PYTHON3 | CODEFORCES | 92 | |
e38c20558f898049bdd9d53ea518eea9 | Permutation Game | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with in... | [
"n,m=map(int,input().split())\r\nl=[]\r\nl=list(map(int,input().split()))\r\na=[-1]*(n+1)\r\ns=set()\r\nsorry = False\r\nfor i in range(1,n+1):\r\n s.add(i)\r\nfor i in range(m-1):\r\n temp = (l[i+1] + n - l[i])%n\r\n if(temp == 0):\r\n temp = n\r\n #print(temp)\r\n if(a[l[i]] == -1 and temp i... | {"inputs": ["4 5\n2 3 1 4 4", "3 3\n3 1 2", "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "6 8\n2 5 4 2 5 4 2 5", "100 1\n6", "10 5\n7 7 9 9 3", "10 20\n10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
e38dfdf946eae11efa5d9a21f3f4c2e0 | Unsorting Array | Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct ... | [
"n=int(input())\r\na=list(map(int,input().split()))\r\nb,c=sorted(a),sorted(a,reverse=True)\r\nfor i in range(n-1):\r\n if a[i]!=a[i+1]:\r\n a[i],a[i+1]=a[i+1],a[i]\r\n if a==b or a==c:\r\n a[i],a[i+1]=a[i+1],a[i]\r\n else:\r\n print(i+1,i+2)\r\n exit()\r\npr... | {"inputs": ["1\n1", "2\n1 2", "4\n1 2 3 4", "3\n1 1 1", "3\n1 2 2", "5\n1 1 1 1 2", "6\n1 2 3 3 2 1", "7\n6 5 4 3 2 1 0", "10\n1 2 1 2 1 2 1 2 1 2", "11\n1 1 1 1 1 2 2 2 2 2 1", "3\n1 2 1", "4\n562617869 961148050 596819899 951133776", "4\n562617869 596819899 951133776 961148050", "4\n961148050 951133776 596819899 5626... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
e39c2b784af5d5aba5d400fe46821f40 | Voting for Photos | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win... | [
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Mar 13 19:40:03 2016\r\n\r\n@author: Kostya S.\r\n\"\"\"\r\nfrom functools import cmp_to_key\r\nn = int(input())\r\nd = {}\r\na = [int(i) for i in input().split()]\r\nfor i,e in enumerate(a):\r\n d[e] = (i+1,1,e) if d.get(e) == None else (i+1,d[e][1] + 1,e)\r\... | {"inputs": ["5\n1 3 2 2 1", "9\n100 200 300 200 100 300 300 100 200", "1\n5", "1\n1000000", "5\n1 3 4 2 2", "10\n2 1 2 3 1 5 8 7 4 8", "7\n1 1 2 2 2 3 3", "12\n2 3 1 2 3 3 3 2 1 1 2 1", "15\n7 6 8 4 9 8 7 3 4 6 7 5 4 2 8", "15\n100 200 300 500 300 400 600 300 100 200 400 300 600 200 100", "10\n677171 677171 677171 6771... | UNKNOWN | PYTHON3 | CODEFORCES | 119 | |
e3abacc6abe0ee07cdb442dc8ff735e4 | Is This a Zebra? | A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of *n* zeros and ones, where 0 means that the corresponding column is all white, and 1 m... | [
"n = int(input())\r\na = input().split()\r\nnow = -1\r\nwhite = 0\r\nblack = 0\r\nfor i in range(n):\r\n if(int(a[i]) == 0):\r\n if(white > 0):\r\n if(now == -1):\r\n now = white\r\n elif(now != white):\r\n print(\"NO\")\r\n exit(0)\r\n ... | {"inputs": ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0", "1\n0", "1\n1", "2\n0 0", "2\n0 1", "2\n1 0", "2\n1 1", "3\n1 1 0", "7\n0 0 0 1 1 1 0", "3\n0 1 1", "3\n0 0 1", "6\n0 0 1 0 1 0", "4\n0 1 1 0", "5\n0 1 1 0 0", "4\n0 1 0 0", "5\n1 1 1 0 0", "10\n0 0 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 91 | |
e3b1fb30d6b7e49c9f8d4e32d68da69a | Little Pony and Summer Sun Celebration | Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration.
Twi... | [
"\"\"\"\n\nCodeforces Contest 259 Div 1 Problem C\n\n\n\nAuthor : chaotic_iak\n\nLanguage: Python 3.3.4\n\n\"\"\"\n\n\n\ndef main():\n\n\n\n # Read N and M from problem statement.\n\n n,m = read()\n\n\n\n # Set up an adjacency list for each vertex.\n\n edges = [[] for _ in range(n+1)]\n\n for i in r... | {"inputs": ["3 2\n1 2\n2 3\n1 1 1", "5 7\n1 2\n1 3\n1 4\n1 5\n3 4\n3 5\n4 5\n0 1 0 1 0", "2 0\n0 0", "10 10\n2 1\n2 3\n4 2\n4 5\n3 6\n5 7\n8 4\n4 9\n5 10\n4 7\n0 0 1 0 1 1 1 0 1 0", "10 10\n2 1\n3 1\n4 1\n3 5\n6 2\n5 7\n1 8\n5 9\n10 5\n7 2\n1 0 0 0 1 1 1 0 0 1", "10 10\n1 2\n1 3\n3 4\n3 5\n6 1\n7 6\n8 7\n9 7\n10 1\n2 4... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
e3bcaa6255789a6043a882a7aa399d52 | Vladik and flights | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | [
"n,a,b = map(int, input().split())\r\n\r\nstring = input()\r\n\r\nif string[a - 1] == string[b - 1]:\r\n\tprint(0)\r\nelse:\r\n\tprint(1)\r\n",
"def min_cost(a,b,l):\r\n return (l[a-1]!=l[b-1])+0\r\n\r\n\r\nn,a,b=map(int,input().split())\r\nl=input()\r\nprint(min_cost(a,b,l))\r\n",
"n, a, b = map(int, input(... | {"inputs": ["4 1 4\n1010", "5 5 2\n10110", "10 9 5\n1011111001", "7 3 7\n1110111", "1 1 1\n1", "10 3 3\n1001011011", "1 1 1\n0", "10 5 8\n1000001110", "10 1 10\n0000011111", "4 1 4\n0011", "10 3 7\n0000011111", "5 1 5\n11010", "6 1 6\n111000", "2 1 2\n01", "10 10 1\n0000011111", "6 1 6\n000111", "10 2 10\n0000011111", ... | UNKNOWN | PYTHON3 | CODEFORCES | 201 | |
e3ef0e1738a58490809dd66924789fd2 | Eleven | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | [
"s = \"\"\r\n\r\n\r\ndef fibo(i):\r\n if i == 1:\r\n return 0\r\n elif i == 2:\r\n return 0\r\n a = 0\r\n b = 1\r\n c = 0\r\n while c < i:\r\n c = a + b\r\n a = b\r\n b = c\r\n if c == i:\r\n return 0\r\n return 1\r\n\r\n\r\nfor i in range(1,... | {"inputs": ["8", "15", "85", "381", "805", "1000", "1", "2", "3", "5", "17", "49", "256", "512", "933", "61", "781", "999"], "outputs": ["OOOoOooO", "OOOoOooOooooOoo", "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo", "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOooooooo... | UNKNOWN | PYTHON3 | CODEFORCES | 455 | |
e3fe082fc38571aabd3b4f88454d51ea | Choosing The Commander | As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.
Ea... | [
"import sys\r\nfrom collections import defaultdict\r\n\r\nclass Node:\r\n\tdef __init__(self, val):\r\n\t\tself.val = val\r\n\t\tself.left = None\r\n\t\tself.right = None\r\n\r\nq = int(sys.stdin.readline())\r\nroot = Node(0)\r\n# def search(node, bit, )\r\n\r\nfor _ in range(q):\r\n\tl = list(map(int, sys.stdin.re... | {"inputs": ["5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3"], "outputs": ["1\n0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
e40684cda255dcda1121368f0af3e27d | Periodic RMQ Problem | You are given an array *a* consisting of positive integers and *q* queries to this array. There are two types of queries:
- 1 *l* *r* *x* — for each index *i* such that *l*<=≤<=*i*<=≤<=*r* set *a**i*<==<=*x*. - 2 *l* *r* — find the minimum among such *a**i* that *l*<=≤<=*i*<=≤<=*r*.
We decided that this problem is... | [
"import sys\r\nimport random\r\n\r\ninput = sys.stdin.readline\r\nrd = random.randint(10 ** 9, 2 * 10 ** 9)\r\n\r\n\r\nclass SegmentTree():\r\n def __init__(self, init, unitX, f):\r\n self.f = f # (X, X) -> X\r\n self.unitX = unitX\r\n self.f = f\r\n if type(init) == int:\r\n ... | {"inputs": ["3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "10 10\n10 8 10 9 2 2 4 6 10 1\n10\n1 17 87 5\n2 31 94\n1 5 56 8\n1 56 90 10\n1 25 93 6\n1 11 32 4\n2 20 49\n1 46 87 8\n2 14 48\n2 40 48", "10 10\n4 2 3 8 1 2 1 7 5 4\n10\n2 63 87\n2 2 48\n2 5 62\n2 33 85\n2 30 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e40c630afd73a6f1182ef69cbf40aad2 | Infinite Inversions | There is an infinite sequence consisting of all positive integers in the increasing order: *p*<==<={1,<=2,<=3,<=...}. We performed *n* swap operations with this sequence. A *swap*(*a*,<=*b*) is an operation of swapping the elements of the sequence on positions *a* and *b*. Your task is to find the number of inversions ... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef get_sum(i):\r\n s = 0\r\n while i > 0:\r\n s += tree[i]\r\n i -= i & -i\r\n return s\r\n\r\ndef add(i, x):\r\n while i < len(tree):\r\n tree[i] += x\r\n i += i & -i\r\n\r\nn = int(i... | {"inputs": ["2\n4 2\n1 4", "3\n1 6\n3 4\n2 5", "1\n1000000000 1", "5\n2 5\n6 3\n4 6\n5 4\n2 5", "4\n2 5\n4 3\n1 4\n6 2", "3\n1 3\n4 6\n5 2", "5\n1 1000000000\n2 999999999\n3 999999998\n4 999999997\n5 999999996", "30\n1 200000\n2 199999\n3 199998\n4 199997\n5 199996\n200001 399996\n200002 399997\n200003 399998\n200004 3... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
e421645e9eb603b650a8ddacc45396f5 | Jamie and Interesting Graph | Jamie has recently found undirected weighted graphs with the following properties very interesting:
- The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The su... | [
"def doit(n, m):\r\n if (n == 2):\r\n print(2, 2)\r\n print(1, 2, 2)\r\n return\r\n sp = 2\r\n mstw = 100003\r\n print(sp, mstw)\r\n print(1, n, sp)\r\n print(2, n, mstw - n + 3 - sp)\r\n for i in range(3, n):\r\n print(i, n, 1)\r\n for i in range(2, n):\r\n ... | {"inputs": ["4 4", "5 4", "2 1", "10 19", "9 18", "92 280", "89 3439", "926 31057", "753 98686", "9724 31045", "8732 93395", "80297 83088", "86549 98929", "87 109", "95 3582", "96 557", "85 3106", "98 367", "77 2344", "84 286", "100 4665", "94 350", "100 4309", "88 666", "93 4075", "100 342", "84 3482", "943 51645", "8... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
e45b65b89c65f1b5c76b0d160106837e | Little Girl and Maximum XOR | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | [
"a,b=map(int,input().split())\r\na=a^b\r\ndef setb(a):\r\n for i in range(63,-1,-1):\r\n if(a&(1<<i)):\r\n return i+1\r\n return 0\r\nz=setb(a)\r\nprint((2**z)-1)\r\n",
"x=1000000007\nfor _ in range(1):\n l,r=map(int,input().split())\n lb=str(bin(l))[2:]\n rb=str(bin(r))[2:]\n ... | {"inputs": ["1 2", "8 16", "1 1", "506 677", "33 910", "36 94", "10000000000 20000000000", "79242383109441603 533369389165030783", "797162752288318119 908416915938410706", "230148668013473494 573330407369354716", "668869743157683834 805679503731305624", "32473107276976561 588384394540535099", "632668612680440378 864824... | UNKNOWN | PYTHON3 | CODEFORCES | 54 | |
e473417d063d5db8ecc735c3ecdaf67d | Alyona and the Tree | Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call ver... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\nd = [[] for i in range(n)]\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n d[i+1].append((a-1, b))\r\n d[a-1].append((i+1, b))\r\n\r\nx = [0]*n\r\nq = [(0, 0, -1, 0)]\r\nwhile q:\r\n... | {"inputs": ["9\n88 22 83 14 95 91 98 53 11\n3 24\n7 -8\n1 67\n1 64\n9 65\n5 12\n6 -80\n3 8", "6\n53 82 15 77 71 23\n5 -77\n6 -73\n2 0\n1 26\n4 -92", "10\n99 60 68 46 51 11 96 41 48 99\n4 50\n6 -97\n3 -92\n7 1\n9 99\n2 79\n1 -15\n8 -68\n5 -84", "8\n53 41 22 22 34 95 56 24\n3 -20\n7 -56\n5 -3\n3 22\n1 37\n6 -34\n2 32", "... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
e47af8d23ee4295de6a8eeae7a68aa9d | Marina and Vasya | Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly *t* characters. Help Vasya find at least one such string.
More formally, you are given two strings *s*1, *s*2 of length *n* and number *t*. Let's denote as *f*(*a*,<=*b*) the number of characters in whi... | [
"import sys\r\ninput = sys.stdin.readline \r\n\r\nl = [chr(i + ord('a')) for i in range(26)]\r\ndef fun(a1, b1):\r\n for i in l:\r\n if(i not in [a1, b1]):\r\n return i\r\n\r\nn, t = map(int, input().split()) \r\na = input()[:-1] \r\nb = input()[:-1]\r\ns, d = 0, 0 \r\nfor i in range(n):\r\n ... | {"inputs": ["3 2\nabc\nxyc", "1 0\nc\nb", "1 1\na\na", "2 1\naa\naa", "3 1\nbcb\nbca", "4 3\nccbb\ncaab", "4 2\nacbc\nacba", "4 1\nbcbc\nacab", "4 2\nacbb\nbabc", "5 2\nabaac\nbbbaa", "5 2\nabbab\nacbab", "5 3\nbcaaa\ncbacc", "5 3\ncbacb\ncbacb", "5 1\ncbabb\nbabaa", "1 0\na\na", "2 2\nbb\ncb", "2 1\ncc\nba", "2 0\nbb\... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
e47bf94879dcfa3359e8b7621c92bda4 | Co-prime Array | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integ... | [
"def primeFactors(n):\n factors = []\n i = 2\n while n > 1:\n while n % i == 0:\n factors.append(i)\n n //= i \n i += 1\n if i * i > n : break\n if n > 1:\n factors.append(n)\n return factors\n\ndef areCoprime(n1,n2):\n n1Factors = primeFactors(n1... | {"inputs": ["3\n2 7 28", "1\n1", "1\n548", "1\n963837006", "10\n1 1 1 1 1 1 1 1 1 1", "10\n26 723 970 13 422 968 875 329 234 983", "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396", "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 133 | |
e4848ab39b32f977a4fce10003d683ec | Second-Price Auction | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | [
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nq=lst.index(max(lst))+1\r\nlst.sort()\r\np=lst[-2]\r\nprint(q,p)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nlargest = max(a)\r\nb = []\r\n\r\nfor i in range(n):\r\n if a[i] == max(a):\r\n winner = i + 1\r\n \r\nfor x ... | {"inputs": ["2\n5 7", "3\n10 2 8", "6\n3 8 2 9 4 14", "4\n4707 7586 4221 5842", "5\n3304 4227 4869 6937 6002", "6\n5083 3289 7708 5362 9031 7458", "7\n9038 6222 3392 1706 3778 1807 2657", "8\n7062 2194 4481 3864 7470 1814 8091 733", "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408", "2\n3458 1504", "50\n9237 3904 407 9... | UNKNOWN | PYTHON3 | CODEFORCES | 409 | |
e485a47b51ae09651c2a41eea8f762d7 | Looksery Party | The Looksery company, consisting of *n* staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much tim... | [
"n=int(input().strip())\r\n\r\nnums=['']+[' '+input().strip() for _ in range(n)]\r\na=[0]+list(map(int,input().split()))\r\n\r\n\r\ndef send(x):\r\n for i in range(1,n+1):\r\n if nums[x][i]=='1':\r\n a[i]-=1\r\n\r\nvis=[0]*(n+1)\r\nwhile True:\r\n for i in range(1,n+1):\r\n if not vis... | {"inputs": ["3\n101\n010\n001\n0 1 2", "1\n1\n1", "4\n1111\n0101\n1110\n0001\n1 0 1 0", "2\n11\n01\n0 2", "5\n10110\n01110\n00101\n00011\n00001\n0 0 2 2 3", "6\n100000\n010000\n001000\n000100\n000010\n000001\n1 1 1 1 1 1", "10\n1000100000\n0100000000\n0010001000\n0011000000\n0100100000\n0000010010\n1000001000\n00000001... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
e48eefa4a778a5eb4ace0e0e546e7606 | Возможно, вы знаете этих людей? | Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*.
В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую ве... | [
"d={}\r\nm,k=map(int,input().split())\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n d.setdefault(a,set()).add(b)\r\n d.setdefault(b,set()).add(a)\r\nfor x in sorted(d):\r\n s=[]\r\n for y in sorted(d):\r\n if x==y or y in d[x]: continue\r\n if len(d[x]&d[y])*100>=k*len(d[x]): s+=[str(y)]\r\n... | {"inputs": ["5 51\n10 23\n23 42\n39 42\n10 39\n39 58", "5 100\n1 2\n1 3\n1 4\n2 3\n2 4", "4 1\n1 2\n1 3\n2 3\n4 5", "10 0\n648169314 459970755\n973677547 255163231\n982998000 498743911\n959912791 891928\n404623428 891928\n474720235 271683165\n709045873 539751127\n973677547 179588015\n629049356 622519100\n624998275 9589... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
e49b35fb289302baa36a4adb166975a2 | Vitaly and Night | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | [
"n,m=list(map(int,input().split()))\r\nc=0\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n for i in range(0,len(l),2):\r\n if l[i]==0 and l[i+1]==1 or l[i]==1 and l[i+1]==1 or l[i]==1 and l[i+1]==0:\r\n c+=1\r\n i+=1\r\n #i+=1\r\nprint(c)",
"# import sys\r\n# sys.stdin=open(\"inpu... | {"inputs": ["2 2\n0 0 0 1\n1 0 1 1", "1 3\n1 1 0 1 0 0", "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1", "1 5\n1 0 1 1 1 0 1 1 1 1", "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 534 | |
e4a7a813d8c783e52c2741581652cff3 | The World is a Theatre | There are *n* boys and *m* girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly *t* actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of th... | [
"import sys\r\nfrom collections import Counter, deque\r\n\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n\r\ndef solve():\r\n n, m, k = map(int, input().split())\r\n ans = 0\r\n for i in range(4, k):\r\n if(i + 1 > k):\r\n continue\r\n b = 1\r\n for j in range(1, n+... | {"inputs": ["5 2 5", "4 3 5", "4 1 5", "7 3 6", "30 30 30", "10 10 8", "10 10 10", "10 10 20", "20 15 27", "20 20 40", "20 20 24", "4 20 20", "4 20 24", "20 3 23", "20 1 21", "20 1 5", "20 20 5", "30 30 60", "30 30 59", "30 29 55", "30 29 59", "4 30 34", "30 1 20", "30 1 31", "29 30 57", "25 30 40", "4 2 6", "5 1 6", "... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
e4b6188d84adf708fa66725c0ebe45c4 | Fox Dividing Cheese | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it... | [
"a,b=list(map(int,input().split()))\r\nc=[2,3,5]\r\nfa=[0,0,0,0,0]\r\nfb=[0,0,0,0,0]\r\nfor k in c:\r\n while a%k==0:\r\n a=a//k\r\n fa[k-1]+=1\r\nfor l in c:\r\n while b%l==0:\r\n b=b//l\r\n fb[l-1]+=1\r\nif a!=b:\r\n print(-1)\r\nelse:\r\n ans=0\r\n for i in range(5):\r\... | {"inputs": ["15 20", "14 8", "6 6", "1 1", "1 1024", "1024 729", "1024 1048576", "36 30", "100 10", "21 35", "9900 7128", "7920 9900", "576000 972000", "691200 583200", "607500 506250", "881280 765000", "800000 729000", "792000 792000", "513600 513600", "847500 610200", "522784320 784176480", "689147136 861433920", "72... | UNKNOWN | PYTHON3 | CODEFORCES | 124 | |
e4bdedea4ab7fc642876b9b634d8943e | Road Improvement | The country has *n* cities and *n*<=-<=1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to *n* inclusive.
All the roads are initially bad, but the government wants to improve the state of some roads. We will ass... | [
"import sys\r\nMODULO = int(1e9) + 7\r\ndef solve(n, p, out_stream):\r\n prod = [1] * n\r\n modpow = [0] * n\r\n for i in range(n - 1, 0, -1):\r\n j = p[i]\r\n if modpow[i] == 0 and prod[i] + 1 == MODULO:\r\n modpow[j] += 1\r\n else:\r\n prod[j] = (prod[j] * ((pro... | {"inputs": ["3\n1 1", "5\n1 2 3 4", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "29\n1 2 2 4 4 6 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28", "70\n1 2 2 4 4 6 6 8 9 9 11 11 13 13 15 15 17 17 19 19 21 22 22 24 24 26 27 27 29 29 31 31 33 34 34 36 37 37 39 39 41 42 42 44 44 46 47... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
e4ca507269f95c66d0e7b2314e214b54 | Magic Squares | The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants.
The magic square is a matrix of size *n*<=×<=*n*. The elements of this matrix are int... | [
"import sys, random\r\ndef f(b):\r\n global a\r\n a = [[0] * n for o in range(n)]\r\n\r\n for i in range(n):\r\n for j in range(n):\r\n a[i][j] = b[i * n + j]\r\n\r\n rez = 0\r\n for i in range(n):\r\n ns = 0\r\n for j in range(n):\r\n ns += a[i][j]\r\n ... | {"inputs": ["3\n1 2 3 4 5 6 7 8 9", "3\n1 0 -1 0 2 -1 -2 0 1", "2\n5 5 5 5", "2\n-1 -1 -1 -1", "3\n58 -83 72 65 -90 -2 -9 -16 -76", "3\n399 -1025 -129 -497 927 -577 479 31 -49", "3\n2 4 6 8 10 12 14 16 18", "3\n36 31 -25 3 -20 -30 8 -2 26", "3\n175 -1047 -731 -141 38 -594 -415 -278 491", "3\n-1256 74 -770 -284 -105 381... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
e4f0ceca7cea499af8cc012c2748fc43 | Mishka and Interesting sum | Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to present her with array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n* of *n* elements!
Mishka loved the array and she instantly decided to determine its beauty value, but she is too little and can't process large arrays. ... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef make_graph(n, m):\r\n x, s = [0] * (2 * m), [0] * (n + 3)\r\n for i in range(0, 2 * m, 2):\r\n u, v = map(int, input().split())\r\n s[u + 2] += 1\r\n x[i], x[i + 1] = u, v\r\n for i in range(... | {"inputs": ["3\n3 7 8\n1\n1 3", "7\n1 2 1 3 3 2 3\n5\n4 7\n4 5\n1 3\n1 7\n1 5", "10\n1 2 4 1 1 1 1 1 1 4\n55\n5 8\n3 9\n6 8\n4 6\n4 10\n2 8\n1 5\n7 8\n8 9\n7 9\n5 6\n8 10\n9 9\n2 2\n3 3\n3 7\n1 8\n2 3\n4 9\n8 8\n10 10\n1 1\n1 6\n2 4\n6 9\n3 10\n3 8\n9 10\n7 7\n3 6\n4 7\n2 10\n7 10\n3 4\n4 8\n5 9\n2 7\n6 6\n4 4\n5 10\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e51ad8620299c1b8250aa20b7d466787 | Wizards' Duel | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | [
"s=int(input())\r\np=int(input())\r\nq=int(input())\r\nprint(s*p/(p+q))",
"#input_values = input().split()\nx = int(input())\np = int(input())\nq = int(input())\nd = ((x*p) / (p+q))\nprint(d)\n\n\t\t \t\t \t\t \t\t \t\t\t\t\t \t\t \t \t \t",
"l=int(input())\r\np=int(input())\r\nq=int(input())\r\nt=1+q/p\r\... | {"inputs": ["100\n50\n50", "199\n60\n40", "1\n1\n1", "1\n1\n500", "1\n500\n1", "1\n500\n500", "1000\n1\n1", "1000\n1\n500", "1000\n500\n1", "1000\n500\n500", "101\n11\n22", "987\n1\n3", "258\n25\n431", "979\n39\n60", "538\n479\n416", "583\n112\n248", "978\n467\n371", "980\n322\n193", "871\n401\n17", "349\n478\n378", "4... | UNKNOWN | PYTHON3 | CODEFORCES | 406 | |
e51e5ab57fe3360c30220d3bf955e2d1 | Nineteen | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | [
"import math\r\ns = input()\r\ncount_n = -1\r\ncount_i = 0\r\ncount_e = 0\r\ncount_t = 0\r\n\r\nfor char in s:\r\n\tif char == 'n':\r\n\t\tcount_n += 1\r\n\telif char == 'i':\r\n\t\tcount_i += 1\r\n\telif char == 'e':\r\n\t\tcount_e += 1\r\n\telif char == 't':\r\n\t\tcount_t += 1\r\n\r\nprint(min(int(count_n / 2), ... | {"inputs": ["nniinneetteeeenn", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "nineteenineteen", "nssemsnnsitjtihtthij", "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsiei... | UNKNOWN | PYTHON3 | CODEFORCES | 119 | |
e53c2a712af419ebf3b9bcf5bb958b21 | Joysticks | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | [
"a,b = [int(x) for x in input().split(\" \")]\r\ntime = 0\r\nwhile a and b:\r\n if a==1 and b==1:\r\n break\r\n if a<b:\r\n a += 1\r\n b -= 2\r\n else:\r\n b += 1\r\n a -= 2\r\n time+=1\r\n\r\nprint(time)",
"a,b=[int(x) for x in input().split()]\r\ncount=0\r\n\r\nwhi... | {"inputs": ["3 5", "4 4", "100 100", "1 100", "100 1", "1 4", "1 1", "8 8", "7 2", "24 15", "19 30", "15 31", "14 15", "58 33", "15 25", "59 45", "3 73", "48 1", "100 25", "40 49", "85 73", "29 1", "74 25", "24 57", "23 12", "2 99", "98 2", "2 97", "30 54", "32 53", "32 54", "1 2", "2 1", "2 2", "1 3", "3 1", "1 4", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 202 | |
e5403e11236a1d22e81c748ae35e1b9f | Soldier and Cards | Two bored soldiers are playing card war. Their card deck consists of exactly *n* cards, numbered from 1 to *n*, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn ... | [
"from collections import deque\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 = open(filename, 'r')\r\n\r\n\r\ndef input():\r\n return stdin.readline().rstrip()\r\n\r\n\r\ndef print(*args, sep=' ', end='\\n'):\r\n... | {"inputs": ["4\n2 1 3\n2 4 2", "3\n1 2\n2 1 3", "5\n4 5 3 2 4\n1 1", "6\n2 6 5\n4 1 2 3 4", "7\n6 6 5 2 7 4 1\n1 3", "8\n7 2 3 1 5 6 4 8\n1 7", "9\n2 3 6\n7 9 7 8 5 2 1 4", "10\n3 7 10 8\n7 4 6 9 2 5 1 3", "3\n2 2 1\n1 3", "3\n2 3 2\n1 1", "3\n1 3\n2 2 1", "3\n1 1\n2 3 2", "3\n1 2\n2 3 1", "3\n2 3 1\n1 2", "3\n1 3\n2 1... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e5433904b208cad09a5947d4ae338fcb | Goats and Wolves | Once Vasya needed to transport *m* goats and *m* wolves from riverbank to the other as quickly as possible. The boat can hold *n* animals and Vasya, in addition, he is permitted to put less than *n* animals in the boat. If in one place (on one of the banks or in the boat) the wolves happen to strictly outnumber the goa... | [
"m, n = map(int, input().split())\n\n\ndef solve():\n global m\n global n\n f = 0\n res = 0\n if n == 1:\n print(-1)\n return\n # 特判\n if (m == 3 and n == 2) or (m == 5 and n == 3):\n print(11)\n return\n while True:\n if n >= 2*m:\n print(res+1)... | {"inputs": ["3 2", "33 3", "2 3", "100000 100000", "100000 4", "1 3", "97351 58063", "76652 89696", "2 1", "2 2", "2 4", "39600 21330", "3 1", "3 3", "3 4", "18900 52964", "4 1", "4 2", "4 3", "4 4", "4 5", "5 1", "5 2", "5 3", "5 4", "5 5", "6 6", "6 1", "6 2", "6 3", "6 4", "6 5", "99998 99998", "99998 99999", "99998... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e55e1d85467875f389fff5bfc8e13913 | Spreadsheet | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th... | [
"import math\r\n\r\ndef sys_split(sstr):\r\n\r\n nums = []\r\n ind = []\r\n\r\n n = ''\r\n c = ''\r\n for i in range(len(sstr)):\r\n\r\n if sstr[i].isdigit():\r\n if len(c):\r\n ind.append(c)\r\n c = ''\r\n n += sstr[i].lower()\r\n\r\n ... | {"inputs": ["2\nR23C55\nBC23", "1\nA1", "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9", "4\nR4C25\nR90C35\nAP55\nX83", "10\nR50C12\nR23C47\nY96\nR44C13\nR19C21\nR95C73\nBK12\nR51C74\nAY34\nR63C25"], "outputs": ["BC23\nR23C55", "R1C1", "C8\nR1C4\nB7\nI8\nI8", "Y4\nAI90\nR55C42\nR83C24", "L50\nAU23\nR96C25\nM44\nU19\nBU95\nR12C63\nBV51... | UNKNOWN | PYTHON3 | CODEFORCES | 83 | |
e56214dc9f144c4a71c86dfcd4bd0a70 | Basketball Team | As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of *n* players, all of which are GUC students. However, the team might have players belonging to differ... | [
"import math\r\nn, m, h = map(int,input().split())\r\nls = list(map(int,input().split()))\r\nif sum(ls) < n :\r\n print(-1)\r\nelse :\r\n print(\"{:.9f}\".format(1 - math.comb(sum(ls)-ls[h-1], n-1)/math.comb(sum(ls)-1, n-1)))",
"\r\nfrom collections import Counter,defaultdict,deque\r\n#from heapq import *\r... | {"inputs": ["3 2 1\n2 1", "3 2 1\n1 1", "3 2 1\n2 2", "3 2 1\n1 2", "6 5 3\n5 2 3 10 5", "7 10 6\n9 10 2 3 3 6 9 9 3 7", "17 5 1\n10 4 9 6 2", "5 8 3\n9 7 2 5 2 10 3 4", "14 8 4\n6 2 10 6 2 8 4 2", "14 9 9\n9 4 7 2 1 2 4 3 9", "46 73 68\n4 2 6 4 1 9 8 10 7 8 7 2 6 4 7 9 7 9 9 1 5 1 5 1 8 2 10 2 1 7 10 2 8 3 5 3 8 9 10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 49 | |
e56de7aaa165df18e9b6695e795b6e28 | Helpful Maths | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | [
"list = input().split(\"+\")\r\nlist.sort()\r\noutput = \"+\".join(list)\r\nprint(output)",
"nums = [int(x) for x in input().split(\"+\")]\n\nnums.sort()\n\n\nstring = \"\"\n\nfor x in nums:\n string += f\"{str(x)}+\"\nstring = string[:len(string)-1]\n\nprint(string)",
"n = input()\r\nn = n.split('+')\r\nn =... | {"inputs": ["3+2+1", "1+1+3+1+3", "2", "2+2+1+1+3", "2+1+2+2+2+3+1+3+1+2", "1+2+1+2+2+2+2+1+3+3", "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1", "1", "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1", "2+2+1+1+1+... | UNKNOWN | PYTHON3 | CODEFORCES | 952 | |
e57fcb4b4002133ee853323ff082131c | Tablecity | There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves.
Tablecity can be represented as 1000<=×<=2 grid, where every cell represents one district. E... | [
"print(1999)\r\nfor i in range(1, 1001):\r\n print(i, 1, i, 2)\r\np = 1000\r\nwhile p != 1:\r\n print(p, 1, p, 2)\r\n p-=1",
"N = 1000\r\nprint(2 * N)\r\nfor i in range(1, N + 1):\r\n print(i, 1, i, 2)\r\nfor i in range(N, 0, -1):\r\n print(i, 1, i, 2)",
"print(2000)\r\n\r\nfor i in range(1, 1001... | {"inputs": ["dummy"], "outputs": ["2000\n1 1 1 2\n2 1 2 2\n3 1 3 2\n4 1 4 2\n5 1 5 2\n6 1 6 2\n7 1 7 2\n8 1 8 2\n9 1 9 2\n10 1 10 2\n11 1 11 2\n12 1 12 2\n13 1 13 2\n14 1 14 2\n15 1 15 2\n16 1 16 2\n17 1 17 2\n18 1 18 2\n19 1 19 2\n20 1 20 2\n21 1 21 2\n22 1 22 2\n23 1 23 2\n24 1 24 2\n25 1 25 2\n26 1 26 2\n27 1 27 2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
e58e3db9d467bc1c9e9645c70d5958ed | Double Cola | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | [
"n=int(input())\na=[\"Sheldon\",\"Leonard\",\"Penny\",\"Rajesh\",\"Howard\"]\nR=1\nwhile(R*5<n):\n n-=R*5\n R*=2\nprint(a[(n-1)//R])\n\t\t\t \t \t\t \t \t \t \t\t\t \t\t\t \t\t",
"x = int(input())\r\n\r\nn=1\r\nlvl_arr = [0]\r\ndef LvL(n):\r\n lvl_arr.append(2**(n-1)*5 + lvl_arr[n-1])\r\n return lvl_a... | {"inputs": ["1", "6", "1802", "1", "2", "3", "4", "5", "10", "534", "5033", "10010", "500000000", "63", "841", "3667", "38614", "282798", "9266286", "27385966", "121580142", "5", "300", "1745", "8302", "184518", "1154414", "28643950", "159222638", "24", "505", "4425", "12079", "469726", "3961838", "57710446", "80719470... | UNKNOWN | PYTHON3 | CODEFORCES | 647 | |
e59289ccaaa19425dda3a70ff20768e5 | Memory and Crow | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | [
"n=int(input())\r\nv=[int(i) for i in input().split()]\r\nb=[v[i]+v[i+1] for i in range(n-1)]\r\nb.append(v[-1])\r\nfor i in range(n):\r\n print(b[i],end=\" \")\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nk=[]\r\nr=0\r\nfor i in range(len(l)):\r\n\tif i==len(l)-1:\r\n\t\tr=l[len(l)-1]\r\n\t\tp... | {"inputs": ["5\n6 -4 8 -2 3", "5\n3 -2 -1 5 6", "10\n13 -2 532 -63 -23 -63 -64 -23 12 10", "10\n0 0 0 0 0 0 0 0 0 0", "10\n1 -1 1 -1 1 -1 1 -1 1 -1", "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000", "10\n124 532 -642 6482 -124 952 -235 7594 34 -12... | UNKNOWN | PYTHON3 | CODEFORCES | 291 | |
e5a3243f561080c07faa1d584aa2ccae | Exam | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | [
"def odd(lst,n):\r\n for i in range(1,n+1,2):\r\n lst.append(i)\r\n \r\ndef even(lst,n):\r\n start=2\r\n if len(lst)==1 or n==3:\r\n start=4\r\n for j in range(start,n+1,2):\r\n lst.append(j) \r\n\r\nn=int(input())\r\nlst=[]\r\n\r\nif n%2==0 and n>2:\r\n ... | {"inputs": ["6", "3", "1", "2", "4", "5", "7", "8", "9", "10", "13", "16", "25", "29", "120", "128", "216", "729", "1111", "1597", "1777", "2048", "2999", "3001", "4181", "4990", "4991", "4992", "4993", "4994", "4995", "4996", "4997", "4998", "4999", "5000"], "outputs": ["6\n5 3 1 6 4 2 ", "2\n1 3", "1\n1 ", "1\n1", "4... | UNKNOWN | PYTHON3 | CODEFORCES | 129 | |
e5ab2a069857df3a839cc2a15ef7044f | Divide by Three | A positive integer number *n* is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible.
The number is called beautiful if it consists of at least one digit, doesn't have leading z... | [
"import re\ns = input()\nt = s.translate(str.maketrans(\"0123456789\", \"0120120120\"))\nx = (t.count('1') + t.count('2') * 2) % 3\nif x:\n res = ['']\n l = t.rsplit(\"12\"[x == 2], 1)\n if len(l) == 2:\n a = len(l[0])\n res.append((s[:a], s[a + 1:]))\n l = t.rsplit(\"12\"[x == 1], 2)\n ... | {"inputs": ["1033", "10", "11", "3", "1", "117", "518", "327", "270461", "609209", "110930", "37616145150713688775", "98509135612114839419", "41674994051436988162", "82547062721736129804", "4902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798814", "12910072096053014468749986... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
e5c1492df82be26090ac459cf081f0c9 | Covered Points Count | You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $k \in [1..n]$, calculate the number of points with in... | [
"import collections\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n ans = collections.defaultdict(int)\r\n for i in range(n):\r\n l, r = list(map(int, input().strip().split()))\r\n ans[l] += 1; ans[r + 1] -= 1\r\n ans = dict(sorted(ans.items(), key=lambda k: k[0]))\r\n keys =... | {"inputs": ["3\n0 3\n1 3\n3 8", "3\n1 3\n2 4\n5 7", "1\n0 1000000000000000000"], "outputs": ["6 2 1 ", "5 2 0 ", "1000000000000000001 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
e5d95d51685545ecb2cbc871cbfe17da | Too Easy Problems | You are preparing for an exam on scheduling theory. The exam will last for exactly *T* milliseconds and will consist of *n* problems. You can either solve problem *i* in exactly *t**i* milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.
Unfortunately, your teacher ... | [
"import sys\r\nimport math\r\nfrom collections import defaultdict,deque\r\nimport heapq\r\ndef search(arr,points,t):\r\n l=[]\r\n n=len(arr)\r\n cnt=0\r\n for i in range(n):\r\n if arr[i][0]>=points:\r\n l.append(arr[i][1])\r\n cnt+=1\r\n if cnt>=points:\r\n l.sort... | {"inputs": ["5 300\n3 100\n4 150\n4 80\n2 90\n2 300", "2 100\n1 787\n2 788", "2 100\n2 42\n2 58", "1 1\n1 1", "10 481\n4 25\n3 85\n6 96\n6 13\n1 9\n4 27\n2 7\n3 42\n9 66\n9 70", "1 1000000000\n1 10000", "1 1\n1 10000", "5 66\n2 64\n4 91\n5 91\n1 79\n3 85", "1 1000000000\n1 1", "5 100\n1 10\n1 10\n1 10\n1 10\n1 10"], "o... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
e5e6897144e5e79c74783dcb22208415 | Binary Protocol | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | [
"n = int(input())\r\n# print(n)\r\ns = input()\r\n# print(s)\r\nk = 0\r\nans = ''\r\nfor c in s:\r\n # print(c)\r\n if c == '0':\r\n ans += str(k)\r\n k = 0\r\n else:\r\n k += 1\r\n\r\nprint(ans + str(k))\r\n",
"n=int(input())\r\ns=input().strip()\r\nprint(*map(len, s.split('0')), se... | {"inputs": ["3\n111", "9\n110011101", "1\n1", "3\n100", "5\n10001", "14\n11001100011000", "31\n1000011111111100011110111111111", "53\n10110111011110111110111111011111110111111110111111111", "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111", "10\n1000000000", "2\n10", "4\n11... | UNKNOWN | PYTHON3 | CODEFORCES | 215 | |
e5eb77ed5fde83dd01fd25945e8d87e6 | Jury Meeting | Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting poi... | [
"g = lambda: map(int, input().split())\r\nn, m, k = g()\r\nF, T = [], []\r\ne = int(3e11)\r\n\r\nfor i in range(m):\r\n d, f, t, c = g()\r\n if f: F.append((d, f, c))\r\n else: T.append((-d, t, c))\r\n\r\nfor p in [F, T]:\r\n C = [e] * (n + 1)\r\n s = n * e\r\n q = []\r\n\r\n p.sort()\r\n fo... | {"inputs": ["2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500", "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000", "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000", "2 4 5\n1 1 0 1\n2 2 0 10\n8 0 1 100\n9 0 2 1000", "1 2 1\n10 1 0 16\n20 0 1 7", "1 2 10\n20 0 1 36\n10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
e5f49ec42951e7d7c45b82e1e5435575 | Symmetric Projections | You are given a set of *n* points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines.
Multiset is a set where equal elements are allowed.
Multiset is called symmetric, if there is a point *P* ... | [
"from fractions import Fraction\r\nimport time\r\n\r\n\r\nclass Point:\r\n def __init__(self, x, y):\r\n self.x = x\r\n self.y = y\r\n\r\n def to_tuple(self):\r\n return (self.x, self.y)\r\n\r\n def __repr__(self):\r\n return \"Point({}, {})\".format(self.x, self.y)\r\n\r\n d... | {"inputs": ["3\n1 2\n2 1\n3 3", "2\n4 3\n1 2", "6\n0 4\n1 5\n2 1\n3 2\n4 3\n5 0", "1\n5 2", "4\n2 4\n1 2\n0 0\n-2 -4", "10\n0 5\n1 0\n2 3\n3 2\n4 6\n5 9\n6 1\n7 8\n8 4\n9 7", "9\n-1000000 -500000\n-750000 250000\n-500000 1000000\n-250000 -250000\n0 -1000000\n250000 750000\n500000 0\n750000 -750000\n1000000 500000", "10... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e5fd38f32e822cd47f7428b401223cab | none | Вам задано прямоугольное клетчатое поле, состоящее из *n* строк и *m* столбцов. Поле содержит цикл из символов «*», такой что:
- цикл можно обойти, посетив каждую его клетку ровно один раз, перемещаясь каждый раз вверх/вниз/вправо/влево на одну клетку; - цикл не содержит самопересечений и самокасаний, то есть две кл... | [
"n, m = map(int, input().split())\r\nA = ['#'*(m+2)]\r\nfor i in range(1, n+1):\r\n B = ['#'] + list(input()) + ['#']\r\n A.append(B)\r\n if 'S' in B:\r\n C = [i, B.index('S')]\r\nA.append('#'*(m+2))\r\nN = C.copy()\r\nq = 'L'\r\nsh = 0\r\nwhile sh==0 or N!=C:\r\n sh+=1\r\n if (A[N[0]-1][N[1]]... | {"inputs": ["3 3\n***\n*.*\n*S*", "6 7\n.***...\n.*.*...\n.*.S**.\n.*...**\n.*....*\n.******", "100 3\n***\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.*\n*.... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
e60b3cbd2c86af1239ce62fe75b31479 | Pizza, Pizza, Pizza!!! | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | [
"x=int(input())\r\nprint( 0 if x==0 else (x+1)//2 if (x+1)%2==0 else x+1 )\r\n\r\n\r\n# My code says who am i\r\n# red is love\r\n# love is not in logic\r\n\r\n",
"n=int(input())\nif n==0:\n print(0)\nelse:\n if (n+1)%2==0:\n print((n+1)//2)\n else:\n print((n + 1))\n \t\t \t\t \t \t \t\... | {"inputs": ["3", "4", "10", "10000000000", "1234567891", "7509213957", "99999999999999999", "21", "712394453192", "172212168", "822981260158260519", "28316250877914571", "779547116602436424", "578223540024979436", "335408917861648766", "74859962623690078", "252509054433933439", "760713016476190622", "919845426262703496... | UNKNOWN | PYTHON3 | CODEFORCES | 154 | |
e638521913c2072acd0316e2f71ff040 | Hamming Distance Sum | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | [
"from collections import deque\r\ndef hamming(arr1, arr2, n):\r\n sum1 = 0\r\n for i in range(n):\r\n sum1 += arr1[i]^arr2[i]\r\n return sum1\r\ns = input()\r\nt = input()\r\nn = len(t)\r\nm = len(s)\r\ntotal = 0\r\ncount1 = 0\r\nlength = n-m+1\r\nfor i in range(n-m+1):\r\n if t[i] == '1':\r\n ... | {"inputs": ["01\n00111", "0011\n0110", "0\n0", "1\n0", "0\n1", "1\n1", "1001101001101110101101000\n01111000010011111111110010001101000100011110101111", "1110010001000101001011111\n00011011000000100001010000010100110011010001111010"], "outputs": ["3", "2", "0", "1", "1", "0", "321", "316"]} | UNKNOWN | PYTHON3 | CODEFORCES | 113 | |
e666dd51fa2686b4cee373003f8f43e6 | Photo Processing | Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo *i* has a contrast *v**i*. In order for the processing to be truly of high quality, the application must receive at least *k* photos with contrasts which differ as little as possible.
Evlampiy a... | [
"from bisect import bisect_left, bisect_right\r\nfrom collections import Counter, deque\r\nfrom functools import lru_cache\r\nfrom math import factorial, comb, sqrt, gcd, lcm, log2\r\nfrom copy import deepcopy\r\nimport heapq\r\n\r\nfrom sys import stdin, stdout\r\n\r\n\r\ninput = stdin.readline\r\n\r\n\r\n\r\ndef ... | {"inputs": ["5 2\n50 110 130 40 120", "4 1\n2 3 4 1", "1 1\n4", "2 2\n7 5", "3 2\n34 3 75", "5 2\n932 328 886 96 589", "10 4\n810 8527 9736 3143 2341 6029 7474 707 2513 2023", "20 11\n924129 939902 178964 918687 720767 695035 577430 407131 213304 810868 596349 266075 123602 376312 36680 18426 716200 121546 61834 851586... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
e66985f39a9769f994faf9ce3d63f424 | none | Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
There are also *n* cards, each card has 2 attributes: length *l**i* and cost *c**i*. If she pays *c**i* dollars then she can apply *i*-th... | [
"def gcd(x, y):\r\n if y == 0:\r\n return x\r\n return gcd(y, x % y)\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nc = [int(x) for x in input().split()]\r\nf = {}\r\nfor i in range(n):\r\n h = {}\r\n for x in f:\r\n h[x] = f[x]\r\n ... | {"inputs": ["3\n100 99 9900\n1 1 1", "5\n10 20 30 40 50\n1 1 1 1 1", "7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10", "8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026", "6\n1 2 4 8 16 32\n32 16 8 4 2 1", "1\n1\n1", "1\n2\n2", "8\n2 3 5 7 11 13 17 19\n4 8 7 1 5 2 6 3", "1\n1000... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
e677e0b9b13403595b58533bae5f399b | April Fools' Problem (medium) | The marmots need to prepare *k* problems for HC2 over *n* days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day *i* (at most one per day) costs *a**i* CHF, and the printing of a problem on day *i* (also at most one per day) costs *b**i* CHF. Of course, a problem cannot be print... | [
"from collections import deque\nfrom heapq import heappop, heappush\n \nclass Edge(object):\n __slots__ = ('x', 'y', 'cap', 'cost', 'inv')\n def __repr__(self):\n return '{e.x}-->{e.y} ({e.cap} , {e.cost})'.format(e=self)\n\nclass MCFP(list):\n def add(G, x, y, cap, cost):\n n = max(x, y) + 1... | {"inputs": ["8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 1", "10 6\n60 8 63 72 1 100 23 59 71 59\n81 27 66 53 46 64 86 27 41 82", "13 13\n93 19 58 34 96 7 35 46 60 5 36 40 41\n57 3 42 68 26 85 25 45 50 21 60 23 79", "12 1\n49 49 4 16 79 20 86 94 43 55 45 17\n15 36 51 20 83 6 83 80 72 22 66 100", "1 1\n96\n86"], "outputs": ["32... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
e68539488f58313b1362264cddb9b8e7 | Diplomas and Certificates | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | [
"s=input()\r\nl=s.split()\r\nn=int(l[0])\r\nk=int(l[1])\r\na=n//2\r\np1=a//(k+1)\r\np2=k*p1\r\np3=n-p2-p1\r\nif p3>=n/2 :\r\n print(int(p1),int(p2),int(p3))\r\nelse :\r\n print(0,0,n)",
"[n, k] = [int(i) for i in input().split()]\r\nhalf = n // 2\r\ncorrection = half % (k + 1)\r\nwinners = half - correction... | {"inputs": ["18 2", "9 10", "1000000000000 5", "1000000000000 499999999999", "1 1", "5 3", "42 6", "1000000000000 1000", "999999999999 999999", "732577309725 132613", "152326362626 15", "2 1", "1000000000000 500000000000", "100000000000 50000000011", "1000000000000 32416187567", "1000000000000 7777777777", "10000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 282 | |
e69b2a591819307c7664c4c2dab6fe18 | Translation | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | [
"s=input()\r\ng=input()\r\nr=s[::-1]\r\nif(g==r):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n",
"s=input()\r\nt=input()\r\nn=len(s)\r\nm=len(t)\r\nif(n==m):\r\n c=0\r\n for i in range(m):\r\n if(s[i]!=t[m-1-i]):\r\n c=1 \r\n if(c==1):\r\n print(\"NO\")\r\n else:\r\n ... | {"inputs": ["code\nedoc", "abb\naba", "code\ncode", "abacaba\nabacaba", "q\nq", "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "z\na", "asd\ndsa", "abcdef\nfecdba", "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkz... | UNKNOWN | PYTHON3 | CODEFORCES | 3,021 | |
e6b16af4f70ea70aaebdec8c6ceac0a5 | New Year and Curling | Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*.
When she slides the *i*-th disk, she will place its center at the point (*... | [
"import math\r\n\r\n# input is a circle with centre (x1,y1)\r\n# and the 2nd centre has x-coordinate x2\r\n# find the y-coordinate of the 2nd circle, larger than y1, when it touches the 1st circle\r\ndef touch_y(x1, y1, x2):\r\n if abs(x1-x2) > 2*r: # no intersection\r\n return r\r\n x_touch_offset = ... | {"inputs": ["6 2\n5 5 6 8 3 12", "1 1\n5", "5 300\n939 465 129 611 532", "5 1\n416 387 336 116 81", "3 10\n1 100 1000", "2 1\n2 20", "3 2\n10 10 100"], "outputs": ["2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613", "1", "300 667.864105343 1164.9596696 1522.27745533 2117.05388391", "1 1 1 1 1", "10 10 10",... | UNKNOWN | PYTHON3 | CODEFORCES | 83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.