Search is not available for this dataset
problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
33 values
language
listlengths
1
1
source
stringclasses
14 values
num_solutions
int64
2
1.9M
starter_code
stringlengths
0
1.47k
subset
stringclasses
3 values
48dea5d3b269153c9936806a0c9b97dc
Perfect Encoding
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o...
{"inputs": ["36", "37", "12345678901234567890123456789", "1", "2", "3", "4", "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "710578858933137458068945311385923411361750305113825125553645790612290407508150966702638025462019898281658661470271198618633853971796952242...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
48e78a1eb2688cd13b05a10a8592caf5
The Last Fight Between Human and AI
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
{"inputs": ["1 2\n-1\n?", "2 100\n-10000\n0\n1", "4 5\n?\n1\n?\n1\n?", "68 -9959\n-3666\n-3501\n9169\n5724\n1478\n-643\n-3039\n-5537\n-4295\n-1856\n-6720\n6827\n-39\n-9509\n-7005\n1942\n-5173\n-4564\n2390\n4604\n-6098\n-9847\n-9708\n2382\n7421\n8716\n9718\n9895\n-4553\n-8275\n4771\n1538\n-8131\n9912\n-4334\n-3702\n7035...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
490145635522fa9a26bed3be4055b932
Counter Attack
Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has *n* cities, numbered from 1 to *n*, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (...
{"inputs": ["4 4\n1 2\n1 3\n4 2\n4 3", "3 1\n1 2", "8 14\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n5 6\n6 7", "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n3 4\n2 3\n2 4\n1 3\n2 1\n4 1", "4 4\n2 3\n1 2\n3 4\n1 3", "5 8\n5 1\n5 2\n5 3\n3 1\n1 4\n4 2\n3 2\n5 4", "5 10\n3 5\n5 1\n1 3\n1 4\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
490201d0bd08c1c3ad12301c1024bdd5
Antipalindrome
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}...
{"inputs": ["mew", "wuffuw", "qqqqqqqq", "ijvji", "iiiiiii", "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "ijvxljt", "fyhcncnchyf", "ffffffffffff", "fyhcncfsepqj", "ybejrrlbcinttnicblrrjeby", "yyyyyyyyyy...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
453
codeforces
493b20f8548f7eeddc61d9e27d46a567
Beauty Pageant
General Payne has a battalion of *n* soldiers. The soldiers' beauty contest is coming up, it will last for *k* days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The v...
{"inputs": ["3 3\n1 2 3", "2 1\n7 12", "1 1\n1000", "5 8\n10 3 8 31 20", "5 15\n1 2 3 4 5", "8 25\n6 8 3 7 2 1 4 9", "10 9\n5 10 2 14 15 6 3 11 4 1", "10 27\n17 53 94 95 57 36 47 68 48 16", "6 5\n17 35 15 11 33 39", "10 27\n17 53 94 95 57 36 47 68 48 16", "30 122\n5858 8519 5558 2397 3059 3710 6238 8547 2167 9401 471 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
496ca3229acb846a688f9099b6dd5e8a
Valera and Elections
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo...
{"inputs": ["5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "2\n1 2 1", "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2", "2\n2 1 1", "2\n1 2 2", "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1", "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2", "10\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
4974f12e3cb593b80705adf0a057f681
Fair Game
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with...
{"inputs": ["4\n11\n27\n27\n11", "2\n6\n6", "6\n10\n20\n30\n20\n10\n20", "6\n1\n1\n2\n2\n3\n3", "2\n1\n100", "2\n1\n1", "2\n100\n100", "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43", "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
208
codeforces
4982d2f28521315d88b166ca7f5f239e
Cards
User ainta loves to play with cards. He has *a* cards containing letter "o" and *b* cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. 1. At first, the score is 0. 1. For each block of contiguous "o"s with length *x* the score increases by *x*2. 1....
{"inputs": ["2 3", "4 0", "0 4", "8 6", "28691 28312", "1 1", "46000 39000", "1234 5678", "19310 18", "38 5", "2 122", "9966 12376", "4 2", "0 26501", "500 500", "98751 29491", "1 18468", "75232 0", "83093 94343", "86224 91008", "92608 85844", "94989 92701", "83195 80484", "4 9", "8 10", "223 874", "206 209", "493 442"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
49b905b62f9c5824272b2291ceda48cc
New Year and North Pole
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40<=000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20<=000 kilometers. Limak, a polar bear, lives on the...
{"inputs": ["5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "2\n15000 South\n4000 East", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "3\n20000 South\n10 East\n20000 North", "2\n1000 North\n1000 South", "4\n50 South\n50 North\n15000 South\n15000 North", "1\n1 South", "1\n1 East",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
49bbc3a391b0992b425b3d452dcca37e
The Great Mixing
Sasha and Kolya decided to get drunk with Coke, again. This time they have *k* types of Coke. *i*-th type is characterised by its carbon dioxide concentration . Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration . The drink should also be tasty...
{"inputs": ["400 4\n100 300 450 500", "50 2\n100 25", "500 3\n1000 5 5", "500 1\n1000", "874 3\n873 974 875", "999 2\n1 1000", "326 18\n684 49 373 57 747 132 441 385 640 575 567 665 323 515 527 656 232 701", "314 15\n160 769 201 691 358 724 248 47 420 432 667 601 596 370 469", "0 1\n0", "0 1\n1000", "345 5\n497 135 21 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
49f2657e95388d8b4d1a4f0171e94002
Caesar's Legions
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had *n*1 footmen and *n*2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that *k*1 footmen standing successively one after another, or there are strictly more than *k*2 ...
{"inputs": ["2 1 1 10", "2 3 1 2", "2 4 1 1", "10 10 5 7", "12 15 7 2", "20 8 4 8", "15 8 2 6", "100 100 10 10", "20 15 10 9", "18 4 3 1", "19 12 5 7", "20 4 9 4", "24 30 5 1", "56 37 4 1", "28 65 5 9", "67 26 6 1", "57 30 5 9", "56 40 3 2", "34 57 1 1", "78 21 10 1", "46 46 2 5", "34 55 2 9", "46 51 4 5", "64 23 3 6",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
4a24486ea6580c3b63d77eca7df64ea9
New Year's Eve
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
{"inputs": ["4 3", "6 6", "2 2", "1022 10", "415853337373441 52", "75 12", "1000000000000000000 1000000000000000000", "1 1", "1000000000000000000 2", "49194939 22", "228104606 17", "817034381 7", "700976748 4", "879886415 9", "18007336 10353515", "196917003 154783328", "785846777 496205300", "964756444 503568330", "848...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
176
codeforces
4a289f586bb2e6645c79c7f0cf249edc
Gerald is into Art
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rec...
{"inputs": ["3 2\n1 3\n2 1", "5 5\n3 3\n3 3", "4 2\n2 3\n1 2", "3 3\n1 1\n1 1", "1000 1000\n999 999\n1 1000", "7 7\n5 5\n2 4", "3 3\n2 2\n2 2", "2 9\n5 1\n3 2", "9 9\n3 8\n5 2", "10 10\n10 5\n4 3", "10 6\n10 1\n5 7", "6 10\n6 3\n6 2", "7 10\n7 5\n1 7", "10 10\n7 4\n3 5", "4 10\n1 1\n9 3", "8 7\n1 7\n3 2", "5 10\n5 2\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
90
codeforces
4a2923425f3801d7d9f54971416d2e24
Fox And Polygon
Fox Ciel just designed a puzzle game called "Polygon"! It is played using triangulations of a regular *n*-edge polygon. The goal is to transform one triangulation to another by some tricky rules. Triangulation of an *n*-edge poylgon is a set of *n*<=-<=3 diagonals satisfying the condition that no two diagonals share a...
{"inputs": ["4\n1 3\n2 4", "6\n2 6\n3 6\n4 6\n6 2\n5 2\n4 2", "8\n7 1\n2 7\n7 3\n6 3\n4 6\n6 1\n6 2\n6 3\n6 4\n6 8", "5\n5 2\n2 4\n5 2\n5 3", "5\n5 2\n2 4\n4 1\n3 1", "10\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n5 1\n5 2\n5 3\n5 7\n5 8\n5 9\n5 10", "20\n15 17\n15 18\n11 15\n11 18\n13 15\n13 11\n6 11\n6 18\n8 11\n8 6\n9 11\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4a300e8ace2b5a9aa665fdd66426a084
Economy Game
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ...
{"inputs": ["1359257", "17851817", "1000000000", "17851818", "438734347", "43873430", "999999987", "27406117", "27404883", "27403649", "27402415", "27401181", "999999999", "999999244", "999129999", "17159199", "13606913", "14841529", "915968473", "980698615", "912331505", "917261049", "999999997", "12345", "1234", "124...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
56
codeforces
4a3abdb3853aba03dd032f21afa9b29e
Vanya and Cubes
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must...
{"inputs": ["1", "25", "2", "4115", "9894", "7969", "6560", "4", "3", "5", "19", "20", "9880", "9879", "7770", "7769", "2925", "220", "219", "3046", "7590", "1014", "7142", "9999", "10000"], "outputs": ["1", "4", "1", "28", "38", "35", "33", "2", "1", "2", "3", "4", "38", "37", "35", "34", "25", "10", "9", "25", "34", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
291
codeforces
4a53944b64c9021707880d6929270e7b
Blown Garland
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is workin...
{"inputs": ["RYBGRYBGR", "!RGYB", "!!!!YGRB", "!GB!RG!Y!", "RYBG", "!Y!!!Y!!G!!!G!!B!!R!!!!B!!!!!Y!!G!R!!!!!!!!!!!!B!!!!GY!B!!!!!YR!G!!!!!!B!Y!B!!!!!!R!G!!!!!!!G!R!!!!B", "!R!GBRYG!RYGB!!G!!YG!!Y!!", "RBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGYRBGY", "GYRB!", "RBYGR"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
4abb8eb6057670c2c03f4e296ac68c82
Restaurant Tables
In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate...
{"inputs": ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1", "1 1 1\n1", "2 1 2\n2 2", "5 1 3\n1 2 2 2 1", "7 6 1\n1 1 1 1 1 1 1", "10 2 1\n2 1 2 2 2 2 1 2 1 2", "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2", "1 1 1\n1", "1 1 1\n2", "1 200000 200000\n2", "30 10 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
4acf4ae14d6675929825cacfbbbf1acd
Nastya Studies Informatics
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (*a*,<=*b*) good, if *GCD*(*a*,<=*b*)<==<=*x* and *LCM*(*a*,<=*b*)<==<=*y*, where *GCD*(*a*,...
{"inputs": ["1 2 1 2", "1 12 1 12", "50 100 3 30", "1 1000000000 1 1000000000", "1 1000000000 158260522 200224287", "1 1000000000 2 755829150", "1 1000000000 158260522 158260522", "1 1000000000 877914575 877914575", "232 380232688 116 760465376", "47259 3393570 267 600661890", "1 1000000000 1 672672000", "1000000000 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
4adbfa2180fc0d9acc69d767c335bc86
Chat Order
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then...
{"inputs": ["4\nalex\nivan\nroman\nivan", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "1\nwdi", "2\nypg\nypg", "3\nexhll\nexhll\narruapexj", "3\nfv\nle\nle", "8\nm\nm\nm\nm\nm\nm\nm\nm", "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
358
codeforces
4ae677cc69c7c41198e0d5325cef87d9
Xenia and Divisors
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held: - *a*<=&lt;<=*b*<=&lt;<=*c*; - *a* divides *b*, *b* divide...
{"inputs": ["6\n1 1 1 2 2 2", "6\n2 2 1 1 4 6", "3\n1 2 3", "3\n7 5 7", "3\n1 3 4", "3\n1 1 1", "9\n1 3 6 6 3 1 3 1 6", "6\n1 2 4 1 3 5", "3\n1 3 7", "3\n1 1 1", "9\n1 2 4 1 2 4 1 3 6", "12\n3 6 1 1 3 6 1 1 2 6 2 6", "9\n1 1 1 4 4 4 6 2 2", "9\n1 2 4 6 3 1 3 1 5", "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4", "3\n2 3 6", "3\n2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
155
codeforces
4b157272fc9144a33406e44107e41fc0
Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee ...
{"inputs": ["3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "2 1 1\n1 1\n200000 200000\n90 100", "1 1 1\n1 1\n1 1", "1 1 1\n200000 200000\n200000 200000"], "outputs": ["3\n3\n0\n4", "0", "1", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
107
codeforces
4b2a63e8f645fb7d2ae4b5d1e88f3dd5
GCD of Polynomials
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way: This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *P*(*x*). is called the remainder of division of polynomial by polynomial ...
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
4b3f5628318bf19366fb2f1bd0cf93fc
Domino Effect
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges *n* dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the domino...
{"inputs": ["14\n.L.R...LR..L..", "1\n.", "1\nL", "1\nR", "2\nL.", "2\nRL", "2\n..", "10\nR........L", "9\nR.......L", "6\n..L.RL", "34\n..R...L..RL..RLRLR...L....R....L..", "2\nLR", "2\n.R", "2\nR.", "2\n.L", "3\nRLR", "3\nLRL", "5\n.L.R.", "5\n.R.L.", "5\nRL.RL", "14\nLR..LR....LRLR", "34\n.RL.R.L.R..L.R...L.R....L.R...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4b48e957142639581342a8c65a0beda0
Smallest number
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced...
{"inputs": ["1 1 1 1\n+ + *", "2 2 2 2\n* * +", "1 2 3 4\n* + +", "15 1 3 1\n* * +", "8 1 7 14\n+ + +", "7 17 3 25\n+ * +", "13 87 4 17\n* * *", "7 0 8 15\n+ + *", "52 0 43 239\n+ + +", "1000 1000 999 1000\n* * *", "720 903 589 804\n* * *", "631 149 496 892\n* * +", "220 127 597 394\n* + +", "214 862 466 795\n+ + +", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
4b49d862e1af6b9a457569a38e2ed5c2
Rational Resistance
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil...
{"inputs": ["1 1", "3 2", "199 200", "1 1000000000000000000", "3 1", "21 8", "18 55", "1 2", "2 1", "1 3", "2 3", "1 4", "5 2", "2 5", "4 5", "3 5", "13 4", "21 17", "5 8", "13 21", "74 99", "2377 1055", "645597 134285", "29906716 35911991", "3052460231 856218974", "288565475053 662099878640", "11504415412768 127540361...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
65
codeforces
4b555db9f755aa0d187fe9ae322aa163
Running Track
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating *t*. On planet AMI-1511 the coating of the t...
{"inputs": ["abc\ncbaabc", "aaabrytaaa\nayrat", "ami\nno", "r\nr", "r\nb", "randb\nbandr", "aaaaaa\naaaaa", "aaaaaa\naaaaaaa", "qwerty\nywertyrewqqq", "qwerty\nytrewq", "azaza\nzazaz", "mnbvcxzlkjhgfdsapoiuytrewq\nqwertyuiopasdfghjklzxcvbnm", "imnothalfthemaniusedtobetheresashadowhangingovermeohyesterdaycamesuddenlywgk...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
4b567bd6e01c14c6cad914fb1e248b98
Luxurious Houses
The capital of Berland has *n* multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in a...
{"inputs": ["5\n1 2 3 1 2", "4\n3 2 1 4", "1\n2", "2\n5 4", "5\n10 18 36 33 20", "5\n91 96 94 95 91", "10\n9 6 8 5 5 2 8 9 2 2", "10\n55 50 51 53 53 52 50 54 54 53", "20\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "20\n82 78 86 80 80 76 88 74 70 88 71 75 73 72 79 85 79 90 79 77", "40\n66 68 59 100 55...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
4b60048a0e4b413fa9ba63a4af5433db
Lucky Probability
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the ...
{"inputs": ["1 10 1 10 2", "5 6 8 10 1", "1 20 100 120 5", "1 10 1 10 3", "1 100 1 100 2", "47 95 18 147 4", "1 1000000000 1 1000000000 47", "1 2 3 4 12", "1 50 64 80 4", "1 128 45 99 2", "45 855 69 854 7", "1 1000 1 1000 2", "999 999 1000 1000 1", "789 5888 1 10 7", "1 1000 1 1000 14", "4 4 7 7 2", "7 7 4 4 2", "2588 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
4b6a67bb76e77433f586d37d78ecdfae
Sofa Thief
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ...
{"inputs": ["2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1", "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0", "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0", "1\n1 2\n1 1 1 2\n0 0 0 0", "1\n2 1\n2 1 1 1\n0 0 0 0", "1\n1000 1000\n63 902 63 901\n0 0 0 0", "6\n10 10\n3 6 3 7\n4 9 5 9\n5 4 5 3\n7 1 8 1\n9 10 8 10\n7 7 7 8\n0 5 2 3", "2\n4 4\n3 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
4b6ebb7fe049d8c36c6388590e93ec3c
Prime Gift
Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn how to solve number theory problems in the past year. That's why instead of Ded Moroz he was visited by his teammate Andrew, who solemnly presented him with a set of *n* distinct prime numbers alongside with a...
{"inputs": ["3\n2 3 5\n7", "5\n3 7 11 13 31\n17", "2\n41 61\n66", "1\n2\n55", "7\n2 3 5 7 11 13 17\n2666471", "16\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53\n755104793", "8\n3 7 13 17 19 29 31 37\n68830", "8\n3 7 11 17 19 23 37 43\n528714", "8\n3 7 13 17 29 41 43 47\n430196", "8\n2 5 7 19 29 31 37 41\n912071", "9\n2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4b846aa0277bb4b4c287ebc625fd544d
Interactive Bulls and Cows (Hard)
The only difference from the previous problem is the constraint on the number of requests. In this problem your program should guess the answer doing at most 7 requests. This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get re...
{"inputs": ["0123", "1234", "9876", "7158", "7590", "7325", "7524", "7269", "7802", "7436", "7190", "7390", "2548", "2193", "2491", "2469", "2659", "2405", "2058", "2580", "2316", "2516", "8796", "8534", "9067", "8712", "9023", "8645", "8623", "8923", "8567", "8756", "0351", "9863", "0518", "0263", "0462", "0429", "062...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4b8bf6a7e20682853f8d4eb7977979bc
Kefa and Park
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v...
{"inputs": ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "3 2\n1 1 1\n1 2\n2 3", "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5", "6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6", "7 3\n1 1 1 1 1 0 1\n1 2\n1 3\n2 4\n3 5\n5 6\n6 7", "15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
44
codeforces
4b9a92245483f4058b4f0cb60081df9b
XOR Equation
Two positive integers *a* and *b* have a sum of *s* and a bitwise XOR of *x*. How many possible values are there for the ordered pair (*a*,<=*b*)? The first line of the input contains two integers *s* and *x* (2<=≤<=*s*<=≤<=1012, 0<=≤<=*x*<=≤<=1012), the sum and bitwise xor of the pair of positive integers, respectivel...
{"inputs": ["9 5", "3 3", "5 2", "6 0", "549755813887 549755813887", "2 0", "2 2", "433864631347 597596794426", "80 12", "549755813888 549755813886", "643057379466 24429729346", "735465350041 356516240229", "608032203317 318063018433", "185407964720 148793115916", "322414792152 285840263184", "547616456703 547599679487...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
4b9efbe937a1036c33df235b8132dfe0
Invariance of Tree
A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles. Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p*<==<=*p*1*p*2... *p**n*, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by a...
{"inputs": ["4\n4 3 2 1", "3\n3 1 2", "3\n3 2 1", "4\n3 4 1 2", "5\n5 3 2 1 4", "8\n1 2 6 4 5 7 8 3", "11\n7 3 5 2 10 1 9 6 8 4 11", "1\n1", "2\n1 2", "2\n2 1", "6\n2 1 6 5 3 4", "6\n2 1 4 5 6 3", "4\n2 3 4 1", "6\n2 3 4 1 6 5", "6\n4 1 2 3 6 5"], "outputs": ["YES\n4 1\n4 2\n1 3", "NO", "YES\n2 1\n2 3", "YES\n4 2\n4 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
4bf42ec96ffd1342873f59118733cee4
Full Binary Tree Queries
You have a full binary tree having infinite levels. Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1. The value of the root is 1. You need to answer *Q* queries. There are 3 types of queries: 1. Cyclically shift the values of...
{"inputs": ["5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8", "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14", "6\n3 1\n2 1 0\n3 10\n2 1 -4\n3 10\n2 10 -5", "3\n3 1000000000000000000\n1 12345 13\n3 1000000000000000000", "10\n3 999\n3 822\n2 339 -75\n2 924 -56\n3 863\n3 311\n1 269 84\n2 604 9\n2 788 -98\n1 233 60", "10\n2 64324170 413214447865...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4bfe1e0069a303c77dfd34af728b3070
Drazil and His Happy Friends
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th ...
{"inputs": ["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1", "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82", "52 91\n13 26 1 3 43 17 19 32 46 33 48 23 37 50\n25 78 26 1 40 2 67 42 4 56 30 70 84 32 20 85 59 8 86 34 73 23 10 88 24 11", "26 52\n8 0 14 16...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
4c06a1bab8e7d9a2924976ed686dc364
Find Amir
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an...
{"inputs": ["2", "10", "43670", "4217", "17879", "31809", "40873", "77859", "53022", "79227", "100000", "82801", "5188", "86539", "12802", "20289", "32866", "33377", "31775", "60397", "100000", "99999", "99998", "99997", "99996", "1", "2", "3", "4", "1", "3"], "outputs": ["0", "4", "21834", "2108", "8939", "15904", "20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
170
codeforces
4c0d2851e8af707dd834cb7304166c2a
Young Physicist
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
{"inputs": ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "10\n-6 21 18\n20 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3,146
codeforces
4c5d9381944990813e0c5b4985ad0cc7
Table Tennis
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of t...
{"inputs": ["2 2\n1 2", "4 2\n3 1 2 4", "6 2\n6 5 3 1 2 4", "2 10000000000\n2 1", "4 4\n1 3 4 2", "2 2147483648\n2 1", "3 2\n1 3 2", "3 3\n1 2 3", "5 2\n2 1 3 4 5", "10 2\n7 10 5 8 9 3 4 6 1 2", "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
206
codeforces
4c5e4af36646b7431328b73207d396aa
Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
{"inputs": ["5\nRUURU", "17\nUUURRRRRUUURURUUU", "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
249
codeforces
4c628953952ca885e9bdfe1f8d432e5f
Points
You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000...
{"inputs": ["4\n1 1\n-1 -1\n1 -1\n-1 1", "1\n6 3", "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1\n-13 -9\n13 17\n-14 -8\n2 5\n18 5"], "outputs": ["32", "0", "265705"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
4c6f3c4cf65608d51f3e8cb2edb582fa
Summarize to the Power of Two
A sequence $a_1, a_2, \dots, a_n$ is called good if, for each element $a_i$, there exists an element $a_j$ ($i \ne j$) such that $a_i+a_j$ is a power of two (that is, $2^d$ for some non-negative integer $d$). For example, the following sequences are good: - $[5, 3, 11]$ (for example, for $a_1=5$ we can choose $a_2=3...
{"inputs": ["6\n4 7 1 5 4 9", "5\n1 2 3 4 5", "1\n16", "4\n1 1 1 1023", "10\n2 10 9 1 10 4 7 8 5 4", "2\n1 1", "2\n1 6", "6\n1 7 7 7 7 7", "3\n1 2 3", "3\n1 3 3", "2\n3 3", "2\n3 1", "3\n1 2 2", "2\n2 2", "2\n2 1", "3\n1 1 3", "3\n1 3 2", "3\n1 1 2", "1\n1"], "outputs": ["1", "2", "1", "0", "5", "0", "2", "0", "1", "0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
4c73f2082dd47092f72be6e744d64e2a
Pursuit For Artifacts
Johnny is playing a well-known computer game. The game are in some country, where the player can freely travel, pass quests and gain an experience. In that country there are *n* islands and *m* bridges between them, so you can travel from any island to any other. In the middle of some bridges are lying ancient powerfu...
{"inputs": ["6 7\n1 2 0\n2 3 0\n3 1 0\n3 4 1\n4 5 0\n5 6 0\n6 4 0\n1 6", "5 4\n1 2 0\n2 3 0\n3 4 0\n2 5 1\n1 4", "5 6\n1 2 0\n2 3 0\n3 1 0\n3 4 0\n4 5 1\n5 3 0\n1 2", "1 0\n1 1", "2 1\n1 2 1\n1 2", "2 1\n1 2 1\n1 1", "3 2\n1 2 1\n2 3 0\n3 1", "3 2\n1 2 1\n2 3 0\n2 3", "3 3\n1 2 0\n2 3 0\n3 1 1\n2 2", "4 4\n1 2 0\n2 3 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4c89c41cf6f52dd1d44ab9210465e0d0
Codeforces World Finals
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a...
{"inputs": ["01.01.98\n01.01.80", "20.10.20\n10.02.30", "28.02.74\n28.02.64", "05.05.25\n06.02.71", "19.11.54\n29.11.53", "01.06.84\n24.04.87", "30.06.43\n14.09.27", "09.05.55\n25.09.42", "14.05.21\n02.01.88", "27.12.51\n26.06.22", "12.10.81\n18.11.04", "26.04.11\n11.07.38", "17.01.94\n17.03.58", "15.01.93\n23.04.97", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
4c9a939d342fd4c12a76fa302d4e427b
Sorting by Subsequences
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a sub...
{"inputs": ["6\n3 2 1 6 5 4", "6\n83 -75 -49 11 37 62", "1\n1", "2\n1 2", "2\n2 1", "3\n1 2 3", "3\n3 2 1", "3\n3 1 2", "10\n3 7 10 1 9 5 4 8 6 2", "20\n363756450 -204491568 95834122 -840249197 -49687658 470958158 -445130206 189801569 802780784 -790013317 -192321079 586260100 -751917965 -354684803 418379342 -253230108 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
4c9bcbb129bcfcac01bafaf31161d591
ucyhf
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. jxu ydfkj sediyiji ev q iydwbu ydjuwuh *d* (1<=≤<=*d*<=≤<=11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt. ekjfkj q iydwbu dkcruh. Sample Input 1 Sample Output 13
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "8216", "119", "10618", "6692", "10962", "6848", "4859", "8653", "6826", "10526", "9819", "10844", "7779", "1340", "4020", "2279", "5581", "11107", "7397", "5273", "10476", "7161", "4168", "1438", "6327", "10107", "6399", "11182", "11183", "11184"], "output...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
4cb7aba01159e7079d9d6d1b8549c5e8
Elimination
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list....
{"inputs": ["1 10\n7 2\n1", "2 2\n2 1\n2", "8 9\n2 2\n3", "5 5\n8 8\n7", "1 8\n8 10\n8", "5 7\n9 1\n8", "35 28\n35 60\n44", "19 76\n91 91\n87", "20 38\n38 70\n58", "2 81\n3 39\n45", "7 63\n18 69\n30", "89 69\n57 38\n15", "3 30\n10 83\n57", "100 3\n93 23\n98", "2 78\n21 24\n88", "40 80\n4 31\n63", "1 48\n89 76\n24", "5 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
4cc15ba1bf48baf470e3df7be87f7edc
none
Есть *n*-подъездный дом, в каждом подъезде по *m* этажей, и на каждом этаже каждого подъезда ровно *k* квартир. Таким образом, в доме всего *n*·*m*·*k* квартир. Они пронумерованы естественным образом от 1 до *n*·*m*·*k*, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором ...
{"inputs": ["4 10 5\n200 6", "3 1 5\n7 2", "100 100 100\n1 1000000", "1000 1000 1000\n1 1000000000", "125 577 124\n7716799 6501425", "624 919 789\n436620192 451753897", "314 156 453\n9938757 14172410", "301 497 118\n11874825 13582548", "491 980 907\n253658701 421137262", "35 296 7\n70033 65728", "186 312 492\n19512588 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
4cc989015af2251b0ec9feb79fcb0189
The Union of k-Segments
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. The first line contains two integers *n* and ...
{"inputs": ["3 2\n0 5\n-3 2\n3 8", "3 2\n0 5\n-3 3\n3 8", "1 1\n-1 1", "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78", "10 1\n3 60\n-73 -37\n59 69\n-56 1\n-84 -24\n-14 46\n-65 -23\n-66 -57\n-87 -80\n-21 20", "10 10\n-92 87\n-100 -67\n-88 80\n-82 -59\n-72 81\n-50 30\n30 77\n65 92\n-76...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
4d20c7698eadee9d13c983381c5be7d6
Vanya and Cards
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time p...
{"inputs": ["3 2\n-1 1 2", "2 3\n-2 -2", "4 4\n1 2 3 4", "2 2\n-1 -1", "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2", "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15", "1 4\n-3", "10 7\n6 4 6 6 -3 4 -1 2 3 3", "2 1\n1 -1", "1 1\n0", "8 13\n-11 -1 -11 12 -2 -2 -10 -11", "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
229
codeforces
4d2e7d38f23a5531f3d391346ad788ae
Journey
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially I...
{"inputs": ["4 3 13\n1 2 5\n2 3 7\n2 4 8", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2", "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4", "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9", "4 4 3\n1 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
4d315db31337800f8068a03044a6854a
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<...
{"inputs": ["6 5\n1 3 8 14 19 20", "6 1\n1 3 5 7 9 10", "1 1\n1000000000", "5 5\n1 7 12 13 14", "2 1000000000\n1 1000000000", "3 5\n1 10 20", "3 10\n1 2 3", "2 1\n1 100", "3 1\n1 2 10", "2 1\n1 2"], "outputs": ["3", "2", "1", "4", "2", "1", "3", "1", "1", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
455
codeforces
4d461faa69703d521ca3e9d5400fb27e
Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him. The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so...
{"inputs": ["2\n1 2 3 4 5 6", "2\n1 2 3 3 2 2", "1\n39 52", "2\n59 96 34 48 8 72", "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89", "5\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82 91 20 64 52 70 6 88 53 47 30 47 34 14 11 22 42 15 28 54 37 48 29 3 14 13 18 77 90 58 54 38 94 49 45 66 13 74 11 14 64 72 95 54 73 79 41 35", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
4d4743cbbd6fab36d93393b725364698
Game Outcome
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ...
{"inputs": ["1\n1", "2\n1 2\n3 4", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "2\n1 1\n1 1", "3\n1 2 3\n4 5 6\n7 8 9", "3\n1 2 3\n3 1 2\n2 3 1", "4\n1 2 3 4\n8 7 6 5\n9 10 11 12\n16 15 14 13", "1\n53", "5\n1 98 22 9 39\n10 9 44 49 66\n79 17 23 8 47\n59 69 72 47 14\n94 91 98 19 54", "1\n31", "1\n92", "5\n61 45 70 19 48\n5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
139
codeforces
4d5a50f021c4770a7b23556a5ad893bf
String
You are given a string *s*. Each pair of numbers *l* and *r* that fulfill the condition 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|, correspond to a substring of the string *s*, starting in the position *l* and ending in the position *r* (inclusive). Let's define the function of two strings *F*(*x*,<=*y*) like this. We'll find a list...
{"inputs": ["aaaa", "abcdef", "abacabadabacaba", "tkth", "eqkrqe", "cwuiax", "hhhhqhqh", "gmxfmcgp", "eleellleeee", "usussubuubbbbs", "lhmpaugvnqzrfxke", "xkkkkkkkkkkkkkkkkxkkkk", "pprppppriiriiiirprppprriir", "jsoxkutcvyshsinfmtrpujedcbmyqlojzco", "emcegmekgnlefkeguqkfffnduqhfhhhndlfhlfdqdncefnn", "ffffdjfddffdjdfffdd...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4d5a544372c1f78904b64c235df052b3
Maximum Submatrix 2
You are given a matrix consisting of digits zero and one, its size is *n*<=×<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations? Let's assume that the rows of matrix *a* are numbered from...
{"inputs": ["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101", "11 16\n0111110101100011\n1000101100010000\n0010110110010101\n0110110010110010\n0011101101110000\n1001100011010111\n0010011111111000\n0100100100111110\n1001000000100111\n0110000011001000\n1011111011010000", "19 12\n110001100110\n100100000000\n101011001111\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4d7ccba00f2546ab87348b15d1ccaedd
Palindrome Transformation
Nam is playing with a string on his computer. The string consists of *n* lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that...
{"inputs": ["8 3\naeabcaez", "8 3\nabcddcbb", "4 4\nrkoa", "39 30\nyehuqwaffoiyxhkmdipxroolhahbhzprioobxfy", "40 23\nvwjzsgpdsopsrpsyccavfkyyahdgkmdxrquhcplw", "10 5\nabcdeedcba", "5 5\npjfjb", "57 9\nibkypcbtpdlhhpmghwrmuwaqoqxxexxqoqawumrwhgmphhldixezvfpqh", "10 6\nabcdefdcba", "167 152\nvqgjxbuxevpqbpnuyxktgpwdgyebn...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4d80ebfc6443ce589574ba07fc4ccc26
Lucky Permutation Triple
Bike is interested in permutations. 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, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=...
{"inputs": ["5", "2", "8", "9", "2", "77", "6", "87", "72", "1", "23", "52", "32", "25", "54", "39", "20", "53", "34", "23", "37123", "41904", "46684", "67817", "72598", "85891", "74320", "11805", "16586", "5014", "73268", "61697", "99182", "79771", "68199", "5684", "10465", "31598", "36379", "16968", "93061", "73650",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
112
codeforces
4d8d291a20665d34f57ee85c1c0b09e5
Nuts
You have *a* nuts and lots of boxes. The boxes have a wonderful feature: if you put *x* (*x*<=≥<=0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into *x*<=+<=1 sections. You are minimalist. Therefore, on the one hand, you are against dividing some box into more than *k* sections. On ...
{"inputs": ["3 10 3 3", "3 10 1 3", "100 100 1 1000", "5 347 20 1", "6 978 10 5", "6 856 50 35", "8 399 13 36", "4 787 48 4", "4 714 7 6", "7 915 12 24", "8 995 3 28", "10 267 4 48", "10 697 1 34", "7 897 49 42", "10 849 3 28", "477 492 438 690", "461 790 518 105", "510 996 830 417", "763 193 388 346", "958 380 405 434...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
66
codeforces
4d968990515143126bf1c953554bd7af
Bottles
Nick has *n* bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda *a**i* and bottle volume *b**i* (*a**i*<=≤<=*b**i*). Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends *x* seconds t...
{"inputs": ["4\n3 3 4 3\n4 7 6 5", "2\n1 1\n100 100", "5\n10 30 5 6 24\n10 41 7 8 24", "1\n1\n100", "1\n100\n100", "1\n50\n100", "10\n18 42 5 1 26 8 40 34 8 29\n18 71 21 67 38 13 99 37 47 76", "20\n24 22 4 34 76 13 78 1 81 51 72 11 25 46 22 33 60 42 25 19\n40 81 10 34 84 16 90 38 99 81 100 19 79 65 26 80 62 47 76 47", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
4d9ab805a078033afdc5d734124742b1
Bank Hacking
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are *n* banks, numbered from 1 to *n*. There are also *n*<=-<=1 wires connecting the b...
{"inputs": ["5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "3\n2 2 2\n3 2\n1 2", "3\n999397 999397 999397\n2 3\n2 1", "5\n1000000000 0 1000000000 0 1000000000\n1 2\n2 3\n3 4\n4 5", "10\n-1000000000 -1000000000 -1000000000 -1000000000 -1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
4dc3104dd6c4d9f7b9c8e2f32e3e753a
Letters Cyclic Shift
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is ...
{"inputs": ["codeforces", "abacaba", "babbbabaababbaa", "bcbacaabcababaccccaaaabacbbcbbaa", "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda", "a", "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec", "fddfbabadaadaddfbfecad...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
56
codeforces
4e08ca09a438f1950115137022731cbe
Pens And Days Of Week
Stepan has *n* pens. Every day he uses them, and on the *i*-th day he uses the pen number *i*. On the (*n*<=+<=1)-th day again he uses the pen number 1, on the (*n*<=+<=2)-th — he uses the pen number 2 and so on. On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the...
{"inputs": ["3\n3 3 3", "5\n5 4 5 4 4", "28\n2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033", "7\n10 10 10 10 10 10 10", "28\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4e1001b37563a9d7ff5a7f598df7bd5e
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills: For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, ...
{"inputs": ["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4", "4\n1 3 4 5", "2\n3 3", "2\n13 2", "5\n2 2 2 2 2", "6\n11 1 7 9 5 13", "2\n100000000 1", "5\n2 3 1 4 6", "5\n1 2 2 3 4", "3\n1 4 2", "3\n8 8 8", "5\n2 2 2 2 3", "1\n100000000", "20\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45", "40\n100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
4e13badfe8593ea28f7db56aa201e76c
Median on Segments (General Case Edition)
You are given an integer sequence $a_1, a_2, \dots, a_n$. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. The median of a sequence is the value of an element which is in the middle of the sequence after s...
{"inputs": ["5 4\n1 4 5 60 4", "3 1\n1 1 1", "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3", "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", "2 2\n1 1", "3 2\n1 1 2", "2 1\n1 1", "1 1\n2", "2 2\n4 1", "3 3\n5 5 3", "4 3\n3 5 2 3", "5 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
4e1984b93f1c4fa1a4de130e3bd4e45c
Bipartite Checking
You are given an undirected graph consisting of *n* vertices. Initially there are no edges in the graph. Also you are given *q* queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of t...
{"inputs": ["3 5\n2 3\n1 3\n1 2\n1 2\n1 2", "5 10\n1 5\n2 5\n2 4\n1 4\n4 5\n2 4\n2 5\n1 4\n2 3\n1 2", "10 20\n1 10\n5 7\n1 2\n3 5\n3 6\n4 9\n3 4\n6 9\n4 8\n6 9\n7 8\n3 8\n7 10\n2 7\n3 7\n5 9\n6 7\n4 6\n2 10\n8 10", "10 30\n5 6\n5 9\n4 9\n6 7\n7 9\n3 10\n5 6\n5 7\n6 10\n2 4\n2 6\n2 5\n3 7\n1 8\n8 9\n3 4\n3 5\n1 9\n6 7\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4e220ac1005c900d81bf721ad9ab46cb
Devu and his Brother
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays *a* and *b* by their father. The array *a* is given to Devu and *b* to his brother. As Devu is really a naughty kid, he wants the minimum value of his array *a* should be at least as much...
{"inputs": ["2 2\n2 3\n3 5", "3 2\n1 2 3\n3 4", "3 2\n4 5 6\n1 2", "10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100", "1 1\n401114\n998223974", "1 1\n100\n4", "1 1\n100\n183299", "1 1\n999999999\n1000000000", "1 1\n1000000000\n1000000000", "1 1\n1\n2", "1 1\n1\n1", "1 1\n2\n1", "1 1\n1\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
4e2f2585b450362d7e2a53f3e8966fe1
none
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly *S* slices. It is known that the *i*-th contestant will eat *s**i* slices of pizza, and ...
{"inputs": ["3 12\n3 5 7\n4 6 7\n5 9 5", "6 10\n7 4 7\n5 8 8\n12 5 8\n6 11 6\n3 3 7\n5 9 6", "1 100\n97065 97644 98402", "1 100000\n1 82372 5587", "25 6\n1 10 5\n1 8 4\n1 8 2\n4 8 9\n3 2 8\n1 9 5\n2 10 10\n3 9 6\n3 5 4\n2 7 8\n2 3 2\n2 6 8\n3 7 8\n4 3 7\n1 8 1\n3 6 4\n3 2 8\n2 2 1\n4 8 8\n4 8 4\n3 10 2\n3 6 6\n2 2 5\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4e6946d661b5320cd47b3c77431ea1bd
Food on the Plane
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats...
{"inputs": ["1f", "2d", "4a", "5e", "2c", "1b", "1000000000000000000d", "999999999999999997a", "1c", "1d", "1e", "1a", "2a", "2b", "2e", "2f", "3a", "3b", "3c", "3d", "3e", "3f", "4b", "4c", "4d", "4e", "4f", "999999997a", "999999997b", "999999997c", "999999997d", "999999997e", "999999997f", "999999998a", "999999998b",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
101
codeforces
4e6f6cbabbc99f8cca4697f102ddcb4a
Kyoya and Photobooks
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
{"inputs": ["a", "hi", "y", "kgan", "zoabkyuvus", "spyemhyznjieyhhbk", "xulsyfkuizjauadjjopu", "e", "zv", "jgv", "zsfo", "jselr", "dwemig", "mddoxsf", "jgirkrmi", "spkxurcum", "fykkiubdkt", "fznbcxsxygs", "qcrvrdqcbtou", "qktrbjzrqgmlr", "foamodbvptlxxg", "ydzpjhsidipricw", "lpfpndmjfvqejdgf", "ofkvparuvjtggnmab", "xxn...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
398
codeforces
4e7689d6c8eafdd03fd8c880eb071bcf
Enemy is weak
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number. In Shapur's opinion the weaknes...
{"inputs": ["3\n3 2 1", "3\n2 3 1", "4\n10 8 3 1", "4\n1 5 4 3", "9\n10 9 5 6 8 3 4 7 11", "7\n11 3 8 4 2 9 6", "6\n2 1 10 7 3 5", "4\n1 5 3 10", "3\n2 7 11", "5\n4 11 7 5 10", "72\n685 154 298 660 716 963 692 257 397 974 92 191 519 838 828 957 687 776 636 997 101 800 579 181 691 256 95 531 333 347 803 682 252 655 297 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
4e7ef17cfdabf27d2d245b8f76ac89d4
Tetrahedron
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
{"inputs": ["2", "4", "1", "3", "5", "6", "7", "8", "9", "10", "15", "30", "10000000", "100", "300", "900", "1500", "3000", "5000", "10000", "50000", "90000", "99999", "100000", "300000", "800000", "1000000", "4000000", "9000000", "9999999", "1000000", "9999999", "10000000", "9999998", "30", "31"], "outputs": ["3", "21...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
4e93562b61be1dc35e16228296a50a7a
Jumping Ball
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at pos...
{"inputs": ["4\n<<><", "5\n>>>>>", "4\n>><<", "3\n<<>", "3\n<<<", "3\n><<", "1\n<", "2\n<>", "3\n<>>", "3\n><>", "2\n><", "2\n>>", "2\n<<", "1\n>", "3\n>><", "3\n>>>", "3\n<><", "10\n<<<><<<>>>", "20\n><><<><<<>>>>>>>>>>>", "20\n<<<<<<<<<<><<<<>>>>>", "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>", "100\n<<<<...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
163
codeforces
4e9884823cc182d8bcd7b08538d77a54
MUH and Sticks
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
{"inputs": ["4 2 5 4 4 4", "4 4 5 4 4 5", "1 2 3 4 5 6", "5 5 5 5 5 5", "1 1 1 2 3 5", "1 1 1 1 1 1", "9 9 9 9 9 9", "1 8 9 1 1 1", "9 9 9 1 9 9", "1 2 3 8 9 7", "5 5 5 6 6 6", "1 1 2 2 3 4", "4 4 4 4 4 2", "2 2 3 3 4 4", "4 4 4 4 4 5", "1 1 2 2 2 2", "1 2 5 5 5 5", "4 4 2 2 2 2", "1 1 1 1 1 2", "2 2 4 4 4 4", "4 4 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
200
codeforces
4eb717ee9cf01551ebb483e88ba4b9f5
Vladik and Entertaining Flags
In his spare time Vladik estimates beauty of the flags. Every flag could be represented as the matrix *n*<=×<=*m* which consists of positive integers. Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that s...
{"inputs": ["4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5", "5 2 9\n6 1\n6 6\n6 6\n6 6\n5 6\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 2\n1 1", "5 4 10\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5\n2 4\n2 2\n1 2\n1 4\n1 1\n1 3\n2 4\n2 3\n1 3\n3 3", "8 4 12\n7 20 20 29\n29 7 29 29\n29 20 20 29\n29 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4ec79af96774776f3541a3c3c00f4d6a
Mike and Foam
Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are *n* kinds of beer at Rico's numbered from 1 to *n*. *i*-th kind of beer has *a**i* milliliters of foam on it. Maxim is Mike's boss. Today he told Mike to perform *q* queries. Initially the shelf is empty. In each request,...
{"inputs": ["5 6\n1 2 3 4 6\n1\n2\n3\n4\n5\n1", "3 3\n151790 360570 1\n2\n3\n3", "1 1\n1\n1", "5 10\n1 1 1 1 1\n1\n2\n3\n4\n5\n5\n4\n3\n2\n1", "1 2\n499590\n1\n1"], "outputs": ["0\n1\n3\n5\n6\n2", "0\n1\n0", "0", "0\n1\n3\n6\n10\n6\n3\n1\n0\n0", "0\n0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4ecaefff8877a36ffd6fb1febd12369d
The Untended Antiquity
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of *n*<=×<=*m* cells, arranged into *n* rows and *m* columns. The *c*-th cell in the *r*-th row is ...
{"inputs": ["5 6 5\n1 2 2 4 5\n1 3 3 3 3\n3 4 4 1 1\n2 2 2 4 5\n3 1 1 4 4", "2500 2500 8\n1 549 1279 1263 2189\n1 303 795 1888 2432\n1 2227 622 2418 1161\n3 771 2492 1335 1433\n1 2017 2100 2408 2160\n3 48 60 798 729\n1 347 708 1868 792\n3 1940 2080 377 1546", "3 3 5\n3 1 3 1 3\n3 1 1 3 1\n1 2 2 2 2\n3 2 3 2 2\n3 1 1 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4ed5cab6a6a8f2e20270f96bf0b11ab9
You're Given a String...
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Lat...
{"inputs": ["abcd", "ababa", "zzz", "kmmm", "wzznz", "qlzazaaqll", "lzggglgpep", "iegdlraaidefgegiagrdfhihe", "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg", "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw", "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbk...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
4eddd3363623be37a94dbf0b2b374a00
Cowslip Collections
In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has *n* diffe...
{"inputs": ["3 3 2\n4\n6\n9\n8\n6", "4 1 2\n6\n5\n4\n3\n2\n1", "3 3 3\n6\n8\n10\n12\n14\n16", "1 1 1\n1\n1", "10 10 10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10", "7 1 9\n3\n6\n7\n2\n10\n8\n1\n3\n9\n2\n9\n10\n2\n4\n5\n2", "5 1 7\n10\n8\n4\n5\n8\n3\n9\n3\n9\n3\n10\n1", "7 2 8\n2\n5\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
4ee030eb81b88d70cace434a5be31ced
Multipliers
Ayrat has number *n*, represented as it's prime factorization *p**i* of size *m*, i.e. *n*<==<=*p*1·*p*2·...·*p**m*. Ayrat got secret information that that the product of all divisors of *n* taken modulo 109<=+<=7 is the password to the secret data base. Now he wants to calculate this value. The first line of the input...
{"inputs": ["2\n2 3", "3\n2 3 2", "1\n2017", "2\n63997 63997", "5\n11 7 11 7 11", "5\n2 2 2 2 2", "4\n3 3 3 5", "6\n101 103 107 109 101 103", "10\n3 3 3 3 3 3 3 3 3 3", "5\n7 5 2 3 13", "23\n190979 191627 93263 72367 52561 188317 198397 24979 70313 105239 86263 78697 6163 7673 84137 199967 14657 84391 101009 16231 1751...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
4efe90f9fc3fbf649ac705ac3ad803c1
Multitasking
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort *n* arrays simultaneously, each array consisting of *m* integers. Iahub can choose a pair of distinct indices *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*). Then in each array the values at positions *i* and *j* are swapped ...
{"inputs": ["2 5 0\n1 3 2 5 4\n1 4 3 2 5", "3 2 1\n1 2\n2 3\n3 4", "2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591", "2 5 1\n331081 525217 574775 753333 840639\n225591 347017 538639 620341 994088", "1 1 0\n1", "1 1 1\n1", "2 1 0\n1\n2", "1 2 1\n2 1", "2 2 0\n2 1\n3 1", "2 2 0\n2 1\n1 3", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
4f3f1b3886bf8084ebd7c68cecda1017
Ring road
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly tw...
{"inputs": ["3\n1 3 1\n1 2 1\n3 2 1", "3\n1 3 1\n1 2 5\n3 2 1", "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42", "4\n1 2 9\n2 3 8\n3 4 7\n4 1 5", "5\n5 3 89\n2 3 43\n4 2 50\n1 4 69\n1 5 54", "10\n1 8 16\n6 1 80\n6 5 27\n5 7 86\n7 9 72\n4 9 20\n4 3 54\n3 2 57\n10 2 61\n8 10 90", "17\n8 12 43\n13 12 70\n7 13 68\n11 7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
90
codeforces
4f57807abc657d81814ba2545baf08e5
Race
Today *s* kilometer long auto race takes place in Berland. The track is represented by a straight line as long as *s* kilometers. There are *n* cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which...
{"inputs": ["2 33\n2 5 1 2 14\n1 3 11", "2 33\n2 1 3 10 3\n1 11 3", "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5", "2 166755\n2 733 187 362 82\n3 813 147 565 57 557 27", "3 228385\n2 307 733 43 78\n2 252 801 157 169\n3 86 346 133 886 467 173", "4 773663\n9 277 398 57 73 62 736 625 393 186 761 129 716 329...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4f681d465ce8905f9eebe024d288c041
Laser
Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of *n*<=×<=*m* cells and a robotic arm. Each cell of the field is a 1<=×<=1 square. The robotic arm has two l...
{"inputs": ["2\n4 4 1 1 3 3\n4 3 1 1 2 2", "1\n2 2 1 2 2 1", "1\n2 2 1 2 2 1", "1\n3 3 3 2 1 1", "1\n3 4 1 1 1 2", "1\n4 3 3 1 4 1", "1\n3 5 2 4 3 5", "1\n4 5 2 2 4 2", "1\n2 5 1 5 2 2", "1\n2 6 2 6 2 3", "1\n3 6 3 5 2 4", "1\n4 6 2 1 2 3", "1\n5 6 3 4 4 2", "1\n7 3 6 2 5 2", "1\n8 2 6 1 7 2", "1\n9 6 6 5 3 1", "20\n10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
4f6d771773c09a28a6671135a970f49c
Death Stars (easy)
The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Tw...
{"inputs": ["4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX", "2\nXX\nOO\nXO\nOX", "1\nO\nO", "1\nX\nO", "2\nOX\nXX\nOX\nXX", "2\nOX\nXO\nXO\nOX", "2\nOX\nOX\nXX\nOX", "2\nOO\nOO\nOO\nOO", "2\nOX\nOX\nXO\nXO", "10\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOX...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
4f84f706f58aeadbed87aac8b2b1859c
Multiplication Table
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* ...
{"inputs": ["2 2 2", "2 3 4", "1 10 5", "1 1 1", "10 1 7", "10 10 33", "500000 500000 1", "500000 500000 250000000000", "3 3 1", "3 3 2", "3 3 3", "3 3 5", "3 3 8", "3 3 9", "1 500000 74747", "500000 1 47474", "499975 499981 12345", "499997 499989 248758432143", "5 1 2", "2 2 4", "1 2 1", "2 44 36", "2 28 49", "3 48 30...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
4f926e59c7bf0478b3b3f334a6fa879a
Shell Game
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
{"inputs": ["4\n2", "1\n1", "2\n2", "3\n1", "3\n2", "3\n0", "2000000000\n0", "2\n0", "2\n1", "4\n0", "4\n1", "5\n0", "5\n1", "5\n2", "6\n0", "6\n1", "6\n2", "7\n0", "7\n1", "7\n2", "100000\n0", "100000\n1", "100000\n2", "99999\n1", "99998\n1", "99997\n1", "99996\n1", "99995\n1", "1999999995\n0", "1999999995\n1", "19999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
172
codeforces
4f96c364ed54ea97246ce9afac3b7d1b
Closest Equals
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that: - both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l...
{"inputs": ["5 3\n1 1 2 3 2\n1 5\n2 4\n3 5", "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6", "10 6\n2 2 1 5 6 4 9 8 5 4\n1 2\n1 10\n2 10\n2 9\n5 5\n2 8", "1 1\n1\n1 1", "1 3\n1\n1 1\n1 1\n1 1", "2 1\n1 1\n1 2", "2 1\n1 1\n1 1", "2 5\n1 1\n1 1\n1 2\n2 2\n1 2\n1 1", "2 4\n1 2\n1 1\n1 2\n2 2\n1 2"], "outputs": ["1\n-1\n2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
4faaadd1d15296e368288dbc1e242dd8
Coins
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d...
{"inputs": ["10", "4", "3", "2", "5", "6", "7", "1", "8", "12", "100", "1000", "10000", "100000", "1000000", "509149", "572877", "152956", "733035", "313114", "893193", "473273", "537000", "117079", "784653", "627251", "9", "999999", "120", "720", "648", "2430", "119070", "15", "21", "25", "100", "524287", "1000000", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
86
codeforces
4fb8a4af89091c7d09f011d25922a148
Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
{"inputs": ["3 5\nabc\nxaybz", "4 10\nabcd\nebceabazcd", "1 1\na\na", "1 1\na\nz", "3 5\naaa\naaaaa", "3 5\naaa\naabaa", "5 5\ncoder\ncored", "1 1\nz\nz", "1 2\nf\nrt", "1 2\nf\nfg", "1 2\nf\ngf", "2 5\naa\naabaa", "2 5\naa\navaca", "3 5\naaa\nbbbbb", "3 5\naba\ncbcbc", "3 5\naba\nbbbbb", "3 5\naaa\naabvd", "3 5\nvvv\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
4fcfeab57c0f51c448943dcc7cb20eb1
Knights of a Polygonal Table
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo...
{"inputs": ["4 2\n4 5 9 7\n1 2 11 33", "5 1\n1 2 3 4 5\n1 2 3 4 5", "1 0\n2\n3", "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9", "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9", "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "2 0\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
73
codeforces
4fe0252045164e7628be3435258cb5a1
Alice and Bob
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ...
{"inputs": ["2\n2 3", "2\n5 3", "3\n5 6 7", "10\n72 96 24 66 6 18 12 30 60 48", "10\n78 66 6 60 18 84 36 96 72 48", "10\n98 63 42 56 14 77 70 35 84 21", "2\n1 1000000000", "2\n1000000000 999999999", "3\n2 4 6", "2\n4 6", "2\n2 6", "2\n6 2", "10\n100000000 200000000 300000000 400000000 500000000 600000000 700000000 8000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
98
codeforces
4fe552649d99fa72c49afc64c9577426
Lucky Division
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
{"inputs": ["47", "16", "78", "48", "100", "107", "77", "477", "480", "1", "3", "4", "49", "56", "124", "1000", "999", "298", "274", "998", "42", "788", "70", "444", "777", "799", "25", "882", "88", "11", "2", "7", "8", "94", "477", "141"], "outputs": ["YES", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "NO", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
451
codeforces
4ff1d09db6f2d9a2ebec4be3201d5014
Squats
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ethe...
{"inputs": ["4\nxxXx", "2\nXX", "6\nxXXxXx", "4\nxXXX", "2\nXx", "22\nXXxXXxxXxXxXXXXXXXXXxx", "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx", "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX", "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXx...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
177
codeforces
50193bc9e697c53d3b8f630d05729da8
Elections
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ...
{"inputs": ["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "1 3\n5\n3\n2", "3 1\n1 2 3", "3 1\n100 100 100", "2 2\n1 2\n2 1", "2 2\n2 1\n2 1", "2 2\n1 2\n1 2", "3 3\n0 0 0\n1 1 1\n2 2 2", "1 1\n1000000000", "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9", "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
180
codeforces
5027834466ec82df4cc3c1242f683414
none
A tree is a connected undirected graph consisting of *n* vertices and *n*<=<=-<=<=1 edges. Vertices are numbered 1 through *n*. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell...
{"inputs": ["5 3 2", "8 5 2", "8 4 2", "2 1 1", "10 3 3", "15 6 4", "16 15 14", "1000 51 25", "100000 10 7", "3 1 1", "3 2 1", "3 2 2", "4 1 1", "4 2 1", "4 2 2", "4 3 1", "4 3 2", "4 3 3", "8 5 3", "20 19 19", "30 14 14", "33 5 3", "5432 200 100", "5433 200 99", "99999 1 1", "99999 2 1", "99999 7 4", "9999 7 3", "1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
50337a54eefe8cc0b248d33a7c217796
Spelling Check
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
{"inputs": ["abdrakadabra\nabrakadabra", "aa\na", "competition\ncodeforces", "ab\na", "bb\nb", "aab\nab", "aabb\nabb", "babaacaacaa\nbbaacaacaa", "bccaabbcccc\nbccaabcccc", "ababcaabaaa\nabacaabaaa", "cccacaccacb\ncccacaccac", "aaaaaaaaaaa\naaaaaaaaaa", "lcaaxcbcjca\nccaaacccca", "babbbtaamba\nbabbbaabba", "xdfxmcnzpch...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
503aa9522a8ac3af4f5e2355c3273d17
Sereja and Contest
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that *n* people took part in the contest. Let's assume that the participant who got the first place has rating *a*1, the second place participant has rating *a*2, .....
{"inputs": ["5 0\n5 3 4 1 2", "10 -10\n5 5 1 7 5 1 2 4 9 2"], "outputs": ["2\n3\n4", "2\n4\n5\n7\n8\n9"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
50551a5504711861b7c6daf400d98f68
Sleepy Game
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of *n* vertices and *m* edges. One of the vertices contains a chip. Initially the chip is located at vertex *s*. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who c...
{"inputs": ["5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1", "3 2\n1 3\n1 1\n0\n2", "2 2\n1 2\n1 1\n1", "92 69\n1 76\n1 14\n1 9\n0\n1 46\n1 80\n0\n0\n1 77\n0\n1 53\n1 81\n1 61\n1 40\n0\n1 20\n1 71\n1 24\n1 54\n1 82\n1 23\n0\n1 63\n1 25\n1 38\n1 68\n0\n1 65\n0\n1 76\n1 55\n1 87\n1 1\n1 37\n1 68\n1 30\n1 17\n1 19\n0\n1 16\n1 69\n0\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces