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
91615ecf5e80dbea491e2b190588ef2c
none
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr...
{"inputs": ["2\n><\n1 2", "3\n>><\n2 1 1", "1\n>\n1000000000", "1\n<\n1000000000", "2\n>>\n1 1", "5\n>><><\n1 2 3 1 2", "5\n>><><\n1 2 2 1 2", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5", "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1", "3\n><<\n2 1 1", "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
96
codeforces
9168c9068c3cb16956fa2cc4c969c235
none
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains *n* ski junctions, numbered from 1 to *n*. Initially the junctions aren't connected in any way. In the constructing process *m* bidirectional...
{"inputs": ["3 4\n1 3\n2 3\n1 2\n1 2", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 5\n10 6\n11 3\n13 14\n7 10\n3 12\n7 14\n8 11\n7 15\n15 8\n12 7\n4 3\n9 4\n8 10", "34 27\n19 10\n8 31\n26 22\n2 30\n32 26\n30 4\n34 1\n2 31\n4 18\n33 11\n10 13\n20 23\n4 32\n23 27\n30 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
916e1fdc90023043052db3e6738ca240
Chores
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted. Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ...
{"inputs": ["4 2 2\n3 6 7 10", "5 2 1\n100 100 100 100 100", "1 1 1\n100", "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
291
codeforces
9193fd7c419ef9dff9dc9dcd79640cdc
Card Game Again
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck. After re...
{"inputs": ["3 4\n6 2 8", "3 6\n9 1 14", "5 1\n1 3 1 3 1", "5 1\n5 5 5 5 5", "5 1\n5 4 4 4 4", "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100 1\n3 3 2 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
919a173054ff13c4de2e0f84f05b8cbb
The Labyrinth
You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such ...
{"inputs": ["3 3\n*.*\n.*.\n*.*", "4 5\n**..*\n..***\n.*.*.\n*.*.*", "1 1\n*", "1 1\n.", "1 10\n**********", "1 10\n*.***.**.*", "10 1\n*\n*\n*\n*\n*\n.\n*\n.\n*\n*", "10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n."], "outputs": ["3.3\n.5.\n3.3", "46..3\n..732\n.6.4.\n5.4.3", "1", ".", "1111111111", "2.212.22.2", "1\n1\n1\n1\n2\n....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
91b19792c755370d0bb363b9e826e496
Message
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*. String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string *s* and c...
{"inputs": ["aaaaa\naaa", "abcabc\nbcd", "abcdef\nklmnopq", "aaabbbaaa\naba", "a\na", "z\nz", "a\nz", "d\nt", "o\nu", "a\nm", "t\nv", "n\ng", "c\nh", "r\ni", "h\nb", "r\na", "c\np", "wbdbzf\nfpvlerhsuf", "zafsqbsu\nhl", "juhlp\nycqugugk", "ladfasxt\ncpvtd", "ally\ncjidwuj", "rgug\npgqwslo", "wmjwu\nrfew", "cpnwcdqff\nq...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
91c3babe38f68cd3ad2fb4f40f35e2f3
Restoring Table
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ...
{"inputs": ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1", "5\n-1 0 0 0 0\n0 -1 1 0 0\n0 1 -1 0 0\n0 0 0 -1 0\n0 0 0 0 -1", "6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
91c49eb218a529b816dfd941b351be69
Queue
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t...
{"inputs": ["5\n15 2 1 5 3", "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\n13 2 5 55 21 34 1 8 1 3", "10\n8 256 16 1 2 1 64 4 128 32", "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "1\n1000000000", "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "20\n16839799 17525904 91276752 42650694 60106463 12243176 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
158
codeforces
91e81a621aec1c42e9fa4f1997c14bf9
Luck is in Numbers
Vasya has been collecting transport tickets for quite a while now. His collection contains several thousands of tram, trolleybus and bus tickets. Vasya is already fed up with the traditional definition of what a lucky ticket is. Thus, he's looking for new perspectives on that. Besides, Vasya cannot understand why all t...
{"inputs": ["13", "2345", "88", "682444", "685116", "576079", "569631", "662302", "453066", "659821", "26592659", "47699969", "09980988", "69886888", "9588995888", "39930089893999008989", "84163081988476808998", "88898888988889888898", "01273988890029888889", "18858998881886898888", "8259988583", "5898888944", "8558898...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
91f7cff482b2b493374285494a5a7025
Beautiful Sets of Points
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer. Consider all points (*...
{"inputs": ["2 2", "4 3", "21 21", "10 1", "4 4", "1 1", "5 5", "100 100", "96 96", "99 100", "67 58", "67 59", "80 91", "100 11", "16 55", "13 71", "30 40", "77 77", "6 6", "37 42", "88 88", "95 99", "93 70", "4 6", "1 4", "2 10", "6 7", "28 28", "10 6", "85 48", "9 6", "2 6", "6 4", "6 10", "16 5", "7 6", "3 4", "13 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
92033556eb9354fb8e42ff803e338e16
Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others. We define as *b**j* th...
{"inputs": ["4 2\n1 2 3 2", "7 3\n1 3 2 2 2 2 1", "4 4\n1000000000 100 7 1000000000", "1 1\n1", "1 1\n381183829", "2 1\n234089514 461271539", "5 4\n3 1 495987801 522279660 762868488", "10 2\n20515728 1 580955166 856585851 1 738372422 1 2 1 900189620", "20 3\n3 2 2 3 3 3 2 3 3 3 2 748578511 149249674 844954396 321901094...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9220b32c3435f2ebc62e4b87277d09cc
Ciel and Robot
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all: - 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go l...
{"inputs": ["2 2\nRU", "1 2\nRU", "-1 1000000000\nLRRLU", "0 0\nD", "0 0\nUURRDL", "987654321 987654321\nUURRDL", "4 2\nUURRDL", "4 3\nUURRDL", "4 4\nUURRDL", "4 6\nUURRDL", "4 7\nUURRDL", "1000000000 1000000000\nUURRDL", "-1 -1\nUR", "1 1\nUURRDDLL", "987654321 2\nUURDD", "0 123456789\nRRULL", "4 4\nUUUURRRRDDDDLLLL",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
9220f6088bde1e658f48d2c43eca3a2e
Transformation: from A to B
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to he...
{"inputs": ["2 162", "4 42", "100 40021", "1 111111111", "1 1000000000", "999999999 1000000000", "1 2", "1 536870912", "11111 11111111", "59139 946224", "9859 19718", "25987 51974222", "9411 188222222", "25539 510782222", "76259 610072", "92387 184774", "8515 85151111", "91939 9193911", "30518 610361", "46646 373168844...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
275
codeforces
9244db8730fb75772e42e09626cc70a0
Lucky Transformation
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 has a number consisting of *n* digits without leading zeroes. He represented it as an array of...
{"inputs": ["7 4\n4727447", "4 2\n4478", "7 7\n4211147", "7 6\n4747477", "10 2\n9474444474", "10 47\n4214777477", "3 99\n447", "4 1000000000\n7747", "3 1000000000\n447", "3 100\n447", "7 74\n4777774", "10 200\n6860544593", "10 477\n5837934237", "47 7477\n83492039276961836565341994102530448486552156001", "100 0\n9179665...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
924ee6af45d93e3e9e8d31fd75d78f25
Palindromic Supersequence
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ...
{"inputs": ["aba", "ab", "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmkmihmoxqtqlxvlsssisvqvvzotoyqryuyqwoknnqcqggysrqpkrccvyhxsjmhoqoyocwcriplarjoyiqrmmpmueqbsbljddw...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
316
codeforces
925e553c109453d152cad07257492d18
Correct Solution?
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe...
{"inputs": ["3310\n1033", "4\n5", "40\n04", "12\n12", "432\n234", "17109\n01179", "888\n888", "912\n9123", "0\n00", "11110\n1111", "7391\n1397", "201\n102", "111111111\n111111111", "32352320\n22203335", "1000000000\n1", "994321\n123499", "10101\n10101", "666\n0666", "2\n02", "313\n133", "987235645\n234556789", "90812\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
95
codeforces
92637dfd121876c5454d4403888576c8
Flow Control
You have to handle a very complex water distribution system. The system consists of $n$ junctions and $m$ pipes, $i$-th pipe connects junctions $x_i$ and $y_i$. The only thing you can do is adjusting the pipes. You have to choose $m$ integer numbers $f_1$, $f_2$, ..., $f_m$ and use them as pipe settings. $i$-th pipe w...
{"inputs": ["4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1", "1\n0\n0", "1\n123\n0", "2\n-1 1\n1\n1 2", "2\n-1 1\n1\n2 1"], "outputs": ["Possible\n-3\n-6\n1\n0\n0", "Impossible", "Possible", "Impossible", "Possible\n1", "Possible\n-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
92666187f65dafd187e08ecca21dfb68
Servers
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*. It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of se...
{"inputs": ["4 3\n1 3 2\n2 2 1\n3 4 3", "3 2\n3 2 3\n5 1 2", "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8", "4 1\n6 1 1", "1 10\n4 1 1\n9 1 1\n10 1 1\n12 1 1\n13 1 1\n15 1 1\n16 1 1\n18 1 1\n19 1 1\n20 1 1", "4 10\n1 1 1\n3 1 2\n4 1 2\n6 1 2\n8 1 2\n13 1 2\n16 1 1\n17 1 2\n19 3 1\n20 1 1", "100 1\n1000000 100 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
926f692c16a1c9cdb53c696bf20cd7b4
Lucky Common Subsequence
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri...
{"inputs": ["AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "AA\nA\nA", "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCUEPHXM\nRRFCZUGFDRKKMQTOETNELXMEWGOCDHFKIXOPVHHEWTCDNXVFKFKTKNWKEIKTCMHMHDNCLLVQSGKHBCDDYVVVQIRPZEOPUGQUGRHH\nR", "CGPWTAPEVBTGANLC...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
92860c2d54613a5f2fb815cb46e37e60
Shooshuns and Sequence
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current ...
{"inputs": ["3 2\n3 1 1", "3 1\n3 1 1", "1 1\n1", "2 1\n1 1", "2 1\n2 1", "4 4\n1 2 3 4", "4 3\n1 2 3 4", "5 3\n2 1 1 1 1", "5 3\n1 1 1 1 1", "5 5\n1 1 1 1 1", "10 1\n1 1 1 1 1 1 1 1 1 1", "10 1\n1 2 1 1 1 1 1 1 1 1", "10 1\n2 1 1 1 1 1 1 1 1 1", "10 2\n2 1 1 1 1 1 1 1 1 1", "10 2\n1 2 1 1 1 1 1 1 1 1", "10 3\n3 2 1 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
134
codeforces
929c86cf60c47745d6a36689f25fc604
Digital Root
Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x...
{"inputs": ["4", "5", "6", "7", "1", "8", "10", "15", "16", "20", "50", "100", "127", "202", "333", "404", "411", "571", "600", "771", "10000", "20000", "30000", "50000", "99999", "200000", "400000", "600000", "800000", "1000000", "828282", "729761", "653451", "987572", "167590", "358712", "498138", "983242", "312433",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
92ccbd5c5653fc913a6ad45681e3a8df
String Mark
At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*. Recently at the BSU was an important test work on which Vasya recived the mark *a*. It is very hard for the teacher to remember the exact mark of every stud...
{"inputs": ["abc\nddd", "abcdef\nabcdeg", "abacaba\nubuduba", "aac\nbbb", "aaaccc\nbbbbbb", "aaaaaa\nzzzzzz", "abcde\nzzzzz", "a\nc", "aaa\nccc", "abacabadaba\ndabacabaaba", "ujfawuezgiy\nvuqvvsivvwe", "jvmzmvqexcqycjcpuqimvyovcffrdwtexpqhxswzytoaokvnexkzgycpmbgvsnyifkwvfbirtwnprmrlotlnhkogjlmxmgruklcuqstwfwoswux\nvzsm...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
92e4245cc1e7a150805ac581d4a69a8b
Producing Snow
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every ...
{"inputs": ["3\n10 10 5\n5 7 2", "5\n30 25 20 15 10\n9 10 12 4 13", "4\n0 0 0 0\n1 2 3 4", "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "10\n20 35 4 0 6 29 4 9 17 10\n0 9 4 7 5 1 4 3 9 4", "1\n4\n5", "1\n5\n4", "1\n5\n5", "2\n9 3\n8 2", "2\n9 3\n4 4", "2\n9 3\n10 2", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
92e6dae987b75873174241e50e0bd7e4
Beautiful Matrix
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
{"inputs": ["0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "1 0 0 0 0\n0 0 0 0 0\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
832
codeforces
93036ead36690dea9ad6cf7ba98801a7
Hit the Lottery
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? The f...
{"inputs": ["125", "43", "1000000000", "4", "5", "1", "74", "31", "59", "79", "7", "55", "40", "719", "847", "225", "4704", "1132", "7811", "7981", "82655", "6364", "74611", "45391", "620448", "265145", "671704", "365173", "7130872", "9628747", "8898399", "9497953", "19070947", "20185520", "91402248", "27035533", "2271...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
853
codeforces
9309776dd3ce513a2e83a90222c7ae3d
Anthem of Berland
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible. H...
{"inputs": ["winlose???winl???w??\nwin", "glo?yto?e??an?\nor", "??c?????\nabcab", "ddddd\nd", "ww?ww\nw", "?????\nn", "xznxr\nxznxr", "wnfbhg?dkhdbh?hdmfjkcunzbh?hdbjjrbh?hddmh?zubhgh?qbjbhghdpwr?bhghdfjnjf?qbhghdqq?qebhgh?umvbhghdivvj\nbhghd", "emnd?t??m?gd?t?p?s??m?dp??t???m?????m?d?ydo????????i??u?d??dp??h??d?tdp???...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
931258d7701c6fe0dd407a74d1675d06
Twins
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
{"inputs": ["2\n3 3", "3\n2 1 2", "1\n5", "5\n4 2 2 2 2", "7\n1 10 1 2 1 1 1", "5\n3 2 3 3 1", "2\n2 1", "3\n2 1 3", "6\n1 1 1 1 1 1", "7\n10 10 5 5 5 5 1", "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
600
codeforces
93133b96b5b3070a160ab0df19ac93d9
Minesweeper 1D
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is *n* squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares. For example, the correct field to play look...
{"inputs": ["?01???", "?", "**12", "1", "?01*??****", "0", "2", "*", "0*", "0?", "01", "1*", "1?", "?1?", "12", "2*", "2?", "2??", "?2?", "?2*?2*??1*2**?2*1???*2???100?????*???*?*????0????2?*?*?1??1??*?01**2**1001??**??**??1*?*???00??**??*", "00***???01", "21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
932312c3309f5b145d6fe3168330ff4b
Buses Between Cities
Buses run between the cities *A* and *B*, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city *A* departs every *a* minutes and arrives to the city *B* in a *t**a* minutes, and a bus from the city *B* departs every *b* minutes and arrives to the city *A* in a *t**b* min...
{"inputs": ["10 30\n10 35\n05:20", "60 120\n24 100\n13:00", "30 60\n60 60\n22:30", "30 60\n10 60\n23:30", "5 45\n4 60\n21:00", "1 1\n1 1\n10:28", "4 1\n5 4\n18:40", "8 8\n1 1\n13:24", "20 4\n1 20\n06:20", "15 24\n23 6\n21:15", "30 19\n21 4\n10:30", "31 15\n36 25\n07:04", "24 3\n54 9\n18:12", "18 69\n62 54\n08:00", "33 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
933534e531757a47f23e4d8f9ec7fa10
Hexagons
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: Ayrat is searching through the field. He started at point (0,<=0) and is ...
{"inputs": ["3", "7", "39", "14", "94", "60", "60", "59", "181994", "486639", "34514", "826594", "1000000000000000000", "854460", "164960", "618459", "496181994", "1000000000", "228939226", "973034514", "984826594", "19164960", "249781780", "851838979", "978618459", "871854460", "302486639", "0", "1", "2", "3", "4", "5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
934ea466a846bb3ce21dc7df2779105b
The Festive Evening
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom...
{"inputs": ["5 1\nAABBB", "5 1\nABABB", "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA", "5 2\nABACA", "6 2\nABCABC", "8 3\nABCBCDCA", "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD", "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA", "41 19\nTMEYYIIELFDCMBD...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
115
codeforces
9360f296a2c7948139a477124eb2a1da
Caisa and Pylons
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is ...
{"inputs": ["5\n3 4 3 2 4", "3\n4 4 4", "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 340...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
361
codeforces
93611e04f3cfd79e75355cf9c18f8e2d
LRU
While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used). Suppose the cache may store no more than *k* objects. At the beginning of the workflow the cache is empty. When some object is querie...
{"inputs": ["3 1\n0.3 0.2 0.5", "2 1\n0.0 1.0", "3 2\n0.3 0.2 0.5", "3 3\n0.2 0.3 0.5", "1 1\n1.0", "10 1\n0.12 0.14 0.13 0.08 0.15 0.10 0.15 0.04 0.02 0.07", "10 5\n0.02 0.17 0.04 0.07 0.21 0.06 0.09 0.11 0.17 0.06", "10 10\n0.02 0.03 0.12 0.21 0.07 0.15 0.21 0.14 0.01 0.04", "20 10\n0.07 0.03 0.02 0.02 0.09 0.07 0.07...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9361fef31b3894cff7eb733b7f116acf
Quadcopter Competition
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w...
{"inputs": ["1 5\n5 2", "0 1\n0 0", "-100 -100\n100 100", "-100 -100\n-100 100", "-100 -100\n100 -100", "100 -100\n-100 -100", "100 -100\n-100 100", "100 -100\n100 100", "-100 100\n-100 -100", "-100 100\n100 -100", "-100 100\n100 100", "100 100\n-100 -100", "100 100\n-100 100", "100 100\n100 -100", "45 -43\n45 -44", "7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
124
codeforces
93962dd461fd0469c9158c0a4409dddc
Vasya and Digital Root
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<...
{"inputs": ["4 4", "5 1", "1 0", "8 7", "487 0", "1000 5", "22 9", "1 1", "1 9", "13 5", "100 4", "123 6", "1000 1", "2 0", "734 9", "678 8", "955 7", "893 3", "998 2", "960 6"], "outputs": ["5881", "36172", "0", "49722154", "No solution", "8541939554067890866522280268745476436249986028349767396372181155840878549622667...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
93a967c27d1e68ac71fb2f506e4822a5
Books
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to...
{"inputs": ["4 5\n3 1 2 1", "3 3\n2 2 3", "1 3\n5", "1 10\n4", "2 10\n6 4", "6 10\n2 3 4 2 1 1", "7 13\n6 8 14 9 4 11 10", "10 15\n10 9 1 1 5 10 5 3 7 2", "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4", "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19", "100 100\n75 92 18 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
308
codeforces
93aa6c82a42a61f509b47c9cafa68e5b
Ann and Half-Palindrome
Tomorrow Ann takes the hardest exam of programming where she should get an excellent mark. On the last theoretical class the teacher introduced the notion of a half-palindrome. String *t* is a half-palindrome, if for all the odd positions *i* () the following condition is held: *t**i*<==<=*t*|*t*|<=-<=*i*<=+<=1, wh...
{"inputs": ["abbabaab\n7", "aaaaa\n10", "bbaabb\n13", "a\n1", "b\n1", "ababbbbbbbaaaaaaaabbbbbb\n23", "aa\n3", "aa\n1", "aa\n2", "ab\n1", "ab\n2", "aaa\n1", "aaa\n2", "aaa\n3", "aaa\n4", "aaa\n5", "aaa\n6", "abb\n1", "abb\n2", "abb\n3", "abb\n4", "aba\n4", "aba\n3", "aba\n2", "aba\n1"], "outputs": ["abaa", "aaa", "bbaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
93e73b0ba3ef401390253ad421d7995a
Progress Bar
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* fr...
{"inputs": ["10 10 54", "11 13 37", "9 25 50", "43 47 77", "20 1 43", "17 4 61", "10 16 0", "17 13 100", "11 9 1", "9 11 99", "6 17 1", "6 17 99", "17 6 1", "17 6 99", "99 1 1", "99 1 99", "1 1 0", "1 1 37", "1 1 50", "1 1 51", "1 1 99", "1 1 100", "1 17 35", "1 31 88", "1 100 0", "1 100 38", "1 100 99", "1 100 100", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
93ed3cd729c322a66d7fe44bf787cab4
No to Palindromes!
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to...
{"inputs": ["3 3\ncba", "3 4\ncba", "4 4\nabcd", "2 2\nab", "2 2\nba", "1 2\na", "1 2\nb", "1 1\na", "3 4\ncdb", "7 26\nzyxzyxz", "10 5\nabcabcabca", "10 10\nfajegfaicb", "1 26\no", "1 2\nb", "1 26\nz", "3 3\ncab", "3 26\nyzx", "5 5\naceba", "10 3\ncbacbacbac", "11 3\nabcabcabcab", "12 10\nabcabcabcabc", "13 7\ngfegfeg...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
93f371930641819822b183ffc5533b6f
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
{"inputs": ["9\n8 6 4 2 1 4 7 10 2", "9\n-1 6 -1 2 -1 4 7 -1 2", "5\n-1 -1 -1 -1 -1", "7\n-1 -1 4 5 1 2 3", "1\n1", "1\n65", "1\n1000000000", "1\n-1", "2\n1000000000 1000000000", "2\n1000000000 -1", "2\n-1 1000000000", "2\n-1 -1", "3\n999999999 1000000000 -1", "3\n999999999 -1 1000000000", "3\n1000000000 999999999 1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9423c1bacb4232559c8da48975cfd38d
none
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors *x* and *y* of size *n* is the sum of the products of the corresponding components of the vectors. The unusual square of an *n*<=×<=*n* square ...
{"inputs": ["3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3", "1\n1\n9\n1 1\n3\n1 1\n1 1\n3\n1 1\n3\n1 1\n3", "3\n1 0 1\n0 1 1\n1 0 1\n4\n3\n3\n3\n3", "1\n0\n5\n1 1\n3\n1 1\n1 1\n3", "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3", "2\n0 1\n1 0\n7\n3\n3\n2 2\n3\n2 2\n2 1\n3", "5\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
942dda7f65cceb57b7d6d092f3bb32d3
Castle Defense
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into *n* sections. At this moment there are exactly *a**i* archers located ...
{"inputs": ["5 0 6\n5 4 3 4 9", "4 2 0\n1 2 3 4", "5 1 1\n2 1 2 1 2", "1 0 0\n0", "1 0 1000000000000000000\n1000000000", "1 1 10\n23", "2 0 100\n98 2", "3 1 1000\n0 0 0", "100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
942ec18dc47325413b71a977730c10fe
Very Interesting Game
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string *s*1, consisting of exactly nine digits and representing a number that does not exceed *a*. After that second player looks at *s*1 and writes a string *s*2, consisting of exactly nine digits and re...
{"inputs": ["1 10 7", "4 0 9", "10 7 8", "6 4 10", "4 1 4", "4 7 9", "13 4 51", "0 0 1", "1 0 1", "2 1 3", "0 2 2", "2 3 1", "3 0 3", "1 1 2", "3 2 1", "0 3 3", "4 0 13", "1 2 13", "4 3 12", "1 2 11", "4 3 12", "815 216 182", "218 550 593", "116482865 344094604 3271060", "19749161 751031022 646204", "70499104 10483793 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
947a2b4f73b2035009e5a5f2fe0b5929
Counting Rhombi
You have two positive integers *w* and *h*. Your task is to count the number of rhombi which have the following properties: - Have positive area. - With vertices at integer points. - All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0,<=0), (*w*,<=0), (*w*,<=*...
{"inputs": ["2 2", "1 2", "1 4000", "4000 1", "4000 4000", "15 10", "7 9", "17 17", "7 13", "9 14", "3 10", "14 2", "4 6", "18 2858", "14 1274", "25 2986", "13 1402", "2955 21", "1665 27", "3671 19", "2541 25", "1913 3980", "3727 2044", "2437 460", "1499 2172", "1 1"], "outputs": ["1", "0", "0", "0", "16000000000000", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
94c0b5d0cd3a264fb19232cc2aa4236a
Chemistry in Berland
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunately, chemical laws allow material transformations (yes, chemistry i...
{"inputs": ["3\n1 2 3\n3 2 1\n1 1\n1 1", "3\n3 2 1\n1 2 3\n1 1\n1 2", "5\n2 1 1 2 3\n1 2 2 2 1\n1 2\n1 3\n2 4\n1 4", "10\n2 8 6 1 2 7 6 9 2 8\n4 9 4 3 5 2 9 3 7 3\n1 8\n2 8\n3 8\n4 10\n5 1\n6 4\n7 3\n8 10\n9 2", "5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
94f22c184db967f634f47abb84439aea
Dima and Trap Graph
Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal... Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate inter...
{"inputs": ["4 4\n1 2 1 10\n2 4 3 5\n1 3 1 5\n2 4 2 7", "5 6\n1 2 1 10\n2 5 11 20\n1 4 2 5\n1 3 10 11\n3 4 12 10000\n4 5 6 6", "6 6\n1 2 1 10\n2 3 1 10\n3 6 1 1\n1 4 1 4\n4 5 1 3\n5 6 1 3", "2 1\n1 2 1 1", "10 0", "5 5\n1 5 9403 40347\n1 3 13851 29314\n4 5 1315 561894\n3 5 2748 33090\n5 3 10717 32306", "1000 0"], "outp...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
94f5f504815e2f4db2c2158e710bb9ad
TV Game
There is a new TV game on BerTV. In this game two players get a number *A* consisting of 2*n* digits. Before each turn players determine who will make the next move. Each player should make exactly *n* moves. On it's turn *i*-th player takes the leftmost digit of *A* and appends it to his or her number *S**i*. After th...
{"inputs": ["2\n1234", "2\n9911", "2\n0153", "3\n614615", "4\n21305374", "4\n00013213", "1\n01", "1\n21", "1\n99", "18\n999999999999999999999999999999999999", "10\n89959999998998796989", "10\n99999988899989998889", "7\n10210320200120", "18\n949787136121830145537930861689777414", "18\n95685957978983485816721877889379638...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
950b70b0c59e455e4a9d58b8858b308d
Plant
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
{"inputs": ["1", "2", "385599124", "989464295", "376367012", "529357306", "782916801", "74859961358140080", "0", "252509053898415171", "760713016078377938", "919845424847912644", "585335721566249104", "522842183413115087", "148049062285906746", "84324827171274022", "354979172034763159", "1312148742261680", "26958744805...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
950cdd5d07ef7b2fb94d84bbff05380a
Vanya and Books
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels th...
{"inputs": ["13", "4", "100", "99", "1000000000", "1000000", "999", "55", "222222222", "8", "13", "313", "1342", "30140", "290092", "2156660", "96482216", "943006819", "1", "7", "35", "996", "6120", "30660", "349463", "8171970", "36123011", "986747865", "9", "10", "11", "101", "1000", "1001", "9999", "10000", "10001", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
290
codeforces
950ec6b7587c04fab5f98f9b0f6f7140
Dima and Magic Guitar
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with *n* strings and *m* frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the *i*-th string holding it on the *j*...
{"inputs": ["4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1", "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5", "5 5 2 2\n2 2 2 1 2\n2 1 2 2 2\n2 2 2 2 2\n1 2 2 2 2\n2 2 2 2 1\n1 1", "5 5 2 2\n2 1 2 2 2\n2 2 2 2 2\n2 2 2 2 1\n2 2 2 2 2\n1 2 2 2 2\n1 1", "11 11 9 11\n1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9512d95f55e6714b775f910ab872b25d
Special Matrices
An *n*<=×<=*n* square matrix is special, if: - it is binary, that is, each cell contains either a 0, or a 1; - the number of ones in each row and column equals 2. You are given *n* and the first *m* rows of the matrix. Print the number of special *n*<=×<=*n* matrices, such that the first *m* rows coincide with the ...
{"inputs": ["3 1 1000\n011", "4 4 100500\n0110\n1010\n0101\n1001", "2 0 1000", "2 1 1000\n11", "5 0 13", "5 3 19\n10001\n10001\n00110", "3 0 100500", "4 0 100500", "5 0 100500", "6 0 100500", "3 1 100501\n101", "4 2 100501\n1010\n1010", "5 2 100501\n10010\n10100", "6 4 100501\n100010\n100100\n010100\n000011", "7 4 1005...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
95134230a7f87d3bd4d0603bfbe2719c
Anton and Digits
Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each...
{"inputs": ["5 1 3 4", "1 1 1 1", "10 2 1 5", "4 2 7 2", "489 292 127 263", "9557 5242 1190 7734", "1480320 1969946 1158387 3940412", "0 0 0 0", "5000000 5000000 5000000 5000000", "1048576 256 1048576 1048576", "2073144 2073145 0 0", "1000000 0 0 1", "2 1 1 1", "0 5000000 5000000 5000000", "4494839 1140434 3336818 4921...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
9514456a8a09980d6d495a6a8edf495c
Polo the Penguin and Strings
Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo...
{"inputs": ["7 4", "4 7", "10 5", "47 2", "10 7", "20 7", "26 26", "47 1", "128 26", "999 7", "4585 1", "6875 2", "7642 3", "100000 7", "68754 25", "1000000 1", "999999 2", "1000000 26", "100000 20", "579466 17", "679854 9", "978458 16", "6791 21", "6795 1", "12 17", "1 1", "2 2", "1 2", "1 26", "26 2", "123 21", "3 3"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
952b7e7743211fb31c5c2332e800bc25
Hamming Distance
Hamming distance between strings *a* and *b* of equal length (denoted by *h*(*a*,<=*b*)) is equal to the number of distinct integers *i* (1<=≤<=*i*<=≤<=|*a*|), such that *a**i*<=≠<=*b**i*, where *a**i* is the *i*-th symbol of string *a*, *b**i* is the *i*-th symbol of string *b*. For example, the Hamming distance betwe...
{"inputs": ["4 4 4\n4 4\n4", "10 10 8\n8 8\n10", "50109 50255 50102\n50104 50011\n50085", "99999 99998 99997\n99996 99995\n99994", "6 6 6\n6 6\n6", "1 1 1\n1 1\n1", "2 2 2\n2 2\n2", "2 1 2\n2 2\n2", "5 6 6\n6 5\n5", "5 3 5\n6 4\n2", "46 53 56\n59 52\n45", "544 474 496\n506 492\n484", "3 6 4\n3 5\n6", "52 57 55\n45 51\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9586d45106030df74f42ad1e662f9280
Watching a movie
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie...
{"inputs": ["2 3\n5 6\n10 12", "1 1\n1 100000", "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
136
codeforces
95cec444d35ca774eda9fe6cb6c283db
none
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train route...
{"inputs": ["5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000", "3 2 5\n1 2 2\n2 3 4\n3 5\n3 5\n3 5\n3 6\n3 7", "5 5 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9609f8411c1b825c8ad1f6fba66ebebb
File Name
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
{"inputs": ["6\nxxxiii", "5\nxxoxx", "10\nxxxxxxxxxx", "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "3\nxxx", "77\naaabbbcccdddeeefffggghhhiiijjjkkkl...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
325
codeforces
961446004eb9d83762673abfd2c4b1e8
Vasya's Calendar
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n...
{"inputs": ["4\n2\n2 2", "5\n3\n3 4 3", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "1\n1\n1", "1\n2\n1 1", "2\n2\n1 1", "10\n2\n10 2", "10\n3\n6 3 6", "10\n4\n8 7 1 5", "10\n5\n2 7 8 4 4", "10\n6\n8 3 4 9 6 1", "10\n7\n10 5 3 1 1 9 1", "10\n8\n6 5 10 6 8 1 3 2", "10\n9\n6 2 7 5 5 4 8 6 2", "10\n10\n1 10 1 10 1 1 7 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
167
codeforces
9627272d7a247485f14cbdc34d6bfddf
Insertion Sort
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array *a* of size *n* in the non-d...
{"inputs": ["5\n4 0 3 1 2", "5\n1 2 3 4 0", "5\n1 3 4 0 2", "10\n9 8 7 6 5 4 3 2 1 0", "5\n0 4 1 3 2", "6\n3 0 1 4 5 2", "3\n0 2 1", "3\n1 0 2", "3\n1 2 0", "3\n2 0 1", "3\n2 1 0", "7\n4 0 3 5 1 2 6", "8\n1 5 4 0 2 7 3 6", "9\n1 5 6 3 0 7 2 8 4", "10\n8 6 7 9 4 5 2 3 1 0", "11\n4 9 1 2 8 5 10 3 0 7 6", "12\n2 7 0 1 3 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
962cab700bb813622b48938f5c54d8b8
Little Pony and Sort by Shift
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
{"inputs": ["2\n2 1", "3\n1 3 2", "2\n1 2", "6\n3 4 5 6 3 2", "3\n1 2 1", "5\n1 1 2 1 1", "4\n5 4 5 4", "7\n3 4 5 5 5 1 2", "5\n2 2 1 2 2", "5\n5 4 1 2 3", "4\n6 1 2 7", "5\n4 5 6 2 3", "2\n1 1", "4\n1 2 2 1", "9\n4 5 6 7 1 2 3 4 10", "7\n2 3 4 1 2 3 4", "6\n1 2 1 2 1 2", "3\n3 2 1", "4\n1 4 4 1", "5\n1 2 1 1 1", "5\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
963d940c5ad407f2d78a56605af11390
s-palindrome
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. You are given a string *s*. Check if the ...
{"inputs": ["oXoxoXo", "bod", "ER", "o", "a", "opo", "HCMoxkgbNb", "vMhhXCMWDe", "iIcamjTRFH", "WvoWvvWovW", "WXxAdbAxXW", "vqMTUUTMpv", "iii", "AAWW", "ss", "i", "ii", "mm", "LJ", "m", "ioi", "OA", "aaaiaaa", "SS", "iiii", "ssops", "ssss", "ll", "s", "bb", "uu", "ZoZ", "mom", "uou", "u", "JL", "mOm", "llll", "ouo", "a...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
969194bd9a4c52b927170f6878291c44
Alyona and a tree
Alyona has a tree with *n* vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex *i* she wrote *a**i*. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define *dist*(*v*,<=*u*) as the ...
{"inputs": ["5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6", "5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1", "1\n1", "2\n1 1\n1 1", "10\n40 77 65 14 86 16 2 51 62 79\n1 75\n10 86\n3 52\n6 51\n10 8\n3 61\n3 53\n5 98\n2 7", "10\n52 1 84 16 59 26 56 74 52 97\n5 7\n7 13\n3 98\n7 22\n7 19\n9 54\n4 45\n10 95\n1 94", "10\n68 29 12 14 27 47 95 100 45 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
9699caf9749110b5eef0cc68b28787b8
Phone Numbers
Winters are just damn freezing cold in Nvodsk! That's why a group of *n* friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size *s**i* (that's the number of phone numbers). We know that tax...
{"inputs": ["4\n2 Fedorov\n22-22-22\n98-76-54\n3 Melnikov\n75-19-09\n23-45-67\n99-99-98\n7 Rogulenko\n22-22-22\n11-11-11\n33-33-33\n44-44-44\n55-55-55\n66-66-66\n95-43-21\n3 Kaluzhin\n11-11-11\n99-99-99\n98-65-32", "3\n5 Gleb\n66-66-66\n55-55-55\n01-01-01\n65-43-21\n12-34-56\n3 Serega\n55-55-55\n87-65-43\n65-55-21\n5 M...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
969d32200550fa6d7a135e41aecf0436
A Shade of Moonlight
"To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino. "See? The clouds are coming." Kanno gazes into the distance. "That can't be better," Mino turns to Kanno. The sky can be seen as a one-dimensional axis. The moon is at the origin whose ...
{"inputs": ["5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1", "4 10 1\n-20 1\n-10 -1\n0 1\n10 -1", "1 100000000 98765432\n73740702 1", "10 2 3\n-1 -1\n-4 1\n-6 -1\n1 1\n10 -1\n-8 -1\n6 1\n8 1\n4 -1\n-10 -1", "3 100000000 100000000\n-100000000 1\n100000000 1\n0 -1", "9 25000000 989\n-100000000 -1\n-75000000 1\n75000000 1\n50000000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
96bbc0ea662787e4b8d5f40b8789dc18
Big Number and Remainder
Stepan has a very big positive integer. Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203...
{"inputs": ["521\n3", "1001\n5", "5678901234567890123456789\n10000", "552352155\n13", "11533077525260\n193983", "15\n19", "2342341\n2342340", "12345\n12344", "23457\n23456", "79\n60847671", "456\n79575973", "1908\n86567928", "30866\n55357692", "980552\n32506042", "4865180\n11799246", "63014535\n5261418", "260597722\n10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
96cafaf521d87be7591992062831ec4a
Fibonacci String Subsequences
You are given a binary string *s* (each character of this string is either 0 or 1). Let's denote the cost of string *t* as the number of occurences of *s* in *t*. For example, if *s* is 11 and *t* is 111011, then the cost of *t* is 3. Let's also denote the Fibonacci strings sequence as follows: - *F*(0) is 0;- *F*(...
{"inputs": ["2 4\n11", "10 100\n1010101010", "10 5\n0110111100", "100 100\n0001010101110010010100111011010101101111110001101101010111011101010000111000110001111010001001000001", "50 50\n00011100010110111111011100101010000001101001001001", "100 50\n011011001111111001000000010101011001100101110000001011010011000000011100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
9710337c757d2ca9a64081eb24308f7e
Collisions
On a number line there are *n* balls. At time moment 0 for each ball the following data is known: its coordinate *x**i*, speed *v**i* (possibly, negative) and weight *m**i*. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing *m*1 and *m*2 and with speeds *v*1 and *v*2 col...
{"inputs": ["2 9\n3 4 5\n0 7 8", "3 10\n1 2 3\n4 -5 6\n7 -8 9", "6 76\n-35 -79 86\n-76 -20 64\n-91 79 10\n12 25 51\n62 6 30\n8 -14 65", "5 69\n-34 28 72\n54 59 51\n65 42 95\n75 1 59\n99 76 54", "5 65\n58 73 74\n98 85 95\n92 94 96\n66 100 79\n44 80 95", "5 10\n-98 -98 1\n-100 -100 1\n-99 -100 2\n-97 -100 1\n-95 -100 1",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
9745559fd17c5609447524b4da506f1e
History
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the Wo...
{"inputs": ["5\n1 10\n2 9\n3 8\n4 7\n5 6", "5\n1 100\n2 50\n51 99\n52 98\n10 60", "1\n1 1000000000", "2\n100 1000\n500 1500", "4\n1 100\n50 150\n120 200\n180 220", "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11", "4\n1 5\n2 4\n10 15\n11 14", "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
9769c0ef0e25d8db168cae2e27ac7268
Visiting a Friend
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos...
{"inputs": ["3 5\n0 2\n2 4\n3 5", "3 7\n0 4\n2 5\n6 7", "1 1\n0 0", "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10", "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
144
codeforces
9799386063eac39226d7076d5e2ace6a
Chicken or Fish?
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat *m*, that means, he will be the *m*-th person to get food. The flight menu has *k* dishe...
{"inputs": ["2\n\n3 4\n2 3 2 1\n1 0\n0 0\n\n5 5\n1 2 1 3 1\n3 0\n0 0\n2 1\n4 0", "4\n\n2 1\n42\n0 0\n\n2 1\n2\n0 0\n\n2 1\n42\n1 0\n\n2 1\n2\n1 0", "5\n\n3 3\n1 1 1\n0 0\n0 1\n\n3 3\n1 1 1\n1 0\n2 1\n\n3 3\n1 1 1\n1 0\n0 1\n\n3 3\n1 1 1\n0 0\n1 0\n\n3 3\n1 1 1\n0 0\n1 1", "1\n\n4 2\n2 2\n0 0\n0 0\n1 1"], "outputs": ["Y...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
97b0be7ad7045d8184a85d460fdf44f0
The Game Of Parity
There are *n* cities in Westeros. The *i*-th city is inhabited by *a**i* people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly *k* cities l...
{"inputs": ["3 1\n1 2 1", "3 1\n2 2 1", "6 3\n5 20 12 7 14 101", "6 3\n346 118 330 1403 5244 480", "7 4\n11 3532 99 3512 12 8 22", "9 4\n2 6 8 1 2 4 2 8 2", "8 2\n1 3 22 45 21 132 78 901", "1 1\n912959", "1 1\n107540", "2 2\n67427 727097", "2 2\n346010 923112", "2 2\n125572 610583", "3 3\n198331 216610 697947", "3 3\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
97e64e857002b4868d4b906fbfc1c164
Kirill And The Game
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers ...
{"inputs": ["1 10 1 10 1", "1 5 6 10 1", "1 1 1 1 1", "1 1 1 1 2", "1 100000 1 100000 100000", "1 100000 1 100000 100001", "25 10000 200 10000 5", "1 100000 10 100000 50000", "91939 94921 10197 89487 1", "30518 58228 74071 77671 1", "46646 79126 78816 91164 5", "30070 83417 92074 99337 2", "13494 17544 96820 99660 6", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
9801dff0e17270152bbd2e68913fa259
Parallelogram is Back
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis...
{"inputs": ["0 0\n1 0\n0 1", "0 -1\n-1 0\n1 1", "-1 -1\n0 1\n1 1", "1000 1000\n-1000 -1000\n-1000 1000", "-1000 1000\n1000 -1000\n-1000 -1000", "-4 -5\n7 10\n3 -10", "-86 25\n-55 18\n58 24", "-301 -397\n192 317\n-98 729", "1000 1000\n999 1000\n-1000 -1000", "-1000 0\n999 0\n1000 1", "-1000 1000\n1000 -1000\n0 1", "1000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
9819394579ff3ea1f184690cb479a47b
Getting an A
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
{"inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5", "1\n5", "4\n3 2 5 4", "5\n5 4 3 2 5", "8\n5 4 2 5 5 2 5 5", "5\n5 5 2 5 5", "6\n5 5 5 5 5 2", "6\n2 2 2 2 2 2", "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
224
codeforces
9819cf7a2ee1577fa2b11b9f03e019a4
Fire
Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take *t**i* seconds to save *i*-th item. In addition, for each item, he estimated the value of *d**i* — the moment after which the item *i* will be completely burned and will no long...
{"inputs": ["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5", "9\n13 18 14\n8 59 20\n9 51 2\n18 32 15\n1 70 18\n14 81 14\n10 88 16\n18 52 3\n1 50 6", "5\n12 44 17\n10 12 11\n16 46 5\n17 55 5\n6 60 2", "6\n18 85 3\n16 91 20\n12 92 11\n20 86 20\n15 43 4\n16 88 7", "2\n12 13 2\n1 9 3", "3\n14 42 16\n13 40 1\n17 33 5", "4\n5 6 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
98290b55151aee048bb03b44cf19df7d
Polyline
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p...
{"inputs": ["1 -1\n1 1\n1 2", "-1 -1\n-1 3\n4 3", "1 1\n2 3\n3 2", "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000", "-510073119 -991063686\n583272581 -991063686\n623462417 -991063686", "-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611", "127447697 -311048187\n-644646254 13509...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
982db9310bb856cf377fea26d0673d07
Bear and Game
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
{"inputs": ["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90", "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
251
codeforces
98428c5ad10009f3b2425646949f8bd0
Army
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is...
{"inputs": ["3\n5 6\n1 2", "3\n5 6\n1 3", "2\n55\n1 2", "3\n85 78\n1 3", "4\n63 4 49\n2 3", "5\n93 83 42 56\n2 5", "6\n22 9 87 89 57\n1 6", "7\n52 36 31 23 74 78\n2 7", "8\n82 14 24 5 91 49 94\n3 8", "9\n12 40 69 39 59 21 59 5\n4 6", "10\n95 81 32 59 71 30 50 61 100\n1 6", "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
511
codeforces
988518cdbf5addd85b86b7c5d7c38a55
Police Recruits
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
{"inputs": ["3\n-1 -1 1", "8\n1 -1 1 -1 -1 1 1 1", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "7\n-1 -1 1 1 -1 -1 1", "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5", "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
729
codeforces
98ff04c41ab2c760488c41a7659953ac
Balloons
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi...
{"inputs": ["3\n1 2 1", "2\n5 5", "1\n10", "1\n1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 1 1 1 1 9", "10\n26 723 970 13 422 968 875 329 234 983", "3\n3 2 1", "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "10\n1 9 7 6 2 4 7 8 1 3", "2\n9 6", "2\n89 7", "2\n101 807", "5\n8 7 4 8 3", "5\n55 62 70 100 90", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
128
codeforces
99180e3f5c7972631604d2137406cd36
Where do I Turn?
Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight...
{"inputs": ["0 0\n0 1\n1 1", "-1 -1\n-3 -3\n-4 -4", "-4 -6\n-3 -7\n-2 -6", "-44 57\n-118 -41\n-216 33", "39 100\n90 85\n105 136", "71 43\n96 -15\n171 -189", "-22 -84\n-117 8\n-25 103", "28 -81\n49 -85\n45 -106", "-20 -60\n-39 -45\n-24 -26", "-61 -24\n-61 35\n-120 35", "-19 27\n-115 -63\n-25 -159", "53 69\n147 114\n102 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
992794c9fddefcc7b1bcf7a5d6bb48ef
Substitutes in Number
Andrew and Eugene are playing a game. Initially, Andrew has string *s*, consisting of digits. Eugene sends Andrew multiple queries of type "*d**i*<=→<=*t**i*", that means "replace all digits *d**i* in string *s* with substrings equal to *t**i*". For example, if *s*<==<=123123, then query "2<=→<=00" transforms *s* to 10...
{"inputs": ["123123\n1\n2->00", "123123\n1\n3->", "222\n2\n2->0\n0->7", "1000000008\n0", "100\n5\n1->301\n0->013\n1->013\n0->103\n0->103", "21222\n10\n1->\n2->1\n1->1\n1->1\n1->1\n1->22\n2->2\n2->1\n1->21\n1->", "21122\n10\n1->\n2->12\n1->\n2->21\n2->\n1->21\n1->\n2->12\n2->\n1->21", "7048431802\n3\n0->9285051\n0->7854...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
9929caf2ab82e2bcb6a1a7d2f22a5c35
Jzzhu and Chocolate
Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements: - each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit...
{"inputs": ["3 4 1", "6 4 2", "2 3 4", "10 10 2", "1000000000 1000000000 2000000000", "1000000000 1000000000 999999999", "1000000000 1000000000 1", "98283 999283848 23", "6 4 5", "6 4 6", "482738478 493948384 502919283", "1 1 1", "1 1 2", "1 1 1000000000", "1000000000 1000000000 123456", "192837483 829387483 828374", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
9938d8d14c5798896320ef4e314adf96
Constellation
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would lik...
{"inputs": ["3\n0 1\n1 0\n1 1", "5\n0 0\n0 2\n2 0\n2 2\n1 1", "3\n819934317 939682125\n487662889 8614219\n-557136619 382982369", "10\n25280705 121178189\n219147240 -570920213\n-829849659 923854124\n18428128 -781819137\n-876779400 528386329\n-780997681 387686853\n-101900553 749998368\n58277314 355353788\n732128908 33641...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
993d6fdfa3a88ca40146880e02e2c72b
On Corruption and Numbers
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
{"inputs": ["2\n5 2 3\n6 4 5", "50\n69 6 6\n22 1 1\n23 3 3\n60 13 13\n13 3 3\n7 4 7\n6 1 1\n49 7 9\n68 8 8\n20 2 2\n34 1 1\n79 5 5\n22 1 1\n77 58 65\n10 3 3\n72 5 5\n47 1 1\n82 3 3\n92 8 8\n34 1 1\n42 9 10\n63 14 14\n10 3 3\n38 2 2\n80 6 6\n79 5 5\n53 5 5\n44 7 7\n85 2 2\n24 2 2\n57 3 3\n95 29 81\n77 6 6\n24 1 1\n33 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
993f91f4cbd61f99613fae57418483be
Find Extra One
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points....
{"inputs": ["3\n1 1\n-1 -1\n2 -1", "4\n1 1\n2 2\n-1 1\n-2 2", "3\n1 2\n2 1\n4 60", "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "2\n1000000000 -1000000000\n1000000000 1000000000", "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
326
codeforces
9940523d0a61cbefac6cca3bfb153524
Road Construction
A country has *n* cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two...
{"inputs": ["4 1\n1 3", "1000 0", "484 11\n414 97\n414 224\n444 414\n414 483\n414 399\n414 484\n414 189\n414 246\n414 115\n89 414\n14 414", "150 3\n112 30\n61 45\n37 135", "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26", "1000 48\n816 885\n576 357\n878 659\n610 647\n37 670\n192 184\n393 407\n598 160\n547 995\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
994b1e0697ee33aebcde79386eb21727
Dubstep
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
{"inputs": ["WUBWUBABCWUB", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "WUBWUBWUBSR", "RWUBWUBWUBLWUB", "ZJWUBWUBWUBJWUBWUBWUBL", "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
920
codeforces
996a30e84b4a1eb1cd09d6828c181d80
Reading
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very lig...
{"inputs": ["5 3\n20 10 30 40 10", "6 5\n90 20 35 40 60 100", "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
63
codeforces
99802e27d1bad6aec23dda7b6149fe4c
Mahmoud and Ehab and the binary string
Mahmoud and Ehab are in the fourth stage now. Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr...
{"inputs": ["101", "0011001100", "01", "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101", "110010011001010100101010001101110010010111001110111110011011111111000110...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
9982ea1d5352957c03052d5ba42f8e98
Magic Numbers
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. The first line of input contains an integ...
{"inputs": ["114114", "1111", "441231", "1", "14", "114", "9", "414", "1000000000", "144144144", "1444", "11", "141414141", "11110111", "114114144", "444", "9999", "111444", "11114", "41111", "114414441", "144414441", "144244144", "111111111", "144444444", "444444444", "141441441", "441", "15", "14444", "11444", "144",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
371
codeforces
999bf32199374ef5363fd5cc2c649a9c
Pashmak and Garden
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al...
{"inputs": ["0 0 0 1", "0 0 1 1", "0 0 1 2", "-100 -100 100 100", "-100 -100 99 100", "0 -100 0 100", "27 -74 27 74", "0 1 2 3", "-100 100 100 -100", "-100 -100 -100 100", "100 100 100 -100", "100 -100 -100 -100", "-100 100 100 100", "0 1 0 0", "1 1 0 0", "0 0 1 0", "1 0 0 1", "1 0 1 1", "1 1 0 1", "15 -9 80 -9", "51 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
109
codeforces
99a87db9a65e8c0f1ea8ea030de379af
Taxi
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers....
{"inputs": ["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1", "5\n4 4 4 4 4", "12\n1 1 1 1 1 1 1 1 1 1 1 1", "2\n2 1", "4\n3 2 1 3", "4\n2 4 1 3", "1\n1", "1\n2", "1\n3", "1\n4", "2\n1 1", "2\n2 2", "2\n3 3", "2\n4 4", "2\n2 1", "2\n3 1", "2\n4 1", "2\n2 3", "2\n4 2", "2\n4 3", "4\n2 2 1 1", "4\n3 1 3 1", "4\n1 4 1 4", "4\n2 2 3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
99c831150672a64c4aa964d7c81ccb57
T-shirt buying
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and...
{"inputs": ["5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1", "2\n1000000000 1\n1 1\n1 2\n2\n2 1", "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3", "20\n414468312 20329584 106106409...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
99cc6b3b398b6c1bd9b18b917231d58c
Mike and Fax
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages ...
{"inputs": ["saba\n2", "saddastavvat\n2", "aaaaaaaaaa\n3", "aaaaaa\n3", "abaacca\n2", "a\n1", "princeofpersia\n1", "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqtht...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
150
codeforces
99e62878fbc428e1631c7ff1a24bf047
Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex ...
{"inputs": ["3\n2 3\n1 0\n1 0", "2\n1 1\n1 0", "10\n3 13\n2 6\n1 5\n3 5\n1 3\n2 2\n2 6\n1 6\n1 3\n2 3", "10\n1 2\n1 7\n1 0\n1 8\n0 0\n1 9\n0 0\n1 1\n1 3\n1 5", "5\n1 1\n2 2\n2 2\n2 6\n1 3", "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "11\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 8\n1 7\n0 0\n0 0", "12\n0 0\n1 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
20
codeforces
99ea4713717dfb495b4af4a4707d2b49
Page Numbers
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
{"inputs": ["1,2,3,1,1,2,6,6,2", "3,2,1", "30,20,10", "826,747,849,687,437", "999,999,993,969,999", "4,24,6,1,15", "511,32", "907,452,355", "303,872,764,401", "684,698,429,694,956,812,594,170,937,764", "646,840,437,946,640,564,936,917,487,752,844,734,468,969,674,646,728,642,514,695", "996,999,998,984,989,1000,996,993,1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
60
codeforces
99fc2ec11dfa7ff1fc0a3b7335550b1e
Alyona and Mex
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,...
{"inputs": ["5\n1 3 3 3 6", "2\n2 1", "1\n1", "1\n1000000000", "1\n2", "2\n1 1", "2\n1 3", "2\n2 2", "2\n2 3", "2\n3 3", "3\n1 1 1", "3\n2 1 1", "3\n3 1 1", "3\n1 1 4", "3\n2 1 2", "3\n3 2 1", "3\n2 4 1", "3\n3 3 1", "3\n1 3 4", "3\n4 1 4", "3\n2 2 2", "3\n3 2 2", "3\n4 2 2", "3\n2 3 3", "3\n4 2 3", "3\n4 4 2", "3\n3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
117
codeforces
9a1fc48ed171b6e3bfc5d1196bac0b54
Arthur and Questions
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length *n* (*a*1,<=*a*2,<=...,<=*a**n*), consisting of integers and integer *k*, not exceeding *n*. This sequence had the following property: if you write out the sums of all its segments consisting of *k* consecutive elements ...
{"inputs": ["3 2\n? 1 2", "5 1\n-10 -9 ? -7 -6", "5 3\n4 6 7 2 9", "9 3\n? ? ? ? ? ? ? ? ?", "5 1\n1000000000 ? ? ? ?", "5 1\n-3 -2 -1 0 1", "7 3\n1 ? -1000000000 ? 100 ? 3", "7 3\n1 ? -1000000000 ? 100 ? 2", "1 1\n?", "1 1\n0", "2 1\n-1000000000 1000000000", "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100", "5 2\n? ? -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
9a39ec0c2b714438bc895874b6e23dff
Little Artem and Dance
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together. More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a...
{"inputs": ["6 3\n1 2\n2\n1 2", "2 3\n1 1\n2\n1 -2", "4 2\n2\n1 3", "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2", "6 8\n1 -1\n2\n2\n1 4\n1 0\n1 -1\n1 0\n1 -1", "10 5\n1 8\n1 -3\n1 -3\n2\n1 5", "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9", "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2", "2 5\n2\n1 -1\n2\n1 1\n2", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces