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
bed62bfd6378b367e3fe0617a419b84a
Save the problem!
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
{"inputs": ["18", "3", "314", "1023", "100000", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "239", "4063", "65536", "65535", "65537", "99991", "99990", "99992", "99971", "99990", "2", "99991"], "outputs": ["30 4\n1 5 10 25", "20 2\n5 2", "183 4\n6 5 2 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
beda8b32b0ec9b99868f00941d309d79
Tyndex.Brome
Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome! The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac...
{"inputs": ["2 10\ncodeforces\ncodeforces\ncodehorses", "9 9\nvkontakte\nvcontacte\nvkontrakte\nvkollapse\nvkrokodile\nvtopke\nvkapuste\nvpechke\nvk\nvcodeforcese", "3 3\nbyg\ndwg\nl\nx", "4 4\nlocw\na\nr\nba\nxuv", "5 5\nvpjjx\njj\ne\nnor\nuthm\nbf", "10 10\nczuanvzpiq\nc\ng\ni\nx\na\ny\nz\nk\nf\nx", "15 15\ndtpbfpabi...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
bee568ff74ad54cec8202b1f59786496
Physics Practical
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h...
{"inputs": ["6\n4 5 3 8 3 7", "4\n4 3 2 4", "6\n5 6 4 9 4 8", "4\n5 4 1 5", "2\n3 2", "10\n39 9 18 13 6 16 47 15 1 24", "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45", "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18", "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
71
codeforces
beedede080fa2c18f6b59e2bbe40ce40
Malek Dance Club
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n* members. Each member of MDC is assigned a unique id *i* from 0 to 2*n*<=-<=1. The same holds for eac...
{"inputs": ["11", "01", "1", "1111111111111111111111111111111111", "0000000000000000000000000000000000000", "11111111111111111111111111111111111000000000000000000000000000", "00000000000000000000111111111111111111111111111111111111111111", "10100101000010011110101011011110001", "0101010000101011111100111100100010101001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
bf3e927823c777d2ef7bd32bc83e59eb
Easter Eggs
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s...
{"inputs": ["8", "13", "7", "10", "14", "50", "9", "11", "12", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "28", "29", "34", "43", "61", "79", "81", "92", "95", "96", "97", "98", "99", "100"], "outputs": ["ROYGBIVG", "ROYGBIVOYGBIV", "ROYGBIV", "ROYGBIVYGB", "ROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBI...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
274
codeforces
bf4dd0423ecea20ddef0b68b094f200c
Holiday Of Equality
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
{"inputs": ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12", "3\n1 2 3", "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 24154...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1,122
codeforces
bf66bc37c82f2c30ec50a774ce6d0932
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-...
{"inputs": ["3\n1 2 1", "5\n20 4 3 2 1", "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086", "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194", "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 63849...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
bf68fad205ecadb130b7e87b5aac8a68
Chris and Road
And while Mishka is enjoying her trip... Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend. Once walking with his friend, John gave Chris the following proble...
{"inputs": ["5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4", "3 3 5 2\n3 1\n4 0\n5 1", "3 3 2 4\n0 1\n2 1\n1 2", "3 3 1 1\n0 0\n1 1\n0 2", "9 10 5 2\n22 5\n25 0\n29 0\n31 2\n32 5\n31 8\n29 10\n25 10\n23 8", "10 10 2 4\n-4 5\n-3 2\n-1 0\n3 0\n5 2\n6 5\n5 8\n3 10\n-1 10\n-2 9", "10 10 1 4\n-1 5\n0 2\n2 0\n5 0\n7 1\n9 5\n8 8\n6 10\n2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
bf78b5d20ae69dfbd2374b041a0e3b55
Valera and Tubes
Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*). Valera w...
{"inputs": ["3 3 3", "2 3 1", "2 3 1", "300 300 2", "300 300 150", "300 299 299", "300 300 45000", "300 299 44850", "2 2 2", "2 3 3", "3 3 4", "5 5 12", "7 5 17", "135 91 4352", "32 27 153", "74 83 2667", "296 218 5275", "89 82 2330", "15 68 212", "95 4 177", "60 136 8", "91 183 7827", "2 15 3", "139 275 10770", "114 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
91
codeforces
bf841357522a9a2799b0b9ada43e47dd
Ksusha and Array
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! The first line contains integer ...
{"inputs": ["3\n2 2 4", "5\n2 1 3 1 6", "3\n2 3 5", "1\n331358794", "5\n506904227 214303304 136194869 838256937 183952885", "2\n500000000 1000000000", "2\n4 6", "5\n10 8 6 4 2", "2\n6 10", "1\n1000000000", "2\n6 8", "5\n2 2 2 2 1000000000", "2\n6 4"], "outputs": ["2", "1", "-1", "331358794", "-1", "500000000", "-1", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
187
codeforces
c008ffb743cb2d9e14ef24a4fd1394ae
Mages and Monsters
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values *x**i* and *y**i* — damage per second and mana cost per second, respectivel...
{"inputs": ["3 100\n1 4 9\n2 19 49\n2 19 49", "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "2 424978864039\n2 7 3\n2 10 8", "3 10\n1 1 1\n2 1 1\n2 999999 999999", "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c01e2b377cf5803a3db4c18e169a42d5
Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores *t* points, he wins the set; then the ...
{"inputs": ["5\n1 2 1 2 1", "4\n1 1 1 1", "4\n1 2 1 2", "8\n2 1 2 1 1 1 1 1", "14\n2 1 2 1 1 1 1 2 1 1 2 1 2 1", "10\n1 1 2 2 1 1 2 2 1 1", "20\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1", "186\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c0315ec500973071a258e2b530a085a5
Maxim Buys an Apartment
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale. Maxim often visi...
{"inputs": ["6 3", "10 1", "10 9", "8 0", "8 8", "966871928 890926970", "20 2", "1 0", "1 1", "2 0", "2 1", "2 2", "7 2", "8 3", "9 4", "10 3", "10 4", "10 5", "1000 1000", "1000 333", "1000 334", "999 333", "999 334", "998 332", "998 333", "89 4", "66 50", "88 15", "95 43", "900 344", "777 113", "964 42", "982 867", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
82
codeforces
c0519a7dc6f0c45ebc244c6c22cec56d
Max History
You are given an array *a* of length *n*. We define *f**a* the following way: - Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=≤<=*i*<=≤<=*n* if *a**M*<=&lt;<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*. Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 1...
{"inputs": ["2\n1 3", "3\n1 1 2", "6\n1 4 5 2 3 3", "8\n8 7 5 4 6 6 6 6", "8\n1 2 3 9 100 100 100 100", "1\n364489807", "1\n194945396", "9\n25401015 88843847 702650194 306965770 57623156 571088345 835502151 56113403 116176210", "3\n855856619 518546431 920370158", "7\n686312223 948248999 138090108 566544521 711825575 41...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
c05fc5f9b4c21dc89887cfb96b7400ea
Colored Balls
There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that: - each ball belongs to exactly one of the sets, - there are no empty sets, - there is no ...
{"inputs": ["3\n4 7 8", "2\n2 7", "1\n1", "1\n1000000000", "2\n1000000000 1", "2\n9 6", "2\n948507270 461613425", "5\n8 7 4 8 3", "5\n11703 91351 99 16279 50449", "20\n3 2 1 1 1 2 2 2 3 3 1 1 3 2 3 3 2 3 3 2", "20\n895 8894 6182 5852 9830 7562 8854 4004 5909 4979 6863 2987 3586 1319 513 5496 9543 9561 6590 5063", "200\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c086d2e71d8091df7b4eef2dd781beec
Valera and Number
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below: Now Valera wonders: given the values *x*, *k* and *p*, what is the expected value of the resulting number *s*? The first line of the input contains three integers *x*,<=*k*,<=*p* (1<=≤<=*x*<=≤<=109; 1<=≤<=*k*<=≤<=200...
{"inputs": ["1 1 50", "5 3 0", "5 3 25", "1132123 200 0", "1213112 200 100", "490879136 12 75", "114566801 2 55", "331870050 6 98", "252615193 9 45", "224314221 19 51", "510823354 20 18", "573292218 200 77", "465672965 100 95", "853095531 50 72", "254290166 200 95", "206910020 200 4", "680841078 112 48", "92021679 54 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c08a7770e7aaa6e439fb7923a9c9b201
Two Melodies
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with *n* notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal....
{"inputs": ["4\n1 2 4 5", "6\n62 22 60 61 48 49", "2\n1 4", "2\n5 4", "10\n9 6 8 5 5 2 8 9 2 2", "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333", "10\n1 1 1 1 1 1 1 1 1 1", "4\n15 11 28 17", "3\n1 36 6", "6\n3 12 4 12 5 6", "6\n7 20 21 22 23 28"], "outputs": ["4", "5", "2", "2", "9", "6", "10", "2", "3",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c0a0039fbe76bdb7d48cb9d1f504232e
System Administrator
Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair o...
{"inputs": ["5 6 3", "6 100 1", "10 26 1", "20 155 1", "30 393 29", "50 535 8", "100 4283 65", "1000 51277 488", "10000 57971 8854", "100000 99999 41895", "99999 100000 66180", "99997 99997 72727", "100000 100000 100000", "100000 100000 1", "100000 99999 100000", "100000 99999 1", "100000 99998 100000", "100000 99998 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
c0c1479e7ce5028f5eaa529aedd3e85c
Bars
Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can eit...
{"inputs": ["3 3\n010", "8 3\n01010110", "9 5\n001100110", "2 2\n00", "3 2\n010", "3 2\n000", "3 3\n000", "4 2\n0000", "4 2\n0100", "4 2\n0010", "4 2\n0110", "4 3\n0000", "4 3\n0010", "4 3\n0100", "4 3\n0110", "4 4\n0000", "4 4\n0100", "4 4\n0010", "4 4\n0110", "10 3\n0111011010", "100 19\n00110111100111111110101111011...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c0c31df16741dd7d0059f2a9ec8f3864
Super Agent
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
{"inputs": ["XX.\n...\n.XX", ".X.\n.X.\n.X.", "XXX\nXXX\nXXX", "XXX\nX.X\nXXX", "X..\n.X.\n..X", "...\nX.X\nX..", ".X.\nX.X\n.X.", "X.X\n.X.\nX.X", "...\n...\n..X", "XXX\n...\nXXX", "..X\nX..\n..X", ".X.\n...\nX.X", "X.X\nX.X\nX.X", ".X.\nX.X\nXX.", "...\nXXX\nXXX", "XXX\n..X\nXXX", "X..\nX.X\n.X.", "...\n..X\nXXX", "....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
320
codeforces
c0f901607f527b8e6f3e00116e7c7ab4
Petya and Square
Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not ha...
{"inputs": ["4 1 1", "2 2 2", "8 2 5", "6 1 6", "2 1 1", "2 1 2", "2 2 1", "4 2 2", "4 2 3", "4 2 4", "60 30 30", "60 34 30", "60 31 29", "100 61 30", "100 52 50", "100 51 51", "100 1 2", "100 1 8", "100 19 99", "100 18 82", "100 100 50", "100 51 100", "100 100 100", "6 3 3", "6 4 4", "6 3 1", "6 3 5", "8 4 4", "6 3 2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c1099b4137bcb0dc819f8df0ea6630c3
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge)....
{"inputs": ["3 3\n2 1 9", "4 20\n10 3 6 3", "1 1000000000\n1", "1 1\n3", "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
c11ed3f7cf93b87239cbf0e5d6a42e5b
Alyona and Numbers
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
{"inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21", "10 15", "1 1", "1 1000000", "1000000 1", "1000000 1000000", "944 844", "368 984", "792 828", "920 969", "640 325", "768 170", "896 310", "320 154", "744 999", "630 843", "54 688", "478 828", "902 184", "31 29", "751 169", "879 14", "7 858", "431 702", "855 355...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
371
codeforces
c12241ccb6ccd236b53aeca845120461
Ciel and Duel
Fox Ciel is playing a card game with her friend Jiro. Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the follo...
{"inputs": ["2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "1 1\nATK 100\n99", "4 8\nDEF 100\nDEF 200\nDEF 300\nATK 100\n100\n101\n201\n301\n1\n1\n1\n1", "3 4\nDEF 100\nATK 200\nDEF 300\n101\n201\n301\n1", "4 4\nDEF 0\nDEF 0\nDEF 0\nATK ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c15f635616d643c4688b14322dc81920
Amr and Music
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for ...
{"inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4", "2 100\n100 100", "3 150\n50 50 50", "4 0\n100 100 100 100", "100 7567\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...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
192
codeforces
c1728962a6cce0de630f0372867289aa
Game Shopping
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
{"inputs": ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "5 1\n1 1 1 1 1\n5", "5 1\n10 1 1 1 1\n1000", "5 1\n100 100 100 100 100\n100", "2 1\n2 1\n1", "2 3\n3 1\n2 4 2", "1 5\n4\n1 4 3 3 2", "5 3\n4 2 3 1 1\n2 1 3", "3 5\n5 2 5\n1 4 1 4 2", "7 3\n9 7 10 2 1 1 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
321
codeforces
c1a730423f27fa14659fb6ff4387706b
Looking for Order
Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl canno...
{"inputs": ["0 0\n2\n1 1\n-1 1", "1 1\n3\n4 3\n3 4\n0 0", "-3 4\n1\n2 2", "7 -7\n2\n3 1\n-3 8", "3 -9\n3\n0 -9\n-10 -3\n-12 -2", "4 -1\n4\n14 -3\n-11 10\n-3 -5\n-8 1", "7 -11\n5\n-1 7\n-7 -11\n12 -4\n8 -6\n-18 -8", "11 3\n6\n-17 -17\n-4 -9\n15 19\n7 4\n13 1\n5 -6", "-6 4\n7\n-10 -11\n-11 -3\n13 27\n12 -22\n19 -17\n21 -...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
c1e7da4ca3f099a03821e7eefe9f889b
Ilya and Escalator
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue en...
{"inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2", "2000 0.61 2000", "100 1.00 200", "417 0.57 742", "100 0.01 53", "300 0.05 55", "1400 0.02 200", "2000 0.01 234", "1 0.01 2000", "300 0.99 1000", "400 0.96 1754", "2000 0.93 100", "1000 0.90 1733", "1 1.00 1", "2000 1.00 2000", "2000 0.00 2000", "2000 0.01 2000", "2000 0....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
c20295e447351fec89195b82e112921a
Preparing Olympiad
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contes...
{"inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20", "4 15 60 10\n10 20 30 25", "1 10 20 1\n15", "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
c238239f5c75f82bf35be066d8493e38
Sonya and Queries
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b...
{"inputs": ["12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "4\n+ 200\n+ 200\n- 200\n? 0", "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
c24a81f69a8987d5a513e4987cd9b6b9
Arpa’s obvious problem and Mehrdad’s terrible solution
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad di...
{"inputs": ["2 3\n1 2", "6 1\n5 1 2 3 4 1", "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
c25593723134889d759fd6786d906c97
none
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ...
{"inputs": ["5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
c25b6da41baeb504d209ee704414dbfc
Area of a Star
It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star. A "star" figure having *n*<...
{"inputs": ["7 10", "5 1", "7 1000", "11 1000000000", "999999937 1", "999999929 2", "999999929 1000000000", "603530531 585244", "7369339 31415926", "2341 5001"], "outputs": ["108.395919545675", "1.122569941449", "1083959.195456745256", "1061689977712182980.125000000000", "1.047197551197", "4.188790204786", "10471975511...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c261497be852ac543fbe17bd9a243b60
Vulnerable Kerbals
You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1. You would like to construct a sequence satisfying the properties: - Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m*...
{"inputs": ["0 5", "3 10\n2 9 1", "0 1", "0 720", "0 9997", "0 200000", "10 200000\n7853 79004 71155 23846 63333 31964 47634 15792 39758 55551", "3 19997\n4524 13719 9073", "3 19997\n2024 4058 6143", "3 19997\n6068 18563 12338"], "outputs": ["5\n1 2 4 3 0", "6\n3 9 2 9 8 0", "1\n0", "397\n1 7 413 263 389 467 77 283 299...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c27368c56a4d9ea1647917157aef81aa
Check the string
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
{"inputs": ["aaabccc", "bbacc", "aabc", "aabbcc", "aaacccbb", "abc", "acba", "bbabbc", "bbbabacca", "aabcbcaca", "aaaaabbbbbb", "c", "cc", "bbb", "bc", "ccbcc", "aaa", "aaccaa", "a", "b", "abca", "aabbcccc", "abac", "abcc", "abcb", "aacc", "aabbaacccc", "aabb", "ac", "abbacc", "abacc", "ababc", "aa", "aabaccc", "bbcc",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
120
codeforces
c28cf0add33a4e63ce6077ddf93bd7e9
Devu, the Dumb Guy
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
{"inputs": ["2 3\n4 1", "4 2\n5 1 2 1", "3 3\n1 1 1", "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3", "1 1\n9273", "1 1\n1", "1 2\n1", "1 2\n2", "2 1\n1 2"], "outputs": ["11", "10", "6", "65", "196", "9273", "1", "2", "4", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
299
codeforces
c2a566fe43974d07b567fd3c0e438366
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $Ox$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $Ox$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recently, ...
{"inputs": ["4\n-5 R\n0 P\n3 P\n7 B", "5\n10 R\n14 B\n16 B\n21 R\n32 R", "10\n66 R\n67 R\n72 R\n73 R\n76 R\n78 B\n79 B\n83 B\n84 B\n85 P", "10\n61 R\n64 R\n68 R\n71 R\n72 R\n73 R\n74 P\n86 P\n87 B\n90 B", "15\n-9518 R\n-6858 P\n-6726 B\n-6486 R\n-4496 P\n-4191 P\n-772 B\n-258 R\n-194 P\n1035 R\n2297 P\n4816 B\n5779 R\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
c2d5c5716d620d4c3e6264bef5bdc57b
Wizards and Trolleybuses
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of *d* meters from the depot. We know for the *i*-th trolleybus that ...
{"inputs": ["3 10 10000\n0 10\n5 11\n1000 1", "1 2 26\n28 29", "7 8 3\n1 3\n5 26\n7 3\n10 15\n18 7\n21 17\n23 21", "3 6 6\n2 10\n14 19\n18 14", "10 7 8\n2 4\n3 13\n4 7\n5 1\n9 16\n10 9\n12 18\n16 4\n17 16\n20 6", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12", "1 2 7\n20 13", "3 3 3\n13 1\n18 12\n19 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
c2fb46bcb0c07141a390386eb43d17e6
Success Rate
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
{"inputs": ["4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2", "5\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
55
codeforces
c305e3530a54f2ea0d43187252188974
Game of Stones
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: - The game starts with *n* piles of stones indexed from 1 to *n*. The *i*-th pile contains *s**i* stones.- The players make their moves alternatively. A...
{"inputs": ["1\n5", "2\n1\n2", "3\n34\n44\n21", "6\n34\n44\n21\n55\n1\n36", "14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32", "10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59", "12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40", "118\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c32aecaf273108e539a4710735fff11f
Gosha is hunting
Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Poke...
{"inputs": ["3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443", "8 4 1\n0.425 0.709 0.507 0.932 0.085 0.389 0.215 0.508\n0.471 0.825 0.240 0.981 0.184 0.241 0.810 0.711", "7 4 4\n0.642 0.036 0.552 0.936 0.866 0.905 0.40...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c33a7c4403551ca5163e14847cc720c9
Bus of Characters
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
{"inputs": ["2\n3 1\n0011", "6\n10 8 9 11 13 5\n010010011101", "1\n1\n01", "1\n1000000\n01", "2\n1 1000000\n0011", "2\n1000000000 1\n0101", "2\n1000000000 999999999\n0011", "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111"], "outputs": ["2 1 1 2 ", "6 6 2 3 3 1 4 4 1 2 5 5 ", "1 1 ", "1 1 ", "1 2 2 1 ", "2 2 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
c33ee1ebed2d67a1fc93b05bf3e8b65a
Eugeny and Play List
Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then son...
{"inputs": ["1 2\n2 8\n1 16", "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9", "3 3\n2 8\n5 1\n10 5\n13 16 62", "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85", "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177", "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265", "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 11...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
100
codeforces
c34576ad4cc651a3744cc85ae9b0a608
Replace To Make Regular Bracket Sequence
You are given string *s* consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;. The following d...
{"inputs": ["[<}){}", "{()}[]", "]]", ">", "{}", "{}", "{]", "{]", "{]", "[]{[]({)([", "(([{>}{[{[)]]>>]", "((<>)[]<]><]", "[[([[(>]>)))[<)>", "({)[}<)](}", "(}{)[<][)(]}", ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([", "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
73
codeforces
c35efd66426b5bd961aa720f0ee29dcb
Guilty --- to the kitchen!
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of *n* ingredients that have to be mixed in prop...
{"inputs": ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60", "2 100\n1 1\n50 50", "2 100\n1 2\n33 66", "3 10000\n1 1 1\n100 0 100", "7 5100\n21 93 52 80 5 46 20\n79 37 74 54 22 15 90", "10 2707\n80 91 41 99 99 48 81 25 80 17\n88 79 64 78 4 54 38 92 77 61", "19 8111\n44 75 80 69 90 64 58 8 93 50 44 39 7 25 14 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
c3b0f25282825914e3165f036647ca3b
Wrath
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
{"inputs": ["4\n0 1 0 10", "2\n0 0", "10\n1 1 3 0 0 0 2 1 0 3", "10\n0 0 2 0 0 3 3 2 2 0", "1\n0", "5\n0 0 0 1 0", "6\n3 1 1 0 3 3", "8\n0 0 0 1 0 0 1 2", "1\n1000000000", "2\n1 3", "2\n1000000000 1000000000", "11\n1 0 0 1 1 3 2 0 0 2 3", "1\n1"], "outputs": ["1", "2", "3", "2", "1", "4", "1", "5", "1", "1", "1", "4", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
206
codeforces
c3caabd20656dfea798193d9f8828c62
bHTML Tables Analisys
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML ...
{"inputs": ["<table><tr><td></td></tr></table>", "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></t...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c3d790805eede963d52bb39905c572fe
Queries about less or equal elements
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second lin...
{"inputs": ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5", "1 1\n-1\n-2", "1 1\n-80890826\n686519510", "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -9296...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
241
codeforces
c3f6f1b2d8283ce5173cfcc44bb75b45
Intersection
You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0. Write the program which finds the number of points in the intersection of two given sets. The first line of the input con...
{"inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0", "0 0 0\n0 0 0", "1 1 1\n1 1 1", "8 3 -4\n-5 2 7", "-1 -1 0\n0 -1 -1", "-1 -1 0\n1 1 -1", "-1 -1 1\n0 -1 0", "0 0 0\n1 -1 -1", "0 0 1\n-1 1 -1", "0 1 -1\n-1 1 -1", "1 0 -1\n0 0 -1", "0 1 1\n1 0 0", "1 0 0\n0 0 1", "1 -1 -1\n1 -1 0", "1 0 0\n0 1 1", "1 -1 1\n-1 -1 1", "1 0 0\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
c3fb39355574a7e1da59bd733c53c45c
Parallelepiped
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. The first and the single line contains three space-separated integers — the areas of the parallelepiped's fa...
{"inputs": ["1 1 1", "4 6 6", "20 10 50", "9 4 36", "324 9 36", "1333 93 129", "1022 584 112", "66 174 319", "912 276 1748", "65 156 60", "1 10000 10000", "1485 55 27", "152 108 4104", "1656 6900 1350", "12 14 42", "615 18 1230", "680 60 408", "644 966 6", "1 432 432", "2239 2239 1", "4106 8212 2", "10000 10000 10000",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
622
codeforces
c405d7dde8cef7bb4e1c964e697aa3e5
T-Shirt Hunt
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination r...
{"inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900", "264 19252 10888", "176 9670 9174", "42 11 6", "412 17647 15917", "91 4883 4302", "200 16031 15842", "186 18666 18329", "486 9748 9598", "180 4213 4207", "329 19989 1", "390 11676 2570", "173 7017 4512", "38 6404 5034", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
c40e9d6ff14b79d32f1975a0c3702047
Dima and Staircase
Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i...
{"inputs": ["5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "3\n1 2 3\n2\n1 1\n3 1", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "8\n6 10 18 23 30 31 31 33\n1\n5 3", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2", "5\n4 7 10 12 12\n9\n3 9\n2 1\n3 5\n4 7\n1 1\n5 1\n1 7\n2 4\n4 10", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6", "3\n2 10 15\n1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
c428cb3795453c6365d8f87de077feb5
Mike and palindrome
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
{"inputs": ["abccaa", "abbcca", "abcda", "kyw", "fccf", "mnlm", "gqrk", "glxlg", "czhfc", "broon", "rmggmr", "wvxxzw", "ukvciu", "vrnwnrv", "vlkjkav", "guayhmg", "lkvhhvkl", "ffdsslff", "galjjtyw", "uosgwgsou", "qjwmjmljq", "ustrvrodf", "a", "qjfyjjyfjq", "ysxibbixsq", "howfslfwmh", "ekhajrjahke", "ucnolsloncw", "jrzsf...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
163
codeforces
c471ea63a38a1fc6ba0d6161cb75b220
Bertown Subway
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station...
{"inputs": ["3\n2 1 3", "5\n1 5 4 3 2", "1\n1", "2\n1 2", "2\n2 1", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
c481daf3fd61e80e4acb7dd5b3b0ad8b
EKG
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native ...
{"inputs": ["6 1\n2 0 4 0 6 0", "6 2\n2 3 0 5 6 0", "4 1\n0 0 0 0", "6 2\n0 0 1 0 4 5", "10 7\n10 8 6 5 0 0 0 4 3 9", "10 1\n8 7 0 2 0 10 0 0 3 5", "10 4\n0 1 4 2 7 0 10 0 5 8", "10 2\n0 7 0 10 8 0 4 2 3 0", "10 2\n10 0 9 0 0 4 2 6 8 0", "10 7\n7 9 2 10 0 0 0 3 5 1", "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"], "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c490d53ce60b1d95c8f1965c603a15cd
Challenge Pennants
Because of budget cuts one IT company established new non-financial reward system instead of bonuses. Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting...
{"inputs": ["2", "1", "3", "4", "5", "6", "7", "12", "28", "43", "139", "321", "100", "498", "500"], "outputs": ["24", "1", "210", "1120", "4410", "14112", "38808", "1589952", "817586560", "21766594410", "212332162372330", "163013183025830865", "15789964684000", "5392730685240975000", "5567867859752100000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c4925395433ef9f0418e15736bd8532f
Squares
Vasya has found a piece of paper with a coordinate system written on it. There are *n* distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to *n*. It turned out that points with coordinates (0,<=0) and (*a**i*,<=*a**i*) are the opposite corners of the *i*-th square. Vasya wa...
{"inputs": ["4 3\n5 1 3 4", "3 1\n2 4 1", "4 50\n5 1 10 2", "3 4\n5 1 4", "1 1\n2", "1 2\n10", "10 5\n68 78 70 3 77 2 24 17 96 63", "5 2\n10 9 19 12 14", "2 2\n7 2", "2 1\n8 20", "2 40\n33 29", "5 10\n7 5 9 10 8", "9 8\n83 6 90 96 42 71 11 82 51", "40 30\n115644639 84968781 502201719 185562964 985439338 904909761 98746...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c49fbe44ec18bf074af51a7b17df7ae3
Maze
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a...
{"inputs": ["5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "3 3 2\n#.#\n...\n#.#", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "1 1 0\n.", "2 3 1\n..#\n#..", "2 3 1\n#..\n..#", "3 3 1\n...\n.#.\n..#", "3 3 1\n...\n.#.\n#..", "5 4 4\n#..#\n....\n.##.\n....\n#..#", "5 5 2\n.#..#\n..#.#\n#....\n##.#.\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces
c4a1a34f497ee40fd471d8de5b3c962b
Lightsabers (medium)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th...
{"inputs": ["8 3\n3 3 1 2 2 1 1 3\n3 1 1", "6 5\n1 2 4 2 4 3\n0 0 1 0 0", "1 1\n1\n1", "2 1\n1 1\n1", "2 1\n1 1\n2", "2 2\n1 2\n1 1", "2 2\n2 2\n1 1", "3 3\n3 3 2\n0 0 1", "4 4\n4 4 4 4\n0 1 1 1", "2 2\n1 1\n1 0", "3 3\n3 3 3\n0 0 1", "4 4\n2 4 4 3\n0 1 0 0", "2 2\n2 1\n0 1", "3 3\n3 1 1\n1 1 1", "4 4\n1 3 1 4\n1 0 0 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
c4ad62bddbc94c55cc70b08762937167
Bombs
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point w...
{"inputs": ["2\n1 1\n-1 -1", "3\n5 0\n0 5\n1 0", "1\n-277226476 314722425", "2\n-404192496 -968658337\n556071553 -256244640", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2"], "outputs": ["12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
c4b0d56e3f40a886b55753344382562d
Minimization
You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*. You need to permute the array elements so that value The first line contains two integers *n*,<=*k* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=*min*(5000,<=*n*<=-<=1)). The second line contains *n* i...
{"inputs": ["3 2\n1 2 4", "5 2\n3 -5 3 -5 3", "6 3\n4 3 4 3 2 5", "2 1\n1 100", "4 3\n1 2 4 8", "5 2\n1 2 8 8 16", "10 3\n-999999914 -999999976 -999999966 -999999952 29 54 -999999963 -999999959 -999999974 48", "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -999...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c4dd3e1e06a63ef2153e3968b846c4ce
Really Big Numbers
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different...
{"inputs": ["12 1", "25 20", "10 9", "300 1000", "500 1000", "1000 2000", "10000 1000", "1000000000000000000 1000000000000000000", "1000000000000000000 100000000000000000", "1000000000000000000 10000000000000000", "1000000000000000000 1000000000000000", "1000000000000000000 100000000000000", "1000000000000000000 200000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
89
codeforces
c4ed979e1e7dc2e04476df656d461770
Square Table
While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=×<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each ...
{"inputs": ["1 1", "1 2", "4 1", "1 4", "2 1", "2 4", "48 2", "3 75", "33 1", "4 23", "58 2", "2 11", "7 14", "48 24", "77 93", "77 20", "30 31", "100 100"], "outputs": ["1 ", "3 4 ", "1 \n1 \n1 \n1 ", "1 1 1 1 ", "3 \n4 ", "3 3 3 3 \n4 4 4 4 ", "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
c4f24bad678c0dc44f16444d1931b0f5
Currency System in Geraldion
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
{"inputs": ["5\n1 2 3 4 5", "1\n2", "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
304
codeforces
c50b1b965f540f3178cb912f00fd25cf
Spyke Talks
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session numbe...
{"inputs": ["6\n0 1 7 1 7 10", "3\n1 1 1", "1\n0", "5\n2 2 1 1 3", "1\n1", "10\n4 21 3 21 21 1 1 2 2 3", "2\n1 2", "5\n0 0 0 0 0", "6\n6 6 0 8 0 0", "10\n0 0 0 0 0 1 0 1 0 1", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
c544dbf38e7f9a8e6286d2e4f208c1e3
Puzzles
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od...
{"inputs": ["4 6\n10 12 10 7 5 22", "2 2\n4 4", "2 10\n4 5 6 7 8 9 10 11 12 12", "4 5\n818 136 713 59 946", "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "4 25\n226 790 628 52...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
385
codeforces
c58eac4bb58780bf424ac77f4fb18275
Physical Education and Buns
The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression. To achieve the goal, the gym teacher ordered a lot of magical buns from the dining ...
{"inputs": ["5\n-3 -4 -2 -3 3", "5\n2 -3 -1 -4 3", "6\n94 65 -33 -43 60 -24", "3\n-10000 10000 -10000", "2\n0 0", "7\n-1 -2 -4 -10 6 6 5", "10\n-10 3 -16 -15 14 -16 13 -6 -8 18", "50\n-67 -84 -89 80 40 42 -38 30 74 -12 -66 27 1 11 -45 -44 2 -70 -59 -70 -59 -59 62 100 -5 1 91 79 47 -64 -51 -88 -5 37 82 87 79 46 76 47 60...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c597f61ed8d5dea2daccb09176049488
Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
{"inputs": ["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "1\n-5 -90", "2\n315 845\n-669 -762", "3\n8911 7861\n-6888 7861\n8911 7861", "2\n-1 1000000000\n0 -1", "2\n1000000000 0\n-7 1", "2\n1 4\n2 1", "2\n1 0\n0 2333333", "2\n2 1\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
194
codeforces
c59ca7de6700cc5a4c83078af6170202
The Monster and the Squirrel
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other v...
{"inputs": ["5", "3", "54321", "4", "6", "7", "8", "9", "10", "54320", "54319", "54318", "54317", "54316", "54315", "54314", "8153", "51689", "16659", "47389", "314", "23481", "20380", "1994"], "outputs": ["9", "1", "2950553761", "4", "16", "25", "36", "49", "64", "2950445124", "2950336489", "2950227856", "2950119225",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
113
codeforces
c5ae15dcd5da50929da25698093ceacc
Second Order Statistics
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
{"inputs": ["4\n1 2 2 -4", "5\n1 2 3 1 1", "1\n28", "2\n-28 12", "3\n-83 40 -80", "8\n93 77 -92 26 21 -48 53 91", "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
442
codeforces
c5c5681c6f810bdbc9e8ce105d24d625
Round Subset
Let's call the roundness of the number the number of zeros to which it ends. You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<...
{"inputs": ["3 2\n50 4 20", "5 3\n15 16 3 25 9", "3 3\n9 77 13", "1 1\n200000000", "1 1\n3", "3 1\n1000000000000000000 800000000000000000 625", "20 13\n93050001 1 750000001 950000001 160250001 482000001 145875001 900000001 500000001 513300001 313620001 724750001 205800001 400000001 800000001 175000001 875000001 8526860...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c5ca3ab2eac89426a9d116a1fd9ce067
Little Girl and Maximum Sum
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)...
{"inputs": ["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "16 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
c5ea6b1be53adf0faf640c2b06b4178e
Seating On Bus
Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*. Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to...
{"inputs": ["2 7", "9 36", "1 1", "1 4", "10 1", "10 10", "10 40", "10 39", "77 1", "77 13", "77 53", "77 280", "100 1", "100 13", "100 77", "100 103", "100 200", "100 199", "100 201", "100 300", "100 399", "100 400", "3 9"], "outputs": ["5 1 6 2 7 3 4", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
c5f46d86f67634da80c5333c585ae150
Phone Numbers
And where the are the phone numbers? You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*. It's guaranteed...
{"inputs": ["3 3\nabc", "3 2\nabc", "3 3\nayy", "2 3\nba", "1 3\nf", "3 1\nazz", "3 3\nzbf", "2 3\ngi", "3 2\nyzy", "5 10\nkekff", "10 5\nhqqqqcdddb", "10 10\nmrfkcsxcuj", "10 3\nggjnohlepu", "8 9\npppppppp", "10 7\nffffffffyf", "10 2\nkmiejhcimj", "10 1\ngiwekrmngf", "8 8\nlolololo", "10 9\nbcegikmyyy", "7 5000\nqqqqq...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
57
codeforces
c60017dd2b08478f814800ebfa6f9f27
Guess Your Way Out! II
Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such t...
{"inputs": ["3 1\n3 4 6 0", "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "4 2\n3 4 6 1\n4 12 15 1", "4 2\n3 4 5 1\n2 3 3 1", "1 0", "1 1\n1 1 1 0"], "outputs": ["7", "14", "Data not sufficient!", "Game cheated!", "1", "Game cheated!"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c64702b7496904c374deec17f72e5c05
Odd sum
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequen...
{"inputs": ["4\n-2 2 -3 1", "3\n2 -5 -3", "1\n1", "1\n-1", "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "2\n-5439 -6705", "2\n2850 6843", "2\n144 9001", "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "10\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
102
codeforces
c6729c66bbbfd7bb2760347f9870b5b0
Sum of Remainders
Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7). The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1. Th...
{"inputs": ["3 4", "4 4", "1 1", "20000000 10000000", "10000000000000 10000000000000", "1 10000000000000", "10000000000000 1", "100 100", "1000 1000", "500 1000", "1010 435", "997167959139 7344481199252", "7244641009859 6300054748096", "3483524125987 5259923264237", "9726702209411 4215496813081", "5965585325539 3175365...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c6cb6358e37594008f8beb2f16fd86b0
Kindergarten
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maxim...
{"inputs": ["5\n1 2 3 1 2", "3\n3 3 3", "1\n0", "2\n-1000000000 1000000000", "4\n1 4 2 3", "4\n23 5 7 1", "4\n23 7 5 1", "8\n23 2 7 5 15 8 4 10", "8\n4 5 3 6 2 7 1 8"], "outputs": ["3", "0", "0", "2000000000", "4", "24", "22", "37", "16"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c6e9fbfb051ff01b6a80e52bde08d396
LCM Challenge
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ...
{"inputs": ["9", "7", "1", "5", "6", "33", "21", "2", "41", "29", "117", "149", "733", "925", "509", "829", "117", "605", "245", "925", "213", "53", "341", "21", "605", "149", "733", "117", "53", "245", "829", "924", "508", "700", "636", "20", "604", "796", "732", "412", "700", "244", "828", "508", "796", "636", "924",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
122
codeforces
c6fc6efb4116f26068ba51942a03faac
Mahmoud and Ehab and the xor
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to...
{"inputs": ["5 5", "3 6", "3 0", "1 0", "3 3", "100000 41243", "100000 100000", "32 32", "32 31", "1 1", "2 0", "3 1", "3 2", "3 5", "3 4", "3 10203", "3 10100", "5 0", "5 1", "5 2", "5 3", "5 4", "5 6", "5 7", "5 8", "5 9", "100000 1", "100000 0", "100000 21323", "100000 65536", "100000 65537", "100000 65535", "4 2", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
c71255b01a479ab3650e790fad56511a
Fire Again
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing...
{"inputs": ["3 3\n1\n2 2", "3 3\n1\n1 1", "3 3\n2\n1 1 3 3", "1 1\n1\n1 1", "2 2\n1\n2 2", "2 2\n2\n1 1 2 1", "2 2\n3\n1 2 2 1 1 1", "2 2\n4\n2 1 2 2 1 1 1 2", "10 10\n1\n5 5", "10 10\n2\n7 8 1 9", "10 10\n3\n3 9 6 3 3 5", "10 10\n4\n5 3 4 7 7 5 8 5", "10 10\n5\n2 7 10 6 5 3 9 5 2 9", "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c73011b7f575e990667e991cae603566
Oath of the Night's Watch
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple...
{"inputs": ["2\n1 5", "3\n1 2 5", "4\n1 2 3 4", "8\n7 8 9 4 5 6 1 2", "1\n1", "1\n100", "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
198
codeforces
c7341b7a840763c95143df19e11cfce1
Oranges and Apples
In 2*N*<=-<=1 boxes there are apples and oranges. Your task is to choose *N* boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. The first input line contains one number *T* — amount of tests. The description of each test starts with a natural number *N* — am...
{"inputs": ["2\n2\n10 15\n5 7\n20 18\n1\n0 0"], "outputs": ["YES\n3 1\nYES\n1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c74fe8f7ab7e5d953a678609275967cc
Inna and New Matrix of Candies
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g...
{"inputs": ["3 4\n*G*S\nG**S\n*G*S", "1 3\nS*G", "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S", "5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****", "4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*", "4 10\n***G****S*\n*****GS*...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
101
codeforces
c7a543879506cdc6eb620e614597cc1f
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of *n* compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ...
{"inputs": ["5\n1 2 2 4 3", "3\n4 1 1", "4\n0 3 0 4", "5\n4 4 3 3 1", "5\n4 3 4 2 4", "10\n2 1 2 3 4 1 3 4 4 4", "10\n2 3 3 1 3 1 3 2 2 4", "120\n1 1 1 1 1 1 1 4 4 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 4 1 1 4 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
c7bebd7fa695c6aa741ee0b47480fe3f
Number Busters
Arthur and Alexander are number busters. Today they've got a competition. Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=&lt;<=*w*,<=0<=&lt;<=*x*<=&lt;<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each s...
{"inputs": ["4 2 3 1 6", "4 2 3 1 7", "1 2 3 2 6", "1 1 2 1 1", "1 0 1000 999 2000000000", "10 1 6 4 20", "10 3 6 5 30", "10 3 5 1 30", "10 32 312 72 1000", "1 102 123 27 2321", "2000000000 159 1000 870 2000000000", "200000000 794 1000 117 2000000000", "20000000 280 1000 25 2000000000", "1999999999 47 1000 527 20000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
c7e27805e59dc67395e03bd861fc9692
Playing with Permutations
Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*. A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct. There is only one thing Petya likes more than p...
{"inputs": ["4 1\n2 3 4 1\n1 2 3 4", "4 1\n4 3 1 2\n3 4 2 1", "4 3\n4 3 1 2\n3 4 2 1", "4 2\n4 3 1 2\n2 1 4 3", "4 1\n4 3 1 2\n2 1 4 3", "4 3\n4 3 1 2\n2 1 4 3", "4 3\n2 1 4 3\n4 3 1 2", "4 1\n2 1 4 3\n2 1 4 3", "4 2\n2 1 4 3\n2 1 4 3", "4 2\n2 3 4 1\n1 2 3 4", "5 3\n2 1 4 3 5\n2 1 4 3 5", "9 10\n2 3 1 5 6 7 8 9 4\n2 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c7e518f6e36784b468c9c07c49fe35b5
Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some...
{"inputs": ["2\naa", "4\nkoko", "5\nmurat", "6\nacbead", "7\ncdaadad", "25\npeoaicnbisdocqofsqdpgobpn", "25\ntcqpchnqskqjacruoaqilgebu", "13\naebaecedabbee", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "10\nbababbdaee", "11\ndbadcdbdbca", "12\nacceaabddaaa", "13\nabddfbfaeecfa", "14\neeceecacdbcbbb", "15\ndcbceaaggabaheb", "16\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
244
codeforces
c7e74819c84278ce098eec5e10bf0950
Harry Potter and the History of Magic
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ...
{"inputs": ["3\n1875\n1936\n1721", "4\n9999\n2000\n3000\n3011", "3\n1999\n5055\n2000", "2\n2037\n2025", "1\n1234", "1\n9876", "2\n9988\n8899", "3\n1095\n1094\n1095", "5\n5555\n4444\n3333\n2222\n1111", "3\n2010\n2011\n2012", "5\n1901\n1166\n1308\n1037\n1808", "5\n1612\n7835\n8183\n3368\n1685", "10\n1501\n1617\n1368\n173...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c81d5e4a49895d98aa46236e26ffe463
Ladder
You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=......
{"inputs": ["8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "1 1\n6\n1 1", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2", "10 10\n4 7 2 6 4 8 1 2 1 9\n6 10\n1 9\n9 9\n2 8\n9 9\n1 1\n8 8\n4 8\n8 8\n7 7", "7 5\n13 13 16 12 16 3 19\n2 7\n3 4\n7 7\n1 2\n4 7", "13 6\n2 6 1 3 5 2 2 1 6 4 2 5 2\n10 13\n4 10\n4 11\n3 5\n9 13\n3 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
c8591ab3dbd3135c5318ccccc83231f2
Yaroslav and Algorithm
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as *a*. 1. The algorithm consists of some number of command. Сommand number *i* looks either as *s**i* &gt;&gt; *w**i*, or as *s**i* &lt;&gt; *w**i*, where *s**i* and...
{"inputs": ["2\n10\n79", "5\n9\n99\n999\n9999\n99999", "5\n99999\n9999\n999\n99\n9", "10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896", "10\n448\n727\n772\n539\n870\n913\n668\n300\n36\n895", "10\n704\n812\n323\n334\n674\n665\n142\n712\n254\n869", "10\n548\n645\n663\n758\n38\n860\n724\n742\n530\n779", "10\n317\n36\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
c88414bf76eef58c9a7872fa666c98b0
Little Pigs and Wolves
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=×<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afra...
{"inputs": ["2 3\nPPW\nW.P", "3 3\nP.W\n.P.\nW.P", "1 1\nP", "2 6\nWW..WW\n.PPPP.", "6 2\n.W\n.W\n.P\nWP\n.P\nPW", "2 10\nW..WWP.P.P\nW..PP.WWP.", "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP", "3 4\nWPPW\n.P..\nPWW.", "4 3\n.WW\n..P\nP.P\nPWW", "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW", "10 3\n...\nPWW\n..P\n..P\nP....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
c8a6479bca3e0c6689745a18c57e353e
Tic-tac-toe
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the...
{"inputs": ["X0X\n.0.\n.X.", "0.X\nXX.\n000", "XXX\n.0.\n000", "XXX\n...\n000", "X.X\nX..\n00.", "X.X\nX.0\n0.0", "XXX\nX00\nX00", "000\nX.X\nX.X", "XXX\n0.0\n0..", "X0X\n0X0\nX0X", "XX.\nX0X\nX..", "X0X\n0X0\nX..", "XX0\n0..\n000", "XXX\n0..\n.0.", "XXX\nX..\n.00", "X00\n0.0\nXX0", "0.0\n0XX\n..0", ".00\nX.X\n0..", "....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
c8b59efdcaa0c4ce3da4b4d5ef8753c8
Death Stars (medium)
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so...
{"inputs": ["10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "1 1\ng\ng"], "outputs": ["4 6", "1 1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
c8c6dafa16661bd281ebc6cc95d78b44
Calendar
BerOilGasDiamondBank has branches in *n* cities, at that *n* is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly *n*<=/<=2 lines of strictly equal length, each of which contains exactly two names and exactly...
{"inputs": ["4\nb\naa\nhg\nc\n.", "2\naa\na\n!", "2\naa\na\n|", "4\nqhcivbxotj\nirgxzzxvw\npxdmcyszvk\nyyaevcdal\n~", "8\nbad\nrnnpg\njvcjsxfob\nad\nairnnpg\nqury\njvcjsxfo\nquryai\n6", "6\neh\nehkhdp\ngque\nkhdptvgque\ntvgque\nehkhdptv\n}", "10\ndoecgzo\ntjptpqp\noitegxzwlp\nmwsrwmeyeg\nsmapaqanak\nsmapaqa\nqghrydm\nn...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
c8c6e9cfbda391ccbc4fdded3cf790eb
Laurenty and Shop
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese. The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each...
{"inputs": ["4\n1 2 3\n3 2 1\n3 2 2 3", "3\n1 2\n3 3\n2 1 3", "2\n1\n1\n1 1", "2\n1\n1\n2 1", "3\n1 100\n1 1\n100 100 100", "4\n5 6 7\n8 9 10\n1 8 8 1", "4\n1 2 3\n2 2 3\n2 3 4 3", "48\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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
78
codeforces
c8ce6e123182a0581d1c615039667841
Reachability from the Capital
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way. The first line of input consists of three integers $n$,...
{"inputs": ["9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "5 4 5\n1 2\n2 3\n3 4\n4 1", "5000 0 2956", "2 0 2", "2 1 1\n1 2", "2 1 2\n1 2", "2 2 2\n1 2\n2 1", "5000 2 238\n3212 238\n238 3212", "5000 2 3810\n3225 1137\n1137 3225", "100 1 30\n69 81", "500 1 209\n183 107", "1000 1 712\n542 916", "39 40 38\n4 8\n24 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
c8d0de1d9d6b8ab910755fb08a28ec2a
Bargaining Table
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t...
{"inputs": ["3 3\n000\n010\n000", "5 4\n1100\n0000\n0000\n0000\n0000", "3 3\n000\n110\n000", "4 2\n00\n10\n11\n00", "3 5\n00001\n00000\n10100", "1 1\n0", "10 11\n11111111101\n01111111111\n11101111111\n01111110111\n11111111111\n11111111111\n11111111111\n11110111111\n11111111111\n11111111111", "7 7\n1110111\n1111111\n111...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
c8d20c0015d8c8ad5f2d84cc1c0da6db
Comments
A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed. Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment ex...
{"inputs": ["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "a,5,A,0,a,0,A,0,a,0,A,0", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0", "BA,0", "Tu,1,dU,1,zncD,0", "nwEwA,2,C,1,aG,0,xgv,0", "aa,0", "ab,0,ba,0", "aa,0,ab,1,a,0", "a,0,bb,1,a,1,bb,0", "a,2,b,0,bb,1,a,1,a,0", "bb,0,b,1,a,1,b,1,a,0,b,0", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
c9003a393c88d23eebbb3bcb8db3ab73
BerOS file system
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ...
{"inputs": ["//usr///local//nginx/sbin", "////a//b/////g", "/a/b/c", "/", "////", "/a//aa/a//", "/aa//b/aa", "////////////////////////////////////////////////////////////////////////////////////////////////////", "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "/root/pokerband/trunk/server/game/c...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
107
codeforces