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 |
|---|---|---|---|---|---|---|---|---|---|
925e553c109453d152cad07257492d18 | Correct Solution? | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe... | [
"def solve():\r\n n=list(input().strip())\r\n m=list(input().strip())\r\n n.sort()\r\n if n[0]=='0':\r\n for i in range(1,len(n)):\r\n if n[i]!='0':\r\n n[0],n[i]=n[i],n[0]\r\n break\r\n if m==n:\r\n print(\"OK\")\r\n else:\r\n print(\"... | {"inputs": ["3310\n1033", "4\n5", "40\n04", "12\n12", "432\n234", "17109\n01179", "888\n888", "912\n9123", "0\n00", "11110\n1111", "7391\n1397", "201\n102", "111111111\n111111111", "32352320\n22203335", "1000000000\n1", "994321\n123499", "10101\n10101", "666\n0666", "2\n02", "313\n133", "987235645\n234556789", "90812\n... | UNKNOWN | PYTHON3 | CODEFORCES | 95 | |
92637dfd121876c5454d4403888576c8 | Flow Control | You have to handle a very complex water distribution system. The system consists of $n$ junctions and $m$ pipes, $i$-th pipe connects junctions $x_i$ and $y_i$.
The only thing you can do is adjusting the pipes. You have to choose $m$ integer numbers $f_1$, $f_2$, ..., $f_m$ and use them as pipe settings. $i$-th pipe w... | [
"import sys\r\nfrom time import time\r\n\r\ndef i_ints():\r\n return list(map(int, sys.stdin.readline().split()))\r\n\r\ndef main():\r\n limit =10**10\r\n\r\n n, = i_ints()\r\n s = [0] + i_ints()\r\n if sum(s):\r\n print(\"Impossible\")\r\n return\r\n print(\"Possible\")\r\n\r\n m... | {"inputs": ["4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "1\n0\n0", "1\n123\n0", "2\n-1 1\n1\n1 2", "2\n-1 1\n1\n2 1"], "outputs": ["Possible\n-3\n-6\n1\n0\n0", "Impossible", "Possible", "Impossible", "Possible\n1", "Possible\n-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
92666187f65dafd187e08ecca21dfb68 | Servers | There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of se... | [
"n, q = map(int, input().split())\r\nt = [0] * q\r\nk = [0] * q\r\nd = [0] * q\r\nfor i in range(q):\r\n t[i], k[i], d[i] = map(int, input().split())\r\narr_n = [0] * n\r\nfor i in range(q):\r\n arr_n1 = arr_n.copy()\r\n sum_ = 0\r\n if i > 0:\r\n for j in range(n):\r\n arr_n1[j] -= (t... | {"inputs": ["4 3\n1 3 2\n2 2 1\n3 4 3", "3 2\n3 2 3\n5 1 2", "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8", "4 1\n6 1 1", "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1", "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1", "100 1\n1000000 100 100... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
926f692c16a1c9cdb53c696bf20cd7b4 | Lucky Common Subsequence | In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri... | [
"def count_virus(sequence, virus):\r\n return sequence.count(virus)\r\n\r\ndef find_longest_subsequence(a, b, virus):\r\n h = [[-1] * len(b) for _ in range(len(a))]\r\n\r\n def recursive_subsequence(i, j):\r\n if i < 0 or j < 0:\r\n return \"\"\r\n if h[i][j] == -1:\r\n ... | {"inputs": ["AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "AA\nA\nA", "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCUEPHXM\nRRFCZUGFDRKKMQTOETNELXMEWGOCDHFKIXOPVHHEWTCDNXVFKFKTKNWKEIKTCMHMHDNCLLVQSGKHBCDDYVVVQIRPZEOPUGQUGRHH\nR", "CGPWTAPEVBTGANLC... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
92860c2d54613a5f2fb815cb46e37e60 | Shooshuns and Sequence | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ... | [
"n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nwhile n and a[n-1]==a[-1]:\r\n n-=1\r\nif k>n:\r\n print(n)\r\nelse:\r\n print(-1)",
"n, k = map(int, input().split())\r\nif n == 1:\r\n arr = [int(input())]\r\nelse:\r\n arr = list(map(int, input().split()))\r\nfromK = set(arr[k-... | {"inputs": ["3 2\n3 1 1", "3 1\n3 1 1", "1 1\n1", "2 1\n1 1", "2 1\n2 1", "4 4\n1 2 3 4", "4 3\n1 2 3 4", "5 3\n2 1 1 1 1", "5 3\n1 1 1 1 1", "5 5\n1 1 1 1 1", "10 1\n1 1 1 1 1 1 1 1 1 1", "10 1\n1 2 1 1 1 1 1 1 1 1", "10 1\n2 1 1 1 1 1 1 1 1 1", "10 2\n2 1 1 1 1 1 1 1 1 1", "10 2\n1 2 1 1 1 1 1 1 1 1", "10 3\n3 2 1 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 134 | |
929c86cf60c47745d6a36689f25fc604 | Digital Root | Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x... | [
"'''\r\nJana Goodman6\r\n\r\n10C Digital Root\r\n\r\nthis is true: d(xy) = d(d(x)d(y))\r\n\r\nneed to count AB\r\n\r\n question is how many d(AB) == d(C)\r\n but AB != C\r\n\r\n'''\r\nimport math\r\nimport time\r\n\r\ndef dr(n):\r\n return (n - 1) % 9 + 1\r\n\r\ndef digsum(n):\r\n return sum(map(int, ... | {"inputs": ["4", "5", "6", "7", "1", "8", "10", "15", "16", "20", "50", "100", "127", "202", "333", "404", "411", "571", "600", "771", "10000", "20000", "30000", "50000", "99999", "200000", "400000", "600000", "800000", "1000000", "828282", "729761", "653451", "987572", "167590", "358712", "498138", "983242", "312433",... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
92c08c69d538b4c2e5079bb390c72c27 | Little Elephant and Magic Square | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | [
"#sys.setrecursionlimit(300000)\r\nimport sys\r\nimport math as m\r\ndef main():\r\n pass\r\ndef binary(n):\r\n #decimal to binary\r\n return (bin(n).replace(\"0b\", \"\"))\r\ndef decimal(s):\r\n #binary to decimal\r\n return (int(s, 2))\r\ndef pow2(n):\r\n #power of a number base 2\r\n p = 0\r... | {"inputs": ["0 1 1\n1 0 1\n1 1 0", "0 3 6\n5 0 5\n4 7 0", "0 4 4\n4 0 4\n4 4 0", "0 54 48\n36 0 78\n66 60 0", "0 17 14\n15 0 15\n16 13 0", "0 97 56\n69 0 71\n84 43 0", "0 1099 1002\n1027 0 1049\n1074 977 0", "0 98721 99776\n99575 0 99123\n98922 99977 0", "0 6361 2304\n1433 0 8103\n7232 3175 0", "0 99626 99582\n99766 0 ... | UNKNOWN | PYTHON3 | CODEFORCES | 246 | |
92ccbd5c5653fc913a6ad45681e3a8df | String Mark | At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*.
Recently at the BSU was an important test work on which Vasya recived the mark *a*. It is very hard for the teacher to remember the exact mark of every stud... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\na = list(input().rstrip())\r\nb = list(input().rstrip())\r\na = [i - 97 for i in a]\r\nb = [i - 97 for i in b]\r\nn = len(a)\r\nmod = pow(10, 9) + 7\r\ncnt = [0] * 26\r\nfor i in a:\r\n cnt[i] += 1\r\nl = n + 5\r\nfact = [... | {"inputs": ["abc\nddd", "abcdef\nabcdeg", "abacaba\nubuduba", "aac\nbbb", "aaaccc\nbbbbbb", "aaaaaa\nzzzzzz", "abcde\nzzzzz", "a\nc", "aaa\nccc", "abacabadaba\ndabacabaaba", "ujfawuezgiy\nvuqvvsivvwe", "jvmzmvqexcqycjcpuqimvyovcffrdwtexpqhxswzytoaokvnexkzgycpmbgvsnyifkwvfbirtwnprmrlotlnhkogjlmxmgruklcuqstwfwoswux\nvzsm... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
92e4245cc1e7a150805ac581d4a69a8b | Producing Snow | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every ... | [
"n = int(input())\r\nvs = [int(x) for x in input().split()]\r\nts = [int(x) for x in input().split()]\r\n\r\nsumt = 0\r\nfor i, t in enumerate(ts):\r\n vs[i]+=sumt\r\n sumt+=t\r\n\r\nvs.sort()\r\n\r\ntl, tr = 0, 0\r\nil, ir = 0, 0\r\nfor ind, t in enumerate(ts): #check\r\n tl = tr\r\n tr += t\r\n whi... | {"inputs": ["3\n10 10 5\n5 7 2", "5\n30 25 20 15 10\n9 10 12 4 13", "4\n0 0 0 0\n1 2 3 4", "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "10\n20 35 4 0 6 29 4 9 17 10\n0 9 4 7 5 1 4 3 9 4", "1\n4\n5", "1\n5\n4", "1\n5\n5", "2\n9 3\n8 2", "2\n9 3\n4 4", "2\n9 3\n10 2", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
92e6dae987b75873174241e50e0bd7e4 | Beautiful Matrix | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | [
"if __name__ == '__main__':\n m, steps = [], 0\n for r in range(5):\n row = input().split()\n if '1' in row:\n steps += abs(2-r) + abs(2-row.index('1'))\n break \n print(steps)\n",
"l1=[]\r\nfor i in range(1,6):\r\n l=list(map(int,input().split()))\r\n ... | {"inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "1 0 0 0 0\n0 0 0 0 0\n... | UNKNOWN | PYTHON3 | CODEFORCES | 832 | |
92f49e48728895bf9355b6b25cadd38b | Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | [
"class CodeforcesTask120BSolution:\n def __init__(self):\n self.result = ''\n self.n_k = []\n self.questions = []\n\n def read_input(self):\n in_ = open(\"input.txt\").read().split(\"\\n\")\n self.n_k = [int(x) for x in in_[0].split(\" \")]\n self.questions = [int(x) ... | {"inputs": ["5 5\n0 1 0 1 0", "2 1\n1 1", "3 2\n1 0 0", "3 3\n0 1 0", "1 1\n1", "6 3\n0 0 1 1 0 1", "3 1\n0 1 0", "3 3\n1 0 1", "4 4\n1 0 1 0", "5 3\n0 1 0 1 1", "6 4\n1 0 0 0 0 1", "7 5\n1 0 0 0 0 0 1", "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
93036ead36690dea9ad6cf7ba98801a7 | Hit the Lottery | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The f... | [
"t=int(input())\r\nx=[100,20,10,5,1]\r\ncount=0\r\nfor i in x:\r\n count+=t//i\r\n t%=i\r\nprint(count)",
"x = int(input(\"\"))\r\nbills = 0\r\n\r\nbills = bills + x//100\r\nx = x%100\r\n\r\nbills = bills + x//20\r\nx = x%20\r\n\r\nbills = bills + x//10\r\nx = x%10\r\n\r\nbills = bills + x//5\r\nx = x%5\r\n... | {"inputs": ["125", "43", "1000000000", "4", "5", "1", "74", "31", "59", "79", "7", "55", "40", "719", "847", "225", "4704", "1132", "7811", "7981", "82655", "6364", "74611", "45391", "620448", "265145", "671704", "365173", "7130872", "9628747", "8898399", "9497953", "19070947", "20185520", "91402248", "27035533", "2271... | UNKNOWN | PYTHON3 | CODEFORCES | 853 | |
9309776dd3ce513a2e83a90222c7ae3d | Anthem of Berland | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef z_algorithm(w):\r\n m = len(w)\r\n z = [0] * m\r\n z[0] = m\r\n i, j = 1, 0\r\n while i < m:\r\n while i + j < m and w[j] == w[i + j]:\r\n j += 1\r\n z[i] = j\r\n if not j:\r\n i += 1\r\n contin... | {"inputs": ["winlose???winl???w??\nwin", "glo?yto?e??an?\nor", "??c?????\nabcab", "ddddd\nd", "ww?ww\nw", "?????\nn", "xznxr\nxznxr", "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd", "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
931258d7701c6fe0dd407a74d1675d06 | Twins | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | [
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\ncoins.sort(reverse=True)\r\ntotal_sum = sum(coins)\r\nmy_sum = 0\r\ncount = 0\r\nfor i in range(n):\r\n my_sum += coins[i]\r\n count += 1\r\n if my_sum > total_sum - my_sum:\r\n break\r\nprint(count)",
"p=int(input())\r\nc=list(map(in... | {"inputs": ["2\n3 3", "3\n2 1 2", "1\n5", "5\n4 2 2 2 2", "7\n1 10 1 2 1 1 1", "5\n3 2 3 3 1", "2\n2 1", "3\n2 1 3", "6\n1 1 1 1 1 1", "7\n10 10 5 5 5 5 1", "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 600 | |
93133b96b5b3070a160ab0df19ac93d9 | Minesweeper 1D | Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is *n* squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.
For example, the correct field to play look... | [
"import sys\r\nfrom collections import Counter, defaultdict\r\nfrom bisect import bisect_left, bisect_right\r\nfrom heapq import heapify, heappop, heappush\r\nfrom queue import deque\r\ninput = lambda: sys.stdin.readline().strip()\r\nfrom math import gcd, inf, sqrt\r\ndef mrd(fun=int): return [fun(x) for x in input... | {"inputs": ["?01???", "?", "**12", "1", "?01*??****", "0", "2", "*", "0*", "0?", "01", "1*", "1?", "?1?", "12", "2*", "2?", "2??", "?2?", "?2*?2*??1*2**?2*1???*2???100?????*???*?*????0????2?*?*?1??1??*?01**2**1001??**??**??1*?*???00??**??*", "00***???01", "21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
932312c3309f5b145d6fe3168330ff4b | Buses Between Cities | Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* min... | [
"a, t1 = map(int, input().split())\r\nb, t2 = map(int, input().split())\r\nhour, minute = map(int, input().split(':'))\r\nminutef = minute + hour * 60 + t1\r\nminutes = minute + hour * 60 - t2\r\ncnt = 0\r\ntime = 300\r\n\r\nwhile time < minutef and time < 240 * 6:\r\n if time > minutes:\r\n cnt += 1\r\n... | {"inputs": ["10 30\n10 35\n05:20", "60 120\n24 100\n13:00", "30 60\n60 60\n22:30", "30 60\n10 60\n23:30", "5 45\n4 60\n21:00", "1 1\n1 1\n10:28", "4 1\n5 4\n18:40", "8 8\n1 1\n13:24", "20 4\n1 20\n06:20", "15 24\n23 6\n21:15", "30 19\n21 4\n10:30", "31 15\n36 25\n07:04", "24 3\n54 9\n18:12", "18 69\n62 54\n08:00", "33 ... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
933534e531757a47f23e4d8f9ec7fa10 | Hexagons | Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:
Ayrat is searching through the field. He started at point (0,<=0) and is ... | [
"#!/usr/bin/python3\r\n\r\nimport math\r\n\r\ndef solve(n):\r\n if n == 0:\r\n return (0, 0)\r\n\r\n k = int(0.5 * (-1 + math.sqrt(1 + 4 * n / 3.0))) + 10\r\n while 3 * k * (k + 1) >= n:\r\n k -= 1\r\n \r\n n -= 3 * k * (k + 1) + 1\r\n x = 1 + 2 * k\r\n y = 2\r\n\r\n lim = [k] + [k + 1] * 5\r\n dx = [... | {"inputs": ["3", "7", "39", "14", "94", "60", "60", "59", "181994", "486639", "34514", "826594", "1000000000000000000", "854460", "164960", "618459", "496181994", "1000000000", "228939226", "973034514", "984826594", "19164960", "249781780", "851838979", "978618459", "871854460", "302486639", "0", "1", "2", "3", "4", "5... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
934ea466a846bb3ce21dc7df2779105b | The Festive Evening | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | [
"n, k = map(int, input().split())\r\ns = input()\r\nd = {}\r\nop = set()\r\nfor i in range(len(s)):\r\n d[s[i]] = i\r\nans = 0\r\ndoors = 0\r\nfor i in range(len(s)):\r\n if s[i] not in op:\r\n doors += 1\r\n op.add(s[i])\r\n ans = max(ans, doors)\r\n if i == d[s[i]]:\r\n doors -= 1... | {"inputs": ["5 1\nAABBB", "5 1\nABABB", "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA", "5 2\nABACA", "6 2\nABCABC", "8 3\nABCBCDCA", "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD", "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA", "41 19\nTMEYYIIELFDCMBD... | UNKNOWN | PYTHON3 | CODEFORCES | 115 | |
9360f296a2c7948139a477124eb2a1da | Caisa and Pylons | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | [
"try:\r\n t=int(input())\r\n a=list(map(int,input().split(\" \")))\r\n k=max(a)\r\n print(k)\r\nexcept:\r\n pass",
"# DO NOT EDIT THIS\r\nimport math\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque, defaultdict\r\nimport heapq\r\ndef counter(a):\r\n c = defaultdict(l... | {"inputs": ["5\n3 4 3 2 4", "3\n4 4 4", "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 340... | UNKNOWN | PYTHON3 | CODEFORCES | 361 | |
93611e04f3cfd79e75355cf9c18f8e2d | LRU | While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).
Suppose the cache may store no more than *k* objects. At the beginning of the workflow the cache is empty. When some object is querie... | [
"n, k = map(int, input().split())\np = list(map(float, input().split()))\n\ntot = 0\nfor i in range(n):\n if p[i] > 0:\n tot += 1\n\nif tot <= k:\n for i in range(n):\n if p[i] > 0:\n print(format(1, '.9f'))\n else:\n print(format(0, '.9f'))\n\nelse:\n N = (1<<20)... | {"inputs": ["3 1\n0.3 0.2 0.5", "2 1\n0.0 1.0", "3 2\n0.3 0.2 0.5", "3 3\n0.2 0.3 0.5", "1 1\n1.0", "10 1\n0.12 0.14 0.13 0.08 0.15 0.10 0.15 0.04 0.02 0.07", "10 5\n0.02 0.17 0.04 0.07 0.21 0.06 0.09 0.11 0.17 0.06", "10 10\n0.02 0.03 0.12 0.21 0.07 0.15 0.21 0.14 0.01 0.04", "20 10\n0.07 0.03 0.02 0.02 0.09 0.07 0.07... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
9361fef31b3894cff7eb733b7f116acf | Quadcopter Competition | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | [
"x1, y1 = map(int, input().split())\r\nx2, y2 = map(int, input().split())\r\na, b = abs(x2-x1), abs(y2-y1)\r\nif a == 0:\r\n print(4 + 2 * (b + 1))\r\nelif b == 0:\r\n print(2 * (a + 1) + 4)\r\nelse:\r\n print(2*(a+1)+2*(b+1))\r\n",
"x,y=map(int,input().split())\r\na,b=map(int,input().split())\r\nprint((... | {"inputs": ["1 5\n5 2", "0 1\n0 0", "-100 -100\n100 100", "-100 -100\n-100 100", "-100 -100\n100 -100", "100 -100\n-100 -100", "100 -100\n-100 100", "100 -100\n100 100", "-100 100\n-100 -100", "-100 100\n100 -100", "-100 100\n100 100", "100 100\n-100 -100", "100 100\n-100 100", "100 100\n100 -100", "45 -43\n45 -44", "7... | UNKNOWN | PYTHON3 | CODEFORCES | 124 | |
93962dd461fd0469c9158c0a4409dddc | Vasya and Digital Root | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | [
"k,d = input().split()\r\nk,d = int(k), int(d)\r\n\r\nif k==1:\r\n print(d)\r\n \r\nelif d!=0:\r\n s = '1'*(k-1)\r\n m = int(s)\r\n m = 9*m + d\r\n print(m)\r\nelse:\r\n print(\"No solution\")\r\n \r\n \r\n \r\n",
"k,d=map(int,input().split(' '))\r\nif (d==0 and k>1):\r\n print('No... | {"inputs": ["4 4", "5 1", "1 0", "8 7", "487 0", "1000 5", "22 9", "1 1", "1 9", "13 5", "100 4", "123 6", "1000 1", "2 0", "734 9", "678 8", "955 7", "893 3", "998 2", "960 6"], "outputs": ["5881", "36172", "0", "49722154", "No solution", "8541939554067890866522280268745476436249986028349767396372181155840878549622667... | UNKNOWN | PYTHON3 | CODEFORCES | 120 | |
93a967c27d1e68ac71fb2f506e4822a5 | Books | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | [
"p=lambda:list(map(int,input().split()))\r\nn,t=p()\r\nl=p()\r\ni=j=s=0\r\nfor j in range(n):\r\n s+=l[j]\r\n if s>t:\r\n s-=l[i]\r\n i+=1\r\nprint(n-i)",
"n, t = map(int, input().split())\r\na = list(map(int, input().split()))\r\nl = 0\r\nr = 0\r\nc = 0\r\nmc = 0\r\nwhile r < n and l < n:\r\n if c + a[r] <=... | {"inputs": ["4 5\n3 1 2 1", "3 3\n2 2 3", "1 3\n5", "1 10\n4", "2 10\n6 4", "6 10\n2 3 4 2 1 1", "7 13\n6 8 14 9 4 11 10", "10 15\n10 9 1 1 5 10 5 3 7 2", "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4", "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19", "100 100\n75 92 18 ... | UNKNOWN | PYTHON3 | CODEFORCES | 308 | |
93aa6c82a42a61f509b47c9cafa68e5b | Ann and Half-Palindrome | Tomorrow Ann takes the hardest exam of programming where she should get an excellent mark.
On the last theoretical class the teacher introduced the notion of a half-palindrome.
String *t* is a half-palindrome, if for all the odd positions *i* () the following condition is held: *t**i*<==<=*t*|*t*|<=-<=*i*<=+<=1, wh... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef add(v):\r\n G0.append(-1)\r\n G1.append(-1)\r\n p.append(v)\r\n cnt.append(0)\r\n return\r\n\r\ns = list(input().rstrip())\r\ns = [i - 97 for i in s]\r\nk = int(input())\r\nn = len(s)\r\nx = [[] for _ in ra... | {"inputs": ["abbabaab\n7", "aaaaa\n10", "bbaabb\n13", "a\n1", "b\n1", "ababbbbbbbaaaaaaaabbbbbb\n23", "aa\n3", "aa\n1", "aa\n2", "ab\n1", "ab\n2", "aaa\n1", "aaa\n2", "aaa\n3", "aaa\n4", "aaa\n5", "aaa\n6", "abb\n1", "abb\n2", "abb\n3", "abb\n4", "aba\n4", "aba\n3", "aba\n2", "aba\n1"], "outputs": ["abaa", "aaa", "bbaa... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
93e73b0ba3ef401390253ad421d7995a | Progress Bar | A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.
A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* fr... | [
"n, k, t = map(int,input().split())\nx = n * k * t / 100\n\nfor i in range(n):\n t = min(x, k)\n print(int(t), end = ' ')\n x -= t\n",
"import math\r\n\r\nvar1 = input().split(\" \")\r\ntotal = math.floor(int(var1[0]) * int(var1[1])*int(var1[2])/100)\r\ncharCount = int(var1[0])\r\nansString = \"\"\r\nfor... | {"inputs": ["10 10 54", "11 13 37", "9 25 50", "43 47 77", "20 1 43", "17 4 61", "10 16 0", "17 13 100", "11 9 1", "9 11 99", "6 17 1", "6 17 99", "17 6 1", "17 6 99", "99 1 1", "99 1 99", "1 1 0", "1 1 37", "1 1 50", "1 1 51", "1 1 99", "1 1 100", "1 17 35", "1 31 88", "1 100 0", "1 100 38", "1 100 99", "1 100 100", "... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
93ed3cd729c322a66d7fe44bf787cab4 | No to Palindromes! | Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to... | [
"n, p = map(int, input().split())\r\ns = list(ord(i) - 97 for i in input())\r\n\r\nfor i in range(n - 1, -1, -1):\r\n for j in range(s[i] + 1, p):\r\n if (i < 1 or j != s[i - 1]) and (i < 2 or j != s[i - 2]):\r\n s[i] = j\r\n for i in range(i + 1, n):\r\n for j in rang... | {"inputs": ["3 3\ncba", "3 4\ncba", "4 4\nabcd", "2 2\nab", "2 2\nba", "1 2\na", "1 2\nb", "1 1\na", "3 4\ncdb", "7 26\nzyxzyxz", "10 5\nabcabcabca", "10 10\nfajegfaicb", "1 26\no", "1 2\nb", "1 26\nz", "3 3\ncab", "3 26\nyzx", "5 5\naceba", "10 3\ncbacbacbac", "11 3\nabcabcabcab", "12 10\nabcabcabcabc", "13 7\ngfegfeg... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
93f371930641819822b183ffc5533b6f | Population Size | Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\ni = 0\r\nans = 0\r\nwhile i < n:\r\n ans += 1\r\n i1 = i\r\n while i1 < n and a[i1] == -1:\r\n i1 += 1\r\n if i1 == n:\r\n break\r\n i2 = i1 + 1\r\n while i2 < n and a[i2] == -1:\r\n i2 += 1\r\n if i2 == n:\r\n ... | {"inputs": ["9\n8 6 4 2 1 4 7 10 2", "9\n-1 6 -1 2 -1 4 7 -1 2", "5\n-1 -1 -1 -1 -1", "7\n-1 -1 4 5 1 2 3", "1\n1", "1\n65", "1\n1000000000", "1\n-1", "2\n1000000000 1000000000", "2\n1000000000 -1", "2\n-1 1000000000", "2\n-1 -1", "3\n999999999 1000000000 -1", "3\n999999999 -1 1000000000", "3\n1000000000 999999999 1000... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
9423c1bacb4232559c8da48975cfd38d | none | Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.
The dot product of two integer number vectors *x* and *y* of size *n* is the sum of the products of the corresponding components of the vectors. The unusual square of an *n*<=×<=*n* square ... | [
"from sys import stdin, stdout\nrd = lambda: list(map(int, stdin.readline().split()))\nrds = lambda: stdin.readline().rstrip()\nii = lambda: int(stdin.readline())\n\nn = ii()\n\na = [rd() for _ in range(n)]\n\np = 0 \nfor i in range(n):\n p += a[i][i]\n\np = p % 2\n\nt = ii()\nans = []\nfor _ in range(t):\n s... | {"inputs": ["3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3", "1\n1\n9\n1 1\n3\n1 1\n1 1\n3\n1 1\n3\n1 1\n3", "3\n1 0 1\n0 1 1\n1 0 1\n4\n3\n3\n3\n3", "1\n0\n5\n1 1\n3\n1 1\n1 1\n3", "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3", "2\n0 1\n1 0\n7\n3\n3\n2 2\n3\n2 2\n2 1\n3", "5\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
942dda7f65cceb57b7d6d092f3bb32d3 | Castle Defense | Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into *n* sections. At this moment there are exactly *a**i* archers located ... | [
"import sys\r\nfrom array import array\r\nfrom collections import deque\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nn, dist, k = map(int, input().split())\r\na = array('i', [int(x) for x in input().split()])\r\ncum = [0] * (n + 1)\r\n\r\nfor i in range(n):\r\n cum[i + 1] = cum[i] + a[i... | {"inputs": ["5 0 6\n5 4 3 4 9", "4 2 0\n1 2 3 4", "5 1 1\n2 1 2 1 2", "1 0 0\n0", "1 0 1000000000000000000\n1000000000", "1 1 10\n23", "2 0 100\n98 2", "3 1 1000\n0 0 0", "100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
942ec18dc47325413b71a977730c10fe | Very Interesting Game | In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and re... | [
"a, b, m = map(int, input().split())\r\nc = (10 ** 9) % m\r\nans = -1\r\nfor x in range(1, min(a + 1, m)):\r\n z = (x * c) % m\r\n if z == 0:\r\n continue\r\n if z + b < m:\r\n ans = x\r\n break\r\nif ans == -1:\r\n print(2)\r\nelse:\r\n s = str(ans)\r\n s = ('0' * 9 + s)[-9:]... | {"inputs": ["1 10 7", "4 0 9", "10 7 8", "6 4 10", "4 1 4", "4 7 9", "13 4 51", "0 0 1", "1 0 1", "2 1 3", "0 2 2", "2 3 1", "3 0 3", "1 1 2", "3 2 1", "0 3 3", "4 0 13", "1 2 13", "4 3 12", "1 2 11", "4 3 12", "815 216 182", "218 550 593", "116482865 344094604 3271060", "19749161 751031022 646204", "70499104 10483793 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
945fb097d72ffaca116be20ac37527ef | President's Office | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | [
"def checa(x, y):\r\n if x < 0 or x >= n or y < 0 or y >= m or matrix[x][y] == c or matrix[x][y] == '.':\r\n return False\r\n return True\r\nn, m, c = input().split()\r\nn, m = int(n), int(m)\r\n\r\nmatrix = []\r\nfor k in range(n):\r\n matrix.append(input())\r\n\r\nx = [-1, 0, 0, 1]\r\ny = [0, 1, -... | {"inputs": ["3 4 R\nG.B.\n.RR.\nTTT.", "3 3 Z\n...\n.H.\n..Z", "1 1 C\nC", "2 2 W\nKW\nKW", "1 10 H\n....DDHHHH", "3 2 W\nOO\nWW\nWW", "3 3 U\nUOO\nUVV\nUVV", "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.", "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ", "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN", "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J", "7 7 Q\n... | UNKNOWN | PYTHON3 | CODEFORCES | 148 | |
947a2b4f73b2035009e5a5f2fe0b5929 | Counting Rhombi | You have two positive integers *w* and *h*. Your task is to count the number of rhombi which have the following properties:
- Have positive area. - With vertices at integer points. - All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0,<=0), (*w*,<=0), (*w*,<=*... | [
"w, h = map(int, input().split())\r\nresult = 0\r\nw -= 1\r\nh -= 1\r\nph = h // 2\r\npw = w // 2\r\nresult = ph * (ph + 1) * pw * (pw + 1)\r\nif h % 2:\r\n result += (pw + 1) * pw * (ph + 1)\r\nif w % 2:\r\n result += (ph + 1) * ph * (pw + 1)\r\nif h % 2 and w % 2:\r\n result += (pw + 1) * (ph + 1)\r\npri... | {"inputs": ["2 2", "1 2", "1 4000", "4000 1", "4000 4000", "15 10", "7 9", "17 17", "7 13", "9 14", "3 10", "14 2", "4 6", "18 2858", "14 1274", "25 2986", "13 1402", "2955 21", "1665 27", "3671 19", "2541 25", "1913 3980", "3727 2044", "2437 460", "1499 2172", "1 1"], "outputs": ["1", "0", "0", "0", "16000000000000", ... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
94ac7aa8df66cdfd45baecfb72de495b | Network Mask | The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.
Polycarpus has found a job, he is a system administrator. One day he came across *n* IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separ... | [
"import math\nimport re\nfrom fractions import Fraction\nfrom collections import Counter\n\nclass Task:\n ips = []\n k = 0\n answer = ''\n \n def __init__(self):\n n, self.k = [int(x) for x in input().split()]\n self.ips = ['' for _ in range(n)]\n for i in range(len(self.ips)):\n... | {"inputs": ["5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3", "2 1\n255.0.0.1\n0.0.0.2", "10 2\n57.11.146.42\n200.130.164.235\n52.119.155.71\n113.10.216.20\n28.23.6.128\n190.112.90.85\n7.37.210.55\n20.190.120.226\n170.124.158.110\n122.157.34.141", "11 4\n30.181.69.1... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
94c0b5d0cd3a264fb19232cc2aa4236a | Chemistry in Berland | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nb = [0] + list(map(int, input().split()))\r\na = [0] + list(map(int, input().split()))\r\nG = [[] for _ in range(n + 1)]\r\nx0, k0 = [0] * (n + 1), [0] * (n + 1)\r\nfor y in range(2, n + 1):\r\n x, k = map(int, input().split())\r\n G[x].appe... | {"inputs": ["3\n1 2 3\n3 2 1\n1 1\n1 1", "3\n3 2 1\n1 2 3\n1 1\n1 2", "5\n2 1 1 2 3\n1 2 2 2 1\n1 2\n1 3\n2 4\n1 4", "10\n2 8 6 1 2 7 6 9 2 8\n4 9 4 3 5 2 9 3 7 3\n1 8\n2 8\n3 8\n4 10\n5 1\n6 4\n7 3\n8 10\n9 2", "5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
94f22c184db967f634f47abb84439aea | Dima and Trap Graph | Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal...
Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate inter... | [
"class Node:\r\n def __init__(self, a, b, l, r):\r\n self.a = a\r\n self.b = b\r\n self.l = l\r\n self.r = r\r\ndef func(a, p):\r\n if p[a] == -1 or p[a] == a:\r\n return a\r\n p[a] = func(p[a], p)\r\n return p[a]\r\nn, m = map(int, input().split())\r\nnode = []\r\nfor... | {"inputs": ["4 4\n1 2 1 10\n2 4 3 5\n1 3 1 5\n2 4 2 7", "5 6\n1 2 1 10\n2 5 11 20\n1 4 2 5\n1 3 10 11\n3 4 12 10000\n4 5 6 6", "6 6\n1 2 1 10\n2 3 1 10\n3 6 1 1\n1 4 1 4\n4 5 1 3\n5 6 1 3", "2 1\n1 2 1 1", "10 0", "5 5\n1 5 9403 40347\n1 3 13851 29314\n4 5 1315 561894\n3 5 2748 33090\n5 3 10717 32306", "1000 0"], "outp... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
94f5f504815e2f4db2c2158e710bb9ad | TV Game | There is a new TV game on BerTV. In this game two players get a number *A* consisting of 2*n* digits. Before each turn players determine who will make the next move. Each player should make exactly *n* moves. On it's turn *i*-th player takes the leftmost digit of *A* and appends it to his or her number *S**i*. After th... | [
"from functools import *\nn,a=int(input()),[*map(int,input())]\n@lru_cache(maxsize=None)\ndef v(h=n,m=n):\n r,t=(0,''),a[-h-m]\n if h:\n w,q=v(h-1,m)\n r=(w+t*10**(h-1),'H'+q)\n if m:\n w,q=v(h,m-1)\n r=max(r,(w+t*10**(m-1),'M'+q))\n return r\nprint(v()[1])",
"n=int(input()... | {"inputs": ["2\n1234", "2\n9911", "2\n0153", "3\n614615", "4\n21305374", "4\n00013213", "1\n01", "1\n21", "1\n99", "18\n999999999999999999999999999999999999", "10\n89959999998998796989", "10\n99999988899989998889", "7\n10210320200120", "18\n949787136121830145537930861689777414", "18\n95685957978983485816721877889379638... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
950b70b0c59e455e4a9d58b8858b308d | Plant | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide... | [
"def mult(a,b,m):\r\n n1,m1=len(a),len(a[0])\r\n n2,m2=len(b),len(b[0])\r\n if m1!=n2: raise Exception('Dimension error')\r\n c=[[0]*m2 for i in range(n1)]\r\n for i in range(m2):\r\n for j in range(n1):\r\n for k in range(n2):\r\n c[j][i]=(c[j][i]+b[k][i]*a[j][k])%m\... | {"inputs": ["1", "2", "385599124", "989464295", "376367012", "529357306", "782916801", "74859961358140080", "0", "252509053898415171", "760713016078377938", "919845424847912644", "585335721566249104", "522842183413115087", "148049062285906746", "84324827171274022", "354979172034763159", "1312148742261680", "26958744805... | UNKNOWN | PYTHON3 | CODEFORCES | 53 | |
950cdd5d07ef7b2fb94d84bbff05380a | Vanya and Books | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | [
"n=int(input())\r\na=len(str(n))\r\nprint(a*(n+1)-int('1'*a))",
"import math\r\nn = int(input())\r\ndigits = 0\r\na = int(math.log10(n)) + 1\r\nfor x in range(1, a):\r\n digits += 10 ** (x - 1) * 9 * x\r\ndigits += (n - 10 ** (a - 1) + 1) * a\r\nprint(digits)",
"a=int(input())\r\ndigits=0\r\nrem=0\r\nfor i i... | {"inputs": ["13", "4", "100", "99", "1000000000", "1000000", "999", "55", "222222222", "8", "13", "313", "1342", "30140", "290092", "2156660", "96482216", "943006819", "1", "7", "35", "996", "6120", "30660", "349463", "8171970", "36123011", "986747865", "9", "10", "11", "101", "1000", "1001", "9999", "10000", "10001", ... | UNKNOWN | PYTHON3 | CODEFORCES | 290 | |
950ec6b7587c04fab5f98f9b0f6f7140 | Dima and Magic Guitar | Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with *n* strings and *m* frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the *i*-th string holding it on the *j*... | [
"n, m, k, s = map(int, input().split())\r\nnotes = [[-1000] * 4 for _ in range(10)]\r\nfor i in range(1, n + 1):\r\n r = list(map(int, input().split()))\r\n for j in range(1, m + 1):\r\n k = r[j - 1]\r\n notes[k][0] = max(notes[k][0], -i - j)\r\n notes[k][1] = max(notes[k][1], -i + j)\r\n... | {"inputs": ["4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1", "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5", "5 5 2 2\n2 2 2 1 2\n2 1 2 2 2\n2 2 2 2 2\n1 2 2 2 2\n2 2 2 2 1\n1 1", "5 5 2 2\n2 1 2 2 2\n2 2 2 2 2\n2 2 2 2 1\n2 2 2 2 2\n1 2 2 2 2\n1 1", "11 11 9 11\n1 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
9512d95f55e6714b775f910ab872b25d | Special Matrices | An *n*<=×<=*n* square matrix is special, if:
- it is binary, that is, each cell contains either a 0, or a 1; - the number of ones in each row and column equals 2.
You are given *n* and the first *m* rows of the matrix. Print the number of special *n*<=×<=*n* matrices, such that the first *m* rows coincide with the ... | [
"n,m,M=[int(e) for e in input().split()]\r\nc=[2]*n\r\nfor i in range(m):\r\n a=[int(e) for e in input()]\r\n for j in range(n):\r\n c[j]-=a[j]\r\ndef C(n,k):\r\n if k>n or n<0 or k<0:\r\n return 0\r\n res=1\r\n for i in range(n-k+1, n+1):\r\n res*=i\r\n for i in range(1, k+1)... | {"inputs": ["3 1 1000\n011", "4 4 100500\n0110\n1010\n0101\n1001", "2 0 1000", "2 1 1000\n11", "5 0 13", "5 3 19\n10001\n10001\n00110", "3 0 100500", "4 0 100500", "5 0 100500", "6 0 100500", "3 1 100501\n101", "4 2 100501\n1010\n1010", "5 2 100501\n10010\n10100", "6 4 100501\n100010\n100100\n010100\n000011", "7 4 1005... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
95134230a7f87d3bd4d0603bfbe2719c | Anton and Digits | Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each... | [
"a, b, d, e = map(int, input().split())\r\nc = 0\r\nr = [a, d, e]\r\nc += min(r) * 256\r\na -= min(r)\r\nq = [a, b]\r\nc += min(q) * 32\r\nprint(c)\r\n",
"numbers = list(map(int, input().split()))\r\n\r\nresult = 0\r\n\r\nif numbers[0] > 0 and numbers[2] > 0 and numbers[3] > 0:\r\n step = min(numbers[0], numbe... | {"inputs": ["5 1 3 4", "1 1 1 1", "10 2 1 5", "4 2 7 2", "489 292 127 263", "9557 5242 1190 7734", "1480320 1969946 1158387 3940412", "0 0 0 0", "5000000 5000000 5000000 5000000", "1048576 256 1048576 1048576", "2073144 2073145 0 0", "1000000 0 0 1", "2 1 1 1", "0 5000000 5000000 5000000", "4494839 1140434 3336818 4921... | UNKNOWN | PYTHON3 | CODEFORCES | 34 | |
9514456a8a09980d6d495a6a8edf495c | Polo the Penguin and Strings | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo... | [
"a,b=map(int,input().split())\r\nif b==1 and a!=1:print(-1)\r\nelif a<b:print(-1)\r\nelif a==1==b:print(\"a\")\r\nelse:\r\n b-=2;a-=b;print(\"ab\"*(a//2)+\"a\"*(a%2),end=\"\")\r\n for i in range(b):print(chr(99+i),end=\"\")",
"X = list(map(int, input().split()))\r\nTemp = \"\".join([chr(ord(\"a\") + i) for ... | {"inputs": ["7 4", "4 7", "10 5", "47 2", "10 7", "20 7", "26 26", "47 1", "128 26", "999 7", "4585 1", "6875 2", "7642 3", "100000 7", "68754 25", "1000000 1", "999999 2", "1000000 26", "100000 20", "579466 17", "679854 9", "978458 16", "6791 21", "6795 1", "12 17", "1 1", "2 2", "1 2", "1 26", "26 2", "123 21", "3 3"... | UNKNOWN | PYTHON3 | CODEFORCES | 29 | |
952b7e7743211fb31c5c2332e800bc25 | Hamming Distance | Hamming distance between strings *a* and *b* of equal length (denoted by *h*(*a*,<=*b*)) is equal to the number of distinct integers *i* (1<=≤<=*i*<=≤<=|*a*|), such that *a**i*<=≠<=*b**i*, where *a**i* is the *i*-th symbol of string *a*, *b**i* is the *i*-th symbol of string *b*. For example, the Hamming distance betwe... | [
"def get_input():\r\n a, b, d = map(int, input().split())\r\n c, e = map(int, input().split())\r\n f = int(input())\r\n return [a, b, c, d, e, f]\r\n\r\n\r\ndef check_condition(a, b, c, d, e, f):\r\n condition1 = (a + b + c) % 2 == 0\r\n condition2 = (d + e + a) % 2 == 0\r\n condition3 = (e + f... | {"inputs": ["4 4 4\n4 4\n4", "10 10 8\n8 8\n10", "50109 50255 50102\n50104 50011\n50085", "99999 99998 99997\n99996 99995\n99994", "6 6 6\n6 6\n6", "1 1 1\n1 1\n1", "2 2 2\n2 2\n2", "2 1 2\n2 2\n2", "5 6 6\n6 5\n5", "5 3 5\n6 4\n2", "46 53 56\n59 52\n45", "544 474 496\n506 492\n484", "3 6 4\n3 5\n6", "52 57 55\n45 51\n... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
956bf36b1fd1dafc14ac9d941a9d4c65 | Name Quest | A Martian boy is named *s* — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets hap... | [
"name = input()\r\nline = input()\r\n\r\ni_name = 0\r\ni_line = 0\r\n\r\nwhile i_name < len(name) and i_line < len(line):\r\n if name[i_name] == line[i_line]:\r\n i_name += 1\r\n i_line += 1\r\n\r\nj_name = len(name) - 1\r\nj_line = len(line) - 1\r\n\r\nwhile j_name >= 0 and j_line >= 0:\r\n if name... | {"inputs": ["aba\nbaobababbah", "mars\nsunvenusearthmarsjupitersaturnuranusneptune", "rry\nsorrymercuryismissedabove", "a\naaaaaaaaaaaaaa", "abcaba\nabcabaabcabaabcabaabcaba", "lol\nlol", "aaaaaaaaaaaa\naaaaaa", "a\na"], "outputs": ["2", "0", "3", "13", "13", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
9586d45106030df74f42ad1e662f9280 | Watching a movie | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie... | [
"n, m = list(map(int, input().split()))\r\ncount = 0\r\nc = 1\r\nl = []\r\nfor i in range(n):\r\n l.append(list(map(int, input().split())))\r\nfor p in l:\r\n a = p[0]\r\n b = p[1]\r\n count += (a-c) % m + (b-a) + 1\r\n c = b + 1\r\nprint(count)",
"n,x = map(int, input().split())\r\nmini = 0\r\nini... | {"inputs": ["2 3\n5 6\n10 12", "1 1\n1 100000", "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 136 | |
95cec444d35ca774eda9fe6cb6c283db | none | Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route... | [
"from heapq import *\r\nfrom collections import Counter, defaultdict, deque\r\nINF = int(1e9)\r\ndef solve():\r\n import sys\r\n input =sys.stdin.buffer.readline\r\n \r\n n,m,k=list(map(int,input().split()))\r\n\r\n gr =[[] for _ in range(n)]\r\n\r\n dist =[INF]*(n)\r\n\r\n dist[0]=0\r\n\r\n ... | {"inputs": ["5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000", "3 2 5\n1 2 2\n2 3 4\n3 5\n3 5\n3 5\n3 6\n3 7", "5 5 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
95f3ddd5d5fddf1a92aaafaa76f4824d | Chessboard Billiard | Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves ... | [
"import sys\nfrom collections import defaultdict\n\nclass UnionFind:\n def __init__(self, n: int):\n self.data = list(range(n))\n self.rank = [1] * n\n self.size = [1] * n\n self.count = n\n \n def find(self, x: int) -> int:\n y = x\n while self.data[y] != y:\n ... | {"inputs": ["3 4", "3 3", "2 2", "4 3", "2 3", "4 4", "4 6", "4 7", "5 7", "5 13", "7 10", "7 21", "7 61", "8 50", "8 8", "9 9", "9 256", "10 10", "999 999", "1000000 1000000", "2311 7771", "146412 710630", "943547 987965", "35329 689665", "672961 948978", "524288 131072", "293492 654942", "962963 1000000", "7 1000000"... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
9609f8411c1b825c8ad1f6fba66ebebb | File Name | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | [
"n = int(input())\r\nfile_name = input()\r\ncount_x,removals = 0,0\r\nfor i in range(n):\r\n if file_name[i] == 'x':\r\n count_x += 1\r\n if count_x >= 3:removals += 1\r\n else:count_x = 0\r\nprint(removals)",
"n = int(input())\r\ns = input()\r\nq = 0\r\nw = 0\r\nfor c in s:\r\n if c == 'x'... | {"inputs": ["6\nxxxiii", "5\nxxoxx", "10\nxxxxxxxxxx", "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "3\nxxx", "77\naaabbbcccdddeeefffggghhhiiijjjkkkl... | UNKNOWN | PYTHON3 | CODEFORCES | 325 | |
961446004eb9d83762673abfd2c4b1e8 | Vasya's Calendar | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | [
"t = int(input())\na = int(input())\nl = input().split(' ')\ntimes = 0\nfor i in range(0, a-1):\n times += t - int(l[i])\nprint(times)\n \t\t\t \t\t\t \t \t\t\t\t \t \t",
"\ndef solve() :\n c=0\n for i in arr[:-1]:\n c+= d - i\n return c\n\n\n\n\n\n \n \nd=int(input())\nn=... | {"inputs": ["4\n2\n2 2", "5\n3\n3 4 3", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "1\n1\n1", "1\n2\n1 1", "2\n2\n1 1", "10\n2\n10 2", "10\n3\n6 3 6", "10\n4\n8 7 1 5", "10\n5\n2 7 8 4 4", "10\n6\n8 3 4 9 6 1", "10\n7\n10 5 3 1 1 9 1", "10\n8\n6 5 10 6 8 1 3 2", "10\n9\n6 2 7 5 5 4 8 6 2", "10\n10\n1 10 1 10 1 1 7 ... | UNKNOWN | PYTHON3 | CODEFORCES | 167 | |
9627272d7a247485f14cbdc34d6bfddf | Insertion Sort | Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array *a* of size *n* in the non-d... | [
"arr = [0 for i in range(5001)]\r\n\r\n\r\ndef insertion_sort(n, a):\r\n def modify(t):\r\n while t > 0:\r\n arr[t] += 1\r\n t -= t & (-t)\r\n\r\n def query(t):\r\n res = 0\r\n while t < 5001:\r\n res += arr[t]\r\n t += t & (-t)\r\n retur... | {"inputs": ["5\n4 0 3 1 2", "5\n1 2 3 4 0", "5\n1 3 4 0 2", "10\n9 8 7 6 5 4 3 2 1 0", "5\n0 4 1 3 2", "6\n3 0 1 4 5 2", "3\n0 2 1", "3\n1 0 2", "3\n1 2 0", "3\n2 0 1", "3\n2 1 0", "7\n4 0 3 5 1 2 6", "8\n1 5 4 0 2 7 3 6", "9\n1 5 6 3 0 7 2 8 4", "10\n8 6 7 9 4 5 2 3 1 0", "11\n4 9 1 2 8 5 10 3 0 7 6", "12\n2 7 0 1 3 1... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
962cab700bb813622b48938f5c54d8b8 | Little Pony and Sort by Shift | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | [
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nc=0\r\nind=-1\r\nfor i in range(1,n):\r\n if a[i]<a[i-1]:\r\n c+=1\r\n s=i\r\nif c==0:\r\n print(0)\r\nelif a[0]>=a[n-1]and c==1:\r\n print(n-s)\r\nelse:\r\n print(-1)",
"n = int(input())\r\narr = list(map(int, input().split()))\r... | {"inputs": ["2\n2 1", "3\n1 3 2", "2\n1 2", "6\n3 4 5 6 3 2", "3\n1 2 1", "5\n1 1 2 1 1", "4\n5 4 5 4", "7\n3 4 5 5 5 1 2", "5\n2 2 1 2 2", "5\n5 4 1 2 3", "4\n6 1 2 7", "5\n4 5 6 2 3", "2\n1 1", "4\n1 2 2 1", "9\n4 5 6 7 1 2 3 4 10", "7\n2 3 4 1 2 3 4", "6\n1 2 1 2 1 2", "3\n3 2 1", "4\n1 4 4 1", "5\n1 2 1 1 1", "5\n4... | UNKNOWN | PYTHON3 | CODEFORCES | 157 | |
963d940c5ad407f2d78a56605af11390 | s-palindrome | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | [
"t = input()\nk = len(t) // 2 + 1\np = zip(t[:k], t[-k:][::-1])\nu, v = 'AHIMOoTUVvWwXxY', 'bd db pq qp'\ns = all(a in u and a == b or a + b in v for a, b in p)\nprint(['NIE', 'TAK'][s])\n\t\t\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t \t\t \t\t \t",
"from string import ascii_lowercase as lowercase\r\nfrom string impo... | {"inputs": ["oXoxoXo", "bod", "ER", "o", "a", "opo", "HCMoxkgbNb", "vMhhXCMWDe", "iIcamjTRFH", "WvoWvvWovW", "WXxAdbAxXW", "vqMTUUTMpv", "iii", "AAWW", "ss", "i", "ii", "mm", "LJ", "m", "ioi", "OA", "aaaiaaa", "SS", "iiii", "ssops", "ssss", "ll", "s", "bb", "uu", "ZoZ", "mom", "uou", "u", "JL", "mOm", "llll", "ouo", "a... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
969194bd9a4c52b927170f6878291c44 | Alyona and a tree | Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).
Let's define *dist*(*v*,<=*u*) as the ... | [
"import sys\r\nimport threading\r\nfrom bisect import *\r\nfrom itertools import *\r\n \r\n \r\n#def ri():\r\n# return map(int, input().split())\r\n \r\n \r\ndef dfs(v):\r\n global d\r\n d += 1\r\n dist[d] = w[v] + dist[d-1]\r\n add[d] = 0\r\n for i in c[v]:\r\n dfs(i)\r\n x = bisect_lef... | {"inputs": ["5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6", "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1", "1\n1", "2\n1 1\n1 1", "10\n40 77 65 14 86 16 2 51 62 79\n1 75\n10 86\n3 52\n6 51\n10 8\n3 61\n3 53\n5 98\n2 7", "10\n52 1 84 16 59 26 56 74 52 97\n5 7\n7 13\n3 98\n7 22\n7 19\n9 54\n4 45\n10 95\n1 94", "10\n68 29 12 14 27 47 95 100 45 ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
9699caf9749110b5eef0cc68b28787b8 | Phone Numbers | Winters are just damn freezing cold in Nvodsk! That's why a group of *n* friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size *s**i* (that's the number of phone numbers). We know that tax... | [
"n = int(input())\n\n#taxi, pizza, girl\nall = [[], [], []]\nnames = []\n\nfor i in range(n):\n s, name = input().split(\" \")\n\n s = int(s)\n names.append(name)\n\n taxi = 0\n pizza = 0\n girl = 0\n\n for ii in range(s):\n phone = [i for i in input().split(\"-\")]\n phone = list... | {"inputs": ["4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "3\n5 Gleb\n66-66-66\n55-55-55\n01-01-01\n65-43-21\n12-34-56\n3 Serega\n55-55-55\n87-65-43\n65-55-21\n5 M... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
969d32200550fa6d7a135e41aecf0436 | A Shade of Moonlight | "To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino.
"See? The clouds are coming." Kanno gazes into the distance.
"That can't be better," Mino turns to Kanno.
The sky can be seen as a one-dimensional axis. The moon is at the origin whose ... | [
"# Codeforces Round #487 (Div. 2)import collections\r\nfrom functools import cmp_to_key\r\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\r\n\r\nimport sys\r\ndef getIntList():\r\n return list(map(int, input().split())) \r\nimport bisect\r\n \r\n \r\n \r\nN,L,WM = getIntList()\r\n\r... | {"inputs": ["5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1", "4 10 1\n-20 1\n-10 -1\n0 1\n10 -1", "1 100000000 98765432\n73740702 1", "10 2 3\n-1 -1\n-4 1\n-6 -1\n1 1\n10 -1\n-8 -1\n6 1\n8 1\n4 -1\n-10 -1", "3 100000000 100000000\n-100000000 1\n100000000 1\n0 -1", "9 25000000 989\n-100000000 -1\n-75000000 1\n75000000 1\n50000000 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
96bbc0ea662787e4b8d5f40b8789dc18 | Big Number and Remainder | Stepan has a very big positive integer.
Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203... | [
"n=input()\r\nm=int(input())\r\n\r\nres=0\r\npw=1\r\nfor i in range(len(n)-1, -1, -1):\r\n res=(res+pw*int(n[i]))%m\r\n if (i>0):\r\n pw=(pw*10)%m\r\n\r\npartial=res\r\nfor x in n:\r\n if (int(x)!=0):\r\n res=min(res, partial)\r\n partial=(partial-int(x)*pw)%m\r\n partial=(partial*10+in... | {"inputs": ["521\n3", "1001\n5", "5678901234567890123456789\n10000", "552352155\n13", "11533077525260\n193983", "15\n19", "2342341\n2342340", "12345\n12344", "23457\n23456", "79\n60847671", "456\n79575973", "1908\n86567928", "30866\n55357692", "980552\n32506042", "4865180\n11799246", "63014535\n5261418", "260597722\n10... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
96cafaf521d87be7591992062831ec4a | Fibonacci String Subsequences | You are given a binary string *s* (each character of this string is either 0 or 1).
Let's denote the cost of string *t* as the number of occurences of *s* in *t*. For example, if *s* is 11 and *t* is 111011, then the cost of *t* is 3.
Let's also denote the Fibonacci strings sequence as follows:
- *F*(0) is 0;- *F*(... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u * n + v\r\n\r\nn, x = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\ns = list(input().rstrip())\r\nm = 105\r\ninv2 = pow(2, mod - 2, mod)\r\nfib = [1, 1]\r\np = [2, 2]\r\nip = [inv2, inv2]\r... | {"inputs": ["2 4\n11", "10 100\n1010101010", "10 5\n0110111100", "100 100\n0001010101110010010100111011010101101111110001101101010111011101010000111000110001111010001001000001", "50 50\n00011100010110111111011100101010000001101001001001", "100 50\n011011001111111001000000010101011001100101110000001011010011000000011100... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
9710337c757d2ca9a64081eb24308f7e | Collisions | On a number line there are *n* balls. At time moment 0 for each ball the following data is known: its coordinate *x**i*, speed *v**i* (possibly, negative) and weight *m**i*. The radius of the balls can be ignored.
The balls collide elastically, i.e. if two balls weighing *m*1 and *m*2 and with speeds *v*1 and *v*2 col... | [
"import sys\r\nfrom math import isclose\r\n \r\nEPSILON = 1e-9\r\n \r\ndef main():\r\n n, t = map(float, input().split())\r\n n = int(n)\r\n \r\n data = []\r\n for _ in range(n):\r\n x, v, m = map(float, input().split())\r\n data.append([x, v, m])\r\n while True:\r\n tmin = 99... | {"inputs": ["2 9\n3 4 5\n0 7 8", "3 10\n1 2 3\n4 -5 6\n7 -8 9", "6 76\n-35 -79 86\n-76 -20 64\n-91 79 10\n12 25 51\n62 6 30\n8 -14 65", "5 69\n-34 28 72\n54 59 51\n65 42 95\n75 1 59\n99 76 54", "5 65\n58 73 74\n98 85 95\n92 94 96\n66 100 79\n44 80 95", "5 10\n-98 -98 1\n-100 -100 1\n-99 -100 2\n-97 -100 1\n-95 -100 1",... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
9745559fd17c5609447524b4da506f1e | History | Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the Wo... | [
"import sys\r\nfrom math import log2,floor,ceil,sqrt,gcd\r\nimport bisect\r\n# from collections import deque\r\nsys.setrecursionlimit(10**5)\r\n\r\nRi = lambda : [int(x) for x in sys.stdin.readline().split()]\r\nri = lambda : sys.stdin.readline().strip()\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\nde... | {"inputs": ["5\n1 10\n2 9\n3 8\n4 7\n5 6", "5\n1 100\n2 50\n51 99\n52 98\n10 60", "1\n1 1000000000", "2\n100 1000\n500 1500", "4\n1 100\n50 150\n120 200\n180 220", "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11", "4\n1 5\n2 4\n10 15\n11 14", "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 53 | |
976830fcfcbc9f7cde317a03dd5b5af3 | Widget Library | Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.
A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on t... | [
"#bobwish(md)\r\nimport re\r\n\r\ndef size(name):\r\n global d\r\n if len(d[name]) == 4:\r\n type, children, border, spacing = d[name]\r\n if not children:\r\n d[name] = (0, 0)\r\n else:\r\n ww, hh = zip(*map(size, children))\r\n b, s = 2 * border, spacing... | {"inputs": ["12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrandpa.pack(uncle)", "15\nWidget pack(10,10)\nHBox dummy\nHBox x\nVBox y\ny.pack... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
9769c0ef0e25d8db168cae2e27ac7268 | Visiting a Friend | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | [
"n, finish = map(int, input().split())\r\n\r\nend_interval = [0, finish]\r\n\r\npoints = []\r\n\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n points.append([x, y])\r\n\r\npoints.sort()\r\n#print(points)\r\nmerge_interval = [points[0][0], points[0][1]]\r\nfor i in range(1, n):\r\n if merge_... | {"inputs": ["3 5\n0 2\n2 4\n3 5", "3 7\n0 4\n2 5\n6 7", "1 1\n0 0", "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10", "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70... | UNKNOWN | PYTHON3 | CODEFORCES | 144 | |
9799386063eac39226d7076d5e2ace6a | Chicken or Fish? | Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat *m*, that means, he will be the *m*-th person to get food.
The flight menu has *k* dishe... | [
"t = int(input())\r\nfor j in range(t):\r\n e = input()\r\n m, k = map(int, input().split())\r\n arr = [int(i) for i in input().split()]\r\n sum, bfail = [0] * k, [0] * k\r\n ffail, undef = -1, 0\r\n used = [False] * k\r\n ubfail = 0\r\n for i in range(m - 1):\r\n c, ns = map(int, inp... | {"inputs": ["2\n\n3 4\n2 3 2 1\n1 0\n0 0\n\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "4\n\n2 1\n42\n0 0\n\n2 1\n2\n0 0\n\n2 1\n42\n1 0\n\n2 1\n2\n1 0", "5\n\n3 3\n1 1 1\n0 0\n0 1\n\n3 3\n1 1 1\n1 0\n2 1\n\n3 3\n1 1 1\n1 0\n0 1\n\n3 3\n1 1 1\n0 0\n1 0\n\n3 3\n1 1 1\n0 0\n1 1", "1\n\n4 2\n2 2\n0 0\n0 0\n1 1"], "outputs": ["Y... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
97b0be7ad7045d8184a85d460fdf44f0 | The Game Of Parity | There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly *k* cities l... | [
"n, k = map(int, input().split())\no = sum(int(x) & 1 for x in input().split())\ne, k = n - o, n - k\nif not k:\n w = o & 1\nelif k & 1:\n if ((n - k) & 1) and o <= (k >> 1):\n w = 0\n elif min(o, e) <= (k >> 1) and not ((n - k) & 1):\n w = 0\n else:\n w = 1\nelif ((n - k) & 1) and ... | {"inputs": ["3 1\n1 2 1", "3 1\n2 2 1", "6 3\n5 20 12 7 14 101", "6 3\n346 118 330 1403 5244 480", "7 4\n11 3532 99 3512 12 8 22", "9 4\n2 6 8 1 2 4 2 8 2", "8 2\n1 3 22 45 21 132 78 901", "1 1\n912959", "1 1\n107540", "2 2\n67427 727097", "2 2\n346010 923112", "2 2\n125572 610583", "3 3\n198331 216610 697947", "3 3\n3... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
97e64e857002b4868d4b906fbfc1c164 | Kirill And The Game | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | [
"\r\ndef play(l,r,x,y,k):\r\n for i in range(x,y+1):\r\n if l<=i*k<=r:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\nl,r,x,y,k=map(int,input().split())\r\nprint(play(l,r,x,y,k))\r\n",
"l,r,x,y,k=[int(x) for x in input().split()]\r\nflag=0\r\nfor i in range(x,y+1):\r\n\tif k*i<=r and k*i>=l:\... | {"inputs": ["1 10 1 10 1", "1 5 6 10 1", "1 1 1 1 1", "1 1 1 1 2", "1 100000 1 100000 100000", "1 100000 1 100000 100001", "25 10000 200 10000 5", "1 100000 10 100000 50000", "91939 94921 10197 89487 1", "30518 58228 74071 77671 1", "46646 79126 78816 91164 5", "30070 83417 92074 99337 2", "13494 17544 96820 99660 6", ... | UNKNOWN | PYTHON3 | CODEFORCES | 91 | |
97eae29cb6754e68b288718743c9be45 | Elevator | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | [
"fi = open('input.txt', 'r')\r\nd, a = fi.readline().strip() == 'front', int(fi.readline()) == 1\r\nprint('L' if d == a else 'R', file=open('output.txt', 'w'))",
"f = open(\"input.txt\", mode=\"r\")\r\nentered, holding = f.read().split()\r\nf.close()\r\nresult = {\"front\": \"1\", \"back\": \"2\"}\r\nf = open(\"o... | {"inputs": ["front\n1", "back\n1", "front\n2", "back\n2"], "outputs": ["L", "R", "R", "L"]} | UNKNOWN | PYTHON3 | CODEFORCES | 64 | |
9801dff0e17270152bbd2e68913fa259 | Parallelogram is Back | Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis... | [
"import math\r\n\r\ndef rl():\r\n return list(map(int,input().split()))\r\n\r\ndef ri():\r\n return int(input())\r\n\r\npt=[]\r\n\r\nfor i in range(3):\r\n a,b=rl()\r\n pt.append((a,b))\r\n\r\n\r\nans=[]\r\n\r\nans.append((pt[0][0]+(pt[2][0]-pt[1][0]),(pt[0][1]+(pt[2][1]-pt[1][1]))))\r\nans.append((pt[0... | {"inputs": ["0 0\n1 0\n0 1", "0 -1\n-1 0\n1 1", "-1 -1\n0 1\n1 1", "1000 1000\n-1000 -1000\n-1000 1000", "-1000 1000\n1000 -1000\n-1000 -1000", "-4 -5\n7 10\n3 -10", "-86 25\n-55 18\n58 24", "-301 -397\n192 317\n-98 729", "1000 1000\n999 1000\n-1000 -1000", "-1000 0\n999 0\n1000 1", "-1000 1000\n1000 -1000\n0 1", "1000... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
9819394579ff3ea1f184690cb479a47b | Getting an A | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | [
"from sys import *\r\n\r\ndef main():\r\n n = int(stdin.readline())\r\n target = 4.5*n\r\n currentTotal = 0\r\n minimumRetakes = 0\r\n listOfScores = [int(x) for x in stdin.readline().split()]\r\n for x in listOfScores:\r\n currentTotal+=x\r\n listOfScores.sort()\r\n while(currentTota... | {"inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5", "1\n5", "4\n3 2 5 4", "5\n5 4 3 2 5", "8\n5 4 2 5 5 2 5 5", "5\n5 5 2 5 5", "6\n5 5 5 5 5 2", "6\n2 2 2 2 2 2", "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 ... | UNKNOWN | PYTHON3 | CODEFORCES | 224 | |
9819cf7a2ee1577fa2b11b9f03e019a4 | Fire | Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take *t**i* seconds to save *i*-th item. In addition, for each item, he estimated the value of *d**i* — the moment after which the item *i* will be completely burned and will no long... | [
"n = int(input())\na = []\nfor i in range(n):\n t,d,p = map(int,input().split())\n a.append([t,d,p,i+1])\na.sort(key = lambda x: x[1])\nd = {0: [0,[]]}\nfor i in a:\n e = {}\n for j in d:\n if d[j][0] + i[0] < i[1]:\n if j + i[2] in d:\n if d[j][0]+i[0] < d[j+i[2]][0]:\n... | {"inputs": ["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5", "9\n13 18 14\n8 59 20\n9 51 2\n18 32 15\n1 70 18\n14 81 14\n10 88 16\n18 52 3\n1 50 6", "5\n12 44 17\n10 12 11\n16 46 5\n17 55 5\n6 60 2", "6\n18 85 3\n16 91 20\n12 92 11\n20 86 20\n15 43 4\n16 88 7", "2\n12 13 2\n1 9 3", "3\n14 42 16\n13 40 1\n17 33 5", "4\n5 6 ... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
981ad6fb86d3e2ed5c0d84780498119a | Magic, Wizardry and Wonders | Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into... | [
"r=[]\r\nn,d,l=map(int,input().split())\r\nfor i in range(1,n):\r\n k=1 if d<=0 else l\r\n r.append(k)\r\n d=k-d\r\nif 1<=d<=l:print(*r+[d])\r\nelse:print(-1)"
] | {"inputs": ["3 3 2", "5 -4 3", "5 -4 4", "2 0 10", "5 2 2", "7 -24 10", "7 -35 10", "10 5 3", "10 -39 10", "15 -639 100", "15 852 100", "20 -179 29", "20 97 13", "25 19 49", "25 1 1", "40 336 83", "40 -1600 85", "40 -1039 73", "40 -118 32", "50 231 39", "50 -357 68", "60 -728 29", "60 -2772 94", "70 1980 84", "70 2335 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
981eab65f82a30b1d20451a60a794f8a | Registration System | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | [
"x = int(input())\r\na = {}\r\nfor i in range(x):\r\n\ts = input()\r\n\tif(s in a):\r\n\t\ta[s]+=1\r\n\t\tprint(s+str(a[s]))\r\n\telse:\r\n\t\ta[s]=0\r\n\t\tprint(\"OK\")",
"n = int(input())\r\nx = {}\r\nfor i in range(0, n):\r\n y = input()\r\n if y in x:\r\n print(y+str(x[y]))\r\n x[y] += 1\... | {"inputs": ["4\nabacaba\nacaba\nabacaba\nacab", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "1\nn", "2\nu\nu", "3\nb\nb\nb", "2\nc\ncn", "3\nvhn\nvhn\nh", "4\nd\nhd\nd\nh", "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "10\nfpqhfouqdldravpjttarh... | UNKNOWN | PYTHON3 | CODEFORCES | 121 | |
98290b55151aee048bb03b44cf19df7d | Polyline | There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p... | [
"def mid(a,b,c):\r\n return c>=max(a,b) or c<=min(a,b)\r\n \r\nx1,y1=list(map(int,input().split()))\r\nx2,y2=list(map(int,input().split()))\r\nx3,y3=list(map(int,input().split()))\r\nif x1==x2==x3 or y1==y2==y3:\r\n print(1)\r\nelse:\r\n # if x1==x2 and (y1==y3 or y2==y3):\r\n # print(2)\r\n #... | {"inputs": ["1 -1\n1 1\n1 2", "-1 -1\n-1 3\n4 3", "1 1\n2 3\n3 2", "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000", "-510073119 -991063686\n583272581 -991063686\n623462417 -991063686", "-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611", "127447697 -311048187\n-644646254 13509... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
982db9310bb856cf377fea26d0673d07 | Bear and Game | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | [
"n=int(input())\r\ntl = list(map(int, input().split()))\r\ntime=cnt=0\r\nwhile cnt <15 and time<90:\r\n time+=1\r\n if tl.count(time)>0:\r\n cnt=0\r\n else:\r\n cnt+=1\r\nprint(time)",
"number = int(input())\r\nlist_array = str(input())\r\n\r\nlist_array = list_array.split()\r\nlist_array =... | {"inputs": ["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90", "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 6... | UNKNOWN | PYTHON3 | CODEFORCES | 251 | |
98428c5ad10009f3b2425646949f8bd0 | Army | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | [
"a = int(input())\r\nb = list(map(int,input().split()))\r\nc , d = list(map(int,input().split()))\r\ncount = 0\r\nfor i in range(c,d):\r\n count += b[i-1]\r\nprint(count)\r\n",
"import math\r\nimport sys\r\nimport itertools\r\n\r\ndef sa(Type= int):\r\n return [Type(x) for x in input().split()]\r\n\r\ndef sol... | {"inputs": ["3\n5 6\n1 2", "3\n5 6\n1 3", "2\n55\n1 2", "3\n85 78\n1 3", "4\n63 4 49\n2 3", "5\n93 83 42 56\n2 5", "6\n22 9 87 89 57\n1 6", "7\n52 36 31 23 74 78\n2 7", "8\n82 14 24 5 91 49 94\n3 8", "9\n12 40 69 39 59 21 59 5\n4 6", "10\n95 81 32 59 71 30 50 61 100\n1 6", "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n... | UNKNOWN | PYTHON3 | CODEFORCES | 511 | |
986f9fb53383c1c7cdfc5b771aaddf74 | Champions' League | In the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play in the group stage and are fighting for advancing to the playoffs. In this problem we are interested in the dr... | [
"import sys\r\nsys.stdin = open(\"input.txt\")\r\nsys.stdout = open(\"output.txt\",'w')\r\n\r\nn = int(input())\r\nm = n//4\r\nx, a, b, c = map(int, input().split())\r\ng = sorted([(int(j), i) for i, j in [input().split() for _ in range(n)]], reverse=1)\r\nw1, w2, w3, w4 = g[:m].copy(), g[m:2*m].copy(), g[2*m:3*m].... | {"inputs": ["8\n1 3 1 7\nBarcelona 158\nMilan 90\nSpartak 46\nAnderlecht 48\nCeltic 32\nBenfica 87\nZenit 79\nMalaga 16", "4\n777 556 763 235\nkRnl 221\nSnxtrev 981\nBAaxtAFAyfYKea 390\nfFZFDYLJSweUcSTo 786", "8\n901 45 13 488\nOsIigEKvzr 17\nigyDhJRjjWEKyCcj 636\nEWy 744\njEvkGATY 856\nXoAReWWsizfhgghKVwce 48\nQJhC 31... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
988518cdbf5addd85b86b7c5d7c38a55 | Police Recruits | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | [
"num = int(input())\r\nnumber = list(map(int,input().split()))\r\ncounter = 0\r\nnumber_poles = 0\r\nfor i in range(len(number)):\r\n if number[i] == -1 and number_poles == 0:\r\n counter += 1\r\n elif number[i] == -1 and number_poles > 0:\r\n number_poles -= 1\r\n else:\r\n number_pol... | {"inputs": ["3\n-1 -1 1", "8\n1 -1 1 -1 -1 1 1 1", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "7\n-1 -1 1 1 -1 -1 1", "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5", "98\n-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 ... | UNKNOWN | PYTHON3 | CODEFORCES | 729 | |
98e429fa33b03d323cd886e28f35b819 | Journey | The territory of Berland is represented by a rectangular field *n*<=×<=*m* in size. The king of Berland lives in the capital, located on the upper left square (1,<=1). The lower right square has coordinates (*n*,<=*m*). One day the king decided to travel through the whole country and return back to the capital, having ... | [
"def d(a, b):\n\n print(a+1, b)\n\n return (a+1, b)\n\n\n\n\n\ndef u(a, b):\n\n print(a-1, b)\n\n return (a-1, b)\n\n\n\ndef l(a, b):\n\n print(a, b-1)\n\n return (a, b-1)\n\n\n\ndef r(a, b):\n\n print(a, b+1)\n\n return (a, b+1)\n\n\n\n\n\na, b = map(int, input().split(' '))\n\n\n\nif a == ... | {"inputs": ["2 2", "3 3", "3 2", "2 3", "3 4", "6 3", "4 3", "1 2", "1 3", "1 99", "1 100", "2 1", "3 1", "99 1", "100 1", "8 97", "2 4", "2 99", "2 100", "4 2", "99 2", "100 2", "100 100", "99 100", "99 99", "100 99", "33 81", "11 17", "36 1", "62 85", "39 69", "64 5", "90 89", "67 73", "40 75", "10 13", "33 51", "4 3... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
98ff04c41ab2c760488c41a7659953ac | Balloons | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi... | [
"n = int(input())\r\narr = list(map(int, input().split()))\r\nif n == 1:\r\n\tprint(-1)\r\n\texit(0)\r\nz = 0\r\nfor i in range(n):\r\n\tif arr[i] < arr[z]:\r\n\t\tz = i\r\nif arr[z] != sum(arr) - arr[z]:\r\n\tprint(1)\r\n\tprint(z + 1)\r\nelse:\r\n\tprint(-1)",
"n = int(input())\na = list(map(int, input().split(... | {"inputs": ["3\n1 2 1", "2\n5 5", "1\n10", "1\n1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 1 1 1 1 9", "10\n26 723 970 13 422 968 875 329 234 983", "3\n3 2 1", "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "10\n1 9 7 6 2 4 7 8 1 3", "2\n9 6", "2\n89 7", "2\n101 807", "5\n8 7 4 8 3", "5\n55 62 70 100 90", "... | UNKNOWN | PYTHON3 | CODEFORCES | 128 | |
99180e3f5c7972631604d2137406cd36 | Where do I Turn? | Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages.
A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight... | [
"xa,ya = input().split()\r\nxa = int(xa)\r\nya = int(ya)\r\n\r\nxb,yb = input().split()\r\nxb = int(xb)\r\nyb = int(yb)\r\n\r\nxc,yc = input().split()\r\nxc = int(xc)\r\nyc = int(yc)\r\n\r\nvab_x = xb-xa\r\nvab_y = yb-ya\r\n\r\nvbc_x = xc - xb\r\nvbc_y = yc - yb\r\n\r\nproduto_vetorial = (vab_x * vbc_y) - (vab_y * ... | {"inputs": ["0 0\n0 1\n1 1", "-1 -1\n-3 -3\n-4 -4", "-4 -6\n-3 -7\n-2 -6", "-44 57\n-118 -41\n-216 33", "39 100\n90 85\n105 136", "71 43\n96 -15\n171 -189", "-22 -84\n-117 8\n-25 103", "28 -81\n49 -85\n45 -106", "-20 -60\n-39 -45\n-24 -26", "-61 -24\n-61 35\n-120 35", "-19 27\n-115 -63\n-25 -159", "53 69\n147 114\n102 ... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
991dc0448b712b255c88c42f60d3010d | Way Too Long Words | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | [
"n = int(input(\"\"))\r\n\r\nfor a in range(0,n):\r\n string = input(\"\")\r\n if len(string)>10:\r\n slice = string[0] + str(len(string)-2) +string[-1]\r\n print(slice)\r\n else:\r\n print(string)",
"def main():\r\n t = int(input())\r\n \r\n for i in range(t):\r\n wo... | {"inputs": ["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "24\nyou\nare\nregi... | UNKNOWN | PYTHON3 | CODEFORCES | 2,022 | |
992794c9fddefcc7b1bcf7a5d6bb48ef | Substitutes in Number | Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10... | [
"MOD = 10**9+7\r\n\r\ns = input()\r\nn = int(input())\r\nqs = [['',s]]+[input().split('->') for i in range(n)]\r\n\r\nds = {}\r\nfor i in range(10):\r\n ds[str(i)] = (10,i)\r\n\r\nfor i in range(n,-1,-1):\r\n out = 0\r\n mul = 1\r\n for d in qs[i][1]:\r\n out = (out * ds[d][0] + ds[d][1]) % MOD\r... | {"inputs": ["123123\n1\n2->00", "123123\n1\n3->", "222\n2\n2->0\n0->7", "1000000008\n0", "100\n5\n1->301\n0->013\n1->013\n0->103\n0->103", "21222\n10\n1->\n2->1\n1->1\n1->1\n1->1\n1->22\n2->2\n2->1\n1->21\n1->", "21122\n10\n1->\n2->12\n1->\n2->21\n2->\n1->21\n1->\n2->12\n2->\n1->21", "7048431802\n3\n0->9285051\n0->7854... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
9929caf2ab82e2bcb6a1a7d2f22a5c35 | Jzzhu and Chocolate | Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit... | [
"import math\r\nn,m,k=map(int,input().split())\r\nif k>n+m-2 :\r\n print(-1)\r\n exit()\r\nif n%(k+1)==0 :\r\n print(int(n/(k+1))*m)\r\n exit()\r\nif m%(k+1)==0 :\r\n print(int(m/(k+1))*n)\r\n exit()\r\nr=max(n//(k+1),1)\r\nr1=max(0,k-n+1)\r\nr2=m//(1+r1)\r\nans=r*r2\r\nr=max(m//(k+1),1)\r\nr1=max... | {"inputs": ["3 4 1", "6 4 2", "2 3 4", "10 10 2", "1000000000 1000000000 2000000000", "1000000000 1000000000 999999999", "1000000000 1000000000 1", "98283 999283848 23", "6 4 5", "6 4 6", "482738478 493948384 502919283", "1 1 1", "1 1 2", "1 1 1000000000", "1000000000 1000000000 123456", "192837483 829387483 828374", "... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
9938d8d14c5798896320ef4e314adf96 | Constellation | Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would lik... | [
"f = lambda: list(map(int, input().split()))\r\nd = lambda x, y: (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2\r\nr = lambda x, y, z: (x[0] - y[0]) * (x[1] - z[1]) == (x[1] - y[1]) * (x[0] - z[0])\r\n\r\nn = int(input())\r\nt = [f() for i in range(n)]\r\n\r\nj = k = -1\r\nb = c = 0\r\n\r\nx = t.pop()\r\nfor i in range(n ... | {"inputs": ["3\n0 1\n1 0\n1 1", "5\n0 0\n0 2\n2 0\n2 2\n1 1", "3\n819934317 939682125\n487662889 8614219\n-557136619 382982369", "10\n25280705 121178189\n219147240 -570920213\n-829849659 923854124\n18428128 -781819137\n-876779400 528386329\n-780997681 387686853\n-101900553 749998368\n58277314 355353788\n732128908 33641... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
993d6fdfa3a88ca40146880e02e2c72b | On Corruption and Numbers | Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w... | [
"t = int(input())\r\nfor i in range(0, t) :\r\n n, l, r = [int(s) for s in input().split()]\r\n print('Yes' if n % l <= (r - l) * (n // l) else 'No')",
"T=int(input())\nwhile T>0:\n T-=1\n n,l,r=map(int,input().split())\n t = n//l\n if t*r>=n:\n print(\"Yes\")\n else:\n print(\... | {"inputs": ["2\n5 2 3\n6 4 5", "50\n69 6 6\n22 1 1\n23 3 3\n60 13 13\n13 3 3\n7 4 7\n6 1 1\n49 7 9\n68 8 8\n20 2 2\n34 1 1\n79 5 5\n22 1 1\n77 58 65\n10 3 3\n72 5 5\n47 1 1\n82 3 3\n92 8 8\n34 1 1\n42 9 10\n63 14 14\n10 3 3\n38 2 2\n80 6 6\n79 5 5\n53 5 5\n44 7 7\n85 2 2\n24 2 2\n57 3 3\n95 29 81\n77 6 6\n24 1 1\n33 4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
993f91f4cbd61f99613fae57418483be | Find Extra One | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points.... | [
"n = int(input())\r\np , nn = 0 ,0\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n if x > 0:\r\n p += 1\r\n else:\r\n nn += 1\r\nif p > 1 and nn > 1:\r\n print('NO')\r\nelif p <= 1 or nn <= 1:\r\n print('YES')",
"n = int(input())\ncnt_pos, cnt_neg = 0, 0\nfor i in range(n... | {"inputs": ["3\n1 1\n-1 -1\n2 -1", "4\n1 1\n2 2\n-1 1\n-2 2", "3\n1 2\n2 1\n4 60", "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "2\n1000000000 -1000000000\n1000000000 1000000000", "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\... | UNKNOWN | PYTHON3 | CODEFORCES | 326 | |
9940523d0a61cbefac6cca3bfb153524 | Road Construction | A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two... | [
"import math\r\nimport sys\r\nfrom collections import defaultdict\r\nfrom collections import Counter\r\nfrom collections import deque\r\nimport bisect\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split())... | {"inputs": ["4 1\n1 3", "1000 0", "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414", "150 3\n112 30\n61 45\n37 135", "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26", "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 147 | |
994b1e0697ee33aebcde79386eb21727 | Dubstep | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | [
"s = input()\r\nfor x in s.split('WUB'):\r\n if ((x != ' ') and (x != '')):\r\n print(x,end=' ')\r\n",
"s=input()\r\ni=0\r\nwhile i<len(s):\r\n\tif s[i:i+3] == \"WUB\":\r\n\t\ti+=3\r\n\telse:\r\n\t\tj=i\r\n\t\twhile s[i:i+3]!=\"WUB\" and i<len(s) :\r\n\t\t\ti+=1\r\n\t\tprint(s[j:i])\r\n",
"s = input()... | {"inputs": ["WUBWUBABCWUB", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "WUBWUBWUBSR", "RWUBWUBWUBLWUB", "ZJWUBWUBWUBJWUBWUBWUBL", "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB... | UNKNOWN | PYTHON3 | CODEFORCES | 920 | |
996a30e84b4a1eb1cd09d6828c181d80 | Reading | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very lig... | [
"F=open('input.txt','r')\nW=open('output.txt','w')\nI=lambda:map(int,F.readline().split())\nn,k=I()\na=sorted(zip(I(),range(n)))[::-1]\nW.write(str(a[k-1][0])+'\\n'+' '.join(map(str,[y+1 for x,y in a[:k]])))\nW.close()\n\t \t \t\t\t\t \t \t\t \t\t \t \t\t \t \t\t\t",
"with open('input.txt', 'r') as rf:\n n... | {"inputs": ["5 3\n20 10 30 40 10", "6 5\n90 20 35 40 60 100", "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49... | UNKNOWN | PYTHON3 | CODEFORCES | 63 | |
99764cd15d549cee60f585eed483e8f7 | Extra-terrestrial Intelligence | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | [
"ip = open(\"input.txt\", \"r\")\nop = open(\"output.txt\", \"w\")\nn = int(ip.readline())\nsignals = ip.readline()\nsigs = 0\nsignallen = len(signals)\nans = True\nfor i in range(signallen):\n\tif signals[i] == '1':\t\n\t\tif sigs == 0:\n\t\t\tsigs = 1\n\t\t\tprev = i\n\t\telse:\n\t\t\tif sigs == 1:\n\t\t\t\tdista... | {"inputs": ["8\n00111000", "7\n1001011", "7\n1010100", "5\n10101", "3\n111", "10\n0011111011", "12\n001010101010", "25\n1000000010000000100000001", "30\n111110111101110111111111111111", "50\n00101010101010101010101010101010101010101010101010", "60\n000000000000000000100001000000001000000001000000001000000001", "66\n000... | UNKNOWN | PYTHON3 | CODEFORCES | 47 | |
99802e27d1bad6aec23dda7b6149fe4c | Mahmoud and Ehab and the binary string | Mahmoud and Ehab are in the fourth stage now.
Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr... | [
"\"\"\"http://codeforces.com/problemset/problem/862/D\"\"\"\nimport sys\n\ndef flip(word, l, p, x):\n \"\"\" Puts x-es at indexes l-p inside word if the indexes are within\n the word boundaries. Otherwise return the same word\"\"\"\n if l in range(len(word)) and p in range(len(word)):\n return word[... | {"inputs": ["101", "0011001100", "01", "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101", "110010011001010100101010001101110010010111001110111110011011111111000110... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
9982ea1d5352957c03052d5ba42f8e98 | Magic Numbers | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
The first line of input contains an integ... | [
"s = input()\r\n\r\nflag = 1\r\np = ''\r\n\r\nif(s[0] != '1'):\r\n\tprint('NO')\r\nelse:\r\n\tfor i in range(len(s)):\r\n\t\tif( s[i] == '4' and ((i>=1 and s[i-1] != '1') and (i>=2 and s[i-2:i] != '14'))):\r\n\t\t\tflag = 0\r\n\t\t\tbreak\r\n\t\tif(s[i] != '4' and s[i] != '1'):\r\n\t\t\tflag = 0\r\n\t\t\tbreak\r\n\... | {"inputs": ["114114", "1111", "441231", "1", "14", "114", "9", "414", "1000000000", "144144144", "1444", "11", "141414141", "11110111", "114114144", "444", "9999", "111444", "11114", "41111", "114414441", "144414441", "144244144", "111111111", "144444444", "444444444", "141441441", "441", "15", "14444", "11444", "144",... | UNKNOWN | PYTHON3 | CODEFORCES | 371 | |
999bf32199374ef5363fd5cc2c649a9c | Pashmak and Garden | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | [
"#https://codeforces.com/contest/459/problem/A\r\nx1,y1,x2,y2 = [int(elem) for elem in input().split()]\r\n\r\nif y1 == y2:\r\n print(x1, y1+(x2-x1), x2, y2+(x2-x1))\r\nelif x1 == x2:\r\n print(x1+(y2-y1), y1, x2+(y2-y1), y2)\r\nelif abs(y2 - y1) != abs(x2 - x1):\r\n print(-1)\r\nelse:\r\n print(x1,y2,x... | {"inputs": ["0 0 0 1", "0 0 1 1", "0 0 1 2", "-100 -100 100 100", "-100 -100 99 100", "0 -100 0 100", "27 -74 27 74", "0 1 2 3", "-100 100 100 -100", "-100 -100 -100 100", "100 100 100 -100", "100 -100 -100 -100", "-100 100 100 100", "0 1 0 0", "1 1 0 0", "0 0 1 0", "1 0 0 1", "1 0 1 1", "1 1 0 1", "15 -9 80 -9", "51 -... | UNKNOWN | PYTHON3 | CODEFORCES | 109 | |
999ed308e5a618b42a0af19a99615fa4 | Hidden Word | Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:
We say that two tiles are adjacent if they share a side or a corn... | [
"from collections import Counter\n\ns = input()\ncnt = Counter(s)\ndouble = cnt.most_common(1)[0][0]\na = s.index(double)\nb = len(s) - 1 - s[::-1].index(double)\nif a + 1 == b:\n print('Impossible')\n exit(0)\n\nx = s[:a]\ny = s[a+1:b]\nz = s[b+1:]\n\nres = [y[:len(y) // 2], y[len(y) // 2:][::-1]]\nres[0] = ... | {"inputs": ["ABCDEFGHIJKLMNOPQRSGTUVWXYZ", "BUVTYZFQSNRIWOXXGJLKACPEMDH", "DYCEUXXKMGZOINVPHWQSRTABLJF", "UTEDBZRVWLOFUASHCYIPXGJMKNQ", "ZWMFLTCQIAJEVUPODMSGXKHRNYB", "QGZEMFKWLUHOVSXJTCPIYREDNAB", "BMVFGRNDOWTILZVHAKCQSXYEJUP", "MKNTKOBFLJSXWQPVUERDHIACYGZ", "YOFJVQSWBUZENPCXGQTHMDKAILR", "GYCUAXSBNAWFIJPDQVETKZOMLHR"... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
99a87db9a65e8c0f1ea8ea030de379af | Taxi | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | [
"def min_taxis(groups):\r\n counts = [groups.count(i) for i in range(1, 5)]\r\n return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4\r\n\r\n# Пример использования\r\nn = int(input())\r\ngroups = list(map(int, input().split()))\r\nresult = min_taxis(groups)\r\nprint(result)\r\n... | {"inputs": ["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1", "5\n4 4 4 4 4", "12\n1 1 1 1 1 1 1 1 1 1 1 1", "2\n2 1", "4\n3 2 1 3", "4\n2 4 1 3", "1\n1", "1\n2", "1\n3", "1\n4", "2\n1 1", "2\n2 2", "2\n3 3", "2\n4 4", "2\n2 1", "2\n3 1", "2\n4 1", "2\n2 3", "2\n4 2", "2\n4 3", "4\n2 2 1 1", "4\n3 1 3 1", "4\n1 4 1 4", "4\n2 2 3 3... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
99c831150672a64c4aa964d7c81ccb57 | T-shirt buying | A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and... | [
"#Mateusz\r\nINDEX = {\"11\": 0, \"12\": 1, \"13\": 2,\r\n \"21\": 1, \"22\": 3, \"23\": 4,\r\n \"31\": 2, \"32\": 4, \"33\": 5}\r\ndef przerob(N, ceny, kol1, kol2):\r\n wej = [[] for i in range(N)]\r\n for i in range(N):\r\n wej[i].append(ceny[i])\r\n wej[i].append(kol1[i])\r\n ... | {"inputs": ["5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1", "2\n1000000000 1\n1 1\n1 2\n2\n2 1", "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3", "20\n414468312 20329584 106106409... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
99cc6b3b398b6c1bd9b18b917231d58c | Mike and Fax | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ... | [
"string = input()\r\npartskitnekarnehai = int(input())\r\nif len(string)%partskitnekarnehai!=0:\r\n print('NO')\r\n exit()\r\n\r\nnayalength = len(string) // partskitnekarnehai\r\n\r\n# o is length of part\r\nfor j in range(partskitnekarnehai):\r\n seedha_part = string[ j*nayalength : (j + 1)*nayalength]\r... | {"inputs": ["saba\n2", "saddastavvat\n2", "aaaaaaaaaa\n3", "aaaaaa\n3", "abaacca\n2", "a\n1", "princeofpersia\n1", "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqtht... | UNKNOWN | PYTHON3 | CODEFORCES | 150 | |
99e62878fbc428e1631c7ff1a24bf047 | Misha and Forest | Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex ... | [
"import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nsum_deg, adj, stk = 0, [], []\r\nfor i in range(n):\r\n d, s = map(int, input().split())\r\n sum_deg += d\r\n adj.append([d, s])\r\n if d == 1:\r\n stk.append(i)\r\nprint(sum_deg // 2)\r\nwhile stk:\r\n u = stk.pop()\r\n if ad... | {"inputs": ["3\n2 3\n1 0\n1 0", "2\n1 1\n1 0", "10\n3 13\n2 6\n1 5\n3 5\n1 3\n2 2\n2 6\n1 6\n1 3\n2 3", "10\n1 2\n1 7\n1 0\n1 8\n0 0\n1 9\n0 0\n1 1\n1 3\n1 5", "5\n1 1\n2 2\n2 2\n2 6\n1 3", "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "11\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 8\n1 7\n0 0\n0 0", "12\n0 0\n1 3... | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
99ea4713717dfb495b4af4a4707d2b49 | Page Numbers | «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to w... | [
"a = sorted(set(map(int, input().split(\",\"))))\nleft = right = a[0]\nfor x in a[1:]:\n if x - right > 1:\n if left == right:\n print(left, end=\",\")\n else:\n print(left, right, sep=\"-\", end=\",\")\n left = x\n right = x\nif left == right:\n print(left)\nelse... | {"inputs": ["1,2,3,1,1,2,6,6,2", "3,2,1", "30,20,10", "826,747,849,687,437", "999,999,993,969,999", "4,24,6,1,15", "511,32", "907,452,355", "303,872,764,401", "684,698,429,694,956,812,594,170,937,764", "646,840,437,946,640,564,936,917,487,752,844,734,468,969,674,646,728,642,514,695", "996,999,998,984,989,1000,996,993,1... | UNKNOWN | PYTHON3 | CODEFORCES | 60 | |
99fc2ec11dfa7ff1fc0a3b7335550b1e | Alyona and Mex | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nans = 1\r\nfor i in a:\r\n if ans <= i:\r\n ans += 1\r\nprint(ans)",
"n = input()\r\na = list(map(int, input().split()))\r\na.sort()\r\n\r\nme... | {"inputs": ["5\n1 3 3 3 6", "2\n2 1", "1\n1", "1\n1000000000", "1\n2", "2\n1 1", "2\n1 3", "2\n2 2", "2\n2 3", "2\n3 3", "3\n1 1 1", "3\n2 1 1", "3\n3 1 1", "3\n1 1 4", "3\n2 1 2", "3\n3 2 1", "3\n2 4 1", "3\n3 3 1", "3\n1 3 4", "3\n4 1 4", "3\n2 2 2", "3\n3 2 2", "3\n4 2 2", "3\n2 3 3", "3\n4 2 3", "3\n4 4 2", "3\n3 3... | UNKNOWN | PYTHON3 | CODEFORCES | 117 | |
9a1fc48ed171b6e3bfc5d1196bac0b54 | Arthur and Questions | After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*.
This sequence had the following property: if you write out the sums of all its segments consisting of *k* consecutive elements ... | [
"INF = 10000000001\r\ndef fill(s):\r\n s.insert(0, -INF)\r\n s.append(INF)\r\n i = 0\r\n for j in filter(lambda x: s[x] != '?', range(1, len(s))):\r\n d = i - j\r\n s[j] = int(s[j])\r\n if s[i] > s[j]+d:\r\n raise\r\n a = max(min(d//2, s[j]+d), s[i])\r\n for t in range(i+1, j):\r\n s[t]... | {"inputs": ["3 2\n? 1 2", "5 1\n-10 -9 ? -7 -6", "5 3\n4 6 7 2 9", "9 3\n? ? ? ? ? ? ? ? ?", "5 1\n1000000000 ? ? ? ?", "5 1\n-3 -2 -1 0 1", "7 3\n1 ? -1000000000 ? 100 ? 3", "7 3\n1 ? -1000000000 ? 100 ? 2", "1 1\n?", "1 1\n0", "2 1\n-1000000000 1000000000", "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100", "5 2\n? ? -... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
9a39ec0c2b714438bc895874b6e23dff | Little Artem and Dance | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a... | [
"import io, os, sys\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nn, q = map(int, input().split())\r\npos = [i for i in range(n)]\r\ncnt, temp, flag = 0, [0, 0], 0\r\nfor _ in range(q):\r\n p = list(map(int, input().split()))\r\n if p[0] == 1:\r\n x = (n + p[1]) % n\r\n ... | {"inputs": ["6 3\n1 2\n2\n1 2", "2 3\n1 1\n2\n1 -2", "4 2\n2\n1 3", "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2", "6 8\n1 -1\n2\n2\n1 4\n1 0\n1 -1\n1 0\n1 -1", "10 5\n1 8\n1 -3\n1 -3\n2\n1 5", "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9", "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2", "2 5\n2\n1 -1\n2\n1 1\n2", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.