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
50791db071f3edbf0b1751f2239c954b
Coin Troubles
In the Isle of Guernsey there are *n* different types of coins. For each *i* (1<=≤<=*i*<=≤<=*n*), coin of type *i* is worth *a**i* cents. It is possible that *a**i*<==<=*a**j* for some *i* and *j* (*i*<=≠<=*j*). Bessie has some set of these coins totaling *t* cents. She tells Jessie *q* pairs of integers. For each *i...
{"inputs": ["4 2 17\n3 1 2 5\n4 2\n3 4", "3 2 6\n3 1 1\n1 2\n2 3", "3 2 10\n1 2 3\n1 2\n2 1", "10 0 97\n7 2 10 5 10 5 8 9 6 2", "10 2 11\n4 9 3 1 4 10 2 6 10 8\n3 6\n6 4", "10 4 18\n9 2 8 2 7 4 9 5 10 9\n7 9\n9 2\n2 5\n5 10", "10 0 96374\n9 4 9 8 4 1 10 1 6 6", "10 5 857\n3 9 8 10 10 5 3 3 8 1\n6 9\n9 2\n2 7\n4 3\n8 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
508e636f3924d8df0d7fac38849e57da
none
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic. Suppose she wants to join two tables, *A* and *B*. Each of them has certain number of rows which are distributed on different number of partitions. Table *A* is distributed on the first cluster cons...
{"inputs": ["2 2\n2 6\n3 100", "2 3\n10 10\n1 1 1", "2 2\n888381664 866366630\n170399907 404233949", "3 4\n337369924 278848730 654933675\n866361693 732544605 890800310 350303294", "10 10\n510955240 684852706 455356451 284505713 595775142 646334608 563116339 941123613 818750895 516673753\n382626402 204542396 341363992 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
50deaa2fdf386fcdaf44f03cf4706b8e
A rectangle
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem. A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will...
{"inputs": ["1 1 5 5", "-1 -3 1 3", "-2 -2 2 2", "0 0 2 2", "0 0 2 0", "0 0 0 0", "0 -2 0 2", "-2 -2 -2 0", "-1000000000 -1000000000 1000000000 1000000000", "-999999999 -999999999 999999999 999999999", "-999999999 -999999999 -1 -1", "-411495869 33834653 -234317741 925065545", "-946749893 -687257665 -539044455 -44356867...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
50e08cf44bddd6a4b194ec1f594526c0
Black Square
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum pos...
{"inputs": ["5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "1 2\nBB", "3 3\nWWW\nWWW\nWWW", "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
73
codeforces
50e3de91cc5521bb0c2850880e212a5f
Commentary Boxes
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil...
{"inputs": ["9 7 3 8", "2 7 3 7", "30 6 17 19", "500000000001 1000000000000 100 100", "1000000000000 750000000001 10 100", "1000000000000 750000000001 100 10", "42 1 1 1", "1 1000000000000 1 100", "7 2 3 7", "999999999 2 1 1", "999999999999 10000000007 100 100", "10000000001 2 1 1", "29 6 1 2", "99999999999 6 100 100",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
269
codeforces
510995f0772298cdcea496ca8e30b37f
Jamie and Alarm Snooze
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ...
{"inputs": ["3\n11 23", "5\n01 07", "34\n09 24", "2\n14 37", "14\n19 54", "42\n15 44", "46\n02 43", "14\n06 41", "26\n04 58", "54\n16 47", "38\n20 01", "11\n02 05", "55\n22 10", "23\n10 08", "23\n23 14", "51\n03 27", "35\n15 25", "3\n12 15", "47\n00 28", "31\n13 34", "59\n17 32", "25\n11 03", "9\n16 53", "53\n04 06", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
221
codeforces
510c8b6e384edf5cc7c5ebc9f24ffc8d
Die Roll
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
{"inputs": ["4 2", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "2 1", "2 2", "2 3", "2 4", "2 5", "2 6", "3 1", "3 2", "3 3", "3 4", "3 5", "3 6", "4 1", "4 3", "4 4", "4 5", "4 6", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6"], "outputs": ["1/2", "1/1", "5/6", "2/3", "1/2", "1/3", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,289
codeforces
51541df11a68a266455ed6830f33bb89
3-cycles
During a recent research Berland scientists found out that there were *n* cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose thr...
{"inputs": ["3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "11", "13", "16", "18", "19", "12", "22", "23", "15", "29", "31", "33", "36", "40", "42", "47", "50", "52", "59", "63", "64", "68", "75", "77", "81", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"], "outputs": ["2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
5178b46518ed8b00d8287e9a143991df
New Year Tree
The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tree is an undirected tree with *n* vertices and root in the vertex 1. You should process the queries of the two types: 1. Cha...
{"inputs": ["7 10\n1 1 1 1 1 1 1\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 3 2\n2 1\n1 4 3\n2 1\n1 2 5\n2 1\n1 6 4\n2 1\n2 2\n2 3", "23 30\n1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n4 11\n6 12\n6 13\n7 14\n7 15\n7 16\n8 17\n8 18\n10 19\n10 20\n10 21\n11 22\n11 23\n2 1\n2 5\n2 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
517c2823ba28b9c195cdcd650d4db4fb
2 + 2 != 4
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... The only line of input data contains the arithmetic ex...
{"inputs": ["8-7+6-5+4-3+2-1-0", "2+2", "112-37", "255+255+255+255+255+255+255+255+255+255", "0-255-255-255-255-255-255-255-255-255", "0+0+0+0+0+0+0+0+0+0", "0-0-0-0-0-0-0-0-0-0", "0+100+100+100+100+100+100+100+100+100", "255-100-100-100-100-100-100-100-100-100", "45+5", "23+6-9", "123+234-56-78-90", "97+67+12+9+42+45+...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
51871bcfc6ef6119fe456069494bd418
Tricky Alchemy
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
{"inputs": ["4 3\n2 1 1", "3 9\n1 1 3", "12345678 87654321\n43043751 1000000000 53798715", "12 12\n3 5 2", "770 1390\n170 442 311", "3555165 6693472\n1499112 556941 3075290", "0 0\n1000000000 1000000000 1000000000", "1 1\n0 1 0", "117708228 562858833\n118004008 360437130 154015822", "999998118 700178721\n822106746 8298...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
401
codeforces
519044032d5415fdfdd43cc483036c0a
Test
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop...
{"inputs": ["ab\nbc\ncd", "abacaba\nabaaba\nx", "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls", "jwdezvgfm\nmdoqvylpuvyk\nqylldbziva", "ujgquqxdlowuwnqkmbd\nwdwkhkdgsujgqu\njlxqvcuivagmw", "rdtevvmiqmfgvafkdypxjthzhfsbavmhgkavkfonscaokdxoscenpxrc\nijbvueenz...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
519062580288920390ab5b9c5f1e5dd1
Divisible by Seven
You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resu...
{"inputs": ["1689", "18906", "2419323689", "8589157262", "2717172350336955863014903670481525170997949309274087058935108848979319747543008692128164875210350026", "9825995656040286793128006047268547610068699214477842995873286607346639816314908021369221299622234988", "100000000689", "16891", "16892", "16893", "16894", "16...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
51911583dab871f5ea0ac52588a84b8b
Antimatter
Iahub accidentally discovered a secret lab. He found there *n* devices ordered in a line, numbered from 1 to *n* from left to right. Each device *i* (1<=≤<=*i*<=≤<=*n*) can create either *a**i* units of matter or *a**i* units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify...
{"inputs": ["4\n1 1 1 1", "10\n16 9 9 11 10 12 9 6 10 8", "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3", "100\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 3 4 2 3 5 3 6 5 3 6 5 6 6 2 6 4 5 5 4 6 4 3 2 8 5 6 6 7 4 4 9 5 6 6 3 7 1 6 2 6 5 9 3 8 6 2 6 3 2 4 4 3 5 4 7 6 5 4 6 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
51b23f121a010950ffd4756d31d02d4a
Fafa and Ancient Alphabet
Ancient Egyptians are known to have used a large set of symbols to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words *S*1 and *S*2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the words w...
{"inputs": ["1 2\n0\n1", "1 2\n1\n0", "7 26\n0 15 12 9 13 0 14\n11 1 0 13 15 12 0", "6 26\n14 5 19 18 9 14\n0 0 0 0 0 0", "4 26\n0 0 0 0\n13 15 18 1", "5 100\n0 0 0 0 0\n0 0 0 0 0", "7 30\n11 1 0 13 15 12 0\n0 15 12 9 13 0 14", "4 50\n19 1 19 1\n19 1 19 15", "4 50\n19 1 19 15\n19 1 19 1", "107 100000\n0 0 0 0 0 0 0 0 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
51cf8476c1c8c68b031ab3f1f1625c98
Points on the line
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2. D...
{"inputs": ["3 1\n2 1 4", "3 0\n7 7 7", "6 3\n1 3 4 6 9 10", "11 5\n10 11 12 13 14 15 16 17 18 19 20", "1 100\n1", "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
121
codeforces
51dcd299d4c1375028194acc6f588742
Vitaly and Strings
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
{"inputs": ["a\nc", "aaa\nzzz", "abcdefg\nabcdefh", "abcdefg\nabcfefg", "frt\nfru", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
118
codeforces
51ea43be131b02c7ef7343fe9f2b02c0
Secret Combination
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis...
{"inputs": ["3\n579", "4\n2014", "1\n1", "3\n039", "4\n4444", "5\n46802", "10\n4447444444", "10\n5810438174", "30\n027027027027027027027027027027", "50\n41012516454101251645410125164541012516454101251645", "72\n464553044645330446455304464553064645530445455304464553044645530446455304", "100\n2144315253572020279108092911...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
89
codeforces
525529e7c4f14a1e5c41a441db482ecb
Mister B and Flight to the Moon
In order to fly to the Moon Mister B just needs to solve the following problem. There is a complete indirected graph with *n* vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles. We are sure that Mister B will solve the problem soon and will fly to the ...
{"inputs": ["3", "5", "299", "300", "4", "5", "6", "7", "8", "9", "10", "298", "297", "11", "14", "21", "28", "35", "42", "49", "56", "63", "70", "77", "84", "91", "98", "105", "112", "119", "126", "133", "140", "147", "154", "161", "168", "175", "182", "189", "196", "203", "210", "217", "224", "231", "238", "245", "25...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
528e74abdd6f1a9f497825c446f2ef2b
Chewbaсca and Number
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
{"inputs": ["27", "4545", "1", "9", "8772", "81", "71723447", "91730629", "420062703497", "332711047202", "3395184971407775", "8464062628894325", "164324828731963982", "384979173822804784", "41312150450968417", "2156", "1932", "5902", "5728", "8537", "55403857", "270739", "28746918", "10279211", "40289679", "5452032385...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
346
codeforces
5292b9c42c14e162f4ce34076de89ae1
none
Little Elephant loves Furik and Rubik, who he met in a small city Kremenchug. The Little Elephant has two strings of equal length *a* and *b*, consisting only of uppercase English letters. The Little Elephant selects a pair of substrings of equal length — the first one from string *a*, the second one from string *b*. ...
{"inputs": ["2\nAB\nBA", "3\nAAB\nCAA", "7\nAAAAAAA\nBBBBBBB", "4\nAAAA\nAAAB", "10\nSATYFFJYBA\nBGFOBFBVAV", "1\nA\nA", "1\nA\nZ", "14\nBABBABABABABAA\nBABABAABAAABAB", "10\nQUDLGGRJEG\nMIZIEZRCJU", "47\nGMQXICWAZQNJFYHHAFWXZOLNEZGUIPEKMWPWXLXUBDFONZF\nXSGRAAAFYJBCJYECMTWRTZNKVWMSVYJOFDNZFEFYLWGUGYX", "25\nYWORWQKEMDA...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
5298cee5f0c18b0718c0ec3fe8bd388a
Wet Shark and Flowers
There are *n* sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks *i* and *i*<=+<=1 are neighbours for all *i* from 1 to *n*<=-<=1. Sharks *n* and 1 are neighbours too. Each shark will grow some number of flowers *s**i*. For *i*-th shark value *s**i* is random integer equipro...
{"inputs": ["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14", "3 3\n3 3\n2 4\n1 1", "5 5\n5 204\n420 469\n417 480\n442 443\n44 46", "3 2\n2 2\n3 3\n4 4", "6 7\n8 13\n14 14\n8 13\n14 14\n8 13\n14 14", "3 7\n7 14\n700000000 700000007\n420 4200", "5 999999937\n999999935 999999936\n999999937 999999938\n999999939 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
52bb700295732c2b5c9555abba470fd8
Kids' Riddle
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? The input contains a single integer *n* (0<=≤<=*n*<=≤<=2000000000). Output a single integer. Sample Input 11 14 61441 571576 2128506 Sample Output 2 0 2 10 3
{"inputs": ["11", "14", "61441", "571576", "2128506", "0", "2000000000", "143165576", "1741", "1919020031", "1795248373", "1818960378", "1285316221", "1309028227", "1304312649", "1180540990", "1204252996", "1199537418", "1075765759", "724264821", "747976826", "624205168", "619489590", "643201595", "638486017", "5147143...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
52bdea90e6852a13d360805c66942d58
Finite or not?
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction. A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that...
{"inputs": ["2\n6 12 10\n4 3 10", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4", "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2", "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10", "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4", "10\n5 8 2\n0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
52c301e110c218203ec5f2e7b16fdaef
k-substrings
You are given a string *s* consisting of *n* lowercase Latin letters. Let's denote *k*-substring of *s* as a string *subs**k*<==<=*s**k**s**k*<=+<=1..*s**n*<=+<=1<=-<=*k*. Obviously, *subs*1<==<=*s*, and there are exactly such substrings. Let's call some string *t* an odd proper suprefix of a string *T* iff the foll...
{"inputs": ["15\nbcabcabcabcabca", "24\nabaaabaaaabaaabaaaabaaab", "19\ncabcabbcabcabbcabca", "2\nza", "20\nbbbaaabbbbbbbbaaabbb", "2\nzz", "3\ndad", "4\naccd", "5\naabcd", "6\nbcabbd", "7\nbaaaadd"], "outputs": ["9 7 5 3 1 -1 -1 -1", "15 13 11 9 7 5 3 1 1 -1 -1 1", "5 3 1 -1 -1 1 1 -1 -1 -1", "-1", "9 7 5 3 1 1 7 5 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
52f5dd7190e4ec2cbb522191d7d08ee6
Robot Sequence
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s...
{"inputs": ["6\nURLLDR", "4\nDLUU", "7\nRLRLRLR", "1\nR", "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL", "200\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
166
codeforces
533ae5b3b2eae7d179cdcdabdab45238
Little Elephant and Chess
The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8<=×<=8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard d...
{"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nW...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
204
codeforces
53591cfe13dfca10ed3fe3da3e03db20
Little Artem and Random Variable
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Consider two dices. When thrown each dice shows some integer from 1 to *n* inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and d...
{"inputs": ["2\n0.25 0.75\n0.75 0.25", "3\n0.125 0.25 0.625\n0.625 0.25 0.125", "10\n0.01 0.01 0.01 0.01 0.01 0.1 0.2 0.2 0.4 0.05\n1.0 0 0 0 0 0 0 0 0 0", "10\n0 0 0 0 0 0 0 0 0 1.0\n1.0 0 0 0 0 0 0 0 0 0", "1\n1.0\n1.0", "2\n0.00001 0.99999\n0.5 0.5", "3\n0.1 0.1 0.8\n0.6 0.2 0.2", "8\n0.09597231 0.11315755 0.3207711...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
535ff148f11b5e0f05a3efd56473da55
Ilya and Roads
Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as *n* holes in a row. We will consider the holes numbered from 1 to *n*, from left to right. Ilya is really keep on helping his city. So, he wants to fix at least *k* holes (perharps he can fix more) on a sing...
{"inputs": ["10 4 6\n7 9 11\n6 9 13\n7 7 7\n3 5 6", "10 7 1\n3 4 15\n8 9 8\n5 6 8\n9 10 6\n1 4 2\n1 4 10\n8 10 13", "10 1 9\n5 10 14", "10 6 9\n6 8 7\n2 8 11\n2 6 10\n8 10 9\n2 5 8\n2 3 8", "10 6 8\n3 6 7\n1 4 3\n2 7 10\n4 7 4\n7 10 15\n4 7 7", "10 4 10\n1 1 11\n7 7 15\n2 3 11\n2 8 6", "10 3 7\n4 6 6\n5 7 1\n2 10 15", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
538e5a259bf9609053b62f07a3684521
The Child and Toy
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts....
{"inputs": ["4 3\n10 20 30 40\n1 4\n1 2\n2 3", "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4", "1 0\n23333", "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5", "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
224
codeforces
53bf4c704b2a544a0f1fb3c16762f47a
Lineland Mail
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
{"inputs": ["4\n-5 -2 2 7", "2\n-1 1", "3\n-1 0 1", "4\n-1 0 1 3", "3\n-1000000000 0 1000000000", "2\n-1000000000 1000000000", "10\n1 10 12 15 59 68 130 912 1239 9123", "5\n-2 -1 0 1 2", "5\n-2 -1 0 1 3", "3\n-10000 1 10000", "5\n-1000000000 -999999999 -999999998 -999999997 -999999996", "10\n-857422304 -529223472 82412...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
608
codeforces
53c54a45f7b49ca7ba7f34ca352c10d6
Dog Show
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win! On the show a dog needs to eat as many bowls of dog food as poss...
{"inputs": ["3 5\n1 5 3", "1 2\n1", "1 1\n1", "1 1\n2", "2 2\n2 3", "2 3\n2 1", "3 3\n2 3 2", "3 2\n2 3 4", "3 4\n2 1 2", "4 4\n2 1 2 3", "4 3\n2 1 2 3", "4 6\n2 3 4 5", "5 5\n2 1 2 3 4", "5 3\n2 3 2 1 2", "5 7\n2 1 2 3 4", "6 6\n2 3 2 3 4 3", "6 4\n2 3 2 3 4 3", "6 9\n2 1 2 1 2 3", "7 7\n2 3 4 5 6 5 6", "7 4\n2 1 2 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
53de648b0565d1a3703a8ca27e960722
Nikita and string
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
{"inputs": ["abba", "bab", "bbabbbaabbbb", "bbabbbbbaaba", "bbabbbababaa", "aabbaababbab", "a", "b", "ab", "ba", "bb", "aa", "babbbaab", "abaaaa", "aaa"], "outputs": ["4", "2", "9", "10", "9", "8", "1", "1", "2", "2", "2", "2", "6", "6", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
72
codeforces
53fa4bd5bc566062e8f1db038d8f15de
Pattern
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules. In this task, a pattern will be a string con...
{"inputs": ["2\n?ab\n??b", "2\na\nb", "1\n?a?b", "1\n?", "3\nabacaba\nabacaba\nabacaba", "3\nabc?t\n?bc?z\nab??t", "4\nabc\ndef\n???\nxyz", "2\n?????\n?????", "2\na\na", "3\nabc\n???\naxc", "1\n?m??x?xxexxx?xxmxx??", "2\nhszhh?zszs\nhhzhz?zzhs", "3\neddzde\needded\nzdde?z", "4\nff?o?\nfk?of\nk?kof\nfk?oo", "5\nyigi\ne?...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
74
codeforces
5400ae66fbdd291d560caf981f43e7e0
Petya and Staircases
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. No...
{"inputs": ["10 5\n2 4 8 3 6", "10 5\n2 4 5 7 9", "10 9\n2 3 4 5 6 7 8 9 10", "5 2\n4 5", "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "10 10\n7 6 4 2 5 10 8 3 9 1", "12312 0", "9817239 1\n6323187", "1 1\n1", "5 4\n4 2 5 1", "5 3\n4 3 5", "500 3\n18 62 445", "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
44
codeforces
5403d9edc0e697bd7a0b0ef11150d83c
Gleb And Pizza
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust. The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or...
{"inputs": ["8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1", "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2", "1 0\n1\n1 1 0", "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1", "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0", "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
190
codeforces
540cb1fd4a6870c7db9c8333423e798f
Cows and Poker Game
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be...
{"inputs": ["6\nAFFAAA", "3\nAFI", "3\nFFF", "3\nFIF", "3\nAAA", "3\nIII", "3\nIIA", "3\nAFF", "5\nFAFFF", "3\nIAA", "3\nIIF", "2\nFA", "2\nFF", "2\nIF", "5\nAAAAI", "5\nIIIIF", "10\nAAAAAAAAAA", "100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "5\nFAIAF", "5\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
126
codeforces
549053419f14efeb49ea7377628d5a2d
Mashmokh and Numbers
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he r...
{"inputs": ["5 2", "5 3", "7 2", "1 1", "2 0", "1 10", "1 0", "7 3", "7 6", "7 7", "100000 100000000", "3455 2792393", "74086 16504611", "28515 44887064", "21324 73830196", "90212 5921828", "25095 2372924", "92977 95851971", "39095 77350428", "785 70908164", "28051 5506872", "74077 37498088", "58284 12998910", "28768 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
54a78b545ae5ffb4e728231eb0a098e9
Surrounded
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround...
{"inputs": ["0 0 1\n6 0 3", "-10 10 3\n10 -10 3", "2 1 3\n8 9 5", "0 0 1\n-10 -10 9", "10000 -9268 1\n-9898 9000 10", "10000 10000 1\n-10000 -10000 1", "123 21 50\n10 100 1000", "0 3278 2382\n2312 1 1111", "3 4 5\n5 12 13", "-2 7 5\n4 0 6", "4 0 2\n6 -1 10", "41 17 3\n71 -86 10", "761 641 6\n506 -293 5", "-5051 -7339 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
54ae528218897038012509ab2051c563
Broken robot
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of *N* rows and *M* columns of cells. The robot is initially at some cell on the *i*-th row and the *j*-th column. Then at every step the...
{"inputs": ["10 10\n10 4", "10 14\n5 14", "126 125\n115 22", "755 51\n205 12", "385 978\n344 18", "663 904\n192 518", "293 183\n279 21", "922 109\n431 55", "552 36\n199 35", "182 314\n54 201", "812 240\n561 19", "595 881\n417 120", "694 685\n278 653", "793 840\n534 276", "892 996\n288 751", "990 800\n801 66", "89 955\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
54b9ba5fab7b748e49429697be63d53e
Present from Lena
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to *n* as the pattern. The digits will form a rhombus. The largest digit *n* should be located in the centre. The digits should decrease as they approach the edges. For example, for *n*<==<=5 t...
{"inputs": ["2", "3", "4", "5", "6", "7", "8", "9"], "outputs": [" 0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0", " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n0 1 2 3 4 3 2 1 0\n 0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
54eabc2821352e7e3a39754857af9e14
A Game With Numbers
Imagine that Alice is playing a card game with her friend Bob. They both have exactly $8$ cards and there is an integer on each card, ranging from $0$ to $4$. In each round, Alice or Bob in turns choose two cards from different players, let them be $a$ and $b$, where $a$ is the number on the player's card, and $b$ is t...
{"inputs": ["4\n1\n0 0 0 0 0 0 0 0\n1 2 3 4 1 2 3 4\n1\n0 0 0 1 0 0 0 0\n0 0 0 0 4 0 0 0\n0\n1 0 0 0 0 0 0 0\n0 0 0 4 0 0 2 0\n1\n1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1", "1\n0\n0 2 2 0 1 2 1 2\n1 2 4 3 2 1 1 0"], "outputs": ["Alice\nBob\nAlice\nDeal", "Alice"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
54ef95eac742c7cf136cec111b8e7b83
Borya's Diagnosis
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t...
{"inputs": ["3\n2 2\n1 2\n2 2", "2\n10 1\n6 5", "3\n6 10\n3 3\n8 2", "4\n4 8\n10 10\n4 2\n8 2", "5\n7 1\n5 1\n6 1\n1 6\n6 8", "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8", "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9", "1\n1 1", "1\n1000 1000", "42\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
54f2b0eb96295a35dd0ba51561306f0a
none
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, w...
{"inputs": ["10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8", "3\nAND 2 3\nIN 0\nIN 0", "3\nAND 2 3\nIN 1\nIN 0", "3\nAND 2 3\nIN 0\nIN 1", "3\nAND 2 3\nIN 1\nIN 1", "3\nOR 2 3\nIN 0\nIN 0", "3\nOR 2 3\nIN 1\nIN 0", "3\nOR 2 3\nIN 0\nIN 1", "3\nOR 2 3\nIN 1\nIN 1", "3\nXOR 2 3\nIN 0\nIN 0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
54f654755a3f3b43fcc1e4463c5ec344
K-Periodic Array
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it...
{"inputs": ["6 2\n2 1 2 2 2 1", "8 4\n1 1 2 1 1 1 2 1", "9 3\n2 1 1 1 2 1 1 1 2", "1 1\n2", "2 1\n1 1", "2 2\n2 2", "100 1\n1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
81
codeforces
5593c830d71188d6cb7298d1414d88e3
Python Indentation
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An ex...
{"inputs": ["4\ns\nf\nf\ns", "4\nf\ns\nf\ns", "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
55ae3df199bb9e610ef7dd2ba38b3fe1
Shooting Gallery
One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him. The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targ...
{"inputs": ["1\n0 0 0 0.5", "2\n0 0 0 0.6\n5 0 5 0.7", "1\n-5 2 3 0.886986", "4\n10 -7 14 0.926305\n-7 -8 12 0.121809\n-7 7 14 0.413446\n3 -8 6 0.859061", "5\n-2 -2 34 0.127276\n5 -5 4 0.459998\n10 3 15 0.293766\n1 -3 7 0.089869\n-4 -7 11 0.772515", "5\n2 5 1 0.955925\n9 -9 14 0.299977\n0 1 97 0.114582\n-4 -2 66 0.5610...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
55bd32dabd659fa4145edf5cace46d7e
Maximal Area Quadrilateral
Iahub has drawn a set of *n* points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is o...
{"inputs": ["5\n0 0\n0 4\n4 0\n4 4\n2 3", "10\n-6 -4\n-7 5\n-7 -7\n5 -7\n4 -9\n-6 7\n2 9\n-4 -6\n2 10\n-10 -4", "4\n-3 3\n0 3\n-2 -1\n2 2", "5\n-4 -3\n-3 -2\n3 3\n-1 2\n3 -3", "6\n-4 -3\n-1 3\n0 0\n2 2\n2 1\n-3 1", "7\n-2 -1\n4 3\n2 2\n-4 0\n-2 4\n0 0\n1 -3", "4\n-874 606\n-996 -207\n897 847\n775 191", "10\n156 -415\n8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
55d0b2a7f663cfde27c5fb8e3f1bdcd8
Schedule
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, beca...
{"inputs": ["3\n3 10\n20 30\n1 3", "4\n3 10\n20 30\n1 3\n1 39", "3\n1 5\n2 6\n3 7", "4\n1 5\n5 7\n6 9\n9 10", "11\n717170 795210\n866429 970764\n163324 322182\n677099 717170\n241684 393937\n50433 114594\n970764 997956\n393937 664883\n235698 241684\n795210 832346\n114594 232438", "16\n203671 381501\n58867 59732\n817520 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
55e0f5d579ec5fa6ede167fd6433cad2
Gifts by the List
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are *n* men in Sasha's family, so let's number them with integers from 1 to *n*. Each man has at most one father but may have arbitrary number of sons. Man number *A* is considere...
{"inputs": ["3 2\n1 2\n2 3\n1 2 1", "4 2\n1 2\n3 4\n1 2 3 3", "1 0\n1", "2 1\n2 1\n2 2", "2 1\n2 1\n1 2", "4 3\n1 2\n2 3\n3 4\n1 1 3 2", "4 3\n4 3\n3 2\n2 1\n3 4 4 4", "4 3\n1 2\n2 3\n3 4\n1 1 1 2"], "outputs": ["-1", "3\n2\n1\n3", "1\n1", "1\n2", "2\n1\n2", "-1", "-1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
55e2de5ea4444a213d58a4e0107ee79d
none
Bob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is *t*1, and the hot water's temperature is *t*2. The cold water tap can transmit any integer number of water units per second from 0 to *x*1, inclusive. Similarly, the hot water ta...
{"inputs": ["10 70 100 100 25", "300 500 1000 1000 300", "143 456 110 117 273", "10 20 5 5 13", "1 3 1999 3444 2", "100 110 2 2 109", "3746 3797 485 485 3747", "900000 1000000 50000 50000 960000", "1 3 100 100 2", "1 3 100 100 3", "1 1 100 100 1", "1 1 1 1 1", "10 14 1 1 12", "10 14 1 1 13", "10 14 1 1 14", "10 14 1 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
55e557b14d1dcc88b6b22982f8316a5d
Verse Pattern
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel...
{"inputs": ["3\n2 2 3\nintel\ncode\nch allenge", "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles", "5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
170
codeforces
5614f76a9a106b37d45a3d86e6f37cd2
Pixels
Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors *x* and *y* (*x*<=≠<=*y*) meet in a violent fight, then t...
{"inputs": ["1 1 1", "3 1 0", "1 4 4", "5 10 6", "6 8 10", "1 10 2", "10 6 8", "18 67 5", "67 81 1", "51 10 91", "48 6 7", "8 97 83", "2 7 95", "772486757 1747374885 377299255", "1358352906 27037371 1947040615", "1944219055 454183506 1369298327", "382601556 881329640 791556039", "246543403 71853598 1504509195", "506063...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
561ea8f650301bad39b3ab5015b8b0dd
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit *n* planets. For planet *i* *a**i* is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and *b**i* is the number of citizens on the planet. The Smart Beaver is going ...
{"inputs": ["2 5\n1 5\n2 4", "1 97\n1 91", "2 79\n1 91\n1 77", "3 100\n8 46\n8 56\n77 98", "71 100\n1 92\n1 94\n1 97\n1 95\n1 100\n1 100\n1 98\n1 99\n1 98\n1 96\n1 97\n1 93\n1 97\n1 92\n1 91\n1 96\n1 97\n1 96\n1 92\n1 99\n1 92\n1 95\n1 93\n1 99\n1 99\n1 99\n1 97\n1 99\n1 95\n1 95\n1 95\n1 96\n1 95\n1 97\n1 93\n1 93\n1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
56451bdd43f18cd529603f3281b1328a
Vanya and Brackets
Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. The firs...
{"inputs": ["3+5*7+8*4", "2+3*5", "3*4*5", "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5", "2*2+2*2", "1+1+1+1+1+1+1", "1+5*6+7*8", "9*8+7*6+5*4+3*2+1", "3*3*9+4+6+8*4+5+1*4*6", "4*9+4+5+8*4+6+9+8+2+5+2+5*7+6+8", "9+9+9*9*9*9+9+9", "9+9+9+9+9*9*9*9", "1*1*1*1*1*1*1*1+1*1*1*1*1*1*1*1", "4+2*7+8+9*6+6*9+8+7*2+4", "5", "4+6*7+4", "2+7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
56463ac6ae649470f5a322be850540a6
Codecraft III
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa...
{"inputs": ["November\n3", "May\n24", "April\n0", "September\n0", "August\n0", "June\n1", "July\n2", "September\n3", "July\n4", "August\n24", "May\n48", "November\n47", "December\n49", "June\n99", "March\n100", "December\n1", "January\n11", "December\n0", "January\n0", "July\n77", "February\n11", "February\n22", "July\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
227
codeforces
565ba3eb6d9564437c2cdd828875b47c
Kefa and Watch
One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money. The pawnbroker said that each watch contains a serial number ...
{"inputs": ["3 1 2\n112\n2 2 3 1\n1 1 3 8\n2 1 2 1", "6 2 3\n334934\n2 2 5 2\n1 4 4 3\n2 1 6 3\n1 2 3 8\n2 3 6 1", "1 0 1\n5\n2 1 1 1", "20 1 2\n34075930750342906718\n2 1 20 20\n1 1 20 6\n2 1 20 1", "10 1 4\n4545454545\n2 1 10 2\n2 2 4 2\n2 2 9 4\n1 2 9 6\n2 3 8 3", "15 1 5\n234072305423089\n2 1 15 1\n2 5 6 1\n2 8 11 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
56792a031cc15f8d2f78b3cbe37979f4
Funky Numbers
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and c...
{"inputs": ["256", "512", "80", "828", "6035", "39210", "79712", "190492", "5722367", "816761542", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "18", "19", "20", "41", "11", "69", "82", "85", "736", "895", "934", "6213", "7405", "9919", "40942", "41992", "68535", "405718", "104...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
116
codeforces
5691be4e6291720f4fc740dc091f5666
Working out
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column. Ia...
{"inputs": ["3 3\n100 100 100\n100 1 100\n100 100 100", "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280", "3 3\n3 1 2\n3 2 0\n2 3 2", "3 3\n1 10 1\n1 10 1\n1 10 1", "3 3\n0 0 0\n0 10000 0\n0 0 0", "3 3\n1 1 1\n0 10000 0\n1 1 1", "3 3\n9 0 9\n0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
569f266d1ef3cadb019f0bea338062a5
none
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
{"inputs": ["5\n! abc\n. ad\n. b\n! cd\n? c", "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "4\n! abcd\n! cdef\n? d\n? c", "1\n? q", "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q", "3\n. abcdefghijklmnopqrs...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
82
codeforces
56c299caf0c2946a94e66bc57bd96b66
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
{"inputs": ["6\ntom\nlucius\nginny\nharry\nginny\nharry", "3\na\na\na", "1\nzn", "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdf...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
591
codeforces
56c6f54cc6eef938ce3755bc6b36a16d
Banana
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly *n* stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length *n*. Piegirl wants to create a string *s* using stickers. She may buy as many s...
{"inputs": ["banana\n4", "banana\n3", "banana\n2", "p\n1000", "b\n1", "aba\n2", "aaa\n2", "aa\n3", "aaaaaaaabbbbbccccccccccccccccccccccccccccccc\n7", "aaaaa\n10", "baba\n3", "a\n1000", "aan\n5", "banana\n5", "a\n5", "aaaaaaa\n5", "abc\n100", "zzz\n4", "aaabbb\n3", "abc\n5", "abc\n10", "aaaaa\n100", "abc\n1000", "a\n10"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
56dd00818d60b0d068df5b0ca0550b87
Perfect Pair
Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of th...
{"inputs": ["1 2 5", "-1 4 15", "0 -1 5", "0 1 8", "-134 -345 -134", "-134 -345 -133", "999999999 -1000000000 1000000000", "0 0 0", "0 0 1", "-1000000000000000000 1 1000000000000000000", "-3 26 -1", "-25 4 -8", "12 30 -8", "-12 17 3", "4 -11 28", "38 174 957147453", "154 30 763391461", "3 193 648520002", "139 82 923851...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
570f9c7077215c141fdea3f969d947e8
Pineapple Incident
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morn...
{"inputs": ["3 10 4", "3 10 3", "3 8 51", "3 8 52", "456947336 740144 45", "33 232603 599417964", "4363010 696782227 701145238", "9295078 2 6", "76079 281367 119938421", "93647 7 451664565", "5 18553 10908", "6 52 30", "6431 855039 352662", "749399100 103031711 761562532", "21 65767 55245", "4796601 66897 4860613", "8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
205
codeforces
571267a70a8005908ca90f309f896f28
Constants in the language of Shakespeare
Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespeare, and numbers are given by combinations of ornate epithets. In this problem we will have a closer look at the way the numbers are described in Shakespeare. Each constant in Shakespeare is created from non-negati...
{"inputs": ["1111", "1010011", "1", "10110111", "10101110", "1011001", "10001", "10", "11", "100", "100", "111", "1000000000", "1011000000", "1100010000", "1000111001", "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "1000000000000000000000000000000000000000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
571ae45c10d438fc84e131b6b6598e6f
Subsequence Counting
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_su...
{"inputs": ["10 5", "4 2", "4 1", "1 1", "63 1", "98 88", "746 173", "890 553", "883 1000", "1 1000", "695 188", "2060 697", "70 3321", "6358 1646", "167959139 481199252", "641009859 54748096", "524125987 923264237", "702209411 496813081", "585325539 365329221", "58376259 643910770", "941492387 72235422", "824608515 94...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
571fcb9db60f838e9e04086862d0e748
Energy exchange
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the *i*-th accumulator has *a**i* units of energy. Energy ...
{"inputs": ["3 50\n4 2 1", "2 90\n1 11", "5 26\n42 65 23 43 64", "5 45\n964 515 454 623 594", "1 20\n784", "10 20\n812 896 36 596 709 641 679 778 738 302", "10 83\n689 759 779 927 15 231 976 943 604 917", "11 1\n235 280 196 670 495 379 391 280 847 875 506", "12 71\n472 111 924 103 975 527 807 618 400 523 607 424", "13 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
47
codeforces
573dc1b93b6aae1166255b4af7c1e03a
k-Multiple Free Set
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*·*k*. You're given a set of *n* distinct positive integers. Your task is to find th...
{"inputs": ["6 2\n2 3 6 5 4 10", "10 2\n1 2 3 4 5 6 7 8 9 10", "1 1\n1", "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
77
codeforces
5798885d5811c8fe3f4c55cfa0dcc0b7
Cave Painting
Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wan...
{"inputs": ["4 4", "5 3", "1 1", "744 18", "47879 10", "1000000000000000000 1000000000000000000", "657180569218773599 42", "442762254977842799 30", "474158606260730555 1", "807873101233533988 39", "423 7", "264306177888923090 5", "998857801526481788 87", "999684044704565212 28", "319575605003866172 71", "75580456057741...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
57afa8f407534eefb24cd9f1ed75cce9
none
While Duff was resting in the beach, she accidentally found a strange array *b*0,<=*b*1,<=...,<=*b**l*<=-<=1 consisting of *l* positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, *a*0,<=...,<=*a**n*<=-<=1 that *b* can be build from *a* with formula: *b**...
{"inputs": ["3 5 3\n5 9 1", "5 10 3\n1 2 3 4 5", "1 1000000000000000000 1\n508953607", "13 1984343432234 32\n347580985 506695806 506695806 42598441 347580985 720568974 208035957 385072757 42598441 506695806 42598441 42598441 506695806", "1 75937459749 1000000\n521563672", "1 1 1000000\n496389707", "10 82374928374234234...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
57b85f4fcba005a67ee75fe25e8a7e4b
Array and Operations
You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*,<=*j**k*) meets the following conditions: *i**k*<=+<=*j**k* is an odd number and 1<=≤<=*i**k*<=&lt;<=*j**...
{"inputs": ["3 2\n8 3 8\n1 2\n2 3", "3 2\n8 12 8\n1 2\n2 3", "6 4\n35 33 46 58 7 61\n4 5\n3 6\n5 6\n1 6", "10 25\n262144 262144 64 64 16 134217728 32 512 32 8192\n1 2\n3 10\n5 8\n9 10\n2 5\n5 10\n3 6\n3 8\n2 9\n4 5\n8 9\n1 4\n4 9\n3 4\n1 6\n4 7\n7 8\n5 6\n2 3\n1 10\n1 8\n6 9\n6 7\n2 7\n7 10", "10 9\n67108864 8 2 131072...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
57b85f9568ee496d7d360784500df856
Strip
Alexandra has a paper strip with *n* numbers on it. Let's call them *a**i* from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: - Each piece should contain at least *l* numbers.- The difference between the maximal and the minimal number on the p...
{"inputs": ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1", "1 0 1\n0", "6 565 2\n31 76 162 -182 -251 214", "1 0 1\n0", "1 0 1\n-1000000000", "1 100 2\n42", "2 1000000000 1\n-1000000000 1000000000", "2 1000000000 2\n-1000000000 1000000000", "10 3 3\n1 1 1 1 1 5 6 7 8 9", "10 3 3\n1 1 1 2 2 5 6 7 8 9"], "outputs":...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
57d971eb6fe7181e2ba33519339db54d
Exams
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha...
{"inputs": ["4 8", "4 10", "1 3", "1 2", "4 9", "50 234", "50 100", "50 250", "29 116", "20 69", "46 127", "3 7", "36 99", "45 104", "13 57", "25 106", "8 19", "20 69", "13 32", "47 128", "17 73", "3 7", "16 70", "1 5", "38 137", "7 20", "1 5", "36 155", "5 15", "27 75", "21 73", "2 5", "49 177", "7 20", "44 173", "49 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
261
codeforces
57d99909d9c306e4442f6732b3ca3243
Little Elephant and Cards
The Little Elephant loves to play with color cards. He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thin...
{"inputs": ["3\n4 7\n4 7\n7 4", "5\n4 7\n7 4\n2 11\n9 7\n1 1", "1\n1 1", "2\n1 1\n1 1", "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8", "2\n1 2\n2 1", "3\n7 7\n1 2\n2 1", "3\n1 1\n2 5\n3 6", "4\n1000000000 1000000000\n999999999 1000000000\n999999997 999999998\n47 74", "6\n1 2\n3 1\n4 7\n4 1\n9 1\n7 2", "4\n1 2\n1 2\n2 1\n2 1",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
57e7e421e1a36b78c8e4fde63ced274c
Anatoly and Cockroaches
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectio...
{"inputs": ["5\nrbbrr", "5\nbbbbb", "3\nrbr", "13\nrbbbrbrrbrrbb", "18\nrrrrrrrrrrrrrrrrrb", "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb", "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
110
codeforces
57ee5e055f24eba95c780683a584296b
ZS and The Birthday Paradox
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland. In Udayland,...
{"inputs": ["3 2", "1 3", "4 3", "1000000000000000000 1000000000000000000", "59 576460752303423489", "1234567891234 100005", "2 4", "59 576460752303423488", "2016 2016", "2016 2017", "468804735183774830 244864585447548924", "172714899512474455 414514930706102803", "876625063841174080 360793239109880865", "7018187597523...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
57f6b670c52d8702a7686ef2568dbfed
The Monster
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if a...
{"inputs": ["20 2\n9 19", "2 1\n16 12", "39 52\n88 78", "59 96\n34 48", "87 37\n91 29", "11 81\n49 7", "39 21\n95 89", "59 70\n48 54", "87 22\n98 32", "15 63\n51 13", "39 7\n97 91", "18 18\n71 71", "46 71\n16 49", "70 11\n74 27", "94 55\n20 96", "18 4\n77 78", "46 44\n23 55", "74 88\n77 37", "94 37\n34 7", "22 81\n80 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
210
codeforces
5828394940254fd6efa3a0abedfaa1be
Genetic Engineering
You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. ...
{"inputs": ["GTTAAAG", "AACCAACCAAAAC", "GTGAATTTCC", "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA", "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGCGTTGTATCACCTCTGCACTTGTTAGTAAGGTCAGGCGTCCATTACGGAAGAACGTA", "GCATTACATGGGGGGGTCCTACGAGCCCGGCATCCCGGAAACTAGCCGGTTAATTTGGTTTAAACCCTCCCACCCCGGATTGTAACCCCCCTCATTGGTT", "TTC...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
42
codeforces
582ec02a56804cc5560660c3e04cd02a
On Number of Decompositions into Multipliers
You are given an integer *m* as a product of integers *a*1,<=*a*2,<=... *a**n* . Your task is to find the number of distinct decompositions of number *m* into the product of *n* ordered positive integers. Decomposition into *n* products, given in the input, must also be considered in the answer. As the answer can be v...
{"inputs": ["1\n15", "3\n1 1 2", "2\n5 7", "2\n5 10", "3\n1 30 1", "2\n1000000000 1000000000", "1\n1", "3\n1 1 1", "2\n1 2", "2\n1 6", "3\n8 10 8", "5\n14 67 15 28 21", "8\n836 13 77 218 743 530 404 741", "10\n6295 3400 4042 2769 3673 264 5932 4977 1776 5637", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
58300c1535aca1212396fa7342a89cff
Domino
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
{"inputs": ["2\n4 2\n6 4", "1\n2 3", "3\n1 4\n2 3\n4 4", "5\n5 4\n5 4\n1 5\n5 5\n3 3", "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
236
codeforces
5836b24c0f11bb4c360cb09cc7022291
Mean Requests
In this problem you will have to deal with a real algorithm that is used in the VK social network. As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a cer...
{"inputs": ["1 1 2.000000\n1\n1\n1", "11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11", "13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13", "1 1 2.000000\n4\n1\n1", "1 1 2.000000\n1121\n1\n1", "1 1 2.000000\n758432\n1\n1", "3 1 2.000000\n8 25 21\n3\n1 2 3", "19 3 1.333333\n12 15 11 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
5845aa1a775a0630183ec6836b5c2a58
Super M
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able ...
{"inputs": ["7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "2 1\n2 1\n1", "1 1\n1", "10 2\n6 9\n6 2\n1 6\n4 10\n3 7\n9 4\n9 5\n6 7\n2 8\n7 6", "15 2\n7 12\n13 11\n6 8\n2 15\n10 9\n5 1\n13 5\n5 4\n14 3\n8 9\n8 4\n4 7\n12 14\n5 2\n7 4", "20 2\n1 16\n12 5\n15 19\n18 9\n8 4\n10 16\n9 16\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
586f37714c4649e29d7df6664178ab08
Find Color
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
{"inputs": ["-2 1", "2 1", "4 3", "3 3", "4 4", "-4 4", "4 -4", "-4 -4", "0 0", "0 1", "0 2", "0 1000", "1000 0", "-1000 0", "0 -1000", "1000 -1000", "12 5", "12 -5", "-12 -35", "20 -21", "-677 492", "-673 -270", "-668 970", "-220 208", "-215 -996", "-211 243", "-206 -518", "-201 278", "-196 -484", "902 479", "-441 572...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
5877a100f511348a0d6590e174c3e4fa
Fake NP
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times...
{"inputs": ["19 29", "3 6", "39 91", "76 134", "93 95", "17 35", "94 95", "51 52", "47 52", "38 98", "30 37", "56 92", "900000000 1000000000", "37622224 162971117", "760632746 850720703", "908580370 968054552", "951594860 953554446", "347877978 913527175", "620769961 988145114", "820844234 892579936", "741254764 741254...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
173
codeforces
587a688de32a2c20d1ca304fba736ece
Camels
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with *t* humps, representing them as polylines in the plane. Each polyline consists of *n* vertices with coordinates (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**n*,...
{"inputs": ["6 1", "4 2", "3 1", "3 2", "3 3", "3 10", "4 1", "4 3", "4 9", "5 1", "5 2", "5 3", "5 5", "5 9", "5 10", "6 1", "6 2", "6 3", "6 4", "6 10", "19 1", "19 2", "19 3", "19 4", "19 5", "19 6", "19 7", "19 8", "19 9", "19 10", "20 1", "20 2", "20 3", "20 4", "20 5", "20 6", "20 7", "20 8", "20 9", "20 10"], "o...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
588081e1dbf946870f913796b2adf243
none
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
{"inputs": ["4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "3 3\n1 0\n2 1\n3 1", "2 1\n7 1", "3 2\n8 1\n9 1", "3 3\n4 1\n5 0\n7 1", "3 3\n4 1\n5 1\n7 0", "3 3\n4 1\n4 0\n4 1", "3 3\n4 0\n5 1\n4 1", "3 3\n5 0\n4 1\n5 1", "4 4\n2 1\n3 0\n3 1\n4 1", "4 5\n4 1\n4 1\n4 0\n4 0\n6 1", "4 6\n2 1\n4 0\n3 0\n1 1\n4 1\n5 0", "4 4\n2 1\n6 0\n7 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
5881aa5d667ad0d66be9e421fbdb0c19
Tanya and Postcard
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s...
{"inputs": ["AbC\nDCbA", "ABC\nabc", "abacaba\nAbaCaBA", "zzzzz\nZZZZZ", "zzzZZZ\nZZZzzZ", "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop", "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM", "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK", "DpiNBmCRFWxpdbfGOzvvO...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
5892b69c55b4fe459e4286fdace16edf
Sort the Array
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr...
{"inputs": ["3\n3 2 1", "4\n2 1 3 4", "4\n3 1 2 4", "2\n1 2", "2\n58 4", "5\n69 37 27 4 2", "9\n6 78 63 59 28 24 8 96 99", "6\n19517752 43452931 112792556 68417469 779722934 921694415", "6\n169793171 335736854 449917902 513287332 811627074 938727967", "6\n509329 173849943 297546987 591032670 796346199 914588283", "25\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces
5897bd968f90d3c87e025d3df2080b70
Dominoes
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put *nm* dominoes on the table as an *n*<=×<=2*m* rectangle so that each of the *n* rows contained *m* dominoes arranged horizontall...
{"inputs": ["2 3\n01 11 00\n00 01 11", "4 1\n11\n10\n01\n00", "1 1\n00", "1 1\n01", "1 1\n11", "9 9\n01 00 00 01 00 01 11 11 11\n10 10 10 01 10 01 11 01 10\n10 00 10 00 11 01 00 10 00\n01 00 01 01 11 00 00 11 11\n11 00 10 11 01 01 11 00 01\n01 10 00 00 11 10 01 01 10\n11 10 11 00 11 11 01 10 10\n10 00 01 00 00 00 11 01...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
5898c00f01fa4b898400dca4b5772eea
Puzzles
Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit an...
{"inputs": ["7\n1 2 1 1 4 4", "12\n1 1 2 2 4 4 3 3 1 10 8", "3\n1 2", "8\n1 1 2 2 3 6 1", "85\n1 1 2 2 4 6 1 3 6 3 3 11 9 14 12 5 8 11 16 19 12 17 2 19 1 24 6 2 6 6 24 3 20 1 1 1 17 8 4 25 31 32 39 12 35 23 31 26 46 9 37 7 5 23 41 41 39 9 11 54 36 54 28 15 25 58 56 18 23 70 68 18 3 48 57 70 15 65 22 35 25 13 49 34", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
58a83557040dfdbc385a042906d45d1f
Wrong Subtraction
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
{"inputs": ["512 4", "1000000000 9", "131203 11", "999999999 50", "999999999 49", "131203 9", "900000000 16", "909090909 50", "1001 2", "5 2", "2 1"], "outputs": ["50", "1", "12", "9999", "99990", "130", "1", "3", "100", "3", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
428
codeforces
58af402ad60c89300051482d9084e5a8
Minimum Ternary String
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For e...
{"inputs": ["100210", "11222121", "20", "1002", "10", "000021", "021", "2", "201", "2112120", "102", "202", "220201", "12", "100022202", "01", "1"], "outputs": ["001120", "11112222", "20", "0012", "01", "000012", "012", "2", "120", "1112220", "012", "202", "122020", "12", "000122202", "01", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
151
codeforces
58bb01f8136f320b940058018a44f47c
Design Tutorial: Learn from Math
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
{"inputs": ["12", "15", "23", "1000000", "63874", "14568", "192", "86", "46220", "57114", "869", "738457", "58113", "4864", "15", "74752", "6073", "1289", "20", "58134", "57756", "765", "59", "991666", "70761", "13", "999999", "17", "21", "19", "100007", "999987", "22"], "outputs": ["4 8", "6 9", "8 15", "500000 500000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
597
codeforces
58c5d42231d8ef54d85d53c0d3311e95
Appleman and Toastman
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman...
{"inputs": ["3\n3 1 5", "1\n10", "10\n8 10 2 5 6 2 4 7 2 1", "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "10\n1 2 2 2 4 5 6 7 8 10", "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "1\n397870", "1\n1000000", "10\n10 8 7 6 5 4 2 2 2 1", "10\n892002 888642 724...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
503
codeforces
58c677856c4b02ac52a4fc953812e4cd
Longest Subsequence
You are given array *a* with *n* elements and the number *m*. Consider some subsequence of *a* and the value of least common multiple (LCM) of its elements. Denote LCM as *l*. Find any longest subsequence of *a* with the value *l*<=≤<=*m*. A subsequence of *a* is an array we can get by erasing some elements of *a*. It...
{"inputs": ["7 8\n6 2 9 2 7 2 3", "6 4\n2 2 2 3 3 3", "10 50\n39 22 60 88 11 65 41 85 65 100", "100 343\n999 284 486 785 176 742 856 415 992 601 600 122 460 214 338 92 627 913 376 835 384 914 335 179 409 957 96 784 531 43 584 206 971 799 592 801 870 978 437 517 466 952 1 327 731 689 816 681 383 969 452 298 114 687 314 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
58d9c92f6edcd490cef2fee5f38142a7
Weather
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther...
{"inputs": ["4\n-1 1 -2 1", "5\n0 -1 1 2 -5", "6\n0 0 0 0 0 0", "6\n-1 -2 -3 -4 5 6", "8\n1 2 -1 0 10 2 12 13", "7\n-1 -2 -3 3 -1 3 4", "2\n3 -5", "50\n4 -8 0 -1 -3 -9 0 -2 0 1 -1 0 7 -10 9 7 0 -10 5 0 1 -6 9 -9 3 -3 3 7 4 -8 -8 3 3 -1 0 2 -6 10 7 -1 -6 -3 -4 2 3 0 -4 0 7 -9", "90\n52 -89 17 64 11 -61 92 51 42 -92 -14 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
32
codeforces
58dd3c2180285dbfc243479705c44459
none
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one of the squares. Bertown has *n* squares, numbered from 1 to *n*, they are ...
{"inputs": ["5 2\n8\n2 4 5 3 1", "5 2\n8\n3 2 4 1 5", "5 4\n1000000000000000\n5 4 3 2 1", "10 1\n55\n45 55 61 64 95 95 98 96 65 81", "10 6\n462\n33 98 95 82 91 63 61 51 68 94", "10 4\n38080\n15 3005 4725 1952 8761 8797 9712 9752 9858 9128", "10 9\n46660\n724 2304 7793 7049 7847 5593 4685 7971 2701 5643", "100 50\n42431...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
58e042e2444f9dd4fa27b74cbe69e58f
Beautiful numbers
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges. The first line of the input contains the number ...
{"inputs": ["1\n1 9", "1\n12 15", "1\n25 53", "1\n1 1000", "1\n1 100000", "2\n234 59843\n46 3243", "4\n55 55\n1234 2348\n620 620\n4 1000", "1\n1 9000000000000000000", "5\n5397562498 1230483490253448\n39218765 5293867493184739\n99 999999999999\n546234 2394748365397856\n67 801834", "3\n1 1\n9000000000000000000 9000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
5905d6dd07b7ab56dc2b9a6790ab9061
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
{"inputs": ["8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
390
codeforces
59114d397555cf1a5a46cb976295c8dc
Vasily the Bear and Sequence
Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *...
{"inputs": ["5\n1 2 3 4 5", "3\n1 2 4", "3\n1 20 22", "10\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642", "30\n61 65 67 71 73 75 77 79 129 131 135 137 139 141 267 520 521 522 524 526 1044 1053 6924600 32125372 105667932 109158064 192212084 202506108 214625360 26007...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces