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 |
|---|---|---|---|---|---|---|---|---|---|
79a38cf64ad5510445ae44b028dbd4aa | Bear and Reverse Radewoosh | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | [
"n,c=map(int,input().split())\r\np=list(map(int,input().split()))\r\nt=list(map(int,input().split()))\r\nq=[0,0]\r\ntm=0\r\nfor i in range(n):\r\n tm+=t[i]\r\n q[0]+=max(0,p[i]-c*tm)\r\ntm=0\r\nfor i in list(range(n))[::-1]:\r\n tm+=t[i]\r\n q[1]+=max(0,p[i]-c*tm)\r\nif q[0]>q[1]: print('Limak')\r\nelif... | {"inputs": ["3 2\n50 85 250\n10 15 25", "3 6\n50 85 250\n10 15 25", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76", "4 1\n3 5 6 9\n1 2 4 8", "4 1\n1 3 6 10\n1 5 7 8", "4 1\n2 4 5 10\n2 3 9 10", "18 4\n68 97 121 132 146 277 312 395 407 431 458 461 595 634 751 855 871 994\n1 2 3 4 9 10 13 21 22 29 31 34 37 38 39 ... | UNKNOWN | PYTHON3 | CODEFORCES | 292 | |
79bee3be5bae0add3e18f78c8efd72b6 | none | It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And ye... | [
"from math import atan, asin\ny1, y2, yw, xb, yb, r = map(float, input().split())\nx = xb * (yw - y1 - 2*r) / (2*yw - y1 - yb - 3*r)\nalpha = atan(x / (yw - y1 - 2*r))\nbeta = asin(r / (y2 - y1 - r))\nprint ('-1' if alpha < beta else '{0:.10f}'.format(x))",
"from math import hypot\r\ny1, y2, yw, xb, yb, r = map(i... | {"inputs": ["4 10 13 10 3 1", "1 4 6 2 2 1", "3 10 15 17 9 2", "4 9 30 3 3 1", "4 9 13 2 3 1", "4 9 13 1 1 1", "1 9 10 6 6 3", "4 9 24 10 3 1", "4 9 20 10 3 1", "1 8 10 8 3 3", "2 9 10 4 6 3", "2 9 10 6 3 3", "1 9 10 7 3 3", "1 9 10 9 5 3", "2 9 10 6 5 3", "1 9 10 5 5 3", "2 9 10 9 3 3", "1 9 10 9 5 3", "1 8 10 3 3 3",... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
79e0d3456ed7b662db679a702bb43977 | Letters Removing | Petya has a string of length *n* consisting of small and large English letters and digits.
He performs *m* operations. Each operation is described with two integers *l* and *r* and a character *c*: Petya removes from the string all characters *c* on positions between *l* and *r*, inclusive. It's obvious that the lengt... | [
"#!/usr/bin/env python\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nclass FenwickTree:\r\n def __init__(self, x):\r\n \"\"\"transform list into BIT\"\"\"\r\n self.bit = x\r\n for i in range(len(x)):\r\n j = i | (i + 1)\r\n if j < len(x):\r\n ... | {"inputs": ["4 2\nabac\n1 3 a\n2 2 c", "3 2\nA0z\n1 3 0\n1 1 z", "10 4\nagtFrgF4aF\n2 5 g\n4 9 F\n1 5 4\n1 7 a", "9 5\naAAaBBccD\n1 4 a\n5 6 c\n2 3 B\n4 4 D\n2 3 A", "10 10\nhRZQK137KY\n1 10 V\n8 10 g\n2 6 E\n2 2 y\n6 8 J\n1 5 w\n4 6 q\n6 8 K\n2 10 c\n4 6 t", "20 4\n8QYQY1tp6CA02NGnR04s\n1 9 N\n1 10 y\n5 11 t\n6 7 C", ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
79f867bd960bd74ebd3a5c734bf1389c | Pasha and Hamsters | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams... | [
"n, a, b = list(map(int, input().split()))\naa = list(map(int, input().split()))\nab = list(map(int, input().split()))\nans = [0] * n\nfor a in aa:\n ans[a - 1] = '1'\nfor a in ab:\n ans[a - 1] = '2'\nprint(' '.join(ans))",
"# PAsha and hamsters\r\n\r\napples = list(map(int,input().split()))\r\narthur = lis... | {"inputs": ["4 2 3\n1 2\n2 3 4", "5 5 2\n3 4 1 2 5\n2 3", "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47... | UNKNOWN | PYTHON3 | CODEFORCES | 283 | |
7a03ba5e18ef1df44dc03ac8d8878cde | Fight the Monster | A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*).
During the battle, every second the monster's HP decrease by *max*(0,<=*ATK**Y*<=-<=*DEF**M*), while Yang's HP ... | [
"I=lambda:map(int,input().split())\r\nR=list(range(999))\r\nq,w,e=I()\r\nr,t,y=I()\r\na,b,c=I()\r\nprint(min(i*b+j*c+max(0,(r//(w+i-y)+bool(r%(w+i-y)))*(t-e-j)-q+1)*a for i in R for j in R if w+i>y))",
"H_y,A_y,D_y = map(int,input().split())\r\nH_m,A_m,D_m = map(int,input().split())\r\nh,a,d = map(int,input().spl... | {"inputs": ["1 2 1\n1 100 1\n1 100 100", "100 100 100\n1 1 1\n1 1 1", "50 80 92\n41 51 56\n75 93 12", "76 63 14\n89 87 35\n20 15 56", "12 59 66\n43 15 16\n12 18 66", "51 89 97\n18 25 63\n22 91 74", "72 16 49\n5 21 84\n48 51 88", "74 89 5\n32 76 99\n62 95 36", "39 49 78\n14 70 41\n3 33 23", "11 82 51\n90 84 72\n98 98 43... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
7a050be457f1abb1e33be44a0a8dfabc | Raising Bacteria | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | [
"n=int(input())\r\ns=1\r\nwhile n!=1:\r\n if n%2==0:\r\n n//=2\r\n else:\r\n s+=1\r\n n-=1\r\nprint(s)",
"w2=int(input())\r\nw=bin(w2)\r\nw1=w[2:]\r\nc=0\r\nfor i in w1:\r\n if int(i)%2!=0:\r\n c+=1\r\nprint(c) ",
"n = int(input())\r\nbact = 0\r\nwhile(n>0):\r\n if... | {"inputs": ["5", "8", "536870911", "1", "343000816", "559980448", "697681824", "41313494", "673935585", "117422204", "954746654", "536838144", "1000000000", "2", "3", "4", "6", "7", "9", "10", "999999999", "999999998", "999999997", "999999996", "999999995", "999999994", "999999993", "999999992", "999999991", "999999990... | UNKNOWN | PYTHON3 | CODEFORCES | 604 | |
7a4dd76945e19b3e410c657bd294b6e1 | Bear and Poker | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | [
"n = int(input())\r\nm=list(map(int,input().split()))\r\nfor i in range(n):\r\n while(m[i]%2==0):\r\n m[i]//=2\r\n while(m[i]%3==0):\r\n m[i]//=3\r\nif(len(set(m))==1):\r\n print('Yes')\r\nelse:\r\n print('No')\r\n ",
"def euc(x, y):\r\n\tif y == 0: return x\r\n\treturn euc(y, x%y... | {"inputs": ["4\n75 150 75 50", "3\n100 150 250", "7\n34 34 68 34 34 68 34", "10\n72 96 12 18 81 20 6 2 54 1", "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058", "2\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 304 | |
7a52b45a3918d9332ab9a559a1953314 | Petr# | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* and ending with the *s**end* (it is possible *s**begin*<==<=*s**end*), the given string... | [
"def calc_lcp(s, sa):\r\n n = len(s)\r\n rank = [0 for _ in range(n)]\r\n for i in range(n):\r\n rank[sa[i]] = i\r\n lcp = [0 for _ in range(n - 1)]\r\n h = 0\r\n for i in range(n):\r\n if rank[i] < n - 1:\r\n while s[i + h] == s[sa[rank[i] + 1] + h]:\r\n h ... | {"inputs": ["round\nro\nou", "codeforces\ncode\nforca", "abababab\na\nb", "aba\nab\nba", "abcdefghijklmnopqrstuvwxyz\nabc\nxyz", "aaaaaaaaaaaaaaa\na\na", "aaaaaaaaa\naa\naaa", "rmf\nrm\nf", "kennyhorror\nkenny\nhorror", "itsjustatest\njust\nits", "ololo\ntrololo\nololo", "ololololololololololololololo\no\nl", "includec... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
7a56eef43ec386b74abffa147e261099 | Ice Sculptures | The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus *n* ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they... | [
"n=int(input())\r\nli=list(map(int,input().split()))\r\nm=-10**9\r\nfor i in range(3,n+1):\r\n\tif(n%i==0):\r\n\t\tfor j in range(0,n//i):\r\n\t\t\tm=max(m,sum(li[j:n:n//i]))\r\nprint(m)\r\n"
] | {"inputs": ["8\n1 2 -3 4 -5 5 2 3", "6\n1 -2 3 -4 5 -6", "6\n1 2 3 4 5 6", "4\n1 -10 1 -10", "6\n1 0 1 0 1 0", "12\n1 1 1 1 1 1 1 -1000 1 1 1 1", "3\n-1 -1 -1", "97\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7a78bd250f3e01a2588006385a66a6ee | The Evil Temple and the Moving Rocks | Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak monsters, you arrived at a square room consisting of tiles forming ... | [
"n=int(input().split()[0])\r\nfor i in range(n):print(\"^\"+\".<\"*((n-1)//4)+\".\"*((n-1)%4>1)+\"<\"*(n//2)if i%2 else\">\"*(n//2)+\".\"*((n-1)%4>1)+\">.\"*((n-1)//4)+\"v\")\r\nprint(1,n)\r\n"
] | {"inputs": ["5 5", "3 2", "100 100000"], "outputs": [">...v\nv.<..\n..^..\n>....\n..^.<\n1 1", ">vv\n^<.\n^.<\n1 3", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>v.\n^v<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<.... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7a89f15c9c25f50f7100dea915d05aa5 | none | International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where *y* stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string *y* that has never been used before.... | [
"import sys\r\n\r\n\r\ndef solve(ma: str, pre: str):\r\n ret = pre\r\n if len(pre) > len(ma):\r\n ret = int(pre) if pre[0] != '0' else int(pre) + 10 ** len(pre)\r\n elif len(pre) == len(ma):\r\n ret = int(pre) if int(pre) >= int(ma) else int(pre) + 10 ** len(pre)\r\n else:\r\n diff ... | {"inputs": ["5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999", "1\nIAO'111110", "2\nIAO'0\nIAO'00", "1\nIAO'111111", "1\nIAO'111111111", "1\nIAO'001", "1\nIAO'2000", "1\nIAO'11109999", "1\nIAO'11111", "1\nIAO'100000", "1\nIAO'18999990", "1\nIAO'113098", "1\nIAO'111122", "1\nIAO'1110222",... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
7a9a8a7e5402fd8076337a84117a28db | Triangle | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | [
"import sys\ninput = sys.stdin.readline\n\na = [int(x) for x in input().split()]\na.sort()\nif a[0] + a[1] > a[2] or a[1] + a[2] > a[3]:\n print(\"TRIANGLE\")\nelif a[0] + a[1] == a[2] or a[1] + a[2] == a[3]:\n print(\"SEGMENT\")\nelse:\n print(\"IMPOSSIBLE\")\n",
"sides=[int(i) for i in input().split()]... | {"inputs": ["4 2 1 3", "7 2 2 4", "3 5 9 1", "3 1 5 1", "10 10 10 10", "11 5 6 11", "1 1 1 1", "10 20 30 40", "45 25 5 15", "20 5 8 13", "10 30 7 20", "3 2 3 2", "70 10 100 30", "4 8 16 2", "3 3 3 10", "1 5 5 5", "13 25 12 1", "10 100 7 3", "50 1 50 100", "50 1 100 49", "49 51 100 1", "5 11 2 25", "91 50 9 40", "27 53 ... | UNKNOWN | PYTHON3 | CODEFORCES | 372 | |
7aa4872341e638bdc2ec23b356052e20 | Lara Croft and the New Game | You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e... | [
"from bisect import bisect_left, bisect_right\r\n\r\ndef _input():\r\n return map(int, input().strip().split())\r\ndef _print(s):\r\n print(''.join(map(str, s)))\r\n\r\nn, m, k = _input()\r\nif k < n:\r\n print(k + 1, 1)\r\n exit(0)\r\nk -= n\r\nx, y = n, 2\r\nd = k // (2 * (m - 1))\r\nr = k % (2 * (m -... | {"inputs": ["4 3 0", "4 3 11", "4 3 7", "1000000000 2 1999999999", "1000000000 1000000000 999999999999999999", "1000000000 1000000000 999999999", "1000000000 1000000000 2000000500", "2 2 2", "28 3 1", "2 3 3", "4 6 8", "6 6 18", "4 3 8", "4 3 4", "4 4 10", "4 5 4", "4 3 9", "4 3 6", "4 5 5", "6 4 8", "4 4 12", "10 6 15... | UNKNOWN | PYTHON3 | CODEFORCES | 67 | |
7ab2968b04610f2f8b3a9b37df7726eb | Vika and Squares | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | [
"from sys import*\r\ndef square(a):\r\n\tk = min(a)\r\n\tl = [i for i, x in enumerate(a) if x == k]\r\n\tif(len(l) == 1):\r\n\t\treturn (n*k + (n-1))\r\n\telse:\r\n\t\tb =[0]*(len(l))\r\n\t\tfor i in range(len(l) - 1):\r\n\t\t\tb[i] = l[i+1] - l[i]\r\n\t\tb[len(l) - 1] = (len(a) - l[len(l)-1] + l[0])\r\n\t\treturn ... | {"inputs": ["5\n2 4 2 3 3", "3\n5 5 5", "6\n10 10 10 1 10 10", "1\n167959139", "10\n896619242 805194919 844752453 848347723 816995848 856813612 805194919 833406689 816255448 805194919", "2\n2 3", "2\n10 10", "2\n1111 1110", "3\n100 101 100", "3\n100 100 101", "3\n101 100 100", "4\n2 3 2 2", "4\n1 1 1 1", "4\n100 100 10... | UNKNOWN | PYTHON3 | CODEFORCES | 90 | |
7ad1ef546a97f18893db5a42709c135a | Road Improvement | In Berland there are *n* cities and *n*<=-<=1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads.
In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work s... | [
"import sys\r\nfrom array import array\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\ninp = lambda dtype: [dtype(x) for x in input().split()]\r\ndebug = lambda *x: print(*x, file=sys.stderr)\r\nceil_ = lambda a, b: (a + b - 1) // b\r\nsum_n = lambda n: (n * (n + 1)) // 2\r\nget_bit = lambda ... | {"inputs": ["4\n1 2\n3 4\n3 2", "6\n3 4\n5 4\n3 2\n1 3\n4 6", "8\n1 3\n1 6\n3 4\n6 2\n5 6\n6 7\n7 8", "5\n1 2\n1 3\n1 4\n1 5", "2\n1 2", "2\n2 1", "3\n1 2\n3 2", "3\n1 3\n2 3", "4\n1 4\n1 2\n4 3", "4\n1 2\n1 3\n1 4", "6\n1 2\n1 3\n1 4\n3 5\n4 6", "6\n1 2\n1 3\n1 4\n3 5\n3 6", "8\n1 2\n2 3\n3 4\n1 5\n5 6\n6 7\n1 8", "10... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7ad6bfee3f30ccca47af9b134d529ac7 | Dasha and Stairs | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | [
"n,m=map(int,input().split())\r\nz=abs(n-m)\r\nif((z==0 and n!=0) or z==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"z=list(map(int,input().split()))\r\nif abs(z[0]-z[1])>1 :\r\n print(\"NO\")\r\nelse:\r\n if z[0]==0 and z[1]==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES... | {"inputs": ["2 3", "3 1", "5 4", "9 9", "85 95", "0 1", "89 25", "74 73", "62 39", "57 57", "100 99", "0 0", "98 100", "99 100", "1 0", "100 0", "0 100", "100 98", "100 100", "0 5", "2 2"], "outputs": ["YES", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "... | UNKNOWN | PYTHON3 | CODEFORCES | 204 | |
7ada3ad5df947ef2e0f77ab0f870f31c | Paper task | Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.
For the purpose of this problem we consider only strings cons... | [
"import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef suffix_array(s):\r\n l = len(s)\r\n x = [[] for _ in range(222)]\r\n for i in range(l):\r\n x[s[i]].append(i)\r\n y = []\r\n z = [0]\r\n for x0 in x:\r\n for i in x0:\r\n ... | {"inputs": ["10\n()()()()()", "7\n)(())()", "1\n(", "2\n))", "15\n(())(()())(()()", "30\n()(())(())(())()(())()()()(()(", "100\n(((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))", "1\n)", "2\n)(", "2\n((", "3\n(()", "3\n()(", "5\n()(()", "7\n(()(())", "10\n()()((())(",... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7af11cd684cd4b3c73c10f445ad8cc8b | none | Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points *A* and *B* on the plane are 4-connected if and only if:
- the Euclidean distance between *A* and *B* is one unit and neither *A* nor *B* is blocked; - or there is ... | [
"import math\r\nn = int(input())\r\nif n <= 0:\r\n print('1')\r\nelse:\r\n x = int(n / math.sqrt(2))\r\n if 2 * x * x + 2 * x + 1 > n * n:\r\n print(8 * x)\r\n else:\r\n print(8 * x + 4)",
"print(max(1, 4*int(int(input())*2**0.5)))",
"from math import sqrt, floor\n\n\ndef calc(n):\n ... | {"inputs": ["1", "2", "3", "4", "0", "30426905", "38450759", "743404", "3766137", "19863843", "24562258", "24483528", "25329968", "31975828", "2346673", "17082858", "22578061", "17464436", "18855321", "614109", "3107977", "39268638", "31416948", "34609610", "17590047", "12823666", "34714265", "2870141", "15012490", "31... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
7b29761fa91b3fd359b750e3b402b806 | Add Points | There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct.
Determine the number *m* — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
The first line contains a single integer *n*... | [
"def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\nn = int(input())\nth = 0\na = []\na = sorted(list(map(int, input().split())))\n#a.sort()\ne1 = a[0]\ne2 = a[-1]\nb = []\nfor i in range(len(a) - 1):\n b.append(a[i+1] - a[i])\n\nst = b[0]\nfor i in range(len(b) - 1):\n st = gcd(st, b[i+1]... | {"inputs": ["3\n-5 10 5", "6\n100 200 400 300 600 500", "4\n10 9 0 -1", "3\n1 4 7", "3\n1 4 6", "3\n1 2 6", "3\n1 3 6", "4\n1 2 3 4", "3\n-1000000000 -999999999 1000000000", "3\n-1000000000 999999999 1000000000", "3\n-1000000000 -999999998 1000000000", "3\n-1000000000 999999998 1000000000", "3\n422800963 4663162 694989... | UNKNOWN | PYTHON3 | CODEFORCES | 92 | |
7b6630ecc28410fed28db9ce61242dda | Imbalanced Array | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of ... | [
"import sys\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\nstk = [(float('-inf'), int(-1))]\nstk1 = [(float('inf'), int(-1))]\nleftSmaller = []\nleftGreater = []\nfor i, a in enumerate(A):\n while stk[-1][0] > a:\n stk.pop()\n leftSmaller.append(stk[-1][1])\n ... | {"inputs": ["3\n1 4 1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 4 4 3 5 2 4 2 4 5", "10\n9 6 8 5 5 2 8 9 2 2", "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5 2 3 5 4 5 4 4 3 5 2", "30\n2 2 9 1 10 8 3 3 1 4 6 10 2 2 1 4 1 1 1 1 1 2 4 7 6 7 5 10 8 9", "30\n6 19 12 6 25 24 12 2 24 14 10 10 24 19 11 29 10 22 7 1 9 1 2 27 7 24 20 2... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
7b72b4b75cf50dfdbb310061b3772773 | Minesweeper | One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficu... | [
"n, m = map(int, input().split())\r\na = [input().replace('.', '0') for i in range(n)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] != '*' and int(a[i][j]) != sum(map(lambda b: b[max(0, j - 1) : j + 2].count('*'), a[max(0, i - 1) : i + 2])):\r\n print('NO')\r\n exit()\... | {"inputs": ["3 3\n111\n1*1\n111", "2 4\n*.*.\n1211", "1 10\n.....1*1..", "1 1\n4", "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..11\n.13**1..1*\n..2*31..11\n..111..111\n.......1*1\n.......111", "10 17\n12*2*22123*31....\n2*333*3*4***3211.\n*22*213**4***3*1.\n11111.12224*6*21.\n221..111.14**4311\n**223... | UNKNOWN | PYTHON3 | CODEFORCES | 33 | |
7b79384344f556b9724fdd5e9b4aa4b6 | Beautiful Year | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | [
"a = int(input()) + 1\r\nwhile len(set(str(a))) != 4: a += 1\r\nprint(a)",
"y = input()\r\ny = str(int(y) + 1)\r\nwhile y[0] == y[1] or y[0] == y[2] or y[0] == y[3] or y[1] == y[2] or y[1] == y[3] or y[2] == y[3]:\r\n y = str(int(y)+1)\r\nelse:\r\n print(y)",
"a=int(input())\r\nwhile True:\r\n a+=1\r\n... | {"inputs": ["1987", "2013", "1000", "1001", "1234", "5555", "9000", "1111", "8999", "4572", "6666", "2001", "3000", "7712", "8088", "1594", "6016", "8800", "3331", "5090", "2342", "2334", "1123", "8989", "8977", "6869", "8999"], "outputs": ["2013", "2014", "1023", "1023", "1235", "5601", "9012", "1203", "9012", "4573",... | UNKNOWN | PYTHON3 | CODEFORCES | 715 | |
7b8a429b011c4755f203e29fac2800e6 | Rectangles | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the num... | [
"n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.append(list(map(int,input().split())))\r\nans=0\r\nfor i in range(n):\r\n r=l[i]\r\n c1=r.count(1)\r\n c2=r.count(0)\r\n ans+=(((2**c1)-1)+((2**c2)-1))\r\nfor i in range(m):\r\n ls=[]\r\n for j in range(n):\r\n ls.append(l... | {"inputs": ["1 1\n0", "2 3\n1 0 1\n0 1 0", "2 2\n1 1\n1 1", "1 10\n0 0 0 0 0 0 0 0 0 0", "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 159 | |
7b93a4c1574b65a354e5e4d577e339f6 | Winnie-the-Pooh and honey | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie... | [
"f=open('input.txt','r')\r\ng=open('output.txt','w')\r\nn,k=map(int,f.readline().split())\r\na=list(map(int,f.readline().split()))\r\ns,res=sum(a),0\r\nfor val in a:\r\n res+=int(k*min(3,val//k))\r\nprint(s-res,file=g)\r\n",
"fin = open('input.txt', 'r')\r\nfout = open('output.txt', 'w')\r\nn, k = list(map(int... | {"inputs": ["3 3\n15 8 10", "1 3\n3", "3 4\n3 8 2", "3 2\n95 25 49", "3 1\n8 3 2", "5 1\n4 7 9 5 7", "8 6\n19 15 1 14 7 2 10 14", "8 5\n5 2 17 12 16 12 17 3", "10 7\n26 11 10 8 5 20 9 27 30 9", "10 10\n20 82 19 82 18 96 40 99 87 2", "10 10\n75 52 78 83 60 31 46 28 33 17", "20 5\n33 45 36 13 46 40 15 11 29 44 43 50 14 1... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
7b9a01e874f7194f37722f21c8c656b9 | Even Odds | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | [
"n, k = map(int, input().split())\r\nif(n%2==0):\r\n half = n/2\r\n if(k>half):\r\n dif = int(abs(k - half))\r\n print(2*dif)\r\n else:\r\n print(2*k-1)\r\nelse:\r\n half = (n-1)/2 +1\r\n if(k>half):\r\n dif = int(abs(k- half))\r\n print(2*dif)\r\n else:\r\n ... | {"inputs": ["10 3", "7 7", "7 1", "7 2", "8 5", "8 3", "8 4", "1000000000000 500000000001", "999999999997 499999999999", "999999999999 999999999999", "1000000000000 1", "999999999999 1", "1 1", "1000000000000 1000000000000", "1000000000000 500000000000", "1000000000000 499999999999", "999999999997 499999999998", "61923... | UNKNOWN | PYTHON3 | CODEFORCES | 291 | |
7bd10aae4248a44fed5def6fc5d7b76f | Inna and Dima | Inna and Dima bought a table of size *n*<=×<=*m* in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:
1. initially, Inna chooses some cell of the... | [
"n, m = map(int, input().split())\nm += 1\nq = {'I': 0, 'M': 1, 'A': 2, 'D': 3}\nt = []\nfor i in range(n):\n t += map(q.get, input())\n t.append(-7)\nt += [-7] * m\np = [[] for q in t]\nc = [0] * len(t)\nfor a in range(n * m):\n for b in (a - m, a + m, a - 1, a + 1):\n if abs(t[b] - t[a] + 1) == 2:... | {"inputs": ["1 2\nDI", "2 2\nMA\nID", "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID", "1 1\nI", "5 5\nDIMAD\nADDDI\nMDDDM\nIDDDA\nDAMID", "5 5\nAAAAA\nAAAAA\nAAAAA\nAAAAA\nAAAAA", "1 1\nD", "1 4\nDIMA", "4 1\nD\nI\nM\nA", "2 2\nDI\nAM", "2 2\nDI\nMA", "5 5\nDIADD\nDMADD\nDDDID\nAMMMD\nMIDAD", "10 10\nDIDDIMDIDD\nDMDDAADIDD\n... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
7bdf1792023fed0ee2299b19cea20807 | New Roads | There are *n* cities in Berland, each of them has a unique id — an integer from 1 to *n*, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.
That is why there was a decision to build *n*<=-<=1 roads so that there will be exactly one simple path between each pai... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, t, k = map(int, input().split())\r\na = list(map(int, input().split())) + [0]\r\nx = [0] * t\r\nfor i in range(t):\r\n x[i] = max(a[i] - a[i + 1], 0)\r\ns = sum(x)\r\nif s > k or k > n - t:\r\n ans = -1\r\n print(... | {"inputs": ["7 3 3\n2 3 1", "14 5 6\n4 4 2 2 1", "3 1 1\n2", "6 3 3\n1 2 2", "11 6 4\n1 2 2 1 3 1", "21 10 9\n2 1 3 1 1 1 3 2 3 3", "51 16 31\n1 3 3 3 4 4 3 5 4 1 3 3 3 2 3 5", "1001 179 490\n8 8 6 7 1 6 10 3 7 8 8 7 2 4 9 8 4 5 8 3 5 7 9 10 9 5 2 6 5 3 3 2 9 6 4 2 10 2 3 5 7 4 5 8 3 9 5 9 2 5 4 9 3 8 2 9 6 7 4 4 10 9 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7bedb5e10e2916d9c08ae8e42bf62636 | Mushroom Gnomes | Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighbori... | [
"#!/usr/bin/pypy3\r\n\r\nfrom sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\np = 0\r\n\r\ndef readints():\r\n return list(map(int, input().split()))\r\ndef writeln(x):\r\n print(str(x) + '\\n')\r\n\r\ndef mod(x):\r\n return (x % p + p) % p\r\ndef matmul(a, b):\r\n n = len... | {"inputs": ["2 1 0 657276545\n1 2", "2 1 1 888450282\n1 2", "4 5 0 10000\n1 2 3 4", "4 0 8 78731972\n1 52 76 81", "4 0 8 414790855\n1 88 97 99", "11 10 6 560689961\n2 17 20 24 32 37 38 39 40 61 86", "8 4 9 371687114\n1 7 22 31 35 38 62 84", "4 8 6 398388678\n21 22 78 88", "49 46 48 698397508\n1098 1160 1173 1269 1438 1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
7c10d0df3c5615067fece309da99e575 | Maxim and Restaurant | Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is *p* meters.
Maxim has got a dinner party tonight, *n* guests will come to him. Let's index the guests of Maxim's restaurant from 1 to *n*. Maxim knows the sizes of all guests that are going to come to him. The *i*-th guest'... | [
"n=int(input())\narr=list(map(int,input().split()))\np=int(input())\ndp=[[[0 for k in range(n+1)] for i in range(p+1)] for i in range(n+1)]\nfor j in range(p+1):\n for k in range(n+1):\n dp[0][j][k]=1\nfor i in range(1,n+1):\n for j in range(p+1):\n for k in range(1,n+1):\n if j>=arr[... | {"inputs": ["3\n1 2 3\n3", "9\n2 2 2 2 2 2 2 1 2\n9", "7\n2 1 1 2 1 1 2\n2", "8\n3 1 5 6 1 5 4 4\n7", "2\n1 3\n3", "2\n1 2\n2", "5\n1 2 3 1 2\n3", "9\n1 2 2 7 4 4 1 4 7\n7", "6\n1 1 1 1 1 1\n1", "10\n35 5 7 41 17 27 32 9 45 40\n30", "27\n38 39 19 33 30 42 34 16 40 9 5 31 28 7 24 37 22 46 25 23 21 30 28 24 48 13 37\n24"... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
7c36cde070092df3c067bac6429bb832 | Magic Five | There is a long plate *s* containing *n* digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ... | [
"t, k = input(), int(input())\r\ns, n, d = 0, 1, 1000000007\r\n\r\nfor i in t:\r\n if i in '05': s += n\r\n\r\n n = (n << 1) % d\r\n\r\np = (pow(n, k, d) - 1) * pow(n - 1, d - 2, d)\r\nprint(((p % d) * (s % d)) % d)",
"MOD = 1000000007\n\ndef potencia(x, n):\n # Calcula x^n de manera eficiente utilizando... | {"inputs": ["1256\n1", "13990\n2", "555\n2", "14\n178", "27755776656210607832788619414635535178188775623838313967013958143619017005079991285469853503718562504927535176713879737569375166451462839457844835806559098448980069427607\n151", "205831218776360805549796263726315728152440389522084825015113219980083245807721536032... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
7c4b50700e3e6704a97d5d9f8e133a5f | Zuma | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones ... | [
"# if you win, you live. you cannot win unless you fight.\r\nfrom sys import stdin,setrecursionlimit\r\ninput=stdin.readline\r\nimport heapq\r\nrd=lambda: map(lambda s: int(s), input().strip().split())\r\nrdone=lambda: map(lambda s: int(s)-1, input().strip().split())\r\nri=lambda: int(input())\r\nrs=lambda :input(... | {"inputs": ["3\n1 2 1", "3\n1 2 3", "7\n1 4 4 2 3 2 1", "1\n1", "2\n1 1", "2\n1 2", "8\n1 2 1 3 4 1 2 1", "50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7 10 5 4 8 1 9 5 5 3 4 4 8 3", "50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 2 18 3 1 9 19 4 19 10 17 12 16 20 10 11 15 10 3 19 8 6 2... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
7c74fd35bee1aab8fedb79f0ecc2c005 | Intercity Travelling | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe... | [
"MOD=998244353\r\ndef f(n):\r\n if(n==0):\r\n return 1\r\n if(n==1):\r\n return 3\r\n return ((n+2)*pow(2,n-1,MOD))%MOD\r\nn=int(input())\r\nar=list(map(int,input().split()))[::-1]\r\nS=0\r\nfor i in range(n):\r\n S+=ar[i]*f(i)\r\nprint(S%MOD)\r\n",
"#from math import *\r\nimport sys\r\n... | {"inputs": ["2\n1 2", "4\n1 3 3 7", "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 ... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
7c76a920fda30ae5d059967f891f2d36 | Numbers Exchange | Eugeny has *n* cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has *m* cards, distinct numbers from 1 to *m* are wr... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\ns = set(a)\r\nx = [[] for _ in range(2)]\r\nfor i in range(1, min(m, 6 * n) + 1):\r\n if not i in s:\r\n x[i % 2].append(i)\r\nn2 = n // 2\r... | {"inputs": ["6 2\n5 6 7 9 4 5", "8 6\n7 7 7 7 8 8 8 8", "4 1\n4 2 1 10", "10 10\n12 13 10 20 13 10 19 15 21 11", "20 16\n23 27 17 29 23 21 24 23 19 25 16 24 20 17 18 17 16 17 28 17", "30 40\n26 22 10 20 29 18 38 11 41 8 33 37 37 3 14 4 3 9 21 38 27 27 7 7 33 12 39 37 17 5", "100 20\n28 42 37 40 26 40 46 46 25 28 36 36 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
7ca6ae0bf81d946812ed8cd9707b606e | Parade | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg... | [
"n = int(input())\nheh = []\nans = 0\nLminusR = 0\nfor i in range(n):\n l, r = map(int, input().split())\n LminusR += l\n LminusR -= r\n heh.append(2 * (r - l))\nkok = abs(LminusR)\nfor e in range(n):\n i = heh[e]\n if abs(LminusR + i) > kok:\n kok = abs(LminusR + i)\n ans = e + 1\np... | {"inputs": ["3\n5 6\n8 9\n10 3", "2\n6 5\n5 6", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "2\n500 499\n500 500", "1\n139 252", "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417", "4\n4 1\n5 3\n7 6\n3 5", "3\n6 5\n9 8\n3 10", "3\n100 9\n1 3\n1 5", "4\n10 1\n10 2\n10 3\n1 10", "5\n25 1... | UNKNOWN | PYTHON3 | CODEFORCES | 76 | |
7cec9617831c07fa8b967fc9a6eedc86 | Keyboard Layouts | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.
You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i... | [
"first=str(input())\r\nsecond=str(input())\r\nsent=str(input())\r\nvariant=[0]*len(sent)\r\nnumbers=\"0123456789\"\r\nfor i in range(0,26):\r\n for j in range(0,len(sent)):\r\n if (sent[j]==first[i]):\r\n variant[j]=second[i]\r\n elif (sent[j]==first[i].upper()):\r\n variant[j... | {"inputs": ["qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7", "ayvguplhjsoiencbkxdrfwmqtz\nkhzvtbspcndierqumlojyagfwx\n3", "oaihbljgekzsxucwnqyrvfdtmp\nwznqcfvrthjibokeglmudpayxs\ntZ8WI33UZZytE8A99EvJjck228LxUQtL5A8q7O21... | UNKNOWN | PYTHON3 | CODEFORCES | 126 | |
7d0021fff1db0738b43fd95baf153cdf | Bindian Signalizing | Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by *n* hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night.
In case of any danger the watchman could make a fire on the hill. One watchman co... | [
"n = int(input())\r\na = tuple(map(int, input().split()))\r\nb = 0\r\nc, at = max((h, k) for k, h in enumerate(a))\r\nlast = c\r\ncount = 0\r\nd = list()\r\ne = d.append\r\nf = d.pop\r\nfor at in range(at - 1, at - n, -1):\r\n current = a[at]\r\n while current > last:\r\n b += count\r\n last, co... | {"inputs": ["5\n1 2 4 5 3", "3\n2118 2118 2118", "3\n2221 1976 2221", "3\n140 989 2895", "4\n2440 2440 2440 2440", "4\n1178 1178 2577 2577", "4\n332 2714 2420 2714", "5\n763 763 763 763 763", "5\n4136 1826 4136 1826 1826", "5\n3581 3581 305 305 3581", "10\n8097 8097 8097 8097 8097 8097 8097 8097 8097 8097", "10\n4972 4... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
7d45cdf7b667f99d847c39980aeeb60c | New Year Table | Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal *r*. Each plate must be completely inside th... | [
"from math import asin, pi\r\nfrom sys import exit\r\n\r\nn, R, r = [int(i) for i in input().split()]\r\nif r == R:\r\n if n == 1:\r\n print(\"YES\")\r\n exit()\r\n else:\r\n print(\"NO\")\r\n exit()\r\nif r > R:\r\n print(\"NO\")\r\n exit()\r\nif 2 * r > R and R > r:\r\n ... | {"inputs": ["4 10 4", "5 10 4", "1 10 10", "3 10 20", "2 20 11", "6 9 3", "1 999 1000", "1 1000 999", "2 1000 500", "2 1000 499", "10 1000 236", "10 1000 237", "6 999 334", "100 1000 1", "100 1000 50", "13 927 179", "13 145 28", "37 307 24", "37 857 67", "100 821 25", "100 197 6", "93 704 23", "93 857 28", "85 870 31",... | UNKNOWN | PYTHON3 | CODEFORCES | 21 | |
7d508bb3c9171e2cb143d709a0195e60 | Cutting Figure | You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected.
A set of painted squares is called connected, if for... | [
"m, n = list(map(int, input().split()))\r\ngrid = [list(input()) for _ in range(m)]\r\ncount = sum(i.count('#') for i in grid)\r\nif count <= 2:\r\n print(-1)\r\n exit()\r\ntable = {}\r\nnode = 0\r\ngraph = [[] for _ in range(count)]\r\nfor i in range(m):\r\n for j in range(n):\r\n if grid[i][j] == ... | {"inputs": ["5 4\n####\n#..#\n#..#\n#..#\n####", "5 5\n#####\n#...#\n#####\n#...#\n#####", "1 10\n.########.", "1 1\n#", "3 3\n.#.\n###\n.#.", "1 2\n##", "2 1\n#\n#", "3 3\n###\n#.#\n###", "2 2\n##\n#.", "2 2\n##\n##", "2 2\n.#\n##", "2 2\n.#\n.#", "9 9\n#########\n#.......#\n#.#####.#\n#.#.#.#.#\n#.#.#.#.#\n#.#.#.#.#\... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
7d64dcb19ecf9079b5165273eaa64d34 | none | There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following steps happe... | [
"n = int(input())\r\na = input().split()\r\nprint((2 ** (n - 1) - 1 - sum([2 ** a.count(x) - 1 for x in set(a) - set(['-1'])])) % (10 ** 9 + 7))"
] | {"inputs": ["3\n-1 -1 -1", "2\n2 -1", "40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3", "8\n-1 3 -1 -1 -1 3 -1 -1", "10\n3 -1 -1 -1 -1 -1 -1 -1 2 2", "50\n36 36 45 44 -1 -1 13 -1 36 -1 44 36 -1 -1 -1 35 -1 36 36 35 -1 -1 -1 14 36 36 22 36 13 -1 35 -1 35 36... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7d844d6775d42e77bdc1cb91244582dc | Win or Freeze | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of cir... | [
"q = int(input())\r\ndef is_prime(n):\r\n if n % 2 == 0 and n != 2:\r\n return False\r\n for i in range(3, int(n**0.5)+1, 2):\r\n if n % i == 0:\r\n return False\r\n return True\r\nif is_prime(q):\r\n print(\"1\\n0\")\r\nelse:\r\n f = []\r\n while q % 2 == 0:\r\n q //= 2\r\n f.append(2)\r\n ... | {"inputs": ["6", "30", "1", "2", "3", "5", "445538663413", "5138168457911", "472670214391", "1468526771489", "1307514188557", "8110708459517", "7938986881993", "34280152201", "8587340257", "1245373417369", "48855707", "614125", "1716443237161", "49380563", "2975", "5839252225", "266418", "319757451841", "3047527844089"... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
7da890448904453791d46d9c3c30dd06 | Straight <<A>> | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | [
"n, k = map(int, input().split())\r\nmarks = list(map(int, input().split()))\r\ns = sum(marks)\r\nq = 0\r\nwhile s < n * (k - 0.5):\r\n q += 1\r\n s += k\r\n n += 1\r\nprint(q) ",
"def average(ns):\n return sum(ns)/len(ns)\n\ndef main():\n t = [int(x) for x in input().split()]\n n = t[0]\n ... | {"inputs": ["2 10\n8 9", "3 5\n4 4 4", "3 10\n10 8 9", "2 23\n21 23", "5 10\n5 10 10 9 10", "12 50\n18 10 26 22 22 23 14 21 27 18 25 12", "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6", "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 ... | UNKNOWN | PYTHON3 | CODEFORCES | 207 | |
7dddbb9040083213e97b91c3df4cdee6 | Micro-World | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c... | [
"n, K = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nnum = 0\r\n\r\n\r\nfor i in a:\r\n while a[num] < i:\r\n if i <= K+a[num]:\r\n n-=1\r\n num += 1\r\nprint(n)\r\n\r\n",
"n ,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\... | {"inputs": ["7 1\n101 53 42 102 101 55 54", "6 5\n20 15 10 15 20 25", "7 1000000\n1 1 1 1 1 1 1", "1 1\n1", "1 4\n8", "10 1\n1 2 3 5 6 8 10 11 9 4", "9 2\n1 6 1 5 5 8 6 8 7", "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "2 1000000\n1 1000000", "7 2\n1 5 5 8 9 8 8", "10 1\n2 6 3 4 2 4 4 3 2 1", "4 1\n2 2 1 1", "10 1\n6 3 1 3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 116 | |
7dddfc97c29f8241b7b8802b5da11818 | Dominoes | You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number of points? You can rotate the dominoes, changing the left and the ri... | [
"import sys\n\n\ndef solve(start, g):\n ret = []\n for i in range(10):\n if g[start][i] == 0: continue\n g[start][i] -= 1\n g[i][start] -= 1\n ret = solve(i, g) + ret\n return [start] + ret\n\n\ndef main():\n n = int(input())\n edge = []\n cnt = [0 for i in range(10)]\n... | {"inputs": ["5\n1 2\n2 4\n2 4\n6 4\n2 1", "1\n0 0", "1\n5 5", "5\n0 0\n0 0\n0 0\n0 0\n0 0", "4\n0 0\n0 0\n1 1\n1 1", "100\n1 5\n0 3\n0 0\n3 1\n1 5\n0 5\n3 0\n3 0\n5 3\n2 4\n3 4\n1 3\n6 2\n1 5\n1 5\n5 4\n6 0\n6 0\n0 0\n3 3\n5 6\n6 3\n4 3\n5 6\n4 0\n4 2\n2 6\n0 6\n6 6\n4 1\n2 0\n1 5\n1 0\n1 5\n0 0\n1 6\n4 5\n3 0\n3 2\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7de8573438838f7b11a5b8ceb7d682db | Football Kit | Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this team has color *y**i* (*x**i*<=≠<=*y**i*).
In the tournament, each team plays exactly one home g... | [
"n = int(input())\r\n\r\na = [0 for i in range(n)]\r\nx = [0 for i in range(100001)]\r\n\r\nfor i in range(n):\r\n s, a[i] = map(int, input().split())\r\n x[s] += 1\r\n\r\nfor i in range(n):\r\n print(n - 1 + x[a[i]], n - 1 - x[a[i]])",
"n=int(input())\r\nMy_dict={}\r\nlst=[]\r\nfor i in range(n):\r\n ... | {"inputs": ["2\n1 2\n2 1", "3\n1 2\n2 1\n1 3", "2\n1 2\n1 2", "2\n1 2\n3 4", "3\n1 100000\n1 100000\n100000 2", "5\n3 2\n3 4\n2 5\n3 2\n4 3", "6\n2 3\n2 1\n2 1\n3 2\n3 2\n3 1", "10\n2 1\n1 3\n4 1\n2 3\n4 1\n1 4\n2 4\n2 1\n2 3\n3 4", "30\n1 10\n1 7\n6 10\n2 6\n10 2\n1 8\n3 8\n10 2\n7 4\n10 4\n9 1\n3 7\n1 8\n2 5\n3 4\n2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
7ded6f93db6dcb0a548c4f4a53af23db | Ilya and tic-tac-toe game | Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by maki... | [
"def check(i, j):\r\n if field[i][j] == '.':\r\n if field[i - 1][j] == field[i + 1][j] and field[i - 1][j] == 'x':\r\n return True\r\n elif field[i - 2][j] == field[i - 1][j] and field[i - 1][j] == 'x':\r\n return True\r\n elif field[i + 2][j] == field[i + 1][j] and fie... | {"inputs": ["xx..\n.oo.\nx...\noox.", "x.ox\nox..\nx.o.\noo.x", "x..x\n..oo\no...\nx.xo", "o.x.\no...\n.x..\nooxx", ".xox\no.x.\nx.o.\n..o.", "o.oo\n.x.o\nx.x.\n.x..", "xxox\no.x.\nx.oo\nxo.o", ".xox\n.x..\nxoo.\noox.", "...x\n.x.o\n.o..\n.x.o", "oo.x\nxo.o\no.xx\n.oxx", ".x.o\n..o.\n..ox\nxox.", "....\n.x..\nx...\n..o... | UNKNOWN | PYTHON3 | CODEFORCES | 45 | |
7e0ef018667adacfdfe7b5aed7fe4248 | Short Program | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an... | [
"from operator import __or__, __and__, __xor__\r\nfrom sys import stdin, stdout\r\nn, b, c = int(stdin.readline()), 0, 1023\r\nm = {'|': __or__, '&': __and__, '^': __xor__}\r\nfor i in range(n):\r\n t, v = [i for i in stdin.readline().split()]\r\n b = m[t](b, int(v))\r\n c = m[t](c, int(v))\r\nx, o, a = 0,... | {"inputs": ["3\n| 3\n^ 2\n| 1", "3\n& 1\n& 3\n& 5", "3\n^ 1\n^ 2\n^ 3", "2\n| 999\n^ 689", "3\n& 242\n^ 506\n^ 522", "2\n| 56\n^ 875", "3\n^ 125\n^ 377\n& 1019", "1\n& 123", "1\n| 123", "1\n^ 123", "10\n^ 218\n& 150\n| 935\n& 61\n| 588\n& 897\n| 411\n| 584\n^ 800\n| 704", "10\n^ 160\n& 1021\n& 510\n^ 470\n& 1022\n& 251... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
7e10a81ffb453c0c0029a121b4341dfb | USB Flash Drives | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line... | [
"n = int(input())\r\nm = int(input())\r\nl = []\r\nfor i in range(n):\r\n s = int(input())\r\n l.append(s)\r\na =0\r\nwhile(m>0):\r\n a+=1\r\n k = max(l)\r\n c = l.index(k)\r\n m -=k\r\n l.pop(c)\r\n if(m<=0):\r\n break\r\n\r\nprint(a)",
"#Code:\r\n\r\ntest=[]\r\n\r\nfor i in range(... | {"inputs": ["3\n5\n2\n1\n3", "3\n6\n2\n3\n2", "2\n5\n5\n10", "5\n16\n8\n1\n3\n4\n9", "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8", "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227", "30\n70\n6\n2\n10\n4\n7\n10\n5... | UNKNOWN | PYTHON3 | CODEFORCES | 513 | |
7e2d429de3caabf36076ceafdf38d459 | Dinner with Emma | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | [
"n, m = map(int, input().split())\r\nul = []\r\npr = []\r\nfor i in range(n):\r\n pr = [int(i) for i in input().split()]\r\n ul.append(pr)\r\n pr = []\r\nmini = []\r\nmaxi = []\r\nfor i in range(n):\r\n min1 = ul[i][0]\r\n for j in range(m):\r\n if min1 > ul[i][j]:\r\n min1 = ul[i][... | {"inputs": ["3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1", "3 3\n1 2 3\n2 3 1\n3 1 2", "1 1\n1", "1 10\n74 35 82 39 1 84 29 41 70 12", "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85", "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 82... | UNKNOWN | PYTHON3 | CODEFORCES | 133 | |
7e3b36d489e3c9308df8f9172f63895f | Kolya and Tandem Repeat | Kolya got string *s* for his birthday, the string consists of small English letters. He immediately added *k* more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length *l* as a substring. How large could *l* be?
See notes for definition of a tandem re... | [
"import sys\r\n#sys.setrecursionlimit(10**7)\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef in... | {"inputs": ["aaba\n2", "aaabbbb\n2", "abracadabra\n10", "zwvrx\n3", "ayi\n10", "eexlzphiay\n1", "zumtumtlitf\n2", "xbmrxbmrkzovhb\n3", "ijtvifbuajod\n5", "jhfwjyyzwrjiyrrgveiqkoltivghgkontrqragikttxxuwszjwqhwxindyrdqhucnbwgwrppgqmsasrzohezjlfmkzsqptwpratprcrxyxecnlsaiqrvimihmhjfgzwdtvmfhgbuonpsblphyoxzclkrwbwrkasahiirz... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
7e625e4a607cb083c6ac116e33b70096 | Reflection | For each positive integer *n* consider the integer ψ(*n*) which is obtained from *n* by replacing every digit *a* in the decimal notation of *n* with the digit (9<=<=-<=<=*a*). We say that ψ(*n*) is the reflection of *n*. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So ... | [
"from sys import stdin\r\ninp = stdin.readline\r\n\r\na, b = inp().split()\r\nmid = \"5\" + \"\".join([\"0\" for _ in range(len(b)-1)])\r\nif int(a) > int(mid):\r\n ans = a\r\nelif int(b) < int(mid):\r\n ans = b\r\nelse:\r\n ans = mid\r\n\r\nref = \"\"\r\nfor c in ans:\r\n ref += str(9 - int(c))\r\n\r\n... | {"inputs": ["3 7", "1 1", "8 10", "4 6", "10 100", "1 999", "40 60", "66 74", "27 71", "66 95", "48 51", "9999999 9999999", "555555 555555", "942 572335596", "2331 77424372", "314 592188442", "6277 181089912", "163 306093048", "9265 978077465", "934 300539101", "850 629417171", "9015 34697316", "595 416293084", "3722 8... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
7e7f3dd7295be10757799855d78df607 | Falling Anvils | For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who ... | [
"for i in range(int(input())):\r\n a, b = map(int, input().split())\r\n print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)",
"for i in range(int(input())):print(\"%.8f\"%(lambda a,b:1 if a==0==b else (a/b/16+1/2)if b>a/4 else(1-b/a))(*list(map(int,input().split()))[0:2]))",
"import sys\ninp... | {"inputs": ["2\n4 2\n1 2", "90\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n1 2\n2 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 2\n9 2\n1 3\n2 3\n3 3\n4 3\n5 3\n6 3\n7 3\n8 3\n9 3\n1 4\n2 4\n3 4\n4 4\n5 4\n6 4\n7 4\n8 4\n9 4\n1 5\n2 5\n3 5\n4 5\n5 5\n6 5\n7 5\n8 5\n9 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n7 6\n8 6\n9 6\n1 7\n2 7\n3 7\n4 7... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
7e867a304eb0618de56b5adeb0adca21 | none | Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены дру... | [
"n = int(input())\r\ns = 0\r\na = list(map(int,input().split()))\r\nj = 1\r\nfor i in range (n*2):\r\n s += a[i]\r\nb = s/n\r\nwhile len (a) > 0:\r\n f = a[0] + a[j]\r\n if f==b:\r\n print (a[0], a[j], sep=' ')\r\n a = a[1:j] + a[j+1:]\r\n j = 0\r\n j+=1\r\n",
"n=int(input())\r\np... | {"inputs": ["3\n1 3 2 4 5 3", "3\n1 1 1 2 2 2", "1\n3 7", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15", "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539", "100\n8 7 7 5 2 7 7 5 1 8 6 3 6 7 2 4 4 2 6 8 5 6 5 2 6 1 3 9 5 8 7 6 5 4 8 6 5 5 3 2 6 5 4 9 7 1 5 7 9 5 7 4 1 6 5 8 2 6... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
7e9e640b2aa2853e7ba9b99a1f729c44 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to *n*. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from *l* to *r* inclusively and put them in the reverse... | [
"n = int(input())\r\nA = list(map(int, input().split()))\r\nT = list(range(1, n+1))\r\nfor i, a in enumerate(A):\r\n if a != i+1:\r\n break\r\nelse:\r\n print(0, 0)\r\n exit()\r\n\r\nB = A[0:i]+list(reversed(A[i:a]))+A[a:]\r\nif B == T:\r\n print(i+1, a)\r\nelse:\r\n print(0, 0)\r\n",
"n = i... | {"inputs": ["8\n1 6 5 4 3 2 7 8", "4\n2 3 4 1", "4\n1 2 3 4", "8\n1 3 2 4 6 5 7 8", "8\n1 3 4 2 6 5 7 8", "1\n1", "2\n1 2", "2\n2 1", "149\n9 120 122 97 93 70 85 56 102 16 103 112 88 84 118 135 113 62 65 19 89 15 108 73 82 21 147 27 115 130 136 6 1 90 29 94 149 17 53 132 99 123 64 95 71 67 141 126 59 8 10 114 121 134 1... | UNKNOWN | PYTHON3 | CODEFORCES | 48 | |
7eb0da0bbbcb2806ed5714ca454320e7 | The Meaningless Game | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is... | [
"import io\r\nimport os\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nt = int(input())\r\n\r\nfor tc in range(t):\r\n\r\n a, b = map(int, input().split())\r\n\r\n cbrt = round(pow(a*b, 1/3))\r\n\r\n if pow(cbrt, 3) == a*b:\r\n if a % cbrt == b % cbrt == 0:\r\n pri... | {"inputs": ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "3\n1 1\n8 27\n1000 1331", "1\n12004 18012002", "1\n3331 11095561", "1\n2 3", "1\n1062961 1031", "1\n6 12", "1\n3 1", "1\n3 10", "1\n31159 970883281", "1\n9907 98148649", "1\n16 8", "1\n90 72"], "outputs": ["Yes\nYes\nYes\nNo\nNo\nYes", "Yes\nNo\nNo"... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
7eb8f58de43c50a8d69328b3803bf014 | Pizza Separation | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide a... | [
"n=int(input())\r\na=[int (i) for i in input().split()]\r\n\r\nmin=361\r\nfor i in range(n):\r\n for j in range(i, n):\r\n if -min<sum(a[0:i])+sum(a[j:])-sum(a[i:j])<min:\r\n min=sum(a[0:i])+sum(a[j:])-sum(a[i:j])\r\n if min<0:\r\n min*=-1\r\n \r\nprint(min)",
"n = int(input())\n\nbest... | {"inputs": ["4\n90 90 90 90", "3\n100 100 160", "1\n360", "4\n170 30 150 10", "5\n10 10 10 10 320", "8\n45 45 45 45 45 45 45 45", "3\n120 120 120", "5\n110 90 70 50 40", "2\n170 190", "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "5\n30 60 180 60 30", "2\n359 1", "5\n100 100 30 100 30", "5\n36 34 35 11 244", "5\n... | UNKNOWN | PYTHON3 | CODEFORCES | 146 | |
7ed2fb332ead357e5fd2ae9c305aaadf | Cormen --- The Best Friend Of a Man | Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least *k* walks for any two consecutive days in order to feel good. For example, if *k*<==<=5 and yesterday Polycarp went... | [
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nc = 0\r\nfor i in range(n-1):\r\n if a[i] + a[i+1] < k:\r\n c += k - (a[i] + a[i + 1])\r\n a[i+1] += k - (a[i] + a[i+1])\r\nprint(c)\r\nprint(*a)",
"n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\... | {"inputs": ["3 5\n2 0 1", "3 1\n0 0 0", "4 6\n2 4 3 5", "5 1\n0 0 0 0 1", "10 500\n164 44 238 205 373 249 87 30 239 90", "1 1\n1", "5 1\n0 0 0 0 0", "5 1\n0 0 0 0 1", "5 2\n0 0 0 1 0", "5 5\n1 4 0 0 0", "5 10\n1 2 1 0 1", "5 10\n0 1 0 1 0", "10 5\n0 2 3 0 0 1 0 2 3 1", "10 1\n0 0 0 0 0 0 0 0 1 0", "10 436\n13 16 45 9 1... | UNKNOWN | PYTHON3 | CODEFORCES | 51 | |
7ee0356b1b5e79e1c67200d0c9a585b1 | Shortest Path | In Ancient Berland there were *n* cities and *m* two-way roads of equal length. The cities are numbered with integers from 1 to *n* inclusively. According to an ancient superstition, if a traveller visits three cities *a**i*, *b**i*, *c**i* in row, without visiting other cities between them, a great disaster awaits him... | [
"\r\nn, m, k = map(int, input().split())\r\ngraph = [[] for i in range(n + 2)]\r\nfor _ in range(m):\r\n x, y = map(int, input().split())\r\n graph[x].append(y)\r\n graph[y].append(x)\r\n\r\ngraph[n].append(n + 1)\r\n \r\ntriples = set(a + (b + c * n) * n for a, b, c in ( map(int, input().split()) for i i... | {"inputs": ["4 4 1\n1 2\n2 3\n3 4\n1 3\n1 4 3", "3 1 0\n1 2", "4 4 2\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4", "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 2 3", "2 1 0\n1 2", "4 4 1\n1 2\n2 3\n3 4\n1 3\n1 3 4", "3 2 0\n1 2\n3 2", "3 2 1\n1 2\n3 2\n1 2 3", "4 4 4\n1 2\n2 3\n3 4\n1 3\n1 2 3\n1 3 4\n1 2 4\n1 3 2"], "outputs": ["2\n1 3 4", "-... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
7ef8d70d94ebd6d424af6d9e8cf5d981 | Coins | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | [
"a = b = c = 0\r\nfor i in range(3):\r\n\ts = input()\r\n\tif s[0] == \"A\" and s[1] == \">\":\r\n\t\ta += 1\r\n\telif s[0] == \"A\" and s[1] == \"<\" and s[2] == \"B\":\r\n\t\tb += 1\r\n\telif s[0] == \"A\" and s[1] == \"<\" and s[2] == \"C\":\r\n\t\tc += 1\r\n\r\n\telif s[0] == \"B\" and s[1] == \">\":\r\n\t\tb +... | {"inputs": ["A>B\nC<B\nA>C", "A<B\nB>C\nC>A", "A<C\nB<A\nB>C", "A<B\nA<C\nB>C", "B>A\nC<B\nC>A", "A>B\nB>C\nC<A", "A>C\nA>B\nB<C", "C<B\nB>A\nA<C", "C<B\nA>B\nC<A", "C>B\nB>A\nA<C", "C<B\nB<A\nC>A", "B<C\nC<A\nA>B", "A>B\nC<B\nC<A", "B>A\nC>B\nA>C", "B<A\nC>B\nC>A", "A<B\nC>B\nA<C", "A<B\nC<A\nB<C", "A>C\nC<B\nB>A", "C... | UNKNOWN | PYTHON3 | CODEFORCES | 275 | |
7f06cf906d3c851d618076732c708a09 | Patrick and Shopping | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | [
"def good(a,b,c):\r\n return min(a,b+c)+min(c,a+b)+min(b,a+c)\r\na,b,c=map(int,input().split())\r\nprint(good(a, b, c))",
"d1,d2,d3=map(int,input().split())\r\nprint(min((d1+d2+d3),(2*d1+2*d2),(2*d2+2*d3),(2*d1+2*d3)))",
"d1,d2,d3=map(int,input().split())\r\nprint(min(d1+d2+d3,d1*2+d2*2,d1*2+d3*2,d2*2+d3*2))... | {"inputs": ["10 20 30", "1 1 5", "100 33 34", "777 777 777", "2 2 8", "12 34 56", "789 101112 131415", "27485716 99999999 35182", "1 293548 5", "12059 259855 5874875", "46981 105809 585858", "9889 1221 2442", "100500 200600 300700", "318476 318476 318476", "23985 3353 75633", "120 1298 2222", "98437 23487 666672", "100... | UNKNOWN | PYTHON3 | CODEFORCES | 512 | |
7f2a40ffb32ee0ea022d8d2ccfef1568 | Big Data | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
- ... | [
"s=\"01001010111001010\"\nprint(s[int(input())])",
"print(\"1001010111001010\"[int(input())-1])",
"# LUOGU_RID: 98515207\nprint(' 1001010111001010'[int(input())])\r\npass",
"# LUOGU_RID: 98179837\nprint(' 1001010111001010'[int(input())])\r\npass",
"# LUOGU_RID: 104668388\nprint(\" 1001010111001010\"[int(inp... | {"inputs": ["1", "7", "13", "3", "8", "16", "11", "2", "5", "10", "9", "15", "4", "12", "6", "14"], "outputs": ["1", "0", "1", "0", "1", "0", "0", "0", "0", "1", "1", "1", "1", "0", "1", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
7f638bd6b5c442a8088b1872b76c3ff9 | Flags | When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught his attention. In the problem one had to find the number of three-colored flags that would satisfy the conditio... | [
"MOD = (10**9)+7\r\ndef cal(x):\r\n if x==0:\r\n return 0\r\n elif x==1:\r\n return 4\r\n elif x&1:\r\n a1=11*pow(3,x//2,MOD)-7\r\n #print(a1,x)\r\n return a1\r\n else:\r\n return 19*pow(3,x//2-1,MOD)-7\r\n\r\n\r\ndef grp(x):\r\n return (cal(x)+cal(x+1>>1))*p... | {"inputs": ["3 4", "5 6", "3 3", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "3 100", "1 1", "1 2", "1 3", "1 4", "2 2", "2 3", "2 4", "4 4", "1 1000000000", "2 1000000000", "3 1000000000", "4 1000000000", "999999998 1000000000", "999999999 1000000000", "1000000000 1000000000", "9 30", "3 47", "9 47", "8 36", "8 37", "8... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
7f642d29a6523b89764d5462b24da7b5 | Garland | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | [
"s=input()\r\ng=input()\r\n\r\nmp1={}\r\nmp2={}\r\n\r\ncount=0\r\ncnt=0\r\n\r\nfor i in s:\r\n if(i not in mp1.keys()):\r\n mp1[i]=1\r\n else:\r\n mp1[i]+=1\r\nfor i in g:\r\n if(i not in mp2.keys()):\r\n mp2[i]=1\r\n else:\r\n mp2[i]+=1 \r\n\r\nfor i in mp2.keys():\r\... | {"inputs": ["aaabbac\naabbccac", "a\nz", "r\nr", "stnsdn\nndnndsn", "yqfqfp\ntttwtqq", "zzbbrrtrtzr\ntbbtrrrzr", "ivvfisvsvii\npaihjinno", "zbvwnlgkshqerxptyod\nz", "xlktwjymocqrahnbesf\nfoo", "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebq... | UNKNOWN | PYTHON3 | CODEFORCES | 150 | |
7f7795304e826b9b5db2579af029fffb | Literature Lesson | Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their ... | [
"n,k=list(map(int,input().split()))\r\ndef z(a,b):\r\n global k\r\n c=0\r\n d=''\r\n for i in range(len(a)-1,-1,-1):\r\n d+=a[i]\r\n if a[i] in ['a','e','i','o','u']:\r\n c+=1\r\n if c==k:\r\n break\r\n f=c==k\r\n c=0\r\n e=''\r\n for i in range(len... | {"inputs": ["1 1\nday\nmay\nsun\nfun", "1 1\nday\nmay\ngray\nway", "2 1\na\na\na\na\na\na\ne\ne", "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "2 5\na\na\na\na\na\na\ne\ne", "1 1\nrezwbgy\nxakgmv\njogezwbgy\napezwbgy", "2 1\nnuqfxwrb\napqfkw\nuqfxwrb\nnhcuqfxwrb\nogkznwncmt\nevf\nogkznwncmt\nogkznwncmt", "1 1\n... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
7f7ccd7bfb17be7014596f08c0ba175f | Watto and Mechanism | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the ... | [
"mod = 9999999999999999\r\nmemory = set()\r\n\r\nn, m = map(int, input().split())\r\n\r\nfor _ in range(n):\r\n \r\n s = input()\r\n slen = len(s)\r\n pwr, h_val = 1, 0\r\n\r\n for i in range(slen):\r\n h_val = (h_val + ord(s[i]) * pwr) % mod\r\n pwr = (pwr * 203) % mod\r\n\r\n pwr =... | {"inputs": ["2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac", "1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb", "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb", "9 9\ncaccbcacabccba\naacbcbcaabacbcbcba\nbabccaaacccacbb\ncaaabcaacbababbabbb\nabbaccacabacaaaa\nbccbccababcaacb\ncaacbcaacbababbab... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
7fade72fccef41df7bb624d7534b67df | Brain Network (easy) | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite!... | [
"from collections import deque\r\n\r\nn, m = [int(i) for i in input().split()]\r\ngraph = [[] for i in range(n)]\r\nfor i in range(m):\r\n a, b = [int(i) for i in input().split()]\r\n graph[a - 1].append(b - 1)\r\n graph[b - 1].append(a - 1)\r\n\r\n\r\ndef bfs():\r\n visited = [False] * n\r\n queue =... | {"inputs": ["4 4\n1 2\n2 3\n3 1\n4 1", "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "2 1\n1 2", "3 3\n2 1\n1 3\n3 2", "3 2\n1 2\n2 3", "9 8\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 9", "8 7\n6 2\n1 5\n4 8\n4 7\n6 7\n8 3\n8 1", "200 5\n93 101\n199 164\n14 94\n115 61\n106 156", "10 9\n6 5\n9 2\n4 7\n2 3\n7 3\n3 4\n10 6\n1 2\n5 8", "10 9... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
7fb1f4b5006d1f42e41292d10c218c31 | Weird Subtraction Process | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then s... | [
"a, b=map (int, input ().split ())\r\nwhile True:\r\n\tif (a==0 or b==0) or (max(a, b)<2*min(a,b)):\r\n\t\tprint (a, b)\r\n\t\tbreak\r\n\telif a>=2*b:\r\n\t\ta=a-(a//(2*b))*2*b\r\n\telse:\r\n\t\tb=b-(b//(2*a))*2*a",
"x, y = map(int, input().split())\r\nans = []\r\nk = 0\r\nwhile True:\r\n if x >= 2 * y:\r\n x... | {"inputs": ["12 5", "31 12", "1000000000000000000 7", "31960284556200 8515664064180", "1000000000000000000 1000000000000000000", "1 1000", "1 1000000", "1 1000000000000000", "1 99999999999999999", "1 4", "1000000000000001 500000000000000", "1 1000000000000000000", "2 4", "2 1", "6 19", "22 5", "10000000000000000 100000... | UNKNOWN | PYTHON3 | CODEFORCES | 98 | |
7fc45e96c02615a2cc4a675cddd533b0 | Fountains | Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are all... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef sparse_table(a):\r\n table = []\r\n s0, l = a, 1\r\n table.append(s0)\r\n while 2 * l <= len(a):\r\n s = [max(s0[i], s0[i + l]) for i in range(len(s0) - l)]\r\n table.append(list(s))\r\n s... | {"inputs": ["3 7 6\n10 8 C\n4 3 C\n5 6 D", "2 4 5\n2 5 C\n2 1 D", "3 10 10\n5 5 C\n5 5 C\n10 11 D", "6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D", "6 4 9\n6 6 D\n1 4 D\n6 7 C\n7 6 D\n5 7 D\n2 5 D", "52 38 22\n9 25 D\n28 29 C\n29 25 D\n4 28 D\n23 29 D\n24 25 D\n17 12 C\n11 19 C\n13 14 C\n12 15 D\n7 25 C\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
7fe9b3c996302555cb30ddbb77124d9e | Unsolvable | Consider the following equation:
Let's find all integer *z* (*z*<=><=0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers *x* and *y* (*x*,<=*y*<=><=0), for which the given above equation holds.
Let's write o... | [
"mod = 10**9+7\r\na = [2,3,5,7,13,17,19,31,61,89,107,127,521,607,1279,2203,2281,3217,4253,4423,9689,9941,11213,19937,21701,23209,44497,86243,110503,132049,216091,756839,859433,1257787,1398269,2976221,3021377,6972593,13466917,20996011]\r\nn = int(input())\r\nprint(pow(2,a[n-1]-1,mod)-1)\r\n",
"n = int(input())\r\n... | {"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"], "outputs": ["1", "3", "15", "63", "4095", "65535", "262143", "73741816", "53... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
8031d3ee80b63cbdd0fc081c9cee561f | Ilya and Queries | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | [
"from sys import stdin\r\ns=input()\r\nlist1=[0]*len(s)\r\nfor i in range(1,len(s)):\r\n list1[i]=list1[i-1]+(s[i]==s[i-1])\r\nfor i in range(int(input())):\r\n l,r=map(int,stdin.readline().split())\r\n print(list1[r-1]-list1[l-1])\r\n",
"# LUOGU_RID: 125426540\nstr = input()\r\nlist = [0] * len(str)\r\n... | {"inputs": ["......\n4\n3 4\n2 3\n1 6\n2 6", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3", "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5", "#..#\n1\n1 4", "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4", "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 204 | |
80349b15c8104db3dc055c860f58511a | Maze 2D | The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2<=×<=*n* maze.
Imagine a maze that looks like a 2<=×<=*n* rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can ... | [
"import sys\ninput = sys.stdin.readline\ninfinity = 10**6\n\ndef convert(c):\n if c == '.':\n return True\n else:\n return False\n\ndef find_next_dist_helper(i, b, c, shift, dist, maze):\n if shift == 1:\n if (not maze[b][i]) or (not maze[c][i + 1]):\n return infinity\n ... | {"inputs": ["4 7\n.X..\n...X\n5 1\n1 3\n7 7\n1 4\n6 1\n4 7\n5 7", "10 3\nX...X..X..\n..X...X..X\n11 7\n7 18\n18 10", "1 1\n.\n.\n1 2", "2 1\n..\n.X\n1 2", "2 1\n..\nX.\n1 2", "2 1\n..\nX.\n1 4", "2 1\n.X\n..\n1 4", "2 1\nX.\n..\n2 3", "2 1\n..\n.X\n3 2"], "outputs": ["1\n4\n0\n5\n2\n2\n2", "9\n-1\n3", "1", "1", "1", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8064634d8049cafb0812bc65774e8736 | Interesting Game | Two best friends Serozha and Gena play a game.
Initially there is one pile consisting of *n* stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of *a*1<=><=*a*2<=><=...<=><=*a**k*<=><=0 stones. The piles should meet the condition *a*1<=-<=... | [
"# LUOGU_RID: 132710750\nfrom functools import reduce\r\n\r\nn = int(input())\r\nsg = [0 for _ in range(n + 1)]\r\nxorSum = [0 for _ in range(n + 1)]\r\nL = [[] for _ in range(n + 1)]\r\nlen = 2\r\n\r\nwhile True:\r\n if len * (len + 1) // 2 > n:\r\n break\r\n a1 = 1\r\n while True:\r\n sum =... | {"inputs": ["3", "6", "100", "33", "23", "35", "15", "99", "46", "78", "627", "250", "873", "871", "684", "303", "93764", "39509", "70878", "7578", "31893", "57113", "66873", "9564", "42237", "92763", "38798", "63359", "573", "60879", "67341", "15748", "42602", "67817", "81207", "8149", "95298", "41385", "27443", "7442... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
807c274c38b88f13353f30a0b0a62af6 | Discounts | One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape... | [
"n, k = list(map(int, input().split()))\n\np = [[], []]\n\nfor i in range(1, n + 1):\n\n c, t = map(int, input().split())\n\n p[t > 1].append((c, i))\n\nif k > len(p[0]):\n\n l = k - len(p[0]) - 1\n\n print(sum(c for c, i in p[0]) / 2 + sum(c for c, i in p[1]))\n\n print('\\n'.join('1 ' + str(i) for ... | {"inputs": ["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2", "1 1\n1 1", "1 1\n1 2", "10 1\n1 1\n2 2\n1 1\n23 2\n17 2\n1 1\n1 1\n30 2\n1 1\n9 2", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2", "5 4\n24 1\n19 1\n28 2\n7 1\n23 2", "20 3\n28 1\n786180179 2\n16 1\n617105650 2\n23 1\n21 1\n22 1\n7 1\n314215... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
80986378f9ecabb610182e9e01ee76c7 | Reconnaissance 2 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | [
"n=int(input())\r\nm=list(map(int, input().split()))\r\na=[]\r\nfor i in range(n):\r\n a.append(abs(m[i]-m[i-1]))\r\ng=a.index(min(a))\r\nif g==0:\r\n print(1,n)\r\nelse:\r\n print(g,g+1)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nmi=100000000000\r\nans=-1\r\nfor i in range(n):\r\n if(ab... | {"inputs": ["5\n10 12 13 15 10", "4\n10 20 30 40", "6\n744 359 230 586 944 442", "5\n826 747 849 687 437", "5\n999 999 993 969 999", "5\n4 24 6 1 15", "2\n511 32", "3\n907 452 355", "4\n303 872 764 401", "10\n684 698 429 694 956 812 594 170 937 764", "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 ... | UNKNOWN | PYTHON3 | CODEFORCES | 529 | |
80a02d317a162a555112fead914c31e1 | Making Sequences is Fun | We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the ... | [
"def cnt(x, y):\r\n return y-x\r\n\r\nw, m, k = map(int, input().split())\r\np, d, res = 1, 0, 0\r\nwhile p <= m:\r\n p *= 10\r\n d += 1\r\nwhile cnt(m, p)*d*k <= w:\r\n w -= cnt(m, p)*d*k\r\n res += cnt(m, p)\r\n m = p\r\n p *= 10\r\n d += 1\r\nlo, hi = m, p\r\nwhile hi-lo > 1:\r\n mid = (lo+hi)//2\r\n i... | {"inputs": ["9 1 1", "77 7 7", "114 5 14", "1 1 2", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "462 183 8", "10000000000000000 1 1", "2155990066796462 2710473050636183 563261158", "552719169048748 7822730034794389 374302919", "6895788044242644 3474119895793364 732614708", "92305738044... | UNKNOWN | PYTHON3 | CODEFORCES | 38 | |
80cc5107e71a2f8ed4a0a93bc8680d56 | Reorder the Array | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can ... | [
"from collections import Counter\r\nn=int(input())\r\np=list(map(int, input().split(' ')))\r\ns=Counter(p)\r\ny=[s[i] for i in s]\r\ny.sort()\r\ny=[0]+y\r\nm=len(y)\r\nans=0\r\ntem=0\r\nfor i in range (0,m):\r\n if y[i]>tem:\r\n ans=ans+(m-i-1)*(y[i]-tem)\r\n tem=y[i]\r\nprint(ans)\r\n",
"# from ... | {"inputs": ["7\n10 1 1 1 5 5 3", "5\n1 1 1 1 1", "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "10\n1 2 3 4 5 6 7 8 9 10", "1\n1", "7\n3 5 2 2 5 2 4", "5\n1 5 4 2 3"], "outputs": ["4", "0", "3", "9", "0", "4", "4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 147 | |
80cfb08e92b0510fb8ce855b2eaa7382 | Phone Code | Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the... | [
"t=int(input())\r\nl=[]\r\nfor _ in range(t):\r\n s=input()\r\n l.append(s)\r\nm=l[0]\r\nc=0\r\nfor k in range(len(m)):\r\n flag=1\r\n for i in range(1,len(l)):\r\n if l[i][k]!=m[k]:\r\n flag=0\r\n break\r\n if flag==1:\r\n c+=1\r\n else:\r\n break\r\npri... | {"inputs": ["4\n00209\n00219\n00999\n00909", "2\n1\n2", "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", "10\n15424\n10953\n19176\n15514\n16284\n18680\n19305\n13816\n16168\n15924", "10\n4906361343\n8985777485\n1204265609\n7088384855\... | UNKNOWN | PYTHON3 | CODEFORCES | 212 | |
80d30acd3149e5f80f5e75a75d506b79 | Developing Skills | Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has *n* different skills, each of which is characterized by an integer *a**i* from 0 to 100. The higher the number *a**i* is, the higher is the *i*-th skill of the character. The total rating of the ... | [
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ns = 0\r\nr = [(10 - x % 10) % 10 for x in a]\r\ns += sum(x // 10 for x in a)\r\nr.sort()\r\nfor i in range(n):\r\n if r[i]:\r\n if r[i] <= k:\r\n k -= r[i]\r\n s += 1\r\ns += k // 10\r\ns = min(s, n * 10)\r\n... | {"inputs": ["2 4\n7 9", "3 8\n17 15 19", "2 2\n99 100", "100 10000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100 10000\n100 100 100 100 100 100 100 100 100 10... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
80f7124129b659f8bb7de526beeedbb7 | Three-level Laser | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*... | [
"def read_ints():\r\n return map(int, input().split())\r\n \r\n \r\ndef read_int():\r\n return int(input())\r\n \r\n\r\nn, max_delta = read_ints()\r\na = list(read_ints())\r\n\r\nans = -1\r\n\r\nright = 0\r\nfor left in range(n):\r\n while right + 1 < n and a[right + 1] - a[left] <= max_delta:\r\n... | {"inputs": ["4 4\n1 3 5 7", "10 8\n10 13 15 16 17 19 20 22 24 25", "3 1\n2 5 10", "5 3\n4 6 8 9 10", "10 128\n110 121 140 158 174 188 251 271 272 277", "20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265", "30 23\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 15... | UNKNOWN | PYTHON3 | CODEFORCES | 41 | |
8116b0c6c5a9ed18caa329c931d33990 | Two Tables | You've got two rectangular tables with sizes *n**a*<=×<=*m**a* and *n**b*<=×<=*m**b* cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the *i*-th row and the *j*-t... | [
"def solve(x,y):\r\n ans=0\r\n for i in range(na):\r\n for j in range(ma):\r\n if i+x<nb and i+x>-1 and j+y<mb and j+y>-1:\r\n v1=int(b[i+x][j+y])\r\n v2=int(a[i][j])\r\n ans+=v1*v2\r\n return ans\r\na,b=[],[]\r\nna,ma=list(map(int,input().spli... | {"inputs": ["3 2\n01\n10\n00\n2 3\n001\n111", "3 3\n000\n010\n000\n1 1\n1", "2 4\n1010\n0011\n5 5\n01100\n01110\n00111\n00110\n00110", "3 1\n0\n1\n0\n2 2\n11\n00", "1 5\n00110\n5 2\n11\n00\n01\n01\n11", "2 2\n11\n01\n2 2\n10\n11", "12 3\n111\n001\n101\n101\n010\n101\n110\n110\n101\n001\n010\n110\n1 26\n1101011001000011... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
81263fa7374bfd7992ffb8b4bd99174b | Coloring Trees | ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where *n* trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to *n* from left to right.
Initially, tree *i* has color *c**i*. ZS the Coder and Chris the Baboon recognizes ... | [
"import sys\r\ninput = sys.stdin.readline\r\nMAX = int(1e18)\r\nn,m,b = list(map(int,input().split()))\r\n\r\nc = list(map(int,input().split()))\r\np = [0]*n\r\nd = [[[0 for _ in range(0,107)] for _ in range(0,107)] for _ in range(0,107)]\r\nfor i in range(0,n):\r\n p[i] = list(map(int,input().split()))\r\n\r\n... | {"inputs": ["3 2 2\n0 0 0\n1 2\n3 4\n5 6", "3 2 2\n2 1 2\n1 3\n2 4\n3 5", "3 2 2\n2 0 0\n1 3\n2 4\n3 5", "3 2 3\n2 1 2\n1 3\n2 4\n3 5", "3 2 3\n0 0 0\n10 30000\n20000 1000000000\n1000000000 50000", "4 2 1\n0 0 0 0\n10 30000\n20000 1000000000\n1000000000 50000\n55 55", "4 2 1\n0 0 0 2\n10 30000\n20000 1000000000\n100000... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
81530ac1defad51d6b2ce6a51a25f966 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color... | [
"m,n=map(int,input().split())\r\nl=[[0 for i in range(n+1)] for j in range(m+1)]\r\nt=[]\r\nfor i in range(m):\r\n t.append(list(map(int,input().split())))\r\n\r\nfor i in range(1,m+1):\r\n for j in range(1,n+1):\r\n l[i][j]=max(l[i][j-1]+t[i-1][j-1],l[i-1][j]+t[i-1][j-1])\r\n\r\n# for i in l:\r\n# ... | {"inputs": ["5 1\n1\n2\n3\n4\n5", "4 2\n2 5\n3 1\n5 3\n10 1", "1 1\n66", "2 2\n1 1\n1 1", "2 2\n10 1\n10 1", "1 5\n1 95 44 14 35", "7 1\n80\n92\n24\n88\n40\n45\n7", "1 2\n51 44", "2 1\n19\n4", "2 2\n1 10\n1 1", "3 3\n3 9 4\n5 10 8\n4 4 7", "10 3\n6 10 3\n2 7 9\n10 4 7\n6 3 4\n6 2 6\n8 4 4\n5 9 8\n6 9 7\n2 7 10\n2 6 2"]... | UNKNOWN | PYTHON3 | CODEFORCES | 134 | |
815ad2e108b5611d42ee9b719310028e | Anton and Making Potions | Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare *n* potions.
Anton has a special kettle, that can prepare one potions in *x* seconds. Also, he knows spells of two types that can faster the process of preparing potions.
1. Spells... | [
"n,m,k=map(int,input().split())\r\na,b=map(int,input().split())\r\nq=list(map(int,input().split()))\r\nq1=list(map(int,input().split()))\r\nl1=[[q1[i],q[i]] for i in range(m)]\r\nqq1=list(map(int,input().split()))\r\nqq2=list(map(int,input().split()))\r\nl2=[[0,0]]+[[qq2[i],qq1[i]] for i in range(k)]\r\np=0\r\nli=a... | {"inputs": ["20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80", "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800", "10 3 3\n10 33\n1 7 6\n17 25 68\n2 9 10\n78 89 125", "94 1 1\n26 324\n7\n236\n77\n5", "3 4 5\n5 9\n1 2 1 1\n3 5 4 1\n1 1 1 1 3\n1 2 3 4 5", "1 4 2\n3 10\n2 1 1 1\n1 5 3 5\n1 1\n1 5", "5 3 3\n4 4\n2 3 1\n1 3 1\... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8166a47ee028698d418e3cf19e5bdbb2 | Newspaper Headline | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a n... | [
"s1 = input()\r\ns2 = input()\r\nfrom collections import defaultdict\r\nd = defaultdict(list)\r\nfor i in range(len(s1)):\r\n d[s1[i]].append(i)\r\nimport bisect\r\nans = 0\r\ncur = 10**18\r\nfor ch in s2:\r\n if ch not in d:\r\n print(-1)\r\n exit()\r\n else:\r\n if cur >= d[ch][-1]:\... | {"inputs": ["abc\nxyz", "abcd\ndabc", "ab\nbabaaab", "ab\nbaaabba", "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb", "ibifgcfdbfdhihbifageaaadegbfbhgeebgdgiafgedchdg\ndedfebcfdigdefdediigcfcafbhhiacgfbeccfchd", "fcagdciidcedeaicgfffgjefaefaachfbfj\naiecchjehdgbjfcdjdefgfhiddjajeddiigidaibeja... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
816c9f5df0e4959202f07bb94b561c90 | Ghosts | Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.
There are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own velocity that does not change in time: $\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrig... | [
"import sys\nif locals()['__file__'][-2:] == 'py':\n sys.stdin = open('in.txt', 'r')\nfrom sys import stdin\nrl = lambda l: tuple(map(int, l.split()))\nn, a, b = rl(input())\nl = list(map(rl, stdin.readlines()))\nc, d = {}, {}\nr = 0\nfor _, x, y in l:\n i, j = a * x - y, (x, y)\n r += c.get(i, 0) - d.get(... | {"inputs": ["4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1", "3 1 0\n-1 1 0\n0 0 -1\n1 -1 -2", "3 1 0\n0 0 0\n1 0 0\n2 0 0", "10 7 -626288749\n795312099 49439844 266151109\n-842143911 23740808 624973405\n-513221420 -44452680 -391096559\n-350963348 -5068756 -160670209\n690883790 11897718 3356227\n-509035268 -45646185 -210137445... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
819e473a539eec5cf984f904af5fbdfa | Bicycle Race | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and ... | [
"n=int(input())\r\nx1,y1=map(int,input().split())\r\nx2,y2=x1,y1\r\ndir1,dir2=\"\",\"\"\r\ncount=0\r\nfor i in range(n-1):\r\n x1,y1=x2,y2\r\n dir1=dir2\r\n x2,y2=map(int,input().split())\r\n if x2>x1:\r\n dir2=\"R\"\r\n elif x2<x1:\r\n dir2=\"L\"\r\n elif y1>y2:\r\n dir2=\"D\... | {"inputs": ["6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000", "4\n6 8\n6 9\n7 9\n7 8\n6 8", "8\n-10000 -10000\n-10000 5000\n0 5000\n0 10000\n10000 10000\n10000 0\n... | UNKNOWN | PYTHON3 | CODEFORCES | 88 | |
81cbf25d21c00e543382dbf2b0b24f1e | Group Projects | There are *n* students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the *i*-th student *a**i* minutes to finish his/her independent piece.
If students work at differen... | [
"# Problem: F. Group Projects\r\n# Contest: Codeforces - 8VC Venture Cup 2016 - Elimination Round\r\n# URL: https://codeforces.com/contest/626/problem/F\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n\r\nimport sys\r\nimport random\r\nfrom types import GeneratorType\r\nimport bisect\r\nimport io, os\r\nfrom ... | {"inputs": ["3 2\n2 4 5", "4 3\n7 8 9 10", "4 0\n5 10 20 21", "20 1000\n50 50 100 100 150 150 200 200 250 250 300 300 350 350 400 400 450 450 500 500", "5 222\n58 369 477 58 90", "9 222\n304 142 38 334 73 122 252 381 438", "9 247\n359 350 140 26 293 488 57 481 71", "5 341\n412 32 189 303 172", "200 0\n1 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
81d086a4bed9b7676ed89bd1eeb0eb3c | Row | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | [
"val=input()\r\n\r\ns=input()\r\ns='0'+s+'0'\r\n\r\nif '11' in s or '000' in s:\r\n print('NO')\r\n\r\n\r\nelse:\r\n print('YES')",
"n=int(input())\r\na=list(map(int,input()))\r\nif len(a)==1:\r\n print(\"Yes\" if a[0]==1 else \"No\"); exit()\r\nif a[0]==a[1]==0 or a[-1]==a[-2]==0: print(\"No\"); exit()\... | {"inputs": ["3\n101", "4\n1011", "5\n10001", "1\n0", "1\n1", "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010", "4\n0100", "42\n011000100101001001101011011010100010011010", "3\n001", "64\n1001001010010010100101010010010100100101001001001001010100101001", "3\n111... | UNKNOWN | PYTHON3 | CODEFORCES | 73 | |
81ef12c3e4dd0f375966669533bed4fb | Fox And Snake | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | [
"def Fox_and_Snake(r,c):\r\n next_ = 3\r\n next_2 = 1\r\n for i in range(r):\r\n for j in range(c):\r\n if i %2 == 0:\r\n print('#', end = '')\r\n else:\r\n if i == next_2 and j == (c-1):\r\n print('#', end = '')\r\n ... | {"inputs": ["3 3", "3 4", "5 3", "9 9", "3 5", "3 6", "7 3", "7 4", "49 50", "43 50", "43 27", "11 15", "11 3", "19 3", "23 50", "49 49", "33 43", "33 44", "45 45", "45 49", "45 3", "45 4", "5 4", "5 5", "5 6", "7 5", "7 6", "7 7"], "outputs": ["###\n..#\n###", "####\n...#\n####", "###\n..#\n###\n#..\n###", "#########\... | UNKNOWN | PYTHON3 | CODEFORCES | 555 | |
81f36a32b0401ec92d93c3f0c7e94903 | New Year and Days | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | [
"'''\r\n╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓█████▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\r\n###########################\r\n\r\n// •︿• \\\\\r\n/\\\\ //\\\r\n /\\\\ //\\\r\n /\\\\/... | {"inputs": ["4 of week", "30 of month", "17 of month", "31 of month", "6 of week", "1 of week", "2 of week", "3 of week", "5 of week", "7 of week", "1 of month", "2 of month", "3 of month", "4 of month", "5 of month", "6 of month", "7 of month", "8 of month", "9 of month", "10 of month", "11 of month", "12 of month", "... | UNKNOWN | PYTHON3 | CODEFORCES | 179 | |
81ffdfad6d7493a8b3a4d2449992fef7 | Gravity Flip | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | [
"n = int(input())\nm = input().split()\nx = ''\nfor i in range(n):\n\tm[i] = int(m[i])\nfor i in sorted(m):\n\tx += str(i)+' '\nprint(x)",
"n=int(input())\na=input().split()\nfor i in range (n) :\n a[i]=int(a[i])\n\n\na.sort();\n\nfor i in range (n) :\n print(a[i],end=' ')\n\n\t\t\t\t \t\t\t \t \t\t \t \... | {"inputs": ["4\n3 2 1 2", "3\n2 3 8", "5\n2 1 2 1 2", "1\n1", "2\n4 3", "6\n100 40 60 20 1 80", "10\n10 8 6 7 5 3 4 2 9 1", "10\n1 2 3 4 5 6 7 8 9 10", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76... | UNKNOWN | PYTHON3 | CODEFORCES | 540 | |
820b4ef0d5db2fef6bd88e9befb86b13 | Suffix Structures | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know th... | [
"def main():\n\ts = input()\n\tt = input()\n\n\tans_list = ['automaton', 'array', 'both', 'need tree']\n\n\tans = ''\n\tif s == t:\n\t\tans = ans_list[0]\n\telif sorted(s) == sorted(t):\n\t\tans = ans_list[1]\n\telif len(s) < len(t):\n\t\tans = ans_list[3]\n\n\tif ans != '':\n\t\tprint(ans)\n\t\treturn\n\n\tls = [0... | {"inputs": ["automaton\ntomat", "array\narary", "both\nhot", "need\ntree", "abacaba\naaaa", "z\nzz", "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet", "y\nu", "nbji... | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
8214a4b1281a44c4db1dc7d3160030f4 | Bits | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the... | [
"def main():\n cases = int(input())\n for i in range(cases):\n left, right = list(map(int, str(input()).split(\" \")))\n res = left\n\n for j in range(65):\n if ((1 << j) & left) == 0:\n if (res | (1 << j)) > right:\n break\n res... | {"inputs": ["3\n1 2\n2 4\n1 10", "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 79 | |
82158427dab9826528da173c784a2c45 | Greg and Graph | Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:
- The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from t... | [
"from array import array\r\nimport sys\r\n\r\ndef input():\r\n return sys.stdin.readline()[:-1]\r\n \r\nINF = 10**10\r\n \r\nN = int(input())\r\nA = [array('i', list(map(int, input().split()))) for _ in range(N)]\r\nX = list(map(lambda x: int(x)-1, input().split()))\r\n \r\nresult = []\r\nfor k in reversed(range... | {"inputs": ["1\n0\n1", "2\n0 5\n4 0\n1 2", "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3", "4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 97007 0\n2 3 1 4", "5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 55784\n70744 17563 79061 0 73981\n70529 35681 9107... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
823926c4d8ea61495c95a7a6f7accf46 | Hack it! | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | [
"a=int(input())\r\nx=a-((10**20)*45*21+1)%a\r\nprint(1+x,10**21+x)",
"a=int(input())\r\nb=int(81e18)\r\nb%=a;b=a-b\r\nprint(b,int(1e18)-1+b);",
"a = int(input())\r\nx = (45 * 18 * 10**17) % a\r\nprint(a - x, a - x + 10**18 - 1)\r\n",
"# LUOGU_RID: 97013648\na=int(input())\nl=a-int(1e18)*81%a\nr=l+int(1e18)-1\... | {"inputs": ["46", "126444381000032", "69645082595", "70602205995", "33898130785", "58929554039", "81696185182", "1", "2", "3", "4", "5", "6", "7", "8", "10", "11", "12", "43", "36", "65", "43", "23", "100", "10000", "1000000", "100000000", "10000000000", "1000000000000", "100000000000000", "10000000000000000", "1000000... | UNKNOWN | PYTHON3 | CODEFORCES | 70 | |
823e9c56b117ced7c4c45cebec880ab8 | Party | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | [
"n=int(input());\nmaxx=-1;\na=[-1];\nfor i in range(n):\n a.append(int(input()));\nfor i in range(1,n+1):\n j=i;c=1;\n while(a[j]!=-1):c+=1;j=a[j];\n maxx=max(c,maxx);\nprint(maxx);\n\t\t\t \t \t\t \t\t \t \t\t\t\t \t \t \t",
"#bfs solution\r\n\r\nfrom collections import defaultdict,deque\r\n\r\... | {"inputs": ["5\n-1\n1\n2\n1\n-1", "4\n-1\n1\n2\n3", "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "6\n-1\n-1\n2\n3\n1\n1", "3\n-1\n1\n1", "1\n-1", "2\n2\n-1", "2\n-1\n-1", "3\n2\n-1\n1", "3\n-1\n-1\n-1", "5\n4\n5\n1\n-1\n4", "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "12\n... | UNKNOWN | PYTHON3 | CODEFORCES | 283 | |
8247c1d90bd78e0e2751b3f923feafa5 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2*k* (*k* is an integer, *k*<=≥<=0) units. A magical box *v* can be pu... | [
"n= int(input())\r\nqq =0\r\nfor i in range(n):\r\n h,m = list(map(int, input().split()))\r\n k= 1\r\n r= 4\r\n while m> r:\r\n k+= 1\r\n r *=4\r\n qq = max(qq, h+k)\r\nprint(qq)",
"n = int(input())\r\nt = [tuple(map(int, input().split())) for i in range(n)]\r\n\r\nm = max(t)\r\nd = 2... | {"inputs": ["2\n0 3\n1 5", "1\n0 4", "2\n1 10\n2 2", "1\n0 1", "1\n1000000000 1000000000", "1\n0 16", "1\n0 17", "2\n0 16\n1 4", "3\n0 20\n1 18\n2 4", "3\n0 64\n1 16\n2 4", "5\n1 1000000\n100 100\n101 9\n102 4\n103 8", "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18", "15\n0 268435456\n1 67108864\n2 167... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
826351390a4115b50553d7685070fc0c | Toys | Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still ... | [
"def combinacoes(x):\n # Se for apenas 1 elemento retorna 1 arranjo\n if x == 1:\n return [[0]]\n else:\n # Adiciona os elementos a lista auxiliar\n aux = combinacoes(x - 1)\n pilha = []\n par = 0\n # Percorre a lista juntando os elementos nas possibilidades possíveis\n for... | {"inputs": ["3", "1", "2", "4", "5", "6", "7", "8", "9", "10"], "outputs": ["5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}", "1\n{1}", "2\n{1,2}\n{1},{2}", "15\n{1,2,3,4}\n{1,2,3},{4}\n{1,2},{3,4}\n{1,2},{3},{4}\n{1,2,4},{3}\n{1,4},{2,3}\n{1},{2,3},{4}\n{1},{2,3,4}\n{1},{2,4},{3}\n{1},{2},{3,4}\n{1},{2},{3},... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
829eac8587d8cba950594bfaa3bdf50e | Mittens | A Christmas party in city S. had *n* children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with integers from 1 to *m*, and the children are numbered from 1 to *n*. Then th... | [
"n, m = map(int, input().split())\r\na, memr, meml = [int(x) - 1 for x in input().split()], [0] * m, [0] * m\r\n\r\nfor i in a:\r\n memr[i] += 1\r\n meml[i] += 1\r\n\r\nout, ans, ran = [], 0, sorted(range(m), key=meml.__getitem__)[::-1]\r\n\r\nfor i in range(m):\r\n ix1 = ran[i]\r\n for j in range(meml[... | {"inputs": ["6 3\n1 3 2 2 1 1", "4 2\n1 2 1 1", "1 1\n1", "4 1\n1 1 1 1", "2 2\n2 2", "2 2\n1 2", "4 4\n4 3 2 1", "4 2\n1 2 1 2", "5 3\n1 1 2 1 1", "6 3\n1 1 2 2 3 3", "10 3\n3 1 2 2 2 1 2 2 2 1", "10 3\n3 1 3 1 1 2 2 2 1 3", "10 3\n1 2 1 2 2 1 2 3 2 1", "10 3\n3 2 3 1 2 2 2 1 1 3", "10 3\n3 3 1 3 1 2 2 1 3 2", "100 10... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
82a0355eb15f93fc5a3bc9c298539d50 | Shaass and Bookshelf | Shaass has *n* books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the *i*-th book is *t**i* and its pages' width is equal to *w**i*. The thickness of each book is either 1 or 2. All books have the same page heights.
Shaass puts the bo... | [
"from operator import itemgetter\n\n\nclass CodeforcesTask294BSolution:\n def __init__(self):\n self.result = ''\n self.books_count = 0\n self.books_dims = []\n\n def read_input(self):\n self.books_count = int(input())\n for x in range(self.books_count):\n self.bo... | {"inputs": ["5\n1 12\n1 3\n2 15\n2 5\n2 1", "3\n1 10\n2 1\n2 4", "10\n2 10\n2 4\n2 8\n2 3\n2 5\n2 6\n1 2\n1 10\n1 10\n2 5", "1\n2 7", "50\n1 24\n1 16\n1 33\n2 34\n1 26\n2 35\n1 39\n2 44\n2 29\n2 28\n1 44\n2 48\n2 50\n2 41\n2 9\n1 22\n2 11\n2 27\n1 12\n1 50\n2 49\n1 17\n2 43\n2 6\n1 39\n2 28\n1 47\n1 45\n2 32\n1 43\n2 4... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
82a7f8952265e9e4692372f6045274b1 | Planning | Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. Thi... | [
"from heapq import heappush, heappop, heapify\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nq = [(-a[i], i) for i in range(k)]\r\nheapify(q)\r\nres, s = [0] * n, 0\r\nfor i in range(k, n):\r\n heappush(q, (-a[i], i))\r\n x, j = heappop(q)\r\n s -= x * (i-j)\r\n res[j] = i... | {"inputs": ["5 2\n4 2 1 10 2", "3 2\n3 1 2", "5 5\n5 5 9 100 3", "1 1\n1", "1 1\n10000000", "6 4\n85666 52319 21890 51912 90704 10358", "10 5\n66220 81797 38439 54881 86879 94346 8802 59094 57095 41949", "8 1\n3669 11274 87693 33658 58862 78334 42958 30572", "2 2\n16927 73456", "6 6\n21673 27126 94712 82700 59725 46310... | UNKNOWN | PYTHON3 | CODEFORCES | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.