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
f23516b21bb43236372be770896daf03
Martian Clock
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored...
{"inputs": ["11:20", "2A:13", "000B:00001", "00000:00000", "70:00", "00:21", "02:130", "123:A", "N8HYJ:042JW", "N:7", "00000:00021", "00002:00130", "00394:00321", "0000P:0000E", "0000F:0002G", "0000N:00007", "000G6:000GD", "000B3:00098", "100:0101", "00101:0101", "00001:00001", "00A:00A", "10101:000", "0010:00000", "00...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
f2643261d115329182a78ea3b0e7a79f
none
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,...
{"inputs": ["6\n4 5 4 5 4 4", "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5", "3\n4 5 4", "3\n4 5 1", "4\n5 4 3 5", "10\n4 4 5 4 4 5 5 5 4 4", "20\n5 5 5 4 5 4 5 5 5 5 5 4 4 5 3 4 4 4 5 4", "30\n4 4 5 5 5 4 5 5 4 5 4 4 5 4 4 4 5 4 4 4 5 5 5 5 4 5 5 5 4 4", "40\n5 4 4 5 5 5 1 5 4 4 4 4 4 2 4 4 4 4 4 4 5 4 4 4 5 5 3 4 4 5 5 5 4 4 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
f26fc951cce2e4c8216142310433c9ea
Coder
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). ...
{"inputs": ["2", "3", "4", "10", "15", "100", "101", "500", "501", "755", "888", "998", "999", "1000", "1"], "outputs": ["2\nC.\n.C", "5\nC.C\n.C.\nC.C", "8\nC.C.\n.C.C\nC.C.\n.C.C", "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C", "113\nC.C.C...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
297
codeforces
f28494b1bb4a51fe0632070103000036
Restoring Numbers
Vasya had two arrays consisting of non-negative integers: *a* of size *n* and *b* of size *m*. Vasya chose a positive integer *k* and created an *n*<=×<=*m* matrix *v* using the following formula: Vasya wrote down matrix *v* on a piece of paper and put it in the table. A year later Vasya was cleaning his table when h...
{"inputs": ["2 3\n1 2 3\n2 3 4", "2 2\n1 2\n2 0", "2 2\n1 2\n2 1", "2 2\n2 3\n1 2", "2 2\n2 0\n1 2", "2 2\n2 1\n0 2", "2 2\n0 2\n2 1", "2 3\n1 3 3\n3 0 1", "3 2\n1 3\n3 0\n3 1", "2 3\n3 0 1\n1 3 3", "3 2\n3 0\n3 1\n1 3", "3 2\n3 1\n3 0\n1 3", "3 2\n3 0\n1 3\n3 1", "2 2\n0 1000000000\n1000000000 0", "2 2\n0 1000000000\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f2d46ff61caf83aa5c9d524ad3d861b9
Terse princess
«Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous on...
{"inputs": ["10 2 3", "5 0 0", "5 2 2", "6 2 2", "10 9 0", "1 0 0", "10 0 9", "42 10 13", "7 3 3", "12 0 0", "19 1 0", "17 2 3", "7 3 1", "19 3 1", "10 4 4", "11 5 4", "8 0 2", "19 5 1", "100 9 0", "2 0 1", "2 1 0", "3 0 2", "3 1 1", "3 2 0", "4 0 0", "4 0 1", "4 0 2", "4 0 3", "4 1 0", "4 2 0", "4 3 0", "4 1 1", "4 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
f2de2e39564f4a23db850d2627d473bd
Friends and Subsequences
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer sequences *a* and *b* of length *n*. Being given a query of the form of pair of integers...
{"inputs": ["6\n1 2 3 2 1 4\n6 7 1 2 3 2", "3\n3 3 3\n1 1 1", "17\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -959271262\n-417715348 -959271262 -959271262 714413739 -189641729 571055593 5710555...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f2f920d63727a5da8738e73b9c49da84
Psychos in a Line
There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arran...
{"inputs": ["10\n10 9 7 8 6 5 3 4 2 1", "6\n1 2 3 4 5 6", "6\n6 5 4 3 2 1", "10\n10 7 4 2 5 8 9 6 3 1", "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4", "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 16 81 67 64 74 46 82 5 88 80 14 48...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
f30a23a3a1dd6e38a255a088067f20fc
Chess Placing
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . In one step you can move...
{"inputs": ["6\n1 2 6", "10\n1 2 3 4 5", "2\n2", "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100", "100\n93 54 57 61 68 66 70 96 64 82 80 75 69 77 76 94 67 86 90 73 74 58 100 83 92 89 56 99 88 59 95 72 81 51 85 71 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
94
codeforces
f33131958c663e5a2ee1b0463cbe2016
Bus
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ...
{"inputs": ["6 9 2 4", "6 10 2 4", "6 5 4 3", "2 2 1 1", "10 4 6 10", "3 1 1 1", "2 1 1 1", "1000000 51923215 2302 10000", "10 11 3 2", "20 50 10 25", "10 10 5 20", "15 65 5 50", "10 19 1 5", "10 19 9 5", "23 46 12 2", "23 46 12 3", "20 20 19 1", "20 23 17 2", "100 70 50 1", "100 70 70 2", "140 480 139 40", "1000000 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
f353ac7a2ae46c10fac90cbe25b2a7fb
Second price auction
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
{"inputs": ["3\n4 7\n8 10\n5 5", "3\n2 5\n3 4\n1 6", "5\n1 10000\n1 10000\n1 10000\n1 10000\n1 10000", "2\n1 2\n1 2", "2\n1 3\n1 3", "5\n1 7\n2 5\n3 9\n4 8\n5 6", "5\n17 9999\n19 9992\n1 10000\n6 9\n34 99", "5\n3778 9170\n2657 6649\n4038 9722\n3392 7255\n4890 8961", "5\n2194 6947\n2062 8247\n4481 8430\n3864 9409\n3784 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
f35e9fe9adbb9f6f5fa5aa441e337afe
Ants on a Circle
*n* ants are on a circle of length *m*. An ant travels one unit of distance per one unit of time. Initially, the ant number *i* is located at the position *s**i* and is facing in the direction *d**i* (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the al...
{"inputs": ["2 4 8\n1 R\n3 L", "4 8 6\n6 R\n5 L\n1 R\n8 L", "4 8 2\n1 R\n5 L\n6 L\n8 R", "10 10 90\n2 R\n1 R\n3 L\n4 R\n7 L\n8 L\n6 R\n9 R\n5 R\n10 L", "10 20 85\n6 L\n12 R\n2 L\n20 R\n18 L\n8 R\n16 R\n14 L\n10 L\n4 R", "10 20 59\n1 R\n15 L\n7 L\n13 R\n5 R\n17 R\n3 L\n9 R\n11 L\n19 L", "2 2 0\n2 L\n1 R", "2 2 0\n2 L\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
f364ca2a099e8d455d001a8fa0bf3be0
Martian Food
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of *R*, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of *r* and is located as close to the edge of the plate as poss...
{"inputs": ["2\n4 3 1\n4 2 2", "1\n4 2 2", "1\n7 2 1", "1\n8 7 2", "1\n2 1 1", "1\n1000 999 2", "1\n1000 1 2", "1\n1000 998 1000", "1\n1000 1 1000", "1\n1000 500 123", "1\n1000 999 1", "1\n1000 1 1"], "outputs": ["0.9230769231\n0.6666666667", "0.6666666667", "1.7948717949", "0.9333333333", "0.6666666667", "0.9999959960...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
f391d73d45dd1d927cf8e993cb4dccc5
Balls and Boxes
Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right. Once Vasya chose one of the boxes, let's assume that its number is *i*, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began pu...
{"inputs": ["4 4\n4 3 1 6", "5 2\n3 2 0 2 7", "3 3\n2 3 1", "10 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "5 4\n0 554459682 978416312 784688178 954779973", "5 2\n1 554459683 978416312 784688178 954779974", "10 8\n994538714 617271264 168716105 9159...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
f3a1a7fd9526cd12c40b83d70cf25ffd
On Sum of Fractions
Let's assume that - *v*(*n*) is the largest prime number, that does not exceed *n*;- *u*(*n*) is the smallest prime number strictly greater than *n*. Find . The first line contains integer *t* (1<=≤<=*t*<=≤<=500) — the number of testscases. Each of the following *t* lines of the input contains integer *n* (2<=≤<...
{"inputs": ["2\n2\n3", "1\n1000000000", "5\n3\n6\n9\n10\n5", "5\n5\n8\n18\n17\n17", "5\n7\n40\n37\n25\n4", "5\n72\n72\n30\n75\n11", "5\n79\n149\n136\n194\n124", "6\n885\n419\n821\n635\n63\n480", "1\n649580447"], "outputs": ["1/6\n7/30", "999999941999999673/1999999887999999118", "7/30\n5/14\n61/154\n9/22\n23/70", "23/70...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
f3be2edd00eefa041c20c29eb293b913
Panoramix's Prediction
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
{"inputs": ["3 5", "7 11", "7 9", "2 3", "2 4", "3 4", "3 5", "5 7", "7 11", "11 13", "13 17", "17 19", "19 23", "23 29", "29 31", "31 37", "37 41", "41 43", "43 47", "2 5", "2 7", "2 6", "2 11", "3 6", "3 7", "3 9", "5 6", "5 9", "5 11", "5 13", "5 15", "7 8", "7 13", "13 15", "13 17", "19 21", "13 20", "41 49", "43 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
706
codeforces
f3befb56bb448c975b4759d7d190e4cb
Counting-out Rhyme
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T...
{"inputs": ["7 5\n10 4 11 4 1", "3 2\n2 5", "2 1\n1", "2 1\n2", "2 1\n3", "10 7\n5 10 4 3 8 10 6", "10 8\n12 6 12 15 20 8 17 12", "12 10\n76 58 82 54 97 46 17 40 36 15", "12 6\n76 61 94 15 66 26", "90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274", "100 30\n601771 913885 829106 91674 465657 367068 142461 873149 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
f3d62dd60c00cd2fd042a33e2c83f89b
Asphalting Roads
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was ma...
{"inputs": ["2\n1 1\n1 2\n2 1\n2 2", "1\n1 1", "2\n1 1\n2 2\n1 2\n2 1", "2\n1 2\n2 2\n2 1\n1 1", "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1", "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3", "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3", "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
262
codeforces
f3d7158f8e0792de72e5f73a3a3af603
Trip For Meal
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ...
{"inputs": ["3\n2\n3\n1", "1\n2\n3\n5", "10\n1\n8\n3", "7\n10\n5\n6", "9\n9\n7\n5", "9\n37\n85\n76", "76\n46\n77\n11", "80\n42\n1\n37", "8\n80\n55\n1", "10\n13\n72\n17", "9\n24\n1\n63", "65\n5\n8\n7", "56\n8\n9\n3", "59\n8\n1\n2", "75\n50\n50\n5", "75\n54\n76\n66", "73\n71\n69\n66", "83\n58\n88\n16", "74\n31\n11\n79", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
234
codeforces
f42402e6c70bf58ecf9462382be78531
Martian Luck
You know that the Martians use a number system with base *k*. Digit *b* (0<=≤<=*b*<=&lt;<=*k*) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year *b* (by Martian chronology). A digital root *d*(*x*) of number *x* is a number that consists of a single digit, resulting aft...
{"inputs": ["10 5 6\n3 2 0 5 6 1", "7 6 4\n3 5 0 4", "257 0 3\n0 0 256", "2 1 1\n0", "2 0 20\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1", "100 29 33\n28 89 23 14 97 97 66 56 55 60 47 29 9 79 26 80 63 78 83 60 41 29 52 10 82 26 47 88 99 75 52 1 31", "3 2 100\n2 0 0 0 0 2 1 1 1 2 0 1 1 1 1 2 0 0 1 0 1 1 2 0 2 0 1 0 1 0 0 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
f431895a1a729fdbd0c3ad3f22be56ce
Professor GukiZ and Two Arrays
Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a *s**a* as close as possible to the sum of the elements in the array b *s**b*. So he wants to minimize the value *v*<==<=|*s**a*<=-<=*s**b*|. In one operation professor can swap some element from the arra...
{"inputs": ["5\n5 4 3 2 1\n4\n1 1 1 1", "5\n1 2 3 4 5\n1\n15", "5\n1 2 3 4 5\n4\n1 2 3 4", "1\n-42\n1\n-86", "1\n-21\n10\n-43 6 -46 79 -21 93 -36 -38 -67 1", "10\n87 -92 -67 -100 -88 80 -82 -59 81 -72\n10\n-50 30 30 77 65 92 -60 -76 -29 -15", "6\n1 2 3 4 5 11\n1\n3", "2\n-2 -17\n2\n11 -9"], "outputs": ["1\n2\n1 1\n4 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
f43a0ddbf858622f14a65dfa900d98f3
Holidays
School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people a...
{"inputs": ["10 5\n1 2\n3 3\n4 6\n7 7\n8 10", "10 5\n1 2\n2 3\n4 5\n7 8\n9 10", "10 5\n1 2\n3 3\n5 7\n7 7\n7 10", "5 4\n1 1\n2 2\n3 3\n4 5", "100 50\n1 2\n3 3\n4 5\n6 8\n9 10\n11 11\n12 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 21\n22 23\n24 24\n25 26\n27 30\n31 34\n35 37\n38 38\n39 40\n41 43\n44 46\n47 53\n54 54\n55 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
32
codeforces
f43a2e0a33c8f44633805b0dd90f0796
Cupboard and Balloons
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure be...
{"inputs": ["1 1", "1 2", "2 1", "2 2", "2 3", "4 1", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 9", "5 10", "5 11", "674098 1358794", "3983458 7761504", "4841874 9131511", "667586 5534221", "1526002 6904227", "4835362 5823289", "5693778 7001807", "6552194 8371814", "2377906 4774524", "4365659 4738707", "98 1358794",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
f453f02226d9971eb7bbf5becec6b38f
Find Marble
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs som...
{"inputs": ["4 2 1\n2 3 4 1", "4 3 3\n4 1 3 2", "4 3 4\n1 2 3 4", "3 1 3\n2 1 3", "1 1 1\n1", "10 6 7\n10 7 8 1 5 6 2 9 4 3", "10 3 6\n5 6 7 3 8 4 2 1 10 9", "10 10 4\n4 2 6 9 5 3 8 1 10 7", "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
222
codeforces
f456a5b7865384e367c56b0d2407ffe7
Composing Of String
Stepan has a set of *n* strings. Also, he has a favorite string *s*. Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and will not take some of them at all. Your task is to determine the minimum...
{"inputs": ["3\na\naa\na\naaa", "4\nab\naab\naa\nbb\nbaaab", "2\naaa\nbbb\naaacbbb", "4\naab\naa\nbb\naba\nbaaab", "2\naaaaaaaa\nabbaaaaaaa\nbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbabbabbbbbbbbbbbbbbbbbbbabbabbbbababbbbbbbbabbbbb", "1\nlol\nlol"], "outputs": ["2", "3", "-1", "2", "52", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
f46e2bd58d7931a2564157375a75ebe5
Pasha and Stick
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
{"inputs": ["6", "20", "1", "2", "3", "4", "2000000000", "1924704072", "73740586", "1925088820", "593070992", "1925473570", "629490186", "1980649112", "36661322", "1943590793", "71207034", "1757577394", "168305294", "1934896224", "297149088", "1898001634", "176409698", "1873025522", "5714762", "1829551192", "16269438",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
381
codeforces
f48a1384754b692e29f1b10ca139a643
none
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the mi...
{"inputs": ["5\n2 2 3 4 6", "4\n2 4 6 8", "3\n2 6 9", "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21", "12\n10 10 14 14 14 14 14 14 14 14 21 21", "5\n10 10 14 21 21", "9\n10 10 10 10 10 14 14 21 21", "9\n10 10 10 10 10 10 10 10 21", "13\n10 10 10 15 15 15 15 15 15 15 15 21 21", "15\n10 10 10 10 10 10 10 10 10 10 10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
f49929c441933b89f099ad18f063b303
Two TVs
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a...
{"inputs": ["3\n1 2\n2 3\n4 5", "4\n1 2\n2 3\n2 3\n1 2", "4\n0 1\n1 2\n2 3\n3 4", "3\n1 2\n2 3\n2 4", "3\n0 100\n0 100\n0 100", "1\n0 1000000000", "2\n0 1\n0 1", "3\n2 3\n4 5\n1 6", "5\n1 3\n1 4\n4 10\n5 8\n9 11", "3\n1 2\n1 2\n2 3", "4\n1 100\n10 15\n20 25\n30 35", "3\n1 8\n6 7\n8 11", "5\n1 2\n3 5\n4 7\n8 9\n5 10", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
81
codeforces
f4a2baf1989ae44e47e1d466007d7165
Contest Balloons
One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ...
{"inputs": ["8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000", "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5", "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n0 0", "2\n100 150\n5 100000", "9\n4 70\n32 56\n32 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
f4dc21b1bc1016c05753a806dc7c6a21
Office Keys
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine th...
{"inputs": ["2 4 50\n20 100\n60 10 40 80", "1 2 10\n11\n15 7", "2 5 15\n10 4\n29 23 21 22 26", "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88", "20 20 1000000000\n911196469 574676950 884047241 98421870...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
f4f8a3dbed3bce393863f09f59c5e587
none
You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string *s* so that for any prime number *p*<=≤<=|*s*| and for any integer *i* ...
{"inputs": ["abc", "abcd", "xxxyxxx", "xxxjddyxduquybxdxx", "jjjjjjjjjjzjjjjjjjjjjjjjjjj", "mggnngggnjgnggggngnggpnggumggpg", "hfihihhfh", "ppppppopppionpppppppppwppppppppppppppppppppppb", "jntnnnnnnngnnnnntnnennannnnnnnnnnnnnnnnjnnnnngnnnnannnnnnnnnq", "dattqddidyddddmriftkdddddddddqvedwddfdrdiaddiokdddodyqqddddtdddvd...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
f53c2e77b713b9fecc9d1983adaae7e8
Sereja and Stairs
Sereja loves integer sequences very much. He especially likes stairs. Sequence *a*1,<=*a*2,<=...,<=*a*|*a*| (|*a*| is the length of the sequence) is stairs if there is such index *i* (1<=≤<=*i*<=≤<=|*a*|), that the following condition is met: For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3,...
{"inputs": ["5\n1 2 3 4 5", "6\n1 1 2 2 3 3", "47\n3 4 5 3 1 4 4 3 4 6 1 5 1 3 5 3 6 5 1 4 3 2 6 5 3 1 4 6 4 6 2 1 1 1 4 3 6 1 6 6 3 5 1 4 6 4 4", "13\n8 23 26 8 15 13 35 36 28 8 4 33 6", "17\n15 29 28 23 20 12 9 30 4 13 1 25 11 20 6 23 10", "31\n189 73 300 133 414 23 150 301 252 21 274 272 316 291 339 356 201 267 257 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
f54731867043ce86f02c1fd79631d7cf
Bear and Up-Down
The life goes up and down, just like nice sequences. Sequence *t*1,<=*t*2,<=...,<=*t**n* is called nice if the following two conditions are satisfied: - *t**i*<=&lt;<=*t**i*<=+<=1 for each odd *i*<=&lt;<=*n*; - *t**i*<=&gt;<=*t**i*<=+<=1 for each even *i*<=&lt;<=*n*. For example, sequences (2,<=8), (1,<=5,<=1) and...
{"inputs": ["5\n2 8 4 7 7", "4\n200 150 100 50", "10\n3 2 1 4 1 4 1 4 1 4", "9\n1 2 3 4 5 6 7 8 9", "5\n1 1 1 4 3", "10\n7 7 8 10 5 10 1 5 2 6", "50\n11836 28308 72527 92281 139289 93797 134555 148444 40866 111317 21564 87813 65466 20541 99238 2287 74647 128071 18163 61672 39766 55589 138385 147443 138100 142683 60703 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
f556bf48bdfac471314a32265c949ac9
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles. Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection...
{"inputs": ["3 7\n1 3 4", "4 14\n4 6 12 8", "5 6\n97746 64770 31551 96547 65684", "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656", "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
93
codeforces
f5636aa985f73a0c339b33d720a5f31e
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
{"inputs": ["3\n64 16 32", "4\n4 2 1 3", "5\n1 5 3 3 2", "52\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 474 474 24 114 9 954 954 954 474", "56\n43 641 626 984 107 521 266 835 707 220 402 406 558 199 988 685 843 808 182 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
f5677e201ea80926f44a9e2ca0e950ce
Running with Obstacles
A sportsman starts from point *x**start*<==<=0 and runs to point with coordinate *x**finish*<==<=*m* (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than *s* meters (in this case for these *s* meters his path should have no obstacles), and after that he can...
{"inputs": ["3 10 1 3\n3 4 7", "2 9 2 3\n6 4", "10 100 2 8\n93 35 24 87 39 46 86 37 73 33", "10 1000000000 8905990 20319560\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858", "100 1000 1 4\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
f56798c29ee8a6da3eda8faa5ae6e069
Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
{"inputs": ["3 2\n100 5 2\n50 10", "4 3\n2 5 10 20\n100 1 3", "2 3\n50 10\n100 5 2", "1 1\n1\n1", "3 2\n100 5 2\n10 100", "5 3\n16 24 36 54 81\n4 6 9", "10 10\n2 5 11 17 23 31 41 47 59 67\n3 7 13 19 29 37 43 53 61 71", "5 5\n2 9 8 3 5\n5 7 8 1 1", "10 11\n7 43 39 13 25 23 33 40 5 2\n42 22 39 1 23 37 12 48 46 2 2", "1 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
f5720d2aa74a1670c2180f6deeffec02
Beads
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
{"inputs": ["4 4", "2 1", "2 2", "3 1", "3 2", "3 3", "4 1", "4 2", "4 3", "4 4", "4 5", "4 6", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "6 7", "6 8", "6 9", "6 10", "6 11", "6 12", "6 13", "6 14", "6 15", "6 16", "6 17", "6 18", "6 19", "6 20", "7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
f5785293d81f3553abdcb79b2d447963
Divide by three, multiply by two
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: - divide the number $x$ by $3$ ($x$ must be divisible by $3$); - multiply the number $x$ by $2$. After each operation, Polycarp writes down the result o...
{"inputs": ["6\n4 8 6 3 12 9", "4\n42 28 84 126", "2\n1000000000000000000 3000000000000000000", "19\n46875000000000000 732421875000000 5859375000000000 11444091796875 2929687500000000 187500000000000000 91552734375000 11718750000000000 3000000000000000000 22888183593750 1464843750000000 375000000000000000 4577636718750...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
f597a081a3acc7008f50eae51fc18f00
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
{"inputs": ["10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "2\nalex\nalex", "40\nuok\nkuu\nku\no\nkku\nuh\nu\nu\nhh\nk\nkh\nh\nh\nou\nokh\nukk\nou\nuhk\nuo\nuko\nu\nuu\nh\nh\nhk\nuhu\nuoh\nooo\nk\nh\nuk\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
f5a3f39afda2c439a842a8a0e82872d9
Start of the session
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n*<=×<=*n* (*n* is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to *n*<=-<=1, main diagonal should...
{"inputs": ["2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "32", "40", "666", "66", "80", "88", "96", "100", "128", "144", "250", "284", "332", "400", "600", "700", "780", "846", "902", "1000"], "outputs": ["0 1\n1 0", "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0", "0 1 4 2 5 3\n1 0 2 5 3 4\n4 2 0 3 1 5\n2 5 3 0 4 1\n5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
f5adec5d79907a5e2e386a91f8277578
Choosing Capital for Treeland
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decid...
{"inputs": ["3\n2 1\n2 3", "4\n1 4\n2 4\n3 4", "2\n1 2", "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7", "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1", "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9", "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "11\n3 10\n4 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
f5b1edc2123050877e37a9fcb3209b4a
George and Number
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers *b*. During the game, George modifies the array by using special changes. Let's mark George's current array as *b*1,<=*b*2,<=...,<=*b*|*b*| (record |*b*| denotes the current length of the array). Then one chang...
{"inputs": ["9555", "10000000005", "800101", "45", "1000000000000001223300003342220044555", "19992000", "310200", "63100605000394089000505000600600062000170273350000", "20900000000090009000070069000026000000000000020008", "60000000000000000000000000000000000000000000000000", "7", "69442629156526594581255999781161144587...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
f5beda691ed3a24d56dfc8e156695d38
Anagram Search
A string *t* is called an anagram of the string *s*, if it is possible to rearrange letters in *t* so that it is identical to the string *s*. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not. The string *t* is called a substring of the string *s* if it can be read starting fr...
{"inputs": ["bb??x???\naab", "ab?c\nacb", "ccaac\ncbcbca", "?bba?\nbba", "aaaaa??a?a\naaa", "?bba?b?aaa\nabb", "?b?aaabaa?\naaa", "aaaaa?ab??\naab", "?bab?a?aab\naaa", "??fb???a??\ndeeefc", "?\na", "a\na", "?\ncb", "a\naa"], "outputs": ["2", "2", "0", "3", "8", "6", "3", "5", "3", "0", "1", "1", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
f5de91435f10ae345408623b2344c3b1
Maximize!
You are given a multiset *S* consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to *S*, the newly added integer is not less than any number in it. 1. Find a subset *s* of the set *S* such that the value is maximum possible. Here *max*(*s*) means maximum valu...
{"inputs": ["6\n1 3\n2\n1 4\n2\n1 8\n2", "4\n1 1\n1 4\n1 5\n2", "8\n1 7\n1 26\n1 40\n1 45\n1 64\n2\n1 88\n1 94", "9\n1 35\n2\n2\n1 45\n1 58\n2\n2\n2\n1 100", "15\n1 300022520\n1 542407315\n2\n2\n2\n1 622764928\n1 706078395\n1 715915848\n1 933742920\n1 942115408\n2\n2\n2\n2\n2", "25\n1 134292126\n2\n1 218916741\n1 23755...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
f6050dd5b349336b7c103efd3295fa88
Dasha and friends
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if...
{"inputs": ["3 8\n2 4 6\n1 5 7", "4 9\n2 3 5 8\n0 1 3 6", "2 4\n1 3\n1 2", "5 9\n0 2 5 6 7\n1 3 6 7 8", "5 60\n7 26 27 40 59\n14 22 41 42 55", "20 29\n0 1 2 4 5 8 9 12 14 15 17 19 20 21 22 23 25 26 27 28\n0 2 4 5 6 7 8 10 11 12 13 14 15 16 18 19 22 23 26 28", "35 41\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 18 19 20 21 22 23 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
f61d78de4dfc8f9ad1757133850be363
Fixed Points
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A p...
{"inputs": ["5\n0 1 3 4 2", "10\n6 9 4 7 8 2 3 5 0 1", "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
111
codeforces
f6259d8cdf46697bf882fbfca39bdc34
Number With The Given Amount Of Divisors
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). Output the smallest positive integer with exactly *n* divisors. Sample Input 4 6 Sampl...
{"inputs": ["1", "7", "8", "9", "10", "15", "20", "47", "59", "100", "159", "265", "312", "473", "637", "500", "720", "902", "940", "1000", "999", "118"], "outputs": ["1", "64", "24", "36", "48", "144", "240", "70368744177664", "288230376151711744", "45360", "40532396646334464", "364791569817010176", "14192640", "25970...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
f662d236d019258c2096118a6174c09f
Bear and Elections
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect...
{"inputs": ["5\n5 1 11 2 8", "4\n1 8 8 8", "2\n7 6", "2\n1 1", "10\n100 200 57 99 1 1000 200 200 200 500", "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 65 61 60 70 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
165
codeforces
f66884c846d9ab53effb39a95437459d
Race Against Time
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with ...
{"inputs": ["12 30 45 3 11", "12 0 1 12 1", "3 47 0 4 9", "10 22 59 6 10", "3 1 13 12 3", "11 19 28 9 10", "9 38 22 6 1", "5 41 11 5 8", "11 2 53 10 4", "9 41 17 10 1", "6 54 48 12 6", "12 55 9 5 1", "8 55 35 9 3", "3 21 34 3 10", "2 52 1 12 3", "7 17 11 1 7", "11 6 37 6 4", "9 6 22 8 1", "3 10 5 5 9", "7 12 22 11 2", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
f67e84e95f79dcc728e8824d78e742f1
Necklace
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). ...
{"inputs": ["3\n4 2 1", "1\n4", "2\n1 1", "1\n2", "1\n3", "1\n5", "2\n2 2", "3\n1 2 4", "3\n3 3 3", "3\n3 3 6", "3\n6 6 6", "3\n6 6 9", "26\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", "3\n7 7 21", "2\n95 50", "3\n30 30 15", "3\n1 50 70", "2\n70 10", "10\n100 100 100 50 20 300 400 300 350 320", "4\n1100 220 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
f6b787869ae37c46c36ee88999a86ba8
Kuro and Walking Route
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which h...
{"inputs": ["3 1 3\n1 2\n2 3", "3 1 3\n1 2\n1 3", "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
f6ed80837137f82f9377e02bf1061dd1
Median on Segments (Permutations Edition)
You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t...
{"inputs": ["5 4\n2 4 5 3 1", "5 5\n1 2 3 4 5", "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9", "1 1\n1", "2 1\n1 2", "2 1\n2 1", "2 2\n1 2", "2 2\n2 1", "3 1\n1 2 3", "3 1\n1 3 2", "3 1\n2 1 3", "3 1\n2 3 1", "3 1\n3 1 2", "3 1\n3 2 1", "5 2\n2 1 3 4 5", "6 3\n3 6 1 4 2 5", "7 4\n1 7 6 4 2 3 5", "8 7\n2 3 6 8 7 5 4 1", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
f6efa3da33b7fe29692c702f81aaa53e
Cut Ribbon
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
{"inputs": ["5 5 3 2", "7 5 5 2", "4 4 4 4", "1 1 1 1", "4000 1 2 3", "4000 3 4 5", "10 3 4 5", "100 23 15 50", "3119 3515 1021 7", "918 102 1327 1733", "3164 42 430 1309", "3043 317 1141 2438", "26 1 772 2683", "370 2 1 15", "734 12 6 2", "418 18 14 17", "18 16 28 9", "14 6 2 17", "29 27 18 2", "29 12 7 10", "27 23 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
168
codeforces
f6f6f7f83556081cb3f54ab634ecbaef
Jumping on Walls
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. ...
{"inputs": ["7 3\n---X--X\n-X--XX-", "6 2\n--X-X-\nX--XX-", "10 1\n-X-X-X-X-X\nX-X-X-X-X-", "5 4\n-X---\n----X", "6 2\n--X--X\nXX-X-X", "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----", "1 1\n-\nX", "2 1\n-X\nX-", "2 1\n-X\n-X", "1 20\n-\n-", "1 100000\n-\n-...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
f7024bf1d013c03844cb96bcc9fa93bb
Chamber of Secrets
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anyb...
{"inputs": ["3 3\n.#.\n...\n.#.", "4 3\n##.\n...\n.#.\n.#.", "3 3\n###\n###\n###", "3 4\n..##\n....\n..#.", "4 3\n#.#\n...\n...\n.##", "4 4\n##..\n..#.\n...#\n...#", "5 5\n...#.\n.....\n.....\n.....\n..#.#", "5 5\n.....\n.#...\n.....\n.....\n#.###", "5 5\n.....\n.###.\n..##.\n..##.\n...#.", "5 5\n.##..\n.##..\n.#.#.\n....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
f718d17fcf33e09f943d8d3f2aa51ab5
A Good Contest
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
{"inputs": ["3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "1\nDb -3373 3591", "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
365
codeforces
f76189f114131cbaa9af76123ee3508a
Red-Green Towers
There are *r* red and *g* green blocks for construction of the red-green tower. Red-green tower can be built following next rules: - Red-green tower is consisting of some number of levels; - Let the red-green tower consist of *n* levels, then the first level of this tower should consist of *n* blocks, second level —...
{"inputs": ["4 6", "9 7", "1 1", "3 3", "2 19", "18 3", "100000 1", "1 100000", "6 6", "10 10", "200000 200000", "0 1", "1 0", "0 200000", "200000 0", "199396 0", "199395 0", "0 199397", "121147 78249", "78250 121147", "121146 78249", "199585 199586", "199586 199586", "199585 199585", "107344 159729", "2954 1977", "255...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f7633c6db0a40963f948f432f5ef18b8
Three Garlands
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s...
{"inputs": ["2 2 3", "4 2 3", "1499 1498 1500", "1500 1500 1500", "100 4 1", "4 2 4", "3 3 3", "2 3 6", "2 3 3", "4 4 2", "1 1 1", "2 11 2", "4 4 4", "4 4 5", "3 3 2", "3 6 6", "2 3 2", "1 1 3", "3 3 4", "2 4 4", "2 2 2", "2 10 10", "3 4 4", "2 5 5", "2 4 5", "228 2 2", "2 998 1000", "2 6 6", "6 4 7", "2 5 2", "2 100 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
75
codeforces
f7641ca673ddd74e3ceea30537a93912
Word Cut
Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w*<==<=*xy*. A split operation is transforming word *w*<==<=*xy* into word *u*<==<=*yx*. For ex...
{"inputs": ["ab\nab\n2", "ababab\nababab\n1", "ab\nba\n2", "aaa\naaa\n0", "hi\nhi\n1", "abcd\ncbad\n5", "ab\nba\n10", "voodoo\ndoovoo\n100000", "ababab\nbababa\n100000", "abcdefgh\ncdefghab\n666", "aaaabaaaaaaaaaaabaaaaaaa\naaaaaaaaaabaaaaaaaaabaaa\n7477", "ssgqcodnqgfbhqsgineioafkkhcmmmihbiefialidgkffrhaiekebpieqgpplm...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
f77027b5a8bdd60ddf914fe8d79e9619
Coprime Subsequences
Let's call a non-empty sequence of positive integers *a*1,<=*a*2... *a**k* coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array *a* consisting of *n* positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109<...
{"inputs": ["3\n1 2 3", "4\n1 1 1 1", "7\n1 3 5 15 3 105 35", "1\n1", "1\n100000", "5\n10 8 6 4 6", "5\n5 1 3 5 4", "5\n5 1 6 6 6", "10\n9 6 8 5 5 2 8 9 2 2", "10\n2 2 16 16 14 1 9 12 15 13", "50\n17 81 20 84 6 86 11 33 19 46 70 79 23 64 40 99 78 70 3 10 32 42 18 73 35 36 69 90 81 81 8 25 87 23 76 100 53 11 36 19 87 89...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
f787e15865d3fc919c7733bf0d10c0ca
none
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation...
{"inputs": ["3\n1 2 3", "3\n2 3 1", "3\n3 2 1", "2\n1 2", "2\n2 1", "10\n10 1 9 2 8 3 7 4 6 5", "108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
f792ab42d078f44a187ba4dbaad41927
Breaking Good
Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers. Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of...
{"inputs": ["2 1\n1 2 0", "4 4\n1 2 1\n1 3 0\n2 3 1\n3 4 1", "8 9\n1 2 0\n8 3 0\n2 3 1\n1 4 1\n8 7 0\n1 5 1\n4 6 1\n5 7 0\n6 8 0", "9 10\n1 2 0\n2 3 0\n1 4 1\n4 5 1\n4 6 1\n6 7 1\n1 7 0\n1 8 0\n7 8 0\n9 7 1", "5 6\n1 2 0\n3 2 0\n5 1 1\n1 3 1\n5 3 0\n4 3 1", "15 31\n6 2 0\n5 15 1\n2 3 1\n6 9 1\n13 12 0\n2 7 0\n15 3 0\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f7aa8d7390b43237f204ef5ed371668b
Hometask
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot ...
{"inputs": ["ababa\n1\nab", "codeforces\n2\ndo\ncs", "nllnrlrnll\n1\nrl", "aludfbjtwnkgnfl\n1\noy", "pgpgppgggpbbnnn\n2\npg\nnb", "eepeeeeppppppeepeppe\n1\npe", "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy", "drvwfaacccwnncfwuptsorrrvvvrgdzytrwweeexzyyyxuwuuk\n13\nld\nac\nnp\nrv\nmo\njh...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
f7ecc31f6717583a02c3bf8945146bfa
Worms Evolution
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ...
{"inputs": ["5\n1 2 3 5 7", "5\n1 8 1 5 1", "4\n303 872 764 401", "6\n86 402 133 524 405 610", "8\n217 779 418 895 996 473 3 22", "10\n858 972 670 15 662 114 33 273 53 310", "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
131
codeforces
f811d54f672bee985c0aacecb9dada21
Report
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands...
{"inputs": ["3 1\n1 2 3\n2 2", "4 2\n1 2 4 3\n2 3\n1 2", "4 1\n4 3 2 1\n1 4", "5 1\n1 2 3 4 5\n2 5", "6 2\n3 1 2 6 4 5\n1 6\n2 3", "10 3\n6 4 0 2 -3 7 8 -9 1 5\n1 8\n1 4\n2 2", "100 30\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
f853095fb8e1806dff3305c2c7f1356a
Two Heaps
Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cub...
{"inputs": ["1\n10 99", "2\n13 24 13 45", "5\n21 60 18 21 17 39 58 74 62 34", "10\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98", "20\n80 56 58 61 75 60 25 49 59 15 43 39 21 73 67 13 75 31 18 87 32 44 53 15 53 76 79 94 85 80 27 25 48 78 32 18 20 78 46 37", "50\n49 13 81 20 73 62 19 49 65 95 32 84 24 96 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
f862e4461b9c0bb971a8c79bb1c73e64
Not Wool Sequences
A sequence of non-negative integers *a*1,<=*a*2,<=...,<=*a**n* of length *n* is called a wool sequence if and only if there exists two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression means...
{"inputs": ["3 2", "4 2", "1 2", "4 11", "5 100", "5444 31525", "60282 92611", "62600 39199", "14095 86011", "78606 36436", "25063 54317", "86232 41348", "94882 95834", "83781 52238", "21857 94145", "7413 87155", "7683 65667", "88201 96978", "50664 46559", "60607 63595", "85264 15318", "100000 100000", "100000 16", "10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
f87bced97729877cde26614688d8cc40
Online Meeting
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat. One day the director of the F ...
{"inputs": ["5 4\n+ 1\n+ 2\n- 2\n- 1", "3 2\n+ 1\n- 2", "2 4\n+ 1\n- 1\n+ 2\n- 2", "5 6\n+ 1\n- 1\n- 3\n+ 3\n+ 4\n- 4", "2 4\n+ 1\n- 2\n+ 2\n- 1", "1 1\n+ 1", "2 1\n- 2", "3 5\n- 1\n+ 1\n+ 2\n- 2\n+ 3", "10 8\n+ 1\n- 1\n- 2\n- 3\n+ 3\n+ 7\n- 7\n+ 9", "5 5\n+ 5\n+ 2\n+ 3\n+ 4\n+ 1", "5 4\n+ 1\n- 1\n+ 1\n+ 2", "10 3\n+ 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
f8a456e2fbac83b186fed6c3beb0157b
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write *n* progress tests, for each test they will get a mark from 1 to *p*. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all t...
{"inputs": ["5 3 5 18 4\n3 5 4", "5 3 5 16 4\n5 5 5", "5 3 5 17 4\n5 5 5", "5 3 5 12 1\n5 5 1", "5 3 5 13 1\n5 5 1", "7 4 5 26 5\n5 2 4 5", "7 4 5 27 5\n5 2 4 5", "1 0 1000 999 1000", "1 0 1000 1000 1000", "1 0 1000 1000 999", "995 1 1000 1772 2\n1", "993 0 1000 63930 1", "5 3 5 25 4\n3 3 3", "7 4 5 25 5\n5 5 4 5", "7 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
f8b348afc539834c64b2f852cbcc0b6e
Increasing Sequence
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
{"inputs": ["4 2\n1 3 3 2", "2 1\n1 1", "2 1\n2 5", "2 1\n1 2", "2 1\n1 1", "2 7\n10 20", "2 7\n1 1", "3 3\n18 1 9", "3 3\n15 17 9", "3 3\n10 9 12", "10 3\n2 1 17 10 5 16 8 4 15 17", "10 3\n6 11 4 12 22 15 23 26 24 26", "10 3\n10 24 13 15 18 14 15 26 33 35", "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
229
codeforces
f8e254217a50cd8cfe9726c4fd64f082
Game of Credit Cards
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the...
{"inputs": ["3\n123\n321", "2\n88\n00", "1\n4\n5", "1\n8\n7", "2\n55\n55", "3\n534\n432", "3\n486\n024", "5\n22222\n22222", "5\n72471\n05604", "5\n72471\n72471", "5\n72471\n41772", "8\n99999999\n99999999", "8\n01234567\n01234567", "8\n07070707\n76543210", "8\n88888888\n98769876", "8\n23456789\n01234567", "5\n11222\n221...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
174
codeforces
f915e41a0bd233ff98b58882ba47ed03
Problems for Round
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules: - Problemset ...
{"inputs": ["5 2\n1 4\n5 2", "3 3\n1 2\n2 3\n1 3", "3 2\n3 1\n3 2", "2 0", "2 1\n1 2", "3 0", "3 1\n1 2", "3 1\n1 3", "100000 0", "4 2\n1 2\n3 4", "3 1\n2 3", "3 2\n1 2\n1 3", "3 2\n1 2\n2 3", "4 0", "100000 1\n100000 1", "100000 1\n26711 97965", "100000 10\n99562 479\n643 99684\n593 99867\n99529 175\n99738 616\n99523 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
f92c029ea391d554908f59e9e6fabd23
Circle Line
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ...
{"inputs": ["4\n2 3 4 9\n1 3", "4\n5 8 2 100\n4 1", "3\n1 1 1\n3 1", "3\n31 41 59\n1 1", "5\n16 13 10 30 15\n4 2", "6\n89 82 87 32 67 33\n4 4", "7\n2 3 17 10 2 2 2\n4 2", "3\n4 37 33\n3 3", "8\n87 40 96 7 86 86 72 97\n6 8", "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "34...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
295
codeforces
f93d8e4fa0765000b58f5a3f530474f7
Kay and Snowflake
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of *n* nodes. The root of tree has index 1. Kay is very intereste...
{"inputs": ["7 4\n1 1 3 3 5 3\n1\n2\n3\n5", "2 2\n1\n1\n2"], "outputs": ["3\n2\n3\n6", "2\n2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f948aec78c25fd48780db400dd2e905b
Rank List
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
{"inputs": ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "3 2\n3 3\n3 3\n3 3", "4 3\n10 3\n6 10\n5 2\n5 2", "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "3 1\n2 1\n1 1\n1 2", "1 1\n28 28", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
143
codeforces
f971e5a1ca10583a10bfb7fe8f0d6ebd
Points on Line
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
{"inputs": ["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50", "10 5\n31 36 43 47 48 50 56 69 71 86", "10 50\n1 4 20 27 65 79 82 83 99 100", "10 90\n24 27 40 41 61 69 73 87 95 97", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
271
codeforces
f992f4c7e4d9227cecb52b2bd79864d2
Grandfather Dovlet’s calculator
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typi...
{"inputs": ["1 3", "10 15", "1 100", "100 10000", "213 221442", "1 1000000", "1000000 1000000", "222145 353252", "2 1000000", "1 999999", "192 200"], "outputs": ["12", "39", "928", "188446", "5645356", "28733372", "38", "3860750", "28733370", "28733334", "122"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
111
codeforces
f9a7d083273864ce5cfc8a3db52acfc5
Strongly Connected City
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes...
{"inputs": ["3 3\n><>\nv^v", "4 6\n<><>\nv^v^v^", "2 2\n<>\nv^", "2 2\n>>\n^v", "3 3\n>><\n^^v", "3 4\n>><\n^v^v", "3 8\n>><\nv^^^^^^^", "7 2\n<><<<<>\n^^", "4 5\n><<<\n^^^^v", "2 20\n><\n^v^^v^^v^^^v^vv^vv^^", "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^", "20 2\n<><<><<>><<<>><><<<<\n^^", "20 2\n><>><>><>><<<><<><><\n^v", "11 12\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
f9a85cbfe549efd66c2fb1f532902fe2
Jamie and Binary Sequence (changed after round)
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. ...
{"inputs": ["23 5", "13 2", "1 2", "1 1", "1000000000000000000 100000", "7 2", "7 3", "7 4", "521325125150442808 10", "498518679725149504 1000", "464823731286228582 100000", "1 4", "9 4", "3 4", "144 4", "59 4", "78 4", "192 4", "107 4", "552 5", "680 5", "808 5", "1528 5", "1656 5", "26972 8", "23100 8", "19228 8", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
f9c5a5763559e747e28b34dcacc8f6e9
Difference Row
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu...
{"inputs": ["5\n100 -100 50 0 -50", "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939", "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 28...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
144
codeforces
f9e30533a717a56cf7677d43d0cff780
Ball
*N* ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ...
{"inputs": ["3\n1 4 2\n4 3 2\n2 5 3", "5\n2 8 10 0 7\n7 7 3 0 10\n2 8 3 2 2", "5\n3 0 0 2 0\n7 10 7 4 0\n9 1 6 1 9", "5\n5 4 0 2 5\n8 3 1 0 10\n4 5 0 0 5", "5\n9 7 0 2 10\n8 6 5 5 9\n1 9 3 0 1", "10\n7 7 10 1 2 1 7 1 5 9\n9 10 6 2 5 6 7 7 5 5\n2 7 4 0 7 10 5 6 2 2", "10\n7 7 0 1 2 6 0 10 3 5\n5 8 4 0 3 4 7 10 5 0\n0 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
f9eb516e2cbf8e42e3e834b5fb2eebba
The Child and Homework
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The chi...
{"inputs": ["A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "A.ab\nB.abcde\nC.ab\nD.abc", "A.c\nB.cc\nC.c\nD.c", "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_b...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
142
codeforces
f9ee988bce99481ccbaa17ab2d8b86b1
Mysterious numbers - 2
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces. Output a single integer. The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces. Output a single integer. Sample Input 2 3 2 13 14 ...
{"inputs": ["2 3 2", "13 14 1", "14 5 9", "17 18 3", "1 1 1", "4 6 7", "1 1 20", "20 20 1", "20 20 20", "12 9 18", "1 19 15", "5 5 5", "10 11 12", "3 7 17", "8 2 9"], "outputs": ["5", "14", "464", "53", "1", "110", "10946", "20", "218920", "42420", "11967", "40", "2474", "14140", "236"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
fa0b50fbf360b509f5fb8c307ce28ba4
Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
{"inputs": ["heavymetalisheavymetal", "heavymetalismetal", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua", "metametaheavyetalalmetalavylkeoheavyhemetaleavycdk", "hg"], "outputs": ["3", "2", "3", "5", "3", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
fa95baebd3d1219835ac38b5de362bb9
Roma and Changing Signs
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s...
{"inputs": ["3 2\n-1 -1 1", "3 1\n-1 -1 1", "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
79
codeforces
fa9e6b7e16715652317cbfb661c3b1f5
none
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe...
{"inputs": ["13\npobeeeedaaaaa", "22\niiiimpleeemeentatiioon", "18\naeiouyaaeeiioouuyy", "24\naaaoooiiiuuuyyyeeeggghhh", "36\naeiouyaaeeiioouuyyaaaeeeiiiooouuuyyy", "100\noiyufyyyioueoudosizoryuoedatenougiuaeuouuyoiimaeigeeycewuooyovacoiyuaygfuuaiaeuahuieeafxsciylaebeufi", "200\nmmffggzvuuzzlkafduueqocuybiiaaeeoiioouaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
faad69b01b68c5b762c9f2b9f2e0453f
Anti-Palindromize
A string *a* of length *m* is called antipalindromic iff *m* is even, and for each *i* (1<=≤<=*i*<=≤<=*m*) *a**i*<=≠<=*a**m*<=-<=*i*<=+<=1. Ivan has a string *s* consisting of *n* lowercase Latin letters; *n* is even. He wants to form some string *t* that will be an antipalindromic permutation of *s*. Also Ivan has de...
{"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1", "8\nabaccaba\n1 2 3 4 5 6 7 8", "8\nabacabca\n1 2 3 4 4 3 2 1", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 74 94 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
fab2904a98f86333c60dab6a407ca40b
Coloring a Tree
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On eac...
{"inputs": ["6\n1 2 2 1 5\n2 1 1 1 1 1", "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "2\n1\n2 2", "3\n1 1\n2 2 2", "4\n1 2 1\n1 2 3 4", "4\n1 2 3\n4 1 2 4", "5\n1 2 1 4\n1 1 1 2 2", "3\n1 2\n2 1 1", "4\n1 1 1\n3 1 3 1", "4\n1 1 2\n4 1 4 1", "4\n1 2 2\n3 1 2 3", "3\n1 1\n1 2 2"], "outputs": ["3", "5", "1", "1", "4", "4", "2", "2",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
136
codeforces
fb0053531c0e388ce49fc51a56856d5c
Coprime Arrays
Let's call an array *a* of size *n* coprime iff *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=1, where *gcd* is the greatest common divisor of the arguments. You are given two numbers *n* and *k*. For each *i* (1<=≤<=*i*<=≤<=*k*) you have to determine the number of coprime arrays *a* of size *n* such that for every *j* (1<=≤<...
{"inputs": ["3 4", "2000000 8", "1000 1000", "400000 400000", "1000 2000", "400000 800000", "1000 3000", "400000 1200000", "1000 4000", "400000 1600000", "1000 5000", "400000 2000000", "2000 1000", "800000 400000", "2000 2000", "800000 800000", "2000 3000", "800000 1200000", "2000 4000", "800000 1600000", "2000 5000", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
fb0ee76ebf2e3c8996349f51635551f9
Heads or Tails
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by t...
{"inputs": ["3 2 1 1", "2 4 2 2", "1 1 1 1", "4 5 2 3", "10 6 3 4", "10 10 1 1", "9 7 4 7", "5 5 3 2", "10 10 1 1", "20 10 1 8", "10 20 4 6", "50 50 1 30", "60 50 30 40", "100 100 1 1", "100 99 10 13", "99 100 20 7", "100 90 100 83", "80 100 1 50", "100 39 70 5", "70 80 30 80", "100 100 1 1", "100 100 100 5", "99 99 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
fb100470ea9dd5ea633506679773b01e
Poster
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of *n* characters, so the decorators hung a l...
{"inputs": ["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!", "7 3\nME,YOU.", "10 1\nEK5JQMS5QN", "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK", "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F", "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHS...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
110
codeforces
fb31e30d59f65c09b714f42e0893a6fa
Birds
Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp needs strong magic. There are *n* trees in a row on an alley in a park, there is a nest on each of the trees. In the *i*-th nest there are *c**i* birds; to summon one bird from this nest Imp needs to stay under this tree and it costs...
{"inputs": ["2 12 0 4\n3 4\n4 2", "4 1000 10 35\n1 2 4 5\n1000 500 250 200", "2 10 7 11\n2 10\n6 1", "5 1 4 6\n3 4 6 5 1\n3 0 10 2 9", "75 262 870 596\n22 13 37 6 15 25 5 1 2 13 6 3 14 7 8 15 6 15 10 3 1 21 33 2 7 14 17 7 4 9 16 29 31 4 31 16 3 11 13 38 3 14 8 18 9 3 1 10 1 5 10 16 7 5 33 9 24 9 8 13 3 31 8 18 33 17 22...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fb35ad5ba58debd68f0aba5949e0c149
Little Artem and Presents
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art...
{"inputs": ["1", "2", "3", "4", "100", "101", "102", "1000000000", "5", "6", "999999999", "999999998", "999999997", "999999996", "999999995", "999999994", "999999993", "999999992", "999999991", "1000", "10000", "100000", "1000000", "10000000", "100000000", "7"], "outputs": ["1", "1", "2", "3", "67", "67", "68", "666666...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
365
codeforces
fb4f19ca832f912bcbe6c0aec5b2d3cd
Chat Online
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between *a*1 and *b*1, between *a*2 and *b*2, ..., between *a**p* and *b**p* (all borders inclusive). But the schedule of Little X is quite strange, it d...
{"inputs": ["1 1 0 4\n2 3\n0 1", "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "5 2 27 452\n148 154\n421 427\n462 470\n777 786\n969 978\n245 247\n313 322", "3 6 25 785\n273 275\n391 397\n775 783\n84 89\n348 354\n480 483\n552 556\n711 716\n838 844", "1 6 364 421\n649 688\n31 39\n438 441\n516 524\n609 615\n708 710\n850 851...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
fb638f1ba3ca020d1c377de702d1dada
Substrings Sort
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su...
{"inputs": ["5\na\naba\nabacaba\nba\naba", "5\na\nabacaba\nba\naba\nabab", "3\nqwerty\nqwerty\nqwerty", "1\nwronganswer", "3\na\nb\nab", "2\nababaab\nabaab", "2\nq\nqq", "5\nabab\nbab\nba\nab\na", "3\nb\nc\nd", "3\naba\nbab\nababa", "4\na\nba\nabacabac\nb", "4\nab\nba\nabab\na", "3\naaa\naab\naaab", "2\nac\nabac", "2\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
169
codeforces
fb72cf1ab655d21cc8e2271adda07ca1
Guess the Permutation
Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n...
{"inputs": ["2\n0 1\n1 0", "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1 6 2 0 3 4 8 8 7\n3 1 3 2 3 0 3 3 3 3\n4 1 4 2 4 3 0 4 4 4\n5 1 6 2 8 3 4 0 9 7\n5 1 6 2 8 3 4 9 0 7\n5 1 6 2 7 3 4 7 7 0", "4\n0 1 3 2\n1 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
123
codeforces
fb74f0c531da115dd79246f7353102f6
Ace It!
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer. The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits....
{"inputs": ["A221033", "A223635", "A232726", "A102210", "A231010", "A222222", "A555555", "A102222", "A234567", "A987654", "A101010", "A246810", "A210210", "A458922", "A999999", "A888888", "A232232", "A222210", "A710210", "A342987", "A987623", "A109109", "A910109", "A292992", "A388338", "A764598", "A332567", "A108888", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
fb9cfeffe8719c2c83cb84f4009cb5d2
Little Elephant and Broken Sorting
The Little Elephant loves permutations of integers from 1 to *n* very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1,<=2,<=3,<=...,<=*n*. This time the Little Elephant has permutation *p*1,<=*p*2,<=......
{"inputs": ["2 1\n1 2\n1 2", "4 3\n1 3 2 4\n1 2\n2 3\n1 4", "7 4\n7 6 4 2 1 5 3\n1 3\n2 1\n7 2\n3 5", "10 1\n1 2 3 4 5 6 7 8 9 10\n1 10", "9 20\n9 8 7 6 5 4 3 2 1\n4 6\n9 4\n5 9\n6 8\n1 9\n5 8\n6 9\n7 3\n1 9\n8 3\n4 5\n9 6\n3 8\n4 1\n1 2\n3 2\n4 9\n6 7\n7 5\n9 6", "20 7\n3 17 7 14 11 4 1 18 20 19 13 12 5 6 15 16 9 2 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fbd08e2f563c304ba65fe1928a5c64af
none
You are given set of *n* points in 5-dimensional space. The points are labeled from 1 to *n*. No two points coincide. We will call point *a* bad if there are different points *b* and *c*, not equal to *a*, from the given set such that angle between vectors and is acute (i.e. strictly less than ). Otherwise, the poin...
{"inputs": ["6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1", "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0", "1\n0 0 0 0 0", "2\n0 1 2 3 4\n5 6 7 8 9", "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
fbe7c79a79bced6e28d91c1e7989b060
Fortune Telling
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a...
{"inputs": ["1\n1", "1\n2", "3\n5 6 7", "2\n5 7", "3\n1 2 3", "4\n4 3 1 2", "10\n90 72 76 60 22 87 5 67 17 65", "10\n18 42 20 68 88 10 87 37 55 51", "100\n25 43 35 79 53 13 91 91 45 65 83 57 9 41 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
58
codeforces