source int64 2 2 | difficulty int64 7 25 | name stringlengths 9 60 | description stringlengths 164 7.12k | public_tests dict | private_tests dict | cf_rating int64 0 3.5k | cf_points float64 0 4k |
|---|---|---|---|---|---|---|---|
2 | 10 | 204_D. Little Elephant and Retro Strings | The Little Elephant has found a ragged old black-and-white string s on the attic.
The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is... | {
"input": [
"10 2\nXXBXXWXXXX\n",
"3 2\nXXX\n",
"4 2\nXXXX\n"
],
"output": [
"166\n",
"0\n",
"1\n"
]
} | {
"input": [
"4 2\nXXBW\n",
"2 1\nWB\n",
"128 100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",
"25 7\nXWBXWBXWXWBWXBWWXBWXXXXBB\n",
"1 1\nX\n",
"2 1\nXW\n",
"20 6\nXXBXBXXBWWWWXWWXBBBW\n",
"100 3\n... | 2,400 | 2,000 |
2 | 8 | 278_B. New Problem | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of n last problems β the strings, consisting of lowercase English letters. Your... | {
"input": [
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n",
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n"
],
"output": [
"ab\n",
"j\n"
]
} | {
"input": [
"3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n",
"1\nz\n",
"30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu\n",
"5\nsplt\nohqykk\nxqpz\nknojbur\npmfm\n",
"2\nhk\nobsp\n",
"5\nzzxpfk\nabcdefghijklmnopqrst\nuvwxz\nsrgkjask... | 1,500 | 1,000 |
2 | 7 | 300_A. Array | Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero ( < 0).
2. The product of all numbers in the second set is greater than zero ( > 0).
3. The product of a... | {
"input": [
"4\n-1 -2 -3 0\n",
"3\n-1 2 0\n"
],
"output": [
"1 -1\n2 -3 -2\n1 0\n",
"1 -1\n1 2\n1 0\n"
]
} | {
"input": [
"100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 ... | 1,100 | 500 |
2 | 7 | 372_A. Counting Kangaroos is Fun | There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is ... | {
"input": [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
],
"output": [
"5\n",
"5\n"
]
} | {
"input": [
"1\n1\n",
"12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n",
"7\n1\n2\n4\n8\n16\n32\n64\n",
"4\n1\n1\n1\n2\n",
"5\n1\n2\n4\n8\n16\n",
"100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n26... | 1,600 | 500 |
2 | 9 | 393_C. Blocked Points | Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
* the Euclidean distance between A and B is one unit and neither A nor B is blocked;
* or there is some inte... | {
"input": [
"2\n",
"3\n",
"1\n"
],
"output": [
"8\n",
"16\n",
"4\n"
]
} | {
"input": [
"11\n",
"0\n",
"17\n",
"18855321\n",
"34609610\n",
"25\n",
"9\n",
"40000000\n",
"17464436\n",
"38450759\n",
"395938\n",
"39099999\n",
"8\n",
"4\n",
"30426905\n",
"7\n",
"17082858\n",
"46341\n",
"46340\n",
"39999996\n",
"6... | 0 | 500 |
2 | 10 | 416_D. Population Size | Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if... | {
"input": [
"9\n-1 6 -1 2 -1 4 7 -1 2\n",
"5\n-1 -1 -1 -1 -1\n",
"7\n-1 -1 4 5 1 2 3\n",
"9\n8 6 4 2 1 4 7 10 2\n"
],
"output": [
"3\n",
"1\n",
"2\n",
"3\n"
]
} | {
"input": [
"3\n-1 1 -1\n",
"4\n45 -1 41 -1\n",
"1\n-1\n",
"5\n40 -1 44 46 48\n",
"6\n43 40 37 34 -1 -1\n",
"7\n-1 2 4 -1 4 1 5\n",
"19\n23 26 -1 -1 35 38 41 -1 -1 -1 53 -1 59 62 6 7 8 9 -1\n",
"6\n-1 2 6 -1 -1 6\n",
"16\n3 8 13 18 23 -1 -1 -1 43 48 53 45 -1 -1 -1 -1\n",
"13\n... | 2,400 | 2,000 |
2 | 8 | 443_B. Kolya and Tandem Repeat | Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
I... | {
"input": [
"aaabbbb\n2\n",
"aaba\n2\n",
"abracadabra\n10\n"
],
"output": [
"6\n",
"6\n",
"20\n"
]
} | {
"input": [
"jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddhzayvouwhumzhcphocqyfcddayfakoxofjgusuonehbxbokjsdlktqrcdurogxltsysyjbiagrvhky\n32\n",
"kbxuunznjtxutlauuuipifggjjkequbpvbagmxojhgxtakxioxsmrmoatlyzwsygibhafspqnfbycyztxmtpir... | 1,500 | 1,000 |
2 | 9 | 465_C. No to Palindromes! | Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable st... | {
"input": [
"3 4\ncba\n",
"3 3\ncba\n",
"4 4\nabcd\n"
],
"output": [
"cbd\n",
"NO\n",
"abda\n"
]
} | {
"input": [
"302 4\nabdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcbdcb... | 1,700 | 500 |
2 | 8 | 489_B. BerSU Ball | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m... | {
"input": [
"4\n1 2 3 4\n4\n10 11 12 13\n",
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
],
"output": [
"0\n",
"3\n",
"2\n"
]
} | {
"input": [
"1\n4\n3\n4 4 4\n",
"3\n7 7 7\n4\n2 7 2 4\n",
"3\n5 4 5\n2\n2 1\n",
"100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 ... | 1,200 | 1,000 |
2 | 7 | 513_A. Game | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f... | {
"input": [
"2 1 1 1\n",
"2 2 1 2\n"
],
"output": [
"First\n",
"Second\n"
]
} | {
"input": [
"50 50 50 50\n",
"49 49 4 1\n",
"48 50 12 11\n",
"5 7 1 10\n",
"1 50 50 50\n",
"5 7 1 4\n",
"32 4 17 3\n",
"1 50 1 50\n",
"50 1 1 1\n",
"32 31 10 9\n",
"5 7 4 1\n",
"49 49 3 3\n",
"50 49 1 2\n",
"50 48 3 1\n",
"50 1 1 50\n",
"5 7 10 10\n",
... | 800 | 3 |
2 | 8 | 538_B. Quasi Binary | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 β are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
Input
The first line contains a single... | {
"input": [
"32\n",
"9\n"
],
"output": [
"3\n11 11 10\n",
"9\n1 1 1 1 1 1 1 1 1\n"
]
} | {
"input": [
"111111\n",
"100009\n",
"10011\n",
"1000000\n",
"8\n",
"10201\n",
"102030\n",
"908172\n",
"123456\n",
"415\n",
"900000\n",
"21\n",
"909090\n",
"314159\n",
"999999\n",
"909823\n",
"987654\n",
"1453\n",
"1435\n",
"98\n",
"1... | 1,400 | 1,000 |
2 | 11 | 630_E. A rectangle | Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will... | {
"input": [
"1 1 5 5\n"
],
"output": [
"13"
]
} | {
"input": [
"-157778763 218978790 976692563 591093088\n",
"-1 -4 1 4\n",
"-999999999 -1000000000 -1 0\n",
"1000000000 1000000000 1000000000 1000000000\n",
"-2 -3 -2 1\n",
"-1000000000 -999999999 1000000000 999999999\n",
"0 -1 0 1\n",
"-999999999 -999999999 999999999 999999999\n",
... | 1,900 | 0 |
2 | 8 | 658_B. Bear and Displayed Friends | Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is ... | {
"input": [
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n",
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n"
],
"output": [
"NO\nYES\nNO\nYES\n",
"NO\nYES\nNO\nYES\nYES\n"
]
} | {
"input": [
"1 1 1\n1000000000\n2 1\n",
"20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 552903993 633087286 656092270 671535141 714291344 717660646 846508634 879748146 937368929\n2 7\n1 2\n2 4\n1 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n... | 1,200 | 500 |
2 | 10 | 680_D. Bear and Tower of Cubes | Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.... | {
"input": [
"6\n",
"48\n"
],
"output": [
"6 6\n",
"9 42\n"
]
} | {
"input": [
"1000000000000000\n",
"994\n",
"200385\n",
"3842529393411\n",
"8\n",
"409477218238717\n",
"2\n",
"419477218238718\n",
"909383000\n",
"7\n",
"999088000000000\n",
"265\n",
"415000000238718\n",
"780869426483087\n",
"9\n",
"850085504652042\n",
... | 2,200 | 1,250 |
2 | 9 | 703_C. 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... | {
"input": [
"5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n"
],
"output": [
"5.0000000000\n"
]
} | {
"input": [
"3 3 5 2\n3 1\n4 0\n5 1\n",
"10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796\n",
"10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734\n",
"10 1000 519 882\n-407 135\n-222 25\n-211 22\n-16... | 2,100 | 1,750 |
2 | 9 | 725_C. Hidden Word | Letβs define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:
ABCDEFGHIJKLM
NOPQRSTUVWXYZ
We say that two t... | {
"input": [
"BUVTYZFQSNRIWOXXGJLKACPEMDH\n",
"ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n"
],
"output": [
"Impossible\n",
"ABCDEFGHIJKLM\nZYXWVUTSRQPON\n"
]
} | {
"input": [
"MKBGVNDJRAWUEHFSYLIZCOPTXKQ\n",
"ABACDEFGHIJKLMNOPQRSTUVWXYZ\n",
"BACDEFGHIJKLMNOPQRSTUVWXYZA\n",
"BADSLHIYGMZJQKTCOPRVUXFWENN\n",
"HVDEBKMJTLKQORNWCZSGXYIPUAF\n",
"UNGHFQRCIPBZTEOAYJXLDMSKNWV\n",
"TEGXHBUVZDPAMIJFQYCWRKSTNLO\n",
"MIDLBEUAGTNPYKFWHVSRJOXCZMQ\n",
"RFKN... | 1,600 | 1,500 |
2 | 9 | 747_C. Servers | There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β integer from 1 to n.
It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β the moment in seconds in which the task will come, ki β the number of servers needed to ... | {
"input": [
"8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n",
"4 3\n1 3 2\n2 2 1\n3 4 3\n",
"3 2\n3 2 3\n5 1 2\n"
],
"output": [
"6\n9\n30\n-1\n15\n36\n",
"6\n-1\n10\n",
"3\n3\n"
]
} | {
"input": [
"100 1\n1000000 100 1000\n",
"5 3\n1 4 10\n2 2 5\n3 1 6\n",
"10 4\n1 5 20\n2 5 200\n100 6 20\n101 1 100\n",
"5 3\n1 3 4\n4 3 4\n6 4 1\n",
"4 1\n6 1 1\n",
"8 6\n1 3 20\n4 2 1\n6 6 5\n9 1 1\n15 3 6\n21 8 8\n",
"4 5\n1 2 3\n2 1 3\n3 1 2\n4 3 3\n5 4 1\n",
"8 4\n1 3 2\n2 3 100\... | 1,300 | 1,500 |
2 | 9 | 794_C. Naming Company | Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea... | {
"input": [
"xxxxxx\nxxxxxx\n",
"tinkoff\nzscoder\n",
"ioi\nimo\n"
],
"output": [
"xxxxxx\n",
"fzfsirk\n",
"ioi\n"
]
} | {
"input": [
"bcdef\nabbbc\n",
"z\ny\n",
"reddit\nabcdef\n",
"abc\naaa\n",
"y\nz\n",
"cbxz\naaaa\n"
],
"output": [
"bccdb\n",
"z\n",
"dfdeed\n",
"aab\n",
"y\n",
"abac\n"
]
} | 1,800 | 1,750 |
2 | 8 | 815_B. Karen and Test | Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
Th... | {
"input": [
"4\n3 7 5 2\n",
"5\n3 6 9 12 15\n"
],
"output": [
"\n1000000006\n",
"\n36\n"
]
} | {
"input": [
"6\n58376259 643910770 5887448 757703054 544067926 902981667\n",
"5\n585325539 365329221 412106895 291882089 564718673\n",
"7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872\n",
"1\n1\n",
"16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 2... | 2,200 | 1,250 |
2 | 8 | 840_B. Leha and another game about graph | Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a Β«goodΒ» subset of edges of the graph or say... | {
"input": [
"3 3\n0 -1 1\n1 2\n2 3\n1 3\n",
"4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n",
"1 0\n1\n",
"2 1\n1 1\n1 2\n"
],
"output": [
"1\n2\n",
"0\n",
"-1\n",
"1\n1\n"
]
} | {
"input": [
"3 2\n1 0 1\n1 2\n2 3\n",
"10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n"
],
"output": [
"2\n1\n2\n",
"0\n"
]
} | 2,100 | 1,000 |
2 | 9 | 860_C. Tests Renumeration | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | {
"input": [
"5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"2\n1 0\n2 1\n",
"5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n"
],
"output": [
"4\nmove 3 1\nmove 01 3\nmove 2extra 4\nmove 99 5\n",
"3\nmove 1 3\nmove 2 1\nmove 3 2\n",
"5\nmove 1 3\nmove 11 1\nmove 111 4\nmove 1111 2\nmove 11111 5\n"
]
} | {
"input": [
"3\n1 1\nzwfnx2 1\n7g8t6z 1\n",
"3\nqmf7iz 1\ndjwdce 1\n1 1\n",
"6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n",
"3\n2 1\n3 0\nhs9j9t 1\n",
"6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9mqv 1\n",
"3\n3 1\n1 0\n2 1\n",
"5\nw0g96a 1\nv99tdi 0\nmywrle 0\nweh22w 1\n9hywt4 0\n",
"6\n5 1\n... | 2,200 | 2,500 |
2 | 8 | 887_B. Cubes for Masha | Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. Aft... | {
"input": [
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n",
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n"
],
"output": [
"98\n",
"87\n"
]
} | {
"input": [
"2\n2 6 8 1 3 1\n2 1 3 8 6 7\n",
"2\n1 8 9 1 1 0\n2 3 4 5 6 7\n",
"2\n0 2 9 8 1 7\n6 7 4 3 2 5\n",
"3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2\n",
"3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7\n",
"3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7\n",
"3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 ... | 1,300 | 1,000 |
2 | 8 | 90_B. African Crossword | An African crossword is a rectangular table n Γ m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette... | {
"input": [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
],
"output": [
"abcd\n",
"codeforces\n"
]
} | {
"input": [
"1 2\nfg\n",
"3 2\nxe\ner\nwb\n",
"7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n",
"9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n",
"100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\n... | 1,100 | 1,000 |
2 | 11 | 931_E. Game with String | Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string ... | {
"input": [
"tictictactac\n",
"bbaabaabbb\n",
"technocup\n"
],
"output": [
"0.333333333333333\n",
"0.100000000000000\n",
"1.000000000000000\n"
]
} | {
"input": [
"fabbbhgedd\n",
"abbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaababbbaab\n",
"hcdhgcchbdhbeagdcfedgcbaffebgcbcccadeefacbhefgeadfgchabgeebegahfgegahbddedfhffeadcedadgfbeebhgfahhfb\n",
"khjcoijiicdkdianmdolmadobdkcmgifdnffddnjehhbldlkjffknficdcmokfacioieg... | 1,600 | 1,000 |
2 | 11 | 985_E. Pencils and Boxes | Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers β saturation of the color of each pencil. Now Mishka wants to ... | {
"input": [
"6 3 10\n7 2 7 7 4 2\n",
"3 2 5\n10 16 22\n",
"6 2 3\n4 5 3 13 4 10\n"
],
"output": [
"YES\n",
"NO\n",
"YES\n"
]
} | {
"input": [
"4 2 12\n10 16 22 28\n",
"10 3 1\n5 5 5 6 6 7 8 8 8 9\n",
"8 7 13\n52 85 14 52 92 33 80 85\n",
"10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342555\n",
"10 3 0\n1 1 2 2 2 2 2 2 2 2\n",
"10 4 28\n5 5 6 6 30 30 32 33 50 55... | 2,100 | 0 |
2 | 9 | 1000_C. Covered Points Count | You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k β [1..n], calculate the number of points with integer ... | {
"input": [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n"
],
"output": [
"6 2 1\n",
"5 2 0\n"
]
} | {
"input": [
"1\n0 1000000000000000000\n"
],
"output": [
"1000000000000000001\n"
]
} | 1,700 | 0 |
2 | 10 | 1025_D. Recovering BST | Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s... | {
"input": [
"9\n4 8 10 12 15 18 33 44 81\n",
"6\n3 6 9 18 36 108\n",
"2\n7 17\n"
],
"output": [
"Yes\n",
"Yes\n",
"No\n"
]
} | {
"input": [
"4\n3 5 7 105\n",
"13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
"11\n2 6 15 35 77 143 221 323 437 667 899\n",
"4\n2 3 5 30\n",
"27\n5 10 29 58 116 174 2297 4594 9188 18376 36752 43643 415757 831514 1663028 2494542 6236355 12472710 22450878 4490175... | 2,100 | 1,750 |
2 | 12 | 1068_F. Knights | Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the en... | {
"input": [
"7\n",
"4\n"
],
"output": [
"0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n",
"0 0\n1 0\n1 3\n2 0\n"
]
} | {
"input": [
"523\n",
"4\n",
"40\n",
"14\n",
"23\n",
"11\n",
"27\n",
"7\n",
"1\n",
"1000\n",
"41\n",
"38\n",
"346\n",
"26\n",
"21\n",
"25\n",
"19\n",
"13\n",
"30\n",
"42\n",
"79\n",
"33\n",
"12\n",
"18\n",
"10\n",
... | 2,600 | 1,750 |
2 | 8 | 110_B. Lucky String | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each i... | {
"input": [
"3\n",
"5\n"
],
"output": [
"abc",
"abcda"
]
} | {
"input": [
"1\n",
"77777\n",
"16\n",
"9999\n",
"10\n",
"64\n",
"74\n",
"99\n",
"1024\n",
"47589\n",
"9475\n",
"100\n",
"1000\n",
"99994\n",
"747\n",
"2\n",
"7\n",
"8\n",
"128\n",
"6\n",
"2075\n",
"9\n",
"47\n",
"512\n",
... | 1,100 | 1,000 |
2 | 11 | 1139_E. Maximize Mex | There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competit... | {
"input": [
"5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n",
"5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n",
"5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n"
],
"output": [
"1\n1\n1\n1\n",
"3\n1\n1\n1\n0\n",
"3\n2\n2\n1\n0\n"
]
} | {
"input": [
"5 5\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n",
"5 3\n0 0 1 1 2\n1 2 2 3 2\n2\n2\n3\n",
"10 5\n0 1 1 0 3 1 3 0 2 0\n5 4 3 4 3 4 1 2 3 3\n10\n1\n2\n8\n7\n3\n9\n6\n5\n10\n4\n",
"10 10\n2 0 3 5 6 1 9 4 7 8\n9 2 5 7 1 6 4 10 8 3\n5\n9\n5\n4\n10\n7\n",
"10 5\n1 2 0 4 2 4 1 3 4 4\n2 4 4 3 5 1 1 4 4... | 2,400 | 2,500 |
2 | 11 | 1157_E. Minimum Array | You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1.
You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ... | {
"input": [
"4\n0 1 2 1\n3 2 1 1\n",
"7\n2 5 1 5 3 4 3\n2 4 3 5 6 5 1\n"
],
"output": [
"1 0 0 2 ",
"0 0 0 1 0 2 4 "
]
} | {
"input": [
"1\n0\n0\n",
"10\n6 3 0 5 4 5 5 5 8 5\n3 8 2 9 5 4 1 0 3 6\n",
"5\n1 4 2 1 3\n3 3 1 0 1\n",
"5\n2 1 3 0 4\n1 0 3 2 3\n",
"4\n1 2 1 1\n1 3 0 2\n",
"3\n2 0 0\n1 0 2\n",
"4\n1 1 0 3\n2 0 2 2\n",
"3\n0 1 1\n0 1 0\n",
"2\n1 1\n0 1\n",
"3\n2 0 0\n2 2 0\n",
"2\n0 0\n1... | 1,700 | 0 |
2 | 8 | 117_B. Very Interesting Game | In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi... | {
"input": [
"4 0 9\n",
"1 10 7\n"
],
"output": [
"1 000000001\n",
"2\n"
]
} | {
"input": [
"1 2 11\n",
"576695 1234562 1234567\n",
"138 11711 11829\n",
"1000000000 100050 1000001\n",
"116482865 344094604 3271060\n",
"0 3 3\n",
"0 0 1\n",
"7004769 3114686 4659684\n",
"0 1 1\n",
"100 2 3\n",
"4 3 12\n",
"0 1000000000 10000000\n",
"6 4 10\n",
... | 1,800 | 1,000 |
2 | 9 | 1198_C. Matching vs Independent Set | You are given a graph with 3 β
n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.
A set of edges is called a matching if no two edges share an endpoint.
A set of vertices is called an independent set if no two vertices are connected with an edge.
Input
The first line... | {
"input": [
"4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n"
],
"output": [
"Matching\n1 \nMatching\n1 \nIndSet\n3 4 \nMatching\n1 10 \n"
]
} | {
"input": [
"4\n1 2\n1 3\n1 2\n1 2\n1 3\n1 2\n2 5\n1 2\n3 1\n1 4\n5 1\n1 6\n2 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6\n",
"1\n5 39\n1 2\n3 4\n5 6\n7 8\n1 9\n3 10\n3 11\n5 12\n5 13\n7 14\n7 15\n9 2\n10 2\n11 2\n12 2\n13 2\n14 2\n15 2\n9 4\n10 4\n11 4\n12 4\n13 4\n14 4\n15... | 2,000 | 1,250 |
2 | 8 | 1215_B. The Number of Products | You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i β 0).
You have to calculate two following values:
1. the number of pairs of indices (l, r) (l β€ r) such that a_l β
a_{l + 1} ... a_{r - 1} β
a_r is negative;
2. the number of pairs of indices (l, r) (l β€ r) such that a_l β
a... | {
"input": [
"10\n4 2 -4 3 1 2 -4 3 2 3\n",
"5\n-1 -2 -3 -4 -5\n",
"5\n5 -3 3 -1 1\n"
],
"output": [
"28 27\n",
"9 6\n",
"8 7\n"
]
} | {
"input": [
"2\n-703630698 870277542\n",
"3\n-1 -1 1\n",
"2\n1000000000 -1000000000\n",
"2\n1 1\n",
"1\n1761402\n",
"5\n1 1 1 1 1\n",
"1\n1\n",
"2\n665876657 284761489\n",
"1\n-648613522\n",
"10\n-27433367 -21216390 1 303383863 -799030648 -1 160141051 -1 -342089574 -215298491\... | 1,400 | 1,000 |
2 | 11 | 1256_E. Yet Another Division Into Teams | There are n students at your university. The programming skill of the i-th student is a_i. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2 β
10^5 students ready for the finals!
Each team should consist of at least three s... | {
"input": [
"5\n1 1 3 4 2\n",
"6\n1 5 12 13 2 15\n",
"10\n1 2 5 129 185 581 1041 1909 1580 8150\n"
],
"output": [
"3 1\n1 1 1 1 1 ",
"7 2\n2 2 1 1 2 1\n",
"7486 3\n3 3 3 2 2 2 2 1 1 1\n"
]
} | {
"input": [
"10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n",
"6\n1 1 2 2 3 3\n"
],
"output": [
"0 3\n3 3 3 3 2 2 2 1 1 1 \n",
"2 2\n2 2 2 1 1 1\n"
]
} | 2,000 | 0 |
2 | 11 | 127_E. E-reader Display | After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read... | {
"input": [
"5\n01110\n10010\n10001\n10011\n11110\n"
],
"output": [
"4\n"
]
} | {
"input": [
"3\n000\n000\n000\n",
"10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n",
"10\n1101010101\n1110101010\n0111010101\n1011101010\n0101110101\n1010111010\n0101011101\n1010101110\n0101010111\n1010101011\n",
"2\n11\n11\... | 2,000 | 1,500 |
2 | 11 | 1342_E. Placing Rooks | Calculate the number of ways to place n rooks on n Γ n chessboard so that both following conditions are met:
* each empty cell is under attack;
* exactly k pairs of rooks attack each other.
An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two... | {
"input": [
"4 0\n",
"3 2\n",
"1337 42\n",
"3 3\n"
],
"output": [
"24\n",
"6\n",
"807905441\n",
"0\n"
]
} | {
"input": [
"4 5\n",
"4 3\n",
"3000 3000\n",
"200000 200000\n",
"200000 1000\n",
"3000 0\n",
"2 1\n",
"3 0\n",
"4 4\n",
"3000 42\n",
"4 1\n",
"200000 199999\n",
"4 6\n",
"200000 199998\n",
"200000 3393\n",
"1 0\n",
"3 1\n",
"1500 1000\n",
"2... | 2,300 | 0 |
2 | 9 | 1406_C. Link Cut Centroids | Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles.
A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the sma... | {
"input": [
"2\n5\n1 2\n1 3\n2 4\n2 5\n6\n1 2\n1 3\n1 4\n2 5\n2 6\n"
],
"output": [
"1 2\n1 2\n2 5\n1 5\n"
]
} | {
"input": [
"15\n4\n1 2\n2 3\n3 4\n4\n1 2\n2 4\n3 4\n4\n1 2\n1 3\n1 4\n4\n1 3\n2 3\n4 3\n4\n1 4\n3 4\n2 3\n4\n4 1\n3 2\n2 1\n5\n1 2\n2 3\n3 4\n4 5\n5\n1 2\n2 3\n4 1\n5 1\n5\n1 2\n3 1\n4 1\n1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6\n1 3\n2 3\n3 4\n4 5\n4 6\n3\n1 2\n1 3\n3\n2 1\n2 3\n3\n3 1\n3 2\n4\n1 2\n2 3\n2 4\n",
... | 1,700 | 1,500 |
2 | 10 | 1427_D. Unshuffling a Deck | You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation.
* Choose 2 β€ k β€ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f... | {
"input": [
"1\n1\n",
"6\n6 5 4 3 2 1\n",
"4\n3 1 2 4\n"
],
"output": [
"0\n",
"4\n3 1 1 4\n3 1 1 4\n3 1 1 4\n3 2 2 2\n",
"2\n3 1 2 1\n2 1 3\n"
]
} | {
"input": [
"44\n1 32 3 18 5 41 27 26 9 10 11 31 13 14 19 35 17 4 22 40 21 15 24 23 44 8 7 43 29 30 37 2 33 34 28 36 12 38 39 20 6 42 16 25\n",
"51\n51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n",
"52\n1 2... | 2,000 | 1,000 |
2 | 10 | 1523_D. Love-Hate | <image>
William is hosting a party for n of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others.
For each William's friend i it is known whether he likes currency j. There are... | {
"input": [
"3 4 3\n1000\n0110\n1001\n",
"5 5 4\n11001\n10101\n10010\n01110\n11011\n"
],
"output": [
"\n1000\n",
"\n10001\n"
]
} | {
"input": [
"2 30 15\n111010000000110001001001111111\n000101111111001110110110000000\n",
"6 30 15\n111111111111111000000000000000\n111111111111111000000000000000\n111111111111111000000000000000\n000000000000000111111111111111\n000000000000000111111111111111\n000000000000000111111111111111\n",
"20 15 4\n0... | 2,400 | 2,250 |
2 | 9 | 155_C. Hometask | Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about ... | {
"input": [
"ababa\n1\nab\n",
"codeforces\n2\ndo\ncs\n"
],
"output": [
"2",
"1\n"
]
} | {
"input": [
"pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n",
"mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n",
"nllnrlrnll\n1\nrl\n",
"aludfbjtwnkgnfl\n1\noy\n",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | 1,600 | 500 |
2 | 10 | 177_D1. Encrypting Messages | The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.
A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers... | {
"input": [
"3 1 5\n1 2 3\n4\n",
"4 3 2\n1 1 1 1\n1 1 1\n"
],
"output": [
"0 1 2 \n",
"0 1 1 0 \n"
]
} | {
"input": [
"80 6 99\n48 97 9 77 73 21 86 78 48 5 71 16 42 67 90 27 30 52 41 86 53 4 60 17 66 38 94 46 51 51 70 11 1 16 74 53 17 12 82 95 51 33 83 70 45 27 90 57 67 2 68 15 20 61 47 90 11 5 95 33 69 35 79 51 95 45 10 17 12 88 93 43 31 31 85 68 85 81 70 43\n47 92 59 85 73 38\n",
"20 15 17\n4 9 14 11 15 16 15 ... | 1,200 | 30 |
2 | 12 | 245_F. Log Stream Analysis | You've got a list of program warning logs. Each record of a log stream is a string in this format:
"2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes).
String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ... | {
"input": [
"60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n",
"2 2\n2012-03-16 23:59:59:Disk size is too s... | {
"input": [
"2 3\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant write varlog\n2012-03-16 16:15:02: Unable to start process\n2012-03-16 16:16:43: Dis\n2012-03-16 16:16:53: Timeout detected\n",
"2 4\n2012-02-20 16:15:00: Dis\n2012-03-16 16:15:01: Net\n2012-03-16 16:15:02: Cant w... | 2,000 | 0 |
2 | 10 | 270_D. Greenhouse Effect | Emuskald is an avid horticulturist and owns the world's longest greenhouse β it is effectively infinite in length.
Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o... | {
"input": [
"3 3\n1 5.0\n2 5.5\n3 6.0\n",
"6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n",
"3 2\n2 1\n1 2.0\n1 3.100\n"
],
"output": [
"0\n",
"2\n",
"1\n"
]
} | {
"input": [
"20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.... | 1,700 | 1,000 |
2 | 7 | 294_A. Shaass and Oskols | Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ... | {
"input": [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
],
"output": [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
]
} | {
"input": [
"1\n100\n1\n1 100\n",
"5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n",
"2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1\n",
"10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51\n",
"1\n10\n0\n",
"1\n100\n1\n1 1\n",
"100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 ... | 800 | 500 |
2 | 10 | 317_D. Game with Powers | Vasya and Petya wrote down all integers from 1 to n to play the "powers" game (n can be quite large; however, Vasya and Petya are not confused by this fact).
Players choose numbers in turn (Vasya chooses first). If some number x is chosen at the current turn, it is forbidden to choose x or all of its other positive in... | {
"input": [
"8\n",
"1\n",
"2\n"
],
"output": [
"Petya\n",
"Vasya\n",
"Petya\n"
]
} | {
"input": [
"10154\n",
"19000881\n",
"6\n",
"18\n",
"3\n",
"947039074\n",
"19000883\n",
"10\n",
"945070564\n",
"15\n",
"987719184\n",
"956726760\n",
"16\n",
"12\n",
"1000000000\n",
"992187002\n",
"987719182\n",
"951352336\n",
"956726762\n",
... | 2,300 | 1,500 |
2 | 7 | 365_A. Good Number | Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).
Input
The first line contains integers n and k (1 β€ n β€ 100, 0 β€ k β€ 9). The i-th ... | {
"input": [
"2 1\n1\n10\n",
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n"
],
"output": [
"1\n",
"10\n"
]
} | {
"input": [
"1 0\n1000000000\n",
"1 3\n1\n",
"2 8\n12345678\n1230\n",
"6 1\n10\n102\n120\n1032\n1212103\n1999999\n",
"6 0\n10\n102\n120\n1032\n1212103\n1999999\n",
"1 1\n1\n",
"1 3\n1000000000\n",
"1 2\n2220\n",
"1 0\n1\n",
"6 9\n10\n102\n120\n1032\n1212103\n1999999\n",
"2... | 1,100 | 500 |
2 | 9 | 409_C. Magnum Opus | Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce in vitro et Γ¦stus, et nil admirari. Festina lente, et nulla tenaci invia est via.
Fac... | {
"input": [
"2 4 6 8 10\n"
],
"output": [
"1\n"
]
} | {
"input": [
"18 13 91 64 22\n",
"31 38 47 26 13\n",
"65 46 3 77 81\n",
"94 21 36 89 20\n",
"12 39 3 50 84\n",
"75 82 48 95 12\n",
"46 68 3 0 51\n",
"1 1 2 6 4\n",
"50 27 17 31 89\n",
"42 9 59 19 24\n",
"74 21 36 68 80\n",
"50 87 29 81 21\n",
"0 74 25 35 48\n",
... | 1,700 | 0 |
2 | 11 | 459_E. Pashmak and Graph | Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.
You are given a weighted directed graph with n vertices and m edges. You need to find a path (perh... | {
"input": [
"6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n",
"3 3\n1 2 1\n2 3 1\n3 1 1\n",
"3 3\n1 2 1\n2 3 2\n3 1 3\n"
],
"output": [
"6\n",
"1\n",
"3\n"
]
} | {
"input": [
"6 7\n1 2 1\n1 5 1\n5 2 3\n2 3 3\n3 4 4\n1 6 1\n6 2 3\n",
"3 6\n1 2 1\n2 3 1\n3 1 1\n2 1 2\n3 2 4\n1 3 3\n",
"2 2\n1 2 1\n2 1 2\n",
"4 3\n1 2 1\n2 3 1\n3 4 2\n",
"4 3\n1 2 1\n3 4 1\n2 1 2\n",
"5 5\n1 2 3\n1 3 3\n2 3 4\n3 4 4\n4 5 5\n",
"4 12\n1 2 2\n2 1 2\n1 3 1\n3 1 1\n1 4 1\... | 1,900 | 3,000 |
2 | 10 | 505_D. Mr. Kitayuta's Technology | Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.
Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha... | {
"input": [
"4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4\n",
"4 5\n1 2\n1 3\n1 4\n2 3\n2 4\n"
],
"output": [
"4",
"3"
]
} | {
"input": [
"7 13\n6 1\n7 2\n3 7\n6 5\n3 6\n7 4\n3 5\n4 1\n3 1\n1 5\n1 6\n6 2\n2 4\n",
"8 12\n6 1\n7 5\n2 5\n4 1\n6 3\n4 3\n5 7\n1 3\n5 2\n2 7\n4 6\n7 2\n",
"10 10\n10 6\n9 4\n7 8\n1 5\n3 10\n2 1\n4 9\n5 2\n10 3\n6 3\n",
"10 4\n7 4\n6 8\n2 3\n3 8\n",
"2 1\n1 2\n",
"5 3\n4 2\n2 1\n5 4\n",
... | 2,200 | 2,000 |
2 | 11 | 554_E. Love Triangles | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (the... | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"3 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n"
],
"output": [
"1",
"4",
"0"
]
} | {
"input": [
"4 4\n1 2 0\n2 3 0\n2 4 0\n3 4 0\n",
"6 6\n1 2 0\n2 3 1\n3 4 0\n4 5 1\n5 6 0\n6 1 1\n",
"5 5\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n1 5 0\n",
"9 2\n1 2 0\n2 3 0\n",
"28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\n10019... | 2,200 | 1,000 |
2 | 10 | 580_D. Kefa and Dishes | When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible.
Kefa knows that the i-th dish gives him ai units of satisfact... | {
"input": [
"2 2 1\n1 1\n2 1 1\n",
"4 3 2\n1 2 3 4\n2 1 5\n3 4 2\n"
],
"output": [
"3",
"12"
]
} | {
"input": [
"10 5 5\n45 45 12 67 32 6 125 33 89 100\n6 3 78\n1 2 23\n5 7 17\n9 2 90\n4 8 39\n",
"16 12 2\n215685056 606689499 786509392 322681480 170763622 255981931 402020260 580776290 525819654 50248606 830314959 223078821 851769718 76817680 251067040 491418559\n14 4 951819487\n4 2 770897556\n",
"18 18... | 1,800 | 2,000 |
2 | 9 | 602_C. The Two Routes | In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network β for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one r... | {
"input": [
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"4 2\n1 3\n3 4\n"
],
"output": [
"3\n",
"-1\n",
"2\n"
]
} | {
"input": [
"3 1\n1 2\n",
"3 1\n1 3\n",
"400 1\n1 400\n",
"3 0\n",
"20 1\n20 1\n",
"3 3\n1 2\n2 3\n3 1\n",
"5 4\n1 2\n3 2\n3 4\n5 4\n",
"3 2\n2 3\n3 1\n",
"381 0\n",
"2 1\n1 2\n",
"100 1\n100 1\n",
"4 5\n1 3\n2 1\n3 4\n4 2\n2 3\n",
"4 1\n1 4\n",
"20 0\n",
"... | 1,600 | 500 |
2 | 7 | 625_A. Guest From the Past | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | {
"input": [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
],
"output": [
"2\n",
" 2\n"
]
} | {
"input": [
"10\n5\n10\n1\n",
"999999999999999999\n2\n50000000000000000\n49999999999999999\n",
"10\n5\n5\n1\n",
"100\n10\n10\n9\n",
"1001\n1000\n1000\n999\n",
"10\n4\n14\n13\n",
"10\n1\n2\n1\n",
"10\n20\n100\n99\n",
"999999999999999999\n180\n180\n1\n",
"999999999\n2\n999999998... | 1,700 | 750 |
2 | 9 | 673_C. Bear and Colors | Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the bigges... | {
"input": [
"3\n1 1 1\n",
"4\n1 2 1 2\n"
],
"output": [
"6 0 0\n",
"7 3 0 0\n"
]
} | {
"input": [
"10\n9 1 5 2 9 2 9 2 1 1\n",
"50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32 19 34 19 34 22 7 28 6 13 19 30 13 30\n",
"2\n2 1\n",
"1\n1\n",
"150\n28 124 138 71 71 18 78 136 138 93 145 93 18 15 71 47 47 64 18 72 138 72 1... | 1,500 | 500 |
2 | 8 | 740_B. Alyona and flowers | Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa... | {
"input": [
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"2 2\n-1 -2\n1 1\n1 2\n"
],
"output": [
"16\n",
"7\n",
"0\n"
]
} | {
"input": [
"3 3\n1 -1 3\n1 2\n2 3\n1 3\n",
"16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15... | 1,200 | 1,000 |
2 | 7 | 764_A. Taymyr is calling you | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day cons... | {
"input": [
"1 1 10\n",
"2 3 9\n",
"1 2 5\n"
],
"output": [
"10\n",
"1\n",
"2\n"
]
} | {
"input": [
"972 1 203\n",
"6 4 36\n",
"550 1 754\n",
"10 20 10000\n",
"4 8 9\n",
"1 1 1\n",
"1 2 10\n",
"10000 1 10000\n",
"3443 2 6701\n",
"358 2 809\n",
"860 1 884\n",
"7 9 2\n",
"10000 10000 10000\n",
"2940 1 9311\n",
"1 10000 10000\n",
"2 2 1\n",
... | 800 | 500 |
2 | 9 | 787_C. Berzerk | Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the oth... | {
"input": [
"8\n4 6 2 3 4\n2 3 6\n",
"5\n2 3 2\n3 1 2 3\n"
],
"output": [
"Win Win Win Win Win Win Win \nLose Win Lose Lose Win Lose Lose \n",
"Lose Win Win Loop \nLoop Win Win Win \n"
]
} | {
"input": [
"1000\n14 77 649 670 988 469 453 445 885 101 58 728 474 488 230\n8 83 453 371 86 834 277 847 958\n",
"100\n84 80 73 28 76 21 44 97 63 59 6 77 41 2 8 71 57 19 33 46 92 5 61 88 53 68 94 56 14 35 4 47 17 79 84 10 67 58 45 38 13 12 87 3 91 30 15 11 24 55 62 39 83 43 89 1 81 75 50 86 72 18 52 78 7 29 ... | 2,000 | 750 |
2 | 13 | 808_G. Anthem of Berland | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | {
"input": [
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n",
"winlose???winl???w??\nwin\n"
],
"output": [
"3",
"2",
"5"
]
} | {
"input": [
"ww?ww\nw\n",
"xznxr\nxznxr\n",
"????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????... | 2,300 | 0 |
2 | 7 | 854_A. Fraction | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive comm... | {
"input": [
"12\n",
"4\n",
"3\n"
],
"output": [
"5 7\n",
"1 3\n",
"1 2\n"
]
} | {
"input": [
"998\n",
"69\n",
"9\n",
"1000\n",
"5\n",
"10\n",
"8\n",
"994\n",
"100\n",
"423\n",
"999\n",
"997\n",
"57\n",
"34\n",
"13\n",
"6\n",
"876\n",
"995\n",
"29\n",
"24\n",
"11\n",
"996\n",
"17\n"
],
"output": [
... | 800 | 500 |
2 | 7 | 902_A. Visiting a Friend | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point m on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost ... | {
"input": [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
],
"output": [
"YES\n",
"NO\n"
]
} | {
"input": [
"50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n",
"30 40\n0 0\n4 8... | 1,100 | 500 |
2 | 9 | 924_C. Riverside Curio | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water d... | {
"input": [
"5\n0 1 1 2 2\n",
"6\n0 1 0 3 0 2\n",
"5\n0 1 2 1 2\n"
],
"output": [
"0\n",
"6\n",
"1\n"
]
} | {
"input": [
"7\n0 1 1 3 0 0 6\n",
"1\n0\n",
"3\n0 1 0\n",
"9\n0 1 0 1 1 4 0 4 8\n",
"10\n0 1 2 0 4 5 3 6 0 5\n",
"4\n0 0 1 2\n",
"6\n0 0 0 2 0 1\n",
"3\n0 1 2\n",
"5\n0 1 0 3 1\n",
"100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15 19 15 7 17 1... | 1,700 | 1,250 |
2 | 11 | 952_E. Cheese Board | Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard).
<image>
Input
The first line of input contains a single integer N (1 β€ N β€ 100) β the number of cheeses you have.
The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and... | {
"input": [
"6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard\n",
"9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard\n"
],
"output": [
"4\n",
"3\n"
]
} | {
"input": [
"9\ngorgonzola soft\ncambozola soft\nmascarpone soft\nricotta soft\nmozzarella soft\nbryndza soft\njarlsberg soft\nhavarti soft\nstilton soft\n",
"17\ngewvfeq soft\noaximz hard\nxkfscel soft\nnbxdbggw soft\ngxgsscq hard\nmqbu hard\nbtpzl soft\npsv soft\niov soft\nhliudz soft\nbmiu soft\nqqegoe ha... | 2,000 | 0 |
2 | 8 | 99_B. Help Chef Gerasim | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup... | {
"input": [
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n250\n230\n250\n",
"5\n270\n250\n249\n230\n250\n"
],
"output": [
"Exemplary pages.\n",
"20 ml. from cup #4 to cup #1.\n",
"Unrecoverable configuration.\n"
]
} | {
"input": [
"3\n1\n1\n0\n",
"4\n0\n0\n2\n0\n",
"2\n1\n0\n",
"4\n1\n1\n0\n1\n",
"4\n2\n0\n2\n1\n",
"4\n0\n2\n0\n2\n",
"4\n0\n0\n0\n2\n",
"4\n0\n2\n2\n2\n",
"2\n1\n2\n",
"3\n2\n1\n0\n",
"4\n1\n2\n1\n0\n",
"3\n1\n2\n2\n",
"2\n0\n1\n",
"4\n2\n1\n1\n1\n",
"4\n2\... | 1,300 | 1,000 |
2 | 7 | 1000_A. Codehorses T-shirts | Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from 0 to 3 "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
Ther... | {
"input": [
"2\nM\nXS\nXS\nM\n",
"3\nXS\nXS\nM\nXL\nS\nXS\n",
"2\nXXXL\nXXL\nXXL\nXXXS\n"
],
"output": [
"0\n",
"2\n",
"1\n"
]
} | {
"input": [
"6\nM\nXXS\nXXL\nXXL\nL\nL\nXXS\nXXL\nS\nXXS\nL\nL\n",
"8\nXL\nXS\nS\nXXXL\nXXXL\nXL\nXXXL\nS\nXS\nXXXS\nXL\nL\nXXXS\nM\nXS\nXXXL\n",
"5\nXXS\nXXS\nXXL\nXXXS\nL\nXXS\nXXXL\nS\nXXS\nXXS\n",
"2\nL\nS\nM\nL\n",
"6\nXXL\nXXS\nXXXS\nL\nXXXS\nXXXL\nXXL\nL\nXXS\nXXXS\nXXXL\nXXXL\n",
"1\n... | 1,200 | 0 |
2 | 8 | 1025_B. Weakened Common Divisor | During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.
For a given list of pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n) their WCD is arbit... | {
"input": [
"2\n10 16\n7 17\n",
"3\n17 18\n15 24\n12 15\n",
"5\n90 108\n45 105\n75 40\n165 175\n33 30\n"
],
"output": [
"-1\n",
"2\n",
"3\n"
]
} | {
"input": [
"3\n14 14\n2 7\n2 2\n",
"30\n3 3\n2 2\n4 4\n8 8\n16 16\n32 32\n64 64\n128 128\n256 256\n512 512\n1024 1024\n2048 2048\n4096 4096\n8192 8192\n16384 16384\n32768 32768\n65536 65536\n131072 131072\n262144 262144\n524288 524288\n1048576 1048576\n2097152 2097152\n4194304 4194304\n8388608 8388608\n1677... | 1,600 | 1,000 |
2 | 10 | 1068_D. Array Without Local Maximums | Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a_{1} β€ a_{2},
a_{n} β€ a_{n-1} and
a_{i} β€ max(a_{i-1}, ... | {
"input": [
"3\n1 -1 2\n",
"2\n-1 -1\n"
],
"output": [
"1\n",
"200\n"
]
} | {
"input": [
"8\n-1 -1 -1 59 -1 -1 -1 -1\n",
"2\n38 38\n",
"2\n-1 35\n",
"3\n-1 200 -1\n",
"2\n24 -1\n",
"37\n52 52 66 149 149 130 47 47 26 110 185 -1 73 73 65 -1 -1 130 -1 -1 -1 94 97 190 -1 -1 49 49 54 -1 92 92 5 25 48 79 79\n",
"5\n1 3 4 1 1\n",
"7\n1 -1 -1 -1 -1 7 6\n",
"3\n-1 ... | 1,900 | 500 |
2 | 9 | 1139_C. Edgy Trees | You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.
You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, β¦, a_k] good if it satisfies the following criterion:
* We will... | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 1\n",
"4 6\n1 2 0\n1 3 0\n1 4 0\n",
"3 5\n1 2 1\n2 3 0\n"
],
"output": [
" 252\n",
" 0\n",
" ... | {
"input": [
"4 19\n2 4 1\n2 3 0\n1 4 0\n",
"13 3\n9 13 1\n8 3 1\n11 9 0\n8 13 0\n10 9 0\n2 7 0\n4 8 1\n11 5 0\n10 12 0\n12 1 1\n5 7 0\n6 8 1\n",
"2 20\n2 1 0\n",
"7 12\n4 5 0\n2 7 1\n7 6 1\n2 5 0\n2 3 0\n1 6 0\n",
"2 2\n1 2 0\n",
"19 20\n8 10 1\n17 15 1\n14 5 0\n6 14 0\n7 15 0\n19 8 1\n12 14 ... | 1,500 | 1,750 |
2 | 9 | 1157_C2. Increasing Subsequence (hard version) | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the... | {
"input": [
"7\n1 3 5 6 5 4 2\n",
"5\n1 2 4 3 2\n",
"4\n1 2 4 3\n",
"3\n2 2 2\n"
],
"output": [
"6\nLRLRRR",
"4\nLRRR",
"4\nLLRR\n",
"1\nR"
]
} | {
"input": [
"20\n2 2 2 1 1 3 1 3 3 1 2 3 3 3 2 2 2 3 1 3\n",
"17\n3 3 2 3 2 3 1 2 3 2 2 3 1 3 1 2 1\n",
"12\n3 3 2 3 2 3 1 2 1 2 2 1\n",
"18\n2 3 3 3 1 2 2 1 3 3 2 3 1 3 1 2 2 2\n",
"3\n3 1 1\n",
"5\n2 1 3 4 2\n",
"5\n3 1 2 3 1\n",
"3\n1 1 2\n",
"8\n1 3 3 2 1 1 1 1\n",
"8\n2 2... | 1,700 | 0 |
2 | 7 | 1198_A. MP3 | One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = β log_{2} ... | {
"input": [
"6 1\n2 1 2 3 4 3\n",
"6 1\n1 1 2 2 3 3\n",
"6 2\n2 1 2 3 4 3\n"
],
"output": [
"2\n",
"2\n",
"0\n"
]
} | {
"input": [
"10 500\n1 2 3 4 5 6 7 8 9 10\n",
"40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 293944170 300817194 842872332 82882809 446438478 304657690 343250734 567326942 ... | 1,600 | 500 |
2 | 8 | 1238_B. Kill 'Em All | Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'... | {
"input": [
"2\n3 2\n1 3 5\n4 1\n5 2 3 5\n"
],
"output": [
"2\n2\n"
]
} | {
"input": [
"1\n3 1383\n1 2 3\n",
"1\n3 3\n1 2 3\n"
],
"output": [
"1\n",
"1\n"
]
} | 1,300 | 0 |
2 | 9 | 1256_C. Platforms Jumping | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | {
"input": [
"7 3 2\n1 2 1\n",
"10 1 5\n2\n",
"10 1 11\n1\n"
],
"output": [
"YES\n0 1 0 2 2 0 3\n",
"YES\n0 0 0 0 1 1 0 0 0 0\n",
"YES\n0 0 0 0 0 0 0 0 0 1\n"
]
} | {
"input": [
"15 2 5\n1 1\n",
"1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n",
"6 3 1\n1 2 3\n",
"11 1 5\n2\n",
"7 1 2\n4\n",
"5 2 1\n1 1\n",
"10 1 4\n10\n",
"10 10 1\n1 1 1 1 1 1 1 1 1 1\n",
"8 4 1\n1 1 4 1\n",
"3 1 1\n2\n",
"1 1 1\n1\n",
"5 1 2\n2\n",
... | 1,700 | 0 |
2 | 9 | 127_C. Hot Bath | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... | {
"input": [
"300 500 1000 1000 300\n",
"10 70 100 100 25\n",
"143 456 110 117 273\n"
],
"output": [
"1000 0\n",
"99 33\n",
"76 54\n"
]
} | {
"input": [
"176902 815637 847541 412251 587604\n",
"1 3 100 100 3\n",
"1 1000000 1000000 1000000 2\n",
"522321 902347 10945 842811 630561\n",
"10 14 1 1 11\n",
"99 99 99 99 99\n",
"1 1000000 1000000 1000000 500000\n",
"77909 251377 937 952 115397\n",
"983534 987908 2 7 984750\n",... | 1,900 | 500 |
2 | 8 | 12_B. Correct Solution? | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
βShuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.... | {
"input": [
"3310\n1033\n",
"4\n5\n"
],
"output": [
"OK\n",
"WRONG_ANSWER\n"
]
} | {
"input": [
"17109\n01179\n",
"111111111\n111111111\n",
"912\n9123\n",
"10101\n10101\n",
"666\n0666\n",
"7391\n1397\n",
"1270\n1027\n",
"0\n00\n",
"987235645\n234556789\n",
"201\n102\n",
"0\n0\n",
"1000000000\n1\n",
"123456789\n123456789\n",
"32352320\n22203335... | 1,100 | 0 |
2 | 10 | 1323_D. Present | Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one β xor of all pairwise sums of elements in the array, she realiz... | {
"input": [
"3\n1 2 3\n",
"2\n1 2\n"
],
"output": [
"2\n",
"3\n"
]
} | {
"input": [
"51\n50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"100\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... | 2,100 | 1,000 |
2 | 9 | 1342_C. Yet Another Counting Problem | You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i β€ x β€ r_i, and ((x mod a) mod b) β ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z... | {
"input": [
"2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n"
],
"output": [
"0\n0\n0\n2\n4\n0\n91\n"
]
} | {
"input": [
"1\n200 200 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 2\n",
"1\n199 200 1\n1 1000000000000000000\n"
],
"output": [
"0\n",
"0\n",
"0\n",
"994974874371859201\n"
]
} | 1,600 | 0 |
2 | 9 | 1364_C. Ehab and Prefix MEXs | Given an array a of length n, find another array, b, of length n such that:
* for each i (1 β€ i β€ n) MEX(\\{b_1, b_2, β¦, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an ... | {
"input": [
"3\n1 2 3\n",
"3\n1 1 3\n",
"4\n0 0 0 2\n"
],
"output": [
"0 1 2\n",
"0 2 1\n",
"1 3 4 0\n"
]
} | {
"input": [
"7\n0 0 2 2 5 5 6\n",
"1\n1\n",
"10\n1 2 3 4 4 4 7 7 7 10\n",
"1\n0\n"
],
"output": [
"1 3 0 4 2 7 5\n",
"0\n",
"0 1 2 3 5 6 4 8 9 7\n",
"1\n"
]
} | 1,600 | 1,500 |
2 | 7 | 1406_A. Subset Mex | Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* m... | {
"input": [
"4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n"
],
"output": [
"5\n3\n4\n0\n"
]
} | {
"input": [
"1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99\n"... | 900 | 500 |
2 | 8 | 149_B. Martian Clock | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored... | {
"input": [
"2A:13\n",
"11:20\n",
"000B:00001\n"
],
"output": [
"0",
"3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ",
"-1"
]
} | {
"input": [
"Z:1\n",
"123:A\n",
"N:7\n",
"00001:00001\n",
"1:11\n",
"000G6:000GD\n",
"0:1N\n",
"Z:2\n",
"0:Z\n",
"Z:00\n",
"0:1A\n",
"000Z:000Z\n",
"0Z:01\n",
"A:10\n",
"00Z:01\n",
"0033:00202\n",
"000B3:00098\n",
"00Z:03\n",
"01B:4A\n",
... | 1,600 | 1,000 |
2 | 8 | 1523_B. Lord of the Values | <image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, β¦, a_n to -a_1, -a_2, β¦, -a_n... | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n"
],
"output": [
"\n8\n2 1 2\n2 1 2\n2 1 3\n2 1 3\n2 1 4\n2 1 4\n1 1 2\n1 1 2\n8\n2 1 4\n1 2 4\n1 2 4\n1 2 4\n1 3 4\n1 1 2\n1 1 2\n1 1 4\n"
]
} | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n"
],
"output": [
"12\n1 1 2\n2 1 2\n1 1 2\n2 1 2\n1 1 2\n2 1 2\n1 3 4\n2 3 4\n1 3 4\n2 3 4\n1 3 4\n2 3 4\n12\n1 1 2\n2 1 2\n1 1 2\n2 1 2\n1 1 2\n2 1 2\n1 3 4\n2 3 4\n1 3 4\n2 3 4\n1 3 4\n2 3 4\n"
]
} | 1,100 | 1,000 |
2 | 7 | 155_A. I_love_%username% | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | {
"input": [
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"5\n100 50 200 150 200\n"
],
"output": [
"4\n",
"2\n"
]
} | {
"input": [
"5\n100 36 53 7 81\n",
"5\n100 81 53 36 7\n",
"10\n8 6 3 4 9 10 7 7 1 3\n",
"33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101\n",
"34\n821 5536 2491 6074 7216 9885 7... | 800 | 500 |
2 | 9 | 177_C1. Party | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n"
],
"output": [
"3"
]
} | {
"input": [
"14\n0\n0\n",
"14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8\n",
"14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7\n",
"14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12\n8 14\n10 11\n10 12\n10 14\n11 13\n11 14\n12 14\n5\n1 8\n1 13\n2 1... | 1,500 | 30 |
2 | 8 | 198_B. Jumping on Walls | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | {
"input": [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
],
"output": [
"YES\n",
"NO\n"
]
} | {
"input": [
"2 1\n-X\nX-\n",
"25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"6 2\n--X--X\nXX-X-X\n",
"12 3\n--XX--XX-XXX\n----X---XXX-\n",
"101 1\n----------------------------------------------------------------------------------------------------X\n------------------------------... | 1,400 | 1,000 |
2 | 9 | 221_C. Little Elephant and Problem | The Little Elephant has got a problem β somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... | {
"input": [
"3\n3 2 1\n",
"4\n4 3 2 1\n",
"2\n1 2\n"
],
"output": [
"YES",
"NO",
"YES"
]
} | {
"input": [
"10\n4 4 4 4 10 4 4 4 4 4\n",
"5\n1 3 2 3 3\n",
"5\n1 2 7 3 5\n",
"11\n2 2 2 2 2 2 2 2 2 2 1\n",
"6\n1 4 3 6 2 5\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5\n",
"6\n1 2 3 1 2 3\n",
"9\n7 7 8 8 10 10 ... | 1,300 | 500 |
2 | 10 | 245_D. Restoring Table | Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ... | {
"input": [
"3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n",
"1\n-1\n"
],
"output": [
"18 18 0 ",
"128 180 148 160 ",
"0 "
]
} | {
"input": [
"6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846864\n34816 306185992 40 -1 306185000 272666176\n68550800 324272924 555155640 306185000 -1 289481232\n34832 289412624 16846864 272666176 289481232 -1\n",
"2\n-1 0\n... | 1,500 | 0 |
2 | 8 | 270_B. Multithreading | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | {
"input": [
"5\n5 2 1 3 4\n",
"4\n4 3 2 1\n",
"3\n1 2 3\n"
],
"output": [
"2\n",
"3\n",
"0\n"
]
} | {
"input": [
"4\n2 3 1 4\n",
"3\n1 3 2\n",
"6\n3 2 1 6 4 5\n",
"67\n45 48 40 32 11 36 18 47 56 3 22 27 37 12 25 8 57 66 50 41 49 42 30 28 14 62 43 51 9 63 13 1 2 4 5 6 7 10 15 16 17 19 20 21 23 24 26 29 31 33 34 35 38 39 44 46 52 53 54 55 58 59 60 61 64 65 67\n",
"132\n13 7 33 124 118 76 94 92 16 ... | 1,400 | 1,500 |
2 | 8 | 317_B. Ants | It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x ... | {
"input": [
"6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"1 3\n0 1\n0 0\n0 -1\n"
],
"output": [
"0\n1\n2\n1\n0\n",
" 0\n 1\n0\n"
]
} | {
"input": [
"203 30\n-3 3\n-3 10\n-7 -6\n1 8\n-5 2\n-9 10\n-6 4\n8 2\n-2 -5\n-3 2\n1 6\n-6 -9\n10 9\n-3 -9\n-7 5\n3 8\n1 -4\n-4 -5\n-2 1\n-6 -10\n10 10\n4 -1\n0 -2\n9 9\n-5 6\n-9 -5\n7 -10\n-6 3\n-3 -4\n9 -4\n",
"25965 53\n-1 -2\n1 5\n0 3\n4 4\n-3 -2\n5 4\n-3 -4\n-4 3\n1 -5\n2 -5\n0 4\n-1 -1\n-3 -2\n1 -5\n-1... | 2,000 | 1,000 |
2 | 8 | 341_B. Bubble Sort Graph | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a... | {
"input": [
"3\n3 1 2\n"
],
"output": [
"2\n"
]
} | {
"input": [
"100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 23 95 32 55 47\n",... | 1,500 | 2,000 |
2 | 9 | 388_C. Fox and Card Game | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | {
"input": [
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"2\n1 100\n2 1 10\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n9 2 8 6 5 9 4 7 1 3\n"
],
"output": [
"18 18\n",
"101 10\n",
"7000 7000\n",
"30 15\n"
]
} | {
"input": [
"6\n2 1 1\n2 2 2\n2 3 3\n2 4 4\n2 5 5\n2 6 6\n",
"2\n2 200 1\n3 1 100 2\n",
"2\n3 1 1000 2\n3 2 1 1\n",
"1\n1 1\n",
"5\n5 1 1 1 1 1\n4 1 1 1 1\n3 1 1 1\n2 1 1\n1 1\n",
"4\n3 1 5 100\n3 1 5 100\n3 100 1 1\n3 100 1 1\n",
"3\n5 1 2 3 4 5\n4 1 2 3 4\n8 1 2 3 4 5 6 7 8\n",
"5\n... | 2,000 | 1,500 |
2 | 7 | 409_A. The Great Game | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between ... | {
"input": [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n"
],
"output": [
"TEAM 2 WINS",
"TEAM 1 WINS"
]
} | {
"input": [
"()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()\n",
"[]8<[]()()()[]\n8<[]8<()8<()8<\n",
"8<()8<[]\n()[][]()\n",
"()\n[]\n",
"8<8<8<\n[]()8<\n",
"[]8<[]8<[]()\n8<[]8<8<[]8<\n",
"[]8<8<[]\n[]8<()[]\n",
"8<8<8<[]\n[][][][]\n",
"[]\n[]\n",
"()[]()()\n()()[]()\n",
"()[]... | 1,700 | 0 |
2 | 8 | 436_B. Om Nom and Spiders | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be represented as a rectangular n Γ m field. The park has k spiders, each spider at ... | {
"input": [
"2 2 2\n..\nRL\n",
"3 3 4\n...\nR.L\nR.U\n",
"2 2 2\n..\nUU\n",
"3 4 8\n....\nRRLL\nUUUU\n",
"2 2 2\n..\nLR\n"
],
"output": [
"1 1 ",
"0 2 2 ",
"0 0 ",
"1 3 3 1 ",
"0 0 "
]
} | {
"input": [
"3 7 14\n.......\nLDUDLLD\nDLRDDLD\n",
"4 5 15\n.....\nDRRLR\nULDLD\nDLRRL\n",
"10 8 30\n........\n.L.LDRR.\nD.LDLR.U\n..RL.L..\nUR.UL...\n.D.....L\nR..UDULL\n........\nDD.U...D\n........\n",
"5 6 20\n......\n.UURD.\nLUD.RR\nU.LDDD\nDDLDDU\n",
"5 7 19\n.......\nRDLLLRL\nUUR..U.\n.D.DL... | 1,400 | 1,000 |
2 | 9 | 459_C. Pashmak and Buses | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | {
"input": [
"3 2 2\n",
"3 2 1\n"
],
"output": [
"1 2 1\n1 1 2\n",
"-1\n"
]
} | {
"input": [
"2 1 1000\n",
"513 2 9\n",
"512 8 3\n",
"729 9 3\n",
"5 3 2\n",
"9 2 3\n",
"1000 1000000000 1\n",
"729 3 6\n",
"1000 999 1\n",
"1 1 1\n",
"1 1000000000 1\n",
"81 3 4\n",
"1 1 10\n",
"625 5 4\n",
"27 3 3\n",
"1000 2 8\n",
"243 3 5\n",
... | 1,900 | 2,000 |
2 | 8 | 480_B. Long Jumps | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | {
"input": [
"3 250 185 230\n0 185 250\n",
"2 300 185 230\n0 300\n",
"4 250 185 230\n0 20 185 250\n"
],
"output": [
"1\n230\n",
"2\n185 230\n",
"0\n"
]
} | {
"input": [
"4 100 90 91\n0 7 8 100\n",
"3 10 1 8\n0 3 10\n",
"4 100 3 5\n0 40 48 100\n",
"4 500 30 50\n0 20 40 500\n",
"4 10 8 9\n0 4 5 10\n",
"3 10 7 8\n0 9 10\n",
"4 100 7 8\n0 3 4 100\n",
"3 350 150 160\n0 310 350\n",
"3 10 2 3\n0 1 10\n",
"5 550 300 400\n0 151 251 450 550... | 1,700 | 2,000 |
2 | 8 | 505_B. Mr. Kitayuta's Colorful Graph | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers β ui... | {
"input": [
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n"
],
"output": [
"1\n1\n1\n1\n2\n",
"2\n1\n0\n"
]
} | {
"input": [
"2 1\n1 2 1\n1\n1 2\n",
"2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n",
"2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n"
],
"output": [
"1\n",
"3\n",
"5\n"
]
} | 1,400 | 1,000 |
2 | 9 | 554_C. Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | {
"input": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
],
"output": [
"3\n",
"1680\n"
]
} | {
"input": [
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n21\n25\n28\n24\n21\n21\n17\n28\n20\n20\n31\n... | 1,500 | 250 |
2 | 8 | 580_B. Kefa and Company | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t... | {
"input": [
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"4 5\n75 5\n0 100\n150 20\n75 1\n"
],
"output": [
"111",
"100"
]
} | {
"input": [
"5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n",
"4 1\n2 4\n2 2\n3 3\n3 3\n",
"3 1\n801 10101\n802 134509124\n801 1\n",
"5 6\n5 11\n10 11\n11 11\n12 11\n100 1\n",
"7 6\n5 11\n9 11\n10 11\n11 11\n12 11\n13 11\n100 1\n",
"3 3\n4 15\n0 17\n9 11\n",
"15 1234\n2... | 1,500 | 1,250 |
2 | 7 | 602_A. Two Bases | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input con... | {
"input": [
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n"
],
"output": [
">",
"<",
"="
]
} | {
"input": [
"8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"4 7\n3 0 6 6\n3 11\n7 10 10\n",
"2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"10 40\n39 39 39 39 39 39 39 39 39 39\n10 39\n38 38 38 38 38 38 38 38 38 38\n",
"9 7\n2 0 3 2 6 6 1 4 3\n9 6\n4 4 1 1 4 5 5 0 2\n",
"9 39\n1... | 1,100 | 500 |
2 | 7 | 673_A. Bear and Game | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Yo... | {
"input": [
"3\n7 20 88\n",
"9\n15 20 30 40 50 60 70 80 90\n",
"9\n16 20 30 40 50 60 70 80 90\n"
],
"output": [
"35\n",
"90\n",
"15\n"
]
} | {
"input": [
"2\n1 18\n",
"9\n6 20 27 28 40 53 59 70 85\n",
"8\n10 20 30 40 50 60 70 80\n",
"6\n13 17 32 47 60 66\n",
"1\n1\n",
"8\n5 17 20 35 42 53 67 76\n",
"1\n90\n",
"6\n14 29 43 59 70 74\n",
"76\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 ... | 800 | 500 |
2 | 8 | 698_B. Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | {
"input": [
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n",
"4\n2 3 3 4\n"
],
"output": [
"0\n3 2 2 5 3 ",
"2 \n2 3 5 4 4 4 6 7 \n",
"1 \n2 3 3 3 \n"
]
} | {
"input": [
"3\n2 1 1\n",
"6\n6 2 6 2 4 2\n",
"2\n1 2\n",
"8\n2 1 2 2 6 5 6 6\n",
"18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n",
"7\n1 2 3 4 5 6 7\n",
"7\n4 3 2 6 3 5 2\n",
"7\n7 5 3 1 2 1 5\n",
"7\n1 6 4 4 5 6 7\n"
],
"output": [
"1\n2 2 1 ",
"0\n6 2 6 2 4 2 ",... | 1,700 | 1,000 |
2 | 8 | 719_B. Anatoly and Cockroaches | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | {
"input": [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
],
"output": [
"1\n",
"2\n",
"0\n"
]
} | {
"input": [
"166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb\n",
"7\nrrbrbrb\n",
"1\nr\n",
"2\nbb\n",
"18\nrrrrrrrrrrrrrrrrrb\n",
"8\nrbbrbrbr\n",
"1\nb\n",
"13\... | 1,400 | 1,000 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.