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 |
|---|---|---|---|---|---|---|---|---|---|
89c2bcffb56fcdb0dba9ea994e161d20 | Color Stripe | A colored stripe is represented by a horizontal row of *n* square cells, each cell is pained one of *k* colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to *k* to repaint the cells.
The first input line contains two integer... | [
"n, k = map(int, input().split())\n\ns = list(input())\n\nif k > 2:\n c = set(ord(\"A\") + i for i in range(26))\n r = 0\n for i in range(1,len(s)):\n if s[i-1] == s[i]:\n r += 1\n if i + 1 < n:\n s[i] = \"A\" if \"A\" not in {s[i-1], s[i+1]} else ('B' if \"B\" n... | {"inputs": ["6 3\nABBACC", "3 2\nBBB", "1 2\nA", "1 26\nZ", "2 2\nAA", "2 2\nBA", "6 2\nAAABBB", "8 3\nAABBABBB", "10 26\nAAAAAAAAAA", "12 3\nAAABBBAAABBB", "3 2\nAAB", "3 3\nBBA", "3 3\nCCC", "8 3\nAABBCCBB", "200 2\nBABAABBABBABBABABBBABAAABABBABABBBAABBBBABBAABBABABAAAAABAABBBAAAAAAABBBABAAAABABBBAABABAABAABBBAABBAB... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
89f33e47241992f5c2c6cbeeaf3d4ead | Captain Marmot | Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has *n* regiments, each consisting of 4 moles.
Initially, each mole *i* (1<=≤<=*i*<=≤<=4*n*) is placed at some position (*x**i*,<=*y**i*) in the Cartesian plane. Captain Marmot wants to move some moles to m... | [
"n = int(input())\r\ndef all_angles(x, y, a, b):\r\n ret = [\r\n (a - x) + (b - y) * 1j\r\n ]\r\n for i in range(3):ret.append(ret[-1] * 1j)\r\n ret = [i + a + b * 1j for i in ret]\r\n ret = ret\r\n return ret[2:] + ret[:2]\r\ndef is_square(a, b, c, d):\r\n lines = [a - b, a - c, a - d, ... | {"inputs": ["4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0", "3\n-2248 6528 -2144 6181\n-2245 6663 -2100 7054\n-4378 7068 -4061 7516\n-4274 6026 -3918 5721\n4942 -6793 5014 -6807\n3463 -5170 3112 -5181\n287... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
8a0c32c216a57e2b1ebcc493f38f1de4 | Movie Critics | A film festival is coming up in the city N. The festival will last for exactly *n* days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to *k*.
On the *i*-th day the festival will show a movie of genre *a**i*. We know that a movie of each of *k* genres occurs in the fes... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom itertools import groupby\r\n\r\nn, k = map(int, input().split())\r\nd = [list(j)[0] for i, j in groupby(map(int, input().split()))]\r\nq = [0]*(k+1)\r\nfor i in range(len(d)):\r\n if i not in [0, len(d)-1] and d[i-1] == d[i+1]:\r\n q[d[i]] += 1\r\n q[d[... | {"inputs": ["10 3\n1 1 2 3 2 3 3 1 1 3", "7 3\n3 1 3 2 3 1 2", "2 2\n1 2", "10 2\n1 2 2 1 1 2 1 1 2 2", "10 10\n5 7 8 2 4 10 1 3 9 6", "100 10\n6 2 8 1 7 1 2 9 2 6 10 4 2 8 7 5 2 9 5 2 3 2 8 3 7 2 4 3 1 8 8 5 7 10 2 1 8 4 1 4 9 4 2 1 9 3 7 2 4 8 4 3 10 3 9 5 7 7 1 2 10 7 7 8 9 7 1 7 4 8 9 4 1 10 2 4 2 10 9 6 10 5 1 4 2... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
8a19c08339325adedb08655029389065 | Robot Bicorn Attack | Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string *s*. Vasya decided ... | [
"def find_max_score(s):\r\n n = len(s)\r\n max_score = -1\r\n for i in range(1, n):\r\n for j in range(i + 1, n):\r\n num1 = int(s[:i])\r\n num2 = int(s[i:j])\r\n num3 = int(s[j:])\r\n if (s[0] != '0' or len(s[:i]) == 1) and \\\r\n (s[i] != '... | {"inputs": ["1234", "9000", "0009", "100000010000001000000", "1000000011", "9991", "1000001999", "100000010000011000000", "100000010000001000001", "102", "100", "000", "001", "090", "999999999999999999999999999999", "12345678901234567", "12635000000127683", "428595000000042345353", "48726340000000", "93246310000000", "... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
8a2e86e2f136815a2d31168586eb8de7 | Roma and Lucky Numbers | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | [
"[n, k] = [int(x) for x in input().split()]\r\nL = [x for x in input().split()]\r\nc = 0\r\nfor i in L:\r\n if i.count('4') + i.count('7') <= k: c += 1\r\nprint(c)\r\n",
"n,k=map(int,input().split())\r\nl=list(map(int,input().split()))[:n]\r\nl1=[]\r\nfor i in l:\r\n i=str(i)\r\n p=i.count('4')\r\n q=... | {"inputs": ["3 4\n1 2 4", "3 2\n447 44 77", "2 2\n507978501 180480073", "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089", "6 100\n170427799 37215529 675016434 168544291 683447134 950090227", "4 2\n194041605 706221269 69909135 257655784", "4 2\n9581849 67346651 530497 272158241", ... | UNKNOWN | PYTHON3 | CODEFORCES | 500 | |
8a318d25c4228c01367164cd22486e42 | Minimum spanning tree for each edge | Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains *n* vertices and *m* edges.
For each edge (*u*,<=*v*) find the minimal possible weight of the spanning tree that contains the edge (*u*,<=*v*).
The weight of the spanning tree is the sum of weights of all edges included... | [
"from sys import stdin, stdout\r\ndef main():\r\n n, m = map(int, stdin.readline().split())\r\n d = []\r\n ev = [set() for _ in range(n + 1)]\r\n ans = [0] * m\r\n for i in range(m):\r\n u, v, w = map(int, stdin.readline().split()) \r\n d.append((w, u, v))\r\n ev[u].add(i)\r\n ... | {"inputs": ["5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4", "2 1\n1 2 42", "3 3\n1 2 10\n2 3 20\n3 1 40", "4 6\n1 2 999999001\n1 3 999999003\n1 4 999999009\n2 3 999999027\n2 4 999999243\n3 4 999999729", "8 10\n2 5 4\n7 5 2\n7 3 28\n4 5 14\n3 2 15\n1 2 3\n6 2 5\n2 8 17\n4 6 2\n1 4 10", "8 10\n8 7 11\n3 5 23\n2 1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
8a39a0fc528e653f23f943f263f57591 | Mister B and Boring Game | Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.
All characters in this game are lowercase English letters. There are two players: Mister B and his competitor.
Initially the players have a string *s* consisting of t... | [
"\na, b, ll, rr = map(int, input().split())\np = 'abcdefghijklmnopqrstuvwxyz'\nss = p[:a]\ndef f(n):\n global a, b, ll, rr, p, ss\n s = ss\n l = ll\n r = rr\n while True:\n s += s[-n]*b\n st = set()\n for i in s[-a:]:\n st.add(i)\n k = 0\n for i in range(a):\n while p[k] in st: k += 1\... | {"inputs": ["1 1 1 8", "4 2 2 6", "3 7 4 6", "4 5 1 1", "12 12 1 1000", "12 1 1000 1000", "3 4 701 703", "12 12 13 1000000000", "3 4 999999999 1000000000", "5 6 1000000000 1000000000", "1 1 1 1", "12 1 100000011 100000024", "10 12 220000011 220000032", "1 1 1 1000000000", "1 1 999999999 1000000000", "1 1 1000000000 100... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8a3b83bb1a842a33deeaa0d6092acc8f | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | [
"__author__ = 'DK Wang'\r\nfrom fractions import gcd\r\n\r\n#Matrix = [[0 for x in range(5)] for x in range(5)]\r\n\r\nhome = input()\r\naway = input()\r\nn = int(input())\r\n\r\ntime = [[0 for x in range(105)] for x in range(2)]\r\n\r\nfor x in range(n):\r\n t, ha, num, type = [x for x in input().split()]\r\n ... | {"inputs": ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r", "MASFF\nSAFBDSRG\n5\n1 h 1 y\n15 h 1 r\n27 a 1 y\n58 a 1 y\n69 h 10 y", "ARMENIA\nBULGARIA\n12\n33 h 17 y\n42 h 21 y\n56 a 17 y\n58 a 6 y\n61 a 7 y... | UNKNOWN | PYTHON3 | CODEFORCES | 48 | |
8a91e345120c4e99d41dd166b1ac3025 | Gerald and Giant Chess | Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game ... | [
"import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,... | {"inputs": ["3 4 2\n2 2\n2 3", "100 100 3\n15 16\n16 15\n99 88", "1000 1000 4\n50 50\n51 50\n50 51\n51 51", "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000", "2 2 2\n2 1\n1 2", "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
8a957f78e0d55fcc24a4b2ca6c9e4fec | Increase Sequence | Peter has a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Peter wants all numbers in the sequence to equal *h*. He can perform the operation of "adding one on the segment [*l*,<=*r*]": add one to all elements of the sequence with indices from *l* to *r* (inclusive). At that, Peter never chooses any element as the be... | [
"f = lambda: map(int, input().split())\r\nn, h = f()\r\ns, i = 1, 0\r\nfor j in f():\r\n j = h - j\r\n if j < 0 or abs(j - i) > 1: exit(print(0))\r\n if j <= i: s = s * (j + 1) % 1000000007\r\n i = j\r\nprint(0 if i > 1 else s)"
] | {"inputs": ["3 2\n1 1 1", "5 1\n1 1 1 1 1", "4 3\n3 2 1 1", "1 2000\n2000", "3 2\n2 1 1", "3 4\n4 3 2", "10 6\n5 4 4 4 5 4 4 4 4 5", "10 6\n5 4 4 4 5 4 4 4 4 5", "7 4\n3 3 4 4 4 3 3", "3 6\n5 6 5", "3 2\n1 0 1", "6 1\n0 1 0 0 0 1", "6 3\n2 1 2 2 1 2", "99 1999\n1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 198... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8b05508e415ac732ef63660436500b6f | Cannon | Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the *Ox* axis is ... | [
"import sys\nfrom math import tan, sin, cos\n\nreadline = sys.stdin.readline\n\nballs = []\nwalls = []\nV = 0\n\ndef read_input():\n global V\n n, v = list(map(int, readline().split()))\n V = v\n for i in range(n):\n balls.append([float(readline().strip()), i])\n balls.sort()\n n = int(read... | {"inputs": ["2 10\n0.7853\n0.3\n3\n5.0 5.0\n4.0 2.4\n6.0 1.9", "2 10\n0.7853\n0.3\n2\n4.0 2.4\n6.0 1.9", "3 186\n0.4084\n0.4559\n0.1203\n3\n978.8435 234.6507\n343.6961 128.6128\n611.2897 458.9593", "4 851\n0.3178\n0.5635\n0.1335\n0.5107\n4\n685.3785 249.6264\n681.8946 242.4571\n917.2937 600.3285\n150.5685 135.5137", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8b08ea902b7acfe6c832a6ab2e5cbf65 | New York Hotel | Think of New York as a rectangular grid consisting of *N* vertical avenues numerated from 1 to *N* and *M* horizontal streets numerated 1 to *M*. *C* friends are staying at *C* hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of *H* restaurants also located ... | [
"N, M = input().split()\r\na, b, c, d = [int(1e10) for _ in range(4)]\r\nfor i in range(int(input())):\r\n x, y = list(map(int, input().split()))\r\n a, b, c, d = min(a, x + y), min(b, x - y), min(c, - x + y), min(d, - x - y)\r\nres, pos = int(1e10), 0\r\nfor i in range(int(input())):\r\n x, y = list(map(i... | {"inputs": ["10 10\n2\n1 1\n3 3\n2\n1 10\n4 4", "100 100\n10\n53 20\n97 6\n12 74\n48 92\n97 13\n47 96\n75 32\n69 21\n95 75\n1 54\n10\n36 97\n41 1\n1 87\n39 23\n27 44\n73 97\n1 1\n6 26\n48 3\n5 69", "100 100\n10\n86 72\n25 73\n29 84\n34 33\n29 20\n84 83\n41 80\n22 22\n16 89\n77 49\n1\n4 23", "100 100\n1\n66 77\n10\n70 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8b27e972e3fa26ad5abe3942fc090f84 | Permute Digits | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line ... | [
"a, b = sorted(input()), int(input())\r\nfor i in range(len(a)):\r\n\tfor j in range(i+1, len(a)):\r\n\t\tc = int(str.join('', a))\r\n\t\ta[i], a[j] = a[j], a[i]\r\n\t\td = int(str.join('', a))\r\n\t\tif c <= d <= b:\r\n\t\t continue\r\n\t\telse:\r\n\t\t a[i], a[j] = a[j], a[i]\r\nprint(str.join('', a))",
"... | {"inputs": ["123\n222", "3921\n10000", "4940\n5000", "23923472834\n23589234723", "102391019\n491010301", "123456789123456789\n276193619183618162", "1000000000000000000\n1000000000000000000", "1\n1000000000000000000", "999999999999999999\n1000000000000000000", "2475345634895\n3455834583479", "15778899\n98715689", "4555\... | UNKNOWN | PYTHON3 | CODEFORCES | 53 | |
8b3fa8eccfdabf8716ba8e9019da55da | none | You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=><=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing sequence of the given array.
The first line contains two space-separated integers: *n*, *T* (... | [
"def solve():\r\n n,T = map(int,input().split())\r\n array = list(map(int,input().split()))\r\n ElementsTillN = {}\r\n for x in range(n):\r\n ElementsTillN[x]={array[x]:1}\r\n for x in range(1,n):\r\n for y in range(x):\r\n if array[y]<=array[x]:\r\n for value,... | {"inputs": ["4 3\n3 1 4 2", "1 1000\n42", "31 3767\n16 192 152 78 224 202 186 52 118 19 13 38 199 196 35 295 100 64 205 37 166 124 169 214 66 243 134 192 253 270 92", "15 12226\n18 125 213 221 124 147 154 182 134 184 51 49 267 88 251", "81 10683\n3 52 265 294 213 242 185 151 27 165 128 237 124 14 43 147 104 162 124 103... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
8b4044b6c20a561a758869590fbe0d05 | GukiZ and Binary Operations | We all know that GukiZ often plays with arrays.
Now he is thinking about this problem: how many arrays *a*, of length *n*, with non-negative elements strictly less then 2*l* meet the following condition: ? Here operation means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equivalent to &... | [
"n,k,l,m=map(int,input().split())\nfc={1:1,2:1}\ndef f(n):\n\tif n not in fc: k=n//2;fc[n]=(f(k+1)**2+f(k)**2 if n%2 else f(k)*(2*f(k+1)-f(k)))%m\n\treturn fc[n]\ns=k<2**l\nfor i in range(l): s*=pow(2,n,m)-f(n+2) if (k>>i)%2 else f(n+2)\nprint(s%m)\n"
] | {"inputs": ["2 1 2 10", "2 1 1 3", "3 3 2 10", "5135 42542 15 4354", "21 21 21 21", "2 0 0 5", "1564 153 12 1000000007", "101 102 13 104", "5 6 29 108", "1000000001 1000000002 37 1000000007", "45305640 6540640606 51 5406546", "68706870687 984089409849 59 156465748", "987408898498 1233432432 15 15", "111111111111 111111... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8b469bd08bc0cbf4598d9a22785da95f | none | Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed... | [
"import itertools\n\nclass Cube:\n def __init__(self, v):\n self.s = v\n def rotate_h(self):\n s = self.s\n self.s = s[0:1] + s[2:5] + s[1:2] + s[5:6]\n def rotate_v1(self):\n s = self.s\n self.s = s[1:2] + s[5:6] + s[2:3] + s[0:1] + s[4:5] + s[3:4]\n def rotate_v2(sel... | {"inputs": ["YYYYYY", "BOOOOB", "ROYGBV", "RRRRRR", "BOOOOO", "GOGGVG", "GRBYVO", "BYOVRR", "VOVRBV", "GVGBVO", "BOBGBB", "OOYYBY", "VVRVVV", "YBBVVY", "GYYGGG", "BRRBRB", "OOOOOO", "OVBRYG", "VOBYGO", "VRRYGR", "VOBVYB", "YYYYRB", "RYYYVV", "YYYYYG", "OBORBR", "RRRGRG", "VYYYVV", "YYYYYY", "YROVBG", "RYGOBG", "BGRGGV"... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
8b794f61bba5cf73f873c4461a6dc912 | Processing Queries | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | [
"n, b = [int(i) for i in input().split()]\r\nq = [0] * n\r\nbg = 0\r\nen = 0\r\ntime = 0\r\nres = [-1] * n\r\nfor it in range(n):\r\n ev = [int(i) for i in input().split()]\r\n ev.append(it)\r\n while bg < en and max(time, q[bg][0]) <= ev[0]:\r\n time = max(time, q[bg][0])\r\n res[q[bg][2]] =... | {"inputs": ["5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "4 1\n2 8\n4 8\n10 9\n15 2", "1 1\n1000000000 1000000000", "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000", "5 1\n2 1\n3 6\n4 5\n6 4\n7 2", "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2", "6 4\n2 4\n4 2\n5 2\n6... | UNKNOWN | PYTHON3 | CODEFORCES | 56 | |
8b980c9c96fff0ee36b71d033b996015 | Lucky Permutation | A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*).
A lucky permutation is such permutation *p*, that any integer *i* (1<=≤<=*i*<=≤<=*n*) meets this condition *p**p**i*<==<=*n*<=-<=*i*<=+<=1.
You have inte... | [
"n=int(input())\r\nif (n//2)&1:\r\n\tprint(-1)\r\nelse:\r\n\tans=[0]*(n+1)\r\n\tfor i in range(1,(n//2)+1,2):\r\n\t\tans[i]=i+1\r\n\t\tans[i+1]=n-i+1\r\n\t\tans[n-i+1]=n-i\r\n\t\tans[n-i]=i\r\n\tif n%2:\r\n\t\tans[(n//2)+1]=(n//2)+1\r\n\tprint(*ans[1:])\r\n",
"n = int(input())\r\neven = []\r\nodd = []\r\nfor i in... | {"inputs": ["1", "2", "4", "5", "3", "100000", "6", "7", "8", "9", "99997", "10000", "10001", "10002", "10003", "10004", "25", "29", "33", "9", "13", "17", "50001", "20001", "30001", "99996", "99999", "101", "505", "565"], "outputs": ["1 ", "-1", "2 4 1 3 ", "2 5 3 1 4 ", "-1", "2 100000 4 99998 6 99996 8 99994 10 9999... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
8baaa070ecac7d157bd2a81f95a18b77 | MUH and Important Things | It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are *n* tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in ord... | [
"while True:\r\n try:\r\n n = int(input())\r\n tasks = list(enumerate(map(int, input().split()), 1)) # [(id, difficulty)]\r\n tasks.sort(key = lambda x: x[1]) # sort by id\r\n i = 0\r\n while i < n - 1:\r\n if tasks[i][1] == tasks[i + 1][1]:\r\n break\r\n i += 1\r\n j = i + 1\r\n... | {"inputs": ["4\n1 3 3 1", "5\n2 4 1 4 8", "8\n1 5 4 12 7 2 10 11", "6\n5 1 2 5 2 4", "1\n1083", "10\n5 5 5 5 5 5 5 5 5 5", "6\n3 8 3 9 3 10", "19\n895 1302 724 952 340 952 939 1302 724 952 939 340 340 1844 770 976 435 1302 1302", "7\n766 766 1477 766 107 1774 990", "11\n1552 1010 1552 1248 1550 388 1541 1010 613 1821 3... | UNKNOWN | PYTHON3 | CODEFORCES | 50 | |
8bb5b84ac8b7a2f06ed0f1e18350f2ef | none | One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane *n* rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.
Help Timofey to color his rectangles in 4 differe... | [
"n = int(input())\r\nprint(\"YES\")\r\nfor i in range(n):\r\n x1, y1, x2, y2 = input().split()\r\n x1 = int(x1)\r\n y1 = int(y1)\r\n print((x1 % 2) * 2 + (y1 % 2) + 1)",
"p = int(input())\r\n\r\nprint(\"YES\")\r\n\r\nfor i in range(p):\r\n a, b, c, d = [abs(int(i)) for i in input().split()]\r\n ... | {"inputs": ["8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1", "1\n0 0 1 1", "4\n0 0 1 1\n1 0 2 1\n1 1 2 2\n0 1 1 2", "3\n0 0 1 3\n1 0 4 1\n1 1 2 2", "6\n0 1 1 4\n0 4 1 7\n1 0 2 3\n1 3 2 4\n1 4 2 5\n2 3 3 4", "25\n0 0 7 7\n0 18 7 29\n7 36 12 41\n7 18 12 29\n15 29 26 36\n7 7 12 18\n... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
8bbcbb9e2645ba1ed5dd33803c1dee7b | Text Volume | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<... | [
"a = set()\r\na.add(0)\r\n\r\nn = int(input())\r\ns = input().split()\r\n\r\nc = 0\r\nfor i in s:\r\n\tfor j in i:\r\n\t\tif j.isupper():\r\n\t\t\tc+=1\r\n\ta.add(c)\r\n\tc = 0\r\n\r\na = sorted(a)\r\n\r\nprint(a[-1])",
"n = int(input())\r\n\r\na = input().split()\r\n\r\nans = 0\r\n\r\ndef f(s):\r\n res = 0\r\... | {"inputs": ["7\nNonZERO", "24\nthis is zero answer text", "24\nHarbour Space University", "2\nWM", "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz", "199\no A r ... | UNKNOWN | PYTHON3 | CODEFORCES | 436 | |
8be1c3722f69c951ceff8bd6b888d662 | 80-th Level Archeology | Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of *n* words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hierogl... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, c = map(int, input().split())\r\nw1 = list(map(int, input().split()))[1:]\r\nng = [0] * (c + 1)\r\nok = 1\r\nfor _ in range(n - 1):\r\n w2 = list(map(int, input().split()))[1:]\r\n f = 0\r\n for i, j in zip(w1, w2... | {"inputs": ["4 3\n2 3 2\n1 1\n3 2 3 1\n4 2 3 1 2", "2 5\n2 4 2\n2 4 2", "4 4\n1 2\n1 3\n1 4\n1 2", "3 1\n2 1 1\n2 1 1\n3 1 1 1", "2 10\n14 9 6 7 1 6 9 3 1 9 4 6 8 8 1\n3 3 7 6", "5 10\n1 5\n7 5 1 10 5 3 7 10\n1 2\n1 3\n7 4 7 3 9 4 6 1", "50 5\n1 4\n1 4\n1 4\n1 4\n2 4 4\n2 4 5\n2 4 5\n3 4 1 1\n4 4 1 2 5\n7 4 3 2 1 4 4 5... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8be653bb7d31a6854b649c9565e080e5 | April Fools' Problem (easy) | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output... | [
"a,b=map(int,input().split())\r\nt=[int(i) for i in input().split()]\r\ncount=0\r\nt.sort()\r\nfor i in range(b):count+=t[i]\r\nprint(count)",
"n, k = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nc = sorted(b)\r\nprint(sum(c[:k]))\r\n",
"Q=lambda:map(int,input().split())\r\n_,k=Q()\r\npri... | {"inputs": ["8 5\n1 1 1 1 1 1 1 1", "10 3\n16 8 2 4 512 256 32 128 64 1", "5 1\n20 10 50 30 46", "6 6\n6 6 6 6 6 6", "1 1\n100", "1 1\n1", "10 5\n147 1917 5539 7159 5763 416 711 1412 6733 4402", "100 60\n1443 3849 6174 8249 696 8715 3461 9159 4468 2496 3044 2301 2437 7559 7235 7956 8959 2036 4399 9595 8664 9743 7688 37... | UNKNOWN | PYTHON3 | CODEFORCES | 44 | |
8bf008186e7ef1b9076e19b8f3ab5c1a | Scrambled | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ... | [
"from fractions import gcd\nfrom functools import reduce\nfrom operator import mul\n\nn = int(input())\nm = [int(x) for x in input().split()]\nr = [int(x) for x in input().split()]\n\nlcm = m[0]\nif len(m) > 1:\n lcm = reduce(mul, m, 1) // reduce(gcd, m, 0)\n\nres = 0\nfor d in range(min(lcm, 100000)):\n for ... | {"inputs": ["1\n2\n0", "2\n2 3\n1 0", "3\n2 4 4\n0 1 3", "1\n16\n15", "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "16\n5 6 9 13 13 15 9 10 2 6 10 11 12 7 4 8\n4 3 3 5 8 3 6 5 1 4 2 6 7 4 0 1", "8\n15 3 7 11 14 10 16 2\n0 2 1 4 0 0 13 1", "1\n7\n5", "9\n6 12 3 10 15 14 6 9 3\n5 2... | UNKNOWN | PYTHON3 | CODEFORCES | 25 | |
8bfbb4d2c2d479b59b4a5cb61941820d | Hide-and-Seek | Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (*x**v*,<=*y**v*) and (*x**p*,<=*y**p*) respectively. The wall is a segment joinin... | [
"xv,yv=list(map(int,input().split()))\r\nxp,yp=list(map(int,input().split()))\r\nxw1,yw1,xw2,yw2=list(map(int,input().split()))\r\nxm1,ym1,xm2,ym2=list(map(int,input().split()))\r\ndef a(x1,y1,x2,y2,x3,y3,x4,y4):\r\n if x1==x2:\r\n if x3==x4:\r\n return False\r\n else:\r\n k2=... | {"inputs": ["-1 3\n1 3\n0 2 0 4\n0 0 0 1", "0 0\n1 1\n0 1 1 0\n-100 -100 -101 -101", "0 0\n1 1\n0 1 1 0\n-1 1 1 3", "0 0\n10 0\n100 100 101 101\n1 0 3 0", "0 0\n1 1\n100 100 101 101\n-100 -100 -101 -101", "-1 1\n1 1\n0 3 0 4\n0 0 0 2", "0 0\n2 0\n1 1 1 -1\n0 2 1 2", "0 0\n2 0\n1 1 1 -1\n-10 2 -12 2", "0 0\n2 0\n0 2 2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8c0044cad84ef54874eff46f8f5fe656 | Sonya and Matrix | Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ... | [
"import collections\ndd = lambda: collections.defaultdict(int)\n\nt = int(input())\ncnt = [0] * t\nfor i in map(int, input().split()):\n cnt[i] += 1\n\nds = [c - 2 * b + a for a, b, c in zip([0, 0] + cnt, [0] + cnt + [0], cnt + [0, 0])]\nds[0] -= 1; ds[1] -= 2; ds[2] -= 1;\n\ndef bop(D):\n while D:\n i... | {"inputs": ["20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4", "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1", "6\n2 1 0 2 1 2", "1\n0", "7\n0 1 2 3 4 2 6", "6\n0 0 0 0 0 0", "4\n0 0 0 0"], "outputs": ["4 5\n2 2", "3 6\n2 3", "-1", "1 1\n1 1", "-1", "-1", "-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
8c3e4d39eb3fa9adae0ac0d73286f72e | none | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o... | [
"# Codeforces Submission\n# User : sudoSieg\n# Time : 14:50:08\n# Date : 21/10/2020\n\nimport io\nimport os\n#input = lambda: io.BytesIO(os.read(0, os.fstat(0).st_size)).readline().strip()\nvalid = True\ns = input()\nze = []\noe = []\n\nfor i, j in enumerate(s):\n if j == '0':\n if len(oe) != 0:\... | {"inputs": ["0010100", "111", "0", "1", "0101010101", "010100001", "000111000", "0101001000", "0000001000", "0101", "000101110", "010101010", "0101001010", "0100101100", "0110100000", "0000000000", "1111111111", "0010101100", "1010000", "0001110", "00000000000110011000111101010001010000100101110001001101100000110100111... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
8c4a32fe0eb2f98ede0b2c62a4d73b97 | Harmony Analysis | The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec... | [
"p = [[0]]\r\nfor i in range(int(input())):\r\n p = [t + t for t in p] + [[1 - q for q in t] + t for t in p]\r\nfor t in p: print(''.join('+*'[q] for q in t))",
"from functools import reduce\nfrom operator import *\nfrom math import *\nfrom sys import *\nfrom string import *\nfrom collections import *\nsetrecu... | {"inputs": ["2", "1", "3", "0", "4", "5", "6", "7", "8", "9"], "outputs": ["++++\n+*+*\n++**\n+**+", "++\n+*", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*", "+", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n++****++++***... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
8c79b8c1ac558a266dbe4c8f55ed51e7 | Vasya and Beautiful Arrays | Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately... | [
"n, k = map(int, input().split())\nt = set(map(int, input().split()))\ny = x = min(t)\nt = list(t)\nwhile True:\n for i in t:\n if i % x > k: x = i // (i // x + 1)\n if y == x: break\n y = x\nprint(y)\n",
"n,k=map(int,input().split())\r\nt=set(map(int,input().split()))\r\ny=x=min(t)\r\nt=list(t)\r... | {"inputs": ["6 1\n3 6 10 12 13 16", "5 3\n8 21 52 15 77", "13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58", "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68", "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64", "7 1\n12 84 21 60 33 21 45", "1 1\n1", "10 10\n40141 53368 66538 6... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
8c94a95b56f6f7c5dcc0c59a65f20967 | Anton and Chess | Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi... | [
"s, n = {}, int(input())\r\nx, y = map(int, input().split())\r\nfor i in range(n):\r\n t, a, b = input().split()\r\n u, v = int(a) - x, int(b) - y\r\n a = (abs(u) == abs(v))\r\n b = (u == 0 or v == 0)\r\n d = abs(u) + abs(v)\r\n p = (u < 0, v < 0, u > 0, v > 0)\r\n q = (d, t in 'Q' + 'RB'[a])\r... | {"inputs": ["2\n4 2\nR 1 1\nB 1 5", "2\n4 2\nR 3 3\nB 1 5", "5\n-1 1\nR -10 10\nQ -9 9\nQ -2 -8\nB -6 10\nB -10 1", "20\n-321 454\nQ 967 -89\nR -811 454\nQ -404 454\nR -734 454\nQ -804 454\nQ -316 77\nQ -802 454\nB -499 454\nQ 401 -663\nQ -601 454\nQ -974 454\nB 710 298\nB -917 454\nB -555 -542\nQ -337 950\nR 501 40\nR... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8c973212d593a4182fe97b22e3f856eb | Olesya and Rodion | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | [
"n, t=(map(int,input().split()))\r\nif n==1 and t==10:\r\n print(-1)\r\nelif n>=2 and t ==10:\r\n for i in range((n-1)):\r\n print('1',end=\"\")\r\n print(0)\r\nelse:\r\n for i in range((n)):\r\n print(t,end=\"\")\r\n ",
"n,t = map(int,input().split())\r\ns = '1'\r\ni = 1\r\nwhile... | {"inputs": ["3 2", "2 2", "4 3", "5 3", "10 7", "2 9", "18 8", "1 5", "1 10", "100 5", "10 2", "18 10", "1 9", "7 6", "4 4", "14 7", "3 8", "1 3", "2 8", "3 8", "4 3", "5 9", "4 8", "3 4", "9 4", "8 10", "1 6", "20 3", "15 10", "31 4", "18 9", "72 4", "76 8", "12 5", "54 5", "96 10", "15 9", "100 2", "99 3", "98 4", "9... | UNKNOWN | PYTHON3 | CODEFORCES | 308 | |
8ca09bef1240e1e23975c668191930e4 | Headquarters | Sensation, sensation in the two-dimensional kingdom! The police have caught a highly dangerous outlaw, member of the notorious "Pihters" gang. The law department states that the outlaw was driving from the gang's headquarters in his car when he crashed into an ice cream stall. The stall, the car, and the headquarters e... | [
"n = int(input())\r\nr = 1; c = 1\r\nfor i in range(n):\r\n s = input()\r\n if (len(s) == 4):\r\n r += 1; c += 1\r\n elif(s == \"UL\" or s == \"DR\"):\r\n r += 1\r\n else:\r\n c += 1\r\nprint(r * c)",
"#!/usr/local/bin/python3\n\nn = int(input())\n\nw = 1\nh = 1\n\nfor _ in range(... | {"inputs": ["3\nUR\nUL\nULDR", "2\nDR\nDL", "4\nUL\nUR\nDR\nDL", "10\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL\nUL", "6\nUL\nDL\nDL\nUL\nUL\nDL", "1\nUL", "1\nUR", "1\nDR", "1\nDL", "1\nULDR", "2\nUL\nULDR", "4\nULDR\nUR\nULDR\nUR", "10\nUR\nDR\nUL\nDR\nUL\nULDR\nUR\nUL\nULDR\nUL", "4\nUL\nUR\nDR\nDL", "10\nUL\nUR\nUR\nDR\nD... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
8cae00fef4c1eedada77f2a75ddf67f4 | Inverse Function | Petya wrote a programme on C++ that calculated a very interesting function *f*(*n*). Petya ran the program with a certain value of *n* and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and ... | [
"import sys\r\ny = int(input())\r\nlines = sys.stdin.read()\r\n \r\nmod = 32768\r\np1 = lines.find('{') + 1\r\np2 = lines.find('}')\r\nlines = lines[p1:p2].strip().replace('\\n', '').split(';')\r\nmp = {}\r\ncmd = \"def f(n):\\n\"\r\nfor line in lines:\r\n line = line.strip()\r\n if line == \"\":\r\n c... | {"inputs": ["17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}", "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}", "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}", "32767\nint f(int n)\n{\nreturn n;\n}", "27926\nint f(int n)... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8cd687a88783833ff1c31127372696fe | George and Accommodation | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | [
"n = int(input())\r\naccomodation = []\r\navailable = 0\r\n\r\nfor i in range(n):\r\n inhabitants, capacity = list(map(int, input().split()))\r\n accomodation.append((inhabitants, capacity))\r\n\r\n if capacity - inhabitants >= 2:\r\n available += 1\r\n else:\r\n continue\r\n\r\nprint(avai... | {"inputs": ["3\n1 1\n2 2\n3 3", "3\n1 10\n0 10\n10 10", "2\n36 67\n61 69", "3\n21 71\n10 88\n43 62", "3\n1 2\n2 3\n3 4", "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100", "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9", "19\n66 67\n97 98\n89 91\n67 69\n67 68\... | UNKNOWN | PYTHON3 | CODEFORCES | 648 | |
8d058a1cf69c59bf09f0190d5dc2e875 | Football | One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into *n* teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the ... | [
"\ndef solve():\n\tn,k = map(int,input().split())\n\tparent = [set() for i in range(n+1)]\n\tans = []\n\tfor i in range(1,n+1):\n\t\tK = k\n\t\tfor j in range(1,n+1):\n\t\t\tif i!=j and j not in parent[i]:\n\t\t\t\tparent[j].add(i)\n\t\t\t\tans.append((i,j))\n\t\t\t\tK-=1\n\t\t\tif K==0:\n\t\t\t\tbreak\n\t\telse:\n... | {"inputs": ["3 1", "7 3", "4 1", "5 2", "5 2", "11 6", "11 5", "1 1", "2 1", "3 1", "1 2", "2 2", "3 2", "531 265", "775 388", "648 581", "57 13", "131 65", "609 305", "197 182", "248 54", "137 68", "47 24", "947 868", "205 50", "863 431", "445 223", "786 393", "122 52", "629 314", "571 286", "980 680", "869 239", "999... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
8d337c19b31a325a4e2c5679c23c0f2a | Fools and Roads | They say that Berland has exactly two problems, fools and roads. Besides, Berland has *n* cities, populated by the fools and connected by the roads. All Berland roads are bidirectional. As there are many fools in Berland, between each pair of cities there is a path (or else the fools would get upset). Also, between eac... | [
"import sys\r\n\r\nMAX_H = 30\r\n\r\ninput = sys.stdin.readline\r\noutput = lambda x: sys.stdout.write(x)\r\n\r\nclass Node:\r\n def __init__(self):\r\n self.pars = []\r\n self.conn = {}\r\n self.count = 0\r\n self.depth = 0\r\n\r\n# input\r\nn = int(input())\r\n\r\nnodes = [Node() fo... | {"inputs": ["5\n1 2\n1 3\n2 4\n2 5\n2\n1 4\n3 5", "5\n3 4\n4 5\n1 4\n2 4\n3\n2 3\n1 3\n3 5"], "outputs": ["2 1 1 1 ", "3 1 1 1 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
8d65492fc90cdeead7cd95db3a21418d | none | Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodo... | [
"import sys\r\ninput = sys.stdin.readline\r\nsys.setrecursionlimit(100000)\r\nfrom collections import defaultdict, deque\r\nfrom itertools import permutations\r\np = print\r\nr = range\r\ndef I(): return int(input())\r\ndef II(): return list(map(int, input().split()))\r\ndef S(): return input()[:-1]\r\ndef M(n): re... | {"inputs": ["2 4\n1 2\n3 4", "4 6\n1 3\n2 3\n4 6\n5 6", "43 1319\n750 1030\n857 946\n941 1203\n407 1034\n947 1290\n546 585\n630 1201\n72 342\n693 1315\n34 719\n176 1097\n36 931\n198 973\n5 1025\n892 1054\n461 1287\n195 1273\n832 1039\n308 955\n642 866\n770 838\n440 777\n289 948\n98 814\n458 768\n82 265\n300 596\n182 70... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8d7482c6a683d3296ea22a704783715b | Om Nom and Necklace | One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.
Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular patt... | [
"\ndef prefix_function(s: str):\n n = len(s)\n pi = [0] * n\n k = 0\n for i in range(1, n):\n while k > 0 and s[i] != s[k]:\n k = pi[k - 1]\n if s[i] == s[k]:\n k += 1\n pi[i] = k\n return pi\n\ndef z_function(s: str):\n n = len(s)\n z = [0] * n\n l, r = 0, 0\n for i in range(1, n):\n ... | {"inputs": ["7 2\nbcabcab", "21 2\nababaababaababaababaa", "321 2\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaa... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
8d8fab3e7d35cb8634eaf569edcf87b7 | Rain and Umbrellas | Polycarp lives on a coordinate line at the point $x = 0$. He goes to his friend that lives at the point $x = a$. Polycarp can move only from left to right, he can pass one unit of length each second.
Now it's raining, so some segments of his way are in the rain. Formally, it's raining on $n$ non-intersecting segments,... | [
"import sys,bisect\r\nfrom functools import cache\r\nread=lambda:map(int,sys.stdin.readline().split())\r\ndst,n,m=read()\r\nrain=sorted([[*read()] for _ in range(n)])\r\numb=sorted([[*read()] for _ in range(m)])+[[dst,dst]]\r\nif umb[0][0]>rain[0][0]:quit(print(-1))\r\n@cache\r\ndef dfs(i):\r\n if i==0:return 0\... | {"inputs": ["10 2 4\n3 7\n8 10\n0 10\n3 4\n8 1\n1 2", "10 1 1\n0 9\n0 5", "10 1 1\n0 9\n1 5", "1 1 1\n0 1\n1 100000", "1 1 1\n0 1\n0 100000", "2000 1 1\n0 1\n2000 33303", "2000 1 1\n1999 2000\n0 18898", "100 50 1\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n21 22\n23 24\n25 26\n27 28\n29 30\n31 32\n33 ... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
8d9078b0a36ff7bd5d993ae41b3780b0 | Rounding | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | [
"n=int(input())\r\nz=int(str(n)[-1])\r\nif z>=5:\r\n\tprint(n+10-z)\r\nelse:\r\n\tprint(n-z)\r\n",
"n=int(input())\r\nk=n%10\r\nif k>0 and k<6:\r\n print(n-k)\r\nif k==0:\r\n print(n)\r\nif k>5 and k<10:\r\n print (n+10-k)",
"n = int(input())\r\nif n % 10 >= 6:\r\n n += 9\r\nprint(n // 10 * 10)\r\n"... | {"inputs": ["5", "113", "1000000000", "5432359", "999999994", "10", "9", "1", "0", "3", "4", "6", "7", "8", "19", "100", "997", "9994", "10002", "100000", "99999", "999999999", "999999998", "999999995", "999999990", "1000000", "1000010", "10000010", "100000011", "400000003", "234234", "675621", "43532", "4576453", "657... | UNKNOWN | PYTHON3 | CODEFORCES | 461 | |
8d9b9f436834145197b35fe3b1a4ec79 | Help Far Away Kingdom | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | [
"def round_number(num_str):\r\n integer_part, fractional_part = num_str.split('.')\r\n last_digit = int(integer_part[-1])\r\n\r\n if last_digit != 9:\r\n if int(fractional_part[0]) < 5:\r\n return integer_part\r\n else:\r\n return str(int(integer_part) + 1)\r\n else:\... | {"inputs": ["0.0", "1.49", "1.50", "2.71828182845904523536", "3.14159265358979323846", "12345678901234567890.1", "123456789123456789.999", "12345678901234567890.9", "123456789123456788.999", "9.000", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "... | UNKNOWN | PYTHON3 | CODEFORCES | 202 | |
8daea05e984def6f793db9d374212130 | Segments | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nx = [0] * (n + 1)\r\nfor l in range(n):\r\n for r in range(l + 1, n + 1):\r\n x[l] += 1\r\n x[r] -= 1\r\nfor i in range(1, n + 1):\r\n x[i] += x[i - 1]\r\nans = max(x)\r\nprint(ans)",
... | {"inputs": ["2", "3", "4", "21", "100", "1", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"... | UNKNOWN | PYTHON3 | CODEFORCES | 157 | |
8db0bc286b569043a28bd31c19f4c65b | Shaass and Oskols | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | [
"n=int(input())\r\ns=input()\r\ns=s.split()\r\nl=[]\r\nfor i in range(n):\r\n l.append(int(s[i]))\r\n\r\n\r\n\r\nm = int(input())\r\n\r\nfor i in range(m):\r\n \r\n ss=input()\r\n ss=ss.split()\r\n xi=int(ss[0])\r\n yi=int(ss[1])\r\n ox=l[xi-1]\r\n l[xi-1]-=yi\r\n if xi-2>=0:\r\n l... | {"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "3\n2 4 1\n1\n2 2", "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "100\n95 15 25 18 64 62 23 59 ... | UNKNOWN | PYTHON3 | CODEFORCES | 397 | |
8dbf384ae645ced530cdc48451343e58 | Pipeline | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has onl... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\n\r\nlo, hi = 0, k\r\nwhile lo < hi:\r\n mid = lo + (hi - lo) // 2\r\n pipes = (mid * (2 * k - mid + 1) // 2) - mid + 1\r\n if pipes >= n:\r\n hi = mid\r\n else:\r\n lo = mid + 1\r\nassert (lo == hi)\r\ntot... | {"inputs": ["4 3", "5 5", "8 4", "1000000000000000000 1000000000", "499999998500000001 1000000000", "499999998500000000 1000000000", "499999999500000000 1000000000", "499999999500000001 1000000000", "525 34", "223265034477 726990", "15597035789572051 185473109", "499999999500000002 1000000000", "1 1000000000", "1000000... | UNKNOWN | PYTHON3 | CODEFORCES | 50 | |
8dd48a95d077948b9426c6505bdbe45c | none | This is an interactive problem.
Jury has hidden a permutation *p* of integers from 0 to *n*<=-<=1. You know only the length *n*. Remind that in permutation all integers are distinct.
Let *b* be the inverse permutation for *p*, i.e. *p**b**i*<==<=*i* for all *i*. The only thing you can do is to ask xor of elements *p*... | [
"import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(n):\r\n L = []\r\n for i in range(n):\r\n sys.stdout.write(f'? {i} 0\\n')\r\n sys.stdout.flush()\r\n ai = int(input())\r\n L.append(ai)\r\n L2 = []\r\n for i in range(n):\r\n sys.stdout.write(f'? 0 {... | {"inputs": ["3\n0 1 2", "4\n3 1 2 0", "4\n3 2 1 0", "8\n2 3 0 1 4 5 6 7", "1\n0", "10\n0 1 2 3 4 5 6 7 8 9", "6\n0 1 2 4 3 5", "2\n0 1", "10\n6 7 4 5 0 1 8 9 2 3", "10\n9 8 1 7 6 4 5 2 0 3", "64\n0 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 41 42 43 44... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8e200e66a6bc8b339fc2303f84d097ff | Geometrical Progression | For given *n*, *l* and *r* find the number of distinct geometrical progression, each of which contains *n* distinct integers not less than *l* and not greater than *r*. In other words, for each progression the following must hold: *l*<=≤<=*a**i*<=≤<=*r* and *a**i*<=≠<=*a**j* , where *a*1,<=*a*2,<=...,<=*a**n* is the ge... | [
"import math\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, l, r = map(int, input().split())\r\nif n == 1:\r\n ans = r - l + 1\r\nelif n == 2:\r\n ans = (r - l + 1) * (r - l)\r\nelse:\r\n x = [1]\r\n if n < 30:\r\n for j in range(2, r + 1):\r\n ... | {"inputs": ["1 1 10", "2 6 9", "3 1 10", "3 3 10", "1 25 845", "2 25 845", "3 25 845", "4 25 845", "5 25 845", "6 25 845", "7 25 845", "8 25 845", "1 1 10000000", "2 1 10000000", "3 1 10000000", "4 1 10000000", "5 1 10000000", "6 1 10000000", "7 1 10000000", "8 1 10000000", "9 1 10000000", "10 1 10000000", "11 1 100000... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8e2fa585a4cce90d151115947a7dfe76 | Maximal Binary Matrix | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | [
"# -*- coding: utf-8 -*-\r\nn,k = map(int, input().split(' '))\r\nif k>n**2:\r\n print(-1)\r\nelif k==n**2:\r\n a = [['1']*n for i in range(n)]\r\n for i in range(n):\r\n a[i] = ' '.join(a[i])\r\n print(a[i])\r\nelse:\r\n a = [['0']*n for i in range(n)]\r\n c = 0\r\n i = 0\r\n b =... | {"inputs": ["2 1", "3 2", "2 5", "1 0", "1 1", "20 398", "20 401", "100 3574", "100 10000", "100 10001", "2 3", "4 5", "5 6", "5 24", "2 0", "3 5", "3 3", "5 10", "3 4", "4 3", "1 1000000", "3 6", "1 2", "1 0", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "1 11", "1 12", "1 13", "1 14", "1 15"... | UNKNOWN | PYTHON3 | CODEFORCES | 99 | |
8e4411543e2b85f1a8bb736483bfdbcb | Beautiful Divisors | Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef divisor(i):\r\n s = []\r\n for j in range(1, int(i ** (1 / 2)) + 1):\r\n if i % j == 0:\r\n s.append(i // j)\r\n s.append(j)\r\n return sorted(set(s))\r\n\r\npow2 = [1]\r\nfor _ in range(20):\r\n pow2.append(2 * pow2[-1])\... | {"inputs": ["3", "992", "81142", "76920", "2016", "1", "6", "32640", "12096", "55948", "47262", "22876", "96120", "42160", "38304", "89408", "97920", "55493", "38021", "21445", "100000", "497", "240", "21204", "65536", "364", "1024", "36", "28", "14400", "10080", "9", "2", "42", "83160", "65534", "1026", "1025", "1027"... | UNKNOWN | PYTHON3 | CODEFORCES | 83 | |
8e47b70b8fb09fa94b3f2521cab6ba43 | Longest Regular Bracket Sequence | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | [
"import sys\r\ninput=lambda:sys.stdin.readline().strip()\r\n\r\ns=input()\r\nstack=[]\r\nm = 0\r\nans = 1\r\nxx = -1\r\nfor i in range(len(s)):\r\n\tif s[i] == '(':stack.append(i)\r\n\telse:\r\n\t\tif len(stack) > 0:\r\n\t\t\tstack.pop()\r\n\t\t\toptimal = i - stack[-1] if len(stack) > 0 else i - xx\r\n\t\t\tif opt... | {"inputs": [")((())))(()())", "))(", "()(())()", "((((()(((", "))))()())))", "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))", ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))", "())(((((())())((((()))(())))())())... | UNKNOWN | PYTHON3 | CODEFORCES | 149 | |
8e4c196a1d858d4cb674277d1f33267d | Bit++ | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | [
"x = int(input())\r\nresultaat = 0\r\nfor y in range(0,x,1):\r\n z = input()\r\n if z == \"++X\" or z == \"X++\":\r\n resultaat += 1\r\n if z == \"--X\" or z == \"X--\":\r\n resultaat -= 1\r\nprint(resultaat)",
"#n is number of statement in the program\r\nx=0\r\nn=int(input())\r\nfor i in r... | {"inputs": ["1\n++X", "2\nX++\n--X", "3\n++X\n++X\n++X", "2\n--X\n--X", "5\n++X\n--X\n++X\n--X\n--X", "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--... | UNKNOWN | PYTHON3 | CODEFORCES | 497 | |
8e50612d70a28d84b770df9166669c6b | The Monster | As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.
Thus, he came up with a puzzle to te... | [
"st=input()\r\nle=len(st)\r\nans=0\r\nfor i in range(le):\r\n l=0\r\n w=0\r\n for j in range(i,le):\r\n if(st[j]==\"(\"):\r\n l+=1\r\n elif(st[j]==\")\"):\r\n l-=1\r\n else:\r\n w+=1\r\n if(l+w<0):\r\n break\r\n elif(w>l):\r\n ... | {"inputs": ["((?))", "??()??", "?????)(???", "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))", "))((()(()((((()))())()())((())())(((()()(())))))((())()()(()()(())()))()()(()()()(((()(()(()(()))))(", "?????????????????????????????????????????????????????????????????????????????????... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
8e64f356f5e4e4ae535eb42d9e1ea3df | Fancy Fence | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | [
"\r\nt = int(input())\r\nrj = []\r\nfor i in range(t):\r\n a = int(input())\r\n\r\n if a < 60:\r\n rj.append('NO')\r\n\r\n else:\r\n n = 3\r\n kut = ((n-2)*180)/n\r\n\r\n while a >= kut:\r\n if a == kut:\r\n rj.append('YES')\r\n break\r\n... | {"inputs": ["3\n30\n60\n90", "6\n1\n2\n3\n170\n179\n25"], "outputs": ["NO\nYES\nYES", "NO\nNO\nNO\nYES\nYES\nNO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 625 | |
8e719483e5e5418e54575f188ffb7458 | Holes | Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:
There are *N* holes located in a single row and numbered from left to right with numbers from 1 to *N*. Each hole has it's own power (hole number *i* has the power *a**i*). If you throw a ... | [
"import sys\nn, m = map(int, sys.stdin.buffer.readline().strip().split())\nbs = 9\na = list(map(int, sys.stdin.buffer.readline().strip().split()))\nrn = [0] * n\nrc = [0] * n\ndef gn(i):\n ni = i + a[i]\n if ni >= n:\n rn[i], rc[i] = i, 0\n elif ni >> bs == i >> bs:\n rn[i], rc[i] = rn[ni], r... | {"inputs": ["8 5\n1 1 1 1 1 2 8 2\n1 1\n0 1 3\n1 1\n0 3 4\n1 2", "10 10\n5 1 2 4 1 7 3 8 10 8\n0 5 6\n1 8\n1 1\n0 10 3\n1 5\n1 3\n1 2\n0 6 1\n1 9\n1 1"], "outputs": ["8 7\n8 5\n7 3", "8 1\n6 2\n5 1\n5 2\n5 3\n9 1\n10 4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
8e83fc290467bbae2f2bbd15052cee39 | Long number | Consider the following grammar:
- <expression> ::= <term> | <expression> '+' <term>- <term> ::= <number> | <number> '-' <number> | <number> '(' <expression> ')'- <number> ::= <pos_digit> | <number> <digit>- <digit> ::= '0' | &... | [
"# a ^ (P-1) ≡ 1 (mod P)\n# a ^ k ≡ (a % P) ^ (k % (P-1)) (mod P)\n\nimport sys\n\nsys.setrecursionlimit(10**5)\n\nMOD = 10**9 + 7\n\n\ndef inv(x):\n return pow(x, MOD - 2, MOD)\n\n\nclass Number:\n def __init__(self, value, length):\n self.value = value % MOD\n self.length = l... | {"inputs": ["8-11", "2(2-4+1)+2(2(17))", "1234-5678", "1+2+3+4-5+6+7-9", "598777", "49603501749575096738857", "11-57", "7177-57797", "4510812433666-7741104736713", "4778066503(27032-80044+16+51+58(9)+5668114736297420472+2336+6-117+8495(7265))", "9678329648012859556810940272201-70370609657815505164700664074744+288702310... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
8e884a3f9a82d8283675daa517424cea | Buying A House | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | [
"n,k,d=map(int,input().split())\r\nk-=1\r\nz=list(map(int,input().split()))\r\ntable=[]\r\ni=0\r\nwhile(i<n):\r\n if(z[i]!=0 and z[i]<=d):\r\n table.append(abs(k-i)*10)\r\n i+=1\r\nprint(min(table))\r\n \r\n",
"n,m,k=map(int,input().split())\r\nm-=1\r\nl=[int(x) for x in input().split()]\r\nq=... | {"inputs": ["5 1 20\n0 27 32 21 19", "7 3 50\n62 0 0 0 99 33 22", "10 5 100\n1 0 1 0 0 0 0 0 1 1", "5 3 1\n1 1 0 0 1", "5 5 5\n1 0 5 6 0", "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20", "7 5 1\n0 100 2 2 0 2 1", "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ... | UNKNOWN | PYTHON3 | CODEFORCES | 329 | |
8e997023d723a3471ac07fd67fc26280 | Gargari and Permutations | Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found *k* permutations. Each of them consists of numbers 1,<=2,<=...,<=*n* in some order. Now he should find the length of the longest common subsequence of these permutatio... | [
"n, k = map(int, input().split())\r\na = [[]]*6\r\nb = []\r\nfor i in range(6):\r\n b.append([0]*(n + 1))\r\n\r\nfor i in range(k):\r\n a[i] = list(map(int, input().split()))\r\n for j in range(n):\r\n b[i][a[i][j]] = j\r\n\r\ndp = [1] * n\r\nfor i in range(n):\r\n for j in range(i):\r\n k... | {"inputs": ["4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3", "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1", "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
8ea2947adf1fbbc23b60a162d770b3ba | Alyona and flowers | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos... | [
"n,m = map(int,input().split())\r\nmoods = list(map(int,input().split()))\r\nfor i in range(1,n):\r\n moods[i] += moods[i-1]\r\ntotal_Happiness=0\r\nwhile(m>0):\r\n l,r = map(int,input().split())\r\n if l==1:\r\n sum = moods[r-1]\r\n else:\r\n sum = moods[r-1] - moods[l-2]\r\n if sum>0:... | {"inputs": ["5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "2 2\n-1 -2\n1 1\n1 2", "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5", "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3", "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8", "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 209 | |
8ed90872b9454656dda60a242d493820 | Ebony and Ivory | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | [
"def main():\r\n a,b,c=map(int,input().split())\r\n if a==c or c%a==0:\r\n print('Yes')\r\n return\r\n if b==c or c%b==0:\r\n print('Yes')\r\n return\r\n if a>b:\r\n a,b=b,a\r\n if a>c:\r\n print('No')\r\n return\r\n for i in range(1,(c-a)//b+1):\r\... | {"inputs": ["4 6 15", "3 2 7", "6 11 6", "3 12 15", "5 5 10", "6 6 7", "1 1 20", "12 14 19", "15 12 26", "2 4 8", "4 5 30", "4 5 48", "2 17 105", "10 25 282", "6 34 323", "2 47 464", "4 53 113", "6 64 546", "1 78 725", "1 84 811", "3 100 441", "20 5 57", "14 19 143", "17 23 248", "11 34 383", "20 47 568", "16 58 410", ... | UNKNOWN | PYTHON3 | CODEFORCES | 192 | |
8f150d098d84cde9f7d73b00f0091443 | none | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | [
"from functools import reduce\r\nfrom math import gcd\r\nn, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nG = gcd(k, reduce(lambda x,y:gcd(x,y),A))\r\nprint(k // G)\r\nprint(*list(range(0, k, G)))",
"n,k=map(int,input().split())\ng=lambda x:int(x)%k\na=list(map(g,input().split()))\ndef n... | {"inputs": ["2 8\n12 20", "3 10\n10 20 30", "5 10\n20 16 4 16 2", "10 5\n4 6 8 6 4 10 2 10 8 6", "20 25\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 20 20 20", "30 30\n11 23 7 30 13 6 25 29 1 15 20 5 28 15 19 22 21 5 27 25 29 10 1 4 12 19 1 5 8 10", "40 30\n16 12 12 22 18 28 32 24 36 26 12 30 22 16 32 30 36 18 20 16 12... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
8f1d925cbfe50cd21d804490a288b86a | Memory and Scores | Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score *a* and Lexa starts with score *b*. In a single turn, both Memory and Lexa get some integer in the range [<=-<=*k*;*k*] (i.e. one integer among <=-<=*k*,<=<=-<=*k*<=+<=1,<=<=-<=*k*<=+<=2,<=...,<=<=-<=2,<=... | [
"def c(n, k):\n\tif k > n:\n\t\treturn 0\n\ta = b = 1\n\tfor i in range(n - k + 1, n + 1):\n\t\ta *= i\n\tfor i in range(1, k + 1):\n\t\tb *= i\n\treturn a // b\na, b, k, t = map(int, input().split())\nn, m, s = 2 * k + 1, 2 * t, 2 * k * t + b - a\nans, mod = 0, 1000000007\nfor i in range(m + 1):\n\tans = (ans + [1... | {"inputs": ["1 2 2 1", "1 1 1 2", "2 12 3 1", "4 6 2 1", "4 6 2 2", "6 4 2 2", "10 1 3 3", "5 3 1 1", "50 22 5 5", "6 20 1 1", "42 42 2 3", "42 42 3 2", "45 54 4 5", "6 5 4 3", "42 42 42 42", "1 100 42 42", "1 100 1000 100", "1 1 1000 100", "100 100 1000 100", "1 8 1 4", "9 4 5 2", "2 6 6 2", "7 8 5 9", "3 7 8 6", "69 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
8f5411ecdb281373c50db07fac8679e9 | Lefthanders and Righthanders | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | [
"# a - 1\ninFile=open(\"input.txt\",\"r\")\noutFiles=open(\"output.txt\",\"w\")\nstudents=inFile.readline().strip()\nstudents=int(students)\nseating=inFile.readline().strip()\nhalfstudents=students//2\nfor i in range(halfstudents):\n if seating[i]==\"L\":\n outFiles.write(str(i+1) + \" \" + str(i+halfstud... | {"inputs": ["6\nLLRLLL", "4\nRRLL", "4\nLLRR", "6\nRLLRRL", "8\nLRLRLLLR", "10\nRLLRLRRRLL", "12\nLRRRRRLRRRRL", "14\nRLLRLLLLRLLLRL", "16\nLLLRRRLRRLLRRLLL", "18\nRRRLLLLRRRLRLRLLRL", "20\nRLRLLRLRRLLRRRRRRLRL", "22\nRLLLRLLLRRLRRRLRLLLLLL", "24\nLRRRLRLLRLRRRRLLLLRRLRLR", "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR", "28\nLLLRRR... | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
8f73f953a8856ca3a4c9cf3d04b14148 | TL | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | [
"n, m = map(int, input().split())\r\ngood = list(map(int, input().split()))\r\nbad = list(map(int, input().split()))\r\nminimum_g, maximum_g = min(good), max(good)\r\nminimum_time = -1\r\nif(minimum_g == maximum_g):\r\n minimum_time = 2*minimum_g\r\nelse:\r\n minimum_time = max(2*minimum_g, maximum_g)\r\n\r\n... | {"inputs": ["3 6\n4 5 2\n8 9 6 10 7 11", "3 1\n3 4 5\n6", "2 5\n45 99\n49 41 77 83 45", "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 5... | UNKNOWN | PYTHON3 | CODEFORCES | 305 | |
8f7bee73b29e1a11e67f9279a1507384 | The Child and Set | At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set *S*:
- its elements were distinct integers from 1 to *limit*; - the value of wa... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\ns, l = map(int, input().split())\r\n\r\nd = []\r\nf = 0\r\nfor i in range(1, l+1):\r\n x = i\r\n c = 1\r\n while 1:\r\n if i & 1:\r\n d.append((c, x))\r\n f += c\r\n break\r\n c *= 2\r\n i >>= 1\r\n ... | {"inputs": ["5 5", "4 3", "5 1", "54321 12345", "1997 508", "100000 30000", "100000 100000", "1 100000", "29985 15678", "83451 17526", "96024 12472", "21741 3575", "40287 17817", "58934 6404", "62658 10881", "89829 8298", "5499 1023", "5499 1024", "53689 10552", "247 3270", "58413 1253", "47283 15757", "93145 14496", "... | UNKNOWN | PYTHON3 | CODEFORCES | 104 | |
8f93f9bd8f9064af561ecdf39f5a1e37 | Alternating Current | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | [
"t = input()\r\n#-+-++--+\r\nstack = []\r\nfor i in t:\r\n\ttry:\r\n\t\tif stack[-1] == i:\r\n\t\t\tstack.pop()\r\n\t\telse:\r\n\t\t\tstack.append(i)\r\n\texcept:\r\n\t\tstack.append(i)\r\nif len(stack) == 0:\r\n\tprint(\"Yes\")\r\nelse:\r\n\tprint(\"No\")",
"arr = list(input())\nans = []\nfor i in arr:\n if l... | {"inputs": ["-++-", "+-", "++", "-", "+-+-", "-+-", "-++-+--+", "+", "-+", "--", "+++", "--+", "++--++", "+-++-+", "+-+--+", "--++-+", "-+-+--", "+-+++-", "-+-+-+", "-++-+--++--+-++-", "+-----+-++---+------+++-++++", "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+... | UNKNOWN | PYTHON3 | CODEFORCES | 189 | |
8fa59503460967189c33fd84aaf7e67c | Help Farmer | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple... | [
"n = int(input())\r\nmn = mx = (n+1)*9\r\ni = 1\r\nwhile i*i <= n :\r\n if n%i == 0 :\r\n j = 1\r\n while j*j <= (n//i) :\r\n if (n//i)%j == 0 :\r\n mn = min(mn,(i+1)*(j+2)*(n//(i*j)+2))\r\n mn = min(mn,(i+2)*(j+1)*(n//(i*j)+2))\r\n mn = min(m... | {"inputs": ["4", "7", "12", "1", "6", "8", "9", "14", "15", "16", "18", "20", "299999771", "54", "96", "348", "748", "908", "1026", "1985", "4472", "20845", "50480", "62497", "646055", "790620", "989903", "7033800", "7661860", "7834243", "45134118", "89054701", "99264891", "127039320", "206898748", "231136953", "257259... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
8fa6e1aca0e2b6bce302b0b112f22de6 | Letter | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | [
"def main():\r\n n, m = list(map(int, input().split()))\r\n arr = []\r\n for _ in range(n):\r\n arr.append(input())\r\n\r\n mn_i, mx_i, mx_j, mn_j = n, -1, -1, m\r\n for i in range(n):\r\n for j in range(m):\r\n if arr[i][j] == \"*\":\r\n mn_i = min(mn_i, i)\r\... | {"inputs": ["6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "3 3\n***\n*.*\n***", "1 1\n*", "2 1\n*\n*", "5 1\n.\n*\n.\n.\n.", "1 6\n*****.", "2 2\n..\n*.", "8 2\n..\n..\n..\n..\n..\n*.\n..\n..", "50 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\... | UNKNOWN | PYTHON3 | CODEFORCES | 218 | |
8fc062d952d56f65554254a2fbe9f3e8 | none | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves long lucky numbers very much. He is interested in the minimum lucky number *d* that me... | [
"a1, a2, a3, a4 = map(int, input().split()) \r\nif a3 == a4 - 1:\r\n if a1 < a4 or a2 < a4:\r\n print(-1)\r\n elif a4 == 1:\r\n print('7' * a2 + '4' * a1)\r\n else:\r\n result = '7' + '4' * (a1 - a4 + 1) + '74' * (a4 - 2) + '7' * (a2 - a4 + 1) + '4'\r\n print(result) \r\nelif a... | {"inputs": ["2 2 1 1", "4 7 3 1", "4 7 4 7", "1 1 1 1", "2 2 1 2", "2 1 2 1", "2 2 2 1", "3 3 1 1", "3 2 1 2", "2 1 3 1", "7 7 1 1", "4 7 2 1", "3 3 2 2", "4 3 2 1", "4 4 2 2", "1000000 1000000 1 1", "1000000 1 1 1", "10 10 3 5", "10 10 3 7", "1 7 1 1", "8 3 2 1", "1000000 1000000 1000000 1000000", "4584 45854 25 685",... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
8fca4ffe8f07d1e257b834639a4873d8 | Hulk | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | [
"import sys\n\ndef inp():\n return int(input())\n\n\ndef inlt():\n return list(map(int, input().split()))\n\n\ndef insr():\n return input().strip()\n\n\ndef out(x):\n sys.stdout.write(str(x) + \"\\n\")\n\ndef main():\n count = inp()\n ans = \"\"\n \n feelings = [\" I love\", \" I hate\"] ... | {"inputs": ["1", "2", "3", "4", "5", "10", "18", "19", "76", "77", "81", "82", "85", "86", "100", "99", "98", "33", "34", "57", "100"], "outputs": ["I hate it", "I hate that I love it", "I hate that I love that I hate it", "I hate that I love that I hate that I love it", "I hate that I love that I hate that I love that... | UNKNOWN | PYTHON3 | CODEFORCES | 532 | |
8fd162f8011e9ed6789a81a11aa77d54 | Winter is here | Winter is here at the North and the White Walkers are close. John Snow has an army consisting of *n* soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.
He has created a method to know how strong his army is. Let the *i*-th soldier’s stre... | [
"import sys\nuseless = sys.stdin.readline()\na = list(map(int,sys.stdin.readline().split()))\nn = 1000001\nmod = 1000000007\ncnt = [0]*n\nfor i in a:\n cnt[i]+=1\narr = [0]*n\nans = 0\nfor i in range(n-1,1,-1):\n j = sum(cnt[i::i])\n if j > 0:\n arr[i]= (j*pow(2,j-1,mod)-sum(arr[i::i]))%mod\n ... | {"inputs": ["3\n3 3 1", "4\n2 3 4 6"], "outputs": ["12", "39"]} | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
902081dac1e789e7037f497776442362 | Recover Polygon (easy) | The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.
Heidi knows that the lair can be represented as a rectangle on a lattice, with si... | [
"import os, sys\r\nfrom io import BytesIO, IOBase\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buff... | {"inputs": ["6\n000000\n000000\n012100\n024200\n012100\n000000", "6\n000000\n012210\n024420\n012210\n000000\n000000", "6\n000100\n001210\n002420\n001210\n000000\n000000", "10\n0000000000\n0122210000\n0244420100\n0122210000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "10\n0000000000\n000000... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
903195a712890e0984e95392fc3fad6d | Positions in Permutations | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
We'l... | [
"mod=10**9+7\r\nn,k=map(int,input().split())\r\n\r\nA=[0]*(n+1)\r\nB=[0]*(n+1)\r\nC=[0]*(n+1)\r\nF=[0]*(n+1)\r\nG=[0]*(n+1)\r\n\r\nF[0]=G[0]=1\r\nfor i in range(1,n+1):\r\n\tG[i]=F[i]=F[i-1]*i%mod\r\n\tG[i]=pow(F[i],(mod-2),mod)\r\n\r\nfor i in range(0,n):\r\n\tif i*2>n:\r\n\t\tbreak\r\n\tB[i]=(F[n-i]*G[i]*G[n-i*2]... | {"inputs": ["1 0", "2 1", "3 2", "4 1", "7 4", "7 7", "8 4", "8 5", "10 3", "20 0", "100 99", "13 13", "100 100", "1000 0", "1000 1", "1000 2", "1000 10", "1000 99", "1000 500", "1000 700", "1000 900", "1000 999", "1000 998", "1000 1000", "999 0", "999 1", "999 5", "999 13", "999 300", "999 600", "999 999", "999 989", ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
903758cfd129ec5da50a446fab0de40f | Mahmoud and Ehab and the function | Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array *a* of length *n* and array *b* of length *m*. He introduced a function *f*(*j*) which is defined for integers *j*, which satisfy 0<=≤<=*j*<=≤<=*m*<=-<=*n*. Suppose, *c**i*<==<=*a**i*<=-<=*b**i*<=+<=*j*. Then *f*(*j*)<==<=|*c*1<=-<=*c*2<=+<... | [
"import bisect\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m, q = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nfor i in range(1, n, 2):\r\n a[i] *= -1\r\nfor i in range(1, m, 2):\r\n b[i] *= -1\r\... | {"inputs": ["5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1", "1 1 1\n937982044\n179683049\n1 1 821220804"], "outputs": ["0\n9\n0\n0", "758298995\n1579519799"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
904ddf9a4d594b95a85d8cf3bef73636 | Turn Off The TV | Luba needs your help again! Luba has *n* TV sets. She knows that *i*-th TV set will be working from moment of time *l**i* till moment *r**i*, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time ... | [
"n = int(input())\nlis = []\nfor i in range(n):\n\ta, b = map(int, input().split())\n\tlis.append([a, b, i+1])\nlis.sort()\ni = 1\nans = -1\n#Turn off the TV\nwhile i<n:\n\tif lis[i][1]<=lis[i-1][1]:\n\t\tans = lis[i][2]\n\t\tprint(ans)\n\t\texit(0)\n\telif( lis[i][0] <= lis[i-1][0] and lis[i][1] >= lis[i-1][1]):\n... | {"inputs": ["3\n1 3\n4 6\n1 7", "2\n0 10\n0 10", "3\n1 2\n3 4\n6 8", "3\n1 2\n2 3\n3 4", "3\n0 500000000\n500000001 1000000000\n0 1000000000", "3\n1 5\n2 4\n6 10", "10\n4 4\n5 9\n5 7\n2 8\n6 10\n4 10\n1 3\n8 9\n0 0\n5 7", "2\n1 3\n2 4", "1\n8 9", "8\n13 17\n83 89\n31 33\n7 13\n52 52\n88 89\n29 30\n16 22", "4\n63 63\n12... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
9051057a015389e58fc1a40a5b2455e2 | Mail Stamps | One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sen... | [
"import sys\r\nfrom collections import deque\r\ninput = sys.stdin.readline\r\ng={}\r\nv=set()\r\nfor _ in range(int(input())):\r\n a,b=[int(x) for x in input().split()]\r\n if a in v:\r\n v.remove(a)\r\n else:\r\n v.add(a)\r\n if b in v:\r\n v.remove(b)\r\n else:\r\n v.add... | {"inputs": ["2\n1 100\n100 2", "3\n3 1\n100 2\n3 2", "3\n458744979 589655889\n248228386 824699605\n458744979 824699605", "4\n90104473 221011623\n18773664 221011623\n90104473 74427905\n74427905 186329050", "5\n695442143 421284135\n641835294 542627184\n852367357 120042890\n641835294 852367357\n542627184 421284135", "6\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 25 | |
909a49d6c60a9180e265a01863223410 | PFAST Inc. | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | [
"# LUOGU_RID: 91401901\nimport copy\r\n\r\n\r\ndef insert(a, b):\r\n try:\r\n g[a][b] = 1\r\n except:\r\n g[a] = {b: 1}\r\n\r\n\r\nglobal ans\r\ng = {}\r\n\r\n\r\ndef dfs(i, n, dv):\r\n if i == n:\r\n return copy.deepcopy(dv)\r\n flag = True\r\n for b in dv:\r\n try:\r\n ... | {"inputs": ["3 1\nPetya\nVasya\nMasha\nPetya Vasya", "3 0\nPasha\nLesha\nVanya", "7 12\nPasha\nLesha\nVanya\nTaras\nNikita\nSergey\nAndrey\nPasha Taras\nPasha Nikita\nPasha Andrey\nPasha Sergey\nLesha Taras\nLesha Nikita\nLesha Andrey\nLesha Sergey\nVanya Taras\nVanya Nikita\nVanya Andrey\nVanya Sergey", "2 0\nAndrey\n... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
90b3babebf9e99d1cac2b06764636584 | none | You are given a rectangular parallelepiped with sides of positive integer lengths $A$, $B$ and $C$.
Find the number of different groups of three integers ($a$, $b$, $c$) such that $1\leq a\leq b\leq c$ and parallelepiped $A\times B\times C$ can be paved with parallelepipeds $a\times b\times c$. Note, that all small p... | [
"from math import gcd\r\n \r\nN = 100001\r\nd = [0 for i in range(N)]\r\nfor i in range(1, N):\r\n for j in range(i, N, i):\r\n d[j] += 1\r\n \r\nn = int(input())\r\nfor _ in range(n):\r\n a, b, c = map(int, input().split())\r\n A, B, C = d[a], d[b], d[c]\r\n AB, BC, CA = d[gcd(a, b)], d[gcd(b, c... | {"inputs": ["4\n1 1 1\n1 6 1\n2 2 2\n100 100 100", "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4", "1\n100000 100000 100000"], "outputs": ["1\n4\n4\n165", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "41\n6\n21\n12\n39\n4\n7\n2... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
90c3ae3432be76316c44df8b294d09fc | Money Transfers | There are *n* banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank *n* are neighbours if *n*<=><=1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative... | [
"# http://codeforces.com/contest/675/problem/C\nfrom collections import defaultdict\n\nn = int(input())\nl = list(map(int, input().split()))\n\n# frequency of the most frequent cumulative sum, using hash\n\nd = defaultdict(int)\n\ncost = n-1\ns = 0 # indicates postion based on sum\nfor x in l:\n s+=x\n d[s]... | {"inputs": ["3\n5 0 -5", "4\n-1 0 1 0", "4\n1 2 3 -6", "1\n0", "50\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 94325701 730397219 358214459 -673647271 -131397668 -377892440 0 0 0 0 0 -487994257 -360271553 639988328 489338210 -281060728 250208758 0 993242346... | UNKNOWN | PYTHON3 | CODEFORCES | 28 | |
90c94d1f5e83e4c8b0d3186dacb5a837 | Good Number | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100,... | [
"n,m=map(int,input().split())\r\nc=0\r\nfor _ in range(n):\r\n a= input()\r\n if all(list(map(lambda x: str(x) in a , range(m+1)))):\r\n c+=1\r\n else:\r\n continue\r\nprint(c)",
"a,b = map(int,input().split())\r\nc = 0\r\nfor i in range(a):\r\n s=0\r\n x=input()\r\n for i in range... | {"inputs": ["10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "2 1\n1\n10", "1 0\n1000000000", "1 1\n1000000000", "6 0\n10\n102\n120\n1032\n1212103\n1999999", "1 3\n1000000000", "1 9\n1000000000", "1 0\n1", "1 1\n1", "1 3\n1", "1 9\n1", "2 8\n123456780\n123", "2 8\n123456... | UNKNOWN | PYTHON3 | CODEFORCES | 318 | |
90e34ecfae4b0a43ec885c28e8b50ef6 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились *n* друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можн... | [
"n = int(input())\r\n\r\ninf = 10**9 + 11\r\narr = []\r\n\r\nfor i in range(n):\r\n wh = list(map(int, input().split()))\r\n wh.sort()\r\n arr.append(wh)\r\n \r\nbest_S = inf\r\ncur_S = 0\r\n\r\nfor h in range(1, 1001):\r\n cur_S = 0\r\n for j in range(n):\r\n if arr[j][0] > h:\r\n ... | {"inputs": ["3\n10 1\n20 2\n30 3", "3\n3 1\n2 2\n4 3", "1\n5 10", "10\n168 538\n836 439\n190 873\n206 47\n891 591\n939 481\n399 898\n859 466\n701 777\n629 222", "42\n13 62\n114 242\n265 839\n756 349\n298 476\n533 704\n348 277\n554 573\n654 112\n429 836\n574 766\n909 415\n163 891\n532 983\n873 457\n719 117\n1 302\n170 6... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
912f39a3ff6a9f5dd8230e1c50920c4f | none | Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.
There are exactly *s* blocks in Chris's set, each block has a unique number from 1 to *s*. Chris's teacher picks a subset of blocks *X* and keeps it to himself. He will give th... | [
"import sys\r\nINF = 10**20\r\nMOD = 10**9 + 7\r\nI = lambda:list(map(int,input().split()))\r\nfrom math import gcd\r\nfrom math import ceil\r\nfrom collections import defaultdict as dd, Counter\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\n\r\n\r\n\"\"\"\r\nFacts and Data representation\r\nConstru... | {"inputs": ["3\n1 4 5", "1\n1", "1\n1000000", "2\n2 999999", "9\n1 2 3 100 500000 500001 999901 999997 999999", "3\n999998 999999 1000000", "3\n1 2 3", "3\n5 345435 999996", "6\n1 10 100 1000 10000 1000000", "2\n1 1000000", "2\n500000 500001", "4\n1 2 999999 1000000", "10\n63649 456347 779 458642 201571 534312 583774 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
9136cb00808749220dc6c0007520b499 | Insomnia cure | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | [
"a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=int(input())\r\ny=int(input())\r\nif a==1 or b==1 or d==1 or c==1:\r\n print(y)\r\nelse:\r\n h=set()\r\n for i in range(1,y+1):\r\n if i%a!=0 and i%b!=0 and i%c!=0 and i%d!=0 :\r\n h.add(i)\r\n print(y-len(h))",
"\r\nk =int(inp... | {"inputs": ["1\n2\n3\n4\n12", "2\n3\n4\n5\n24", "1\n1\n1\n1\n100000", "10\n9\n8\n7\n6", "8\n4\n4\n3\n65437", "8\n4\n1\n10\n59392", "4\n1\n8\n7\n44835", "6\n1\n7\n2\n62982", "2\n7\n4\n9\n56937", "2\n9\n8\n1\n75083", "8\n7\n7\n6\n69038", "4\n4\n2\n3\n54481", "6\n4\n9\n8\n72628", "9\n7\n8\n10\n42357", "5\n6\n4\n3\n60504",... | UNKNOWN | PYTHON3 | CODEFORCES | 410 | |
913a723377dcbcee617e84424051c006 | Guess the Array | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have init... | [
"nnums = int(input())\n\nans = [-1] * nnums\n\nprint(\"? 1 2\", flush = True)\na = int(input())\nprint(\"? 2 3\", flush = True)\nb = int(input())\nprint(\"? 3 1\", flush = True)\nc = int(input())\n\nans[0 : 3] = [(a-b+c)/2, (b-c+a)/2, (c-a+b)/2]\n\nfor i in range(3, nnums):\n print(\"? \" + str(i) + \" \" + str(... | {"inputs": ["5\n4 6 1 5 5", "3\n1 1 1", "4\n100 1 100 1", "10\n9 5 10 7 4 4 8 5 10 5", "3\n1 1 1", "3\n100000 100000 100000", "3\n91906 50782 19777", "15\n5 10 10 7 7 6 4 6 8 10 8 4 10 9 4", "30\n2 3 3 4 3 2 4 4 4 3 3 2 4 2 3 4 4 2 4 3 4 2 2 4 3 3 4 4 4 4", "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 3 2 2 4 3 3 3 3 4... | UNKNOWN | PYTHON3 | CODEFORCES | 109 | |
9143317c9ec97376be9a5c100718a323 | Passwords | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | [
"import math\r\nn,k= map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n w= input()\r\n l.append(w)\r\nr= input()\r\nl.sort(key=len)\r\nle= len(r)\r\nm=[x for x in l if len(x)<le]\r\nprint((len(m)+1)+(len(m)//k)*5,end=\" \") #best\r\no= [x for x in l if len(x)<=le]\r\nprint(((len(o)-1)//k)*5+ len(o)) #... | {"inputs": ["5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "4 100\n11\n22\n1\n2\n22", "1 1\na1\na1", "1 100\na1\na1", "2 1\nabc\nAbc\nAbc", "2 2\nabc\nAbc\nabc", "2 1\nab\nabc\nab", "2 2\nab\nabc\nab", "2 1\nab\nabc\nabc", "2 2\nab\nabc\nabc", "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no", "10 3\n... | UNKNOWN | PYTHON3 | CODEFORCES | 104 | |
91615ecf5e80dbea491e2b190588ef2c | none | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr... | [
"n = int(input())\ns = str(input())\nL = list(map(int, input().split()))\nD = [0 for _ in range(n)]\nr = 0\nok = 1\nwhile r >= 0 and r < n:\n if D[r]:\n ok = 0\n break\n else:\n D[r] = 1\n if s[r] == \"<\":\n r = r - L[r]\n else:\n r = r + L[r]\nif ok:\n print(\"FIN... | {"inputs": ["2\n><\n1 2", "3\n>><\n2 1 1", "1\n>\n1000000000", "1\n<\n1000000000", "2\n>>\n1 1", "5\n>><><\n1 2 3 1 2", "5\n>><><\n1 2 2 1 2", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1", "3\n><<\n2 1 1", "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100", "... | UNKNOWN | PYTHON3 | CODEFORCES | 96 | |
9168c9068c3cb16956fa2cc4c969c235 | none | A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains *n* ski junctions, numbered from 1 to *n*. Initially the junctions aren't connected in any way.
In the constructing process *m* bidirectional... | [
"def find(f, x):\r\n if f[x] != x:\r\n f[x] = find(f, f[x])\r\n return f[x]\r\n\r\ndef un(f, x, y):\r\n x = find(f, x)\r\n y = find(f, y)\r\n if x != y: f[x] = y\r\n \r\nMOD = 10 ** 9 + 9\r\nn, m = map(int, input().split())\r\nf = list(range(n + 1))\r\nans = 1\r\nfor i in range(m):\r\n x... | {"inputs": ["3 4\n1 3\n2 3\n1 2\n1 2", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 5\n10 6\n11 3\n13 14\n7 10\n3 12\n7 14\n8 11\n7 15\n15 8\n12 7\n4 3\n9 4\n8 10", "34 27\n19 10\n8 31\n26 22\n2 30\n32 26\n30 4\n34 1\n2 31\n4 18\n33 11\n10 13\n20 23\n4 32\n23 27\n30 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
916e1fdc90023043052db3e6738ca240 | Chores | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ... | [
"if __name__ == \"__main__\":\r\n n, k, x = list(map(int, input().split()))\r\n chore_times = list(map(int, input().split()))\r\n for i in range(1, k + 1):\r\n chore_times[-i] = x\r\n print(sum(chore_times))\r\n ",
"#----Kuzlyaev-Nikita-Codeforces-----\r\n#------------03.04.2020-------------... | {"inputs": ["4 2 2\n3 6 7 10", "5 2 1\n100 100 100 100 100", "1 1 1\n100", "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 10... | UNKNOWN | PYTHON3 | CODEFORCES | 291 | |
9172cd6361befbdd0dd7efc95b7a917d | Haiku | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | [
"a = input()\r\ndamn = 0\r\ndamn += a.count('a')\r\ndamn += a.count('e')\r\ndamn += a.count('i')\r\ndamn += a.count('o')\r\ndamn += a.count('u')\r\nif damn != 5:\r\n print('NO')\r\n exit()\r\ndamn = 0\r\nb = input()\r\ndamn += b.count('a')\r\ndamn += b.count('e')\r\ndamn += b.count('i')\r\ndamn += b.count('o'... | {"inputs": ["on codeforces \nbeta round is running\n a rustling of keys ", "how many gallons\nof edo s rain did you drink\n cuckoo", " hatsu shigure\n saru mo komino wo\nhoshige nari", "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", " furuike ya\nkawazu... | UNKNOWN | PYTHON3 | CODEFORCES | 426 | |
9193fd7c419ef9dff9dc9dcd79640cdc | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After re... | [
"R,G=lambda:map(int,input().split()),range\r\nn,k=R();a=[0]+[*R()];z,l,p=0,1,1\r\nfor r in G(1,n+1):\r\n p=p*a[r]%k\r\n if p==0:\r\n p=1;i=r\r\n while p*a[i]%k:p=p*a[i]%k;i-=1\r\n z+=(n-r+1)*(i-l+1);l=i+1\r\nprint(z)",
"def gcd(a,b):\r\n if a == 0:\r\n return b\r\n return gcd(b%a,a)\r\n\r\nn,k = [... | {"inputs": ["3 4\n6 2 8", "3 6\n9 1 14", "5 1\n1 3 1 3 1", "5 1\n5 5 5 5 5", "5 1\n5 4 4 4 4", "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100 1\n3 3 2 1... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
919a173054ff13c4de2e0f84f05b8cbb | The Labyrinth | You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such ... | [
"# n=int(input())\r\n# n,k=map(int,input().split())\r\n# arr=list(map(int,input().split()))\r\n#ls=list(map(int,input().split()))\r\n#for i in range(m):\r\n# for _ in range(int(input())):\r\nfrom collections import Counter\r\n#from fractions import Fraction\r\n#n=int(input())\r\n#arr=list(map(int,input().split()))\... | {"inputs": ["3 3\n*.*\n.*.\n*.*", "4 5\n**..*\n..***\n.*.*.\n*.*.*", "1 1\n*", "1 1\n.", "1 10\n**********", "1 10\n*.***.**.*", "10 1\n*\n*\n*\n*\n*\n.\n*\n.\n*\n*", "10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n."], "outputs": ["3.3\n.5.\n3.3", "46..3\n..732\n.6.4.\n5.4.3", "1", ".", "1111111111", "2.212.22.2", "1\n1\n1\n1\n2\n.... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
91b19792c755370d0bb363b9e826e496 | Message | Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*.
String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".
Dr. Moriarty plans to take string *s* and c... | [
"# 156A - Message\r\nx, y = input(), input()\r\nz = len(y)\r\nx = \"0\"*z+x+\"0\"*z\r\nm = 0\r\nfor i in range(len(x)-z):\r\n w = x[i:i+z]\r\n a = 0\r\n for j in range(z):\r\n if w[j] == y[j]:\r\n a += 1\r\n m = max(m, a)\r\nprint(z-m)\r\n",
"s = input()\r\nu = input()\r\n\r\ns = '#'... | {"inputs": ["aaaaa\naaa", "abcabc\nbcd", "abcdef\nklmnopq", "aaabbbaaa\naba", "a\na", "z\nz", "a\nz", "d\nt", "o\nu", "a\nm", "t\nv", "n\ng", "c\nh", "r\ni", "h\nb", "r\na", "c\np", "wbdbzf\nfpvlerhsuf", "zafsqbsu\nhl", "juhlp\nycqugugk", "ladfasxt\ncpvtd", "ally\ncjidwuj", "rgug\npgqwslo", "wmjwu\nrfew", "cpnwcdqff\nq... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
91c3babe38f68cd3ad2fb4f40f35e2f3 | Restoring Table | Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ... | [
"n=int(input())\r\nl=[]\r\nfor _ in range(n):\r\n q=0\r\n for i in map(int,input().split()):\r\n if i!=-1:q|=i\r\n l+=[q]\r\nprint(*l)",
"n=int(input())\r\na=[]\r\nfor i in range(n):\r\n a.append(list(map(int,input().split())))\r\nans = [0]*n\r\nfor i in range(n):\r\n for j in range(n):\r\n i... | {"inputs": ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1", "5\n-1 0 0 0 0\n0 -1 1 0 0\n0 1 -1 0 0\n0 0 0 -1 0\n0 0 0 0 -1", "6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
91c49eb218a529b816dfd941b351be69 | Queue | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | [
"n = int(input())\r\ntlist = list(map(int, input().split()))\r\ntlist.sort()\r\ncount = 0\r\nsum1 = tlist[0]\r\nfor i in range(1,n):\r\n if sum1 <= tlist[i]:\r\n count += 1\r\n sum1 += tlist[i]\r\nprint(count+1) ",
"'''\r\n2300015897\r\n吴杰稀\r\n光华管理学院\r\n'''\r\nn = int(input())\r\nnum_list = list(... | {"inputs": ["5\n15 2 1 5 3", "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\n13 2 5 55 21 34 1 8 1 3", "10\n8 256 16 1 2 1 64 4 128 32", "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "1\n1000000000", "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "20\n16839799 17525904 91276752 42650694 60106463 12243176 ... | UNKNOWN | PYTHON3 | CODEFORCES | 158 | |
91ddbbe8aa042ec08491c7c25d7aba7b | Triangle | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | [
"class point:\n\tdef __init__(self, x=0, y=0):\n\t\tself.x = x\n\t\tself.y = y\n\tdef trans(self, d):\n\t\treturn point(self.x + d[0], self.y + d[1])\ndef cross(a, b, c): return (a.x-c.x) * (b.y-c.y) - (a.y-c.y) * (b.x-c.x)\ndef dot(a, b, c): return (a.x-c.x) * (b.x-c.x) + (a.y-c.y) * (b.y-c.y)\ndef isRight(a, b, c... | {"inputs": ["0 0 2 0 0 1", "2 3 4 5 6 6", "-1 0 2 0 0 1", "27 74 85 23 100 99", "-97 -19 17 62 30 -76", "28 -15 86 32 98 -41", "-66 24 8 -29 17 62", "-83 40 -80 52 -71 43", "-88 67 -62 37 -49 75", "58 45 6 22 13 79", "75 86 -82 89 -37 -35", "34 74 -2 -95 63 -33", "-7 63 78 74 -39 -30", "-49 -99 7 92 61 -28", "-90 90 87... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
91e81a621aec1c42e9fa4f1997c14bf9 | Luck is in Numbers | Vasya has been collecting transport tickets for quite a while now. His collection contains several thousands of tram, trolleybus and bus tickets. Vasya is already fed up with the traditional definition of what a lucky ticket is. Thus, he's looking for new perspectives on that. Besides, Vasya cannot understand why all t... | [
"import sys\r\n\r\nsys.stdin = open('input.txt', 'r')\r\nsys.stdout = open('output.txt', 'w')\r\n\r\ns = input()\r\nn = len(s) // 2\r\n\r\nlines = [\"1111110\", \"0110000\", \"1101101\", \"1111001\", \"0110011\", \"1011011\", \"1011111\", \"1110000\", \"1111111\", \"1111011\"]\r\ncommon = [[0] * 10 for _ in range(1... | {"inputs": ["13", "2345", "88", "682444", "685116", "576079", "569631", "662302", "453066", "659821", "26592659", "47699969", "09980988", "69886888", "9588995888", "39930089893999008989", "84163081988476808998", "88898888988889888898", "01273988890029888889", "18858998881886898888", "8259988583", "5898888944", "8558898... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
91f7cff482b2b493374285494a5a7025 | Beautiful Sets of Points | Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer.
Consider all points (*... | [
"import sys\ninput = lambda:sys.stdin.readline().strip()\nn,m = map(int,input().split())\nx = min(n,m)\nprint(x+1)\nfor i in range(x+1):\n print(i,x-i)\n\t \t\t\t \t\t\t\t\t \t \t\t\t \t\t\t\t\t\t \t \t",
"from math import *\r\nn,m=map(int,input().split())\r\nt=min(n,m)\r\nprint(t+1)\r\nfor i in range(t+1):... | {"inputs": ["2 2", "4 3", "21 21", "10 1", "4 4", "1 1", "5 5", "100 100", "96 96", "99 100", "67 58", "67 59", "80 91", "100 11", "16 55", "13 71", "30 40", "77 77", "6 6", "37 42", "88 88", "95 99", "93 70", "4 6", "1 4", "2 10", "6 7", "28 28", "10 6", "85 48", "9 6", "2 6", "6 4", "6 10", "16 5", "7 6", "3 4", "13 ... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
92033556eb9354fb8e42ff803e338e16 | Polycarp at the Radio | Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others.
We define as *b**j* th... | [
"n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\ntot,ans,s=n//m,0,dict()\r\nfor i in range(m):\r\n s[i+1]=0\r\nfor i in range(n):\r\n if a[i]<=m:\r\n s[a[i]]+=1\r\ni,j=0,0\r\nwhile i<m:\r\n while s[i+1]<tot:\r\n if a[j]>m:\r\n a[j]=i+1\r\n ans+=... | {"inputs": ["4 2\n1 2 3 2", "7 3\n1 3 2 2 2 2 1", "4 4\n1000000000 100 7 1000000000", "1 1\n1", "1 1\n381183829", "2 1\n234089514 461271539", "5 4\n3 1 495987801 522279660 762868488", "10 2\n20515728 1 580955166 856585851 1 738372422 1 2 1 900189620", "20 3\n3 2 2 3 3 3 2 3 3 3 2 748578511 149249674 844954396 321901094... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
9220b32c3435f2ebc62e4b87277d09cc | Ciel and Robot | Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all:
- 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go l... | [
"#!/usr/bin/python3\nimport sys\n\nMAPPING = {\n 'U': (0, 1),\n 'D': (0, -1),\n 'L': (-1, 0),\n 'R': (1, 0),\n}\n\n\ndef read_ints():\n return [int(x) for x in input().split()]\n\n\ndef get_vectors(moves):\n vector = (0, 0)\n yield vector\n for move in moves:\n delta = MAPPING[move]\n... | {"inputs": ["2 2\nRU", "1 2\nRU", "-1 1000000000\nLRRLU", "0 0\nD", "0 0\nUURRDL", "987654321 987654321\nUURRDL", "4 2\nUURRDL", "4 3\nUURRDL", "4 4\nUURRDL", "4 6\nUURRDL", "4 7\nUURRDL", "1000000000 1000000000\nUURRDL", "-1 -1\nUR", "1 1\nUURRDDLL", "987654321 2\nUURDD", "0 123456789\nRRULL", "4 4\nUUUURRRRDDDDLLLL",... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
9220f6088bde1e658f48d2c43eca3a2e | Transformation: from A to B | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | [
"def fc(a,b,re,bl,tmp):\r\n if(a>b):\r\n return\r\n if(a==b):\r\n bl[0]=False\r\n # tmp.append(a)\r\n re.append(tmp)\r\n return\r\n if(bl[0]):\r\n \r\n \r\n fc(a*2,b,re,bl,tmp+[a*2])\r\n fc(a*10+1,b,re,bl,tmp+[a*10+1])\r\nre=[]\r\nbl=[True]\r\n... | {"inputs": ["2 162", "4 42", "100 40021", "1 111111111", "1 1000000000", "999999999 1000000000", "1 2", "1 536870912", "11111 11111111", "59139 946224", "9859 19718", "25987 51974222", "9411 188222222", "25539 510782222", "76259 610072", "92387 184774", "8515 85151111", "91939 9193911", "30518 610361", "46646 373168844... | UNKNOWN | PYTHON3 | CODEFORCES | 275 | |
9244db8730fb75772e42e09626cc70a0 | Lucky Transformation | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of... | [
"n,k=map(int,input().split())\r\ns=[*input()]+[0,0]\r\ni=1\r\nwhile k and i<=n:\r\n if s[i-1]==\"4\" and s[i]==\"7\" and s[i+1]==\"7\" and i%2:\r\n if k%2:\r\n s[i]=\"4\"\r\n break\r\n elif s[i-1]==\"4\" and s[i]==\"4\" and s[i+1]==\"7\" and i%2:\r\n if k%2:\r\n s[i]... | {"inputs": ["7 4\n4727447", "4 2\n4478", "7 7\n4211147", "7 6\n4747477", "10 2\n9474444474", "10 47\n4214777477", "3 99\n447", "4 1000000000\n7747", "3 1000000000\n447", "3 100\n447", "7 74\n4777774", "10 200\n6860544593", "10 477\n5837934237", "47 7477\n83492039276961836565341994102530448486552156001", "100 0\n9179665... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
924ee6af45d93e3e9e8d31fd75d78f25 | Palindromic Supersequence | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | [
"a=input()\r\na1,c=a[::-1],-1\r\nif a==a1:\r\n print(a)\r\n quit()\r\nfor i in range(len(a)):\r\n if a[i:]==a1[:-i]:\r\n c=i\r\n break\r\nif c==-1:\r\n print(a+a1)\r\n quit()\r\nprint(a+a[:c][::-1])\r\n",
"A = input()\r\n\r\nprint(A+A[::-1])",
"def pal(s):\r\n if(s==s[::-1]):\r\n... | {"inputs": ["aba", "ab", "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddw... | UNKNOWN | PYTHON3 | CODEFORCES | 316 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.