problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
34 values
language
listlengths
1
1
source
stringclasses
15 values
num_solutions
int64
1
1.12M
starter_code
stringlengths
0
1.47k
subset
stringclasses
4 values
0778aa7a20f7b27334849051c11f9602
Students and Shoelaces
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f...
{"inputs": ["3 3\n1 2\n2 3\n3 1", "6 3\n1 2\n2 3\n3 4", "6 5\n1 4\n2 4\n3 4\n5 4\n6 4", "100 0", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "5 4\n1 4\n4 3\n4 5\n5 2", "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11", "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7", "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
237
codeforces
07902d236432619d14659700820648c9
Print Check
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr...
{"inputs": ["3 3 3\n1 1 3\n2 2 1\n1 2 2", "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1", "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1", "4 6 8\n1 2 1\n2 2 2\n2 5 2\n1 1 1\n1 4 1\n1 3 2\n2 1 1\n2 6 1", "2 2 3\n1 1 1\n1 2 1\n2 1 2", "1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 1 4", "2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7", "2 1 1\n1 2 10000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
07989c83d8bc7dc0fdea38e2fd47631e
Limit
You are given two polynomials: - *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*. Calculate limit . The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤...
{"inputs": ["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2", "1 2\n5 3\n-3 2 -1", "1 2\n-4 8\n-2 5 -3", "3 2\n4 3 1 2\n-5 7 0", "2 1\n-3 5 1\n-8 0", "1 1\n-5 7\n3 1", "2 2\n-4 2 1\n-5 8 -19", "0 100\n1\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
07cfb7284bc4b16ef707dca90a4ae19b
Ciel and Flowers
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
{"inputs": ["3 6 9", "4 4 4", "0 0 0", "0 3 6", "7 8 9", "8 8 9", "15 3 999", "32 62 92", "123456789 123456789 123456789", "3 5 5", "666806767 385540591 357848286", "80010646 727118126 817880463", "829651016 732259171 572879931", "242854896 442432924 180395753", "139978911 5123031 935395222", "553182792 10264076 395427...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
164
codeforces
07e8e7ca410450aa80ee6f50332b2730
Nested Segments
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2. Print indices ...
{"inputs": ["5\n1 10\n2 9\n3 9\n2 3\n2 9", "3\n1 5\n2 6\n6 20", "1\n1 1000000000", "2\n1 1000000000\n1 1000000000", "2\n1 1000000000\n500000000 500000000", "2\n1 10\n2 10", "2\n10 20\n10 11", "3\n1 10\n10 20\n9 11", "3\n1 1\n2 3\n2 2", "4\n1 10\n2 11\n3 10000000\n3 100000000", "2\n3 7\n3 9", "3\n1 2\n2 3\n1 2", "3\n5 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
0805544b42a2fa2cf7c8af86b1828a24
Woodcutters
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
{"inputs": ["5\n1 2\n2 1\n5 10\n10 9\n19 1", "5\n1 2\n2 1\n5 10\n10 9\n20 1", "4\n10 4\n15 1\n19 3\n20 1", "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
119
codeforces
0809402a1a60bd55b9c7d727fb789750
I'm Feeling Lucky!
You have one chip and one chance to play roulette. Are you feeling lucky? none Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). Sample Input Sample Output
{"inputs": ["1", "2"], "outputs": ["Red", "Red"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
081a9bd5d32d2b49603b55c4d22f0f1a
CGCDSSQ
Given a sequence of integers *a*1,<=...,<=*a**n* and *q* queries *x*1,<=...,<=*x**q* on it. For each query *x**i* you have to count the number of pairs (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=*n* and *gcd*(*a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*)<==<=*x**i*. is a greatest common divisor of *v*1,<=*v*2,<=...,<=*v**n*...
{"inputs": ["3\n2 6 3\n5\n1\n2\n3\n4\n6", "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000", "10\n2 2 4 3 2 4 4 2 4 2\n104\n3\n3\n1\n4\n1\n1\n4\n1\n1\n3\n1\n1\n4\n1\n1\n1\n4\n3\n1\n1\n4\n1\n1\n1\n1\n1\n4\n1\n1\n1\n4\n1\n1\n4\n1\n1\n1\n1\n1\n4\n4\n1\n3\n1\n4\n1\n1\n1\n4\n1\n2\n4\n1\n4\n1\n4\n1\n4\n3\n1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
081d8e6da4564dd6581c8fa783184064
Bear and Tower of Cubes
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side *a* has volume *a*3. A tower consisting of blocks with sides *a*1,<=*a*2,<=...,<=*a**k* has the total volume *a*13<=...
{"inputs": ["48", "6", "1", "994", "567000123", "123830583943", "3842529393411", "999999993700000", "2", "7", "8", "9", "112", "113", "114", "265", "995", "200385", "909383000", "108000000057", "385925923480002", "735412349812385", "980123123123123", "999088000000000", "409477218238716", "409477218238717", "40947721823...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
083a9815944008ba711925b5f50cf089
Quest
Polycarp is making a quest for his friends. He has already made *n* tasks, for each task the boy evaluated how interesting it is as an integer *q**i*, and the time *t**i* in minutes needed to complete the task. An interesting feature of his quest is: each participant should get the task that is best suited for him, d...
{"inputs": ["5 5\n1 1\n1 1\n2 2\n3 3\n4 4", "5 5\n4 1\n4 2\n4 3\n4 4\n4 5", "2 2\n1 1\n2 10", "10 1\n1 732\n1 649\n1 821\n1 756\n1 377\n1 216\n1 733\n1 420\n1 857\n1 193", "26 5\n2 377\n3 103\n1 547\n2 700\n3 616\n5 363\n2 316\n5 260\n3 385\n2 460\n4 206\n4 201\n3 236\n1 207\n1 400\n2 382\n2 365\n1 633\n1 775\n4 880\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
084b9cdce2412ac171a9ce35f14235bf
A and B and Compilation Errors
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix...
{"inputs": ["5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "3\n1 2 3\n3 2\n2", "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 38...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
469
codeforces
085cd5f8330878529b11be96555d4370
Modular Exponentiation
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108)....
{"inputs": ["4\n42", "1\n58", "98765432\n23456789", "8\n88127381", "32\n92831989", "92831989\n25", "100000000\n100000000", "7\n1234", "1\n1", "1\n100000000", "100000000\n1", "1\n2", "2\n1", "2\n2", "2\n3", "2\n4", "2\n5", "25\n33554432", "26\n33554432", "25\n67108864", "26\n67108864", "25\n92831989", "26\n92831989", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
207
codeforces
0882f289635cddade3200c48974d967a
Summer sell-off
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag...
{"inputs": ["4 2\n2 1\n3 5\n2 3\n1 5", "4 1\n0 2\n0 3\n3 5\n0 6", "1 1\n5 8", "2 1\n8 12\n6 11", "2 1\n6 7\n5 7", "2 1\n5 7\n6 7", "2 1\n7 8\n3 6", "2 1\n9 10\n5 8", "2 1\n3 6\n7 8", "1 0\n10 20", "2 1\n99 100\n3 6", "4 2\n2 10\n3 10\n9 9\n5 10", "2 1\n3 4\n2 8", "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
161
codeforces
088b9540ecc22ef3dbc2ddd6c0379edb
Mysterious numbers - 1
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. Output a single integer. The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. Output a single integer. Sample Input 3 14 27 12 100 200 Sample Output 44 48 102
{"inputs": ["3 14", "27 12", "100 200", "0 0", "31415 92653", "1000000000 0", "0 1000000000", "1000000000 1000000000", "804289383 846930886", "681692777 714636915", "957747793 424238335", "719885386 649760492", "596516649 189641421", "25202362 350490027", "783368690 102520059", "44897763 967513926", "365180540 54038342...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
134
codeforces
088e63003cb5ff192da74dde87343ee2
Cubes for Masha
Absent-minded Masha got set of *n* cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*. To make a number Masha can rotate her cubes and put them in a ro...
{"inputs": ["3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9", "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5", "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8", "1\n5 2 2 5 6 7", "1\n7 6 5 8 9 0", "1\n2 5 9 6 7 9", "1\n6 3 1 9 4 9", "1\n1 9 8 3 7 8", "2\n1 7 2 0 4 3\n5 2 3 6 1 0", "2\n6 0 1 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
66
codeforces
088f715b6f6f4cbc5ca4bf8d45009bac
Shark
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the d...
{"inputs": ["8\n1 2 7 3 4 8 5 6", "6\n25 1 2 3 14 36", "20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11", "7\n1 2 5 7 3 4 6", "1\n1000000000", "1\n1", "2\n1 2", "2\n2 1", "22\n22 1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11 21", "63\n32 48 31 56 30 47 29 60 28 46 27 55 26 45 25 62 24 44 23 54 22 43 21 59 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
089b8a488dba959a972c0b836cdecbcb
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of *n* rows and *m* columns. Each cell consis...
{"inputs": ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "5 3\n.XX\n...\n.X.\n.X.\n...\n1 3\n4 1", "1 1\nX\n1 1\n1 1", "1 6\n.X...X\n1 2\n1 5", "7 1\nX\n.\n.\n.\nX\n.\n.\n5 1\n3 1", "1 2\nXX\n1 1\n1 1", "2 1\n.\nX\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
08aee82431bd65836b8729845b0259d3
Building Permutation
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
{"inputs": ["2\n3 0", "3\n-1 -1 2", "5\n-3 5 -3 3 3", "10\n9 6 -2 4 1 1 1 9 6 2", "9\n2 0 0 6 5 4 1 9 3", "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
473
codeforces
08db6a75d49bfd251c8032e15206044e
Soldier and Badges
Colonel has *n* badges. He wants to give one badge to every of his *n* soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the s...
{"inputs": ["4\n1 3 1 4", "5\n1 2 3 2 5", "5\n1 5 3 2 4", "10\n1 1 2 3 4 5 6 7 8 9", "11\n9 2 10 3 1 5 7 1 4 8 6", "4\n4 3 2 2", "1\n1", "50\n49 37 30 2 18 48 14 48 50 27 1 43 46 5 21 28 44 2 24 17 41 38 25 18 43 28 25 21 28 23 26 27 4 31 50 18 23 11 13 28 44 47 1 26 43 25 22 46 32 45", "50\n37 31 19 46 45 1 9 37 15 19...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
09028546725df22927fed193057b8579
Interesting Array
We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) meaning that value should be equal to *q**i*. Your task is to find any inte...
{"inputs": ["3 1\n1 3 3", "3 2\n1 3 3\n1 3 2", "3 2\n1 2 536870912\n2 3 536870911", "1 1\n1 1 10", "1 2\n1 1 10\n1 1 5", "1 2\n1 1 1\n1 1 3"], "outputs": ["YES\n3 3 3", "NO", "YES\n536870912 1073741823 536870911", "YES\n10", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
093473bbf5193af87dcc821da582c09a
Mice problem
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i...
{"inputs": ["4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "4\n8 42 60 54\n9 54 -58 -62\n46 47 52 -76\n15 50 -37 -40\n54 51 78 64", "4\n17501 63318 51967 74514\n1305 84026 79493 -78504\n41159 81000 -44104 -42722\n31063 65435 25578 33487\n18330 79949 83467 -745...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
0934a086c394bd534e3de5e39e4d2d6d
none
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory. Though Ryouko is forgetful, she is also bo...
{"inputs": ["4 6\n1 2 3 4 3 2", "10 5\n9 4 3 8 8", "5 10\n2 5 2 2 3 5 3 2 1 3", "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2", "100 100\n28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
09461ae3143b37d74a6e1f5d636239d7
F1 Champions
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the cha...
{"inputs": ["3\n3\nHamilton\nVettel\nWebber\n2\nWebber\nVettel\n2\nHamilton\nVettel", "2\n7\nProst\nSurtees\nNakajima\nSchumacher\nButton\nDeLaRosa\nBuemi\n8\nAlonso\nProst\nNinoFarina\nJimClark\nDeLaRosa\nNakajima\nPatrese\nSurtees", "5\n3\nWebber\nTrulli\nJones\n9\nVilleneuve\nBerger\nJimClark\nReneArnoux\nKubica\nJo...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
09721cc3e0498b7c44b09aaff2a73aec
Fibonacci-ish
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if 1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=2<==<=*f**n*<=+<=1<=+<=*f**n* for all *n*<=≥<=0. You are given some sequence of integers *a*1,<=*a...
{"inputs": ["3\n1 2 -1", "5\n28 35 7 14 21", "11\n-9 -1 -10 9 7 -4 0 -8 -3 3 5", "10\n-4 -8 -8 8 -9 0 -7 9 1 0", "2\n2 2", "4\n1 -1 0 -2", "2\n1000000000 1000000000", "3\n1 1 2", "5\n0 0 0 0 0", "6\n1 -1 0 -1 -1 -2", "5\n-7 0 -7 -7 -14", "3\n0 -44 -49", "5\n-1 1 0 0 0", "2\n0 0", "3\n0 0 0", "4\n0 0 0 0", "5\n0 0 0 0 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
0997d5cbc678eb115b8bcdbbc2972483
OR in Matrix
Let's define logical *OR* as an operation on two logical values (i. e. values that belong to the set {0,<=1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical *OR* of three or more logical values in the same manner: where is equal to 1 if some *a**i*<==...
{"inputs": ["2 2\n1 0\n0 0", "2 3\n1 1 1\n1 1 1", "2 3\n0 1 0\n1 1 1", "5 5\n1 1 1 1 1\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0\n1 0 0 0 0", "5 5\n1 1 1 0 1\n1 1 0 0 1\n0 0 1 1 1\n1 1 1 1 0\n1 0 1 1 1", "5 6\n1 0 0 0 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 0 0 0 1 1\n1 0 0 0 1 1", "5 6\n1 1 1 1 0 1\n1 1 1 1 0 1\n1 1 1 0 1 1\n1 1 0 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
09d000220511dfbd7fd7cc548757d59f
Cinema Line
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t...
{"inputs": ["4\n25 25 50 50", "2\n25 100", "4\n50 50 25 25", "3\n25 50 100", "10\n25 25 25 25 25 25 25 25 25 25", "10\n50 50 50 50 50 50 50 50 50 50", "10\n100 100 100 100 100 100 100 100 100 100", "7\n25 25 25 25 50 100 50", "2\n25 25", "3\n50 100 100", "3\n25 50 50", "2\n50 25", "14\n25 25 25 25 25 25 25 50 50 50 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
231
codeforces
09d40e2bc0055c8680e6d11af183944d
Chocolate
Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a se...
{"inputs": ["2 2 2\n1 0 1 2\n0 1 1 1", "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "2 4 2\n0 1 2 1\n0 3 2 3", "5 5 3\n2 1 2 5\n0 1 5 1\n4 0 4 1", "10 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4", "9 8 5\n4 3 4 4\n0 4 9 4\n5 4 5 8\n0 3 9 3\n1 4 1 8", "100 100 1\n0 14 100 14"], "outputs": ["1 1 2 ", "1 1 1 1 ", "2 2 4 ", "1 4 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
09f17070acfce7ef738cea733b9580cc
Guard Duty (easy)
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign *R* Rebel spaceships to guard *B* bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching)....
{"inputs": ["3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2", "2 1\n1 0\n2 2\n3 1", "1 1\n3686 4362\n-7485 5112", "1 2\n1152 -7324\n-5137 -35\n-6045 -5271", "1 3\n-8824 -9306\n-5646 -9767\n8123 9355\n-6203 -1643", "1 5\n-8775 6730\n-3806 -6906\n-9256 -8240\n-1320 6849\n8155 746\n8284 -7317", "1 8\n8741 3638\n381 -9191\n7534 8792\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
0a0588ca9a3a9fe73cf3652e5a256608
Counting Sticks
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
{"inputs": ["||+|=|||||", "|||||+||=||", "|+|=||||||", "||||+||=||||||", "||||||||||||+|||||||||||=||||||||||||||||||||||", "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||", "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||", "||||||...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
66
codeforces
0a48bba8bf70b092497deaa39818e3b3
Replacement
Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace thi...
{"inputs": ["10 3\n.b..bz....\n1 h\n3 c\n9 f", "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a", "3 3\n...\n1 .\n2 a\n3 b", "5 1\n.....\n5 z", "1 5\n.\n1 .\n1 w\n1 w\n1 .\n1 .", "2 7\nab\n1 w\n2 w\n1 c\n2 .\n2 .\n1 .\n2 b"], "outputs": ["4\n3\n1", "1\n3\n1\n1", "2\n0\n0", "3", "0\n0\n0\n0\n0", "0\n0\n0\n0\n0\n1\n0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
0a6472dce2494a2e91dfd077f9e702f5
Ksusha and Square
Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles. Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integer points (points with integer coordinates) inside or on the border of the ...
{"inputs": ["3\n0 0\n5 5\n5 0", "4\n-1 3\n4 5\n6 2\n3 -5", "3\n17 136\n859 937\n16 641", "6\n-29 6\n-28 27\n-2 18\n13 9\n20 -18\n19 -27", "7\n-29 5\n-20 13\n-4 22\n8 20\n21 9\n16 -29\n-23 -30", "8\n-18 -20\n16 -28\n29 -29\n29 25\n15 27\n-19 30\n-28 18\n-30 -16", "6\n13 -22\n26 -11\n30 12\n22 19\n-10 24\n-29 6", "6\n13 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0a77299d877452686d821dfc2e1a59db
Kingdom and its Cities
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible. The kingdom curren...
{"inputs": ["4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7", "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 5 7\n3 2 4 6\n2 1 7\n2 3 4\n3 1 6 7", "30\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n4 8\n4 9\n6 10\n6 11\n11 30\n11 23\n30 24\n30 25\n25 26\n25 27\n27 29\n27 28\n23 20\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0a8a38ebf3e78262dba34af1e7e92873
LCS Again
You are given a string *S* of length *n* with each character being one of the first *m* lowercase English letters. Calculate how many different strings *T* of length *n* composed from the first *m* lowercase English letters exist such that the length of LCS (longest common subsequence) between *S* and *T* is *n*<=-<=...
{"inputs": ["3 3\naaa", "3 3\naab", "1 2\na", "10 9\nabacadefgh", "15 3\nabababababababa", "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf", "1 26\nz"], "outputs": ["6", "11", "1", "789", "345", "237400", "25"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
0a939d1c828a3ea1733a4fa8264770f0
Sereja and Bottles
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use...
{"inputs": ["4\n1 1\n2 2\n3 3\n4 4", "4\n1 2\n2 3\n3 4\n4 1", "3\n2 828\n4 392\n4 903", "4\n2 3\n1 772\n3 870\n3 668", "5\n1 4\n6 6\n4 3\n3 4\n4 758", "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
152
codeforces
0a95eeba755158f174d4cf94db15d536
Playing on Graph
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task. Vova has a non-directed graph consisting of *n* vertices and *m* edges without loops and multiple edges. Let's define the operation of contraction two vertices *a* and *b* that are not connected by an edge. ...
{"inputs": ["5 4\n1 2\n2 3\n3 4\n3 5", "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4", "4 2\n1 3\n2 4", "1 0", "1000 0", "1000 4\n100 200\n200 300\n300 400\n400 100", "14 30\n12 10\n1 7\n12 13\n7 3\n14 10\n3 12\n11 1\n2 12\n2 5\n14 3\n14 1\n14 4\n6 7\n12 6\n9 5\n7 10\n8 5\n6 14\n13 7\n4 12\n9 10\n1 9\n14 5\n1 8\n2 13\n5 11\n8 6\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
0aafc953e4cb8c334f377fa3d8dade25
Mike and Cellphone
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and ...
{"inputs": ["3\n586", "2\n09", "9\n123456789", "3\n911", "3\n089", "3\n159", "9\n000000000", "4\n0874", "6\n235689", "2\n10", "3\n358", "6\n123456", "1\n0", "4\n0068", "6\n021149", "5\n04918", "2\n05", "4\n0585", "4\n0755", "2\n08", "4\n0840", "9\n103481226", "4\n1468", "7\n1588216", "9\n188758557", "1\n2", "2\n22", "8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
74
codeforces
0ac572944c18ff62cd4cdee0e5b6d977
Prefix Sums
Consider the function *p*(*x*), where *x* is an array of *m* integers, which returns an array *y* consisting of *m*<=+<=1 integers such that *y**i* is equal to the sum of first *i* elements of array *x* (0<=≤<=*i*<=≤<=*m*). You have an infinite sequence of arrays *A*0,<=*A*1,<=*A*2..., where *A*0 is given in the input...
{"inputs": ["2 2\n1 1", "3 6\n1 1 1", "3 1\n1 0 1", "3 1000000000000000000\n5 4 5", "4 1000000000000000000\n0 4 4 5", "5 1000000000000000000\n5 7 4 2 5", "3 999999999000999944\n7 2 6", "4 999999999000531216\n8 7 4 6", "5 152742477016321721\n0 0 2 6 2", "6 1000000000000000000\n1 1 0 1 0 1", "7 1000000000000000000\n77 94...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
0accdcf59f157331ff148bce81f9c08f
The Child and Binary Tree
Our child likes computer science very much, especially he likes binary trees. Consider the sequence of *n* distinct positive integers: *c*1,<=*c*2,<=...,<=*c**n*. The child calls a vertex-weighted rooted binary tree good if and only if for every vertex *v*, the weight of *v* is in the set {*c*1,<=*c*2,<=...,<=*c**n*}....
{"inputs": ["2 3\n1 2", "3 10\n9 4 3", "5 10\n13 10 6 4 15", "1 1\n1", "10 100\n9 95 37 56 39 86 59 5 68 82", "10 100\n7 9 8 6 4 10 1 3 5 2", "50 1000\n10 93 11 34 85 17 61 87 58 38 56 83 55 52 70 18 47 82 36 67 53 98 81 41 23 39 13 99 64 16 91 48 22 12 92 78 86 1 65 46 21 57 7 72 31 71 90 68 35 45", "100 1000\n302 622...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0adb4a5d61e65a02984cf51e149b2854
Hongcow Builds A Nation
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world. There is at ...
{"inputs": ["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3", "10 3 2\n1 10\n1 2\n1 3\n4 5", "1 0 1\n1", "1000 0 1\n72", "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
70
codeforces
0af3b1bc78e71d52499dca72feb7585a
Matrix
You have a string of decimal digits *s*. Let's define *b**ij*<==<=*s**i*·*s**j*. Find in matrix *b* the number of such rectangles that the sum *b**ij* for all cells (*i*,<=*j*) that are the elements of the rectangle equals *a* in each rectangle. A rectangle in a matrix is a group of four integers (*x*,<=*y*,<=*z*,<=*t...
{"inputs": ["10\n12345", "16\n439873893693495623498263984765", "0\n1230", "8398\n67950927224842887617892831243606761170908507858527", "2\n11", "4\n111", "0\n0", "1\n0", "0\n1", "0\n0000", "1\n00", "1\n000", "1\n11111", "700\n10010101101100110011110110010100010000000001100111100011111000101101110001011000000000010010000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
0afab2f715e57b35f1e1aec2cc5c45c4
Mike and Feet
Mike is the president of country What-The-Fatherland. There are *n* bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to *n* from left to right. *i*-th bear is exactly *a**i* feet high. A group of bears is a non-empty contiguous segment of the line. The size of...
{"inputs": ["10\n1 2 3 4 5 4 3 2 1 6", "3\n524125987 923264237 374288891", "5\n585325539 365329221 412106895 291882089 564718673", "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 7178028...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
41
codeforces
0b127ebd2dca7cee059e0809b100c238
Forgotten Episode
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which...
{"inputs": ["10\n3 8 10 1 7 9 6 5 2", "5\n4 3 2 1", "2\n1", "2\n2", "3\n1 2", "3\n1 3", "3\n2 3", "3\n2 1", "3\n3 1", "3\n3 2", "5\n2 3 4 5", "5\n5 4 3 2", "5\n5 2 4 3", "5\n1 2 3 4", "5\n2 1 3 4", "5\n1 5 3 4", "5\n1 4 5 2", "5\n2 1 5 3", "5\n2 3 4 5"], "outputs": ["4", "5", "2", "1", "3", "2", "1", "3", "2", "1", "1"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
226
codeforces
0b317f93ef6e52490255f4b48d43b09a
Tickets
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for t...
{"inputs": ["5 3 1", "0 5 5", "0 1 0", "95105 76851 10", "60503 53620 1", "25902 30390 2", "53475 7159 4", "18874 21756 8", "84273 98526 10", "49672 75296 0", "15071 89892 4", "80471 66661 6", "39377 94889 10", "15566 15472 0", "91756 73882 2", "67945 32292 4", "44133 52876 8", "100000 100000 10", "100000 50000 10", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
0b43e528e6abeac53cf533a31aa42623
Old Peykan
There are *n* cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as *c*1,<=*c*2,<=...,<=*c**n*. The Old Peykan wants to travel from city *c*1 to *c**n* using roads. There are (*n*<=-<=1) one way roads, the *i*-th road goes from city *c**i*...
{"inputs": ["4 6\n1 2 5 2\n2 3 3 4", "2 3\n5 6\n5 5", "24 3\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3", "43 5\n6 7 15 12 15 7 22 33 38 15 7 23 31 21 26 41 25 14 26 33 5 28 22 6 35 17 19 32 41 27 20 25 5 32 37 19 40 9 25 22 10 24 9\n3 5 3 6 5 4 5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
0b492da43be959fece6400df5847d362
Greg and Array
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*. Greg wrote down *k* qu...
{"inputs": ["3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3", "1 1 1\n1\n1 1 1\n1 1", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3", "1 1 1\n0\n1 1 0\n1 1"], "outputs": ["9 18 17", "2", "5 18 31 20", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
126
codeforces
0b99387d2eff332b59651e06fd553dc0
none
Jeff loves regular bracket sequences. Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of *nm* brackets. Let's number all brackets of this sequence from 0 to *nm* - 1 from left to right. Jeff knows that he is going to spend *a**i* *mod* *n* liters of ink on the *i*-th...
{"inputs": ["2 6\n1 2\n2 1", "1 10000000\n2\n3", "3 184\n3 2 8\n3 9 2", "4 26\n10 2 5 9\n5 4 2 5", "3 76\n4 7 9\n10 1 1", "3 98\n6 1 9\n10 2 4", "5 114\n7 5 8 10 10\n2 7 9 4 5", "1 14\n7\n6", "5 142\n8 7 6 2 2\n8 2 6 1 7", "1 184\n8\n8", "2 1900670\n10 3\n9 6", "6 17656\n2 7 4 7 7 3\n3 5 3 6 9 10", "16 3273408\n3 2 8 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0bd6a065baad38a3fd4c209f4a95f13b
LCIS
This problem differs from one which was on the online contest. The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=&lt;<=*a**i*<=+<=1 for *i*<=&lt;<=*n*. The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of inde...
{"inputs": ["7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "5\n1 2 0 2 1\n3\n1 0 1", "2\n6 10\n3\n6 3 3", "1\n7\n2\n7 9", "3\n37 49 24\n3\n33 5 70", "10\n7 10 1 2 1 7 1 5 9 9\n9\n6 2 5 6 7 7 5 5 2", "9\n7 0 1 2 6 0 10 3 5\n4\n8 4 0 3", "9\n7 4 4 5 0 6 5 4 10\n4\n5 2 10 9", "8\n7 8 6 6 8 10 3 3\n5\n7 4 10 8 7", "7\n4 2 4 3 10 3 6\n9\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
0c154754b5d73543126f0c6904d0f27a
HQ9+
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-s...
{"inputs": ["Hi!", "Codeforces", "a+b=c", "hq-lowercase", "Q", "9", "H", "+", "~", "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "@F%K2=%RyL/", "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "6G_\"Fq#<AWyHG=R...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
281
codeforces
0c30ee035d1be2789b81861987cb9945
Okabe and El Psy Kongroo
Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (*x*,<=*y*) such that *x* and *y* are non-negative. Okabe starts at the origin (point (0,<=0)), and n...
{"inputs": ["1 3\n0 3 3", "2 6\n0 3 0\n3 10 2", "2 3\n0 2 13\n2 3 11", "2 9\n0 8 0\n8 10 10", "1 1\n0 3 9", "3 8\n0 7 3\n7 8 5\n8 9 13", "2 10\n0 9 6\n9 10 5", "2 6\n0 3 3\n3 8 13", "1 5\n0 6 15", "2 6\n0 5 8\n5 8 4", "2 10\n0 9 13\n9 10 1", "3 100\n0 94 4\n94 99 5\n99 100 2", "4 100\n0 51 3\n51 98 2\n98 99 1\n99 100 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
0c34bbbc2306102aab4c7b97a203e0e5
Disposition
Vasya bought the collected works of a well-known Berland poet Petya in *n* volumes. The volumes are numbered from 1 to *n*. He thinks that it does not do to arrange the book simply according to their order. Vasya wants to minimize the number of the disposition’s divisors — the positive integers *i* such that for at lea...
{"inputs": ["2", "3", "4", "5", "6", "1", "7", "8", "9", "10", "96", "97", "98", "99", "100", "9996", "9997", "9998", "9999", "10000", "99996", "99997", "99998", "99999", "100000", "9149", "72877", "52956", "33035", "13114", "93193", "73273", "37000", "17079", "84653", "27251", "53496", "96093", "22338", "64935"], "out...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
0c45b94028303ef4fffe2d2c090237ad
Minimize the error
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the min...
{"inputs": ["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4", "2 0 1\n1 2\n2 2", "2 1 1\n0 0\n1 1", "5 5 5\n0 0 0 0 0\n0 0 0 0 0", "3 4 5\n1 2 3\n3 2 1", "3 1000 0\n1 2 3\n-1000 -1000 -1000", "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3", "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
87
codeforces
0c4fbb69ea6a8fda6a0507a8c111bb9a
Unary
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "&lt;", "&gt;", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following alg...
{"inputs": [",.", "++++[>,.<-]", "[-],<],<<,<[,>,+>[[<>.,[>-[-[<><>><<<<]>,.-].>-[[>+,>,[,-,.-,-[[]>..<>,<[+,-<]-++.<+.]<,[[.<<-><<<],", "+", "-", "<", ">", ".", ",", "[", "]", ",]+>.],,+->+>-[]][><,-]><]++<.,-[.>.<+.[.<,[-,,[<]+>]->>]>]-+-+<][].,.]+][[<,-.+][+<<-+.],,,<,.]-].-", "][-+>,>[,<[<+-,[+[-.<+,<[.,<+<,>+],.]>...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
0c57b0428a882e021b4f692a3e535189
Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the prob...
{"inputs": ["5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "3 2\n1 0\n1 1\n0 1", "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1\n1 0 0\n1 1 0\n0 0 0", "10 4\n1 0 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 0 1\n1 0 1 0\n0 0 0 0\n0 0 1 0\n1 0 1 0\n0 0 1 1", "2 2\n0 0\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
0c6e3e4e843b406632384caa2fbb3749
Burglar and Matches
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl...
{"inputs": ["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1", "1 1\n1 2", "1 2\n1 9\n1 6", "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "2 1\n2 1", "2 2\n2 4\n1 4", "2 3\n1 7\n1 2\n1 5", "4 1\n2 2", "4 2\n1 10\n4 4", "4 3\n1 4\n6 4\n1 7", "5 1\n10 5", "5 2\n3 9\n2 2", "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "5 10\n1 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
244
codeforces
0c70c1730bd895feea2883bb012782b2
none
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to...
{"inputs": ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "5 4\n1 2\n3 2\n3 4\n5 4", "3 1\n1 2", "2 1\n1 2", "2 0", "20 0", "381 0", "3 3\n1 2\n2 3\n3 1", "3 0", "3 1\n1 3", "3 2\n2 3\n3 1", "4 1\n1 4", "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "20 1\n20 1", "21 1\n21 1", "100 1\n100 1", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
164
codeforces
0c7952f2ca39ae21d131031bba678184
Vanya and Scales
Vanya has a scales for weighing loads and weights of masses *w*0,<=*w*1,<=*w*2,<=...,<=*w*100 grams where *w* is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass *m* using the given weights, if the weights can be put on both pans of the scale...
{"inputs": ["3 7", "100 99", "100 50", "1000000000 1", "100 10002", "4 7", "4 11", "5 781", "7 9", "5077 5988", "2 9596", "4 1069", "4 7134", "4 9083", "4 7927", "4 6772", "5 782", "4 1000000000", "4 357913941", "4 357918037", "5 12207031", "5 41503906", "5 90332031", "11 1786324", "10 999", "8 28087", "8 28598", "32 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
40
codeforces
0c84e48381cf6190a9397d86d6c3b7de
Blackjack
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to...
{"inputs": ["12", "20", "10", "11", "15", "18", "25", "22", "1", "2", "3", "4", "5", "6", "7", "8", "9", "13", "14", "16", "17", "19", "21", "23", "24"], "outputs": ["4", "15", "0", "4", "4", "4", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "4", "4", "4", "4", "4", "4", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
329
codeforces
0cd13038b6b1d8af20a4bfe259f65af7
Pages
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this: When someone clicks the button "&lt;&lt;" he is redirected to page 1, and wh...
{"inputs": ["17 5 2", "6 5 2", "6 1 2", "6 2 2", "9 6 3", "10 6 3", "8 5 4", "100 10 20", "100 25 11", "5 2 1", "5 3 1", "79 35 12", "100 99 5", "100 99 15", "100 100 17", "100 35 28", "100 46 38", "100 46 48", "100 10 100", "3 1 1", "3 2 1", "17 5 3", "3 1 3", "7 5 1", "5 5 5", "5 3 5"], "outputs": ["<< 3 4 (5) 6 7 >>...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
196
codeforces
0cd16fcabb7afbcb633d4e2d16d8330b
none
This is an interactive problem. Bob lives in a square grid of size $n \times n$, with rows numbered $1$ through $n$ from top to bottom, and columns numbered $1$ through $n$ from left to right. Every cell is either allowed or blocked, but you don't know the exact description of the grid. You are given only an integer $...
{"inputs": ["5\n.....\n.###.\n.###.\n.###.\n...#.", "7\n.......\n.......\n.......\n.......\n......#\n.......\n....#..", "2\n..\n..", "2\n.#\n..", "2\n..\n#.", "5\n.....\n.....\n.....\n.....\n.#.#.", "10\n..#.......\n..#......#\n......###.\n.#......#.\n.......#.#\n.##....#.#\n.....#....\n#...####..\n.#....##..\n##..#......
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0ce006c0eb78b2ee3e77330642120204
none
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomi...
{"inputs": ["3 1000000000\n10 -9 -3 5", "3 12\n10 -9 -3 5", "2 20\n14 -7 19", "5 5\n0 -4 -2 -2 0 5", "6 10\n-2 -1 7 -3 2 7 -6", "7 100\n2 21 11 45 58 85 -59 38", "100 1000\n-62 57 -27 -67 49 -10 66 -64 -36 -78 62 -75 -39 75 -47 -36 41 -88 62 -43 22 29 -20 58 40 16 71 -2 -87 12 86 -90 -92 67 -12 -48 -10 -26 78 68 22 -3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0ce04c7522161634da17dd0a350180e7
Juicer
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ...
{"inputs": ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1", "2 951637 951638\n44069 951637", "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126", "100 1000 1083\n992 616 818 359 609 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
419
codeforces
0d78606b1f006c98a437599329ad938e
Volleyball
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has *n* junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads c...
{"inputs": ["4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "3 3\n1 3\n1 2 2\n1 3 3\n3 2 1\n2 7\n2 7\n3 6", "3 1\n1 3\n1 2 2\n2 7\n2 7\n3 6", "3 2\n3 3\n1 2 2\n1 3 3\n2 7\n2 7\n3 7", "2 2\n1 2\n1 2 3\n1 2 2\n2 7\n3 2", "1 0\n1 1\n74 47", "5 5\n1 3\n1 3 3\n5 1 6\n4 3 8\n1 3 3\n5 2 4\n1 2\n4 1\n2 5\n5 2\n1 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
0d902b95505260c05a57bdc1eeca9891
Warrior and Archer
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest. V...
{"inputs": ["6\n0 1 3 7 15 31", "2\n73 37", "2\n0 1000000000", "8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782", "2\n0 1", "8\n552283832 997699491 89302459 301640204 288141798 31112026 710831619 862166501", "4\n0 500000000 500000001 1000000000", "18\n515925896 832652240 279975694 5709...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
0d91bb06eb67c4ce2c2a089bdde1617d
Petr and Book
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
{"inputs": ["100\n15 20 20 15 10 30 45", "2\n1 0 0 0 0 0 0", "100\n100 200 100 200 300 400 500", "3\n1 1 1 1 1 1 1", "1\n1 1 1 1 1 1 1", "20\n5 3 7 2 1 6 4", "10\n5 1 1 1 1 1 5", "50\n10 1 10 1 10 1 10", "77\n11 11 11 11 11 11 10", "1\n1000 1000 1000 1000 1000 1000 1000", "1000\n100 100 100 100 100 100 100", "999\n10 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
402
codeforces
0d96290ec1b71abbe19125d7e7eb6517
Seat Arrangements
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied. The classroom contains $n$ rows of seat...
{"inputs": ["1 2 2\n..", "3 3 4\n.*.\n*.*\n.*.", "1 1 1\n.", "1 1 1\n*", "2 2 2\n.*\n*.", "1 1 1000\n.", "1 1 2000\n*", "3 3 1\n.*.\n.*.\n.*.", "2 2 1\n..\n.."], "outputs": ["1", "0", "1", "0", "0", "0", "0", "6", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
0debd0e39e8f9597e4e1a057bfdb4df9
Места в самолёте
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа. Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ...
{"inputs": ["1 2\nSP.-SS.S-S.S", "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP", "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP", "5 6\nPP.-PS.P-P..\nPPS-SP..-P.P\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP", "1 1\n..S-PS..-.PP", "2 2\nPP.-S.SS-.S.\nSSP-SSSS-S.S", "30 1\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPP...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
0df75644338ab2c4b5718e93078c22e0
Game
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
{"inputs": ["3\n2 1 3", "3\n2 2 2", "9\n44 53 51 80 5 27 74 79 94", "10\n38 82 23 37 96 4 81 60 67 86", "10\n58 26 77 15 53 81 68 48 22 65", "1\n124", "2\n2 1", "3\n1 1 1000", "2\n322 322", "3\n9 92 12", "3\n1 2 2"], "outputs": ["2", "2", "53", "60", "53", "124", "1", "1", "322", "12", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
391
codeforces
0e157a547fc5207bba32733c03b0e7fa
Dark Assembly
Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed. The Dark Assembly consists of *n* senators. Each ...
{"inputs": ["5 6 100\n11 80\n14 90\n23 70\n80 30\n153 70", "5 3 100\n11 80\n14 90\n23 70\n80 30\n153 70", "1 3 20\n20 20", "4 3 40\n10 40\n11 50\n10 50\n9 50", "4 4 60\n10 40\n11 50\n10 50\n12 30", "2 7 20\n10 40\n10 50", "2 1 25\n10 40\n12 50", "3 3 31\n10 40\n12 50\n15 0", "1 3 40\n10 0", "1 4 30\n10 20", "1 7 10\n40...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0e34ebe5fef7204f2fe932a215b89c7f
Domino Principle
Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put *n* dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The *i*-th domino ...
{"inputs": ["4\n16 5\n20 5\n10 10\n18 2", "4\n0 10\n1 5\n9 10\n15 10", "3\n6 7\n2 9\n-6 10", "4\n-6 9\n9 5\n-7 4\n0 9", "5\n-47 19\n-43 14\n83 27\n-67 46\n-58 98", "6\n20 39\n38 13\n-25 48\n-22 38\n13 39\n90 54", "10\n34 9\n-41 26\n-62 32\n1 10\n77 14\n92 7\n-45 35\n75 19\n-23 2\n-46 8"], "outputs": ["3 1 4 1 ", "4 1 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
0e82cefa01c6997641a42ae83143b95c
Arpa's weak amphitheater and Mehrdad's valuable Hoses
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if...
{"inputs": ["3 1 5\n3 2 5\n2 4 2\n1 2", "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3", "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5", "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 69...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
0ea22e7ee558ec693ca7ade63f2070c0
none
Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water...
{"inputs": ["6\n0 1 0 3 0 2", "5\n0 1 2 1 2", "5\n0 1 1 2 2", "1\n0", "100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15 19 15 7 17 17 18 19 9 10 21 0 22 9 2 24 24 4 24 7 25 14 5 8 28 29 30 31 31 31 0 3 15 31 8 33 6 35 35 35 36 36 37 37 38 39 28 0 2 23 41 9 9 0 6 25 41 41 12 42 43 43 36...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
0ea603ee7629911d0ced82f19b960bfe
none
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are *n* objects numbered from 1 to *n* arranged in a circle (in clockwise order). Object number 1 is a black hole and the...
{"inputs": ["5\n2 3 2\n3 1 2 3", "8\n4 6 2 3 4\n2 3 6", "10\n3 4 7 5\n2 8 5", "17\n1 10\n1 12", "23\n1 20\n3 9 2 12", "85\n12 76 7 75 51 43 41 66 13 59 48 81 73\n3 65 60 25", "100\n84 80 73 28 76 21 44 97 63 59 6 77 41 2 8 71 57 19 33 46 92 5 61 88 53 68 94 56 14 35 4 47 17 79 84 10 67 58 45 38 13 12 87 3 91 30 15 11 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
0ebc1719d1f245ede35d95c7bd681e06
Taxes
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo...
{"inputs": ["4", "27", "3", "5", "10", "2000000000", "26", "7", "2", "11", "1000000007", "1000000009", "1999999999", "1000000011", "101", "103", "1001", "1003", "10001", "10003", "129401294", "234911024", "192483501", "1234567890", "719241201", "9", "33", "25", "15", "147", "60119912", "45", "21", "9975", "17", "99", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
101
codeforces
0ec70b522b9282b4d80872c39c9db3fb
Berland Square
Last year the world's largest square was built in Berland. It is known that the square can be represented as an infinite plane with an introduced Cartesian system of coordinates. On that square two sets of concentric circles were painted. Let's call the set of concentric circles with radii 1,<=2,<=...,<=*K* and the cen...
{"inputs": ["1 0 1 1", "1 0 1 2", "3 3 4 7", "2 2 2 3", "1 100000 1 99999", "4 7 3 3", "1 0 1 100", "1 0 2 3", "2 2 4 4", "4 4 2 2", "1 -1 5 -10", "5 2 1 -5", "5 4 3 -2", "3 7 4 1", "3 -9 3 4", "2 -6 4 6", "2 -4 1 9", "2 1 4 -7", "2 4 5 -4", "5 7 1 2", "94925 5648 96389 1799", "94244 7010 97753 -7757", "93564 8371 9911...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
0ee88c557025d4dd9e3747078da8071a
Long Path
One day, little Vasya found himself in a maze consisting of (*n*<=+<=1) rooms, numbered from 1 to (*n*<=+<=1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (*n*<=+<=1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider roo...
{"inputs": ["2\n1 2", "4\n1 1 2 3", "5\n1 1 1 1 1", "7\n1 2 1 3 1 2 1", "1\n1", "3\n1 1 3", "10\n1 1 3 2 2 1 3 4 7 5", "20\n1 2 2 2 2 1 4 7 8 6 5 3 5 3 8 11 5 10 16 10", "32\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\n1 1 3 2 2 1 3 4 7 5", "30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
54
codeforces
0f282b1f9ea8de06a0b9a6c9266ff534
Cards
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards ...
{"inputs": ["6\n1 5 7 4 4 3", "4\n10 10 10 10", "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "4\n82 46 8 44", "2\n35 50", "8\n24 39 49 38 44 64 44 50", "100\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
354
codeforces
0f2fcfff4d971d95c3358fe7ecd570c7
Collecting Beats is Fun
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with...
{"inputs": ["1\n.135\n1247\n3468\n5789", "5\n..1.\n1111\n..1.\n..1.", "1\n....\n12.1\n.2..\n.2..", "1\n6981\n.527\n4163\n2345", "5\n9999\n9999\n9999\n9999", "2\n4444\n3333\n2222\n1111", "3\n2123\n1232\n2321\n3213", "2\n1...\n.1..\n..1.\n...1", "2\n1.1.\n.1.1\n2.2.\n.222", "1\n1..2\n.3.4\n567.\n.89.", "1\n1122\n3344\n55...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
224
codeforces
0f58d81163a401fa15ec625c5344c8cd
Geometry Horse
Vasya plays the Geometry Horse. The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are *n* types of geometric figures. The number of figures of type *k**i* and figure cost *c*...
{"inputs": ["1\n5 10\n2\n3 6", "2\n3 8\n5 10\n1\n20", "3\n10 3\n20 2\n30 1\n3\n30 50 60", "1\n100 1000\n1\n1", "1\n1 1000\n1\n1", "1\n1 1000\n1\n2", "2\n1000000000 1000\n1 1\n1\n10", "6\n5 9\n63 3\n30 4\n25 6\n48 2\n29 9\n8\n105 137 172 192 632 722 972 981", "7\n9902 9\n5809 6\n2358 0\n6868 7\n9630 2\n8302 10\n9422 3\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
0f7b0ee4cd52ba5f602dd8c53867f494
Multicolored Marbles
Polycarpus plays with red and blue marbles. He put *n* marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are ze...
{"inputs": ["3", "4", "1", "2", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "30", "40", "35", "747", "811", "523", "939", "7218", "6578", "4994", "3410", "9122", "11500", "37212", "95628", "21341", "63405", "670293", "12357", "838069", "696485", "1000000", "999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
0fa262b62ad1fc05fa98a73f6cec7828
Complicated GCD
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
{"inputs": ["1 2", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "1 100", "100 100000", "12345 67890123456789123457", "1 1", "2 2", "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 839273915883927391588392739...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
374
codeforces
0fafdabf58fdb7b9bc79f12cceb407f3
Airplane Arrangements
There is an airplane which has *n* rows from front to back. There will be *m* people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the...
{"inputs": ["3 3", "1000000 1000000", "1000000 500000", "1 1", "10 1", "285042 201091", "896437 604720", "284114 73851", "541826 316395", "353093 96536", "540898 158491", "858309 773589", "56322 42432", "461466 56468", "29102 1503", "42800 41731", "235175 92933", "921643 744360", "619924 583916", "43657 852", "4672 308...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
0fce72ef3ce162bced800165e0d75fe4
Interesting Sequence
Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A...
{"inputs": ["2", "3", "13", "1729", "1", "156", "144", "15407021574586369", "1283918464548876", "106993205379216", "8916100449984", "743008391424", "61917613056", "5162766336", "465813504", "749018868196746805223329946373352590959663287279411259311764529219426154819446575772163700626968045411915608325823147333921760188...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
0fd3c9bddbe0ccc202f9c7c24aea01d3
King Moves
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
{"inputs": ["e4", "a1", "h8", "a4", "g7", "e1", "b2", "c7", "h6", "c8", "h2", "h5", "a8", "f8", "h1", "f2", "e8", "h3", "b8", "g8", "d8", "h4", "b1", "a2"], "outputs": ["8", "3", "3", "5", "8", "5", "8", "8", "5", "5", "5", "5", "3", "5", "3", "8", "5", "5", "5", "5", "5", "5", "5", "5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
324
codeforces
0fd712709f42f0903bd59203c4ea71f4
Beaver Game
Two beavers, Timur and Marsel, play the following game. There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than *k* meter...
{"inputs": ["1 15 4", "4 9 5", "14 30 9", "81 180 53", "225 187 20", "501 840 11", "3 11 6", "1 2 1", "1 1 2", "1 1 1", "1 2 2", "2 1 1", "2 1 2", "2 2 1", "2 2 2", "1000000000 1000000000 1000000000", "999999999 735134400 1", "999999999 735134400 100", "787965358 999999986 2", "588462355 999999986 2", "994427144 999999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
0ff293f9b8bd79037a2e24a7751fb766
Constellation
A star map in Berland is a checked field *n*<=×<=*m* squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer *x* (radius of the constellation) the follow...
{"inputs": ["5 6 1\n....*.\n...***\n....*.\n..*...\n.***..", "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..", "5 5 1\n.....\n.....\n.*..*\n*.*..\n....*", "5 5 3\n*.***\n.****\n..***\n*.***\n.**.*", "10 10 6\n.*..**.**.\n**********\n****.*****\n**.***....\n***.******\n****.**..*\n**.**.****\n****.**..*\n..**.**.*.\n.*.*...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
10283a6443b1aa148146d9713d2ec662
none
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two d...
{"inputs": ["30", "59", "2", "7", "9", "13", "55", "89", "3", "4", "6", "8", "11", "12", "25", "36", "46", "47", "49", "51", "53", "59", "64", "81", "91", "93", "94", "95", "96", "97", "99", "100", "26", "94", "25", "46", "49", "82", "87", "85", "74", "86", "93", "58", "47", "22", "23", "62", "38", "91", "34", "95", "4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
65
codeforces
102e033fa305ffe7eb4ac9cd64298025
Towers
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
{"inputs": ["3\n1 2 3", "4\n6 5 6 7", "4\n3 2 1 1", "4\n1 2 3 3", "3\n20 22 36", "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
790
codeforces
1040a7cfb73d4e95e9ff68875b67993c
Two Buttons
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so...
{"inputs": ["4 6", "10 1", "1 2", "2 1", "1 3", "3 1", "2 10", "100 99", "99 100", "10 17", "666 6666", "6666 666", "1 8192", "1 8193", "9999 10000", "10000 9999", "10000 1", "1234 5678", "9102 9103", "8192 1", "9912 1023", "100 500", "9997 9999", "5000 10000", "4000 7997", "1 10000", "1 8191", "9999 10000", "9097 9998...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
1047525a13a957e0b64cc5b18b0b5e81
Candies
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *...
{"inputs": ["12 4", "15 6", "18 8", "1 1", "2 1", "100 1", "100 100", "100 10", "64 8", "81 27", "100 99", "100 51", "100 49", "100 13", "97 11", "19 3", "99 10", "88 5", "87 34", "97 55"], "outputs": ["3 3 3 3 ", "2 2 2 3 3 3 ", "2 2 2 2 2 2 3 3 ", "1 ", "2 ", "100 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
355
codeforces
105128009fdb4d359d3d6d3777c9553b
Students in Railway Carriage
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carri...
{"inputs": ["5 1 1\n*...*", "6 2 3\n*...*.", "11 3 10\n.*....**.*.", "3 2 3\n***", "9 5 3\n*...*...*", "9 2 4\n*...*...*", "9 2 200000\n*...*...*", "1 0 1\n.", "14 3 7\n.*.......*..*.", "6 1 3\n*....*", "5 1 2\n...*.", "2 2 0\n..", "2 0 2\n..", "5 3 3\n...**", "3 0 1\n.*.", "13 3 3\n*...*...*...*", "7 0 4\n...*..*", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
75
codeforces
105e3758d5f44e0c1bef1b8e45b47ba2
Rectangle Puzzle II
You are given a rectangle grid. That grid's size is *n*<=×<=*m*. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (*x*,<=*y*) (0<=≤<=*x*<=≤<=*n*,<=0<=≤<=*y*<=≤<=*m*). Your task is to find a maximum sub-rectangle on the grid (*x*1,<=*y*1,<=*x*2,<=*y*2...
{"inputs": ["9 9 5 5 2 1", "100 100 52 50 46 56", "100 100 16 60 42 75", "100 100 28 22 47 50", "100 100 44 36 96 21", "100 100 56 46 1 47", "100 100 20 53 6 22", "100 100 32 63 2 41", "100 100 48 73 63 16", "100 100 13 59 14 20", "36830763 28058366 30827357 20792295 11047103 20670351", "87453374 60940601 74141787 3214...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
1085303f1d6a1301030c5bec6cc8f050
Race
The Old City is a rectangular city represented as an *m*<=×<=*n* grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one block and are either vertical or horizontal. There is a junction on both sid...
{"inputs": ["3 10 12\n##########\n#z1a1111b#\n##########\n2 3 ab 2 8", "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababababababab 6 2", "3 10 6\n##########\n#z1a1311b#\n##########\n2 3 ab 2 8", "14 14 187\n##############\n##############\n##############\n##############\n#####a5284b7c#\n#####1####7#7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
10b1b7f6e837f3a28641aed3a8d8cfd6
Washer, Dryer, Folder
You have *k* pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has *n*1 washing machines, *n*2 drying machines and *n*3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it ...
{"inputs": ["1 1 1 1 5 5 5", "8 4 3 2 10 5 2", "10000 1000 1000 1000 1000 1000 1000", "8 3 4 3 10 9 4", "5 2 4 5 9 9 6", "4 5 1 2 4 6 2", "11 5 5 1 9 6 8", "1 3 2 2 5 2 8", "2933 578 144 393 710 699 874", "2460 502 99 260 659 409 586", "1444 75 246 287 64 416 2", "4076 135 200 961 469 286 418", "7251 708 347 932 65 292...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
10cc24a3b490499bfd4553c68f068241
Local Extrema
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*...
{"inputs": ["3\n1 2 3", "4\n1 5 2 5", "1\n1", "1\n548", "2\n1 1", "3\n3 2 3", "2\n1 1000", "3\n1 2 1"], "outputs": ["0", "2", "0", "0", "0", "1", "0", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
250
codeforces
1110f42e88d5749b1b194cda75112c7e
Cosmic Tables
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of mete...
{"inputs": ["3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3", "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2", "2 2 6\n1 2\n3 4\nc 1 2\nr 1 2\ng 1 1\ng 1 2\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
1117c37e54f15529eba3946a452af50b
123-sequence
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a...
{"inputs": ["9\n1 3 2 2 2 1 1 2 3", "6\n3 3 2 2 1 3", "12\n3 1 3 1 2 1 3 2 2 1 2 1", "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "2\n2 1", "2\n3 2", "2\n3 1", "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2", "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1", "1\n1", "1\n2", "1\n3"], "outputs": ["5", "3", "7", "10", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
327
codeforces
11378dd44866f43b807db4d6e54786f9
Game
Allen and Bessie are playing a simple number game. They both know a function $f: \{0, 1\}^n \to \mathbb{R}$, i. e. the function takes $n$ binary arguments and returns a real value. At the start of the game, the variables $x_1, x_2, \dots, x_n$ are all set to $-1$. Each round, with equal probability, one of Allen or Bes...
{"inputs": ["2 2\n0 1 2 3\n2 5\n0 4", "1 0\n2 3", "2 0\n1 1 1 1"], "outputs": ["1.500000\n2.250000\n3.250000", "2.500000", "1.000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
113eb2e2363de9dd2354a2f80ef3e77c
The Great Julya Calendar
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open ...
{"inputs": ["24", "0", "3", "8", "9", "10", "31", "701", "222", "156", "12343", "7984", "1000000", "1", "3", "5", "11", "77", "216", "1468", "1995", "11010", "47320", "258634"], "outputs": ["5", "0", "1", "1", "1", "2", "6", "116", "39", "28", "1778", "1178", "128207", "1", "1", "1", "3", "14", "37", "233", "305", "156...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
236
codeforces
1151407dedf0eca70322463ffde4a040
Arpa and an exam about geometry
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ...
{"inputs": ["0 1 1 1 1 0", "1 1 0 0 1000 1000", "1 0 2 0 3 0", "3 4 0 0 4 3", "-1000000000 1 0 0 1000000000 1", "49152 0 0 0 0 81920", "1 -1 4 4 2 -3", "-2 -2 1 4 -2 0", "5 0 4 -2 0 1", "-4 -3 2 -1 -3 4", "-3 -3 5 2 3 -1", "-1000000000 -1000000000 0 0 1000000000 999999999", "-1000000000 -1000000000 0 0 1000000000 10000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
84
codeforces
115825905aae4a75d5ae8efd5fd5deda
Network Topology
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them...
{"inputs": ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n2 3\n3 1\n1 4", "5 4\n1 2\n3 5\n1 4\n5 4", "5 5\n3 4\n5 2\n2 1\n5 4\n3 1", "5 4\n4 2\n5 2\n1 2\n2 3", "5 9\n5 3\n4 5\n3 1\n3 2\n2 1\n2 5\n1 5\n1 4\n4 2", "4 3\n2 4\n1 3\n4 1", "4 4\n2 4\n4 1\n1 3\n2 3", "4 3\n1 2\n2 4\n3 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
131
codeforces