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
19d770e2c74d695b37b93d822093c5aa
Marathon
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0,<=0) and the length of the side equals *a* meters. The sides of the square are parallel to coordinate axes. As the length o...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\na,d = map(float, input().split())\r\nN = int(input())\r\nperi = a*4\r\n\r\npos = [(0,0),(a,0),(a,a),(0,a)]\r\ndirs = [(1,0),(0,1),(-1,0),(0,-1)]\r\nfor i in range(1,N+1):\r\n t = (d*i)%peri\r\n j = int(t//a)\r\n \r\n x,y = pos[j]\r\n ...
{"inputs": ["2 5\n2", "4.147 2.8819\n6", "16904.8597 21646.2846\n10", "40356.3702 72886.7142\n100", "70092.4982 95833.7741\n1000", "39712.7105 19285.2846\n10000", "97591.0354 49021.4126\n100000", "1 100000\n100000", "1 1\n1", "99999.9999 99999.9998\n100000", "1.0001 9999.9999\n100000", "100000 1\n100000", "100000 10000...
UNKNOWN
PYTHON3
CODEFORCES
6
19dae5f00909e7d63f427950e41e714c
Game with Coins
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x...
[ "n = int(input())\r\nif n == 1 or n & 1 == 0: print(-1)\r\nelse:\r\n t = list(map(int, input().split()))\r\n s, k = 0, n // 2 - 1\r\n for i in range(n - 1, 1, -2):\r\n p = max(t[i], t[i - 1])\r\n t[k] = max(0, t[k] - p)\r\n s += p\r\n k -= 1\r\n print(s + t[0])", "def solve...
{"inputs": ["1\n1", "3\n1 2 3", "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 509 236 782 44 467 607 326 267 15 564 858 499 337 74 346 443 436 48 795 206 403 379 313 3...
UNKNOWN
PYTHON3
CODEFORCES
9
19e898254aab6b1c7f5fa0c9454533fb
R3D3’s Summer Adventure
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met anoth...
[ "import sys,heapq\r\n#sys.stdin=open(\"data.txt\")\r\ninput=sys.stdin.readline\r\n\r\nn,a,b=map(int,input().split())\r\n\r\nif a<b: a,b=b,a\r\n\r\nif b==0:\r\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\r\n print((n-1)*a)\r\nelse:\r\n # pascal's triangle thing\r\n pascal=[[1]*20005]\r\n ...
{"inputs": ["4 1 2", "2 1 5", "3 1 1", "5 5 5", "4 0 0", "6 0 6", "6 6 0", "2 1 2", "100000000 1 0", "2 0 0", "2 100000000 100000000", "2 100000000 0", "2 0 100000000", "100000000 0 0", "100000000 100000000 100000000", "100000000 100000000 0", "100000000 0 100000000", "2 50000000 0", "2 50000000 100000000", "2 50000000...
UNKNOWN
PYTHON3
CODEFORCES
2
1a01e8cd6ea9e6b13f69248a9cdca0db
Monitor
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999...
[ "from math import gcd\n\na, b, x, y = map(int, input().split())\nx, y = x // gcd(x, y), y // gcd(x, y)\nq = min(a // x, b // y)\nprint(x * q, y * q)", "'''\r\nBeezMinh\r\n15:36 UTC+7\r\n04/10/2023\r\n'''\r\nfrom sys import stdin\r\nfrom math import gcd\r\ninput = lambda: stdin.readline().rstrip()\r\na, b, x, y = ...
{"inputs": ["800 600 4 3", "1920 1200 16 9", "1 1 1 2", "1002105126 227379125 179460772 1295256518", "625166755 843062051 1463070160 1958300154", "248228385 1458744978 824699604 1589655888", "186329049 1221011622 90104472 1769702163", "511020182 242192314 394753578 198572007", "134081812 857875240 82707261 667398699", ...
UNKNOWN
PYTHON3
CODEFORCES
34
1a3833e219a41346e746f849967f9b3c
Meeting
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at...
[ "xa, ya, xb, yb = tuple([int(x) for x in input().split()])\n\nxmax = max(xa, xb)\nxmin = min(xa, xb)\nymax = max(ya, yb)\nymin = min(ya, yb)\n# xa = 1; ya = 2; xb = 10; yb = 20\n\ncoord_dict = dict()\nfor i in range(xmin, xmax+1):\n\tcoord_dict[(i, ymin)] = 1\n\tcoord_dict[(i, ymax)] = 1\nfor i in range(ymin, ymax+...
{"inputs": ["2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2", "5 2 6 3\n2\n6 2 2\n6 5 3", "-705 595 -702 600\n1\n-589 365 261", "-555 674 -553 774\n5\n-656 128 631\n597 -220 999\n-399 793 155\n-293 -363 1000\n-557 -914 1000", "-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-7...
UNKNOWN
PYTHON3
CODEFORCES
7
1a3944c48c6207815c1e4c534d54831f
Sereja and Table
Sereja has an *n*<=×<=*m* rectangular table *a*, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is,...
[ "from functools import *\r\n \r\nread_line = lambda: [int(i) for i in input().split()]\r\n \r\nn, m, k = read_line()\r\na = [read_line() for i in range(n)]\r\nif n < m:\r\n n, m, a = m, n, zip(*a)\r\n \r\nxs = [reduce(lambda x, b: 2 * x + b, y) for y in a]\r\nminm = lambda a: min(a, m - a)\r\nwork = lambda y: su...
{"inputs": ["5 5 2\n1 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1", "3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0", "3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1", "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0", "3 10 7\n0 1 0 0 1 0 1 0 0 0\n0 0 1 1 0 0 0 1 0 1\n1 0 1 1 1 0 1 1 0 0", "4 9 7\n0 0 0 1 0 1 1 0 0\n1 1 1 0 0 0 0 1 1\n1 1 0 0 1 1 0 1 0\n0...
UNKNOWN
PYTHON3
CODEFORCES
3
1a542256851fbf03363cd7fffc84c4a0
Bear and Tree Jumps
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of *n* vertices, numbered 1 through *n*. Limak recently learned how to jump. He can jump from a vertex to any v...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\nfrom collections import deque\r\n\r\nn, k = map(int, input().split())\r\ntot_dist = 0\r\nvis = [0]*(n+1)\r\ndist = [[[0]*2 for j in range(k)] for i in range(n+1)]\r\nadj = [[]for i in range(n+1)]\r\nfor i in range(n-1):\r\n u,v = map(int,input().split())\r\n ...
{"inputs": ["6 2\n1 2\n1 3\n2 4\n2 5\n4 6", "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12", "3 5\n2 1\n3 1", "2 1\n1 2", "2 5\n2 1", "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2", "4 2\n3 4\n2 4\n3 1", "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n...
UNKNOWN
PYTHON3
CODEFORCES
1
1aa40a049ab142e496e372c4df124c0a
Perfect Security
Alice has a very important message *M* consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key *K* of the length equal to the message's length. Alice computes the bitwise xor of each element of t...
[ "import math\r\nimport random\r\nimport heapq, bisect\r\nimport sys\r\nfrom collections import deque, defaultdict\r\nfrom fractions import Fraction\r\nimport sys\r\nimport threading\r\nfrom collections import defaultdict\r\n#threading.stack_size(10**8)\r\nmod = 10 ** 9 + 7\r\nmod1 = 998244353\r\n \r\n# ------------...
{"inputs": ["3\n8 4 13\n17 2 7", "5\n12 7 87 22 11\n18 39 9 12 16", "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667", "5\n134 246 57 176 239\n14 83 97 175 187", "...
UNKNOWN
PYTHON3
CODEFORCES
3
1aae09d59fdc0c4399e58e8469772e31
Equation
You are given an equation: Your task is to find the number of distinct roots of the equation and print all of them in ascending order. The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. In case of infinite root count print the onl...
[ "import math\r\na, b, c = map(int, input().split())\r\nd = 0\r\nif a == 0 and b == 0 and c == 0:\r\n print(-1)\r\n exit()\r\nif a == 0 and b == 0:\r\n print(0)\r\n exit()\r\nif a == 0:\r\n d -= c\r\n d /= b\r\n print(1)\r\n if d == -0:\r\n d = 0\r\n print(d)\r\n exit()\r\nd = b ...
{"inputs": ["1 -5 6", "1 1 1", "1 2 1", "0 0 0", "0 -2 1", "0 -2 0", "0 0 1", "0 0 -100000", "0 10000 -100000", "1 100000 -100000", "0 3431 43123", "100 200 100", "50000 100000 50000", "-1 10 20", "-50000 100000 -50000", "1 -2 1", "1000 -5000 6000", "0 -100000 0", "1 -100000 0", "1223 -23532 1232", "-1 -2 -1", "1 0 0",...
UNKNOWN
PYTHON3
CODEFORCES
36
1adf051fd4437e5a6984d9c248647615
Drazil and Date
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ...
[ "a,b,s=map(int,input().split())\r\nif a<0:\r\n a*=-1\r\nif b<0:\r\n b*=-1\r\nif (s-a-b)%2==0 and (s-a-b)>=0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x,y,s=[int(i) for i in input().split()]\r\nk=abs(x)+abs(y)\r\nif k<=s:\r\n s-=k\r\n if s%2==0:print('Yes')\r\n else:print('No')\r\nelse...
{"inputs": ["5 5 11", "10 15 25", "0 5 1", "0 0 2", "999999999 999999999 2000000000", "-606037695 998320124 820674098", "948253616 -83299062 1031552680", "711980199 216568284 928548487", "-453961301 271150176 725111473", "0 0 2000000000", "0 0 1999999999", "1000000000 1000000000 2000000000", "-1000000000 1000000000 200...
UNKNOWN
PYTHON3
CODEFORCES
146
1b086a205dcde6ba4c9ab03dfd1792b0
Two strings
You are given two strings *a* and *b*. You have to remove the minimum possible number of consecutive (standing one after another) characters from string *b* in such a way that it becomes a subsequence of string *a*. It can happen that you will not need to remove any characters at all, or maybe you will have to remove a...
[ "def solve(s1,s2):\r\n n=len(s1)\r\n m=len(s2)\r\n s1=' ' +s1 + ' '\r\n s2=' ' +s2 + ' '\r\n tmp=0\r\n v1=[0]*100005\r\n v2=[0]*100005\r\n for i in range(1,n+1):\r\n if s1[i]==s2[tmp+1]:\r\n tmp+=1\r\n v1[i]=tmp\r\n tmp=m+1\r\n v2[n+1]=tmp\r\n for i in range...
{"inputs": ["hi\nbob", "abca\naccepted", "abacaba\nabcdcba", "lo\neuhaqdhhzlnkmqnakgwzuhurqlpmdm", "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk", "npnkmawey\nareakefvowledfriyjejqnnaeqheoh", "fdtffutxkujflswyddvhusfcook\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc"...
UNKNOWN
PYTHON3
CODEFORCES
8
1b36d9af899bb91e38c9a85d7cb7a906
Data Recovery
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer ...
[ "a,b,c,d=map(int,input().split())\r\nz=list(map(int,input().split()))\r\nk=z.copy()\r\nif c in k:k.remove(c)\r\nif d in k:k.remove(d)\r\nif (max(z)>d or min(z)<c or len(k)+2>a ):print(\"Incorrect\")\r\nelse:print(\"Correct\")", "I = lambda: map(int, input().split())\r\n\r\nn, m, Tmin, Tmax = I()\r\nT = sorted(I()...
{"inputs": ["2 1 1 2\n1", "3 1 1 3\n2", "2 1 1 3\n2", "3 1 1 5\n3", "3 2 1 5\n1 5", "3 2 1 5\n1 1", "3 2 1 5\n5 5", "3 2 1 5\n1 6", "3 2 5 10\n1 10", "6 5 3 6\n4 4 4 4 4", "100 50 68 97\n20 42 93 1 98 6 32 11 48 46 82 96 24 73 40 100 99 10 55 87 65 80 97 54 59 48 30 22 16 92 66 2 22 60 23 81 64 60 34 60 99 99 4 70 91 9...
UNKNOWN
PYTHON3
CODEFORCES
38
1b5ef8cfd69d5dc48a7f392e465d3a59
A Colourful Prospect
Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circl...
[ "from math import sqrt\r\ndef pt(x):\r\n print(x)\r\nrd = lambda: map(int, input().split())\r\nn = int(input())\r\ndef f(x1, y1, r1, x2, y2, r2):\r\n a = (r1 + r2) ** 2\r\n b = (r1 - r2) ** 2\r\n d = (x1 - x2) ** 2 + (y1 - y2) ** 2\r\n if d > a:\r\n return 1\r\n elif d == a:\r\n retu...
{"inputs": ["3\n0 0 1\n2 0 1\n4 0 1", "3\n0 0 2\n3 0 2\n6 0 2", "3\n0 0 2\n2 0 2\n1 1 2", "1\n0 0 10", "2\n-10 10 1\n10 -10 1", "2\n-6 6 9\n3 -6 6", "2\n-10 -10 10\n10 10 10", "3\n-4 1 5\n-7 7 10\n-3 -4 8", "3\n-2 8 10\n3 -2 5\n3 1 3", "3\n0 0 2\n0 0 4\n3 0 2", "3\n8 5 7\n7 3 7\n5 2 5", "3\n-6 5 7\n1 -2 7\n7 9 7", "3\n...
UNKNOWN
PYTHON3
CODEFORCES
1
1b67757cd76a83e0896376acaf8af9eb
Vacations
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
[ "n=int(input())\r\ndp=[[0 for i in range(3)]for j in range(n+1)]\r\nar=tuple(map(str,input().split()))\r\nfor i in range(1,n+1):\r\n x=ar[i-1]\r\n dp[i][0]=min(dp[i-1])+1 \r\n if(x=='1' or x=='3'):\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n else:\r\n dp[i][1]=dp[i-1][1]+1 \r\n if(x=='2...
{"inputs": ["4\n1 3 2 0", "7\n1 3 3 2 1 2 3", "2\n2 2", "1\n0", "10\n0 0 1 1 0 0 0 0 1 0", "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "10\n2 3 0 1 3 1 2 2 ...
UNKNOWN
PYTHON3
CODEFORCES
490
1ba3cfe4997ee8dcd640bb7f5ff1c2d8
Orange
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. Output the required string. Sample Input AprilFool 14 Sample Output AprILFooL
[ "alphabet_lower=list('abcdefghijklmnopqrstuvwxyz')\r\ns=input()\r\ns=s.lower()\r\ns=list(s)\r\ncount=int(input())\r\nfor i in range(len(s)):\r\n if alphabet_lower.index(s[i])<count:\r\n s[i]=s[i].upper()\r\nprint(''.join(s))", "from sys import stdin,stdout\r\n# from bisect import bisect_left,bisect\r\n#...
{"inputs": ["AprilFool\n14", "abcdefabc\n3", "fgWjSAlPOvcAbCdDEFjz\n7", "sm\n26", "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12", "sPWSFWWqZBPon\n3", "fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0", "RtsUOGkraqKyjTktAXloOEmQj\n18", "DuFhhnq\n4", "RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22", "isfvbcBEEPaXUDhbVhwddjEutVQqNdli...
UNKNOWN
PYTHON3
CODEFORCES
16
1ba91a102a7f37aac8832718ae66b16b
Biridian Forest
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest. The forest The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vac...
[ "\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque, Counter\r\n\r\n\r\ndef is_ok(x, y):\r\n return 0 <= x < r and 0 <= y < c\r\n\r\n\r\nr, c = map(int, input().split())\r\ng = []\r\nfor i in range(r):\r\n s = input()[:-1]\r\n if 'E' in s:\r\n x = (i, s.index('E'), 0)\r\n ...
{"inputs": ["5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000", "1 4\nSE23", "3 3\n000\nS0E\n000", "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E", "1 10\n9T9TSET9T9", "10 1\nS\n9\n9\n9\n9\nE\n9\n9\n9\n9", "4 3\nS01\n234\n567\n89E", "2 2\nE9\nS4", "3 3\n920\n752\nE8S", "5 1\n9\nT\nE\n6\nS", "1 5\n78S6E", "9 8\n38030772\n697T8...
UNKNOWN
PYTHON3
CODEFORCES
8
1bbc1b8f93c00a8c754ecaa1479f9bbf
Lesha and array splitting
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays...
[ "a=int(input())\r\nb=list(map(int,input().split()))\r\ns=0\r\nl=[]\r\nfor i in b:\r\n s+=i\r\nif s!=0:\r\n print(\"YES\")\r\n print(\"1\")\r\n print(\"1\",len(b))\r\nelif len(b)==b.count(0):\r\n print(\"NO\")\r\nelse:\r\n for i in b:\r\n if i!=0:\r\n break\r\n t=b.index(i)+1\r...
{"inputs": ["3\n1 2 -3", "8\n9 -12 3 4 -4 -10 7 3", "1\n0", "4\n1 2 3 -5", "6\n0 0 0 0 0 0", "100\n507 -724 -243 -846 697 -569 -786 472 756 -272 731 -534 -664 202 592 -381 161 -668 -895 296 472 -868 599 396 -617 310 -283 -118 829 -218 807 939 -152 -343 -96 692 -570 110 442 159 -446 -631 -881 784 894 -3 -792 654 -273 -7...
UNKNOWN
PYTHON3
CODEFORCES
88
1bc048bce4f6f19733a32be0b610de7a
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
[ "class Container:\n pass\n\nn = int(input())\nvalues = list(map(int, input().split()))\nbest_prefixes = (n + 1) * [ 0 ]\nplus = 0\nbest_double_minus = double_minus = 0\n\nfor i, x in enumerate(values):\n plus += x\n double_minus -= 2 * x\n best_double_minus = max(best_double_minus, double_minus)\n be...
{"inputs": ["3\n-1 -2 -3", "5\n-4 2 0 5 0", "5\n-1 10 -5 10 -2", "1\n-3", "4\n1 4 -5 -2", "7\n-17 6 5 0 1 4 -1", "3\n0 -2 3", "2\n0 3", "15\n14 0 -10 -5 0 19 -6 0 -11 -20 -18 -8 -3 19 -7", "15\n0 -35 32 24 0 27 10 0 -19 -38 30 -30 40 -3 22", "100\n-43 0 -81 10 67 61 0 76 -16 1 -1 69 -59 -87 14 -20 -48 -41 90 96 8 -94 -...
UNKNOWN
PYTHON3
CODEFORCES
18
1bc2b438bd8b82a4aa536af61323166e
Magazine Ad
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
[ "n = int(input())\r\na = input()\r\nr=len(a)+1\r\na = a.replace(' ','- ').replace('-','- ').split()\r\nl = max(map(lambda x: len(x),a))\r\nwhile l < r:\r\n m,lines,x = (r-l)//2+l,1,0\r\n for b in a:\r\n if x+len(b) > m:\r\n x = len(b)\r\n lines += 1\r\n else:\r\n ...
{"inputs": ["4\ngarage for sa-le", "4\nEdu-ca-tion-al Ro-unds are so fun", "1\nj", "10\nb", "1\nQGVsfZevMD", "1\nqUOYCytbKgoGRgaqhjrohVRxKTKjjOUPPnEjiXJWlvpCyqiRzbnpyNqDylWverSTrcgZpEoDKhJCrOOvsuXHzkPtbXeKCKMwUTVk", "100000\nBGRHXGrqgjMxCBCdQTCpQyHNMkraTRxhyZBztkxXNFEKnCNjHWeCWmmrRjiczJAdfQqdQfnuupPqzRhEKnpuTCsVPNVTIMi...
UNKNOWN
PYTHON3
CODEFORCES
25
1bc3e611b56cd450a7fb71b37744f2d8
Sagheer and Apple Tree
Sagheer is playing a game with his best friend Soliman. He brought a tree with *n* nodes numbered from 1 to *n* and rooted at node 1. The *i*-th node has *a**i* apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths...
[ "q= int(input())\na = [int(_) for _ in input().split()]\nc = [int(_) for _ in input().split()]\ndepth = [0] * (q)\nfor i in range(1,q):\n depth[i] = depth[c[i-1]-1] + 1\nMAX = max(depth)\nt = 0\nstore = {}\ntodo = []\np = 0\n\nfor i in range(q):\n if (MAX-depth[i]) % 2 == 0: # odd, useful\n t ^= a[i]\n ...
{"inputs": ["3\n2 2 3\n1 1", "3\n1 2 3\n1 1", "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6", "6\n7 7 7 7 7 7\n1 1 1 1 1", "6\n3 1 1 1 2 2\n1 1 1 1 1", "6\n1 2 3 4 5 6\n1 2 3 4 5", "7\n15 3 5 1 2 4 8\n1 1 2 2 3 3", "7\n15 3 5 1 2 4 9\n1 1 2 2 3 3", "7\n15 16 32 1 2 4 9\n1 1 2 2 3 3", "6\n49 70 74 18 64 63\n1 2 2 1 5", "9\n15 17 6...
UNKNOWN
PYTHON3
CODEFORCES
3
1bd2de89b88911f54537f09932bbfcf9
Degenerate Matrix
The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is min...
[ "a, b = map(int, input().split())\r\nc, d = map(int, input().split())\r\n\r\nz = a * d - b * c\r\nif z == 0:\r\n print(0)\r\n exit()\r\nt = max(abs(a + b + c + d), abs(a + d - c - b), abs(a + c - b - d), abs(a + b - c - d))\r\nprint(abs(z / t))", "a, b= map(int, input().split())\nc, d = map(int, input().spl...
{"inputs": ["1 2\n3 4", "1 0\n0 1", "1000000000 0\n0 1000000000", "8205 9482\n11 -63", "0 0\n0 0", "1000000000 -1000000000\n1000000000 1000000000", "1000000000 1000000000\n1000000000 -1000000000", "-1 -1\n1 0", "5 2\n-15 -6", "2 -5\n-3 2", "-5 -2\n-1 -3", "-5 8\n1 6", "1 3\n3 2", "-42 63\n77 -32", "91 -7\n-21 91", "-67...
UNKNOWN
PYTHON3
CODEFORCES
19
1be5e5a36186928a169b53c3d91ce365
Nephren Runs a Cinema
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.) There are three t...
[ "import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,...
{"inputs": ["4 97 2 3", "4 100 0 4", "13 143 6 11", "999 998244353 666 777", "23333 1000000007 0 23333", "100000 100160063 2332 99774", "100000 996991027 54321 67890", "1 1 0 0", "1 1 0 1", "1 233332 0 0", "1 999888663 0 1", "1 2000000000 1 1", "2 14 0 0", "2 39 0 1", "2 1999999999 0 2", "2 15 1 1", "2 2 1 2", "2 3 2 2...
UNKNOWN
PYTHON3
CODEFORCES
1
1c3d7c7c251da6bd6d5318dc55816483
On Segment's Own Points
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 ce...
[ "n = int(input())\r\nseta = set()\r\nax,ay = map(int, input().split(\" \"))\r\nfor i in range(ax,ay):\r\n seta.add(i+0.5)\r\nfor i in range(0,n-1):\r\n nx,ny = map(int, input().split(\" \"))\r\n for j in range(nx,ny):\r\n seta.discard(j+0.5)\r\nprint(len(seta))", "# https://codeforces.com/problems...
{"inputs": ["3\n0 5\n2 8\n1 6", "3\n0 10\n1 5\n7 15", "1\n0 100", "2\n1 9\n1 9", "2\n1 9\n5 10", "2\n1 9\n3 5", "2\n3 5\n1 9", "10\n43 80\n39 75\n26 71\n4 17\n11 57\n31 42\n1 62\n9 19\n27 76\n34 53", "50\n33 35\n98 99\n1 2\n4 6\n17 18\n63 66\n29 30\n35 37\n44 45\n73 75\n4 5\n39 40\n92 93\n96 97\n23 27\n49 50\n2 3\n60 6...
UNKNOWN
PYTHON3
CODEFORCES
80
1c41a03010f966e896c90f173d265027
PLEASE
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. Then at one turn Barney swaps the cup in the middle with a...
[ "k = int(input())\n\nMOD = 10 ** 9 + 7\n\nantithree = pow(3, MOD - 2, MOD)\n\nantitwo = pow(2, MOD - 2, MOD)\n\npower = 1\n\nparity = False\n\nfor t in map(int, input().split()):\n\n power *= t\n\n power %= MOD - 1\n\n if t % 2 == 0:\n\n parity = True\n\nq = pow(2, power, MOD) * antitwo\n\nq %= MOD\...
{"inputs": ["1\n2", "3\n1 1 1", "1\n983155795040951739", "2\n467131402341701583 956277077729692725", "10\n217673221404542171 806579927281665969 500754531396239406 214319484250163112 328494187336342674 427465830578952934 951554014286436941 664022909283791499 653206814724654845 66704816231807388", "8\n137264686188377169 ...
UNKNOWN
PYTHON3
CODEFORCES
7
1c6303b7e51d261699ad1d56d6f87efd
Seller Bob
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB me...
[ "max_x = 2001\r\nn = int(input())\r\nincome = [0]*n\r\nwin = {}\r\nfor i in range(n):\r\n s, a = input().split()\r\n a = int(a)\r\n if (i > 0):\r\n income[i] = income[i-1]\r\n if (s[0] == 'w'):\r\n win[a] = i;\r\n elif (win.get(a) != None):\r\n income[i] = max(income[i], inco...
{"inputs": ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4", "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsel...
UNKNOWN
PYTHON3
CODEFORCES
65
1c9df2f477b8d47d31cf463f5a731156
Joty and Chocolate
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl...
[ "from sys import stdin, stdout\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n\ndef read_ints():\n\treturn list(map(int, read().split()))\n\ndef gcd(x,y):\n\twhile y>0:\n\t\tx,y=y,x%y\n\treturn x\n\ndef solve():\n\tn,a,b,p,q=read_ints()\n\tprint((n//a)*p + (n//b)*q - (n//...
{"inputs": ["5 2 3 12 15", "20 2 3 3 5", "1 1 1 1 1", "1 2 2 2 2", "2 1 3 3 3", "3 1 1 3 3", "4 1 5 4 3", "8 8 1 1 1", "15 14 32 65 28", "894 197 325 232 902", "8581 6058 3019 2151 4140", "41764 97259 54586 18013 75415", "333625 453145 800800 907251 446081", "4394826 2233224 609367 3364334 898489", "13350712 76770926 6...
UNKNOWN
PYTHON3
CODEFORCES
107
1cc716b77421e3d6b18974cbc830152f
Hard problem
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given *n* strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only o...
[ "n = int(input())\r\nc = tuple(map(int, input().split()))\r\nw = [input() for i in range(n)]\r\nwr = [w[i][::-1] for i in range(n)]\r\n\r\ninf = 10**19\r\n\r\ndp = [inf] * n\r\ndpr = [inf] * n\r\ndpr[0] = c[0]\r\ndp[0] = 0\r\n\r\nfor i in range(1, n):\r\n if w[i] >= w[i - 1]:\r\n dp[i] = dp[i - 1]\r\n\r\n...
{"inputs": ["2\n1 2\nba\nac", "3\n1 3 1\naa\nba\nac", "2\n5 5\nbbb\naaa", "2\n3 3\naaa\naa", "4\n0 0 8 6\nbi\nqp\nbt\nya", "5\n8 0 4 8 2\nac\ncl\ngg\ngm\nfs", "10\n7 7 0 0 0 1 6 6 7 3\ndv\ngb\nvg\nxg\nkt\nml\nqm\nnq\nrt\nxn", "3\n999999999 999999999 999999999\nxosbqqnmxq\nsdbvjhvytx\naydpuidgvy", "3\n228 1488 228\nkek\...
UNKNOWN
PYTHON3
CODEFORCES
10
1cc7f991569d0b44661ef185c3842674
Party Lemonade
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and co...
[ "s=input()\r\ns1=s.split()\r\n\r\ntot=int(s1[1])\r\n\r\ns=input()\r\ns1=s.split()\r\n\r\nl=[int(i) for i in s1]\r\n\r\n\r\navg=[[l[i]/(2**i),i] for i in range(len(l))]\r\navg.sort()\r\ncost=0\r\ni=0\r\n\r\ndef fun(i,tot):\r\n\r\n if i==len(avg):\r\n\r\n return(1e8)\r\n\r\n if tot%(2**avg[i][1])==0:\r\n...
{"inputs": ["4 12\n20 30 70 90", "4 3\n10000 1000 100 10", "4 3\n10 100 1000 10000", "5 787787787\n123456789 234567890 345678901 456789012 987654321", "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390...
UNKNOWN
PYTHON3
CODEFORCES
46
1ccc257b517cd0fd9a4117df8d25e6ba
Broken Clock
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken ...
[ "def f(x):\r\n if(x==0): return(\"00\")\r\n elif(len(str(x))==1): return(\"0\"+str(x))\r\n else: return (str(x))\r\n\r\ndef ch(a,b):\r\n q=0\r\n for i in range(len(a)): q+=int(a[i]!=b[i])\r\n return q\r\n\r\ntf=int(input())\r\ntime=[x for x in input().split(':')]\r\nhr12=[]\r\nhr24=[]\r\nmins=[]\r...
{"inputs": ["24\n17:30", "12\n17:30", "24\n99:99", "12\n05:54", "12\n00:05", "24\n23:80", "24\n73:16", "12\n03:77", "12\n47:83", "24\n23:88", "24\n51:67", "12\n10:33", "12\n00:01", "12\n07:74", "12\n00:60", "24\n08:32", "24\n42:59", "24\n19:87", "24\n26:98", "12\n12:91", "12\n11:30", "12\n90:32", "12\n03:69", "12\n33:8...
UNKNOWN
PYTHON3
CODEFORCES
62
1cdc43323dd7fe34277766feb4665594
Gargari and Bishops
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by b...
[ "import sys\r\ninput = sys.stdin.readline \r\n\r\nn = int(input())\r\na =[]\r\nfor i in range(n):\r\n a.append(list(map(int, input().split()))) \r\nb1, b2 = [0] * (2 * n), [0] * (2 * n)\r\nfor i in range(n):\r\n for j in range(n):\r\n b1[i + j] += a[i][j] \r\n b2[n + i - j] += a[i][j] \r\nx, y =...
{"inputs": ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1", "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 7...
UNKNOWN
PYTHON3
CODEFORCES
10
1ce225768b73b495b489addb4d0fd10a
Okabe and Boxes
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta...
[ "n=int(input())\ndata=[]\nneed=1\nanswer=0\ni=0\nwhile i!=n:\n s=input()\n if s[0:3]=='add':\n data.append(int(s[4::]))\n else:\n if len(data)==0:\n need += 1\n elif data[-1]==need:\n need+=1\n data.pop()\n else:\n answer+=1\n ...
{"inputs": ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove", "2\nadd 1\nremove\nadd 2\nremove", "1\nadd 1\nremove", "15\nadd 12\nadd 7\nadd 10\n...
UNKNOWN
PYTHON3
CODEFORCES
33
1cec334a5ccee5eb45955d9a63427621
Graph Coloring
You are given an undirected graph that consists of *n* vertices and *m* edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue ...
[ "from collections import deque\r\n \r\nn, m = map(int, input().split())\r\nadj = [[] for i in range(n)]\r\nfor i in range(m):\r\n u, v, c = input().split()\r\n u, v = int(u)-1, int(v)-1\r\n adj[u].append((v, c))\r\n adj[v].append((u, c))\r\n \r\nvisited = S = T = None\r\n \r\ndef bfs(i, k):\r\n q = d...
{"inputs": ["3 3\n1 2 B\n3 1 R\n3 2 B", "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B", "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B", "3 3\n1 2 R\n1 3 R\n2 3 R", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R", "2 1\n1 2 B"], "outputs": ["1\n2 ", "2\n3 4 ", "-1", "-1", "...
UNKNOWN
PYTHON3
CODEFORCES
1
1cf5b764b7c020a63fed240ea3c9ed09
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*n* is divisible by *k*) *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* and *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k*. Le...
[ "MOD=10**9+7\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nk1,k2,ans=10**k,10**(k-1),1\r\nfor i in range(n//k):\r\n z,x=a[i],b[i]\r\n if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1\r\n else: c=(k1-1)//z-(k2-1)//z\r\n ans=ans*c%MOD\r\npri...
{"inputs": ["6 2\n38 56 49\n7 3 4", "8 2\n1 22 3 44\n5 4 3 2", "2 1\n9 9\n9 9", "2 1\n9 9\n0 9", "4 1\n4 3 2 1\n1 2 3 4", "18 9\n2 3\n0 4", "4 4\n1122\n2", "10 5\n8378 11089\n7 5", "10 5\n52057 11807\n0 1", "10 1\n3 1 1 4 8 7 5 6 4 1\n0 0 0 5 5 6 8 8 4 0", "100 4\n388 2056 122 1525 2912 1465 3066 257 5708 3604 3039 618...
UNKNOWN
PYTHON3
CODEFORCES
30
1cfd8e00daefe70b7d76fc42938a21b8
New Password
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should cons...
[ "n, k = map(int,input().split())\r\n\r\nprint(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n])", "from string import ascii_lowercase as alph\r\nn, k = map(int, input().split())\r\nprint(''.join(alph[i % k] for i in range(n)))", "n,k=[int(n) for n in input().split()]\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\np=s[0:k]\r\...
{"inputs": ["4 3", "6 6", "5 2", "3 2", "10 2", "26 13", "100 2", "100 10", "3 3", "6 3", "10 3", "50 3", "90 2", "6 2", "99 3", "4 2", "100 3", "40 22", "13 8", "16 15", "17 17", "19 4", "100 26", "100 25", "26 26", "27 26", "2 2", "26 25", "99 2", "99 26", "4 4", "5 3", "5 4", "5 5", "24 22", "26 14", "26 15", "30 12...
UNKNOWN
PYTHON3
CODEFORCES
611
1d1a1e0764f53ad7c036de5671142880
Sad powers
You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*. The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two...
[ "from math import *\nimport bisect as bs\n\n\ndef full():\n limit = 10**18\n ds = []\n for a in range(2, 10**6+1):\n ap = a*a*a\n while ap <= limit:\n if floor(sqrt(ap))**2 != ap:\n ds.append(ap)\n ap *= a\n ds.sort()\n n = 0\n for i in range(1, l...
{"inputs": ["6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000", "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770"], "outputs": ["2\n1\n0\n3\n17\n1111", "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
2
1d43ed69859cb281bfafbf1d2a06eb3f
Promocodes with Mistakes
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ. As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at a...
[ "n=int(input())\r\nl=[input() for i in range(n)]\r\nprint(min([sum(a!=b for a,b in zip(l[i],l[j]))-1 for i in range(n) for j in range(i+1,n)]+[12])//2)", "s, r = [13], range(int(input()))\r\nt = [input() for i in r]\r\nfor i in r: s += [sum(x != y for x, y in zip(t[i], t[j])) for j in r[i + 1:]]\r\nprint(min(s) -...
{"inputs": ["2\n000000\n999999", "6\n211111\n212111\n222111\n111111\n112111\n121111", "1\n123456", "2\n000000\n099999", "2\n000000\n009999", "2\n000000\n000999", "2\n000000\n000099", "2\n000000\n000009", "1\n000000", "1\n999999", "10\n946965\n781372\n029568\n336430\n456975\n119377\n179098\n925374\n878716\n461563", "10\...
UNKNOWN
PYTHON3
CODEFORCES
15
1d8453764c751d2f477673148a740919
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw *n* distinct points and *m* s...
[ "n, m = map(int, input().split())\nt = list(enumerate(list(map(int, input().split()))))\nt.sort(key=lambda x: x[1])\np = ['0' for i in range(n)]\nfor i, x in t[::2]:\n\tp[i] = '1'\nprint(' '.join(p))\n", "n, m = map(int, input().split())\r\nc = list(map(int, input().split()))\r\ncc = c.copy()\r\nd = []\r\nfor i i...
{"inputs": ["3 3\n3 7 14\n1 5\n6 10\n11 15", "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "10 10\n3 4 2 6 1 9 0 5 8 7\n5 7\n2 6\n0 1\n5 6\n3 4\n2 5\n2 10\n4 6\n3 6\n3 7", "3 3\n50 51 52\n1 5\n6 10\n11 15", "3 1\n1 2 3\n2 3"], "outputs": ["0 0 0", "1 0 1 ", "0 1 1 1 0 0 1 0 1 0 ", "1 0 1 ", "1 0 1 "]}
UNKNOWN
PYTHON3
CODEFORCES
29
1d95be69ba194a67b9185fef152c655f
Army Creation
As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires. In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balan...
[ "class segtree():\r\n def __init__(self,init,func,ide):\r\n self.n=len(init)\r\n self.func=func\r\n self.ide=ide\r\n self.size=1<<(self.n-1).bit_length()\r\n self.tree=[self.ide for i in range(2*self.size)]\r\n for i in range(self.n):\r\n self.tree[self.size+i]=init[i]\r\n for i in range(...
{"inputs": ["6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6", "5 5\n3 4 4 2 1\n5\n5 5\n5 4\n5 4\n3 4\n5 5", "5 5\n2 1 2 4 1\n5\n5 3\n1 1\n5 1\n2 1\n2 3", "10 5\n4 5 7 3 5 6 6 8 10 9\n5\n10 8\n9 8\n7 5\n8 10\n5 8", "20 5\n9 5 4 10 2 1 8 9 7 4 1 5 4 9 8 10 5 8 4 10\n5\n9 13\n17 13\n6 12\n13 11\n8 8", "100 5\n45 51 23 10 62...
UNKNOWN
PYTHON3
CODEFORCES
1
1dab00c247d5b6f4504eecd845bdc5a9
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
[ "w, h = map(int, input().split())\r\na = []\r\nfor i in range(h):\r\n a.append(list(input()))\r\nb = [[0 for j in range(h)] for i in range(w)] \r\nfor i in range(h):\r\n for j in range(w):\r\n b[j][i] = a[i][j] \r\nfor i in range(w):\r\n x = ''\r\n for j in range(h):\r\n x = x + b[i][j] ...
{"inputs": ["3 2\n.*.\n.*.", "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "1 100\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n....
UNKNOWN
PYTHON3
CODEFORCES
65
1dad4aab8c75f71ea2952a36002504ad
Predict Outcome of the Game
There are *n* games in a football tournament. Three teams are participating in it. Currently *k* games had already been played. You are an avid football fan, but recently you missed the whole *k* games. Fortunately, you remember a guess of your friend for these *k* games. Your friend did not tell exact number of wins...
[ "from sys import stdin ,stdout\r\ninput=stdin.readline\r\ninp = lambda : map(int,input().split())\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end) \r\n\r\n\r\ndef check() :\r\n global ans , arr , n , k\r\n for i in arr : \r\n if i<0 : return 0 \r\n ...
{"inputs": ["5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2"], "outputs": ["yes\nyes\nyes\nno\nno"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1dafc81807943eded66d0fe91f4eb6db
Help Chef Gerasim
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup...
[ "def help_chef():\r\n\tcount = int(input())\r\n\r\n\tvolumes = []\r\n\ttotal = 0\r\n\tfor _ in range(count):\r\n\t\tvolume = int(input())\r\n\t\tvolumes.append(volume)\r\n\t\ttotal += volume\r\n\t\r\n\tif total % count != 0:\r\n\t\tprint(\"Unrecoverable configuration.\")\r\n\telif len(set(volumes)) == 1:\r\n\t\tpri...
{"inputs": ["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250", "4\n200\n190\n210\n200", "4\n1\n2\n3\n4", "1\n0", "2\n0\n0", "2\n0\n1", "2\n0\n2", "2\n1\n0", "2\n1\n1", "2\n1\n2", "2\n2\n0", "2\n2\n1", "2\n2\n2", "3\n0\n0\n0", "3\n0\n0\n1", "3\n0\n0\n2", "3\n0\n1\n0", "3\n0\n1\n1",...
UNKNOWN
PYTHON3
CODEFORCES
15
1df64825d70c19acab8be693fb95a789
Bear and Three Musketeers
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose thre...
[ "from collections import defaultdict,deque\r\ndef main():\r\n n,m = map(int, input().split())\r\n d = defaultdict(set)\r\n for i in range(m):\r\n a,b = map(int,input().split())\r\n d[a].add(b)\r\n d[b].add(a)\r\n ans = 1e10\r\n for key,v in d.items():\r\n for j in v:\r\n ...
{"inputs": ["5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "7 4\n2 1\n3 6\n5 1\n1 7", "5 0", "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11", "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n...
UNKNOWN
PYTHON3
CODEFORCES
101
1e05022190289ddb4726bb4ad2a1b069
Ancient Berland Circus
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec...
[ "from decimal import Decimal\r\nimport math\r\n\r\ndef dis(x1, y1, x2, y2):\r\n\treturn math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))\r\n\r\ndef ang(a, b, c):\r\n\treturn math.acos((a*a + b * b - c * c) / (2.0 * a*b))\r\n\r\ndef zero(n):\r\n\treturn (n < 1e-3) and (n > -1e-3)\r\n\r\ndef check(n):\r\n\treturn...
{"inputs": ["0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000", "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739", "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248", "-13.242302 -45.014124\n-33.825369 51.083964\n84.512928 -55.134407", "115.715093 141.583620\n136.158119 -23.780834\n...
UNKNOWN
PYTHON3
CODEFORCES
15
1e05c048abf89b10b87662857fb3d340
Porcelain
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed. The collection of porcelain is arranged neatly on *n* shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items — the leftmost or the...
[ "def main():\r\n inp = list(map(int, input().split()))\r\n dp = [0] * (inp[1] + 1)\r\n \r\n for _ in range(inp[0]):\r\n total, *shelf = map(int, input().split())\r\n max_val= [0] * (total + 1)\r\n \r\n shelf= [0] + shelf\r\n \r\n for j in range(1, total + 1):\r\...
{"inputs": ["2 3\n3 3 7 2\n3 4 1 5", "1 3\n4 4 3 1 2", "1 4\n6 5 1 10 1 1 5", "3 2\n1 10\n1 2\n1 5", "1 68\n100 26 58 15 8 69 66 49 97 18 74 27 39 19 76 37 25 4 88 75 17 79 41 21 44 39 7 42 63 82 92 87 41 85 25 30 43 80 95 70 98 88 16 15 97 74 81 76 33 19 64 3 14 72 17 36 33 21 34 59 38 75 48 1 57 20 81 56 74 67 14 89 ...
UNKNOWN
PYTHON3
CODEFORCES
1
1e20de0e4e64dcaf65977de7275cd6b7
Array
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The produ...
[ "\nn = int(input())\na = list(map(int,input().split()))\n\nnegative = []\npositive = []\nzeros = []\n\na = sorted(a)\n\nif a[-1] > 0:\n positive.append(a[-1])\n negative.append(a[0])\n a.pop(0)\n a.pop(-1)\n zeros = a\nelse:\n positive.append(a[0])\n positive.append(a[1])\n negative.append(...
{"inputs": ["3\n-1 2 0", "4\n-1 -2 -3 0", "5\n-1 -2 1 2 0", "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28...
UNKNOWN
PYTHON3
CODEFORCES
248
1e526c78e232fa1191bd872a5767a30a
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s...
[ "n = int(input())\r\ncounter = 0\r\na = [[0 for j in range(n)] for i in range(n)]\r\nfor i in range(n - 1):\r\n i, j = map(int, input().split())\r\n a[i - 1][j - 1] = 1\r\n a[j - 1][i - 1] = 1\r\n\r\nfor element in a:\r\n if element.count(1) == 1:\r\n counter += 1\r\n\r\nprint(counter)", "impor...
{"inputs": ["5\n4 1\n4 2\n1 3\n1 5", "4\n1 2\n4 3\n1 4", "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9"], "outputs": ["3", "2", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
104
1e55fccee6224084c321804a4e02e995
Forecast
The Department of economic development of IT City created a model of city development till year 2100. To prepare report about growth perspectives it is required to get growth estimates from the model. To get the growth estimates it is required to solve a quadratic equation. Since the Department of economic developmen...
[ "a,b,c = map(int,input().split())\r\nif a < 0:\r\n a,b,c = -a,-b,-c\r\nprint((-b+(b*b-4*a*c)**0.5)/(2*a),(-b-(b*b-4*a*c)**0.5)/(2*a))", "a, b, c = map(int, input().split())\r\nf = lambda x : a * x ** 2 + b * x + c\r\nxv = -b / (2 * a)\r\nl1 = -1e12\r\nr1 = xv\r\nwhile (r1 - l1 > 1e-6):\r\n mid1 = (r1 + l1) ...
{"inputs": ["1 30 200", "1 1 -1", "-1 1 1", "1000 1 -1", "-1 1000 1", "1000 1000 -999", "633 304 -186", "-181 -227 368", "-779 -814 321", "1 1 0", "1 0 -9"], "outputs": ["-10.000000000000000\n-20.000000000000000", "0.618033988749895\n-1.618033988749895", "1.618033988749895\n-0.618033988749895", "0.031126729201737\n-0.0...
UNKNOWN
PYTHON3
CODEFORCES
10
1e5d848978933dde5b192f0f60219f6d
Credit Card
Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of *i*-th day a transaction *a**i* occurs. If *a**i*<=&gt;<=0, then *a**i* bourles are deposited to Luba's account. If *a**i*<=&lt;<=0, then *a**i* bour...
[ "def main():\r\n n, d = map(int, input().split())\r\n a = list(map(int, input().split()))\r\n ans = 0\r\n cur = 0\r\n balance = 0\r\n lows = [0] * n\r\n rigs = [0] * n\r\n for i in range(n):\r\n balance += a[i]\r\n if a[i] == 0:\r\n lows[i] = -balance\r\n rigs...
{"inputs": ["5 10\n-1 5 0 -5 3", "3 4\n-10 0 20", "5 10\n-5 0 10 -11 0", "5 13756\n-2 -9 -10 0 10", "20 23036\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1", "12 82016\n1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2", "7 8555\n-2 -3 -2 3 0 -2 0", "16 76798\n-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10", "20 23079\n0 1 1 -1 1 0 -1 ...
UNKNOWN
PYTHON3
CODEFORCES
4
1e69e3da1ef219365379e87e1145a53c
Crosses
There is a board with a grid consisting of *n* rows and *m* columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number *i* and column number *j* as (*i*,<=*j*). A group of six numbers (*a*,<=*b*,<=*c*,<=*...
[ "from sys import stdin\r\ndef read(): return map(int, stdin.readline().split())\r\n\r\n\r\ndef ways(h,w,area):\r\n if area == h*w:\r\n return 2 * ( (h+1)//2 * (w+1)//2 ) - 1\r\n if area > h*w: return 0\r\n if area < h+w-1: return 0\r\n \r\n area = h*w - area\r\n if area % 4 != 0: return 0\r\n area //= 4...
{"inputs": ["2 2 1", "3 4 5", "2 2 3", "5 1 3", "9 7 55", "5 10 25", "20 12 101", "21 10 155", "49 7 105", "74 99 5057", "9 10 5", "10 14 47", "6 14 23", "27 9 57", "20 17 319", "2 20 37", "10 4 33", "30 8 53", "48 76 2921", "2 78 117", "2 55 9", "56 54 2639", "72 65 2843", "32 71 297", "48 81 2573", "1 1 1", "100 100 ...
UNKNOWN
PYTHON3
CODEFORCES
1
1e6b1ebdeec5065319d5165cebc63f4d
Robbers' watch
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in *n* ho...
[ "def D(n):\r\n\tx,r=n-1,1\r\n\twhile x>=7:\r\n\t\tx//=7\r\n\t\tr+=1\r\n\treturn r\r\ndef H(n,l):\r\n\tx,r=n,\"\"\r\n\tif x==0:r+='0'\r\n\twhile x:\r\n\t\tr+=chr(ord('0')+x%7)\r\n\t\tx//=7\r\n\tr+='0'*(l-len(r))\r\n\treturn r\r\na,b=map(int,input().split())\r\nla=D(a)\r\nlb=D(b)\r\nV=[0]*99\r\nr=0\r\ndef F(deep,wa,w...
{"inputs": ["2 3", "8 2", "1 1", "1 2", "8 8", "50 50", "344 344", "282475250 282475250", "8 282475250", "1000000000 1000000000", "16808 7", "2402 50", "343 2401", "1582 301", "421414245 4768815", "2401 343", "2 1", "282475250 8", "8 7", "50 7", "16808 8", "2402 49", "123 123", "123 456", "1 9", "1 10", "50 67", "7 117...
UNKNOWN
PYTHON3
CODEFORCES
14
1e74392cb55352ace00ff81a62ba0aa3
Calculating Function
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Print *f*(*n*) in a single line. Sample Input 4 5 Sample Output 2 -3
[ "S0l=int(input())\r\nif S0l%2==0:\r\n print(S0l//2)\r\nelse:\r\n print(S0l//2-S0l)", "y = int(input())\r\nprint(y//2-y * (y%2))", "n = int(input())\r\nif n%2 != 0:\r\n val = -(n + 1) / 2\r\nelse:\r\n val = n/2\r\nprint(int(val))", "f=int(input())\r\nprint(f//2-f*(f%2))", "n: int = int(input())\r...
{"inputs": ["4", "5", "1000000000", "1000000001", "1000000000000000", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "208170109961052", "46017661651072", "4018154546667", "288565475053", "3052460231", "29906716", "87897701693326", "8240", "577935", "62", "1", "2", "9999999999999", "1000000000000"...
UNKNOWN
PYTHON3
CODEFORCES
371
1ebe3a50c08a441116f53867534813de
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
[ "\ns = ' '+input()+' '\nn = int(input())\nprint(s[1:-1])\nfor i in range(n):\n l,r = input().split()\n s = s.replace(' '+l+' ',' '+r+' ')\n print(s[1:-1])\n", "n,m= input().split()\r\nprint(n,m)\r\nnum = int(input())\r\nfor i in range(num):\r\n\ta,b=input().split()\r\n\tif(a==n):\r\n\t\tprint(b,m)\r\n\t\...
{"inputs": ["ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "icm codeforces\n1\ncodeforces technex", "a b\n3\na c\nb d\nd e", "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg", "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o", "iii iiiiii\n7\niii ...
UNKNOWN
PYTHON3
CODEFORCES
264
1ebfd6c2cb572ab66eb2884fa508a34f
k-Interesting Pairs Of Integers
Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=...
[ "def binary(n):\r\n curr=0\r\n while(n>0):\r\n if(n%2):\r\n curr+=1\r\n n=n//2\r\n return curr\r\nl=input().split()\r\nn=int(l[0])\r\nk=int(l[1])\r\nl=input().split()\r\nli=[int(i) for i in l]\r\narr=[]\r\nfor i in range(2**15):\r\n if(binary(i)==k):\r\n arr.append(i)\r\n...
{"inputs": ["4 1\n0 3 2 1", "6 0\n200 100 100 100 200 200", "2 0\n1 1", "2 0\n0 0", "2 0\n10000 10000", "2 0\n0 10000", "2 1\n0 1", "2 1\n0 2", "3 1\n0 1 2", "3 2\n0 3 3", "3 2\n3 3 3", "10 0\n1 1 1 1 1 1 1 1 1 1", "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8...
UNKNOWN
PYTHON3
CODEFORCES
3
1ec7fb216711d8f95bde17bc32969245
Clear Symmetry
Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th col...
[ "n = int(input())\r\nif n == 3:\r\n print(5)\r\nelse:\r\n s = [((2 * i + 1) * (2 * i + 1)+ 1)// 2 for i in range(200)]\r\n for i in range(200):\r\n if s[i] >= n:\r\n print(2 * i + 1)\r\n break", "import sys\r\nimport math\r\n\r\ninput = sys.stdin.readline\r\nprint = sys.stdou...
{"inputs": ["4", "9", "10", "12", "1", "19", "3", "2", "5", "6", "7", "8", "11", "13", "14", "15", "16", "17", "18", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",...
UNKNOWN
PYTHON3
CODEFORCES
20
1ed6ca77cf602d8ebffe43cfd3e5166b
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
[ "from collections import defaultdict \r\n \r\ndef Root(child):\r\n while(Parent[child]!=child):\r\n child = Parent[child]\r\n return child\r\n \r\ndef Union(a,b):\r\n root_a = Root(a)\r\n root_b = Root(b)\r\n \r\n if(root_a!=root_b):\r\n if(Size[root_a]<Size[root_b]):\r\n ...
{"inputs": ["9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "2\n1\n1 2\n0", "2\n0\n1\n1 2", "3\n2\n1 2\n1 3\n1\n2 3", "3\n3\n1 3\n2 1\n2 3\n0", "4\n3\n1 2\n2 3\n3 1\n3\n1 4\n4 2\n3 4", "7\n8\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 4\n5 6\n3\n2 6\n5 7\n6 7", "14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\...
UNKNOWN
PYTHON3
CODEFORCES
13
1f1dcedf1144203ac39ca0e477b614f3
Pasha Maximizes
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k...
[ "a, k = list(map(int, input().split()))\r\na = str(a); q = []\r\nfor i in a:\r\n q.append(i)\r\nfor i in range(len(q)):\r\n x = i\r\n for j in range(i+1, len(q)):\r\n if j-i > k:\r\n break\r\n if q[x] < q[j]:\r\n x = j\r\n k -= x-i\r\n while x > i:\r\n q[x],...
{"inputs": ["1990 1", "300 0", "1034 2", "9090000078001234 6", "1234 3", "5 100", "1234 5", "1234 6", "9022 2", "66838 4", "39940894417248510 10", "5314 4", "1026 9", "4529 8", "83811284 3", "92153348 6", "5846059 3", "521325125110071928 4", "39940894417248510 10", "77172428736634377 29", "337775999910796051 37", "1169...
UNKNOWN
PYTHON3
CODEFORCES
90
1f4cbe261ba5bc12af16f0c6bfe7bd72
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special...
[ "s, l, r = 0, 0, int(input()) - 1\r\nt = list(map(int, input().split()))\r\nwhile 1:\r\n while l < r and t[l] < t[l + 1]: l += 1\r\n while l < r and t[r] < t[r - 1]: r -= 1\r\n if l == r: break\r\n if t[l] < t[r]:\r\n s += t[l] - t[l + 1] + 1\r\n t[l + 1] = t[l] + 1\r\n else:\r\n ...
{"inputs": ["5\n1 4 3 2 5", "5\n1 2 2 2 1", "7\n10 20 40 50 70 90 30", "1\n1", "2\n1 15", "4\n36 54 55 9", "5\n984181411 215198610 969039668 60631313 85746445", "10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916", "100\n9997 9615 4045 2846 7656 2941 2233 9214 837 2369 583...
UNKNOWN
PYTHON3
CODEFORCES
8
1f4e69ed4131031462be5f829f047a10
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul...
[ "def scanf(t=int):\r\n return list(map(t, input().split()))\r\nn, m = scanf()\r\ns = '01' * (n//2) + '0' * (n % 2)\r\nprint(s)", "# import atexit\r\n# import io\r\n# import sys\r\n#\r\n# _INPUT_LINES = sys.stdin.read().splitlines()\r\n# input = iter(_INPUT_LINES).__next__\r\n# _OUTPUT_BUFFER = io.StringIO()\r\...
{"inputs": ["5 3\n1 3\n2 4\n2 5", "6 3\n5 6\n1 4\n4 6", "10 4\n3 3\n1 6\n9 9\n10 10", "1 1\n1 1", "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999", "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 ...
UNKNOWN
PYTHON3
CODEFORCES
202
1f5631011a2485df36b8c0ae1a556024
Peculiar apple-tree
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the ...
[ "n = int(input())\r\na = [int(e) for e in input().split()]\r\nd = {1:0}\r\nfor k, v in enumerate(a):\r\n d[k+2] = d[v] + 1\r\nd2 = {}\r\nfor k, v in d.items():\r\n d2[v] = d2.get(v,0) + 1\r\ns = sum([v%2 for v in d2.values()])\r\nprint(s)", "def f(x):\r\n return int(x) - 1\r\n\r\n\r\nn = int(input())\r\n...
{"inputs": ["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "2\n1", "3\n1 2", "20\n1 1 1 1 1 4 1 2 4 1 2 1 7 1 2 2 9 7 1", "20\n1 2 1 2 2 1 2 4 1 6 2 2 4 3 2 6 2 5 9", "20\n1 1 1 4 2 4 3 1 2 8 3 2 11 13 15 1 12 13 12", "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15", "20\n1 2 3 4 5 6 7 8 9 6 11 1...
UNKNOWN
PYTHON3
CODEFORCES
60
1f5ecc480ea7750a08db8a7787697704
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
[ "n = int(input())\r\ncountofopenleft = 0\r\ncountofopenright = 0\r\nfor _ in range(n):\r\n l,r = input().split()\r\n if l=='1':\r\n countofopenleft +=1\r\n if r=='1':\r\n countofopenright+=1\r\n\r\ncountofcloseleft = n- countofopenleft\r\ncountofcloseright = n - countofopenright\r\ntotalmoves...
{"inputs": ["5\n0 1\n1 0\n0 1\n1 1\n0 1", "2\n0 0\n0 0", "3\n0 1\n1 1\n1 1", "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "5\n1 0\n1 0\n1 0\n0 1\n0 1"], "outputs": ["3", "0", "1", "7", "6", "0",...
UNKNOWN
PYTHON3
CODEFORCES
738
1fa51f9955817acd74ac1d152389d2d2
Correct Bracket Sequence Editor
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, ...
[ "# LUOGU_RID: 103549808\nn, m, p = map(int, input().split())\nbracketStr = input()\nopStr = input()\np -= 1\nleft, right, pair = [0]*500001, [0]*500001, [0]*500001\nstk = []\nfor i in range(n):\n left[i] = i-1\n right[i] = i+1\n if bracketStr[i] == '(':\n stk.append(i)\n else:\n pair[i] = ...
{"inputs": ["8 4 5\n(())()()\nRDLD", "12 5 3\n((()())(()))\nRRDLD", "8 8 8\n(())()()\nLLLLLLDD", "4 2 2\n()()\nLD", "6 4 1\n()()()\nDRRD", "8 2 4\n(())()()\nRR", "10 7 3\n(()())()()\nRDLRDRD", "12 10 11\n(())()()()()\nDLRDLRDDLR", "14 8 13\n((())())((()))\nDLRLLRLR", "16 2 10\n(((())())())()()\nLD", "18 8 11\n((()))(()...
UNKNOWN
PYTHON3
CODEFORCES
3
1fb3786e6d9b85eeaa60c2c28a859b75
Sail
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will ...
[ "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nvert,hori=\"\",\"\"\r\nif ey>sy:\r\n vert='N'\r\nelse:\r\n vert='S'\r\nif ex>sx:\r\n hori='E'\r\nelse:\r\n hori='W'\r\n \r\nx,y=abs(ex-sx),abs(ey-sy)\r\n\r\ncnt=0\r\nfor i in range(0,len(s)):\r\n if s[i]==vert:\r\n y-=1\r\n \r\n...
{"inputs": ["5 0 0 1 1\nSESNW", "10 5 3 3 6\nNENSWESNEE", "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE", "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "34 -1...
UNKNOWN
PYTHON3
CODEFORCES
225
1fc7fba6d45b4304f5f03ecf43c6b69a
Yet Another Problem On a Subsequence
The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 &gt; 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integers is called good if it can be divided into a positive number ...
[ "from heapq import heappush, heappop\r\nfrom collections import defaultdict, Counter, deque\r\nimport threading\r\nimport sys\r\nimport bisect\r\ninput = sys.stdin.readline\r\ndef ri(): return int(input())\r\ndef rs(): return input()\r\ndef rl(): return list(map(int, input().split()))\r\ndef rls(): return list(inpu...
{"inputs": ["3\n2 1 1", "4\n1 1 1 1", "1\n0", "1\n1"], "outputs": ["2", "7", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1fcdb4cf00b2bfe5bedab19d41b730b4
We Need More Bosses
Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $n$ locations connected by $m$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location. Of course, some passages shoul...
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\n\r\ndef lowlink(links):\r\n n = len(links)\r\n order = [-1] * n\r\n low = [n] * n\r\n parent = [-1] * n\r\n child = [[] for _ in range(n)]\r\n roots = set()\r\n x = 0\r\n for root in range(n):\r\n if order[root] != -...
{"inputs": ["5 5\n1 2\n2 3\n3 1\n4 1\n5 2", "4 3\n1 2\n4 3\n3 2", "50 72\n35 38\n19 46\n35 12\n27 30\n23 41\n50 16\n31 6\n20 33\n38 1\n10 35\n13 43\n29 25\n25 4\n1 13\n4 20\n36 29\n13 47\n48 5\n30 21\n30 38\n28 50\n41 45\n25 43\n40 36\n19 47\n31 32\n26 28\n8 13\n43 24\n27 35\n14 29\n14 38\n50 9\n34 49\n12 34\n43 42\n41...
UNKNOWN
PYTHON3
CODEFORCES
1
1ffbf62bfc508f4f29980f6d780c61fa
Anton and Danik
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. The first line of the input contains a singl...
[ "n=int(input())\r\na=d=0\r\ns=input()\r\nfor i in range(n):\r\n if s[i]=='A': a+=1\r\n else: d+=1\r\nif a==d: print('Friendship')\r\nelif a>d: print('Anton')\r\nelse: print('Danik')", "n=input()\r\ns=input()\r\nna,nd=s.count(\"A\"),s.count(\"D\")\r\nif na>nd:\r\n print(\"Anton\")\r\nelif na==nd:\r\n print(\...
{"inputs": ["6\nADAAAA", "7\nDDDAADA", "6\nDADADA", "10\nDDDDADDADD", "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDA...
UNKNOWN
PYTHON3
CODEFORCES
731
203a84df1d79d9a67272cb7eb7e52e97
Sale
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
[ "n, m = [int(x) for x in input().split(' ')]\r\na = [int(x) for x in input().split(' ') if int(x) < 0]\r\na.sort()\r\nprint(-sum(a[:min(len(a), m)]))\r\n\r\n", "#F\nn, m = [int(x) for x in input().split()]\ntotal = int(0)\na = [int(x) for x in input().split()]\na.sort()\nfor i in range(m):\n if (a[i]<=0):\n ...
{"inputs": ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7", "6 6\n756 -611 251 -66 572 -818", "5 5\n976 437 937 788 518", "5 3\n-2 -2 -2 -2 -2", "5 1\n998 997 985 937 998", "2 2\n-742 -187", "3 3\n522 597 384", "4 2\n-215 -620 192 647", "10 6\n557 605 685 231 910 633 130 838 -564 -85", "20 14\n932 442 960 943 624 624 955 998 631...
UNKNOWN
PYTHON3
CODEFORCES
841
205ab1b2596b19d0ff35371ea3cf18a1
Mashmokh and Lights
Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn...
[ "def main():\n [n, m] = [int(_) for _ in input().split()]\n buttons = [int(_) for _ in input().split()]\n\n # index = 0\n # while index < len(buttons) - 1:\n # button = buttons[index]\n # buttons = buttons[:(index + 1)] + [buttons[i] for i in range(index + 1, len(buttons)) if buttons[i] < ...
{"inputs": ["5 4\n4 3 1 2", "5 5\n5 4 3 2 1", "16 11\n8 5 12 10 14 2 6 3 15 9 1", "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 61 12 60 57", "25 19\n3 12 21 11 19 6 5 15 4 16 20 8 9 1 22 23 25 18 13", "48 8\n42 27 40 1 18 3 19 2", "44 19\n13 20 7 10 9 14 43 17 18 39 21 42 37 1 33 8 35 4 6", "80 29\n79 5...
UNKNOWN
PYTHON3
CODEFORCES
214
205c37248279a0d5d0fe8acbffb500f4
Quasi Binary
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. The first line contains a single integ...
[ "#### B. Quasi Binary\r\nn=int(input())\r\nresult=[]\r\nwhile n:\r\n r=''.join(min(i,'1') for i in str(n))\r\n n=n-int(r)\r\n result.append(r)\r\nprint(len(result))\r\nprint(*result)", "n = int(input())\r\ns = list(map(int, str(n)))\r\nprint(max(s))\r\nl = len(s)\r\nfor i in range(max(s)):\r\n f = 0\r...
{"inputs": ["9", "32", "1", "415", "10011", "10201", "314159", "999999", "2", "10", "21", "98", "102030", "909090", "909823", "1000000", "111111", "123456", "987654", "908172", "8", "100009", "900000", "1435", "1453"], "outputs": ["9\n1 1 1 1 1 1 1 1 1 ", "3\n10 11 11 ", "1\n1 ", "5\n1 101 101 101 111 ", "1\n10011 ", "...
UNKNOWN
PYTHON3
CODEFORCES
288
2069be9dcf332b37be07c41ab9a6cbe3
Prime Number
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=......
[ "import sys\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nmod = 10 ** 9 + 7\r\nn, x = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\nans = pow(x, sum(a[:n - 1]), mod)\r\nma = a[-1]\r\n\r\nwhile len(a) > 1:\r\n cur, num = a.pop(), 1\r\n\r\n while a and a[-1] == c...
{"inputs": ["2 2\n2 2", "3 3\n1 2 3", "2 2\n29 29", "4 5\n0 0 0 0", "1 2\n1000000000", "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "3 2\n0 1 1", "1 127\n1000000000", "1 800000011\n800000011", "1 800000011\n999999999", "3 3\n1 1 1"], "outputs"...
UNKNOWN
PYTHON3
CODEFORCES
13
207081d9060d847aa6f8df056fb88ba6
Divisibility
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer ...
[ "# LUOGU_RID: 113656736\nprint(int(input())//2520)", "import math\r\nn = int(input())\r\nb = math.sqrt(n)\r\nc=0\r\nprint(n//2520)", "from math import floor\r\nn = int(input())\r\nprint(floor(n/2520))", "print(int(input())//2520)", "x = int(input())\nprint( x // 2520)\n \t\t \t\t \t \t\t \t \t\t \t\t\t ...
{"inputs": ["3000", "2520", "2519", "2521", "1", "314159265", "718281828459045235", "1000000000000000000", "987654321234567890", "3628800", "504000000000000000"], "outputs": ["1", "1", "0", "1", "0", "124666", "285032471610732", "396825396825396", "391926317950225", "1440", "200000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
13
207eede200d9ba24f994330c2b8cfabe
Pearls in a Row
There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal ...
[ "n = int(input())\r\nli = list(map(int,input().split()))\r\ns=set()\r\notv=[]\r\nl=0\r\nr=-1\r\nfor i in range(n):\r\n\tif li[i] in s:\r\n\t\totv.append([l+1,i+1])\r\n\t\ts = set()\r\n\t\tl = i+1\r\n\t\tr=1\r\n\telse:\r\n\t\ts.add(li[i])\r\nif r==-1:\r\n\tprint(-1)\r\nelse:\r\n\tprint(len(otv))\r\n\totv[len(otv)-1]...
{"inputs": ["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1", "9\n1 2 1 2 1 2 1 2 1", "11\n1 1 2 1 2 1 2 1 2 1 1", "1\n576560149", "10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451", "10\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 8067228...
UNKNOWN
PYTHON3
CODEFORCES
39
208c10eb84654fa8b3a2fc7a644f7f88
Grammar Lessons
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: - There are three parts of spee...
[ "import sys,os,math,cmath,timeit,functools,operator,bisect\r\nfrom sys import stdin,stdout,setrecursionlimit\r\nfrom io import BytesIO, IOBase\r\nfrom collections import defaultdict as dd , Counter\r\nfrom math import factorial , gcd\r\nfrom queue import PriorityQueue\r\nfrom heapq import merge, heapify, heappop, h...
{"inputs": ["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites", "qweasbvflios", "lios lios petr initis qwe", "lios initis", "petr initis lios", "petra petra petra", "in", "liala petra initis", "liala petra inites", "liala initis", "liala petra petr inites", "liala petr inites", "llilito...
UNKNOWN
PYTHON3
CODEFORCES
17
208e0d102a4aff006ad18836092a1fd9
Jeff and Digits
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that numbe...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\n_5=a.count(5)\r\n_0=a.count(0)\r\nif _0!=0:\r\n ans='5'*(_5)+'0'*(_0)\r\n while s/9!=s//9:\r\n s-=5\r\n _5-=1\r\n ans='5'*(_5)+'0'*(_0)\r\n print(int(ans))\r\nelse:\r\n print(-1)", "x = int(input())\r\nls = sorted(...
{"inputs": ["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5", "7\n5 5 5 5 5 5 5", "1\n5", "1\n0", "11\n5 0 5 5 5 0 0 5 5 5 5", "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "9\n5 5 5 5 5 5 5 5 5", "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "10\n0 0 0 0 0 0 0 0 0 0", "10\n5 5 5 5 5 0 0 5 0 5", "3\n5 5 0", "5...
UNKNOWN
PYTHON3
CODEFORCES
159
2098cd490c69f659d881f9271b7531fc
String Game
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert...
[ "s = input()\r\nsmall = input()\r\nnums = [int(x)-1 for x in input().split()]\r\nn = len(s)\r\nlo = 0\r\nans = 0\r\nhi = n-1\r\ndef check(x):\r\n copy = [1]*n\r\n index = 0\r\n for i in range(x):\r\n copy[nums[i]]=0\r\n for i in range(n):\r\n if s[i]==small[index] and copy[i]:\r\n ...
{"inputs": ["ababcba\nabb\n5 3 4 1 7 6 2", "bbbabb\nbb\n1 6 3 4 2 5", "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2", "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaa...
UNKNOWN
PYTHON3
CODEFORCES
82
20bba2c3e5ff8b9338dc245960535aab
Vanya and Triangles
Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area. The first line contains integer *n* (1...
[ "import math\r\nfrom collections import defaultdict\r\nclass Solution:\r\n def maxPoints(self, points):\r\n ans=0\r\n n=len(points)\r\n if n<=2:\r\n return ans\r\n def customise_gcd(x,y):\r\n if x==0 and y==0:\r\n return 1\r\n if x==0:\r...
{"inputs": ["4\n0 0\n1 1\n2 0\n2 2", "3\n0 0\n1 1\n2 0", "1\n1 1", "5\n0 0\n1 1\n2 2\n3 3\n4 4", "5\n0 0\n1 1\n2 3\n3 6\n4 10", "4\n-100 -100\n-100 100\n100 -100\n100 100", "5\n-100 -100\n-100 100\n100 -100\n100 100\n0 0", "4\n1 -100\n2 -100\n100 -99\n99 -99", "25\n26 -54\n16 56\n-42 -51\n92 -58\n100 52\n57 -98\n-84 -2...
UNKNOWN
PYTHON3
CODEFORCES
11
20bfb8b140bbbbc6164f4c0a84a2dc05
Sonya and Problem Wihtout a Legend
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of opera...
[ "from bisect import bisect_left as BL\r\n\r\nn = int(input())\r\ngraph = [(-99**9, 0)] # x, slope\r\nans = 0\r\nfor i,a in enumerate(map(int,input().split())):\r\n a-= i\r\n new = []\r\n turnj = BL(graph, (a,99**9)) - 1\r\n if turnj != len(graph)-1:\r\n ans+= graph[-1][0] - a\r\n \r\n # add...
{"inputs": ["7\n2 1 5 11 5 9 11", "5\n5 4 3 2 1", "2\n1 1000", "2\n1000 1", "5\n100 80 60 70 90", "10\n10 16 17 11 1213 1216 1216 1209 3061 3062", "20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158", "1\n1", "5\n1 1 1 2 3", "1\n1000", "50\n499 780 837 984 481 526 944 482 862 136 265 60...
UNKNOWN
PYTHON3
CODEFORCES
14
20c1e9422796af441c387c631d2715ab
Code Parsing
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the ...
[ "s=input()\r\nif s.count('x')>s.count('y'):\r\n s=\"x\"*(s.count('x')-s.count('y'))\r\nelse:\r\n s=\"y\"*(s.count('y')-s.count('x'))\r\nprint(s)\r\n", "string = input()\r\n\r\nx_count = string.count(\"x\")\r\ny_count = string.count(\"y\")\r\n\r\nif x_count > y_count:\r\n for _ in range(x_count - y_count)...
{"inputs": ["x", "yxyxy", "xxxxxy", "yxyyxyyx", "yxxyxyx", "xxx", "xxyxx", "xxxyx", "yxxxx", "xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy", "xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy", "xxxxxxxxxxxyxyyxxxxyxxxxxyxxxxxyxxxxxxxxyx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...
UNKNOWN
PYTHON3
CODEFORCES
54
20c573c0f46f02b35925d1e59ce6fc1e
Voting
There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions...
[ "import sys\r\nimport math\r\nfrom bisect import bisect_right as br\r\nfrom collections import deque\r\n#from statistics import mode\r\n\r\nfrom itertools import combinations as cb\r\n\r\ndef int_arr(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\ndef str_arr(): return list(map(str, sys.stdin....
{"inputs": ["5\nDDRRR", "6\nDDRRRR", "1\nD", "1\nR", "2\nDR", "3\nRDD", "3\nDRD", "4\nDRRD", "4\nDRRR", "4\nRDRD", "5\nDRDRR", "4\nRRRR", "5\nRDDRD", "5\nDDRRD", "5\nDRRRD", "5\nDDDDD", "6\nDRRDDR", "7\nRDRDRDD", "7\nRDRDDRD", "7\nRRRDDDD", "8\nRRRDDDDD", "9\nRRRDDDDDR", "9\nRRDDDRRDD", "9\nRRDDDRDRD", "10\nDDRRRDRRDD"...
UNKNOWN
PYTHON3
CODEFORCES
11
20ca84dc7382a495acdf33245bff71ca
Bear and Fair Set
Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate your mathematical skills. To test you, Limak is going to give you a puzzle to solve. It's a well-known fact that Limak, as e...
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,b,q=map(int,input().split())\r\nt=[(b,n)]\r\nfor _ in range(q):\r\n x,y=map(int,input().split())\r\n t.append((x,y))\r\n\r\nt.sort(key=lambda x:x[0])\r\ntask=[]\r\ntmp=1\r\nnow=0\r\nng=False\r\nfor x,y in t:\r\n if x+1==tmp:\r\n if y==now:...
{"inputs": ["10 20 1\n10 10", "10 20 3\n15 10\n5 0\n10 5", "10 20 2\n15 3\n20 10", "15 27 2\n6 4\n23 5", "50 7654 4\n1273 11\n6327 38\n1244 3\n5208 22", "50 7654 4\n2899 15\n3848 26\n2718 12\n5511 36", "50 7654 4\n4881 20\n4957 6\n4764 50\n944 44", "50 6457 1\n945 41", "500 5000 5\n1289 221\n694 178\n2179 454\n160 11\n...
UNKNOWN
PYTHON3
CODEFORCES
3
20e1b109cf2c373246172c975ecfd79e
Polo the Penguin and Matrix
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add ...
[ "n,m,d=map(int,input().split())\r\nans=True\r\nhehe=-1\r\nmat=[]\r\nfor i in range(n):\r\n row=list(map(int,input().split()))\r\n for k in row:\r\n mat.append(k)\r\n for j in range(m):\r\n if i==0 and j==0:\r\n hehe=row[j]%d\r\n continue\r\n if row[j]%d!=hehe:\r\n...
{"inputs": ["2 2 2\n2 4\n6 8", "1 2 7\n6 7", "3 2 1\n5 7\n1 2\n5 100", "3 3 3\n5 8 5\n11 11 17\n14 5 2", "3 3 3\n5 8 5\n11 11 17\n14 5 3", "2 2 4\n5 5\n5 5", "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7", "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 ...
UNKNOWN
PYTHON3
CODEFORCES
200
20f1c94c1e992cb8f01b83ea4ed216fb
none
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer *m*, bit depth of the game, which means that all numbers in the game will consist of *m* bits. Then he asks Peter to choose some *m*-bit number. After ...
[ "n, m = map(int, input().split())\n\nv = [('?', '')]\ntemp = [(0, 1)]\nd = {}\nd['?'] = 0\n\nmn, mx = '', ''\n\nfor i in range(n):\n name, val = input().split(' := ')\n v.append((name, val.split()))\n temp.append((-1, -1))\n d[name] = i + 1\n\ndef eval(expr, bit1, bit2):\n if expr == 'OR':\n r...
{"inputs": ["3 3\na := 101\nb := 011\nc := ? XOR b", "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb", "2 10\nb := 0100101101\na := ? XOR b", "1 10\na := 0110110011", "1 6\na := ? OR ?", "13 6\na := 111010\nb := 100100\nc := 001110\nd := b AND b\ne := c AND ?\nf := e OR c\ng := 011110\nh := d XOR ?\ni ...
UNKNOWN
PYTHON3
CODEFORCES
6
20fd49f9c64735d6bfb5a2ded627b23d
Shifts
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclically shift a table row one cell to the right means to move the ...
[ "def calc_shift_cost(row):\n starts = [i for i, x in enumerate(row) if x]\n for start in starts:\n d = 2\n pos = start + 1\n if pos == len(row):\n pos = 0\n while row[pos] != 1:\n if row[pos]:\n row[pos] = min(row[pos], d)\n else:\n ...
{"inputs": ["3 6\n101010\n000100\n100000", "2 3\n111\n000", "1 1\n1", "1 1\n0", "3 1\n1\n1\n0", "6 2\n10\n11\n01\n01\n10\n11", "3 3\n001\n010\n100", "4 4\n0001\n0100\n0010\n1000", "5 5\n10000\n01000\n00100\n00010\n00001", "5 5\n10001\n00100\n01000\n01001\n11111", "5 5\n11111\n11111\n11111\n11111\n00000", "5 10\n0001000...
UNKNOWN
PYTHON3
CODEFORCES
9
20fee0d2046c45179bcd2f922d225aae
Queue
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*. The *i*-th walrus becomes displeased if there's a younger...
[ "import bisect\r\nfrom collections import deque\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n\tl.append((arr[i],i))\r\nl.sort()\r\narr1=[]\r\nans=[-1]*n\r\na=-1\r\nfor i in range(n):\r\n\tif a<l[i][1]:\r\n\t\ta=l[i][1]\r\n\tans[l[i][1]]=a-l[i][1]-1\r\nprint(*ans)\r\n\r\n\...
{"inputs": ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11", "13\n18 9 8 9 23 20 18 18 33 25 31 37 36", "10\n15 21 17 22 27 21 31 26 32 30", "10\n18 20 18 17 17 13 22 20 34 29", "13\n16 14 12 9 11 28 30 21 35 30 32 31 43", "15\n18 6 18 21 14 20 13 9 18 20 28 13 19 25 21", "11\n15 17 18 18 26 22 23 33 33 21...
UNKNOWN
PYTHON3
CODEFORCES
51
20ffe02488c708a6ac25d6687efe45a2
Snacktower
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b...
[ "n = int(input())\r\nsnacks = {int(num): day for day, num in enumerate(input().split(\" \"))}\r\ndays = [[] for _ in range(n)]\r\nsorted_snacks = sorted(snacks, reverse=True)\r\ncurrent_day = None\r\nfor snack in sorted_snacks:\r\n snack_day = snacks[snack]\r\n if current_day is None:\r\n current_day =...
{"inputs": ["3\n3 1 2", "5\n4 5 1 2 3", "1\n1", "2\n1 2", "10\n5 1 6 2 8 3 4 10 9 7", "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 ...
UNKNOWN
PYTHON3
CODEFORCES
283
2107d7677a31fc3b2e3f2f48f90ea65d
Coach
A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on ...
[ "import sys\r\nfrom collections import defaultdict\r\ninput = sys.stdin.readline \r\n\r\nn, m = map(int, input().split()) \r\nd = defaultdict(list) \r\nfor i in range(m):\r\n u, v = map(int, input().split()) \r\n d[u].append(v) \r\n d[v].append(u) \r\n\r\nv = [0] * (n + 1) \r\np = [-1] * (n + 1) \r\n\r\nan...
{"inputs": ["3 0", "6 4\n1 2\n2 3\n3 4\n5 6", "3 3\n1 2\n2 3\n1 3", "6 3\n1 2\n3 4\n5 6", "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n13 15", "3 1\n1 3", "15 13\n1 9\n1 11\n2 7\n2 12\n3 8\n3 15\n4 10\n5 6\n5 14\n6 14\n7 12\n8 15\n9 11", "36 27\n1 34\n2 18\n2 20\n3 9\n3 21\n4 5\n4 25\n5 25\n6 13\n6 22\n8 23\n8 31...
UNKNOWN
PYTHON3
CODEFORCES
17
210b0dcb71762d4b15aa74549a099ce5
Compote
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ...
[ "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nans = 0\r\nfor aa in range(a + 1):\r\n bb, cc = 2 * aa, 4 * aa\r\n if bb <= b and cc <= c:\r\n ans = aa + bb + cc\r\nprint(ans)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\na, p = a//2, p//4\r\nm = min(a,l,p)\r\nprint(m*1 + m*...
{"inputs": ["2\n5\n7", "4\n7\n13", "2\n3\n2", "1\n1\n1", "1\n2\n4", "1000\n1000\n1000", "1\n1\n4", "1\n2\n3", "1\n1000\n1000", "1000\n1\n1000", "1000\n2\n1000", "1000\n500\n1000", "1000\n1000\n4", "1000\n1000\n3", "4\n8\n12", "10\n20\n40", "100\n200\n399", "200\n400\n800", "199\n400\n800", "201\n400\n800", "200\n399\n8...
UNKNOWN
PYTHON3
CODEFORCES
334
21597ff5cde4d9dc159f25a26dd6a0ce
Directed Roads
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of *n* towns numbered from 1 to *n*. There are *n* directed roads in the Udayland. *i*-th of them goes from town *i* to some other town *a**i* (*a**i*<=≠<=*i*). ZS the Coder can flip the direction of any road in...
[ "n = int(input())\r\nl = list(map(int, input().split()))\r\nl.insert(0,0)\r\nmark = {}\r\nloop, pos, res , mod= 0, 1, 1, int(1e9+7)\r\nfor i in range(1, n+1):\r\n if not i in mark:\r\n start, j = pos, i\r\n while not j in mark:\r\n mark[j] = pos\r\n pos+= 1\r\n j =...
{"inputs": ["3\n2 3 1", "4\n2 1 1 1", "5\n2 4 2 5 3", "4\n2 1 4 3", "7\n2 3 4 1 6 5 4", "20\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1", "2\n2 1", "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81...
UNKNOWN
PYTHON3
CODEFORCES
8
216626f8e3129d6463eb791d51eaa0ad
Permutation Cycle
For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows: Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists. For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=...
[ "#This code sucks, you know it and I know it. \r\n#Move on and call me an idiot later.\r\n\r\ndef solve(a, b, n):\r\n \r\n i = 0\r\n while i * a <= n:\r\n \r\n if (n - (i * a)) % b == 0:\r\n x = i\r\n y = (n - (i * a)) // b\r\n return (x, y)\r\n i = i + ...
{"inputs": ["9 2 5", "3 2 1", "7 4 4", "1000000 999998 3", "1 1 1", "993012 997 1001", "1000000 2017 881", "390612 20831 55790", "689292 69319 96267", "99929 99929 2", "807990 72713 11616", "514004 50866 26101", "631610 7702 63553", "391861 47354 60383", "822954 53638 55936", "794948 794948 85946", "786009 37429 59524"...
UNKNOWN
PYTHON3
CODEFORCES
21
21675d66e7006d324b0336d4ffb917d7
Almost Permutation
Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were *n* elements in the array, and each element was not ...
[ "#~ # MAGIC CODEFORCES PYTHON FAST IO\nimport atexit\nimport io\nimport sys\n\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput = iter(_INPUT_LINES).__next__\n_OUTPUT_BUFFER = io.StringIO()\nsys.stdout = _OUTPUT_BUFFER\n\n@atexit.register\ndef write():\n sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\n#~ # E...
{"inputs": ["3 0", "3 1\n1 1 3 2", "3 2\n1 1 3 2\n2 1 3 2", "3 2\n1 1 3 2\n2 1 3 1", "50 0", "50 1\n2 31 38 25", "50 2\n2 38 41 49\n1 19 25 24", "50 10\n2 4 24 29\n1 14 49 9\n2 21 29 12\n2 2 46 11\n2 4 11 38\n2 3 36 8\n1 24 47 28\n2 23 40 32\n1 16 50 38\n1 31 49 38", "50 20\n1 14 22 40\n1 23 41 3\n1 32 39 26\n1 8 47 25...
UNKNOWN
PYTHON3
CODEFORCES
4
216b7c32d3e33f332f60bc12ab2da822
Logo Turtle
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward"). You are given a list of commands that will be given to the turtle. You have to change exactly *n* commands from the l...
[ "s = input()\r\nn = int(input())\r\nl, r = [-1e9] * 101, [-1e9] * 101\r\nl[0] = r[0] = 0\r\nfor q in s:\r\n for j in range(n, -1, -1):\r\n x = max(r[j], l[j - 1] + 1) if q == 'T' else max(l[j] + 1, r[j - 1])\r\n y = max(l[j], r[j - 1] + 1) if q == 'T' else max(r[j] - 1, l[j - 1])\r\n l[j], r...
{"inputs": ["FT\n1", "FFFTFFF\n2", "F\n1", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n50", "FTFTFTFFFFTFTFTTTTTTFFTTTTFFTFFFTFTFTFFTFTFTFFFTTTFTTFTTTTTFFFFTTT\n12", "TTFFTFTTFTTTFFFTFTFFTFFTTFFTFTFTFTFFTTTFTFFTFFTTTTFTTTFFT\n46", "TTFFFFFFFTTTTFTTFTFFTTFFFTFTT...
UNKNOWN
PYTHON3
CODEFORCES
7
217e38012c7854256183c07a6bdc62c5
Petya's Exams
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: - $s_i$ — the day, when questions for the $i$-th exam will be published, -...
[ "(n, m) = map(int, input().split())\r\n\r\narray = [0] * (n + 1)\r\nlst = []\r\nfor x in range(m):\r\n (s, d, c) = map(int, input().split())\r\n lst.append((d, s, c, x + 1))\r\n\r\nlst.sort()\r\ni = 0\r\nflag = True\r\nfor (d, s, c, p) in lst:\r\n x = s\r\n while c > 0 and x < d:\r\n if array[x] ...
{"inputs": ["5 2\n1 3 1\n1 5 1", "3 2\n1 3 1\n1 2 1", "10 3\n4 7 2\n1 10 3\n8 9 1", "2 1\n1 2 1", "3 1\n1 2 2", "3 1\n1 3 2", "100 1\n1 100 99", "100 1\n1 100 100", "100 1\n1 100 98", "100 2\n1 100 49\n1 99 49", "10 2\n3 7 4\n6 10 1", "10 4\n2 5 1\n1 4 2\n4 7 1\n7 10 2", "20 5\n6 16 3\n4 14 4\n3 13 1\n1 11 1\n10 20 4",...
UNKNOWN
PYTHON3
CODEFORCES
10
2189a2c8e311addc29b933b2d542edfc
Circle of Numbers
*n* evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number *k*. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by *k* or decrease all numbers at ...
[ "def factor(n):\n ps = []\n for i in range(2, n):\n if i * i > n:\n break\n if n % i == 0:\n e = 0\n while n % i == 0:\n e += 1\n n //= i\n ps += [(i, e)]\n if n > 1:\n ps += [(n, 1)]\n return ps\n\n\nn = int(...
{"inputs": ["30\n000100000100000110000000001100", "6\n314159", "3\n000", "15\n522085220852208", "300\n51849955123882532841766314023795544655059625429948511546532555041357758442089311502553567597180892645169105593021958599780734407001184543473352601711893354858975964992001656857820176956422821004573923066450696828141422...
UNKNOWN
PYTHON3
CODEFORCES
1
218df72e4efbe2b7cc341ffe3d16707e
Rebranding
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog...
[ "def solve():\n N, M = map(int, input().split())\n name = input()\n\n td = {}\n for c in 'abcdefghijklmnopqrstuvwxyz':\n td[c] = c\n\n for i in range(M):\n p, m = input().split()\n if p == m:\n continue\n pt = td[p]\n mt = td[m]\n del td[p]\n ...
{"inputs": ["6 1\npolice\np m", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "1 1\nf\nz h", "1 1\na\na b", "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e"], "outputs": ["molice", "cdcbcdcfcdc", "f", "b", "lellelleel"]}
UNKNOWN
PYTHON3
CODEFORCES
119
219366dfd3d5a68d977c0efa6cb0721a
DZY Loves Sequences
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible ...
[ "# Love u Atreyee\nn = int(input())\na = list(map(int, input().split()))\nleft = [1] * n\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n left[i] = left[i - 1] + 1\nright = [1] * n\nfor i in range(n-2,-1,-1):\n if a[i] < a[i + 1]:\n right[i] = right[i + 1] + 1\nans = max(left)\nif ans < n:\n an...
{"inputs": ["6\n7 2 3 1 5 6", "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 ...
UNKNOWN
PYTHON3
CODEFORCES
59
21981a6dd776117fe98a2f0d77c136c9
Average Sleep Time
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp k...
[ "n, k = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\n\ntot = 0\nfor i in range(k):\n tot += a[i]\n\nans = tot\nfor i in range(k, n):\n tot += a[i]\n tot -= a[i - k]\n ans += tot\n\nprint(ans / (n - k + 1))\n\n \t \t\t\t\t\t \t \t\t\t\t\t \t\t \t\t \t \t\t\t", "from sys impo...
{"inputs": ["3 2\n3 4 7", "1 1\n10", "8 2\n1 2 4 100000 123 456 789 1", "1 1\n1", "1 1\n100000", "3 1\n1 2 3", "10 4\n11 3 5 20 12 7 9 2 2 20", "10 5\n15 9 3 2 17 10 9 18 4 19", "10 6\n19 3 20 16 14 10 1 13 7 3", "10 7\n8 16 2 13 15 9 5 13 9 2", "10 4\n127 1459 718 1183 880 1044 1857 1340 725 1496", "10 5\n1384 1129 17...
UNKNOWN
PYTHON3
CODEFORCES
97
21b7de902f49277b20a3051ca8ba9528
Rook, Bishop and King
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of...
[ "def stessocolore(x1,y1,x2,y2):\r\n if (x1+y1)%2 == (x2+y2)%2:\r\n return True\r\n else:\r\n return False\r\nx1, y1, x2, y2 = map(int, input().split())\r\nif x1 == x2 or y1 == y2:\r\n rook = 1\r\nelse:\r\n rook = 2\r\nking = max([abs(x1-x2),abs(y1-y2)])\r\nif stessocolore(x1,y1,x2,y2):\r\n...
{"inputs": ["4 3 1 6", "5 5 5 6", "1 1 8 8", "1 1 8 1", "1 1 1 8", "8 1 1 1", "8 1 1 8", "7 7 6 6", "8 1 8 8", "1 8 1 1", "1 8 8 1", "1 8 8 8", "8 8 1 1", "8 8 1 8", "8 8 8 1", "1 3 1 6", "1 3 1 4", "1 3 1 5", "3 3 2 4", "3 3 1 5", "1 6 2 1", "1 5 6 4", "1 3 3 7", "1 1 8 1", "1 7 5 4", "1 5 2 7", "1 4 6 2", "1 2 3 5", ...
UNKNOWN
PYTHON3
CODEFORCES
217
21c7afb1480e78ad47c23361b6dbbc61
Valera and Plates
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can...
[ "n, m, k = map(int, input().split())\r\ndaf = list(map(int, input().split()))\r\n\r\nc = 0\r\ntotal = 0\r\nwhile (m>0 or k>0) and c < n:\r\n f = daf[c]\r\n if f == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n total += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r...
{"inputs": ["3 1 1\n1 2 1", "4 3 1\n1 1 1 1", "3 1 2\n2 2 2", "8 2 2\n1 2 1 2 1 2 1 2", "2 100 100\n2 2", "1 1 1\n2", "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 ...
UNKNOWN
PYTHON3
CODEFORCES
223
21c80b84de37c0a6a459ebd411c862bc
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the customer takes a special basket, where he puts exactly *q**i* items he buys. Unde...
[ "from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor _ in range(1):#nmbr()):\r\n n=nmbr()\r\n a=sorted(lst())\r\n d=a[0]\r\n n=nmbr()\r\n a=sorted(lst())\r\n ans=0\r\n p=n-1;buy=d\r\n while p>=0:\r\n if d...
{"inputs": ["1\n2\n4\n50 50 100 100", "2\n2 3\n5\n50 50 50 50 50", "1\n1\n7\n1 1 1 1 1 1 1", "60\n7 4 20 15 17 6 2 2 3 18 13 14 16 11 13 12 6 10 14 1 16 6 4 9 10 8 10 15 16 13 13 9 16 11 5 4 11 1 20 5 11 20 19 9 14 13 10 6 6 9 2 13 11 4 1 6 8 18 10 3\n26\n2481 6519 9153 741 9008 6601 6117 1689 5911 2031 2538 5553 1358 ...
UNKNOWN
PYTHON3
CODEFORCES
35
21d3086ee327553584f533280fdd7ad2
Broken checker
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. The only line of the input contains ...
[ "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-29 23:39:34\nLastEditTime: 2021-11-29 23:40:38\nDescription: Broken checker\nFilePath: CF171D.py\n'''\n\n\ndef func():\n n = int(input())\n print(n % 5 % 3 + 1)\n\n\nif __name__ == '__main__':\n func()\n", "from collections import ...
{"inputs": ["3", "1", "4", "2", "5"], "outputs": ["1", "2", "2", "3", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
39
21daae042f23778474d174e49a3103bf
DravDe saves the world
How horrible! The empire of galactic chickens tries to conquer a beautiful city "Z", they have built a huge incubator that produces millions of chicken soldiers a day, and fenced it around. The huge incubator looks like a polygon on the plane *Oxy* with *n* vertices. Naturally, DravDe can't keep still, he wants to dest...
[ "class Point:\r\n def __init__(self, x, y, z=0):\r\n self.x = x\r\n self.y = y\r\n self.z = z\r\ndef main():\r\n n = int(input())\r\n pt = [Point(0, 0) for _ in range(n)]\r\n for i in range(n):\r\n pt[i].x, pt[i].y = map(float, input().split())\r\n a = Point(0, 0)\r\n v...
{"inputs": ["4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 0 1\n-1\n0 1 -1", "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n-1 -1 1\n-1\n0 1 -1", "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-1\n1 1 -1", "3\n-3 4\n5 -1\n-1 0\n-4 3\n4 4 5\n-3\n0 -3 -4", "4\n-2 1\n3 3\n2 -4\n0 -5\n-4 3\n2 4 4\n-4\n2 5 -4", "5\n10 10\n9 10\n8 9\n9 8\n10 9\n-10 -10\n1 1 1\n-1\n0...
UNKNOWN
PYTHON3
CODEFORCES
1