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 | 8 | 797_B. Odd sum | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | {
"input": [
"3\n2 -5 -3\n",
"4\n-2 2 -3 1\n"
],
"output": [
"-1\n",
"3\n"
]
} | {
"input": [
"4\n1 -4 -3 -4\n",
"10\n-2 6 6 5 0 10 6 7 -1 1\n",
"8\n0 -7 -5 -5 5 -1 -8 -7\n",
"9\n-3 -1 4 4 8 -8 -5 9 -2\n",
"5\n5 5 1 2 -2\n",
"4\n-1 -3 0 -3\n",
"7\n0 7 6 2 7 0 6\n",
"3\n1 1 1\n",
"4\n2 3 0 5\n",
"7\n6 -6 -1 -5 7 1 7\n",
"9\n-9 -1 3 -2 -7 2 -9 -1 -4\n",
... | 1,400 | 0 |
2 | 10 | 817_D. Imbalanced Array | You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of arra... | {
"input": [
"3\n1 4 1\n"
],
"output": [
"9\n"
]
} | {
"input": [
"30\n2 2 9 1 10 8 3 3 1 4 6 10 2 2 1 4 1 1 1 1 1 2 4 7 6 7 5 10 8 9\n",
"10\n1 1 1 1 1 1 1 1 1 1\n",
"10\n9 6 8 5 5 2 8 9 2 2\n",
"10\n1 4 4 3 5 2 4 2 4 5\n",
"30\n6 19 12 6 25 24 12 2 24 14 10 10 24 19 11 29 10 22 7 1 9 1 2 27 7 24 20 25 20 28\n",
"100\n9 9 72 55 14 8 55 58 35 67... | 1,900 | 0 |
2 | 10 | 842_D. Vitya and Strange Lesson | Today at the lesson Vitya learned a very interesting function β mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0.
Vitya quickly understood all tasks of the teacher, but can you do the sa... | {
"input": [
"2 2\n1 3\n1\n3\n",
"5 4\n0 1 5 6 7\n1\n1\n4\n5\n",
"4 3\n0 1 5 6\n1\n2\n4\n"
],
"output": [
"1\n0\n",
"2\n2\n0\n2\n",
"2\n0\n0\n"
]
} | {
"input": [
"10 30\n0 0 0 0 0 0 0 0 0 0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"5 5\n1 2 3 4 5\n1\n2\n3\n4\n5\n",
"17 30\n4194 1990 2257 1363 2798 386 3311 3152 1808 1453 3874 4388 1268 3924 3799 1269 968\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\... | 2,000 | 2,000 |
2 | 10 | 863_D. 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 li ri β perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li β€ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari;
... | {
"input": [
"6 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3\n"
],
"output": [
"3 3 1 5 2 "
]
} | {
"input": [
"1 1 1\n474812122\n2 1 1\n1\n",
"5 2 5\n64 3 4 665 2\n1 1 3\n2 1 5\n1 2 3 4 5\n"
],
"output": [
"474812122 ",
"2 665 3 64 4 "
]
} | 1,800 | 0 |
2 | 7 | 889_A. Petya and Catacombs | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | {
"input": [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
],
"output": [
"2\n",
"3\n"
]
} | {
"input": [
"100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13\n",
"1\n0\n",
"7\n0 1 0 0 0 0 0\n",
... | 1,300 | 1,500 |
2 | 12 | 911_F. Tree Destruction | You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps:
1. choose two leaves;
2. add the length of the simple path between them to the answer;
3. remove one of the chosen leaves from the tree.
Initial an... | {
"input": [
"5\n1 2\n1 3\n2 4\n2 5\n",
"3\n1 2\n1 3\n"
],
"output": [
"9\n3 5 5\n4 3 3\n4 1 1\n4 2 2\n",
"3\n2 3 3\n2 1 1\n"
]
} | {
"input": [
"8\n6 2\n2 1\n1 8\n8 5\n5 7\n7 3\n3 4\n",
"7\n2 7\n7 6\n6 5\n5 4\n4 1\n1 3\n",
"5\n1 4\n1 2\n1 3\n1 5\n",
"10\n7 10\n10 6\n6 4\n4 5\n5 8\n8 2\n2 1\n1 3\n3 9\n",
"9\n1 6\n1 4\n1 5\n1 9\n1 8\n1 7\n1 3\n1 2\n",
"4\n3 4\n4 1\n1 2\n",
"10\n5 6\n6 7\n7 3\n7 8\n7 4\n7 2\n7 1\n7 10\n7... | 2,400 | 0 |
2 | 7 | 960_A. Check the string | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | {
"input": [
"aabc\n",
"aaabccc\n",
"bbacc\n"
],
"output": [
"YES\n",
"YES\n",
"NO\n"
]
} | {
"input": [
"aa\n",
"ccbcc\n",
"bc\n",
"c\n",
"babc\n",
"aaa\n",
"aaccaa\n",
"aabbcc\n",
"aabbcccc\n",
"b\n",
"cc\n",
"ccbbaa\n",
"abababccc\n",
"acbbc\n",
"aabb\n",
"aabaccc\n",
"bbabbc\n",
"ac\n",
"acba\n",
"abcb\n",
"aacc\n",
... | 1,200 | 500 |
2 | 7 | 1006_A. Adjacent Replacements | Mishka got an integer array a of length n as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
* Replace each occurre... | {
"input": [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
],
"output": [
"1 1 3 5 9 ",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999 "
]
} | {
"input": [
"3\n2 2 2\n",
"2\n2 2\n",
"1\n2441139\n",
"1\n999999999\n",
"2\n4 4\n",
"1\n210400\n",
"1\n1000000000\n",
"5\n100000000 100000000 100000000 100000000 100000000\n"
],
"output": [
"1 1 1 ",
"1 1 ",
"2441139 ",
"999999999 ",
"3 3 ",
"210399 ",
... | 800 | 0 |
2 | 12 | 1029_F. Multicolored Markers | There is an infinite board of square tiles. Initially all tiles are white.
Vova has a red marker and a blue marker. Red marker can color a tiles. Blue marker can color b tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be e... | {
"input": [
"3 9\n",
"4 4\n",
"506 2708\n",
"3 6\n",
"9 3\n"
],
"output": [
"14\n",
"12\n",
"3218\n",
"12\n",
"14\n"
]
} | {
"input": [
"97821761637600 97821761637600\n",
"99999999999962 99999999999973\n",
"1 1\n",
"11 49\n",
"2 2\n",
"1 6\n",
"99999999999973 99999999999971\n",
"11003163441270 11003163441270\n",
"87897897895 29835496161\n",
"58 53\n",
"1 2\n",
"100000000000000 1000000000000... | 2,000 | 0 |
2 | 7 | 1073_A. Diverse Substring | You are given a string s, consisting of n lowercase Latin letters.
A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is not.
The length of the substring is the number of letters in it.
Let's call some string of length n diverse if and o... | {
"input": [
"5\naaaaa\n",
"10\ncodeforces\n"
],
"output": [
"NO\n",
"YES\nco\n"
]
} | {
"input": [
"4\ncbba\n",
"6\naabbcc\n",
"6\naabbab\n",
"2\nss\n",
"2\nab\n",
"3\nbaa\n",
"3\nabb\n",
"4\naaba\n",
"1\ng\n",
"6\nsssssa\n",
"2\naa\n",
"5\naabaa\n",
"4\naabb\n",
"3\naba\n",
"9\naabbccaab\n",
"10\ncodeforces\n",
"5\noomph\n",
"25\... | 1,000 | 0 |
2 | 7 | 1095_A. Repeating Cipher | Polycarp loves ciphers. He has invented his own cipher called repeating.
Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{m} (1 β€ m β€ 10), Polycarp uses the following algorithm:
* he writes down s_1 ones,
* he writes down s_2 twice,
* he writes down s_3 three times,
* ...
... | {
"input": [
"6\nbaabbb\n",
"10\nooopppssss\n",
"1\nz\n"
],
"output": [
"bab",
"oops",
"z"
]
} | {
"input": [
"testa\n",
"zqwertyuioasdfghjklrtyuiodfghjklqwertyuioasdfssd\n",
"ncteho\n",
"code\n",
"qwertyuioasdfghjklrtyuiodfghjklqwertyuioasdfssddxb\n",
"gecabdfh\n",
"bz\n",
"3\nzww\n",
"aechs\n",
"abcdef\n",
"erfdcoeocs\n",
"abcdefg\n",
"55\naaaaaaaaaaaaaaaaaaa... | 800 | 0 |
2 | 8 | 1114_B. Yet Another Array Partitioning Task | An array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, β¦, a_r for some l, r.
Suppose m is some known constant. For any array, having m or more elements, let's define it's beauty as the sum of m largest elements of that array. For example:
* ... | {
"input": [
"2 1 2\n-1000000000 1000000000\n",
"9 2 3\n5 2 5 2 4 1 1 3 2\n",
"6 1 4\n4 1 3 2 2 3\n"
],
"output": [
"0\n1 ",
"21\n2 4 ",
"12\n1 3 4 "
]
} | {
"input": [
"37 3 10\n74 42 92 -64 -11 -37 63 81 -58 -88 52 -6 40 -24 29 -10 -23 41 -36 -53 1 94 -65 47 87 -40 -84 -65 -1 99 35 51 40 -21 36 84 -48\n",
"69 9 5\n-7 10 7 3 8 -9 9 -6 -5 -1 6 7 -3 10 2 3 -10 3 1 -7 -9 -10 7 2 -10 -7 -5 -5 -8 -7 4 3 10 -7 -8 7 4 6 -5 -6 8 -7 6 -5 -1 -4 0 -3 1 -2 -8 -3 -4 9 8 5 5... | 1,500 | 1,250 |
2 | 9 | 1142_C. U2 | Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one.
Vasya drew several distinct points with integer coordinates on a plane and then drew an... | {
"input": [
"3\n-1 0\n0 2\n1 0\n",
"5\n1 0\n1 -1\n0 -1\n-1 0\n-1 -1\n"
],
"output": [
"2\n",
"1\n"
]
} | {
"input": [
"1\n-751115 -925948\n"
],
"output": [
"0\n"
]
} | 2,400 | 1,500 |
2 | 11 | 1162_E. Thanos Nim | Alice and Bob are playing a game with n piles of stones. It is guaranteed that n is an even number. The i-th pile has a_i stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly n/2 nonempty piles and independently remove a positive number of stone... | {
"input": [
"4\n3 1 4 1\n",
"2\n8 8\n"
],
"output": [
"Alice\n",
"Bob\n"
]
} | {
"input": [
"4\n2 3 3 3\n",
"4\n1 2 2 2\n",
"8\n1 1 1 1 1 2 2 2\n",
"44\n28 28 36 40 28 28 35 28 28 33 33 28 28 28 28 47 28 43 28 28 35 38 49 40 28 28 34 39 45 32 28 28 28 50 39 28 32 28 50 32 28 33 28 28\n",
"4\n2 1 1 1\n",
"28\n48 14 22 14 14 14 14 14 47 39 14 36 14 14 49 41 36 45 14 34 14 ... | 2,000 | 1,500 |
2 | 10 | 1183_D. Candy Box (easy version) | This problem is actually a subproblem of problem G from the same contest.
There are n candies in a candy box. The type of the i-th candy is a_i (1 β€ a_i β€ n).
You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all di... | {
"input": [
"3\n8\n1 4 8 4 5 6 3 8\n16\n2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1\n9\n2 2 4 4 4 7 7 7 7\n"
],
"output": [
"3\n10\n9\n"
]
} | {
"input": [
"3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n"
],
"output": [
"6\n3\n1\n"
]
} | 1,400 | 0 |
2 | 11 | 1200_E. Compress Words | Amugae has a sentence consisting of n words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "sa... | {
"input": [
"5\nsample please ease in out\n",
"5\nI want to order pizza\n"
],
"output": [
"sampleaseinout\n",
"Iwantorderpizza\n"
]
} | {
"input": [
"2\nPCXFTTTQEZ EHZMCWSWUW\n",
"2\nbq5rwXgEwj 9J5SlbNxMd\n",
"2\nORKJRPHXPV GKQFDIKTTC\n",
"4\nX XtS XtS XtSo4P0Mhj\n",
"2\nBPHNQFVKHX NFXBLVAWZL\n",
"9\nM M5 M5D M5DAYBl0r6gmttCTR M5DAYBl0r6gmttCTRoKdM9EFrX22qBZpAc M5DAYBl0r6gmttCTRoKdM9EFrX22qBZpAczv7fKrVhg0xe M5DAYBl0r6gmttCTRoK... | 2,000 | 2,000 |
2 | 10 | 1261_D1. Wrong Answer on test 233 (Easy Version) | Your program fails again. This time it gets "Wrong answer on test 233"
.
This is the easier version of the problem. In this version 1 β€ n β€ 2000. You can hack this problem only if you solve and lock both problems.
The problem is about a test containing n one-choice-questions. Each of the questions contains k options... | {
"input": [
"3 3\n1 3 1\n",
"5 5\n1 1 4 2 2\n"
],
"output": [
"9\n",
"1000\n"
]
} | {
"input": [
"98 102\n79 30 51 87 80 91 32 16 21 54 79 14 48 24 8 66 9 94 45 50 85 82 54 89 44 92 23 62 47 11 75 33 102 27 63 39 91 38 33 55 81 63 81 87 26 19 41 85 46 56 91 97 67 30 94 45 40 5 22 8 23 34 8 77 43 66 67 31 7 77 26 22 19 71 26 82 69 52 40 4 98 27 63 74 68 74 55 75 25 51 18 100 22 66 50 38 43 43\n",... | 2,200 | 1,000 |
2 | 12 | 1283_F. DIY Garland | Polycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself.
Simple garlands consisting of several lamps connected by one wire are too boring for Polycarp. He is going to solder a garland consisting of n lam... | {
"input": [
"6\n3 6 3 1 5\n"
],
"output": [
"3\n3 6\n6 5\n3 1\n1 4\n5 2\n"
]
} | {
"input": [
"100\n1 48 78 56 75 22 48 7 28 70 77 32 43 71 40 72 29 28 83 15 9 16 52 40 91 14 69 75 13 95 5 6 53 47 93 33 92 7 7 95 51 66 11 58 77 3 29 27 34 89 80 60 47 95 79 60 3 32 86 50 39 85 5 58 99 6 29 42 36 77 53 15 8 78 51 58 65 96 49 47 70 70 80 37 47 51 40 12 57 19 5 77 32 47 68 86 44 57 60\n",
"10... | 2,200 | 0 |
2 | 9 | 1327_C. Game with Chips | Petya has a rectangular Board of size n Γ m. Initially, k chips are placed on the board, i-th chip is located in the cell at the intersection of sx_i-th row and sy_i-th column.
In one action, Petya can move all the chips to the left, right, down or up by 1 cell.
If the chip was in the (x, y) cell, then after the oper... | {
"input": [
"5 4 3\n3 4\n3 1\n3 3\n5 3\n1 3\n1 4\n",
"3 3 2\n1 2\n2 1\n3 3\n3 2\n"
],
"output": [
"26\nUUUULLLRRRDLLLDRRRDLLLDRRR",
"12\nUULLRRDLLDRR"
]
} | {
"input": [
"3 3 2\n1 2\n2 1\n3 3\n3 2\n",
"2 2 1\n1 1\n1 1\n",
"2 2 2\n2 1\n2 1\n1 2\n1 1\n",
"10 10 20\n7 5\n4 5\n5 4\n7 4\n1 5\n6 7\n9 5\n8 4\n1 4\n2 10\n3 10\n4 10\n3 6\n5 7\n6 2\n1 1\n10 9\n7 6\n1 4\n6 4\n8 2\n8 3\n5 1\n10 4\n4 2\n1 9\n1 10\n9 5\n2 2\n6 7\n8 6\n8 9\n4 2\n7 8\n3 3\n4 2\n6 10\n9 4... | 1,600 | 0 |
2 | 9 | 1368_C. Even Picture | Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction.
To draw a picture, Leo Jr. colors some of the cells on a sheet gray. He considers the resulting picture beautiful if the follo... | {
"input": [
"4\n"
],
"output": [
"16\n0 0\n0 1\n1 0\n1 1\n1 2\n2 1\n2 2\n2 3\n3 2\n3 3\n3 4\n4 3\n4 4\n4 5\n5 4\n5 5\n"
]
} | {
"input": [
"3\n",
"500\n",
"7\n",
"23\n",
"496\n",
"13\n",
"6\n",
"1\n",
"14\n",
"499\n",
"79\n",
"8\n",
"4\n",
"17\n",
"12\n",
"100\n",
"256\n",
"48\n",
"99\n",
"66\n",
"9\n",
"16\n",
"495\n",
"498\n",
"11\n",
"... | 1,500 | 1,500 |
2 | 8 | 140_B. New Year Cards | As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ... | {
"input": [
"4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4\n"
],
"output": [
"2 1 1 3 \n"
]
} | {
"input": [
"10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 1\n6 5 1 3 2 7 9 10 8 4\n1 10 9 3 7 8 4 2 6 5\n6 8 4 5 9 1 2 10 7 3\n9 6 8 5 10 3 1 7 2 4\n5 7 4 8 9 6 1 10 3 2\n",
"5\n1 4 2 3 5\n5 1 3 4 2\n3 2 4 1 5\n1 4 5 3 2\... | 1,800 | 1,000 |
2 | 12 | 1430_F. Realistic Gameplay | Recently you've discovered a new shooter. They say it has realistic game mechanics.
Your character has a gun with magazine size equal to k and should exterminate n waves of monsters. The i-th wave consists of a_i monsters and happens from the l_i-th moment of time up to the r_i-th moments of time. All a_i monsters spa... | {
"input": [
"2 3\n2 3 6\n3 4 3\n",
"2 5\n3 7 11\n10 12 15\n",
"5 42\n42 42 42\n42 43 42\n43 44 42\n44 45 42\n45 45 1\n",
"1 10\n100 111 1\n"
],
"output": [
"9\n",
"30\n",
"-1\n",
"1\n"
]
} | {
"input": [
"4 10\n1 3 1\n3 3 10\n5 6 15\n7 8 1\n",
"10 76\n1 2 82\n4 6 43\n9 10 13\n12 12 8\n14 15 16\n15 15 9\n16 16 92\n16 18 77\n18 19 95\n20 20 81\n",
"10 75\n1 2 44\n2 3 105\n4 5 30\n6 6 104\n8 10 26\n11 14 101\n14 16 93\n17 17 20\n18 20 43\n20 20 57\n",
"10 79\n2 2 70\n2 10 35\n10 10 76\n11 11... | 2,600 | 0 |
2 | 8 | 1454_B. Unique Bid Auction | There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem).
Let's simplify this game a bit. Formally, there are n participants, the i-th participant chose the number a_i. The winner of the game is... | {
"input": [
"6\n2\n1 1\n3\n2 1 3\n4\n2 2 2 3\n1\n1\n5\n2 3 2 4 2\n6\n1 1 5 5 4 4\n"
],
"output": [
"\n-1\n2\n4\n1\n2\n-1\n"
]
} | {
"input": [
"2\n2\n1 1\n1\n1\n",
"4\n19\n16 3 11 9 3 13 11 9 14 10 10 19 19 15 11 8 8 7 3\n10\n8 6 1 4 1 4 2 9 7 10\n7\n7 1 1 4 4 1 2\n1\n1\n",
"8\n12\n10 1 3 2 11 5 12 11 12 12 9 4\n11\n10 9 7 6 6 3 8 10 1 7 9\n12\n3 11 8 9 5 9 6 5 11 12 8 7\n15\n6 6 13 12 7 6 6 7 14 7 14 13 11 3 11\n40\n31 32 2 37 19 3... | 800 | 0 |
2 | 8 | 1505_B. DMCA | Many people are aware of DMCA β Digital Millennium Copyright Act. But another recently proposed DMCA β Digital Millennium Calculation Act β is much less known.
In this problem you need to find a root of a number according to this new DMCA law.
Input
The input contains a single integer a (1 β€ a β€ 1000000).
Output
O... | {
"input": [
"1\n",
"81\n"
],
"output": [
"\n1\n",
"\n9\n"
]
} | {
"input": [
"81\n"
],
"output": [
"1\n"
]
} | 1,600 | 0 |
2 | 8 | 15_B. Laser | Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n Γ m cells and a robotic arm. Each cell of the field is a 1 Γ 1 square. The robotic arm has two lasers po... | {
"input": [
"2\n4 4 1 1 3 3\n4 3 1 1 2 2\n"
],
"output": [
"8\n2\n"
]
} | {
"input": [
"1\n3 3 3 2 1 1\n",
"1\n4 5 2 2 4 2\n",
"1\n2 5 1 5 2 2\n",
"1\n5 6 3 4 4 2\n",
"1\n3 5 2 4 3 5\n",
"1\n2 6 2 6 2 3\n",
"1\n2 2 1 2 2 1\n",
"1\n7 3 6 2 5 2\n",
"20\n100 200 100 1 100 100\n100 200 1 100 100 100\n2 2 1 1 2 2\n100 100 50 50 1 1\n10 10 5 5 1 1\n100 100 99 ... | 1,800 | 0 |
2 | 11 | 201_E. Thoroughly Bureaucratic Organization | Once n people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person per day. As a consequence, each of n people made an appointment on one of the... | {
"input": [
"5\n4 1\n4 2\n7 3\n1 1\n42 7\n"
],
"output": [
"3\n2\n3\n0\n11\n"
]
} | {
"input": [
"12\n11 4\n9 2\n10000 100\n1000000000 2345\n123456 1234567\n123456 65536\n5 55\n5 3\n2323 10\n999111000 232323\n999888777 777888999\n999888777 777\n",
"17\n1 1000000000\n1000000000 1\n1000000000 1000000000\n1000000000 999999999\n999999999 1000000000\n1 2\n2 1\n2 3\n3 2\n2 1000000000\n1000000000 2... | 2,600 | 2,500 |
2 | 10 | 226_D. The table | Harry Potter has a difficult homework. Given a rectangular table, consisting of n Γ m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second β in the selected column. Harry's task is to make non-negative the ... | {
"input": [
"2 4\n-1 -1 -1 2\n1 1 1 1\n",
"4 1\n-1\n-1\n-1\n-1\n"
],
"output": [
"1 1 \n1 4 \n",
"4 1 2 3 4 \n0 \n"
]
} | {
"input": [
"20 10\n-6 8 -4 -1 3 10 2 5 4 7\n6 9 9 8 -8 3 7 9 7 3\n0 10 10 1 -3 -4 5 -1 10 10\n8 9 10 4 7 10 10 3 9 10\n3 0 8 -5 0 5 7 8 -5 4\n9 -6 7 10 -4 -2 7 0 -5 9\n-10 7 -4 5 10 8 3 7 1 8\n-3 -6 0 3 2 1 5 9 8 9\n4 -3 5 3 4 -6 9 5 3 4\n2 -4 0 -5 -2 0 5 5 9 7\n-4 -1 5 1 10 9 4 -8 6 6\n2 3 6 8 9 6 5 -7 -2 -5\n... | 2,100 | 2,000 |
2 | 8 | 250_B. Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons β 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | {
"input": [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
],
"output": [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\... | {
"input": [
"6\n0:00:000:0000::\n1:01:001:0001::\nf:0f:00f:000f::\n1:10:100:1000::\nf:f0:f00:f000::\nf:ff:fff:ffff::\n",
"4\n1:2:3:4:5:6:7:8\n0:0:0:0:0:0:0:0\nf:0f:00f:000f:ff:0ff:00ff:fff\n0fff:0ff0:0f0f:f0f:0f0:f0f0:f00f:ff0f\n",
"3\n::\n::\n::\n",
"10\n1::7\n0:0::1\n::1ed\n::30:44\n::eaf:ff:000b\n... | 1,500 | 1,000 |
2 | 9 | 275_C. k-Multiple Free Set | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = xΒ·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-mu... | {
"input": [
"6 2\n2 3 6 5 4 10\n"
],
"output": [
"3\n"
]
} | {
"input": [
"2 2\n500000000 1000000000\n",
"2 2\n4 2\n",
"2 1\n2 1\n",
"2 1000000000\n276447232 100000\n",
"3 1\n1 2 3\n",
"1 1\n1000000000\n",
"8 65538\n65535 65536 65537 65538 65539 131072 262144 196608\n",
"2 2\n16 8\n",
"2 2\n1 3\n",
"10 2\n1 2 3 4 5 6 7 8 9 10\n",
"10... | 1,500 | 500 |
2 | 7 | 346_A. Alice and Bob | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di... | {
"input": [
"2\n2 3\n",
"3\n5 6 7\n",
"2\n5 3\n"
],
"output": [
"Alice\n",
"Bob\n",
"Alice\n"
]
} | {
"input": [
"10\n78 66 6 60 18 84 36 96 72 48\n",
"2\n1 1000000000\n",
"2\n10 4\n",
"2\n2 6\n",
"2\n6 2\n",
"10\n72 96 24 66 6 18 12 30 60 48\n",
"3\n4 12 18\n",
"2\n1000000000 999999999\n",
"4\n2 3 15 30\n",
"2\n4 6\n",
"10\n100000000 200000000 300000000 400000000 5000000... | 1,600 | 500 |
2 | 8 | 440_B. Balancer | Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired configura... | {
"input": [
"6\n1 6 2 5 3 7\n"
],
"output": [
"12\n"
]
} | {
"input": [
"20\n1 1 1 1 1 1 1 1 1 1 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999\n",
"20\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 2 2 2 2 2 2 2 2 2 2\n",
"2\n0 1000000000\n",
... | 1,600 | 1,000 |
2 | 10 | 462_D. Appleman and Tree | Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of k (0 β€ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree... | {
"input": [
"3\n0 0\n0 1 1\n",
"10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1\n",
"6\n0 1 1 0 4\n1 1 0 0 1 0\n"
],
"output": [
"2\n",
"27\n",
"1\n"
]
} | {
"input": [
"5\n0 1 1 3\n0 0 0 1 1\n",
"2\n0\n1 0\n",
"100\n0 0 2 2 0 3 5 0 6 2 0 4 0 2 3 7 8 3 15 19 13 8 18 19 3 14 23 9 6 3 6 17 26 24 20 6 4 27 8 5 14 5 35 31 27 3 41 25 20 14 25 31 49 40 0 1 10 5 50 13 29 58 1 6 8 1 40 52 30 15 50 8 66 52 29 71 25 68 36 7 80 60 6 2 11 43 62 27 84 86 71 38 14 50 88 4... | 2,000 | 1,000 |
2 | 9 | 486_C. Palindrome Transformation | Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down.
There is a cursor pointing at some symbol of the string. Suppose that c... | {
"input": [
"8 3\naeabcaez\n"
],
"output": [
"6\n"
]
} | {
"input": [
"5 5\npjfjb\n",
"10 5\nabcdeedcba\n",
"1 1\nd\n",
"2 2\nat\n",
"4 4\nrkoa\n",
"10 4\nabcddddcef\n",
"46 29\nxxzkzsxlyhotmfjpptrilatgtqpyshraiycmyzzlrcllvu\n",
"198 3\ntuxqalctjyegbvouezfiqoeoazizhmjhpcmvyvjkyrgxkeupwcmvzcosdrrfgtdmxwfttxjxsbaspjwftgpnvsfyfqsrmyjmypdwonbzws... | 1,700 | 1,500 |
2 | 8 | 50_B. Choosing Symbol Pairs | There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that
1. 1 β€ i, j β€ N
2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.
Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is ... | {
"input": [
"aaaaaaaaaa\n",
"great10\n"
],
"output": [
"100\n",
"7\n"
]
} | {
"input": [
"zazaeeeeeeeq34443333444tttttt\n",
"abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321\n",
"233444\n",
"00000000000000000000000\n",
"999000888775646453342311\n",
"aabb\n",
"129a\n",
"abacaba\n",
"w\n"
],
"ou... | 1,500 | 1,000 |
2 | 10 | 534_D. Handshakes | On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in... | {
"input": [
"9\n0 2 3 4 1 1 0 2 2\n",
"5\n2 1 3 0 1\n",
"4\n0 2 1 1\n"
],
"output": [
"Possible\n7 6 9 3 4 8 1 5 2\n",
"Possible\n4 5 1 3 2\n",
"Impossible"
]
} | {
"input": [
"54\n4 17 18 15 6 0 12 19 20 21 19 14 23 20 7 19 0 2 13 18 2 1 0 1 0 5 11 10 1 16 8 21 20 1 16 1 1 0 15 2 22 2 2 2 18 0 3 9 1 20 19 14 0 2\n",
"6\n0 1 2 1 2 0\n",
"7\n3 0 0 4 2 2 1\n",
"123\n114 105 49 11 115 106 92 74 101 86 39 116 5 48 87 19 40 25 22 42 111 75 84 68 57 119 46 41 23 58 9... | 1,900 | 2,000 |
2 | 8 | 585_B. Phillip and Trains | The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmo... | {
"input": [
"2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\n",
"2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n"
],
"output": [
"YES\nNO\n",
"YES\nNO\n"
]
} | {
"input": [
"1\n100 26\ns................PPPP.CCCCC..UUUUUU.........YYYQQQQQQQ...GGGGG............MMM.....JJJJ..............\n.OOOOOO....EEE....................................................SSSSSS........LLLLLL......NNNIIII.\n......FFFFFF...VVVV..ZZZBBB...KKKKK..WWWWWWWXXX..RRRRRRR......AAAAADDDDDDD.HHH.......... | 1,700 | 750 |
2 | 8 | 607_B. Zuma | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is ... | {
"input": [
"3\n1 2 3\n",
"3\n1 2 1\n",
"7\n1 4 4 2 3 2 1\n"
],
"output": [
"3\n",
"1\n",
"2\n"
]
} | {
"input": [
"50\n30 17 31 15 10 3 39 36 5 29 16 11 31 2 38 1 32 40 7 15 39 34 24 11 4 23 9 35 39 32 4 5 14 37 10 34 11 33 30 14 4 34 23 10 34 34 26 34 26 16\n",
"2\n1 2\n",
"50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 2 18 3 1 9 19 4 19 10 17 12 16 20 10 11 15 10 3 19 8 6 2 8 9 15 13 7 8 8 5 8 15 18 9 ... | 1,900 | 1,250 |
2 | 7 | 629_A. 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 started t... | {
"input": [
"4\nCC..\nC..C\n.CC.\n.CC.\n",
"3\n.CC\nC..\nC.C\n"
],
"output": [
"9\n",
"4\n"
]
} | {
"input": [
"7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.\n",
"3\nC..\nC..\nC..\n",
"20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C... | 800 | 500 |
2 | 8 | 653_B. Bear and Compressing | Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.
You are given a set of q possible operations. Limak can perform them in any order, ... | {
"input": [
"6 2\nbb a\nba a\n",
"2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c\n",
"3 5\nab a\ncc c\nca a\nee c\nff d\n"
],
"output": [
"0\n",
"1\n",
"4\n"
]
} | {
"input": [
"6 36\nac a\naf a\ndb a\nab a\ncb a\nef a\nad a\nbd a\nfe a\nde a\nbe a\nbb a\naa a\nae a\ndf a\nbc a\nbf a\nce a\nba a\nfd a\ndc a\neb a\ncd a\nca a\nee a\ncc a\ncf a\ndd a\nda a\nec a\nfc a\nfa a\nea a\ned a\nff a\nfb a\n",
"2 5\nfe b\nbb a\naf b\nfd b\nbf c\n",
"6 15\nab b\nbd b\nae b\ncd ... | 1,300 | 1,000 |
2 | 7 | 701_A. Cards | There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be ... | {
"input": [
"4\n10 10 10 10\n",
"6\n1 5 7 4 4 3\n"
],
"output": [
"1 2\n3 4\n",
"1 3\n6 2\n4 5\n"
]
} | {
"input": [
"36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41\n",
"12\n22 83 2 67 55 12 40 93 83 73 12 28\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 1... | 800 | 500 |
2 | 8 | 723_B. Text Document Analysis | Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of:
* uppercase and lowercase English... | {
"input": [
"37\n_Hello_Vasya(and_Petya)__bye_(and_OK)\n",
"27\n(LoooonG)__shOrt__(LoooonG)\n",
"5\n(___)\n",
"37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__\n"
],
"output": [
"5 4\n",
"5 2\n",
"0 0\n",
"2 6\n"
]
} | {
"input": [
"6\na(al)a\n",
"20\nm(_)jzay()s()d()T(M)\n",
"255\nAf________T_C____t_p(_Ug___Fr_Wg_)j_____x__j_a___Q_____(__p_____M)__J__jj____E__J(_W____eT)__wtm____T____Z_c_____C____P_____k___(___ql_X_B_________l____L_______F___m___p_S__DI______w)_f__r_lGG_m__SJ(__q__G_____s___s___o_______bg____f____vZ___... | 1,100 | 1,000 |
2 | 7 | 745_A. Hongcow Learns the Cyclic Shift | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | {
"input": [
"abcd\n",
"bbb\n",
"yzyz\n"
],
"output": [
"4\n",
"1\n",
"2\n"
]
} | {
"input": [
"zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw\n",
"aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba\n",
"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\n",
"aaababaab\n",
"yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs\n",
"zclkjadoprqronzclkjadoprqronzclkjadoprqron\n",... | 900 | 500 |
2 | 9 | 768_C. Jon Snow and his Favourite Number | Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now t... | {
"input": [
"2 100000 569\n605 986\n",
"5 1 2\n9 7 11 15 5\n"
],
"output": [
"986 605\n",
"13 7\n"
]
} | {
"input": [
"11 1003 9\n12 5 10 8 0 6 8 10 12 14 4\n",
"5 4 6\n0 2 2 2 3\n",
"31 3 4\n7 18 16 14 16 7 13 10 2 3 8 11 20 4 7 1 7 13 17 12 9 8 10 3 11 3 4 8 16 10 3\n",
"10 3 5\n1 2 3 4 5 6 7 8 9 10\n",
"1 1 100\n923\n",
"10 22196 912\n188 111 569 531 824 735 857 433 182 39\n",
"5 8 6\n0 2 ... | 1,800 | 1,250 |
2 | 8 | 792_B. Counting-out Rhyme | n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one ... | {
"input": [
"3 2\n2 5\n",
"7 5\n10 4 11 4 1\n"
],
"output": [
"3 2\n",
"4 2 5 6 1\n"
]
} | {
"input": [
"90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274\n",
"10 7\n5 10 4 3 8 10 6\n",
"2 1\n1\n",
"12 10\n76 58 82 54 97 46 17 40 36 15\n",
"3 2\n301633543 643389490\n",
"6 5\n532623340 628883728 583960589 690950241 488468353\n",
"12 6\n76 61 94 15 66 26\n",
"68 1\n5\n",... | 1,300 | 0 |
2 | 10 | 812_D. Sagheer and Kindergarten | Sagheer is working at a kindergarten. There are n children and m different toys. These children use well-defined protocols for playing with the toys:
* Each child has a lovely set of toys that he loves to play with. He requests the toys one after another at distinct moments of time. A child starts playing if and onl... | {
"input": [
"5 4 7 2\n1 1\n2 2\n2 1\n5 1\n3 3\n4 4\n4 1\n5 3\n5 4\n",
"3 3 5 1\n1 1\n2 2\n3 3\n1 2\n2 3\n3 1\n"
],
"output": [
"0\n2\n",
"3\n"
]
} | {
"input": [
"13 18 27 13\n1 1\n1 2\n1 3\n1 4\n1 17\n2 5\n2 1\n3 6\n3 2\n5 14\n5 3\n4 4\n6 9\n6 3\n7 8\n7 3\n8 7\n8 9\n10 11\n10 18\n11 10\n11 15\n11 11\n9 12\n9 11\n12 10\n13 15\n6 8\n6 14\n6 1\n6 17\n6 18\n11 12\n11 18\n11 9\n11 17\n1 18\n1 12\n1 7\n1 14\n",
"2 1 1 1\n1 1\n2 1\n",
"1 2 1 1\n1 1\n1 2\n",... | 2,700 | 2,000 |
2 | 10 | 838_D. Airplane Arrangements | There is an airplane which has n rows from front to back. There will be m people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the pla... | {
"input": [
"3 3\n"
],
"output": [
"128\n"
]
} | {
"input": [
"175236 173750\n",
"646205 361804\n",
"284114 73851\n",
"261457 212062\n",
"3745 1612\n",
"519169 430233\n",
"976535 433238\n",
"896437 604720\n",
"784160 282537\n",
"942045 878421\n",
"43657 852\n",
"921643 744360\n",
"361284 5729\n",
"234247 67712... | 2,700 | 0 |
2 | 7 | 859_A. Declined Finalists | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | {
"input": [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"3\n14 15 92\n",
"5\n16 23 8 15 4\n"
],
"output": [
"3",
"67",
"0"
]
} | {
"input": [
"1\n1\n",
"25\n3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2\n",
"25\n13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7\n",
"4\n999 581 787 236\n",
"2\n26 27\n",
"3\n1 25 90\n",
"3\n40 30 35\n",
"25\n1000000 999999 999998 999997 999996 ... | 800 | 500 |
2 | 20 | 883_M. Quadcopter Competition | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
* start the race from some point of a field,
* go around the flag,
* close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (x1, y1) and the coordinates of the poin... | {
"input": [
"0 1\n0 0\n",
"1 5\n5 2\n"
],
"output": [
"8",
"18"
]
} | {
"input": [
"24 41\n24 42\n",
"41 -82\n-33 -15\n",
"1 1\n0 1\n",
"-90 -54\n9 -9\n",
"-100 100\n-100 -100\n",
"100 -100\n-100 100\n",
"-68 26\n-2 6\n",
"25 76\n24 76\n",
"-20 34\n-9 55\n",
"-53 63\n-53 62\n",
"-30 94\n31 -58\n",
"18 -67\n-51 21\n",
"76 76\n75 75\n",... | 1,100 | 0 |
2 | 8 | 908_B. New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | {
"input": [
"5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n",
"5 3\n...\n.S.\n###\n.E.\n...\n3\n"
],
"output": [
"1\n",
"14\n",
"0\n"
]
} | {
"input": [
"2 2\n#E\nS.\n01\n",
"3 3\nE..\n.S.\n...\n001123110023221103\n",
"3 5\n....S\n....#\n....E\n0112\n",
"10 10\n####S.####\n#####.####\n#####.####\n#####.####\n#####..###\n######.###\n######.###\n######.E##\n##########\n##########\n0111101110\n",
"2 2\nSE\n..\n22\n",
"2 2\nSE\n##\n0\... | 1,200 | 750 |
2 | 7 | 92_A. Chips | There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.
The presenter has m chips. The presenter... | {
"input": [
"4 11\n",
"17 107\n",
"3 8\n"
],
"output": [
"0",
"2",
"1"
]
} | {
"input": [
"36 6218\n",
"46 7262\n",
"44 7888\n",
"17 4248\n",
"4 7455\n",
"29 7772\n",
"32 6864\n",
"50 50\n",
"25 9712\n",
"50 1\n",
"45 9465\n",
"50 9555\n",
"1 9058\n",
"50 10000\n",
"9 7601\n",
"36 880\n",
"24 7440\n",
"29 1241\n",
"1 ... | 800 | 500 |
2 | 7 | 958_A2. Death Stars (medium) | The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so... | {
"input": [
"10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n"
],
"output": [
"4 6"
]
} | {
"input": [
"1 1\ng\ng\n"
],
"output": [
"1 1"
]
} | 2,000 | 0 |
2 | 7 | 983_A. Finite or not? | You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction ... | {
"input": [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
],
"output": [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
]
} | {
"input": [
"1\n1 864691128455135232 2\n",
"1\n1 4294967297 4294967296\n",
"10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2\n",
"11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14... | 1,700 | 500 |
2 | 7 | 1040_A. Palindrome Dance | A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them β a black one, and for the rest the suit will be bought in the future.
On ... | {
"input": [
"3 12 1\n0 1 0\n",
"5 100 1\n0 1 2 1 2\n",
"3 10 12\n1 2 0\n"
],
"output": [
"0\n",
"101\n",
"-1\n"
]
} | {
"input": [
"5 55 62\n0 1 1 0 1\n",
"2 100 1\n2 2\n",
"15 24 41\n0 2 1 1 0 0 1 0 0 0 0 0 0 1 0\n",
"2 2 2\n2 2\n",
"20 53 67\n1 2 1 2 0 0 0 2 2 2 1 0 0 2 0 0 0 1 1 2\n",
"3 2 2\n2 2 2\n",
"8 4 13\n2 2 1 2 1 2 2 2\n",
"1 100 1\n2\n",
"5 2 3\n2 2 2 2 2\n",
"7 16 16\n1 1 2 2 0 2 ... | 1,000 | 500 |
2 | 7 | 1063_A. Oh Those Palindromes | A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.
A string is called a substring of another string, if it can be obtained from that string by dropping some (possi... | {
"input": [
"5\noolol\n",
"16\ngagadbcgghhchbdf\n"
],
"output": [
"llooo",
"aabbccddfgggghhh"
]
} | {
"input": [
"2\naz\n",
"10\nmsunonames\n",
"4\nmems\n",
"7\nlolikek\n",
"15\nabacabadabacaba\n",
"9\nabcabcabc\n",
"21\narozaupalanalapuazora\n",
"1\nz\n",
"6\nmsucmc\n",
"2\naa\n"
],
"output": [
"az",
"aemmnnossu",
"emms",
"eikkllo",
"aaaaaaaabbbbccd",... | 1,300 | 500 |
2 | 9 | 1104_C. Grid game | You are given a 4x4 grid. You play a game β there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time in... | {
"input": [
"010\n"
],
"output": [
"1 1\n3 1\n1 2\n"
]
} | {
"input": [
"1\n",
"010\n",
"011110\n",
"0\n",
"01\n"
],
"output": [
"1 1\n",
"1 1\n3 1\n1 2\n",
"1 1\n4 3\n4 1\n4 3\n4 1\n3 1\n",
"1 1\n",
"1 1\n1 2\n"
]
} | 1,400 | 500 |
2 | 7 | 1132_A. Regular Bracket Sequence | A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; ")... | {
"input": [
"1\n2\n3\n4\n",
"3\n1\n4\n3\n",
"0\n0\n0\n0\n"
],
"output": [
"0\n",
"1\n",
"1\n"
]
} | {
"input": [
"0\n10\n2\n0\n",
"0\n0\n3\n0\n",
"0\n1\n5\n0\n",
"1\n2\n5\n1\n",
"2\n6\n6\n2\n",
"0\n1\n10\n0\n",
"0\n2\n3\n0\n",
"2\n1\n5\n2\n",
"2\n0\n1\n2\n",
"1\n0\n500\n1\n",
"7\n1\n0\n7\n",
"1\n2\n11\n1\n",
"2\n0\n0\n1\n",
"1\n0\n0\n1\n",
"4\n0\n20\n4\n",... | 1,100 | 0 |
2 | 10 | 1152_D. Neko and Aki's Prank | Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys...
It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of w... | {
"input": [
"2\n",
"1\n",
"3\n"
],
"output": [
"3",
"1",
"9"
]
} | {
"input": [
"12\n",
"19\n",
"17\n",
"11\n",
"25\n",
"24\n",
"22\n",
"996\n",
"8\n",
"1000\n",
"9\n",
"6\n",
"10\n",
"20\n",
"998\n",
"13\n",
"26\n",
"21\n",
"30\n",
"18\n",
"16\n",
"28\n",
"5\n",
"4\n",
"7\n",
"50... | 2,100 | 2,000 |
2 | 8 | 1174_B. Ehab Is an Odd Person | You're given an array a of length n. You can perform the following operation on it as many times as you want:
* Pick two integers i and j (1 β€ i,j β€ n) such that a_i+a_j is odd, then swap a_i and a_j.
What is lexicographically the smallest array you can obtain?
An array x is [lexicographically smaller](https://... | {
"input": [
"3\n4 1 7\n",
"2\n1 1\n"
],
"output": [
"1 4 7\n",
"1 1\n"
]
} | {
"input": [
"3\n3 1 5\n",
"3\n3 5 1\n",
"36\n398353608 662365068 456456182 594572278 958026500 524977116 903404403 382220192 142092809 137516115 522872496 527845939 116437661 423289717 907151540 961740613 981968938 143206666 773454188 691188206 95402302 602570397 986508327 617421132 46091276 866348540 48... | 1,200 | 1,000 |
2 | 10 | 1230_D. Marcin and Training Camp | Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integers from 1 to n. Each of them can be described with two integers a_i... | {
"input": [
"3\n1 2 3\n1 2 3\n",
"1\n0\n1\n",
"4\n3 2 3 6\n2 8 5 10\n"
],
"output": [
"0\n",
"0\n",
"15\n"
]
} | {
"input": [
"10\n206158430208 206162624513 68719476737 137506062337 206162624513 4194305 68719476737 206225539072 137443147777 68719476736\n202243898 470292528 170057449 290025540 127995253 514454151 607963029 768676450 611202521 68834463\n",
"2\n0 1\n1 1\n",
"10\n3 3 5 5 6 6 1 2 4 7\n1 1 1 1 1 1 1 1 1 1... | 1,700 | 500 |
2 | 7 | 1295_A. Display The Number | You have a large electronic screen which can display up to 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 segments which can be turned on and off to compose different digits. The following picture describes how you can dis... | {
"input": [
"2\n3\n4\n"
],
"output": [
"7\n11\n"
]
} | {
"input": [
"100\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\... | 900 | 0 |
2 | 7 | 1316_A. Grade Allocation | n students are taking an exam. The highest possible score at this exam is m. Let a_{i} be the score of the i-th student. You have access to the school database which stores the results of all students.
You can change each student's score as long as the following conditions are satisfied:
* All scores are integers ... | {
"input": [
"2\n4 10\n1 2 3 4\n4 5\n1 2 3 4\n"
],
"output": [
"10\n5\n"
]
} | {
"input": [
"27\n1 1\n0\n1 2\n0\n1 5\n0\n1 10\n0\n1 50\n0\n1 100\n0\n1 500\n0\n1 1000\n0\n1 5000\n0\n1 10000\n0\n1 50000\n0\n1 100000\n0\n1 5\n4\n1 5\n5\n1 10\n9\n1 10\n10\n1 100000\n9999\n1 100000\n100000\n1 4999\n386\n1 100000\n1\n4 5\n1 0 0 0\n4 5\n0 1 0 0\n4 5\n0 0 0 0\n4 5\n5 5 5 5\n4 5\n4 4 5 5\n4 5\n5 4 4... | 800 | 500 |
2 | 9 | 1337_C. Linova and Kingdom | Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
<image>
There are n cities and n-1 two-way roads connecting pairs of cities in the ki... | {
"input": [
"8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n",
"7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n",
"4 1\n1 2\n1 3\n2 4\n"
],
"output": [
"9\n",
"7\n",
"2\n"
]
} | {
"input": [
"3 2\n1 2\n1 3\n",
"3 1\n1 2\n2 3\n",
"20 7\n9 7\n3 7\n15 9\n1 3\n11 9\n18 7\n17 18\n20 1\n4 11\n2 11\n12 18\n8 18\n13 2\n19 2\n10 9\n6 13\n5 8\n14 1\n16 13\n",
"2 1\n1 2\n"
],
"output": [
"2\n",
"2\n",
"38\n",
"1\n"
]
} | 1,600 | 500 |
2 | 7 | 135_A. Replacement | Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that als... | {
"input": [
"5\n1 2 3 4 5\n",
"5\n2 3 4 5 6\n",
"3\n2 2 2\n"
],
"output": [
"1 1 2 3 4\n",
"1 2 3 4 5\n",
"1 2 2\n"
]
} | {
"input": [
"1\n5\n",
"4\n1000000000 234765 3485636 385634876\n",
"25\n1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 1 2\n",
"10\n5 6 1 2 3 1 3 45 7 1000000000\n",
"3\n1 2 1\n",
"2\n5 5\n",
"4\n1 1 2 3\n",
"1\n2\n",
"3\n1 1 1\n",
"1\n4\n",
"2\n1 1\n",
"2\n1 2\n",
"... | 1,300 | 500 |
2 | 8 | 137_B. Permutation | "Hey, it's homework time" β thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of n integers is calle... | {
"input": [
"2\n2 2\n",
"3\n3 1 2\n",
"5\n5 3 3 3 1\n"
],
"output": [
"1\n",
"0\n",
"2\n"
]
} | {
"input": [
"100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 41... | 1,000 | 1,000 |
2 | 17 | 1423_K. Lonely Numbers | In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.
More precisely, two different numbers a and b are friends if gcd(a,b), (a)/(gcd(a,b)), (b)/(gcd(a,b)) can form sides of a triangle.
Three numbers a, b and c can form sides of a triangle if a + b > c, b... | {
"input": [
"3\n1 5 10\n"
],
"output": [
"1\n3\n3\n"
]
} | {
"input": [
"100\n791 303 765 671 210 999 106 489 243 635 807 104 558 628 545 926 35 3 75 196 35 460 523 621 748 45 501 143 240 318 78 908 207 369 436 6 285 200 236 864 731 786 915 672 293 563 141 708 698 646 48 128 603 716 681 329 389 489 683 616 875 510 20 493 141 176 803 106 92 928 20 762 203 336 586 258 56 7... | 1,600 | 0 |
2 | 20 | 1468_M. Similar Sets | You are given n sets of integers. The i-th set contains k_i integers.
Two sets are called similar if they share at least two common elements, i. e. there exist two integers x and y such that x β y, and they both belong to each of the two sets.
Your task is to find two similar sets among the given ones, or report that... | {
"input": [
"3\n4\n2 1 10\n3 1 3 5\n5 5 4 3 2 1\n3 10 20 30\n3\n4 1 2 3 4\n4 2 3 4 5\n4 3 4 5 6\n2\n3 1 3 5\n3 4 3 2\n"
],
"output": [
"\n2 3 \n1 2 \n-1\n"
]
} | {
"input": [
"7\n2\n2 1 2\n2 2 1\n3\n4 4 5 6 7\n3 1 2 3\n3 2 3 4\n3\n3 1 2 3\n3 2 3 4\n3 3 4 5\n2\n3 10 20 30\n2 40 50\n4\n2 500 100\n2 500 100\n2 500 100\n2 499 100\n2\n3 1 3 2\n2 1 4\n2\n2 1 5\n2 3 2\n",
"10\n2\n5 190511 174892 60413 161099 192095\n2 190511 174892\n2\n2 25224 33915\n2 33915 25224\n2\n2 1028... | 2,300 | 0 |
2 | 7 | 1494_A. ABC String | You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting charac... | {
"input": [
"4\nAABBAC\nCACA\nBBBBAC\nABCA\n"
],
"output": [
"\nYES\nYES\nNO\nNO\n"
]
} | {
"input": [
"12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n",
"17\nAABBCCAAAA\nAABBCCABBA\nAABBBBAAAA\nBBBBCCAAAA\nAABBBCAAAA\nABBBCCAAAA\nAABBCCABAA\nAABBBCAAAA\nBABBCCAAAA\nAABBCCABBA\nABBBCAAAAA\nBABBCAAAAA\nABBBCCAACA\nAABACCAACA\nAABBACAAAB\nAABACCAAAA\nAAABACAAAB\n",
"3\nAABB\nCAAB\nABCA\n",
... | 900 | 0 |
2 | 10 | 1516_D. Cut | This time Baby Ehab will only cut and not stick. He starts with a piece of paper with an array a of length n written on it, and then he does the following:
* he picks a range (l, r) and cuts the subsegment a_l, a_{l + 1}, β¦, a_r out, removing the rest of the array.
* he then cuts this range into multiple subrange... | {
"input": [
"6 3\n2 3 10 7 5 14\n1 6\n2 4\n3 5\n"
],
"output": [
"\n3\n1\n2\n"
]
} | {
"input": [
"1 1\n100000\n1 1\n"
],
"output": [
"1\n"
]
} | 2,100 | 2,000 |
2 | 12 | 171_F. ucyhf | qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.
Input
jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 β€ d β€ 11184) β jxu edu-rqiut ydtun ev jxu ucyhf je vydt.
Output
ekjfkj q iydwbu dkcruh.
Examples
Input
1
Output
13 | {
"input": [
"1\n"
],
"output": [
"13\n"
]
} | {
"input": [
"5273\n",
"2279\n",
"4020\n",
"10526\n",
"7779\n",
"4859\n",
"5\n",
"1438\n",
"6\n",
"8\n",
"6848\n",
"10\n",
"8216\n",
"4168\n",
"11183\n",
"6327\n",
"10107\n",
"3\n",
"10476\n",
"10962\n",
"6826\n",
"11184\n",
"... | 1,600 | 0 |
2 | 10 | 215_D. Hot Days | The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 β€ i β€ n) region has a stable temperature of ti degrees in summer.
This summer a group of m schoolchildren wants to get from the official capital to the cul... | {
"input": [
"3 100\n10 30 1000 1\n5 10 1000 3\n10 40 1000 100000\n",
"2 10\n30 35 1 100\n20 35 10 10\n"
],
"output": [
"200065\n",
"120\n"
]
} | {
"input": [
"1 1000000\n4 4 6 2\n",
"10 1\n8 6 3 4\n9 10 7 7\n1 3 9 5\n10 9 4 2\n1 10 2 10\n1 1 8 5\n5 5 9 2\n5 8 4 3\n4 4 9 7\n5 7 5 10\n",
"20 102\n73 79 75 27\n13 15 62 47\n74 75 85 86\n49 81 23 69\n43 17 45 27\n35 14 90 35\n51 74 35 33\n54 66 46 24\n33 76 49 3\n34 53 25 76\n69 72 76 31\n41 31 8 48\n4... | 1,900 | 2,000 |
2 | 8 | 264_B. Good Sequences | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.
Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions:
* The sequence is strictly increasing, i.e. xi < xi + 1 f... | {
"input": [
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
],
"output": [
"4",
"4"
]
} | {
"input": [
"2\n1009 2018\n",
"10\n2 4 8 67 128 324 789 1296 39877 98383\n",
"1\n1\n",
"10\n2 3 45 67 89 101 234 567 890 1234\n",
"2\n5101 10202\n",
"3\n150 358 382\n",
"44\n1 5 37 97 107 147 185 187 195 241 249 295 311 323 341 345 363 391 425 431 473 525 539 541 555 577 595 611 647 695 7... | 1,500 | 1,000 |
2 | 8 | 288_B. Polo the Penguin and Houses | Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 β€ pi β€ n).
Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a hou... | {
"input": [
"7 4\n",
"5 2\n"
],
"output": [
"1728\n",
"54\n"
]
} | {
"input": [
"8 5\n",
"975 8\n",
"50 2\n",
"999 7\n",
"2 2\n",
"876 8\n",
"1000 2\n",
"12 8\n",
"227 6\n",
"3 3\n",
"2 1\n",
"1 1\n",
"137 5\n",
"1000 1\n",
"1000 8\n",
"1000 3\n",
"473 4\n",
"8 1\n",
"8 8\n",
"9 8\n",
"1000 5\n",
... | 1,500 | 1,000 |
2 | 8 | 313_B. Ilya and Queries | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 β€ li < ri β€ n)... | {
"input": [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
],
"output": [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
]
} | {
"input": [
"#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3\n",
"#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4\n",
".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3\n",
"#.\n1\n1 2\n",
"#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3\n",
"...\n2\n1 2\n1 2\n",
"##\n1\n1 2\n",
"..\n1\n1 2\n",
"#.##.... | 1,100 | 1,000 |
2 | 9 | 402_C. Searching for Graph | Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:
* the graph contains exactly 2n + p edges;
* the graph doesn't contain self-loops and multiple edges;
* for any integer k (1 β€ k β€ n), any subgraph consisting of k vertices contains at most 2k + p edges.
A sub... | {
"input": [
"1\n6 0\n"
],
"output": [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
]
} | {
"input": [
"5\n24 1\n23 1\n22 1\n21 1\n20 1\n",
"5\n24 0\n24 0\n24 0\n24 0\n24 0\n",
"5\n24 0\n23 0\n24 1\n23 1\n22 0\n",
"5\n6 0\n5 0\n7 0\n8 0\n9 0\n",
"5\n24 0\n23 0\n22 0\n21 0\n24 1\n",
"5\n19 1\n18 1\n17 1\n16 1\n15 1\n",
"5\n10 1\n11 1\n12 1\n13 1\n14 1\n",
"1\n24 100\n",
... | 1,500 | 1,500 |
2 | 10 | 42_D. Strange town | Volodya has recently visited a very odd town. There are N tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) assigned to it and all prices are distinct. But the most striking thing about this town is that each city sightseeing to... | {
"input": [
"3\n"
],
"output": [
"0 3 4\n3 0 5\n4 5 0\n"
]
} | {
"input": [
"17\n",
"11\n",
"18\n",
"4\n",
"13\n",
"15\n",
"14\n",
"19\n",
"14\n",
"10\n",
"5\n",
"12\n",
"13\n",
"12\n",
"7\n",
"18\n",
"15\n",
"17\n",
"10\n",
"19\n",
"16\n",
"20\n",
"20\n",
"6\n",
"9\n",
"8\n",... | 2,300 | 2,000 |
2 | 8 | 452_B. 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 p1, p2, p3, p4 consists of the line segment... | {
"input": [
"0 10\n",
"1 1\n"
],
"output": [
"0 1\n0 10\n0 0\n0 9\n",
"0 0\n1 1\n0 1\n1 0\n"
]
} | {
"input": [
"9 3\n",
"3 2\n",
"2 4\n",
"5 3\n",
"555 1\n",
"1000 3\n",
"6 5\n",
"987 567\n",
"1000 500\n",
"3 1\n",
"10 100\n",
"2 1\n",
"955 956\n",
"1 5\n",
"4 4\n",
"3 4\n",
"6 4\n",
"20 10\n",
"1000 20\n",
"1 1\n",
"3 5\n",
"... | 1,800 | 1,000 |
2 | 7 | 522_A. Reposts | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | {
"input": [
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n",
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted w... | {
"input": [
"10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS\n",... | 1,200 | 500 |
2 | 9 | 549_C. The Game Of Parity | There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities left.
The ... | {
"input": [
"3 1\n1 2 1\n",
"6 3\n5 20 12 7 14 101\n",
"3 1\n2 2 1\n"
],
"output": [
"Stannis\n",
"Stannis\n",
"Daenerys\n"
]
} | {
"input": [
"2 2\n67427 727097\n",
"3 3\n767153 643472 154791\n",
"3 3\n814664 27142 437959\n",
"1 1\n107540\n",
"6 3\n346 118 330 1403 5244 480\n",
"7 4\n11 3532 99 3512 12 8 22\n",
"3 3\n349371 489962 45420\n",
"4 1\n1 1 2 2\n",
"1 1\n912959\n",
"2 2\n125572 610583\n",
"... | 2,200 | 2,000 |
2 | 9 | 597_C. Subsequences | For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8Β·1018.
Input
First line contain two integer values n and k (1 β€ n β€ 105, 0 β€ k β€ 10) β the length of sequence and the number of elements in increasing ... | {
"input": [
"5 2\n1\n2\n3\n5\n4\n"
],
"output": [
"7\n"
]
} | {
"input": [
"10 2\n6\n10\n9\n7\n1\n2\n8\n5\n4\n3\n",
"100 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n6... | 1,900 | 1,500 |
2 | 11 | 618_E. Robot Arm | Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0) is colored blue for all segments. Thus, the blue endpoint of the i-th segm... | {
"input": [
"5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1\n"
],
"output": [
"8.000000000 0.000000000\n5.000000000 -3.000000000\n4.256855175 -2.669130606\n4.256855175 -3.669130606\n"
]
} | {
"input": [
"1 1\n2 1 302\n",
"50 50\n1 41 261\n2 47 324\n1 41 256\n1 31 339\n2 23 116\n2 44 184\n2 32 115\n1 40 301\n2 40 303\n1 29 309\n2 49 348\n2 47 356\n1 41 263\n2 42 276\n1 45 135\n1 33 226\n2 31 166\n1 50 171\n2 47 166\n2 50 284\n2 25 324\n2 48 307\n2 41 176\n1 50 353\n1 45 323\n2 50 343\n1 47 200\n2... | 2,500 | 2,500 |
2 | 8 | 690_B1. Recover Polygon (easy) | The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.
Heidi knows that the lair can be represented as a rectangle on a lattice, with si... | {
"input": [
"6\n000000\n000000\n012100\n024200\n012100\n000000\n"
],
"output": [
"Yes"
]
} | {
"input": [
"8\n00000000\n00001210\n00002420\n00002020\n00001210\n00000000\n00000000\n00000000\n",
"7\n0000000\n0000000\n0000000\n1122210\n0244420\n0122210\n0000000\n",
"7\n0000000\n0012210\n0024420\n0012210\n0000000\n0000000\n0000000\n",
"6\n000000\n000000\n002200\n002200\n000000\n000000\n",
"6\... | 1,700 | 0 |
2 | 10 | 779_D. String Game | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain ... | {
"input": [
"bbbabb\nbb\n1 6 3 4 2 5\n",
"ababcba\nabb\n5 3 4 1 7 6 2\n"
],
"output": [
"4",
"3"
]
} | {
"input": [
"aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 ... | 1,700 | 500 |
2 | 7 | 827_A. String Reconstruction | Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.
Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more... | {
"input": [
"3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n",
"3\nab 1 1\naba 1 3\nab 2 3 5\n",
"1\na 1 3\n"
],
"output": [
"abacaba\n",
"ababab\n",
"aaa\n"
]
} | {
"input": [
"18\nabacab 2 329 401\nabadabacabae 1 293\nbacab 1 2\nabacabadabacabaga 1 433\nc 1 76\nbaca 1 26\ndab 1 72\nabagabaca 1 445\nabaea 1 397\ndabac 1 280\nab 2 201 309\nca 1 396\nabacabadab 1 497\nac 1 451\ncaba 1 444\nad 1 167\nbadab 1 358\naba 1 421\n",
"4\na 2 1 10\na 3 1 2 9\na 2 3 8\na 2 4 7\n",... | 1,700 | 500 |
2 | 7 | 849_A. Odds and Ends | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subse... | {
"input": [
"4\n3 9 9 3\n",
"3\n4 3 1\n",
"5\n1 0 1 5 1\n",
"3\n1 3 5\n"
],
"output": [
"No\n",
"No\n",
"Yes\n",
"Yes\n"
]
} | {
"input": [
"4\n1 0 1 1\n",
"2\n10 10\n",
"5\n1 3 2 4 5\n",
"2\n1 1\n",
"4\n1 1 2 1\n",
"6\n1 2 3 5 6 7\n",
"100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46... | 1,000 | 500 |
2 | 9 | 897_C. Nephren gives a riddle | What are you doing at the end of the world? Are you busy? Will you save us?
<image>
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, f0... β.
f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about i... | {
"input": [
"10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n",
"3\n1 1\n1 2\n1 111111111111\n",
"5\n0 69\n1 194\n1 139\n0 47\n1 66\n"
],
"output": [
"Areyoubusy",
"Wh.",
"abdef"
]
} | {
"input": [
"10\n96759 970434747560290241\n95684 985325796232084031\n99418 855577012478917561\n98767 992053283401739711\n99232 381986776210191990\n97804 22743067342252513\n95150 523980900658652001\n98478 290982116558877566\n98012 642382931526919655\n96374 448615375338644407\n",
"10\n72939 670999605706502447\... | 1,700 | 500 |
2 | 10 | 918_D. MADMAX | As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower... | {
"input": [
"5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n",
"4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n"
],
"output": [
"BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB\n",
"BAAA\nABAA\nBBBA\nBBBB\n"
]
} | {
"input": [
"100 1\n92 93 p\n",
"3 2\n1 3 l\n2 1 v\n",
"2 1\n1 2 q\n",
"8 20\n2 4 a\n1 8 a\n1 2 v\n8 4 h\n1 7 w\n5 4 h\n2 8 h\n7 4 i\n4 3 w\n6 8 l\n1 4 v\n1 3 g\n5 3 b\n1 6 a\n7 3 w\n6 4 f\n6 7 g\n7 8 n\n5 8 g\n2 6 j\n"
],
"output": [
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,700 | 750 |
2 | 10 | 940_D. Alena And The Heater | "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array b of length n is obtained from the array a of length n and two integers l and r (l β€ r) using the following procedure:
b1 = b2 = b3... | {
"input": [
"5\n1 2 3 4 5\n00001\n",
"10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n"
],
"output": [
"6 1000000000\n",
"-5 5\n"
]
} | {
"input": [
"99\n-94 -97 -95 -99 94 98 91 95 90 -98 -92 -93 -91 -100 84 81 80 89 89 70 76 79 69 74 -80 -90 -83 -81 -80 64 60 60 60 68 56 50 55 50 57 39 47 47 48 49 37 31 34 38 34 -76 -71 -70 -76 -70 23 21 24 29 22 -62 -65 -63 -60 -61 -56 -51 -54 -58 -59 -40 -43 -50 -43 -42 -39 -33 -39 -39 -33 17 16 19 10 20 -32 ... | 1,600 | 1,500 |
2 | 7 | 96_A. Football | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | {
"input": [
"1000000001\n",
"001001\n"
],
"output": [
"YES\n",
"NO\n"
]
} | {
"input": [
"111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010\n",
"1111100111\n",
"10101011111111111111111111111100\n",
"11110110011000100111100111101101011111110100010101011011111101110110110111\n",
"10000000\n",
"100001000010000010001000010... | 900 | 500 |
2 | 7 | 994_A. Fingerprints | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | {
"input": [
"4 4\n3 4 1 0\n0 1 7 9\n",
"7 3\n3 5 7 1 6 2 8\n1 2 7\n"
],
"output": [
"1 0\n",
"7 1 2\n"
]
} | {
"input": [
"10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6\n",
"8 2\n7 2 9 6 1 0 3 4\n6 3\n",
"10 2\n4 9 6 8 3 0 1 5 7 2\n0 1\n",
"8 2\n7 4 8 9 2 5 6 1\n6 4\n",
"10 1\n9 0 8 1 7 4 6 5 2 3\n0\n",
"3 6\n1 2 3\n4 5 6 1 2 3\n",
"3 7\n6 3 4\n4 9 0 1 7 8 6\n",
"1 10\n9\n0 1 2 3 4 5 6 7 8 9\n",
... | 800 | 500 |
2 | 8 | 1007_B. Pave the Parallelepiped | You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.
Find the number of different groups of three integers (a, b, c) such that 1β€ aβ€ bβ€ c and parallelepiped AΓ BΓ C can be paved with parallelepipeds aΓ bΓ c. Note, that all small parallelepipeds have to be rotated in the same d... | {
"input": [
"4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n"
],
"output": [
"1\n4\n4\n165\n"
]
} | {
"input": [
"10\n9 6 8\n5 5 2\n8 9 2\n2 7 9\n6 4 10\n1 1 8\n2 8 1\n10 6 3\n7 5 2\n9 5 4\n",
"10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n",
"1\n100000 100000 100000\n"
],
"output": [
"41\n6\n21\n12\n39\n4\n7\n26\n8\n18\n",
"1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
"8... | 2,400 | 1,000 |
2 | 8 | 1030_B. Vasya and Cornfield | Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n).
<image> An example of a cornfield with n = 7 and d = 2.
Vasya also knows that there are m grasshoppers near the fie... | {
"input": [
"7 2\n4\n2 4\n4 1\n6 3\n4 5\n",
"8 7\n4\n4 4\n2 8\n8 1\n6 1\n"
],
"output": [
"YES\nNO\nNO\nYES\n",
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [
"2 1\n50\n1 0\n0 1\n0 1\n1 2\n0 1\n0 1\n0 1\n0 1\n1 0\n1 2\n2 1\n1 0\n1 2\n1 2\n2 1\n0 1\n0 1\n1 2\n0 1\n0 1\n1 2\n0 1\n2 1\n1 2\n0 1\n2 1\n2 1\n1 2\n1 0\n0 1\n2 1\n1 0\n2 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n0 1\n2 1\n1 0\n2 1\n1 0\n1 0\n1 0\n0 1\n1 0\n",
"2 1\n50\n0 1\n1 2\n1 2\n2 1\n0 1\... | 1,100 | 500 |
2 | 7 | 1075_A. The King's Race | On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column.
The white ki... | {
"input": [
"4\n2 3\n",
"5\n3 5\n",
"2\n2 2\n"
],
"output": [
"White",
"Black",
"Black"
]
} | {
"input": [
"878602530892252875\n583753601575252768 851813862933314387\n",
"982837494536444311\n471939396014493192 262488194864680421\n",
"778753534913338583\n547836868672081726 265708022656451521\n",
"100000000000000000\n50000000000000001 50000000000000001\n",
"1000000000000000000\n353555355335 ... | 800 | 500 |
2 | 8 | 1096_B. Substring Removal | You are given a string s of length n consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to calculate the number of ways to remove exactly one substring from thi... | {
"input": [
"7\naacdeee\n",
"2\naz\n",
"4\nabaa\n"
],
"output": [
"6\n",
"3\n",
"6\n"
]
} | {
"input": [
"23\nszsqqwareupmhkxlqwdtgbn\n",
"7\nabcdaaa\n",
"5\nabcde\n",
"24\nbxstlxalhkcaguyydabgpyts\n",
"420\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | 1,300 | 0 |
2 | 9 | 1117_C. Magic Ship | You a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x_2, y_2).
You know the weather forecast β the string s of length n, consisting only of letters U, D, L and R. The letter corresponds t... | {
"input": [
"0 3\n0 0\n3\nUDD\n",
"0 0\n4 6\n3\nUUU\n",
"0 0\n0 1\n1\nL\n"
],
"output": [
"3\n",
"5\n",
"-1\n"
]
} | {
"input": [
"0 1\n2 1\n1\nR\n",
"0 0\n0 1\n2\nLU\n",
"0 0\n1000000000 1000000000\n2\nDR\n"
],
"output": [
"1\n",
"2\n",
"2000000000\n"
]
} | 1,900 | 0 |
2 | 11 | 1143_E. Lynyrd Skynyrd | Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n.
Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the ... | {
"input": [
"2 4 3\n2 1\n1 1 2 2\n1 2\n2 3\n3 4\n",
"3 6 3\n2 1 3\n1 2 3 1 2 3\n1 5\n2 6\n3 5\n"
],
"output": [
"010\n",
"110\n"
]
} | {
"input": [
"1 1 1\n1\n1\n1 1\n"
],
"output": [
"1\n"
]
} | 2,000 | 1,000 |
2 | 10 | 1163_D. Mysterious Code | During a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string c consisting of lowercase English characters and asterisks ("*"), where each of the asterisks denotes an unreadable character. Excited wi... | {
"input": [
"***\ncc\nz\n",
"*****\nkatie\nshiro\n",
"*a*\nbba\nb\n",
"caat\ncaat\na\n"
],
"output": [
"2\n",
"1\n",
"0\n",
"-1\n"
]
} | {
"input": [
"kljab**abs\nab\nba\n",
"***********************************************************************************************************************************************************************\ngcoldfocaplzqobdv\nhuptdsgpmrqrcjchuyxnxncoivvtgkpuhdlvdkfzkrswwp\n",
"uhnuhbzynlgtze\ndvxryfxdxmgp... | 2,100 | 2,250 |
2 | 11 | 1243_E. Sum Balance | Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are k boxes numbered from 1 to k. The i-th box contains n_i integer numbers. The integers can be negative. All of the integers are distinct.
Ujan is lazy, so he will do the following reordering of the numbe... | {
"input": [
"2\n2 -10 10\n2 0 -20\n",
"2\n2 3 -2\n2 -1 5\n",
"4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n"
],
"output": [
"Yes\n-10 2\n-20 1\n",
"No\n",
"Yes\n7 2\n2 3\n5 1\n10 4\n"
]
} | {
"input": [
"1\n1 0\n",
"2\n2 1 2\n10 0 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 589934621\n",
"3\n1 20\n2 30 40\n3 50 60 80\n",
"5\n10 -251 650 475 -114 364 -75754 -982 -532 -151 -484\n10 -623 -132 -317561 -438 20 -275 -323 -530089 -311 -587\n10 450900 -519 90... | 2,400 | 1,500 |
2 | 10 | 1263_D. Secret Passwords | One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of n passwords β strings, consists of small Latin letters.
Hacker went home and started preparing to... | {
"input": [
"1\ncodeforces\n",
"3\nab\nbc\nabc\n",
"4\na\nb\nab\nd\n"
],
"output": [
"1\n",
"1\n",
"2\n"
]
} | {
"input": [
"3\nac\nbde\nbc\n",
"5\nyyyyyyyyyyyyyyyyyyyyyyyyyyy\nxxxxxx\nzz\nzzzzzzzzzzz\nzzzzzzzzzz\n",
"3\nab\ncd\nda\n",
"2\nab\nad\n",
"5\nnznnnznnnnznnnnznzznnnznnznnnnnnnzzn\nljjjjlljlllllj\nduuuudududduuuuududdddduduudduddududdduuuudduddd\nssssssssss\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n",
... | 1,500 | 1,750 |
2 | 8 | 1304_B. Longest Palindrome | Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.
Gildong lo... | {
"input": [
"4 2\noo\nox\nxo\nxx\n",
"3 5\nhello\ncodef\norces\n",
"3 3\ntab\none\nbat\n",
"9 4\nabab\nbaba\nabcd\nbcde\ncdef\ndefg\nwxyz\nzyxw\nijji\n"
],
"output": [
"6\noxooxo\n",
"0\n",
"6\ntabbat\n",
"20\nababwxyzijjizyxwbaba\n"
]
} | {
"input": [
"17 14\ntzmqqlttfuopox\ndlgvbiydlxmths\ndxnyijdxjuvvej\nnfxqnqtffqnojm\nrkfvitydhceoum\ndycxhtklifleqe\nldjflcylhmjxub\nurgabqqfljxnps\nshtmxldyibvgld\nosjuvluhehilmn\nwtdlavffvaldtw\nabjixlbuwfyafp\naojogsmvdzyorp\nsicdoeogurcwor\nocxbhsfmhmumef\ndqxmxaadjwhqus\nclwotgqvdwcbar\n",
"19 6\nbbsssb\... | 1,100 | 1,000 |
2 | 9 | 1348_C. Phoenix and Distribution | Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and re... | {
"input": [
"6\n4 2\nbaba\n5 2\nbaacb\n5 3\nbaacb\n5 3\naaaaa\n6 4\naaxxzz\n7 1\nphoenix\n"
],
"output": [
"ab\nabbc\nb\naa\nx\nehinopx\n"
]
} | {
"input": [
"9\n8 2\nchefspam\n11 7\nmonkeyeight\n8 2\nvcubingx\n6 1\namazed\n4 4\nhebs\n8 1\narolakiv\n9 7\nhidavidhu\n33 33\ngosubtovcubingxheneedssubscribers\n7 4\nhiimbad\n"
],
"output": [
"c\nm\nc\naademz\ns\naaiklorv\ni\nx\nh\n"
]
} | 1,600 | 1,500 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.