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
685a6673a4ee325db24fee9ffee225da
Ghd
John Doe offered his sister Jane Doe find the gcd of some set of numbers *a*. Gcd is a positive integer *g*, such that all number from the set are evenly divisible by *g* and there isn't such *g*' (*g*'<=&gt;<=*g*), that all numbers of the set are evenly divisible by *g*'. Unfortunately Jane couldn't cope with the ta...
[ "import math\r\nfrom random import randint\r\nfrom bisect import bisect_left\r\n\r\ntest = False\r\n\r\nif test:\r\n n = randint(100000,100000)\r\n a = [randint(1,100000000) for _ in range(n)]\r\n #print('n =', n)\r\n #print('a =', a)\r\nelse: \r\n n = int(input())\r\n a=[*map(int,input().s...
{"inputs": ["6\n6 2 3 4 5 6", "5\n5 5 6 10 15", "100\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 7560 7560 7560 7560 3 5 7560 8 7560 42 45 5 7560 5 7560 4 7 3 7560 7 3 7560 7 2 7560 75...
UNKNOWN
PYTHON3
CODEFORCES
1
685f668a8903dff2f2a9f3a5dcc24c21
Nuclear Fusion
There is the following puzzle popular among nuclear physicists. A reactor contains a set of *n* atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, k = map(int, input().split())\r\na = list(input().rstrip().decode().split())\r\nb = list(input().rstrip().decode().split())\r\nx = [\"?\"]\r\nc = [\"H\", \"He\"]\r\nfor i in c:\r\n x.append(i)\r\nc = [\"Li\", \"Be\", \"...
{"inputs": ["10 3\nMn Co Li Mg C P F Zn Sc K\nSn Pt Y", "2 1\nH H\nHe", "2 2\nBk Fm\nCf Es", "8 8\nTl Pb Bi Po Np Pu Am Cm\nAt Rn Fr Ra Ac Th Pa U", "4 2\nZr Nb Sr Zr\nHg Au", "8 1\nBe B N O Ne Na Al Si\nHf", "7 3\nH He Be O S Ge Gd\nIr Cr Fe", "6 3\nCl Ni Ti V Ar Cu\nRh Br La", "5 5\nOs Lu Ta Re W\nW Ta Re Os Lu", "8 ...
UNKNOWN
PYTHON3
CODEFORCES
1
6860f3118664ad3c940eaa801d33763f
Minimum and Maximum
This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.flush(). In this problem, you need to find maximal and minimal elements of an ar...
[ "import sys\r\n\r\n\r\ndef find_min_max(l, d=None):\r\n #print(l)\r\n n = len(l)\r\n if n == 1:\r\n return (l[0], l[0])\r\n \r\n lesser = []\r\n greater = []\r\n for i in range(n//2):\r\n first = l[2*i]\r\n second = l[2*i + 1]\r\n \r\n print(\"? {} {}\".format...
{"inputs": ["2\n2\n2 1\n3\n1 1 1", "1\n4\n1 1 2 2", "2\n5\n1 1 2 1 1\n3\n3 2 1", "2\n6\n2 1 2 1 2 2\n3\n2 2 1", "2\n4\n2 3 3 3\n5\n4 4 4 3 2", "1\n10\n1 2 1 2 1 3 1 3 1 2", "1\n1\n1", "2\n2\n1 2\n2\n2 1", "6\n3\n1 2 3\n3\n1 3 2\n3\n2 1 3\n3\n2 3 1\n3\n3 1 2\n3\n3 2 1", "24\n4\n1 2 3 4\n4\n1 2 4 3\n4\n1 3 2 4\n4\n1 3 4 ...
UNKNOWN
PYTHON3
CODEFORCES
5
6898b78f6da5c9b53c37dff69497cf71
none
Stepan had a favorite string *s* which consisted of the lowercase letters of the Latin alphabet. After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about the string, namely the sequence of integers *c*1,<=*c*2,<=...,<=*c**n*, whe...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\nans=\"\"\r\narr=[0]*(n+1)\r\ncurchar='a'\r\nfor i in range(n-1,-1,-1):\r\n for j in range(i+1,n):\r\n a[i]-=a[j]*(1+j-i)\r\n for j in range(a[i]):\r\n ans+=curchar*(i+1)\r\n if curchar=='z':\r\n curchar='a'\r\n else:...
{"inputs": ["6\n6 3 1 0 0 0", "4\n4 0 0 0", "1\n1", "5\n5 0 0 0 0", "10\n10 8 7 6 5 4 3 2 1 0", "20\n20 16 12 8 5 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "99\n99 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
UNKNOWN
PYTHON3
CODEFORCES
11
689adc88f3b1fbc872a2e559e8d4e224
Put Knight!
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=...
[ "r = open('input.txt','r')\r\nw = open('output.txt','w')\r\nn = int(r.readline())\r\nt = ['10'[int(r.readline()) % 2] for i in range(n)]\r\nw.write('\\n'.join(t))", "f = open('input.txt', 'r').readlines()\r\nn = int(f[0])\r\na = []\r\nfor i in range(1, n + 1):\r\n a.append('10'[int(f[i]) % 2])\r\nopen('output....
{"inputs": ["2\n2\n1", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5", "6\n10\n7\n10\n8\n5\n1", "100\n5\n6\n8\n7\n5\n7\n10\n2\n8\n3\n10\n3\n7\n3\n2\n7\n10\n3\n7\n3\n9\n5\n1\n1\n1\n5\n7\n5\n4\n8\n7\n3\n2\n10\n5\n10\n1\n10\n5\n2\n10\n6\n4\n10\n7\n6\n10\n8\n8\n5\n5\n7\n5\n7\n8\n6\n...
UNKNOWN
PYTHON3
CODEFORCES
25
68acf953f608b461ee64ff436ef99467
Roads not only in Berland
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are *n* cities in Berland and neighboring countries in total and exactly *n*<=-<=1 two...
[ "n = int(input())\np = [i for i in range(n + 1)]\ndef asd(i):\n if i != p[i]:\n p[i] = asd(p[i])\n return p[i]\ndef qwe(i, j):\n i = asd(i)\n j = asd(j)\n if i != j:\n p[i] = p[j]\n return True\n return False\n\nl = list()\nfor i in range(n - 1):\n a, b = map(int, input()....
{"inputs": ["2\n1 2", "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7", "3\n3 2\n1 2", "3\n3 1\n3 2", "4\n1 4\n3 1\n3 4", "5\n4 1\n4 3\n5 3\n2 4", "6\n5 2\n5 3\n1 4\n3 1\n5 6", "10\n5 9\n8 5\n7 6\n7 9\n3 9\n2 1\n7 2\n3 6\n7 1", "21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\...
UNKNOWN
PYTHON3
CODEFORCES
50
68c4515d74411c8dc12e75c9f23458ad
Edge coloring of bipartite graph
You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour. The first line contains three integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*<=≤<=1000, 0<=≤<=*m*<=≤<=105), *a* is the size of the first par...
[ "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n...
{"inputs": ["4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3", "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3", "4 3 0", "10 10 67\n1 1\n1 2\n1 3\n1 7\n1 9\n1 10\n2 1\n2 2\n2 3\n2 6\n2 8\n2 10\n3 2\n3 3\n3 6\n3 8\n3 9\n3 10\n4 1\n4 4\n4 5\n4 6\n4 7\n4 8\n5 2\n5 4\n5 7\n5 8\n5 9\n5 10\n6 1\n6 2\n6 3\n6 4\n6 6\n6 8\n6 9\n6 10\n7 2\n7 4\n7 6\n7 9\n7 10\...
UNKNOWN
PYTHON3
CODEFORCES
3
68c89b5c6d3ad091555738ff9b320b01
Urbanization
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ...
[ "n,n1,n2=map(int ,input().split());\r\nl=list(map(int,input().split()));\r\nl.sort(reverse=True)\r\nn1,n2=max(n1,n2),min(n1,n2);\r\ns1=0\r\ns2=0\r\nfor i in range(n2):\r\n s1+=l[i]\r\nfor i in range(n2,n1+n2):\r\n s2+=l[i]\r\nprint(s1/n2+s2/n1)", "n,n1,n2=map(int,input().split())\r\narr=list(map(int,input()...
{"inputs": ["2 1 1\n1 5", "4 2 1\n1 4 2 3", "3 1 2\n1 2 3", "10 4 6\n3 5 7 9 12 25 67 69 83 96", "19 7 12\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 100000 100000", "100 9 6\n109 711 40 95 935 48 228 253 308 726 816 534 252 8 966 363 162 508 84 83 807 506 748 178 45 30 106 108 764 698 825 198 3...
UNKNOWN
PYTHON3
CODEFORCES
110
68d01f12124a47d6571ff3bdf392dfee
I'm bored with life
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
[ "import math as m\r\na,b=map(int,input().split())\r\nc=min(a,b)\r\nprint(m.factorial(c))", "d = input().split(' ')\nA = int(d[0])\nB = int(d[1])\n\ndef factorial(x):\n if x == 0: \n return 1\n return x * factorial(x-1)\n\nif A>=B:\n print(factorial(B))\nelse:\n print(factorial(A))\n\n\t\t \t\t ...
{"inputs": ["4 3", "10 399603090", "6 973151934", "2 841668075", "7 415216919", "3 283733059", "11 562314608", "3 990639260", "11 859155400", "1 1", "5 3", "1 4", "5 4", "1 12", "9 7", "2 3", "6 11", "6 7", "11 11", "4 999832660", "7 999228288", "11 999257105", "11 999286606", "3 999279109", "999632727 11", "999625230 ...
UNKNOWN
PYTHON3
CODEFORCES
580
68d1584556ca86c9b30666956022b06f
Transmigration
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes...
[ "from collections import Counter\r\nn, m, k = input().split()\r\nk, c = int(k.split('.')[1]), Counter()\r\nfor i in range(int(n)):\r\n s, e = input().split()\r\n e = int(e) * k // 100\r\n if e >= 100:\r\n c[s] = e\r\nfor i in range(int(m)):\r\n c[input()] += 0\r\nprint(len(c))\r\nprint('\\n'.join...
{"inputs": ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost", "1 1 0.50\nstaff 1005\nionize", "4 3 0.32\ninrf 48\nfdgdf 200\nvbkdfk 450\nfdbvfdd 1000\ndff\ninrf\nnfdkd", "5 1 0.99\na 1\nb 2\nc 3\nd 4\ne 5\nf", "2 2 0.02\nfn 1003\nzz 7000\nkk\nau", "3 3 0.10\n...
UNKNOWN
PYTHON3
CODEFORCES
8
68f881cb48278b79a28b227309589ed8
Generating Sets
You are given a set *Y* of *n* distinct positive integers *y*1,<=*y*2,<=...,<=*y**n*. Set *X* of *n* distinct positive integers *x*1,<=*x*2,<=...,<=*x**n* is said to generate set *Y* if one can transform *X* to *Y* by applying some number of the following two operation to integers in *X*: 1. Take any integer *x**i* ...
[ "import sys\r\ninput = lambda :sys.stdin.readline()[:-1]\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n####...
{"inputs": ["5\n1 2 3 4 5", "6\n15 14 3 13 1 12", "6\n9 7 13 17 5 11", "10\n18 14 19 17 11 7 20 10 4 12", "100\n713 716 230 416 3 2 597 216 779 839 13 156 723 793 168 368 232 316 98 257 170 27 746 9 616 147 792 890 796 362 852 117 993 556 885 73 131 475 121 753 508 158 473 931 527 282 541 325 606 321 159 17 682 290 586...
UNKNOWN
PYTHON3
CODEFORCES
8
68fad3ac9deae97955c6f83d645d9847
Divisibility Rules
Vasya studies divisibility rules at school. Here are some of them: - Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even.- Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3.- Divisibility by 4. A n...
[ "import math\r\nfrom collections import defaultdict\r\nimport itertools\r\n\r\nPRIME = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\n\r\n\r\ndef int_sqrt(n):\r\n return int(round(math.sqrt(n)))\r\n\r\n\r\ndef is_2_type(base, divisor):\r\n return [k for k i...
{"inputs": ["10 10", "2 3", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "3 2", "3 3", "3 4", "3 5", "3 6", "3 7", "3 8", "4 2", "4 3", "4 4", "4 5", "4 6", "4 7", "4 8", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "6 2", "6 3", "6 4", "6 5", "6 6", "6 7", "6 8", "7 2", "7 3", "7 4", "7 5", "7 6", "7 7", "7 8"...
UNKNOWN
PYTHON3
CODEFORCES
2
692e674495305d943f08aa56e354992d
Third Month Insanity
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2*N* teams participating in the tournament, numbered from 1 to 2*N*. The tournament lasts *N* rounds, with each round eliminating half the teams. The first round consists of...
[ "n = int(input())\r\nm = 1 << n\r\np = [list(map(int, input().split())) for i in range(m)]\r\nu, x = [1] * m, [0] * m\r\nv, y = u[:], x[:]\r\nfor i in range(n):\r\n d = 1 << i\r\n for j in range(m):\r\n s = d * (j // d ^ 1)\r\n v[j] = u[j] * sum(u[k] * p[j][k] for k in range(s, s + d)) / 100\r\n...
{"inputs": ["2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0", "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0", "2\n0 21 41 26\n79 0 97 33\n59 3 0 91\n74 67 9 0", "3\n0 7...
UNKNOWN
PYTHON3
CODEFORCES
2
693ab3157cd165892ac491541b2035b8
Array
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤...
[ "import sys\r\nimport os.path\r\n \r\nif(os.path.exists('input.txt')) :\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n sys.stdout = open(\"output.txt\", \"w\")\r\n sys.stderr = open(\"error.txt\", \"w\")\r\n \r\ndepth = 1000005\r\nmod = 1000000007 \r\nlim = mod * mod\r\nsys.setrecursionlimit(depth) \r\n...
{"inputs": ["4 2\n1 2 2 3", "8 3\n1 1 2 2 3 3 4 5", "7 4\n4 7 7 4 7 4 7", "5 1\n1 7 2 3 2", "1 2\n666", "1 1\n5", "10 4\n1 1 2 2 3 3 4 4 4 4", "4 2\n3 3 4 3", "4 3\n4 4 4 2", "10 5\n15 17 2 13 3 16 4 5 9 12", "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148", "17 14\n271 158 573 88 792 767 392 646 392 3...
UNKNOWN
PYTHON3
CODEFORCES
96
696c1c749977e10e2eeedbc66e7b754f
Anfisa the Monkey
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble h...
[ "k,a,b=list(map(int,input().split()))\r\ns=input()\r\nn=len(s)\r\nif not(k*a<=n<=k*b):\r\n print('No solution')\r\nelse:\r\n c=n//k\r\n d=n%k\r\n j=0\r\n for i in range(k):\r\n print(s[j:j+c+int(i<d)])\r\n j+=c+int(i<d)", "\r\nk,a,b = map(int,input().split())\r\nqo = input()\r\n\r\n\...
{"inputs": ["3 2 5\nabrakadabra", "4 1 2\nabrakadabra", "3 1 2\nvgnfpo", "5 3 4\nvrrdnhazvexzjfv", "10 12 15\nctxgddcfdtllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmp", "10 20 30\nbvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrb...
UNKNOWN
PYTHON3
CODEFORCES
89
69769ded2ddea958b4e6622ce7fb7d10
none
Pavel cooks barbecue. There are *n* skewers, they lay on a brazier in a row, each on one of *n* positions. Pavel wants each skewer to be cooked some time in every of *n* positions in two directions: in the one it was directed originally and in the reversed direction. Pavel has a plan: a permutation *p* and a sequence ...
[ "n = int(input())\r\np = list(map(lambda x: int(x)-1, input().split()))\r\nb = list(map(int, input().split()))\r\ncp = 0\r\nz = [True]*n\r\nold = -1\r\nnn = n\r\nwhile nn:\r\n cp += 1\r\n cur = next(i for i in range(old + 1, n) if z[i])\r\n old = cur\r\n while(z[cur]):\r\n z[cur] = False\r\n nn -= 1\r\n ...
{"inputs": ["4\n4 3 2 1\n0 1 1 1", "3\n2 3 1\n0 0 0", "1\n1\n0", "2\n1 2\n0 0", "2\n2 1\n0 0", "2\n1 2\n0 1", "2\n2 1\n1 0", "2\n1 2\n1 1", "2\n2 1\n1 1", "5\n2 1 3 4 5\n1 0 0 0 1", "10\n4 10 5 1 6 8 9 2 3 7\n0 1 0 0 1 0 0 1 0 0", "20\n10 15 20 17 8 1 14 6 3 13 19 2 16 12 4 5 11 7 9 18\n0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 ...
UNKNOWN
PYTHON3
CODEFORCES
20
6978724378602e63542d64fd1f157f42
Line
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist. The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*...
[ "x0=1\r\ny0=1\r\nd=0\r\ndef euclides(a,b):\r\n global x0,y0,d\r\n if b==0:\r\n x0=1\r\n y0=0\r\n d=a\r\n return\r\n euclides(b,a%b)\r\n x1=y0\r\n y1=x0-(a//b)*y0\r\n x0=x1\r\n y0=y1\r\n\r\na,b,c=map(int,input().split())\r\neuclides(a,b)\r\nif c%d!=0:\r\n print(-1)...
{"inputs": ["2 5 3", "0 2 3", "931480234 -1767614767 -320146190", "-1548994394 -1586527767 -1203252104", "296038088 887120955 1338330394", "1906842444 749552572 -1693767003", "-1638453107 317016895 -430897103", "-1183748658 875864960 -1315510852", "427055698 738296578 -52640953", "-1516373701 -584304312 -746376800", "2...
UNKNOWN
PYTHON3
CODEFORCES
29
69acc2eae81f23c8a6ec3869ee66ed2f
Archer
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will...
[ "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\na,b,c,d=(int(i) for i in input().split())\r\nk1=1-(a/b)\r\nk2=1-(c/d)\r\nprint((1-k1)/(1-k1*k2))", "entrada = input()\nitens = entrada.split()\na, b, c, d = float(itens[0]), int(itens[1]), int(itens[2]), int(itens[3])\...
{"inputs": ["1 2 1 2", "1 3 1 3", "1 3 2 3", "3 4 3 4", "1 2 10 11", "4 5 4 5", "466 701 95 721", "268 470 444 885", "632 916 713 821", "269 656 918 992", "71 657 187 695", "435 852 973 978", "518 816 243 359", "882 962 311 811", "684 774 580 736", "486 868 929 999", "132 359 996 998", "933 977 266 450", "298 833 615 8...
UNKNOWN
PYTHON3
CODEFORCES
353
6a1937e725b9a6aff7dc0feedc20e9f0
Binary Number
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divide...
[ "t = input()\n\nx, y, z = len(t), t.rfind('1'), t.count('1')\n\nprint(x + y - z + (2 if z > 1 else 0))\n\n\n\n\n\n# Made By Mostafa_Khaled", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nx = [48] + list(input().rstrip())\r\nans = 0\r\nwhile len(x) ^ 1 and (len(x) ^ 2 o...
{"inputs": ["1", "1001001", "101110", "11", "11110001101", "1010101001001111000111110011111000010101011111101010", "1100000010010100111011100011110101111", "11000111111110110110100110110101111100010100110110010", "11100000110100011110101001101111100000011001111000011110000000111110111", "1000101100110000000001111010110...
UNKNOWN
PYTHON3
CODEFORCES
47
6a27434e92a6ae2b20c2a2389a4b2455
Pawn
On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having c...
[ "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom types import GeneratorType\r\nfrom collections import defaultdict\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n ...
{"inputs": ["3 3 1\n123\n456\n789", "3 3 0\n123\n456\n789", "2 2 10\n98\n75", "3 4 2\n8244\n4768\n4474", "4 3 10\n194\n707\n733\n633", "5 6 0\n564132\n152314\n382748\n956060\n261008", "2 4 2\n3916\n9593", "5 5 6\n78237\n84658\n09523\n48007\n70591", "6 6 0\n962504\n555826\n306365\n336593\n304184\n461978", "7 7 8\n917861...
UNKNOWN
PYTHON3
CODEFORCES
5
6a442951f918b3291f7632fa0bf0689e
Connected Components?
You are given an undirected graph consisting of *n* vertices and edges. Instead of giving you the edges that exist in the graph, we give you *m* unordered pairs (*x*,<=*y*) such that there is no edge between *x* and *y*, and if some pair of vertices is not listed in the input, then there is an edge between these verti...
[ "import sys\nimport math\nimport string\n\ndef solve(s, l, a):\n c = 0\n v = l[0]\n l.pop(0)\n rem = list(s)\n for i in rem:\n if((min(i,v), max(i,v)) not in a):\n c += 1\n l.append(i)\n s.remove(i)\n for i in l:\n c += solve(s, [i], a)\n return c\...
{"inputs": ["5 5\n1 2\n3 4\n3 2\n4 2\n2 5", "8 15\n2 1\n4 5\n2 4\n3 4\n2 5\n3 5\n2 6\n3 6\n5 6\n4 6\n2 7\n3 8\n2 8\n3 7\n6 7", "12 58\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n4 5\n4 6\n4 8\n4 11\n4 12\n5 6\...
UNKNOWN
PYTHON3
CODEFORCES
16
6a66d1afd709b4c997f0e107675265b7
Fedya and Maths
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language). The single line contains a single int...
[ "print('04'[int(input())%4<1])", "n = int(input(\"\"))\r\n\r\nif n%4 == 0:\r\n\tprint(\"4\")\r\nelif n%4 == 1:\r\n\tprint(\"0\")\r\nelif n%4 == 2:\r\n\tprint(\"0\")\r\nelse:\r\n\tprint(\"0\")\r\n\r\n", "# Topicos Especiais em Programacao | UFRJ | 2023.1\n# Gabriele Jandres Cavalcanti | 119159948\n# Aula 1 | Pro...
{"inputs": ["4", "124356983594583453458888889", "2", "7854", "584660", "464", "192329", "85447", "956", "83", "33", "64", "971836", "578487", "71752", "2563", "51494", "247", "52577", "13", "26232", "0", "10", "12", "8", "1"], "outputs": ["4", "0", "0", "0", "4", "4", "0", "0", "4", "0", "0", "4", "4", "0", "4", "0", "...
UNKNOWN
PYTHON3
CODEFORCES
84
6a681fb01eaba2e90830b8381036cd5d
Not Equal on a Segment
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the ...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nN, M = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nB = [N + 1 for _ in range(N)]\r\nidx = N + 1\r\n\r\nfor i in range(N - 1)[::-1]:\r\n if A[i] != A[i + 1]:\r\n idx = i + 1\r\n B[i] = idx\r\n\r\nres = []\r\n\r\nfor _ in range(...
{"inputs": ["6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2", "1 1\n1\n1 1 1", "1 1\n2\n1 1 2", "1 1\n569888\n1 1 967368", "10 10\n1 1 1 1 1 1 1 1 1 1\n3 10 1\n3 6 1\n1 8 1\n1 7 1\n1 5 1\n3 7 1\n4 7 1\n9 9 1\n6 7 1\n3 4 1", "10 10\n1 2 2 2 2 1 1 2 1 1\n3 3 1\n4 9 1\n4 8 1\n2 7 2\n2 8 2\n3 10 1\n7 7 2\n10 10 2\n1 5 1\n1 2...
UNKNOWN
PYTHON3
CODEFORCES
15
6a78ba8347b792003daee4ed7923df54
Exposition
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub...
[ "from sys import stdin\r\ninput = stdin.buffer.readline\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nminq, maxq = [], []\r\ni1, i2, l = 0, 0, 0\r\nans, sz = [], 0\r\nfor r in range(n):\r\n while i1 < len(minq) and a[r] < minq[-1][0]: minq.pop()\r\n minq.append([a[r], r])\r...
{"inputs": ["3 3\n14 12 10", "2 0\n10 10", "4 5\n8 19 10 13", "1 1\n1", "2 10\n35 45", "4 8\n89 33 54 75", "5 1\n9 6 8 7 5", "3 3\n3 8 6", "4 1000000\n100001 1 200001 300001", "4 1000\n11497 9999 10730 12280", "3 0\n1000000 1000000 1000000", "4 50\n165 182 157 132", "5 173\n350 250 200 300 400", "4 0\n1 1 1 1", "2 1000...
UNKNOWN
PYTHON3
CODEFORCES
18
6a9c2f420ce1c26085455b0f8032be0f
Palindrome Degree
String *s* of length *n* is called *k*-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (*k*<=-<=1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string *s* such a maximum number *k*, for which *s* is *k*-palindrome. For examp...
[ "# import sys\r\n# sys.stdout=open('C:\\Program Files (x86)\\Sublime Text 3\\cp_setup\\output.txt','w')\r\n# sys.stdin=open('C:\\Program Files (x86)\\Sublime Text 3\\cp_setup\\input.txt','r')\r\n\r\n\r\nimport heapq\r\nimport math\r\nimport collections\r\nimport bisect\r\nmod=10**9+7\r\nmaxi=5*10**6\r\nppow=[0]*max...
{"inputs": ["a2A", "abacaba", "CCeCeCCCee", "opooppppopppopoppopoooppopopooopopppooopppoppoppoppppoooppooooooopppoopoopooooppooooppppppppooopooop", "odribmizzsgholprdsth", "z"], "outputs": ["1", "6", "4", "3", "1", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
2
6a9dad7100e9c491d15d4d8c2341be0d
Bear and Raspberry
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfo...
[ "n,c=map(int,input().split())\r\nx=list(map(int,input().split()))\r\ne=0\r\n\r\nfor i in range(n-1):\r\n e=max(e,x[i]-x[i+1]-c)\r\n \r\nprint(e)", "\r\ns = input().rstrip().split(' ')\r\nn, c = int (s[0]), int(s[1])\r\n\r\nx = input().rstrip().split(' ')\r\n\r\nmax = int (x[0]) - int (x[1]) - c\r\nfor i in ...
{"inputs": ["5 1\n5 10 7 3 20", "6 2\n100 1 10 40 10 40", "3 0\n1 2 3", "2 0\n2 1", "10 5\n10 1 11 2 12 3 13 4 14 5", "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 9...
UNKNOWN
PYTHON3
CODEFORCES
297
6aa3d5f844967d0a5b0f77f9aec93c4b
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
[ "\r\nn = int(input())\r\ng = [int(i) - 1 for i in input().split()]\r\n\r\ndef solve(n, g):\r\n vertex_id = [-1]*n\r\n current_id = 0\r\n\r\n starts_a_cycle = [-1]*n\r\n cycle_vertex_sample = []\r\n start_on_cycle = []\r\n cycle_index_by_ID = []\r\n cycle_count = 0\r\n\r\n for v in range(n):\...
{"inputs": ["3\n3 3 2", "7\n2 3 1 3 4 4 1", "2\n2 1", "3\n2 3 1", "4\n2 4 4 3", "5\n5 3 5 2 3", "9\n2 5 6 7 4 1 9 6 8", "20\n20 10 16 14 9 20 6 20 14 19 17 13 16 13 14 8 8 8 8 19", "100\n13 71 16 92 25 53 97 63 70 83 51 16 51 84 5 10 54 89 18 95 48 29 82 27 84 68 7 4 65 99 95 37 26 24 24 39 3 28 74 7 75 32 27 24 73 48 ...
UNKNOWN
PYTHON3
CODEFORCES
2
6acf2fb9e0257a25a02dab4cf9af8c13
Minimal Labels
You are given a directed acyclic graph with *n* vertices and *m* edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: - Labels form a valid permutation of length *n* — an integer sequence such that each ...
[ "import sys\r\nimport math\r\nimport collections\r\nfrom heapq import heappush, heappop\r\ninput = sys.stdin.readline\r\n\r\nints = lambda: list(map(int, input().split()))\r\n\r\nn, m = ints()\r\ng = [[] for _ in range(n)]\r\ndeg = [0] * n\r\n\r\nfor _ in range(m):\r\n u, v = ints()\r\n u -= 1\r\n v -= 1\r...
{"inputs": ["3 3\n1 2\n1 3\n3 2", "4 5\n3 1\n4 1\n2 3\n3 4\n2 4", "5 4\n3 1\n2 1\n2 3\n4 5", "2 1\n2 1", "5 10\n5 2\n4 1\n2 1\n3 4\n2 4\n3 2\n5 4\n3 5\n3 1\n5 1", "100 10\n73 55\n29 76\n15 12\n94 46\n77 67\n76 16\n72 50\n41 40\n89 75\n27 22", "100000 10\n4412 787\n97243 62644\n78549 66107\n43440 41961\n39621 35680\n870...
UNKNOWN
PYTHON3
CODEFORCES
21
6afaf721b3cad15051de8a10a3b6a477
Hamster Farm
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory ...
[ "arr=input().split()\r\nn=int(arr[0])\r\nk=int(arr[1])\r\narr1=list(map(int,input().split()))\r\nmx=(0,10**18)\r\nfor i in range(k):\r\n if n%arr1[i]<mx[1]:\r\n mx=(i,n%arr1[i])\r\nprint(mx[0]+1,n//arr1[mx[0]])", "n,k=[int(x) for x in input().split()]\r\ncapacities=[int(x) for x in input().split()]\r\nm...
{"inputs": ["19 3\n5 4 10", "28 3\n5 6 30", "1 1\n1", "0 2\n2 3", "30 4\n4 5 5 4", "120 7\n109 92 38 38 49 38 92", "357 40\n12 10 12 11 12 12 12 10 10 10 12 12 12 12 12 10 12 10 10 10 11 10 12 10 12 10 12 10 10 12 12 12 12 10 10 10 12 12 12 12", "587 100\n92 92 76 95 61 60 64 79 64 96 63 92 60 61 95 71 60 61 65 63 84 7...
UNKNOWN
PYTHON3
CODEFORCES
70
6b3e4bd0a44e3c15f50145c3a8b35a30
Pasha and Pixels
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos...
[ "#10_2.py\r\nm, n, k = map(int,input().split())\r\nc = [[0]*(n+1) for i in range(m+1)]\r\ncolor = [[0]*(n+1) for i in range(m+1)]\r\ndx = [-1,-1,0,0]\r\ndy = [-1,0,-1,0]\r\nflag = False\r\nfor cnt in range(k):\r\n i, j = map(int,input().split())\r\n if flag:\r\n continue\r\n if c[i][j]:\r\n c...
{"inputs": ["2 2 4\n1 1\n1 2\n2 1\n2 2", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2", "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352", ...
UNKNOWN
PYTHON3
CODEFORCES
207
6b3e915ee56ea07b2680bd5f2731c25e
Walking!
There is a sand trail in front of Alice's home. In daytime, people walk over it and leave a footprint on the trail for their every single step. Alice cannot distinguish the order of the footprints, but she can tell whether each footprint is made by left foot or right foot. Also she's certain that all people are walkin...
[ "s=input()\r\nn=len(s)\r\nlid,sz=[],0\r\nlst=[[],[]]\r\nfor id,c in enumerate(s):\r\n\tc=c=='R'\r\n\tif not lst[not c]:\t\r\n\t\tlst[not c].append(sz)\r\n\t\tlid.append([]);sz+=1\r\n\tlid[lst[not c][-1]].append(id)\r\n\tlst[c].append(lst[not c][-1])\r\n\tlst[not c].pop()\r\nprint(sz-1)\r\nnlst=[[],[],[],[]]\r\nfor ...
{"inputs": ["RRLRL", "RLRLRLRLR", "RRRRRLLLL", "RRLLRRRRLLRRLLRRLLLLRRLL", "RRLRRRLLRRLRRRLRLLRRLLLRRRLLRLRRRLRLLRRRRRLLLLRLRRRLRRRLRLRLLLRLLLLLRRLRLLLRRLLLLLRLRRLRRLLLRLLRRLRL", "L", "R", "LLLLRRRRRRLLLLLLRRRRR", "RLRRLLLRLRLRR", "LR", "RL", "LLRRRLLRRRLL", "RRLLLRRLLLRR", "RRLLR", "LLRRL"], "outputs": ["1\n2 5 1 3 4"...
UNKNOWN
PYTHON3
CODEFORCES
1
6b44c6785c6ccefed3314b846f146f9e
Molly's Chemicals
Molly Hooper has *n* different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The *i*-th of them has affection value *a**i*. Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total ...
[ "import sys\r\nimport collections\r\ninput = sys.stdin.readline\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nlt, pk = [], 1\r\nfor i in range(47):\r\n if abs(pk) <= 10**14:\r\n lt.append(pk)\r\n pk *= k\r\nlt = list(set(lt))\r\n# s[i] - s[j] = w (w in lt) --> s[i] = s[j...
{"inputs": ["4 2\n2 2 2 2", "4 -3\n3 -6 -3 12", "14 -9\n-2 -4 62 53 90 41 35 21 85 74 85 57 10 39", "20 9\n90 21 -6 -61 14 -21 -17 -65 -84 -75 -48 56 67 -50 16 65 -79 -61 92 85", "89 -7\n5972 4011 3914 670 3727 2913 6935 6927 2118 6645 7141 3585 9811 2859 459 8870 6578 8667 468 5152 3241 7455 7323 8817 4866 1040 5102 9...
UNKNOWN
PYTHON3
CODEFORCES
6
6b5a6f7fd3372a62826ecad686da6fb9
Cinema Cashier
All cinema halls in Berland are rectangles with *K* rows of *K* seats each, and *K* is an odd number. Rows and seats are numbered from 1 to *K*. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is th...
[ "[n,k]=[int(x) for x in input().split()];\r\nxc=(k//2)+1;\r\nreq=[int(x) for x in input().split()];\r\n\r\nava=[[xc,xc] for x in range(k+1)];\r\nfor m in req:\r\n mindis=10**10;\r\n x=None;\r\n yl=None;\r\n yr=None;\r\n for i in range(1,k+1):\r\n dis=m*abs((i-xc))\r\n if ava[i][0]==ava[...
{"inputs": ["2 1\n1 1", "4 3\n1 2 3 1", "1 3\n1", "2 3\n3 3", "3 3\n3 2 3", "1 5\n5", "2 5\n3 4", "3 5\n2 5 2", "4 5\n5 5 3 5", "5 5\n4 1 3 1 1", "10 11\n3 11 6 4 4 11 9 2 1 9", "10 13\n12 8 7 11 11 9 2 12 10 1", "10 15\n15 6 1 9 3 10 11 1 14 10", "10 17\n5 8 13 5 11 12 10 17 16 7", "10 19\n8 19 17 12 4 5 9 16 7 3", "5...
UNKNOWN
PYTHON3
CODEFORCES
5
6b5c9fda8d18efd41bd1e2f20140d0ed
Mind the Gap
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut...
[ "def next(h1, m1, minutes):\r\n return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60)\r\n\r\nn, s = map(int, input().split())\r\nschedule = []\r\n\r\nfor i in range(n):\r\n schedule.append(tuple(map(int, input().split())))\r\n\r\nif schedule[0][0] * 60 + schedule[0][1] >= s + 1:\r\n print('0 0')\r\nelse:...
{"inputs": ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0", "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7...
UNKNOWN
PYTHON3
CODEFORCES
85
6b803dbd74756c7a0ce25de8e96ff2e5
A Compatible Pair
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big B...
[ "n,m = input().split()\r\nn = int(n)\r\nm = int(m)\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\nans = 10000000000000000000\r\nfor i in range(n):\r\n maxi = -10000000000000000000\r\n for j in range(n):\r\n if j != i:\r\n for k in range...
{"inputs": ["2 2\n20 18\n2 14", "5 3\n-1 0 1 2 3\n-1 0 1", "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "5 7\n-1...
UNKNOWN
PYTHON3
CODEFORCES
92
6b871f4add35d8a08ea4c61c04c0b5d4
Mishka and trip
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of *n* cities, *k* of whose (just imagine!) are capital cities. 1. All of cities...
[ "input()\r\nl, c, t = list(map(int, input().split())), [int(s) - 1 for s in input().split()], 0\r\ns = sum(l)\r\nfor i in c:\r\n x, l[i] = l[i], 0\r\n s -= x\r\n t += s * x\r\nprint(t + sum(l[i] * x for i, x in enumerate(l, -1)))", "n,k = map(int,input().split())\r\nlst = list(map(int,input().split()))\r...
{"inputs": ["4 1\n2 3 1 2\n3", "5 2\n3 5 2 2 4\n1 4", "3 1\n1 1 1\n1", "3 3\n1 1 1\n1 2 3", "7 7\n6 9 2 7 4 8 7\n1 2 3 4 5 6 7", "5 5\n6 2 4 10 2\n1 2 3 4 5", "5 5\n6 7 8 8 8\n1 2 3 4 5", "9 4\n5 6 7 1 5 4 8 7 1\n1 5 7 9", "7 2\n1 6 8 3 3 5 5\n1 3", "9 4\n182 938 865 240 911 25 373 22 875\n3 6 7 8", "10 4\n7931 7116 49...
UNKNOWN
PYTHON3
CODEFORCES
5
6ba63d2f5d8138cc02354cc2aa491aa6
Watermelon
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
[ "weight = input()\r\nw = int(weight)\r\na = 0\r\nb = w - a\r\nwhile True:\r\n a += 1\r\n b = w - a\r\n if a % 2 == 0 and b % 2 == 0 and b != 0:\r\n print('YES')\r\n break\r\n elif a > w:\r\n print('NO')\r\n break\r\n else:\r\n continue", "# Read the input\nw = int...
{"inputs": ["8", "5", "4", "3", "2", "1", "7", "6", "10", "9", "53", "77", "32", "44", "98", "99", "90", "67", "100", "88"], "outputs": ["YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
693
6bf60cd692f741caed0e551b1119e8ec
Devu, the Singer and Churu, the Joker
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
[ "n,m=map(int, input().split())\r\na=sum(list(map(int, input().split())))\r\nif a+(n-1)*10<=m:\r\n print((m-a)//5)\r\nelse:\r\n print(-1)", "n,d=map(int,input().split())\r\ns=0\r\nj=0\r\nt=list(map(int,input().split()))\r\nfor i in range(n):\r\n s=s+t[i]\r\ns=s+(n-1)*10\r\nif(s<=d):\r\n j=2*(n-1)+(...
{"inputs": ["3 30\n2 2 1", "3 20\n2 1 1", "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1", "100 9000\n5 ...
UNKNOWN
PYTHON3
CODEFORCES
471
6c1dc382c40cf5b2c5380259ad2c0879
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to g...
[ "# https://codeforces.com/problemset/problem/358/C\n# Solution credits (Adapted from C++): Sujoy Ghosh\n\ndef solve():\n n = int(input())\n\n inputs = ['pushStack', 'pushQueue', 'pushFront', 'pushBack']\n outputs = ['popStack', 'popQueue', 'popFront', 'popBack']\n\n v = []\n\n for _ in range(n):\n ...
{"inputs": ["10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "4\n1\n2\n3\n0", "2\n0\n1", "5\n1\n1\n1\n2\n1", "5\n3\n2\n3\n1\n0", "49\n8735\n95244\n50563\n33648\n10711\n30217\n49166\n28240\n0\n97232\n12428\n16180\n58610\n61112\n74423\n56323\n43327\n0\n12549\n48493\n43086\n69266\n27033\n37338\n43900\n5570\n25293\n44517\n7183\n41969\n...
UNKNOWN
PYTHON3
CODEFORCES
6
6c50edebb128b0ef825474bcdce42054
Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will co...
[ "n, m, k = map(int, input().split())\r\nh = [0]*(n+1)\r\nfor i in map(int, input().split()):\r\n h[i] = 1\r\npos = 1\r\nimport sys\r\nif h[1]:\r\n print(1)\r\n sys.exit()\r\nfor _ in range(k):\r\n a, b = map(int, input().split())\r\n if pos == a:\r\n pos = b\r\n if h[b]:\r\n ...
{"inputs": ["7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "5 1 2\n2\n1 2\n2 4", "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11", "100000 3 7\n2 3 4\n1 5\n5 1\n1 5\n5 1\n1 4\n4 3\n3 2", "1000000 9 11\n38 59 999999 199 283 4849 1000000 2 554\n39 94\n3 9\n1 39\n39 40\n40 292\n5399 5858\n292 4...
UNKNOWN
PYTHON3
CODEFORCES
50
6c621b042edda2efa0b07e0276d2de62
Ilya and Diplomas
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly...
[ "n = int(input())\r\na1, b1 = map(int, input().split())\r\na2, b2 = map(int, input().split())\r\na3, b3 = map(int, input().split())\r\n\r\nres = [a1,a2,a3]\r\nif sum(res) < n: res[0] += min(b1-a1, n-sum(res))\r\nif sum(res) < n: res[1] += min(b2-a2, n-sum(res))\r\nif sum(res) < n: res[2] += n-sum(res)\r\nprint(\" \...
{"inputs": ["6\n1 5\n2 6\n3 7", "10\n1 2\n1 3\n1 5", "6\n1 3\n2 2\n2 2", "55\n1 1000000\n40 50\n10 200", "3\n1 1\n1 1\n1 1", "3\n1 1000000\n1 1000000\n1 1000000", "1000\n100 400\n300 500\n400 1200", "3000000\n1 1000000\n1 1000000\n1 1000000", "11\n3 5\n3 5\n3 5", "12\n3 5\n3 5\n3 5", "13\n3 5\n3 5\n3 5", "3000000\n1000...
UNKNOWN
PYTHON3
CODEFORCES
151
6c6b2a5d327c870946b66c611f883ca5
Array
Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of *n*, containing only integers from 1 to *n*. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beaut...
[ "t,a,b,M,I=int(input()),1,1,1000000007,1000000005\nfor i in range(1,t):\n a=a*i%M\na=pow(a,I,M)\nfor i in range(t+1,t*2):\n b=b*i%M\nprint(((2*a*b)%M-t)%M)\n \t\t\t\t \t\t\t\t\t\t\t \t\t\t \t \t\t\t\t \t\n \t \t \t \t \t\t \t\t \t \t \t", "import sys\n\nreadline = sys.stdin.readline\n\n\nMOD = 10...
{"inputs": ["2", "3", "12", "19", "20", "26", "35", "38", "42", "82", "388", "691", "1000", "1300", "1589", "1885", "2197", "2490", "2798", "49948", "52402", "54904", "57500", "59913", "62467", "64922", "67491", "69942", "72484", "74977", "77461", "79964", "82463", "84999", "87440", "89915", "92481", "94962", "97469", ...
UNKNOWN
PYTHON3
CODEFORCES
16
6c7887430d8f0c8d26269c0b9a7af34e
You're a Professional
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be...
[ "n,kitten,t= map(int, input().split())\r\na=[str(input()) for i in range(n)]\r\nq=0\r\nfor i in range(kitten):\r\n l=0\r\n for j in range(n):\r\n if (a[j][i]==\"Y\"):\r\n l+=1\r\n if (l >= t):\r\n q+=1\r\nprint(q)", "f,I,t=map(int,input().split())\r\nd=[0]*I\r\nfor i in range(f):...
{"inputs": ["3 3 2\nYYY\nNNN\nYNY", "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN", "3 5 2\nNYNNY\nYNNNN\nNNYYN", "1 10 1\nYYYNYNNYNN", "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN", "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN", "10 10 10\nYYYYYYYYYY\nYYYYY...
UNKNOWN
PYTHON3
CODEFORCES
16
6c919e2b0df67554198028b21a7e301e
First Digit Law
In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgeho...
[ "import sys\nimport math\n\nreadline = sys.stdin.readline\n\nN, K = 0, 0\nquery = []\ntable = [0]\n\n\ndef read_input():\n global N, K\n N = int(readline().strip())\n for _ in range(N):\n query.append([int(w) for w in readline().split()])\n K = int(readline().strip())\n for i in range(21):\n ...
{"inputs": ["1\n1 2\n50", "2\n1 2\n9 11\n50", "3\n2 9\n20 99\n5 5\n0", "3\n2 9\n20 99\n5 5\n100", "1\n1 1\n100", "4\n1 100\n11 19\n101 199\n15 15\n100", "10\n10 17\n10 12\n3 6\n17 18\n6 15\n9 18\n3 10\n10 15\n17 19\n2 13\n59", "10\n5 20\n13 16\n12 30\n7 16\n10 29\n21 21\n22 26\n14 22\n2 10\n1 29\n48", "15\n11 20\n16 18...
UNKNOWN
PYTHON3
CODEFORCES
4
6ca98a9abcdc68bfd325eb090fa72aab
New Year Cards
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has *n* friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to *n* in the order in which they send the cards. Le...
[ "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nN = int(input...
{"inputs": ["4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "2\n1 2\n2 1\n2 1", "3\n1 2 3\n2 3 1\n1 3 2\n3 2 1", "5\n1 4 2 3 5\n5 1 3 4 2\n3 2 4 1 5\n1 4 5 3 2\n5 2 3 4 1\n5 4 2 1 3", "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 ...
UNKNOWN
PYTHON3
CODEFORCES
6
6cb4576303d3b40dbf510002d41cd3b1
Andrey and Problem
Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choo...
[ "# Contest: 20 - 2100 <= Codeforces Rating <= 2199 (https://a2oj.com/ladder?ID=20)\n# Problem: (16) Andrey and Problem (Difficulty: 4) (http://codeforces.com/problemset/problem/442/B)\n\ndef rint():\n return int(input())\n\n\ndef rints():\n return list(map(int, input().split()))\n\n\nn = rint()\np = sorted((f...
{"inputs": ["4\n0.1 0.2 0.3 0.8", "2\n0.1 0.2", "1\n0.217266", "2\n0.608183 0.375030", "3\n0.388818 0.399762 0.393874", "4\n0.801024 0.610878 0.808545 0.732504", "5\n0.239482 0.686259 0.543226 0.764939 0.401318", "6\n0.462434 0.775020 0.479749 0.373861 0.492031 0.746333", "7\n0.745337 0.892271 0.792853 0.892917 0.76824...
UNKNOWN
PYTHON3
CODEFORCES
28
6cd6eb131d7d6138089bf3122403faa6
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
[ "n=int(input())\nd={}\nl=[]\nfor test in range(n):\n\ta,b=input().split()\n\tl.append((a,b))\n\td[a]=int(b)+d.get(a,0)\nm=0\nfor item in d.items():\n\tm=max(m,item[1])\nd={}\nx=[]\nfor a,b in l:\n\tc=int(b)+d.get(a,0)\n\td[a]=c\n\tif(c>=m):\n\t\tx.append(a)\nr=\"\"\nfor c in x:\n\tif d[c]==m:\n\t\tr=c\n\t\tbreak\np...
{"inputs": ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5", "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerb...
UNKNOWN
PYTHON3
CODEFORCES
296
6cefe83344a570d72979ed5ace1b0015
Alyona and copybooks
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ...
[ "n, a, b, c = map(int, input().split())\nto_buy = (4 - (n % 4)) % 4\nb = min(a * 2, b)\nc = min(a * 3, a + b, c)\n\n# possibilities:\nif to_buy == 3:\n print(min(3*a, a+b, c))\nelif to_buy == 2:\n print(min(2*a, b, 2*c))\nelif to_buy == 1:\n print(min(a, b+c, 3*c))\nelse:\n print(0)\n", "n,a,b,c=map(i...
{"inputs": ["1 1 3 4", "6 2 1 1", "4 4 4 4", "999999999 1000000000 1000000000 1000000000", "1016 3 2 1", "17 100 100 1", "17 2 3 100", "18 1 3 3", "19 1 1 1", "999999997 999999990 1000000000 1000000000", "999999998 1000000000 999999990 1000000000", "634074578 336470888 481199252 167959139", "999999999 1000000000 100000...
UNKNOWN
PYTHON3
CODEFORCES
142
6cf2d7404c1710c85dd4176b03c54664
Summer Camp
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
[ "s=\"\"\r\nfor i in range(1,1000):\r\n f=str(i)\r\n s=s+f\r\nn=int(input())\r\nprint(s[n-1])\r\n", "\r\n\r\ns = ''\r\nfor i in range(1,371):\r\n s+=str(i)\r\ndef solve():\r\n n = int(input())\r\n print(s[n-1])\r\nfor _ in range(1):\r\n solve()\r\n", "a = int(input())\r\ns = \"\"\r\ni = 1\r\nwhile ...
{"inputs": ["3", "11", "12", "13", "29", "30", "1000", "999", "100", "123", "8", "157", "289", "179", "942", "879", "394", "423", "952", "121", "613", "945", "270", "781", "453", "171", "643", "570", "750", "500", "2", "1", "108", "500", "189", "491", "191"], "outputs": ["3", "0", "1", "1", "9", "2", "3", "9", "5", "6"...
UNKNOWN
PYTHON3
CODEFORCES
368
6d148cae240f77dfadc8aeb8612faf2f
Lucky Numbers
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. The only lin...
[ "a=int(input())\r\nprint(2*((2**a)-1))", "n = int(input())\r\nprint(sum(2**x for x in range(1,n+1)))\r\n", "n = int(input())\r\nz=0\r\nwhile n!=0:\r\n z=z+2**n\r\n n=n-1\r\nprint(z) \n# Sat Sep 23 2023 11:38:26 GMT+0300 (Moscow Standard Time)\n", "n = int(input())\r\na1 =2 \r\nr =2 \r\nprint(a1*(1-r**n...
{"inputs": ["2", "1", "3", "5", "12", "34", "43", "49", "54", "55"], "outputs": ["6", "2", "14", "62", "8190", "34359738366", "17592186044414", "1125899906842622", "36028797018963966", "72057594037927934"]}
UNKNOWN
PYTHON3
CODEFORCES
58
6d1cac7373c96ae8858afbefb263bce5
Pangram
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi...
[ "n = int(input())\r\nstr = input()\r\ns = set(str.lower())\r\nif len(s) == 26: print(\"YES\")\r\nelse: print(\"NO\")", "n = int(input())\r\n\r\ns= input()\r\ns = s.lower()\r\n\r\n\r\nalphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nfor i in alphabet:\r\n c = s.count(i)\r\n if c < 1:\r\n print('NO')\r\n ...
{"inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "1\na", "26\nqwertyuiopasdfghjklzxcvbnm", "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "48\nthereisasyetinsufficientdataforameaningfulanswer", "30\nToBeOrNotToBeThatIsTheQuestion", "30\njackdawslovemybigsphinxofquarz", "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY"...
UNKNOWN
PYTHON3
CODEFORCES
568
6d2e99edaf65af436e74bf409494fe5b
Very Beautiful Number
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office. The teacher remembers that the "very beau...
[ "def mypow(a,b,c):\r\n ans = 1\r\n while b:\r\n if b&1:\r\n ans*=a%c\r\n b>>=1\r\n a*=a%c\r\n return ans\r\na, b = map(int, input().split())\r\nu = 10 * b - 1\r\nv = mypow(10, a - 1, u) - b\r\nfor y in range(b, 10):\r\n if (y * v) % u == 0:\r\n q = d = 9 * y\r\n ...
{"inputs": ["6 5", "1 2", "6 4", "11 1", "42 5", "36 5", "56 3", "88 9", "81 7", "100 1", "58 6", "3282 5", "24002 7", "8140 7", "23910 4", "11478 4", "12818 8", "999999 8", "100002 4", "337 6", "11389 6", "1000000 3", "1000000 1", "2 7", "1 1"], "outputs": ["142857", "Impossible", "102564", "11111111111", "10204081632...
UNKNOWN
PYTHON3
CODEFORCES
7
6d5221a978b652defdeae7f5e3469cac
Levko and Permutation
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g...
[ "import sys\r\nn,k=map(int,input().split())\r\na=[]\r\nif(n==k):\r\n print(\"-1\")\r\n sys.exit()\r\nfor i in range(n):\r\n a.append(i+1)\r\nfor j in range(n-k-1):\r\n a[j],a[j+1]=a[j+1],a[j]\r\nprint(*a)", "import sys\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w...
{"inputs": ["4 2", "1 1", "7 4", "10 9", "10000 5000", "7 0", "1 0", "7 7", "100000 47", "100000 100000", "100000 43425", "7 6", "100000 99999", "47 46", "5 0", "4 2", "1533 1052", "81314 52747", "17767 145", "18168 7942", "26593 15915", "26593 8877", "13852 12727", "4 1", "8834 8834", "8485 8484", "14564 14564", "8254...
UNKNOWN
PYTHON3
CODEFORCES
108
6d5b1c026ba6c1af6fba85c8d6e409bb
Purification
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and the columns are numbered 1 through *n* from left to right. At the far side...
[ "import traceback\r\nimport math\r\nfrom collections import defaultdict\r\nfrom functools import lru_cache\r\n\r\n\r\ndef main():\r\n N = int(input())\r\n grid = []\r\n for _ in range(N):\r\n s = input()\r\n grid.append(s)\r\n \r\n if all('.' in [grid[i][j] for j in range(N)] for i in r...
{"inputs": ["3\n.E.\nE.E\n.E.", "3\nEEE\nE..\nE.E", "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE", "3\n.EE\n.EE\n.EE", "5\nEE.EE\nEE..E\nEEE..\nEE..E\nEE.EE", "1\nE", "8\nE.EEE..E\nEEE.E.E.\nEEE.E.E.\nEE.E.E..\nE...EE..\nE.EE....\n..EE....\nE..E.EE.", "17\nEE...E.EE.EE..E..\nE.....EE..E..E..E\nEEEE.EEEE..E..E.E\n.E.E.EEE.EEEE...
UNKNOWN
PYTHON3
CODEFORCES
21
6dadd620920edfb1edbee1553bb820ee
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string,...
[ "n,m = list(map(int, input().split(\" \")))\nstrings = []\nfor i in range(n): \n\tstrings.append(input())\n\nspec = set('#*&')\ndig = set('0123456789')\nalpha = set('abcdefghijklmnopqrstuvwxyz')\n\n\ndef num(checkset, checkstring):\n\tm = len(checkstring)+1\n\tfor i, c in enumerate(checkstring):\n\t\tif c in checks...
{"inputs": ["3 4\n1**2\na3*0\nc4**", "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "5 2\n&l\n*0\n*9\n*#\n#o", "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#t&2w#jbqb\nwfo&#&***0xp#&hp\njbw##h*###nkmkdn\nqrn*&y#3cnf&d*rc\nend*zg&0f*&g*&ak\niayh&r#8om#o**yq\nwym&e&*v0j&#zono\ntzu*vj&i...
UNKNOWN
PYTHON3
CODEFORCES
43
6dd4ecd12771553ae125882e94ff943c
Significant Cups
Stepan is a very experienced olympiad participant. He has *n* cups for Physics olympiads and *m* cups for Informatics olympiads. Each cup is characterized by two parameters — its significance *c**i* and width *w**i*. Stepan decided to expose some of his cups on a shelf with width *d* in such a way, that: - there is ...
[ "from functools import cmp_to_key\r\n\r\ndef comparator(a, b) :\r\n if a[0] > b[0] :\r\n return -1\r\n if a[0] < b[0] :\r\n return 1\r\n if a[1] < b[1] :\r\n return -1\r\n if a[1] > b[1] :\r\n return 1\r\n return 0\r\n\r\nn, m, d = list(map(int, input().split()))\r\na = []...
{"inputs": ["3 1 8\n4 2\n5 5\n4 2\n3 2", "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "2 2 2\n5 3\n6 3\n4 2\n8 1", "10 10 229\n15 17\n5 4\n4 15\n4 17\n15 11\n7 6\n5 19\n14 8\n4 1\n10 12\n20 13\n20 14\n16 13\n7 15\n2 16\n11 11\n19 20\n6 7\n4 11\n14 16", "10 20 498\n40 12\n23 25\n20 9\n8 1\n23 8\n31 24\n33 2\n22 33\n4 13...
UNKNOWN
PYTHON3
CODEFORCES
2
6df7a596947d9d0d3c1607821180ca35
Beautiful Paintings
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ...
[ "\"\"\"\r\n Bismillahir Rahmanir Rahim\r\n A |-| |\\| A F\r\n\"\"\"\r\nfrom collections import defaultdict\r\n\r\nn = int(input())\r\nar = list(map(int, input().split()))\r\nar.sort()\r\nchk = defaultdict(lambda : 0)\r\nans = []\r\nfor i in range(0, n):\r\n if not chk[i]:\r\n ans.append(ar[i])\r\n ...
{"inputs": ["5\n20 30 10 50 40", "4\n200 100 100 200", "10\n2 2 2 2 2 2 2 2 2 2", "1\n1000", "2\n444 333", "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12...
UNKNOWN
PYTHON3
CODEFORCES
97
6dfc961b9b9cd5602504e14fc0fb01c4
Finding Team Member
There is a programing contest named SnakeUp, 2*n* people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct. Every contestant hopes that he can find...
[ "n = int(input())\r\nstrengths = []\r\nfor i in range(1, 2 * n):\r\n strengths.append(list(map(int, input().split())))\r\n\r\n# Initialize the teammates array\r\nteammates = [0] * (2 * n)\r\n\r\n# Sort the strengths in descending order\r\npairs = []\r\nfor i in range(1, 2 * n):\r\n for j in range(i):\r\n ...
{"inputs": ["2\n6\n1 2\n3 4 5", "3\n487060\n3831 161856\n845957 794650 976977\n83847 50566 691206 498447\n698377 156232 59015 382455 626960", "3\n8\n1 6\n14 13 15\n4 2 11 9\n12 5 3 7 10", "1\n1000000", "3\n1000000\n999999 999998\n999997 999996 999995\n999994 999993 999992 999991\n999990 999989 999988 999987 999986"], "...
UNKNOWN
PYTHON3
CODEFORCES
7
6dfcac919c08dffa6e6836e1c3a3b8ed
Sequence Formatting
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected ...
[ "s = input()\r\nlst = []\r\ni = 0\r\nwhile i < len(s):\r\n if s[i].isdigit():\r\n num = ''\r\n while i < len(s) and s[i].isdigit():\r\n num += s[i]\r\n i += 1\r\n lst.append(num)\r\n continue\r\n if s[i] == '.':\r\n lst.append('...')\r\n i += 2\r...
{"inputs": ["1,2 ,3,..., 10", "1,,,4...5......6", ",,,,,,,,,,,,,", "123456789", ",", "1 4 5 6 7 999 1 1 1 2 311111111111111111111111111111111111111111", "1,2,,,,,,,,,5566", "...,", ",,", ",...,", "1...10", ", ,", "1235634615111235634615111235634615111235634615111235634615111235634...
UNKNOWN
PYTHON3
CODEFORCES
14
6e0b77cb8cb7c6adcab680be206a2647
Points and Powers of Two
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any sub...
[ "from sys import stdin\r\ninput = stdin.readline\r\n\r\ndef solve():\r\n n = int(input())\r\n x = [int(x) for x in input().split()]\r\n s = set(x)\r\n ans = [x[0]]\r\n for i in range(n):\r\n for j in range(0, 32):\r\n if x[i] + 2**j in s:\r\n ans = [x[i], x[i] + 2**j]...
{"inputs": ["6\n3 5 4 7 10 12", "5\n-1 2 5 8 11", "1\n42", "3\n0 -536870912 536870912", "2\n536870912 -536870912", "3\n1 2 3", "4\n1 2 3 8", "2\n1 2", "3\n0 1 2", "2\n-3 -2", "2\n-4 -2", "2\n2 1", "1\n1", "3\n0 2 6", "3\n2 4 8", "2\n1 0", "3\n5 6 7", "3\n-1 1 0"], "outputs": ["3\n3 4 5 ", "1\n-1 ", "1\n42 ", "3\n-53687...
UNKNOWN
PYTHON3
CODEFORCES
33
6e0bc12d128f12665442cb838644357e
Giga Tower
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it ...
[ "def c(a):\r\n if str(a).find(\"8\")==-1:\r\n return False \r\n else:\r\n return True\r\n\r\na=int(input())\r\nk=0\r\nwhile True:\r\n a+=1; k+=1\r\n if c(a):break\r\n\r\nprint(k)\r\n", "n=int(input())+1\r\ns=1\r\nwhile '8' not in str(n):\r\n n+=1\r\n s+=1\r\nprint(s)", "n = int(in...
{"inputs": ["179", "-1", "18", "-410058385", "-586825624", "852318890", "919067153", "690422411", "-408490162", "-8", "-6", "-4", "-2", "0", "2", "4", "6", "8", "1000000000", "-1000000000", "88888", "89", "-80000000", "-8888", "-17", "78", "-19", "-999999998", "-999999997", "999999997", "811111111", "-8", "-5", "-7", "...
UNKNOWN
PYTHON3
CODEFORCES
325
6e0dc02ba7291c453c2ec9afee5215ce
Petya and Exam
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno...
[ "import sys\r\ninput=sys.stdin.readline\r\nc=input().rstrip()\r\ncan=set(list(c))\r\ncannot=set([chr(i) for i in range(ord(\"a\"),ord(\"z\")+1)])-can\r\npattern=input().rstrip()\r\ntmp=(\"*\" in pattern)\r\nq=int(input())\r\nfor _ in range(q):\r\n s=input().rstrip()\r\n ls=len(s)\r\n p=pattern\r\n l=len(p)\r\n ...
{"inputs": ["ab\na?a\n2\naaa\naab", "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "s\nc*?cb\n26\nbbaa\nb\ncc\ncbaab\nacacc\nca\na\nc\ncb\nabb\nba\nb\nba\ncac\nccccb\nccb\nbbbc\nabbcb\na\nbc\nc\na\nabb\nca\ncacb\nac", "o\n*\n28\nbac\nbcc\ncbcb\ncaabc\ncb\nacab\ncbccb\ncbccc\nc\nbbaa\ncaaaa\nbbc\nba\nc\ncacbc\ncbab\na...
UNKNOWN
PYTHON3
CODEFORCES
8
6e3a93f64f548eb3db06492d2471a959
Alex and broken contest
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ...
[ "s=input()\r\ncnt=s.count(\"Danil\")+s.count(\"Olya\")+s.count(\"Slava\")+s.count(\"Nikita\")+s.count(\"Ann\") \r\nprint(\"YES\" if cnt == 1 else \"NO\")", "import re\n\nstr = 'Danil|Olya|Slava|Ann|Nikita'\nif (len(re.findall(str, input())) == 1):\n print('YES')\nelse:\n print('NO')\n \t \t\t\t \t\t\t\t \t ...
{"inputs": ["Alex_and_broken_contest", "NikitaAndString", "Danil_and_Olya", "Slava____and_the_game", "Olya_and_energy_drinks", "Danil_and_part_time_job", "Ann_and_books", "Olya", "Nikita", "Slava", "Vanya", "I_dont_know_what_to_write_here", "danil_and_work", "Ann", "Batman_Nananananananan_Batman", "Olya_Nikita_Ann_Slav...
UNKNOWN
PYTHON3
CODEFORCES
246
6e5afbd84d28e58ac91f81bf4f65bc6c
Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for th...
[ "import math\nn = int(input())\nans = 1\nwhile int(bin(ans)[2:]) <= n:\n ans += 1\nprint(ans-1)", "__author__ = 'Darren'\r\n\r\n\r\ndef solve():\r\n str_n = input()\r\n len_n = len(str_n)\r\n count = 0\r\n ord_1, ord_2 = ord('1'), ord('2')\r\n for i in range(len_n):\r\n if ord(str_n[i]) >...
{"inputs": ["10", "20", "72", "99", "100", "101", "102", "111", "112", "745", "23536", "1", "1010011", "312410141", "1000000000", "999999999", "111111111", "101010101", "121212121", "106341103", "901556123", "832513432", "3", "732875234", "7", "9", "2", "11", "12", "13", "101020101", "111100100", "110110101", "10011100...
UNKNOWN
PYTHON3
CODEFORCES
156
6e8114ca264a25df7a13855f7cf6b174
Palindrome
Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long as possible. The only line of the input contains one string *s* of length *n* (1<=≤<=*n*<=≤<=5·...
[ "from collections import defaultdict\n\ns = input()\nn = len(s)\n\nif n >= 2600:\n print(s[0] * 100)\nelif n > 2574:\n count = defaultdict(int)\n for l in s:\n count[l] += 1\n max_l = s[0]\n for l, c in count.items():\n if c >= 100:\n max_l = l\n print(max_l * 100)\n\nelse...
{"inputs": ["bbbabcbbb", "rquwmzexectvnbanemsmdufrg", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "ab", "abacaba", "star...
UNKNOWN
PYTHON3
CODEFORCES
1
6e860da383f076b1aad581c40df6343a
Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size *w*<=×<=*h*, represented by a rectangle with corners (0,<=0), (*w*,<=0), (*w*,<=*h*) and (0,<=*h*). It can be seen that no collisions will happen before one enters the stage. ...
[ "# https://codeforces.com/problemset/problem/848/B\r\n\r\ndef push(d, val, type_, arr):\r\n # pos index\r\n type_ %= 2\r\n if val not in d:\r\n d[val] = [[],[]]\r\n d[val][type_].append(arr)\r\n\r\nd = {}\r\n\r\nn, w, h = map(int, input().split())\r\nfor index in range(n):\r\n g, p, t = map(in...
{"inputs": ["8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1", "3 2 3\n1 1 2\n2 1 1\n1 1 5", "1 10 10\n1 8 1", "3 4 5\n1 3 9\n2 1 9\n1 2 8", "10 500 500\n2 88 59\n2 470 441\n1 340 500\n2 326 297\n1 74 45\n1 302 273\n1 132 103\n2 388 359\n1 97 68\n2 494 465", "20 50000 50000\n2 45955 55488\n1 19804 293...
UNKNOWN
PYTHON3
CODEFORCES
8
6e98357b8c0bdb3110306bd85830da4a
Convert to Ones
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for examp...
[ "import math\r\nimport sys\r\nimport queue\r\n\r\n\r\ndef solve():\r\n n, x, y = map(int, input().split())\r\n s = str(input())\r\n\r\n subsq = 1\r\n zeros = int(s[0] == \"0\")\r\n for i in range(1, n):\r\n if s[i] != s[i - 1]:\r\n subsq += 1\r\n if s[i] == \"0\":\r\n ...
{"inputs": ["5 1 10\n01000", "5 10 1\n01000", "7 2 3\n1111111", "1 60754033 959739508\n0", "1 431963980 493041212\n1", "1 314253869 261764879\n0", "1 491511050 399084767\n1", "2 163093925 214567542\n00", "2 340351106 646854722\n10", "2 222640995 489207317\n01", "2 399898176 552898277\n11", "2 690218164 577155357\n00", ...
UNKNOWN
PYTHON3
CODEFORCES
118
6e9dcbd071b375bcf1238a31296b6008
Bear and Big Brother
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
[ "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 19 15:47:18 2023\r\n\r\n@author: lenovo\r\n\"\"\"\r\n\r\na,b=map(int,input().split())\r\ns=0\r\nwhile a<=b:\r\n a*=3\r\n b*=2\r\n s=s+1\r\nprint(s)\r\n", "sign = True\r\na,b = map(int,input().split())\r\nyear = 0\r\nwhile sign:\r\n a *= 3\r\n ...
{"inputs": ["4 7", "4 9", "1 1", "4 6", "1 10", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "2 9", "2 10", "3 3", "3 4", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "4 4", "4 5", "4 6", "4 7", "4 8", "4 9", "4 10", "5 5", "5 6", "5 7", "5 8", "5...
UNKNOWN
PYTHON3
CODEFORCES
631
6eb3acd71c00c75cca50a5dd39bc7fab
Defining Macros
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T...
[ "P, A, S, M, D = 1, 2, 4, 8, 16\r\nADD = A | S\r\nANY = A | S | M | D\r\nOP_BIT = {\"+\": A, \"-\": S, \"*\": M, \"/\": D, \")\": 0}\r\nUNSAFE_BEFORE = {P: 0, A: 0, S: ADD, M: ADD, D: ANY}\r\nUNSAFE_AFTER = {P: 0, A: 0, S: 0, M: ADD, D: ADD}\r\nmacro = dict()\r\ndef expr(chars,\r\n pseudo=P,\r\n exp...
{"inputs": ["1\n#define sum x + y\n1 * sum", "1\n#define sum (x + y)\nsum - sum", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/Denomina...
UNKNOWN
PYTHON3
CODEFORCES
2
6ec23bfaec147ed3968f9eb421419a85
Sorting Railway Cars
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor...
[ "n = int(input())\r\nnums = list(map(int, input().split()))\r\nnote_nums = sorted([(val, idx) for idx, val in enumerate(nums)])\r\ntmp = [0] * n\r\nfor i in range(n):\r\n tmp[note_nums[i][1]] = i\r\nans = [0] * (n + 1)\r\nfor val in tmp:\r\n ans[val + 1] = ans[val] + 1\r\nprint(n - max(ans))", "n = int(inpu...
{"inputs": ["5\n4 1 2 5 3", "4\n4 1 3 2", "1\n1", "2\n1 2", "2\n2 1", "6\n5 3 6 1 4 2", "7\n1 2 3 6 7 4 5", "8\n6 2 1 8 5 7 3 4", "3\n1 2 3", "3\n1 3 2", "3\n2 1 3", "3\n2 3 1", "3\n3 1 2", "3\n3 2 1", "7\n1 3 5 7 2 4 6", "7\n1 5 2 6 3 7 4", "5\n1 4 2 3 5", "9\n1 6 4 5 9 8 7 3 2", "10\n5 1 6 2 8 3 4 10 9 7", "50\n39 8 ...
UNKNOWN
PYTHON3
CODEFORCES
82
6eec6d76e2ac4d80c0ce716c2185a9b9
Lizards and Basements 2
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the las...
[ "__author__ = 'Darren'\r\n\r\n\r\ndef solve():\r\n n, a, b = map(int, input().split())\r\n h = [0]\r\n h.extend(map(int, input().split()))\r\n\r\n fires = []\r\n count = h[1] // b + 1 if h[1] >= 0 else 0\r\n fires.extend([2 for i in range(count)])\r\n h[1] -= b * count\r\n h[2] -= a * count\...
{"inputs": ["3 2 1\n2 2 2", "4 3 1\n1 4 1 1", "3 5 3\n1 2 1", "3 5 3\n3 2 2", "3 5 3\n3 2 2", "3 5 1\n10 10 10", "3 5 3\n10 9 7", "3 5 1\n1 9 10", "3 5 3\n10 9 7", "3 5 2\n9 3 6", "4 5 3\n2 2 2 1", "4 5 3\n2 3 2 2", "4 5 3\n4 2 4 2", "4 5 1\n4 9 1 8", "4 5 3\n9 9 3 4", "4 5 1\n8 8 9 8", "4 5 3\n10 10 10 10", "4 5 2\n7 ...
UNKNOWN
PYTHON3
CODEFORCES
5
6ef0e2137716f500bd93702edd34f22b
Propagating tree
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of *n* nodes numbered from 1 to *n*, each node *i* having an initial value *a**i*. The root of the tree is node 1. This tree has a special property: when a value *val* is added to a value of node *i*, the ...
[ "class BIT():\r\n \"\"\"区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する\r\n add: 区間[begin, end)にvalを加える\r\n get_val: i番目(0-indexed)の値を求める\r\n \"\"\"\r\n def __init__(self, n):\r\n self.n = n\r\n self.bit = [0] * (n + 1)\r\n\r\n def get_val(self, i):\r\n i = i + 1\r\n s = 0\r\n ...
{"inputs": ["5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4", "10 10\n137 197 856 768 825 894 86 174 218 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1\n1 8 631\n2 4\n1 7 244", "10 10\n418 45 865 869 745 901 177 773 854 462\n4 8\n1 4\n3 6\n1 5\n1 10...
UNKNOWN
PYTHON3
CODEFORCES
1
6ef6aa8c3cea245a90dd5d88c9e3b6e7
Captains Mode
Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that the greatest responsibility lies on him, so he wants to resort to the analys...
[ "n = int(input())\r\ns = list(map(int, input().split()))\r\nm = int(input())\r\ns.sort(reverse=True)\r\nchoose = []\r\nteam = []\r\nfor _ in range(m):\r\n choose1, team1 = input().split()\r\n choose.append(choose1)\r\n team.append(team1)\r\ndp = [0] * (1 << 21)\r\nfor i in range(1, 1 << m):\r\n t = m - ...
{"inputs": ["2\n2 1\n2\np 1\np 2", "6\n6 4 5 4 5 5\n4\nb 2\np 1\nb 1\np 2", "4\n1 2 3 4\n4\np 2\nb 2\np 1\nb 1", "4\n1 2 3 5\n4\nb 2\np 1\np 2\nb 1", "6\n6 7 8 1 2 3\n6\nb 1\np 1\np 2\nb 2\np 2\np 1", "8\n1 2 3 4 5 6 7 8\n6\np 1\np 2\np 2\np 1\np 1\np 2", "8\n1 2 4 8 16 32 64 128\n8\nb 1\np 2\nb 2\np 1\nb 2\np 1\nb 1\n...
UNKNOWN
PYTHON3
CODEFORCES
1
6f1948aa1a3f58e6b1b4feacc7b7e014
Tower of Hanoi
The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the pu...
[ "#\t!/bin/env python3\r\n#\tcoding: UTF-8\r\n\r\n\r\n#\t✪ H4WK3yE乡\r\n#\tMohd. Farhan Tahir\r\n#\tIndian Institute Of Information Technology and Management,Gwalior\r\n\r\n#\tQuestion Link\r\n#\thttps://codeforces.com/problemset/problem/392/B\r\n#\r\n\r\n# ///==========Libraries, Constants and Functions=============...
{"inputs": ["0 1 1\n1 0 1\n1 1 0\n3", "0 2 2\n1 0 100\n1 2 0\n3", "0 2 1\n1 0 100\n1 2 0\n5", "0 5835 1487\n6637 0 9543\n6961 6820 0\n7", "0 3287 5433\n6796 0 5787\n1445 6158 0\n26", "0 4449 3122\n6816 0 8986\n1048 1468 0\n4", "0 913 8129\n8352 0 4408\n9073 7625 0\n30", "0 8392 3430\n5262 0 6256\n8590 8091 0\n29", "0 6...
UNKNOWN
PYTHON3
CODEFORCES
2
6f32c4a1bdb0354e980a56e43f7f70b4
Matrix Walk
There is a matrix *A* of size *x*<=×<=*y* filled with integers. For every , *A**i*,<=*j*<==<=*y*(*i*<=-<=1)<=+<=*j*. Obviously, every integer from [1..*xy*] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells *a*1, *a*2, ..., *a**...
[ "q=int(input())\r\nl=list(map(int,input().split()))\r\nw=set()\r\nfor i in range(1,q):\r\n w.add(abs(l[i]-l[i-1]))\r\nf=1\r\ns=1000000000\r\nif q==1:\r\n print('YES')\r\n print(s,f)\r\n exit()\r\nif 1 in w:\r\n w.remove(1)\r\nif len(w)>1:\r\n print('NO')\r\n exit()\r\nelif 0 in w:\r\n print(...
{"inputs": ["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10", "3\n1 2 2", "1\n1", "1\n6", "2\n2 3", "2\n1000000000 1", "4\n3 2 4 2", "5\n1 2 5 4 3", "2\n1 1", "3\n1 3 4", "1\n1000000000", "6\n1 4 5 6 3 2", "8\n1 2 3 6 9 8 7 6", "9\n4 3 2 1 5 6 7 8 9", "8\n2 5 8 9 6 3 2 1", "4\n1 2 1 3", "3\n1 4 3", "5\n1 2 3 4 1", "6\...
UNKNOWN
PYTHON3
CODEFORCES
1
6f6ba61afc5da72f67d05cadb8e29e00
Hungry Student Problem
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ...
[ "#903A\r\nn = int(input())\r\nfor i in range(n):\r\n x = int(input())\r\n if x%3==0:\r\n print('YES')\r\n elif x %3== 1:\r\n if x >= 7:\r\n print('YES')\r\n else:\r\n print('NO')\r\n else:\r\n if x >=14:\r\n print('YES')\r\n else:\r\n ...
{"inputs": ["2\n6\n5", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n...
UNKNOWN
PYTHON3
CODEFORCES
205
6f88d078f556c38aa64f874a732d49a1
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
[ "\n\nn = int(input())\n\nA = set()\n\nfor _ in range(n):\n x, d = map(int, input().split())\n A.add((x, d))\n\nfound = False\n\nfor x, d in A:\n if (x + d, -d) in A:\n found = True\n\nif found:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "# n,m = map(lambda x: int(x), input().split())\r\n# n...
{"inputs": ["2\n0 1\n1 -1", "3\n0 1\n1 1\n2 -2", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872", "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122...
UNKNOWN
PYTHON3
CODEFORCES
244
6f94033e42e6a08e91be2f6a70cd3a1f
Lakes in Berland
The map of Berland is a rectangle of the size *n*<=×<=*m*, which consists of cells of size 1<=×<=1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, s...
[ "MAX = 55\r\nberland = [None] * MAX\r\ndesberland = [None] * MAX\r\ndr = [-1, 0, 0, 1]\r\ndc = [0, -1, 1, 0]\r\nanswer = []\r\nvisited = [[False for _ in range(MAX)] for _ in range(MAX)]\r\npath = [[0 for _ in range(MAX)] for _ in range(MAX)]\r\ndef DFSLakes(sr, sc):\r\n global count, total, testEsc\r\n s = [...
{"inputs": ["5 4 1\n****\n*..*\n****\n**.*\n..**", "3 3 0\n***\n*.*\n***", "3 5 1\n.**.*\n*.*.*\n***..", "3 5 0\n.**.*\n*.*.*\n***..", "3 50 7\n***.********.*********************.**********.****\n*...**..*.**.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*..*\n****************.*.********.**********************", "50 3 4\n***\n*.*\n...
UNKNOWN
PYTHON3
CODEFORCES
3
6fa56519080e5ae2d001b4538fae2064
Less or Equal
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$. Note that the sequence can contain equal elements. If there is no suc...
[ "n,k = map(int,input().split())\r\nl = sorted(list(map(int,input().split())))\r\na = [1] + l\r\nprint(a[k] if k == n or a[k + 1] - a[k] else -1)", "#initialize sscenario\r\nn, k = map(int, input().split(' '))\r\nintegers = []\r\n\r\n#makes a list of integers then orders it from highest to lowest\r\nfor integer in...
{"inputs": ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20", "1 0\n1", "1 0\n2", "1 1\n1000000000", "3 0\n3 3 3", "3 0\n2 2 3", "5 0\n3 4 5 6 7", "4 0\n2 3 4 5", "2 2\n1000000000 1000000000", "7 2\n2 7 5 1 10 2 20", "2 1\n1 1", "5 3\n1 3 3 4 5", "4 4\n1000000000 1000000000 1000000000 1000000000"], "outputs": ["5", "-1",...
UNKNOWN
PYTHON3
CODEFORCES
34
6fad140b01b60938c5f1ca7ca0c595c1
A Mist of Florescence
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing." "What is it like?" "Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses. The wood can be represented by a ...
[ "s='ABCD'\r\na=list(map(int,input().split()))\r\nprint(48,50)\r\nfor k in range(4) :\r\n print(s[k]*50)\r\n cnt=0\r\n for i in range(11) :\r\n for j in range(50) :\r\n if i%2==0 and j%2==1 and cnt<a[(k+1)%4]-1 :\r\n print(s[(k+1)%4],end='')\r\n cnt=cnt+1\r\n ...
{"inputs": ["5 3 2 1", "50 50 1 1", "1 6 4 5", "1 1 1 1", "4 8 16 32", "1 1 1 50", "19 58 20 18", "100 100 100 100", "1 1 1 2", "1 1 3 1", "1 4 1 1", "5 1 1 1", "1 4 7 3", "6 2 5 1", "1 5 6 3", "4 1 4 5", "4 5 3 6", "2 5 1 17", "11 4 5 14", "19 19 8 10", "49 49 49 49", "49 50 50 50", "50 50 51 50", "15 63 41 45", "45 3...
UNKNOWN
PYTHON3
CODEFORCES
37
6fcc6e981568cc6fcb2d4525c65fed0a
Queries for Number of Palindromes
You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which a...
[ "import sys\r\nfrom array import array\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\ns, out = input(), array('i')\r\nn = len(s)\r\ndp = [array('i', [1] * n) for _ in range(n)]\r\npre = array('i', [1] * n)\r\n\r\nfor i in range(2, n + 1):\r\n for j in range(n - i + 1):\r\n l, r = j...
{"inputs": ["caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5", "a\n100\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1...
UNKNOWN
PYTHON3
CODEFORCES
1
6fd7e39fbfb49f8c3355674346e9c9e3
none
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ...
[ "import sys\n# sys.stdin = open(\".in\", \"r\")\n# sys.stdout = open(\".out\", \"w\")\ninput = sys.stdin.readline\ndef print(*args, end='\\n', sep=' ') -> None:\n sys.stdout.write(sep.join(map(str, args)) + end)\ndef map_int():\n return map(int, input().split())\ndef list_int():\n return list(map(int, inpu...
{"inputs": ["3\n7 1 3\n1 2 1", "4\n5 10 3 2\n2 3 2 4", "3\n1 1000000000 2\n1 2 1000000000", "2\n4 5\n10 8", "4\n14 12 10 17\n8 6 5 10", "5\n1 15 61 29 43\n15 11 19 19 19", "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13", "2\n1000000000 1000000000\n1 1", "3\n1 1 1\n1 1 1"], "outputs": ["2.000000000000",...
UNKNOWN
PYTHON3
CODEFORCES
126
6fda7a991fde3dff8210e9177cbb9d24
Lightsabers (easy)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
[ "import io, os, sys\r\n\r\npypyin = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\ncpyin = sys.stdin.readline\r\ninput = pypyin if 'PyPy' in sys.version else cpyin\r\n\r\ndef strput():\r\n return input().decode() if 'PyPy' in sys.version else input()\r\n\r\n# code starts here\r\n\r\ndef main():\r\n n...
{"inputs": ["5 2\n1 1 2 2 1\n1 2", "1 1\n1\n1", "2 1\n1 1\n1", "2 1\n1 1\n2", "2 2\n1 2\n1 1", "3 3\n1 1 3\n0 1 2", "4 4\n2 3 3 2\n0 0 1 0", "2 2\n2 2\n0 2", "3 3\n1 1 3\n0 1 1", "4 4\n2 4 4 3\n1 1 1 1", "2 2\n2 1\n0 1", "3 3\n3 1 1\n1 1 1", "4 4\n1 3 1 4\n1 0 0 1", "2 2\n2 1\n1 0", "3 3\n3 1 1\n2 0 0", "4 4\n4 4 2 2\n...
UNKNOWN
PYTHON3
CODEFORCES
10
6fef8e4304c116331fb41daf0b0b2c4b
Bear and Different Names
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names...
[ "names = [i for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] + [ 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'[i:i+2] for i in range(0, len('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'), 2)]\r\nn, k = map(int, input().split())\r\nyes_no = input().split()\r\nguess = names[:n]\r\nfor i in range(len(yes_no)):...
{"inputs": ["8 3\nNO NO YES YES YES NO", "9 8\nYES NO", "3 2\nNO NO", "2 2\nYES", "2 2\nNO", "7 2\nYES NO YES YES NO YES", "18 7\nYES YES YES YES YES YES YES NO NO NO NO NO", "50 3\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
UNKNOWN
PYTHON3
CODEFORCES
48
6ff3cefda98378fc0c21b62cb6ae02e9
Music
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ...
[ "n,m,r=map(int,input().split());o=0\r\nwhile(m<n):\r\n m*=r;o+=1\r\nprint(o)\r\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\nimport math\n\n(T, S, q) = (int(i) for i in input().split())\nstart = time.time()\n\nans = math.log(T/S, q)\nif int(ans) - ans != 0:\n ans = int(ans) + 1\ne...
{"inputs": ["5 2 2", "5 4 7", "6 2 3", "2 1 2", "2 1 3", "2 1 10000", "12326 6163 2", "10000 2500 4", "100000 99999 4", "12351 1223 6", "100000 1 10000", "10028 13 10000", "100000 99999 2", "100000 99999 3", "100000 1 2", "100000 1 3", "100000 1 4", "100000 1 5", "100000 3125 2", "12628 1804 7", "100000 45 13", "100000...
UNKNOWN
PYTHON3
CODEFORCES
92
6ff5c28d8fd9e8778ea5afef93fb2782
Lucky Tree
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tree with *n* vertexes. Besides, the tree was weighted, i. e. each edge ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef get_root(s):\r\n v = []\r\n while not s == root[s]:\r\n v.append(s)\r\n s = root[s]\r\n for i in v:\r\n root[i] = s\r\n return s\r\n\r\ndef unite(s, t):\r\n rs, rt = get_root(s), get_ro...
{"inputs": ["4\n1 2 4\n3 1 2\n1 4 7", "4\n1 2 4\n1 3 47\n1 4 7447", "9\n1 2 7\n1 3 12\n4 1 2\n4 5 4\n4 6 47\n4 7 9\n5 8 2\n5 9 1", "2\n1 2 7", "2\n2 1 1000000000", "9\n1 2 1\n1 3 7\n3 4 19\n3 5 2\n4 6 46\n7 4 25\n5 8 64\n5 9 73", "7\n1 2 47\n1 3 9\n3 7 7\n3 4 2\n3 5 4\n3 6 1", "5\n1 2 1\n2 3 1\n3 4 1\n4 5 2", "7\n1 2 4...
UNKNOWN
PYTHON3
CODEFORCES
2
6ff65660825765bf2edf2a8845293afc
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
[ "#391_A\n\nst = list(input())\n\n#B = 1, u = 2, l = 1, b = 1, a = 2, s = 1, r = 1\n\ndct = {\"B\": 0, \"u\": 0, \"l\": 0, \"b\": 0, \"a\": 0, \"s\": 0, \"r\": 0}\n\nfor i in range(0, len(st)):\n if st[i] in dct:\n dct[st[i]] += 1\n\nn = min(dct[\"B\"], dct[\"u\"] // 2, dct[\"l\"], dct[\"b\"], dct[\"a\"] /...
{"inputs": ["Bulbbasaur", "F", "aBddulbasaurrgndgbualdBdsagaurrgndbb", "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
162
704b7c118ec16d231e3db433b28d05dd
Minimal string
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*...
[ "import math\r\nimport bisect\r\n\r\n\r\ndef getList(method=int):\r\n return list(map(method, input().split()))\r\n\r\n\r\ndef getInt():\r\n return int(input())\r\n\r\n\r\ndef hasGreater(c):\r\n global mp\r\n for k, v in mp.items():\r\n if c > k and v:\r\n return True\r\n return Fal...
{"inputs": ["cab", "acdb", "a", "ab", "ba", "dijee", "bhrmc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba", "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacba...
UNKNOWN
PYTHON3
CODEFORCES
51
70508fa3136cf8b828716a70521f6ef9
Couple Cover
Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a rectangle. A bag with *n* balls, each with an integer written on it, is placed on the table. The first player reaches in and grabs a ball randomly (all balls have equal probability of being chosen) — the num...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\nn = int(input())\r\nl = 3 * pow(10, 6) + 5\r\ncnt = [0] * l\r\nfor i in list(map(int, input().split())):\r\n cnt[i] += 1\r\nc1, c2 = [0] * l, [0] * l\r\nm0 = pow(10, 8)\r\nfor i in range(1, l):\r\n ci = cnt[i]\r\n if i * i < l:\r\n j = i * i\r\...
{"inputs": ["5\n4 2 6 1 3\n4\n1 3 5 8", "2\n5 6\n2\n30 31", "2\n2000000 2000000\n1\n2000000", "1\n1\n1\n5", "10\n18 34 3 49 40 50 53 30 23 44\n10\n246 305 45 212 788 621 449 876 459 899"], "outputs": ["20\n18\n14\n10", "2\n0", "2", "0", "72\n72\n90\n72\n60\n66\n70\n58\n70\n56"]}
UNKNOWN
PYTHON3
CODEFORCES
3
705bd4865fdc3cbea4d14da2c58f73e0
Online Courses In BSU
Now you can take online courses in the Berland State University! Polycarp needs to pass *k* main online courses of his specialty to get a diploma. In total *n* courses are availiable for the passage. The situation is complicated by the dependence of online courses, for each course there is a list of those that must be...
[ "import sys\r\nsys.setrecursionlimit(10 ** 8)\r\n\r\ncycle = False\r\ndef DFS(i, graph, result, visited):\r\n\tglobal cycle\r\n\tstack = [i]\r\n\twhile len(stack) != 0:\r\n\t\tu = stack[-1]\r\n\t\tvisited[u] = 1\r\n\t\tif len(graph[u]) != 0:\r\n\t\t\tv = graph[u].pop()\r\n\t\t\tif visited[v] == 1:\r\n\t\t\t\tcycle ...
{"inputs": ["6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5", "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2", "3 3\n1 2 3\n1 2\n1 3\n1 1", "5 3\n2 1 4\n0\n0\n1 5\n0\n0", "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2", "5 2\n4 5\n2 3 4\n1 4\n1 4\n0\n0", "6 6\n5 4 3 2 6 1\n1 4\n0\n2 2 6\n2 3 6\n3 3 4 6\n0", "6 6\n4 1 6 3 2 5\n2 3 5\n4 1...
UNKNOWN
PYTHON3
CODEFORCES
6
7064cdd96129ae92a071cde28506aecb
Learning Languages
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official la...
[ "n,m = map(int,input().split())\r\narr = []\r\nki = False\r\nfor i in range(n):\r\n\ta = list(map(int,input().split()))\r\n\tset_a = set(());\r\n\tfor j in range (a[0]):\r\n\t\tki=True\r\n\t\tset_a.add(a[j+1])\r\n\tarr.append(set_a)\r\nchange = 0\r\nif ki:\r\n\twhile(change!=-1):\r\n\t\tchanged = -1\r\n\t\tchange =...
{"inputs": ["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0", "2 2\n0\n0", "5 5\n1 3\n0\n0\n2 4 1\n0", "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0", "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1", "8 4\n0\n0\n4 2 3 1 4\n4 2 1 4 3\n3 4 3 1\n1 2\n2 4 1\n2 4 2", "...
UNKNOWN
PYTHON3
CODEFORCES
105
706acd5730014b72a9d13d61f09d85ff
Mister B and Book Reading
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ...
[ "# https://codeforces.com/problemset/problem/820/A\n# 900\n\nc,v0,v1,a,l = map(int, input().split())\n\nd = 0\np = 0\nwhile True:\n p += v0\n d += 1\n if p >= c:\n break\n\n v0 += a\n if v0 > v1:\n v0 = v1\n\n p -= l\n\nprint(d)", "c, v0, v1, a, l = map(int, input().split())\r\n\r\...
{"inputs": ["5 5 10 5 4", "12 4 12 4 1", "15 1 100 0 0", "1 1 1 0 0", "1000 999 1000 1000 998", "1000 2 2 5 1", "1000 1 1 1000 0", "737 41 74 12 11", "1000 1000 1000 0 999", "765 12 105 5 7", "15 2 2 1000 0", "1000 1 1000 1000 0", "20 3 7 1 2", "1000 500 500 1000 499", "1 1000 1000 1000 0", "1000 2 1000 56 0", "1000 2 ...
UNKNOWN
PYTHON3
CODEFORCES
195
7076598337a1b1fdaeeb053b998c22c7
none
Память компьютера состоит из *n* ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до *n* слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, которому она принадлежит). Для каждого процесса известно, что принадлежащие ему ячейки занимают ...
[ "n = int(input())\r\nl = list(map(int, input().split()))\r\nans = 0\r\ncount = 0\r\nd = dict()\r\ns = set()\r\ns1 = set()\r\nfor i in l:\r\n if i in s:\r\n d[i] += 1\r\n else:\r\n d[i] = 1\r\n s.add(i)\r\nfor i in range(n):\r\n if l[i] == 0:\r\n count += 1\r\n else:\r\n ...
{"inputs": ["4\n0 2 2 1", "8\n0 8 8 8 0 4 4 2", "5\n0 0 0 1 1", "6\n0 0 0 3 0 0", "10\n0 10 10 0 0 3 3 0 0 0", "10\n0 9 9 9 9 0 8 8 8 8", "15\n0 0 6 6 0 0 0 0 4 0 0 0 9 0 0", "21\n0 11 11 11 11 0 7 0 12 12 12 12 12 0 19 19 19 0 1 1 1", "24\n0 0 6 6 6 0 22 22 0 23 23 0 19 19 19 19 0 0 17 0 0 3 3 3", "15\n1 1 1 1 5 5 5 4...
UNKNOWN
PYTHON3
CODEFORCES
4
708021a251c01c25860c6d84972d479c
Primes or Palindromes?
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this! Let us remind you...
[ "n = 2 * 10 ** 6 + 10 ** 5\np, q = map(int, input().split(' '))\npi = 0\nsi = 0\npr = [0] * n\npr[1] = 1\nfor i in range(2, n):\n if pr[i] == 0:\n for j in range(i*i, n, i):\n pr[j] = 1\n\nres = 'Palindromic tree is better than splay tree'\nfor i in range(1, n):\n if pr[i] == 0:\n pi ...
{"inputs": ["1 1", "1 42", "6 4", "3 1", "42 1", "10000 239", "5 8", "7 11", "16 60", "214 210", "620 35", "940 480", "1307 3420", "6811 5416", "7 267", "106 6", "10000 10000", "10000 9999", "9999 9998", "9999 9999", "4 9", "1000 10000", "238 9996", "999 10000", "241 10000", "239 10000", "5858 674"], "outputs": ["40", ...
UNKNOWN
PYTHON3
CODEFORCES
33
708287e8934727d8ebe2beebfac85f87
Chtholly's request
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation with...
[ "a, k = map(int, input().split())\r\nsm = 0\r\nfor i in range(1, a + 1):\r\n r = str(i)\r\n sm += int(r + r[::-1])\r\n sm %= k\r\nprint(sm % k)", "k, p = map(int, input().split())\r\nres = 0\r\nfor i in range(1, k+1):\r\n res += int(str(i)+(str(i)[::-1]))\r\n res %= p\r\nprint(res)", "k,p=list(ma...
{"inputs": ["2 100", "5 30", "42147 412393322", "77809 868097296", "5105 443422097", "75615 376679484", "22951 23793302", "12785 993582106", "60276 428978808", "84776 104860385", "41984 653766991", "100000 1000000000", "41163 472310076", "6983 765352180", "33493 967727004", "90898 94010922", "67298 349286579", "92452 2...
UNKNOWN
PYTHON3
CODEFORCES
239
7086902dabc23efb313bf9a8eb66893f
Presents
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
[ "# N,M = map(int,input().split())\r\n# N = int(input())\r\n# A = list(map(int,input().split()))\r\n\r\n\r\nN = int(input())\r\nA = list(map(int,input().split()))\r\n\r\nd = [0] * N\r\nfor i in range(N):\r\n d[A[i]-1] = i+1\r\n\r\nprint(*d)\r\n", "v = int(input())\r\ngivers = list(map(int, input().split()))\r\n...
{"inputs": ["4\n2 3 4 1", "3\n1 3 2", "2\n1 2", "1\n1", "10\n1 3 2 6 4 5 7 9 8 10", "5\n5 4 3 2 1", "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "10\n3 4 5 6 7 8 9 10 1 2", "8\n1 5 3 7 2 6 4 8", "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44...
UNKNOWN
PYTHON3
CODEFORCES
875
709787118e4472b115d8d0cf837ebc30
A Determined Cleanup
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficien...
[ "p,k=input().strip().split(' ')\r\nflag=1\r\np=int(p)\r\nk=int(k)\r\nA=[]\r\nB=[]\t\r\nk=-k\r\nwhile p!=0:\r\n\tA.append(p%k)\r\n\tp//=k\r\n\tif A[-1]<0:\r\n\t\tp+=1\r\nfor i in A:\r\n\tif i<0:\r\n\t\tB.append(i-k);\r\n\telse:\r\n\t\tB.append(i);\r\nprint(len(B))\r\nfor i in B:\r\n\tprint(i,end=\" \")\r\n", "p, k...
{"inputs": ["46 2", "2018 214", "4 2", "5 2", "10 3", "250 1958", "1000000000000000000 2000", "1 2", "2 2", "3 2", "6 2", "7 2", "8 2", "9 2", "10 2", "1 3", "2 3", "3 3", "4 3", "5 3", "6 3", "7 3", "8 3", "9 3", "462 2", "462 3", "2018 4", "20180214 5", "1317 221", "1314 520", "1562 862", "6666666666666666 3", "25252...
UNKNOWN
PYTHON3
CODEFORCES
37
709fd4d9e29409d95b3039b0cf648ced
Correcting Mistakes
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
[ "n = int(input())\r\nS = list(input())\r\nT = list(input())\r\nindex = 0\r\nfor i in range(n):\r\n if S[i] != T[i]:\r\n index = i\r\n break\r\nS = S[index:]\r\nT = T[index:]\r\nn -= index\r\nindex = 0\r\nfor i in range(n-1, -1, -1):\r\n if S[i] != T[i]:\r\n index = i+1\r\n break\r\...
{"inputs": ["7\nreading\ntrading", "5\nsweet\nsheep", "3\ntoy\ntry", "5\nspare\nspars", "1\na\nb", "1\nz\ny", "2\nab\nac", "2\nba\nca", "2\nac\ncb", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\ndacdeebebeaeaacdeedadbcbaedcbddddddedacbabeddebaaebbdcebebaaccb...
UNKNOWN
PYTHON3
CODEFORCES
14
70ad39a204d5f344618bb21bc61d6a45
Karen and Supermarket
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to *b* dollars. The supermarket sells *n* goods. The *i*-th good can be bought for *c**i* dollars. Of course, e...
[ "import sys\r\n\r\ndef rd(): return sys.stdin.readline().strip()\r\ndef rdl(typ,sep=\" \"): return list(map(typ, rd().split(sep)))\r\ndef wt(x,sep=\"\\n\") : sys.stdout.write(str(x) + sep) # string / num\r\n\r\ndef treeOrdering2(n, adjList, root=0): # order by depth\r\n order = []\r\n stack = [root]\r\n ...
{"inputs": ["6 16\n10 9\n10 5 1\n12 2 1\n20 18 3\n10 2 3\n2 1 5", "5 10\n3 1\n3 1 1\n3 1 2\n3 1 3\n3 1 4", "13 30\n6 4\n25 5 1\n7 1 2\n9 4 2\n10 2 1\n12 3 1\n5 2 3\n10 9 6\n2 1 1\n5 3 9\n10 2 10\n10 9 6\n3 2 11", "8 9\n4 3\n8 3 1\n2 1 1\n4 2 2\n7 2 2\n3 1 2\n7 3 5\n2 1 3", "9 15\n3 1\n6 2 1\n8 3 2\n4 1 2\n2 1 2\n3 2 3\...
UNKNOWN
PYTHON3
CODEFORCES
2
70cd612001f2bd39369ae10726c2feac
none
A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands *n* and 1. The center of each island contains an identical pedestal, and all but...
[ "read = lambda: map(int, input().split())\r\nn = int(input())\r\na = list(read())\r\nb = list(read())\r\nA, B = [], []\r\ni = a.index(1)\r\nwhile len(A) < n:\r\n if a[i]: A.append(a[i])\r\n i = (i + 1) % n\r\ni = b.index(1)\r\nwhile len(B) < n:\r\n if b[i]: B.append(b[i])\r\n i = (i + 1) % n\r\nans = 'Y...
{"inputs": ["3\n1 0 2\n2 0 1", "2\n1 0\n0 1", "4\n1 2 3 0\n0 3 2 1", "9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7", "4\n2 3 1 0\n2 0 1 3", "4\n0 1 2 3\n2 0 1 3", "4\n3 0 1 2\n1 0 2 3", "3\n0 2 1\n1 2 0", "2\n0 1\n0 1", "6\n3 1 5 4 0 2\n0 4 3 5 2 1", "4\n2 0 3 1\n3 1 0 2", "5\n3 0 2 1 4\n4 3 0 1 2", "3\n2 0 1\n1 0 2", "10\n...
UNKNOWN
PYTHON3
CODEFORCES
45