problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
34 values
language
listlengths
1
1
source
stringclasses
15 values
num_solutions
int64
1
1.12M
starter_code
stringlengths
0
1.47k
subset
stringclasses
4 values
38108be8e55699235894cccfaad42904
Berland Federalization
Recently, Berland faces federalization requests more and more often. The proponents propose to divide the country into separate states. Moreover, they demand that there is a state which includes exactly *k* towns. Currently, Berland has *n* towns, some pairs of them are connected by bilateral roads. Berland has only *...
{"inputs": ["5 2\n1 2\n2 3\n3 4\n4 5", "5 3\n1 2\n1 3\n1 4\n1 5", "1 1", "11 4\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11", "11 10\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11", "12 3\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11\n11 12", "12 6\n1 2\n1 3\n1 4\n2 6\n2 7\n1 5\n2 8\n4 9\n4 10\n4 11\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
38761594b2560cef7c16e6b89aea0872
Parquet Re-laying
Peter decided to lay a parquet in the room of size *n*<=×<=*m*, the parquet consists of tiles of size 1<=×<=2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter likes, and workers will have to re-lay it. The workers decided that removing entire parquet and then laying it ag...
{"inputs": ["2 3\nULR\nDLR\nLRU\nLRD", "4 3\nULR\nDLR\nLRU\nLRD\nULR\nDUU\nUDD\nDLR", "2 5\nLRUUU\nLRDDD\nLRLRU\nLRLRD", "3 8\nLRULRLRU\nUUDLRLRD\nDDLRLRLR\nULRLRLRU\nDLRLRLRD\nLRLRLRLR", "7 6\nULRULR\nDLRDLR\nUUULRU\nDDDLRD\nLRUULR\nLRDDUU\nLRLRDD\nULRLRU\nDUUUUD\nUDDDDU\nDLRLRD\nULRULR\nDLRDUU\nLRLRDD", "10 9\nLRLRLR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
38845cbb3505f416bccfeb0211eb9e98
Rock-Paper-Scissors
Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!). Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independently from each other. They show the items with their hands: a rock, scisso...
{"inputs": ["7\nRPS\nRSPP", "5\nRRRRRRRR\nR", "23\nRSP\nRPSS", "52\nRRPSS\nRSSPRPRPPP", "1293\nRRPSSRSSPRPRPPPRPPPRPPPPPRPSPRSSRPSPPRPRR\nSSPSSSSRPPSSSSRPRPRPPSRSRRSPPSPPRPSRSPSRR", "103948\nRRPSSRSSPRPRPPPRPPPRPPPPPRPSPRSSRPSPPRPRRSSPSSSSRPPSSSSRPRPRPPSRSRRSPPSPPRPSRSPSRRPSRSRSRPRPRSSPSPRPRSSPRPSPPRPRRRPRRPRPSPRPRSSRR...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
388ebdc52277ab7440b7e20c3040e284
Which floor?
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
{"inputs": ["10 3\n6 2\n2 1\n7 3", "8 4\n3 1\n6 2\n5 2\n2 1", "8 3\n7 2\n6 2\n1 1", "4 2\n8 3\n3 1", "11 4\n16 4\n11 3\n10 3\n15 4", "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "1 0", "1 1\n1 1", "1 1\n1 1", "1 2\n1 1\n2 2", "2 2\n2 1\n1 1", "2 0", "2 1\n3 3", "3 2\n1 1\n3 3", "3 3\n1 1\n3 3\n2 2", "3 0", "1 1\n2 1", "2 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
38a0572f7ab04f490a1b64127c32ee44
Text Editor
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, b...
{"inputs": ["4\n2 1 6 4\n3 4 4 2", "4\n10 5 6 4\n1 11 4 2", "3\n10 1 10\n1 10 1 1", "4\n2 1 6 4\n4 2 3 5", "3\n20 3 20\n1 20 1 1", "2\n10 1\n1 3 2 1", "20\n3 1 9 9 6 1 3 4 5 6 7 3 1 9 9 1 9 1 5 7\n17 7 19 5", "20\n81 90 11 68 23 18 78 75 45 86 58 37 21 15 98 40 53 100 10 70\n11 55 8 19", "25\n55 47 5 63 55 11 8 32 0 62...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
38a77f9b1565bb7b2f12271aa22b060e
Dead Ends
Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are *n* junctions and *m* two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to *n*<=-<=1 roads and i...
{"inputs": ["3 3 2\n1 2\n2 3\n1 3", "4 6 2\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4", "4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4", "5 4 3\n2 1\n5 3\n3 2\n1 4", "5 10 2\n2 4\n1 5\n2 5\n3 5\n4 3\n1 4\n3 1\n5 4\n3 2\n2 1", "6 6 2\n6 3\n5 2\n5 1\n3 5\n6 2\n4 3", "7 7 5\n2 1\n4 2\n7 1\n4 5\n7 6\n2 6\n2 3", "5 5 2\n1 2\n2 3\n3 4\n4 2\n4 5", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
38b21dffaeb42cac1f2f9489c6203f5b
Karen and Morning
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palin...
{"inputs": ["05:39", "13:31", "23:59", "13:32", "14:40", "14:00", "05:50", "12:22", "12:34", "05:30", "14:14", "01:10", "02:20", "03:30", "04:40", "10:01", "11:11", "12:21", "14:41", "15:51", "20:02", "21:12", "22:22", "23:32", "01:11", "02:21", "03:31", "04:41", "05:51", "10:02", "11:12", "14:42", "15:52", "20:03", "2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
133
codeforces
38bddbbfe2d04819082a90ef67615560
Sum the Fibonacci
You are given an array *s* of *n* non-negative integers. A 5-tuple of integers (*a*,<=*b*,<=*c*,<=*d*,<=*e*) is said to be valid if it satisfies the following conditions: - 1<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*<=≤<=*n* - (*s**a* | *s**b*) &amp; *s**c* &amp; (*s**d* ^ *s**e*)<==<=2*i* for some integer *i* - *s**a* &am...
{"inputs": ["2\n1 2", "3\n7 4 1", "10\n1 3 0 7 3 7 6 5 7 5", "10\n50 9 11 44 39 40 5 39 23 7", "10\n4 4 3 1 5 1 3 6 4 4", "10\n5 6 3 2 6 4 3 0 2 7", "10\n7 0 4 3 7 6 2 1 0 2", "10\n1 2 4 4 7 1 1 2 7 5", "10\n3 5 5 4 0 4 1 4 5 1", "10\n6826 5946 9767 38900 11942 58422 45007 53023 3656 41010", "10\n53002 36454 23921 1410...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
38cc59de94bca64c6c7c4f4eb9abdbc9
Permutation Sum
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. Pety...
{"inputs": ["3", "5", "13", "1", "2", "4", "6", "15", "16", "7", "8", "9", "10", "11", "12", "14"], "outputs": ["18", "1800", "695720788", "1", "0", "0", "0", "150347555", "0", "670320", "0", "734832000", "0", "890786230", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
38e555730668a446d73aaad7b3fe78f0
Roads in Berland
There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance ...
{"inputs": ["2\n0 5\n5 0\n1\n1 2 3", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1", "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763", "4\n0 537 1064 656\n537 0 527 119\n1064 527 0 408\n656 119 408 0\n4\n1 4 123\n1 4 344\n3 2 982\n3 2 587", "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
392ed5caa360e1dc63110f061175dd82
Thor
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). *q* events are ...
{"inputs": ["3 4\n1 3\n1 1\n1 2\n2 3", "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3", "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n1 1\n1 7\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
39309ddd3f632f4dfef8be76b7678c4c
Paths in a Complete Binary Tree
*T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So *n* is a number such t...
{"inputs": ["15 2\n4\nUURL\n8\nLRLLLLLLLL", "1 1\n1\nL", "1 1\n1\nR", "1 1\n1\nU", "1 10\n1\nURLRLULUR\n1\nLRRRURULULL\n1\nLURURRUUUU\n1\nRRULLLRRUL\n1\nUULLUURL\n1\nRLRRULUL\n1\nLURRLRUULRR\n1\nLULLULUUUL\n1\nURULLULL\n1\nLRRLRUUUURRLRRL", "3 10\n2\nRUUUULULULUU\n1\nULLLURLU\n3\nLLURLULU\n2\nRRLURLURLLR\n3\nLRURURLRLL...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
394d35313163682fb593a583a299c398
none
There are *n* types of coins in Byteland. Conveniently, the denomination of the coin type *k* divides the denomination of the coin type *k*<=+<=1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types *k*<=+<=1 and *k* equals *a**k*. It is known that for each *x* there are a...
{"inputs": ["1\n\n4\n2", "2\n1\n4 4\n2", "3\n3 3\n10 10 10\n17", "2\n2\n200000 100000\n34567", "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 299981\n1234567890", "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n299981 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1034567", "10\n1 1 1 1 1 1 1 1 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
39544f28821bb5aa59b8dec97a4e1e49
Error Correct System
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings *S* and *T* of equal length to be "similar". After a brief search on th...
{"inputs": ["9\npergament\npermanent", "6\nwookie\ncookie", "4\npetr\negor", "6\ndouble\nbundle", "1\na\na", "1\na\nb", "2\naa\naa", "2\nzz\nzz", "2\nzx\nzz", "2\nzz\nzx", "2\nxy\nzz", "2\nzz\nxy", "2\nzx\nxz", "2\nab\nbc", "2\nab\ncb", "2\nxx\nyy", "10\ncdcddbacdb\naababacabc", "2\nab\ncd", "2\naa\nab", "3\nabc\nbca",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
3958501202101ff6b2ac1fdd5918475d
Buggy Robot
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo...
{"inputs": ["4\nLDUR", "5\nRRRUU", "6\nLLRRRR", "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDU...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
226
codeforces
3988deb311c9bfcfc4ac5c195612dbd0
Far Relative’s Birthday Cake
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta...
{"inputs": ["3\n.CC\nC..\nC.C", "4\nCC..\nC..C\n.CC.\n.CC.", "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.C...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
430
codeforces
39bbee704fc84a224ebeb5084d155b4f
Make a Square
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently ...
{"inputs": ["8314", "625", "333", "1881388645", "1059472069", "1354124829", "149723943", "101", "1999967841", "2000000000", "1999431225", "30", "1000", "3081", "10", "2003064", "701", "1234567891", "10625", "13579", "1999999999", "150000", "8010902", "20100", "40404", "70000729", "1899933124", "1999999081", "326700", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
76
codeforces
39d7d73ee8bf7fb917707a725fcecbc3
Potions Homework
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ...
{"inputs": ["2\n1\n3"], "outputs": ["6"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
39e33fe03d8030b451d146fb78f7dab7
Point on Spiral
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0,<=0),<=(1,<=0)], [(1,<=0),<=(1,<=1)], [(1,<=1),<=(<=-<=1,<=1)], [(<=-<=1,<=1),<=(<=-<=1,<=<=-<=1)], [(<=-<=1,<=<=-<=1),<=(2,<=<=-<=1)], [(2,<...
{"inputs": ["0 0", "1 0", "0 1", "-1 -1", "10 10", "0 6", "-7 -13", "37 -100", "99 100", "16 -32", "1 1", "-1 1", "-1 0", "3 -5", "0 -1", "1 -1", "100 100", "0 99", "-98 98", "-97 0", "-96 -96", "0 -95", "94 -94", "93 0", "17 25", "1 -84", "-5 44", "11 -15", "42 9", "-81 3", "100 99", "2 -1"], "outputs": ["0", "0", "2"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
39e8800931f696ffb8fdfc41c39b18dd
Valera and Contest
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually. After the contest was over, Valer...
{"inputs": ["5 3 1 3 13 9", "5 3 1 3 15 9", "50 25 1 1 50 25", "1000 700 782 1000 892330 648282", "1000 999 500 503 501513 501013", "999 998 500 501 500009 499509", "999 998 500 500 499500 499000", "999 997 500 502 500516 499516", "1000 300 50 500 269795 127658", "50 25 1000 1000 50000 25000", "100 100 500 1000 75589 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
3a2ed3d0ddf1e89b171a443e3b293e3c
The number of positions
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. The only line contains three integers *n*, *a* an...
{"inputs": ["3 1 1", "5 2 3", "5 4 0", "6 5 5", "9 4 3", "11 4 6", "13 8 7", "14 5 5", "16 6 9", "20 13 17", "22 4 8", "23 8 14", "26 18 22", "28 6 1", "29 5 23", "32 27 15", "33 11 5", "37 21 15", "39 34 33", "41 27 11", "42 25 16", "45 7 43", "47 16 17", "49 11 37", "51 38 39", "52 29 7", "56 43 12", "58 57 28", "59 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
466
codeforces
3a34b87fc366a4d65f122e24216aa3f8
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of the...
{"inputs": ["5\n7 5 8 6 9", "5\n-1 -2 0 0 -5", "5\n5 4 3 2 1", "5\n1000000000 0 0 0 0", "5\n1000000000 1 0 -999999999 -1000000000", "3\n998 244 353", "3\n-1000000000 0 1000000000", "5\n-1 -1 -1 -1 1", "4\n-9763 530 3595 6660", "4\n-253090305 36298498 374072642 711846786", "5\n-186772848 -235864239 -191561068 -193955178...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
3a4944a4a61a49529d73e0c3ffb1252b
Bag of mice
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chanc...
{"inputs": ["1 3", "5 5", "100 100", "100 1", "1 100", "67 420", "0 1000", "1000 0", "0 0", "1000 1000", "32 1000", "581 406", "459 52", "900 853", "778 218", "219 20", "815 665", "773 467", "215 269", "93 633", "267 270", "226 72", "666 436", "544 519", "141 883", "581 685", "459 487", "980 133", "858 934", "455 299",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
3a7496dc01395a64dcd10c9444286d53
Guess a number!
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that *y* is st...
{"inputs": ["4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "2\n> 100 Y\n< -100 Y", "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N", "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y", "4\n< 10 Y\n> -6 Y\n< 10 Y\n< -10 N", "1\n< 1 N", "1\n<= 1 Y", "1\n> 1 N", "1\n>= 1 Y", "4\n< 1 N\n< 1 N\n< 1 N\n<= 1 Y", "4\n< 1 N\n>= 1 Y\n< 1 N\n< 1 N", "4\n> 1 N\n<= 1 Y\n<=...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
61
codeforces
3a77f3f4e5388497e5271357cd5d6a2b
Path Counting
You are given a rooted tree. Let's denote *d*(*x*) as depth of node *x*: depth of the root is 1, depth of any other node *x* is *d*(*y*)<=+<=1, where *y* is a parent of *x*. The tree has the following property: every node *x* with *d*(*x*)<==<=*i* has exactly *a**i* children. Maximum possible depth of a node is *n*, a...
{"inputs": ["4\n2 2 2", "3\n2 3", "2\n2", "6\n2 2 4 2 4"], "outputs": ["14 19 20 20 16 16 ", "8 13 6 9 ", "2 1 ", "182 415 420 980 1216 2432 1536 3328 2048 4096 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
3a9926b5ae6c5e1afb1e2414cad41a5d
Vasya the Architect
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides ...
{"inputs": ["2\n0 0 3 3\n1 0 4 3", "2\n0 0 3 3\n2 0 5 3", "3\n0 0 3 3\n1 0 4 3\n2 0 5 3", "5\n7 -10 -8 5\n4 -7 -5 2\n2 -5 -3 0\n-9 48 50 -11\n50 -4 -2 48", "5\n6 -2 13 -9\n17 2 2 -13\n13 -2 6 -9\n4 0 15 -11\n8 -7 11 -4", "7\n4 6 1 9\n-1 4 6 11\n8 13 -3 2\n-5 0 45 50\n-2 50 45 3\n45 50 -4 1\n45 50 -1 4", "7\n24 6 11 -7\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3add68635ce4d4c3e1958fcf25655fc7
Browser
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong ...
{"inputs": ["6 3 2 4", "6 3 1 3", "5 2 1 5", "100 1 1 99", "100 50 1 99", "100 99 1 99", "100 100 1 99", "100 50 2 100", "100 1 100 100", "100 50 50 50", "6 4 2 5", "100 5 2 50", "10 7 3 9", "7 4 2 5", "43 16 2 18", "100 50 2 51", "6 5 2 4", "10 5 2 7", "10 10 2 9", "10 7 3 7", "64 64 8 44", "5 4 2 4", "6 6 3 5", "10 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
94
codeforces
3aedbea91125683b6bcdb3225a3a9a4b
Team
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ...
{"inputs": ["1 2", "4 8", "4 10", "1 5", "3 4", "3 10", "74 99", "19 30", "33 77", "3830 6966", "1000000 1000000", "1027 2030", "4610 4609", "3342 3339", "7757 7755", "10 8", "4247 8495", "7101 14204", "9801 19605", "4025 6858", "7129 13245", "8826 12432", "6322 9256", "8097 14682", "6196 6197", "1709 2902", "455 512",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
106
codeforces
3b240e3783c43aa47c25b9f1274195ff
Xenia and Bit Operations
Xenia the beginner programmer has a sequence *a*, consisting of 2*n* non-negative integers: *a*1,<=*a*2,<=...,<=*a*2*n*. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value *v* for *a*. Namely, it takes several iterations to calculate value *v*. At the ...
{"inputs": ["2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2", "1 1\n1 1\n1 1", "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31", "1 10\n22 17\n2 15\n2 12\n1 6\n1 16\n2 24\n1 21\n2 19\n2 25\n2 19\n2 1", "2 10\n15 27 17 18\n2 12\n4 19\n2 3\n4 1\n3 15\n3 11\n2 5\n1 26\n1 17\n3 18", "2 10\n31 17 22 5\n2 15\n2 26\n1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
3b61de978dbfc1b20b9f022753ecc871
4-point polyline
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of...
{"inputs": ["1 1", "0 10", "10 10", "100 100", "10 100", "20 1000", "1000 20", "100 10", "2 2", "3 3", "2 15", "15 2", "1000 1000", "1000 999", "999 1000", "987 567", "555 555", "555 1", "1 4", "955 956", "4 0", "0 3", "3 0", "2 3", "3 2", "3 4", "4 3", "3 5", "5 3", "3 6", "6 3", "4 4", "4 5", "5 4", "4 6", "6 4", "4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
11
codeforces
3b63b03c271256ddd7519d874f49bf6d
Ciel the Commander
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26...
{"inputs": ["4\n1 2\n1 3\n1 4", "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10", "6\n1 2\n2 4\n4 5\n6 4\n3 2", "2\n2 1", "15\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15", "30\n23 13\n10 23\n21 10\n17 21\n2 17\n4 2\n14 4\n1 14\n19 1\n26 19\n11 26\n15 11\n25 15\n3 25\n28 3\n5 28\n18 5\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
3b7679613a34b5a0390fc195fff3af71
IT Restaurants
Сity N. has a huge problem with roads, food and IT-infrastructure. In total the city has *n* junctions, some pairs of them are connected by bidirectional roads. The road network consists of *n*<=-<=1 roads, you can get from any junction to any other one by these roads. Yes, you're right — the road network forms an undi...
{"inputs": ["5\n1 2\n2 3\n3 4\n4 5", "10\n1 2\n2 3\n3 4\n5 6\n6 7\n7 4\n8 9\n9 10\n10 4", "3\n3 1\n2 1", "4\n4 3\n4 1\n4 2", "5\n5 4\n4 1\n5 2\n3 2", "5\n1 4\n2 1\n5 1\n1 3", "6\n1 5\n3 4\n6 1\n3 2\n3 1", "6\n5 1\n1 2\n1 3\n6 1\n4 1", "6\n5 4\n2 1\n2 5\n3 4\n3 6", "18\n7 12\n14 8\n11 4\n6 3\n2 3\n15 10\n8 16\n6 16\n15 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
3b8a51ebdac11b1f7888e126253f4c09
Bets
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor. To begin with friends...
{"inputs": ["4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20", "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20", "2 2\n1 2 3 1\n2 2 3 10", "20 30\n15 17 54 46\n4 18 26 18\n18 20 49 94\n12 12 83 12\n11 13 88 47\n8 8 8 12\n18 18 94 2\n14 17 88 96\n19 19 62 97\n1 12 81 67\n10 12 78 26\n19 20 63 93\n9 20 38 32\n7 9 90 17\n9 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
3b9d861c71dcfb2461f6d7a5f9309258
Tree Constructing
You are given three integers $n$, $d$ and $k$. Your task is to construct an undirected tree on $n$ vertices with diameter $d$ and degree of each vertex at most $k$, or say that it is impossible. An undirected tree is a connected undirected graph with $n - 1$ edges. Diameter of a tree is the maximum length of a simpl...
{"inputs": ["6 3 3", "6 2 3", "10 4 3", "8 5 3", "8 3 3", "5 4 2", "5 4 3", "5 5 2", "5 5 3", "6 4 2", "6 4 3", "6 5 2", "6 5 3", "7 4 2", "7 4 3", "7 5 2", "7 5 3", "1 1 1", "400000 400000 400000", "400000 399999 400000", "400000 399999 2", "200000 100000 3", "200000 100000 2", "400000 2 399999", "400000 100 399999", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
3ba660d87505352bc671bca512dd542a
Little Elephant and Inversions
The Little Elephant has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*. The Little Elephant wants to count, how many pairs of integers *l* and *r* are there, such that 1<=≤<=*l*<=&lt;<=*r*<=≤<=*n* and sequence *b*<==<=*a*1*a*2... *a**l**a**r**a**...
{"inputs": ["3 1\n1 3 2", "5 2\n1 3 2 1 7", "7 3\n1 7 6 4 9 5 3", "5 0\n1 2 3 4 5", "2 1\n2 1", "3 1000000000000\n3 2 1", "10 5\n1 4 4 2 3 7 6 5 1 2", "10 10\n7 5 5 5 9 10 9 8 7 5", "7 1\n10 38 46 40 88 5 94", "20 7\n5 10 23 7 24 7 15 11 13 18 18 18 8 20 5 16 7 25 2 22", "40 1000000000000000000\n83 35 47 18 96 63 24 91...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3bf5c3e48c7b053e6aa8fc1ca6730f73
Han Solo and Lazer Gun
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot...
{"inputs": ["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0", "1 1 1\n0 0", "2 0 0\n10000 -10000\n-10000 10000", "2 0 0\n10000 -10000\n10000 10000", "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4", "10 5 -3\n1 1\n2 -1\n2 2\n1 -2\n4 -5\n1 4\n0 1\n1 -4\n-2 0\n-4 -5", "10 -3 3\n3 -5\n4 3\n0 -2\n0 0\n3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
49
codeforces
3c01c47c4140ffb5cc3d12303aab46b6
Radio Station
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o...
{"inputs": ["2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;", "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
318
codeforces
3c179f3122e0ce363e5ca25b758760cf
Yet Another Array Queries Problem
You are given an array *a* of size *n*, and *q* queries to it. There are queries of two types: - 1 *l**i* *r**i* — perform a cyclic shift of the segment [*l**i*,<=*r**i*] to the right. That is, for every *x* such that *l**i*<=≤<=*x*<=&lt;<=*r**i* new value of *a**x*<=+<=1 becomes equal to old value of *a**x*, and ne...
{"inputs": ["6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3", "5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5", "1 1 1\n474812122\n2 1 1\n1"], "outputs": ["3 3 1 5 2 ", "2 665 3 64 4 ", "474812122 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
3c32c34ac5004228f7041da8bc753e4d
Cows and Primitive Roots
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consumin...
{"inputs": ["3", "5", "7", "11", "17", "19", "1583", "997", "2", "1987", "1993", "1997", "1999", "1297", "163", "1259", "821", "29", "43", "1949", "1879", "1759", "1597", "1619", "1277", "1097", "953", "751", "607", "509", "431", "317", "211", "127", "101", "31"], "outputs": ["1", "2", "2", "4", "8", "6", "672", "328",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
51
codeforces
3c5efa15dc96e7b2f9d279fa7af33f0a
Design Tutorial: Make It Nondeterministic
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull. Let's try to make a new task. Firstly we will use the following task. There are *n* people, sort them by their name. It is just an ordi...
{"inputs": ["3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3", "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2", "2\ngalileo galilei\nnicolaus copernicus\n2 1", "10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma mil...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
3cb7da3f6aa21d20c10d29e847128545
Squares and not squares
Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this can...
{"inputs": ["4\n12 14 30 4", "6\n0 0 0 0 0 0", "6\n120 110 23 34 25 45", "10\n121 56 78 81 45 100 1 0 54 78", "10\n0 675178538 310440616 608075179 0 0 0 0 0 0", "10\n49727640 89440577 0 957792200 0 0 0 0 623726477 0", "20\n4 595258838 0 305922562 0 471450344 1 1 29794053 307197649 0 32960227 1 0 0 1 1 0 0 1", "100\n444...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
3cbd09c654179a180514a5cac06fafc4
Scissors
Jenya has recently acquired quite a useful tool — *k*-scissors for cutting strings. They are generally used for cutting out two non-intersecting substrings of length *k* from an arbitrary string *s* (its length should be at least 2·*k* in order to perform this operation) and concatenating them afterwards (preserving th...
{"inputs": ["7 4 3\nbaabaab\naaaa", "6 3 2\ncbcbcb\nbcc", "7 5 3\naabbaaa\naaaaa", "16 6 4\nabcdcadbbbcacdca\ndcadbc", "81 5 3\nacbbcccbcbcbbbabaabbbcbacbaabbabaacccaaaaaabbbaacbaabcbcacbbacacbaaaaccbbcacbbcba\ncbbab", "12 3 4\ndbcbabbbdcbb\nbba", "18 3 4\ndcdbdbadddbddbbccc\nbba", "7 3 3\naaabbaa\naaa", "8 3 4\nbcbaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3cc5285df504e353dace9de67bd01859
Mahmoud and Ehab and the xor-MST
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of *n* vertices numbered from 0 to *n*<=-<=1. For all 0<=≤<=*u*<=&lt;<=*v*<=&lt;<=*n*, vertex *u* and vertex *v* are connected with an undirected edge that has weight...
{"inputs": ["4", "10", "2", "1000000000000", "999999999999", "23131234", "100000", "1024", "536870912", "536870911", "536870913", "123456789", "200", "3", "5", "6", "7", "1000", "12000", "65536", "1048576", "8", "549755813888", "549755813887", "549755813889"], "outputs": ["4", "21", "1", "20140978692096", "201409786920...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
3ccb12ebf4d2df622e19e5477742fdb5
none
Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero. A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0. Limak wants to choose some nice rectangles a...
{"inputs": ["6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15", "4\n0 -1 0 0\n0 0 1 0", "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998", "1\n0\n0", "1\n20\n-20", "2\n-1 0\n0 0", "3\n-2 -1 1\n0 1 0", "5\n-1 -2 2 0 -2\n-1 2 -2 2 2", "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "10\n2 1 -2 -1 2 2 -2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3cf407119513b751bc463ccedd2359a7
Letter
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ...
{"inputs": ["Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog", "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears", "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears", "abcd...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
248
codeforces
3cfec1b69fe2adf1d00ee6f434777a8c
Blood Cousins
Polycarpus got hold of a family relationship tree. The tree describes family relationships of *n* people, numbered 1 through *n*. Each person in the tree has no more than one parent. Let's call person *a* a 1-ancestor of person *b*, if *a* is the parent of *b*. Let's call person *a* a *k*-ancestor (*k*<=&gt;<=1) of p...
{"inputs": ["6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1", "1\n0\n20\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "2\n0 1\n20\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 1\n1 1\n1 1\n2 1\n1 1\n2 1\n2 1\n2 1\n1 1\n2 1\n2 1\n1 1\n1 1\n2 1", "3\n0 0 2\n20\n2 1\n1 1\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
3cffef1fee59b03bd6899de7b943aa9b
Key races
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
{"inputs": ["5 1 2 1 2", "3 3 1 1 1", "4 5 3 1 5", "1000 1000 1000 1000 1000", "1 1 1 1 1", "8 8 1 1 1", "15 14 32 65 28", "894 197 325 232 902", "1 2 8 8 5", "37 261 207 1 1000", "29 344 406 900 1", "1 2 8 9 8", "2 9 8 8 9", "213 480 811 134 745", "2 313 856 964 421", "1 10 2 6 10", "2 7 6 2 3", "637 324 69 612 998", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
613
codeforces
3d2a87f340c6112637ca5c250096c894
Worms
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w...
{"inputs": ["5\n2 7 3 4 9\n3\n1 25 11"], "outputs": ["1\n5\n3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
207
codeforces
3d44911c778a334eb3c3c200eb0958dc
Mysterious Present
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes *A*<==<={*a*1,<=<=*a*2,<=<=...,<=<=*a**n*}, where the width and the height of the *i*-th envelope is strictly higher than the...
{"inputs": ["2 1 1\n2 2\n2 2", "3 3 3\n5 4\n12 11\n9 8", "5 10 10\n22 23\n17 19\n13 17\n8 12\n2 6", "5 13 13\n4 4\n10 10\n7 7\n1 1\n13 13", "4 12 140\n172 60\n71 95\n125 149\n53 82", "3 500 789\n56 32\n64 42\n74 55", "4 100 100\n332 350\n232 250\n32 50\n132 150", "2 10 10\n15 15\n16 16", "6 1 1\n900000 900000\n902400 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
3d7a918b546bcb1f8edc711f260f83e9
Numbers
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ...
{"inputs": ["1 10 2", "12 23 3", "6 19 5", "1 80 7", "100 1000 1009", "11 124 11", "1000 10000 19", "2020 6300 29", "213 1758 41", "201 522 233", "97 10403 101", "1 340431 3", "3500 100000 1009", "300 300000 5003", "100000 100000 5", "300 700 41", "7000 43000 61", "12 20000000 11", "35000 100000000 50021", "1 20000000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3d88853ec11a6f22622d7af3d8efba50
Pseudorandom Sequence Period
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for *i*<=≥<=1). Here *a*, *b*, *m* are constants, fixed for the given realization of the pseudorandom numbers generator, *r*0 is the so-called *randseed* (t...
{"inputs": ["2 6 12 11", "2 3 5 1", "3 6 81 9", "10 11 12 3", "4 4 5 4", "0 1 6 5", "1 0 7 3", "25 154 200 68", "0 0 1 0", "1 1 100000 0", "73 778 36193 20163", "65 101 43738 16242", "177 329 83469 5951", "452 53 51476 50033", "900 209 34129 21607", "137 936 79151 3907", "687 509 56521 48466", "977 461 14937 9343", "54...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
3dab8c5075e0332c36e38519909f1c65
Japanese Crosswords Strike Back
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<...
{"inputs": ["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3", "1 1\n1", "1 10\n10", "1 10000\n10000", "10 1\n5 78 3 87 4 9 5 8 9 1235", "3 12\n3 3 3", "3 9\n2 2 2", "2 5\n1 1", "1 2\n1", "3 13\n3 3 3", "3 6\n1 1 1", "1 6\n5", "3 11\n3 3 2", "2 6\n1 3", "3 10\n2 2 2", "3 8\n2 1 1", "1 5\n2", "1 3\n1", "5 5\n1 1 1 1 1", "2 10\n4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
211
codeforces
3dbee8c53095be15c54fd95fa1d23783
Lucky Interval
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya came across an interval of numbers [*a*,<=*a*<=+<=*l*<=-<=1]. Let *F*(*x*) be the numb...
{"inputs": ["7 4", "4 7", "10 10", "47 74", "469 1", "47 74", "100 1", "104 1", "477 7", "777 10", "100 100", "1 1000", "47 9454", "458 10000", "9548 748", "10000 10000", "46999 100000", "548454 845445", "459544 48587874", "1000000000 1000000000", "779999 1000000000", "4699999 1000000000", "9999 107545", "954 71", "974...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3dc2dd5bf116a1f0df0313bb38a1a3d8
Traffic Lights
A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light ...
{"inputs": ["2 1 3 4 5", "5 4 3 1 1", "862 33 604 888 704", "458 251 49 622 472", "772 467 142 356 889", "86 64 587 89 657", "400 333 31 823 74", "714 474 124 205 491", "29 12 569 939 259", "65 24 832 159 171", "2 1 1 1 1", "2 1 1 1 1000", "2 1 1 1000 1", "2 1 1 1000 1000", "2 1 1000 1 1", "2 1 1000 1 1000", "2 1 1000 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
53
codeforces
3ddf6953a9633fbc02a19ac2d84f63d3
Красивая команда
Завтра у хоккейной команды, которой руководит Евгений, важный матч. Евгению нужно выбрать шесть игроков, которые выйдут на лед в стартовом составе: один вратарь, два защитника и три нападающих. Так как это стартовый состав, Евгения больше волнует, насколько красива будет команда на льду, чем способности игроков. А име...
{"inputs": ["1 2 3\n15\n10 19\n20 11 13", "2 3 4\n16 40\n20 12 19\n13 21 11 10", "4 4 5\n15 16 19 6\n8 11 9 18\n5 3 1 12 14", "6 7 7\n32 35 26 33 16 23\n4 40 36 12 28 24 3\n39 11 31 37 1 25 6", "9 10 7\n935 433 848 137 548 958 758 576 592\n780 129 631 991 575 421 245 944 487 771\n430 34 276 8 165 188 727", "17 15 17\n5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
3de5d2ad422d9650f7b7c73ff464e988
A Simple Task
This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*<==<=1 or in non-increasing order if *k*<==<=0. Output the final string after applying the queries...
{"inputs": ["10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1", "10 1\nagjucbvdfk\n1 10 1", "10 6\nrmaahmdmuo\n1 3 1\n4 6 0\n5 6 1\n7 8 0\n8 10 0\n8 9 1", "10 5\nhbtngdflmj\n1 10 1\n2 9 0\n3 8 1\n4 7 0\n5 6 1", "13 0\nokaywearedone"], "outputs": ["cbcaaaabdd", "abcdfgjkuv", "amrmahmoud", "bnflhjgmdt", "okaywearedo...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3df03802b37da8b768eedaa9b38bc34c
T-decomposition
You've got a undirected tree *s*, consisting of *n* nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows. Let's denote the set of all nodes *s* as *v*. Let's consider an undirected tree *t*, whose nodes are some non-empty subsets of *v*, we'll call them *x**i* . The...
{"inputs": ["2\n1 2", "3\n1 2\n2 3", "4\n2 1\n3 1\n4 1", "6\n2 5\n4 3\n4 2\n4 6\n3 1", "6\n3 6\n4 2\n3 4\n3 1\n6 5", "6\n3 2\n6 5\n1 3\n1 4\n6 1", "6\n5 3\n4 2\n5 6\n6 1\n5 4", "5\n1 2\n1 3\n4 5\n4 1", "5\n1 5\n5 3\n2 4\n4 1", "5\n1 5\n5 2\n1 4\n1 3", "4\n1 4\n3 1\n3 2", "20\n19 2\n19 18\n20 9\n20 10\n18 4\n17 5\n17 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
3e0305ad00a8ce7041ada4c908f96a24
none
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree...
{"inputs": ["2\n1 1 1", "2\n1 2 2", "10\n1 1 1 1 1 1 1 1 1 1 1", "10\n1 1 1 1 1 2 1 1 1 1 1", "10\n1 1 1 1 2 2 1 1 1 1 1", "10\n1 1 1 1 1 1 1 2 1 1 2", "10\n1 1 1 3 2 1 2 4 1 3 1", "10\n1 1 1 4 1 1 2 1 5 1 2", "10\n1 1 11 12 12 11 15 13 8 8 8", "10\n1 1 21 1 20 1 14 1 19 1 20", "10\n1 1 93 121 112 103 114 112 112 122 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
3e1d040318b5b2ff2bff5feb4d9fa67a
Lovely Palindromes
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro...
{"inputs": ["1", "10", "11", "12", "100", "1321", "2", "3", "4", "5", "6", "7", "8", "9", "13", "14", "15", "16", "17", "18", "19", "20", "26550", "16137", "91471", "41242", "30866", "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "78065260847320107428504709029792...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
477
codeforces
3e50d65928f72db74df1ec21ab597cd8
none
Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2. По заданной последовательности целых положительных чисел *a*1,<=*a*2,<=...,<=*a**n* требуется найти *r* — максимальную степень числа 2, на которую делится хотя бы од...
{"inputs": ["5\n80 7 16 4 48", "4\n21 5 3 33", "10\n8 112 52 86 93 102 24 24 100 826791168", "3\n458297759 18 104", "7\n12 14 40 8 74 104 11", "11\n35 16 664311776 46 48 52 63 82 84 80 23", "7\n67 68 58 24 96 73 72", "8\n48 112 40 8 112 14 80 36", "10\n14 6 68 8 84 949689614 91 26 80 56", "4\n39 56 939117699 56", "5\n9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
3e647b09d39c70908a6b850df8244f27
none
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm! Of course, there is a code lock is installed on the safe. The lock...
{"inputs": ["6\nabacbb\nbabcba", "3\naba\nbba", "1\nw\nw", "2\nvb\nvb", "7\nvhypflg\nvprhfly", "8\nzyzxzyzw\nzzyzxywz", "8\nvnidcatu\nuiacnvdt", "3\nxhh\nxhh", "4\nwnsc\nnwcs", "5\nutvrb\nvbtru", "8\nvnidcatu\nvnidcatu", "8\nabbabaab\nbaababba", "8\nabaababa\nabaaabab", "49\nssizfrtawiuefcgtrrapgoivdxmmipwvdtqggsczdipn...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
3e78ba92ef883d1b1e8971722951af9d
Numbers
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it. There is integer *n* and array *a*, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positi...
{"inputs": ["1\n0 0 0 0 0 0 0 0 0 1", "2\n1 1 0 0 0 0 0 0 0 0", "3\n1 1 0 0 0 0 0 0 0 0", "4\n0 1 0 1 2 0 0 0 0 0", "5\n2 1 2 0 0 0 0 0 0 0", "6\n1 1 0 1 2 1 0 0 0 0", "7\n0 0 2 2 1 0 1 0 0 0", "8\n1 0 1 0 1 1 2 2 0 0", "9\n1 1 1 2 1 0 0 2 0 1", "10\n2 0 0 1 0 2 0 1 1 0", "100\n10 11 14 16 12 17 10 10 0 0", "100\n0 0 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
3e9a4ebf95b6b8fe90488c34ac94b6b2
Cardiogram
In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners: That is, a cardiogram is fully defined by a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to paint a cardiogram by given sequence *a**i*. The first line contains...
{"inputs": ["5\n3 1 2 5 1", "3\n1 5 1", "2\n1 1", "2\n2 1", "2\n1 2", "2\n2 2", "3\n1 1 1", "100\n14 6 10 12 11 12 6 19 12 7 10 17 8 10 10 5 9 6 9 14 15 5 9 11 8 12 14 15 9 9 9 11 13 15 11 10 4 10 8 7 13 11 17 10 14 14 15 8 10 7 12 8 7 15 13 8 7 13 5 11 12 8 9 8 7 16 11 10 10 15 9 11 2 12 12 9 9 13 7 6 9 7 8 7 4 6 15 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
3eba397c78e7876c6f513acead37b714
The Intriguing Obsession
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands! There are three...
{"inputs": ["1 1 1", "1 2 2", "1 3 5", "6 2 9", "7 3 7", "135 14 39", "5000 5000 5000", "2 1 1", "1 1 3", "1 2 3", "4 1 2", "5 9 4", "4 2 5", "9 4 10", "16 8 29", "17 46 45", "28 47 1", "94 87 10", "84 29 61", "179 856 377", "1925 1009 273", "1171 2989 2853", "3238 2923 4661", "1158 506 4676", "4539 2805 2702", "4756 7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
3ec537dbbb4d9020531b843e0d184b4d
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling ...
{"inputs": ["3\n4 0 2\n3 5 7\n8 1 6", "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "1\n0", "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 0 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
3ee91e91636c5ffb1ea55d1b76d482a0
Good Sequences
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good. Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions: - The sequence is strictly increas...
{"inputs": ["5\n2 3 4 6 9", "9\n1 2 3 5 6 7 8 9 10", "4\n1 2 4 6", "7\n1 2 3 4 7 9 10", "1\n1", "8\n3 4 5 6 7 8 9 10", "5\n2 3 7 9 10", "3\n1 4 7", "1\n4", "9\n1 2 3 4 5 6 7 9 10", "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 64...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
3ef2760c88ad3bfbe9fc232ac88a8cf4
Code For 1
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s...
{"inputs": ["7 2 5", "10 3 10", "56 18 40", "203 40 124", "903316762502 354723010040 354723105411", "33534354842198 32529564319236 32529564342569", "62518534961045 50734311240112 50734311287877", "95173251245550 106288351347530 106288351372022", "542 321 956", "3621 237 2637", "9056 336 896", "36007 368 24490", "244269...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
67
codeforces
3f39c6661843648becc971efaa0a76e1
Merge Equal Elements
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both a...
{"inputs": ["6\n5 2 1 1 2 2", "4\n1000000000 1000000000 1000000000 1000000000", "7\n4 10 22 11 12 5 6", "2\n1 1", "3\n2 1 1", "4\n3 2 1 1", "7\n5 5 4 4 5 6 7"], "outputs": ["2\n5 4 ", "1\n1000000002 ", "7\n4 10 22 11 12 5 6 ", "1\n2 ", "1\n3 ", "1\n4 ", "3\n7 6 7 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
3fa3ff835903925f73dff6b30ce57d8d
000001
The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). Output a single integer. The input contains a single integer *a* (1<=≤<=*a*<=≤<=64). Output a single integer. Sample Input 2 4 27 42 Sample Output 1 2 5 6
{"inputs": ["2", "4", "27", "42", "1", "3", "64", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
3fa63a22428f9feb1c46ac8c4c844904
Bark to Unlock
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p...
{"inputs": ["ya\n4\nah\noy\nto\nha", "hp\n2\nht\ntp", "ah\n1\nha", "bb\n4\nba\nab\naa\nbb", "bc\n4\nca\nba\nbb\ncc", "ba\n4\ncd\nad\ncc\ncb", "pg\n4\nzl\nxs\ndi\nxn", "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
237
codeforces
3fc3f99751dce181d2a4d87285222ec8
Colorful Field
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f...
{"inputs": ["4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "2 3 2 2\n1 1\n2 2\n2 1\n2 2", "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces
3fc90abc9145be915e2ce28bbd6e8bb7
Towers
As you know, all the kids in Berland love playing with cubes. Little Petya has *n* towers consisting of cubes of the same size. Tower with number *i* consists of *a**i* cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the h...
{"inputs": ["3 2\n5 8 5", "3 4\n2 2 4", "5 3\n8 3 2 6 3", "4 6\n1 10 8 2", "5 3\n2 2 2 2 2", "95 720\n9119 7480 7245 2431 7986 4088 3498 7724 9291 3853 9733 4018 1109 6476 6915 6456 8956 2877 8090 7557 1886 5944 9952 6275 2877 6488 2688 319 4635 8618 2724 7047 3261 8750 971 9114 6552 7749 4356 6059 1495 5713 2625 7230 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
3fd31c857915f9f288689eeab0d1ed96
Paper Airplanes
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people....
{"inputs": ["5 3 2 3", "5 3 100 1", "10000 10000 1 1", "1 1 10000 10000", "300 300 21 23", "300 2 37 51", "2 400 23 57", "1 1 1 1", "10000 10000 3 2", "1 2 1 2", "1 1 2 2", "1 1 10 10", "5324 5439 32 13", "9000 1 2432 1", "230 1234 9124 23", "11 1 1 1", "6246 8489 1227 9", "9 20 5 7"], "outputs": ["4", "5", "100000000"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
414
codeforces
3fd6afa7e65bd757f1d253da0506bad2
none
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't ...
{"inputs": ["4\n2 3\n3 1\n6 1\n0 2", "1\n42 23", "2\n1 5\n2 6", "2\n1 5\n12 6", "1\n0 1", "1\n1000000000 1000000000", "2\n4 4\n12 5", "2\n4 4\n12 4", "2\n4 4\n12 3", "3\n0 1\n2 1\n4 1", "3\n0 1\n2 2\n4 1", "2\n0 1\n1000000000 1", "2\n0 1000000000\n1000000000 1000000000", "1\n76438 10", "10\n6 15\n4 5\n1 4\n2 4\n0 6\n9 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
3ff2cbe65f52ba8911e911d0182c829d
Spotlights
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
{"inputs": ["2 4\n0 1 0 0\n1 0 1 0", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "1 5\n1 1 0 0 0", "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "3 1\n1\n0\n0", "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
83
codeforces
3ff91f444ea82f0d659a0cee9eab7199
University Classes
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the ...
{"inputs": ["2\n0101010\n1010101", "3\n0101011\n0011001\n0110111", "1\n0111000", "1\n0000000", "1\n1111111", "2\n1000000\n0101000", "3\n0101111\n1101011\n1010011", "5\n0100101\n0000001\n0110000\n0010000\n0011110", "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100", "10\n0000000\n0010000\n0000000\n0000010\n000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
205
codeforces
400f7e05f6be90746148a4be088b9c36
Cards and Joy
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$. There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. Also, you are given a sequence $h_1, h_2, \dots, h_k$. Its meaning...
{"inputs": ["4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7", "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3", "1 1\n1\n2\n1", "1 1\n1\n1\n1", "1 1\n1\n1\n100000", "50 1\n52 96 99 37 143 148 10 140 131 29 82 134 56 73 121 57 98 101 134 4 103 10 86 70 4 98 102 35 149 47 136 87 4 127 142 105 78 10 123 75 67 149 81 78 34 79 62 12 43...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
402e655a9681a4ba53d28cd08cebe137
Dot
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: - On the checkered paper ...
{"inputs": ["0 0 2 3\n1 1\n1 2", "0 0 2 4\n1 1\n1 2", "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76", "0 0 5 100\n16 24\n29 6\n44 24\n66 37\n102 19", "0 0 5 100\n4 108\n5 170\n7 30\n7 101\n21 117", "0 0 5 100\n30 9\n53 14\n84 7\n94 18\n121 16", "0 0 5 100\n52 144\n55 58\n56 103\n98 65\n134 16", "0 0 5 100\n17 3\n42 24\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
404367fb62cada8206433e740328e249
Trees in a Row
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=&lt;<=*n*), *a**i*<=+<=1<=-<=*a...
{"inputs": ["4 1\n1 2 1 5", "4 1\n1 2 3 4", "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50", "10 1\n1 2 3 4 5 6 7 8 9 10", "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 13...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
25
codeforces
404b200d427f3ddb6485f4203e91fecd
Weird Chess
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous. Igor's chessboard is a square of size *n*<=×<=*n* cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of...
{"inputs": ["5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "3\no.x\noxx\no.x", "1\no", "2\nox\n.o", "5\n.xxo.\n..oxo\nx.oxo\no..xo\noooox", "8\n..x.xxx.\nx.x.xxxx\nxxxxxxox\nxxoxxxxx\n.xxxx.x.\nx.xxx.x.\n..x..xx.\n.xx...x.", "8\noxxxxxxx\nxoxxxoxx\nxx...x..\nxx...x..\nxx......
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
40717239356b32937395da93d2c71397
TCMCF+++
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of po...
{"inputs": ["5\n1 2 -3 3 3", "13\n100 100 100 100 100 100 100 100 100 100 100 100 100", "4\n-2 -2 -2 -2", "1\n1", "1\n-1", "1\n0", "2\n1 1", "2\n1 -1", "2\n-1 1", "2\n-1 -1", "2\n1 0", "2\n0 1", "2\n0 0", "2\n-1 0", "2\n0 -1", "1\n13", "1\n-13", "1\n100", "1\n-100", "2\n100 100", "2\n100 -100", "2\n-100 100", "2\n100 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
408f82f624583dec0966eee9d774fe37
Valera and Fruits
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec...
{"inputs": ["2 3\n1 5\n2 3", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "2 1500\n2 575\n1 2522", "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
49
codeforces
40c9ef84c365e270b4156155cd48a810
Forbidden Indices
You are given a string *s* consisting of *n* lowercase Latin letters. Some indices in this string are marked as forbidden. You want to find a string *a* such that the value of |*a*|·*f*(*a*) is maximum possible, where *f*(*a*) is the number of occurences of *a* in *s* such that these occurences end in non-forbidden in...
{"inputs": ["5\nababa\n00100", "5\nababa\n00000", "5\nababa\n11111", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\n1101101101110110001000001101001000100001010111001001111000111011000111111010110100000111001100100000", "100\nabbbafdcebdafbfdbbcfbdbeaceccccaaa...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
40cca99cdf0629447b7e56038528c854
Common ancestor
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are *...
{"inputs": ["ababa\naba\n2\nc->ba\nc->cc", "ababa\naba\n7\nc->ba\nc->cc\ne->ab\nz->ea\nb->ba\nd->dd\nd->ab", "ababa\naba\n1\nc->ba", "mvo\nmx\n5\nu->dl\nt->fb\nx->vo\nn->kq\na->ca", "bxr\nbxr\n5\nw->jk\nm->ie\nh->ab\nu->sy\nj->gj", "oaujn\noaemvsbb\n50\ny->zr\nw->qg\nf->ep\nw->pd\nq->gf\ng->sn\nw->ug\ne->yj\nn->bb\nd->...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
40ce2b9ba56732ac93bbdb9bc82a216d
Color the Fence
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d...
{"inputs": ["5\n5 4 3 2 1 2 3 4 5", "2\n9 11 1 12 5 8 9 10 6", "0\n1 1 1 1 1 1 1 1 1", "50\n5 3 10 2 2 4 3 6 5", "22\n405 343 489 474 385 23 100 94 276", "62800\n867 936 2 888 474 530 287 822 220", "27\n836 637 966 929 82 678 213 465 688", "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "8982...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
35
codeforces
40eb40e325de8be7bfeb81c76388a9d4
Amr and Chemistry
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has *n* different types of chemicals. Each chemical *i* has an initial volume of *a**i* liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. ...
{"inputs": ["3\n4 8 2", "3\n3 5 6", "2\n50000 100000", "2\n99999 99998", "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "19\n1 2 3 4 6 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6 8 16 20 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "20\n1 2 3 4 6...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
40f2e176a6abf8dae6b38e3250395111
Four Segments
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
{"inputs": ["1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0", "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2", "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5", "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0", "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0", "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1", "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
32
codeforces
40f403a46246b12aacc68b00452a2120
Crash
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive i...
{"inputs": ["2\n0 1\n1 1", "4\n0 1\n1 2\n1 1\n0 2", "4\n0 1\n1 1\n0 1\n0 2", "4\n7 1\n4 2\n8 2\n1 8", "2\n0 8\n0 5", "3\n7 9\n5 8\n8 2", "1\n0 8", "5\n8 10\n7 9\n5 6\n5 2\n10 7", "7\n0 2\n0 3\n0 2\n0 1\n0 10\n1 10\n0 5", "6\n0 1\n1 1\n2 1\n1 1\n2 1\n4 1", "4\n0 1\n1 1\n0 1\n2 1", "6\n0 1\n1 1\n2 1\n3 1\n4 1\n2 1", "3\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
4104e11d5fa7683657dfb3c6de1bb921
Opponents
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar...
{"inputs": ["2 2\n10\n00", "4 1\n0100", "4 5\n1101\n1111\n0110\n1011\n1111", "3 2\n110\n110", "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111", "10 10\n000010001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
201
codeforces
411cf6d0e6f1f53b7fb05afd40bdfab6
New Year and Old Property
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
{"inputs": ["5 10", "2015 2015", "100 105", "72057594000000000 72057595000000000", "1 100", "1000000000000000000 1000000000000000000", "1 1000000000000000000", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "3 3", "3 4", "3 5", "3 6", "3 7", "4 4", "4 5", "4 6", "4 7", "5 5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
148
codeforces
413a2efed103298f61dbbdaba82b5d29
Trains and Statistic
Vasya commutes by train every day. There are *n* train stations in the city, and at the *i*-th station it's possible to buy only tickets to stations from *i*<=+<=1 to *a**i* inclusive. No tickets are sold at the last station. Let ρ*i*,<=*j* be the minimum number of tickets one needs to buy in order to get from station...
{"inputs": ["4\n4 4 4", "5\n2 3 5 5", "2\n2", "10\n2 10 8 7 8 8 10 9 10", "3\n3 3", "4\n3 3 4", "5\n4 4 4 5", "6\n3 3 6 6 6", "7\n7 3 4 6 6 7", "8\n3 7 7 8 8 7 8", "9\n2 9 7 6 9 7 8 9"], "outputs": ["6", "17", "1", "63", "3", "8", "13", "21", "35", "37", "52"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
413ca22062394aad71eddbd8f0a7027b
Tea Party
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that: - Every cup...
{"inputs": ["2 10\n8 7", "4 4\n1 1 1 1", "3 10\n9 8 10", "1 1\n1", "1 1\n2", "1 10\n20", "3 10\n8 4 8", "3 100\n37 26 37", "3 60\n43 23 24", "20 14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 8\n1 2 1 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2", "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
46
codeforces
417ce5067c4e2e68d756c82c73b1dd87
none
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t...
{"inputs": ["2\n4 7", "3\n4 3 1", "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97", "1\n78091781", "2\n1000000000 1", "3\n999999998 999999999 999999992", "3\n465343471 465343474...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
41a166ab295ee669618ba2141ea4821c
Expensive Strings
You are given *n* strings *t**i*. Each string has cost *c**i*. Let's define the function of string , where *p**s*,<=*i* is the number of occurrences of *s* in *t**i*, |*s*| is the length of the string *s*. Find the maximal value of function *f*(*s*) over all strings. Note that the string *s* is not necessarily some s...
{"inputs": ["2\naa\nbb\n2 1", "2\naa\nab\n2 1", "1\naaa\n2", "3\na\naa\naaa\n1 2 3", "3\na\naaa\naa\n2 1 3", "1\nabcde\n-1", "1\na\n1", "5\nbbbb\nbaaa\nbbba\naaba\nbbaa\n17 -17 -82 47 -85", "10\nckxyxnoyqw\nlwvjsygwrc\nhretftiphn\nrqqncjnggb\ntxvnxgkynk\nbukntrryio\ncinrjaobxu\nxqvurzhxth\nkmvrlhpqdk\ndsdubnyoun\n-78 8...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
41ab7444d442dab8d3d66fbf569ee337
Interestring graph and Apples
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f...
{"inputs": ["3 2\n1 2\n2 3", "1 1\n1 1", "1 2\n1 1\n1 1", "1 3\n1 1\n1 1\n1 1", "2 0", "2 1\n1 1", "2 1\n2 2", "2 1\n2 1", "2 2\n1 1\n2 2", "2 2\n1 2\n2 1", "2 3\n1 1\n1 2\n2 1", "3 2\n1 2\n1 2", "1 0", "4 3\n1 2\n1 3\n1 4", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1", "49 0", "50 0", "50 1\n2 3", "3 2\n1 2\n2 3", "5 3\n3 5\n4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
41c39b952ce670cd8ffe912e78607de7
A Blend of Springtime
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
{"inputs": [".BAC.", "AA..CB", ".", "ACB.AAAAAA", "B.BC.BBBCA", "BA..CAB..B", "CACCBAA.BC", ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.", "A", "..", "BC", "CAB", "A.CB", "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB", "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC....
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
358
codeforces
41ca8fb7f117ce4485016a95203706a3
Crazy Town
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ...
{"inputs": ["1 1\n-1 -1\n2\n0 1 0\n1 0 0", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 854898\n-846967 -749453 -341866\n-622388 434663 264157\n-638453 625357 344195\n-255265 -6763...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
72
codeforces
41d636d593d8694e8ec12e3e434c3a50
none
A tree is a graph with *n* vertices and exactly *n*<=-<=1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree *T* is a tree with both vertices and edges as subsets of vertices and edges of *T*. You're ...
{"inputs": ["3\n1 2\n1 3\n1 -1 1", "5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3", "10\n5 6\n8 2\n9 3\n4 1\n6 10\n9 8\n7 10\n7 4\n5 2\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3", "5\n3 1\n2 4\n3 4\n2 5\n0 -3 -1 2 4", "12\n1 6\n10 1\n4 1\n7 1\n1 2\n5 1\n1 8\n1 11\n3 1\n12 1\n9 1\n580660007 861441526 -264928594 488291045 253254575 -974301934 709...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
41eb93137fa630da03ff834ead54d33f
Running Student
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0,<=0), he got on a minibus and they drove along a straight line, parallel to axis *OX*, in the direction of increasing *x*. Poor Student knows the following: - during one run the minibus makes ...
{"inputs": ["4 5 2\n0 2 4 6\n4 1", "2 1 1\n0 100000\n100000 100000", "6 5 1\n0 1 2 3 4 5\n0 0", "4 100 10\n0 118 121 178\n220 220", "4 3 3\n0 6 8 10\n7 -4", "5 900 1\n0 37474 80030 85359 97616\n-1 -1", "5 200 400\n0 8068 28563 51720 66113\n5423 -34", "6 10 3\n0 12 14 16 19 20\n14 0", "6 13 11\n0 16 27 31 39 42\n54 3", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
62
codeforces
41ebdff11474320eb192b62f53bee417
Duff and Meat
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
{"inputs": ["3\n1 3\n2 2\n3 1", "3\n1 3\n2 1\n3 2", "1\n39 52", "2\n25 56\n94 17", "5\n39 21\n95 89\n73 90\n9 55\n85 32", "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88", "2\n100 68\n38 80"], "outputs": ["10", "8", "2028", "2998", "6321", "6742", "9384"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
576
codeforces