question
stringlengths
29
1.88k
test_input
listlengths
0
10
test_output
listlengths
0
10
test_time_limit
int64
1
1
test_method
stringclasses
1 value
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; take any two (not necessarily adjacent) c...
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n", "1\nR\n", "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB\n", "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRR...
[ "G\n", "BR\n", "B\n", "R\n", "BGR\n", "BG\n", "BGR\n", "BGR\n", "BGR\n", "B\n" ]
1
stdio
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a, b, c. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c....
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n", "1 0 2 0 3 0\n", "3 4 0 0 4 3\n", "-1000000000 1 0 0 1000000000 1\n", "49152 0 0 0 0 81920\n", "1 -1 4 4 2 -3\n", "-2 -2 1 4 -2 0\n", "5 0 4 -2 0 1\n", "-4 -3 2 -1 -3 4\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
1
stdio
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t...
[ "2 1\n", "10 7\n", "1000000000000 1\n", "3 1\n", "4 1\n", "3 2\n", "4 2\n", "1000 700\n", "959986566087 524054155168\n", "4 3\n" ]
[ "2\n", "6\n", "1000000000000\n", "3\n", "4\n", "3\n", "2\n", "6\n", "90\n", "4\n" ]
1
stdio
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found out that calculating this...
[ "3 5\n", "6 3\n", "1000000009 1000000008\n", "1000000007 1000000006\n", "2000000018 2000000017\n", "1000000000000 1\n", "1000000000000 1000000000000\n", "1 1000000000000\n", "100000000000 100000000000\n", "1 100000000000\n" ]
[ "3\n", "1\n", "1000000008\n", "1000000006\n", "1000000009\n", "1\n", "1\n", "1000000000000\n", "1\n", "100000000000\n" ]
1
stdio
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int...
[ "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n", "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n", "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n", "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n", "1000000 1000000\n1000000 999999\n1000000 999998\n999999 1000000\n999999 999998\n999998 1000000\n999998 999999\n999998 999998\n", ...
[ "respectable\n", "ugly\n", "ugly\n", "ugly\n", "respectable\n", "ugly\n", "ugly\n", "ugly\n", "ugly\n", "ugly\n" ]
1
stdio
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside. Big Banban is hesitating over the amount ...
[ "2\n", "6\n", "3\n", "4\n", "5\n", "1000000\n", "1\n", "7\n", "8\n", "9\n" ]
[ "8\n", "888\n", "86\n", "88\n", "886\n", "-1\n", "6\n", "8886\n", "8888\n", "88886\n" ]
1
stdio
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles: [Image] It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar pi...
[ "3 1\n", "6 1\n", "100 100\n", "5 6\n", "7 5\n", "8 3\n", "10 5\n", "4 2\n", "5 6\n", "7 3\n" ]
[ "6.4641016\n", "1.0000000\n", "3.2429391\n", "8.5555200\n", "3.8321081\n", "1.8597432\n", "2.2360680\n", "4.8284271\n", "8.5555200\n", "2.2992648\n" ]
1
stdio
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
[ "3\n2014 2016 2015\n", "1\n2050\n", "1\n2010\n", "1\n2011\n", "3\n2010 2011 2012\n", "3\n2049 2047 2048\n", "5\n2043 2042 2041 2044 2040\n", "5\n2012 2013 2014 2015 2016\n", "1\n2045\n", "1\n2046\n" ]
[ "2015\n", "2050\n", "2010\n", "2011\n", "2011\n", "2048\n", "2042\n", "2014\n", "2045\n", "2046\n" ]
1
stdio
Let $f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$ for $x \ge 4$. You have given integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$. Find $f_{n} \bmod (10^{9}+7)$. -----Input----- The only line contains five integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$ ($4 \le n \le 10^{18}$, $1 \le f_{1}$, $f_{2}$,...
[ "5 1 2 5 3\n", "17 97 41 37 11\n", "4 1 1 1 1\n", "1000000000000000000 1000000000 1000000000 1000000000 1000000000\n", "27230 83472 9488 55320 2081\n", "44618 45855 80403 31174 63416\n", "67025 50601 5471 94645 97571\n", "89432 31159 22014 66629 31727\n", "11842 44412 71268 71316 98586\n", "38100 ...
[ "72900\n", "317451037\n", "1\n", "607659049\n", "791627460\n", "468227325\n", "252720835\n", "100809399\n", "543142695\n", "231750081\n" ]
1
stdio
Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists. - Let s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\ldots{s'}_i (the first i chara...
[ "contest\nson\n", "contest\nprogramming\n", "contest\nsentence\n", "d\nd\n", "j\nw\n", "zv\nz\n", "jh\nh\n", "l\nll\n", "s\nsv\n", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...
[ "10\n", "-1\n", "33\n", "1\n", "-1\n", "1\n", "2\n", "2\n", "-1\n", "100000\n" ]
1
stdio
[Image] -----Input----- The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. -----Output----- Output the required string. -----...
[ "AprilFool\n14\n", "abcdefabc\n3\n", "fgWjSAlPOvcAbCdDEFjz\n7\n", "sm\n26\n", "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12\n", "sPWSFWWqZBPon\n3\n", "fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0\n", "RtsUOGkraqKyjTktAXloOEmQj\n18\n", "DuFhhnq\n4\n", "RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22\n" ]
[ "AprILFooL\n", "ABCdefABC\n", "FGwjsAlpovCABCDDEFjz\n", "SM\n", "GnLFoqpEztpIBKvvLHADvGpGFqBtnLGmt\n", "spwsfwwqzBpon\n", "fqhhxcdeaintxhwcfcasgwfvqnymebymlsnkumifgnjb\n", "RtsuOGKRAQKyJtKtAxLOOEMQJ\n", "Dufhhnq\n", "RVPUyTxSBDIJDOLAURLFATCFwVTNDzKyAEwGRz\n" ]
1
stdio
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ...
[ "1 2\n", "4 8\n", "4 10\n", "1 5\n", "3 4\n", "3 10\n", "74 99\n", "19 30\n", "33 77\n", "3342 3339\n" ]
[ "101\n", "110110110101\n", "11011011011011\n", "-1\n", "1010101\n", "-1\n", "11011011011011011011011011011011011011011011011011011011011011011011011010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\n", "1101101101101101101101101101101010101010101010...
1
stdio
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strin...
[ "131\n", "320\n", "2010200\n", "1\n", "1000000000\n", "999999999\n", "999999998\n", "102000\n", "210000000\n", "213443120\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n" ]
1
stdio
Imp is in a magic forest, where xorangles grow (wut?) [Image] A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest. For...
[ "6\n", "10\n", "3\n", "4\n", "5\n", "2500\n", "952\n", "88\n", "1216\n", "2140\n" ]
[ "1\n", "2\n", "0\n", "0\n", "0\n", "700393\n", "118547\n", "536\n", "160822\n", "614785\n" ]
1
stdio
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s_1, s_2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a an...
[ "3 2\nabc\nxyc\n", "1 0\nc\nb\n", "1 1\na\na\n", "2 1\naa\naa\n", "3 1\nbcb\nbca\n", "4 3\nccbb\ncaab\n", "4 2\nacbc\nacba\n", "4 1\nbcbc\nacab\n", "4 2\nacbb\nbabc\n", "5 2\nabaac\nbbbaa\n" ]
[ "bac", "-1\n", "b", "ab", "bcc", "cbca", "acab", "-1\n", "aaba", "abbab" ]
1
stdio
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decim...
[ "27\n", "4545\n", "1\n", "9\n", "8772\n", "81\n", "71723447\n", "91730629\n", "420062703497\n", "332711047202\n" ]
[ "22\n", "4444\n", "1\n", "9\n", "1222\n", "11\n", "21223442\n", "91230320\n", "420032203402\n", "332211042202\n" ]
1
stdio
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed...
[ "1 10 2\n", "2 4 5\n", "18102 43332383920 28554\n", "19562 31702689720 17701\n", "11729 55221128400 313\n", "5482 100347128000 342\n", "3680 37745933600 10\n", "17098 191120104800 43\n", "10462 418807699200 2\n", "30061 641846400000 3\n" ]
[ "1 2 4 8 ", "-1", "28554 815330916 ", "313325401 ", "97969 30664297 9597924961 ", "116964 40001688 13680577296 ", "10000 100000 1000000 10000000 100000000 1000000000 10000000000 ", "79507 3418801 147008443 6321363049 ", "16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216...
1
stdio
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: - For each block, use one of the M colors, ...
[ "3 2 1\n", "100 100 0\n", "60522 114575 7559\n", "1 1 0\n", "1 1 0\n", "1 200000 0\n", "1 200000 0\n", "200000 1 0\n", "200000 1 199999\n", "200000 200000 0\n" ]
[ "6\n", "73074801\n", "479519525\n", "1\n", "1\n", "200000\n", "200000\n", "0\n", "1\n", "815343867\n" ]
1
stdio
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones. Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions: - For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq...
[ "2\n1 0\n", "3\n0 0 0\n", "5\n0 1 0 1 0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 1\n", "2999\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
[ "1 1\n", "0 0 0\n", "0 2 0 1 3\n", "0 0\n", "0 1\n", "1 0\n", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
1
stdio
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any giv...
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n", "4\n0 1\n1 2\n2 3\n3 4\n", "3\n1 2\n2 3\n2 4\n", "3\n0 100\n0 100\n0 100\n", "1\n0 1000000000\n", "2\n0 1\n0 1\n", "3\n2 3\n4 5\n1 6\n", "5\n1 3\n1 4\n4 10\n5 8\n9 11\n", "3\n1 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n" ]
1
stdio
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that...
[ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n", "2 1\n1 10\n", "3 12\n5 6 6\n", "4 10\n6 3 8 7\n", "5 16\n3 3 2 7 9\n", "6 38\n9 10 3 8 10 6\n", "7 12\n4 4 5 2 2 4 9\n", "8 15\n8 10 4 2 10 9 7 6\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n" ]
1
stdio
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ci...
[ "1\n", "2\n", "3\n", "4\n", "5\n", "7\n", "10\n", "14\n", "58000\n", "6\n" ]
[ "20", "680", "19340", "529040", "14332100", "459529590", "848178170", "356372551", "66667472", "387302840" ]
1
stdio
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some num...
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n", "6\nacbead\n", "7\ncdaadad\n", "25\npeoaicnbisdocqofsqdpgobpn\n", "25\ntcqpchnqskqjacruoaqilgebu\n", "13\naebaecedabbee\n", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "10\nbababbdaee\n" ]
[ "1\n", "2\n", "0\n", "1\n", "4\n", "12\n", "7\n", "8\n", "-1\n", "6\n" ]
1
stdio
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each ot...
[ "1 1\n", "7 6\n", "25 38\n", "8311 2468\n", "250708 857756\n", "957985574 24997558\n", "999963734 999994456\n", "1000000000 1000000000\n", "946 879\n", "10819 45238\n" ]
[ "Valera\n", "Vladik\n", "Vladik\n", "Valera\n", "Vladik\n", "Valera\n", "Vladik\n", "Vladik\n", "Valera\n", "Vladik\n" ]
1
stdio
Given an array $a$, consisting of $n$ integers, find: $$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$ where $LCM(x, y)$ is the smallest positive integer that is divisible by both $x$ and $y$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, 3) = 6$. -----Input----- The first line contains an integer $n$...
[ "3\n13 35 77\n", "6\n1 2 4 8 16 32\n", "2\n2 5\n", "4\n12 9 1 8\n", "4\n15 12 9 10\n", "56\n15 10 44 38 12 7 20 17 16 3 43 10 32 4 31 38 8 15 21 8 37 44 19 21 26 24 22 21 16 43 45 36 29 36 41 44 39 34 7 8 42 49 5 31 50 34 22 13 22 38 38 45 14 15 18 45\n", "74\n25 41 29 49 11 14 23 7 23 12 47 14 31 38 41...
[ "1001", "32", "10", "72", "90", "2450", "2450", "214671", "231752", "270" ]
1
stdio
VK news recommendation system daily selects interesting publications of one of $n$ disjoint categories for each user. Each publication belongs to exactly one category. For each category $i$ batch algorithm selects $a_i$ publications. The latest A/B test suggests that users are reading recommended publications more act...
[ "5\n3 7 9 7 8\n5 2 5 7 5\n", "5\n1 2 3 4 5\n1 1 1 1 1\n", "5\n12 4 19 18 19\n15467 14873 66248 58962 90842\n", "40\n19 20 8 13 13 17 1 14 15 20 14 17 2 9 9 10 19 16 6 12 9 7 20 5 12 6 4 4 12 5 4 11 8 1 2 8 11 19 18 4\n52258 5648 46847 9200 63940 79328 64407 54479 1788 60107 8234 64215 15419 84411 50307 78075 ...
[ "6\n", "0\n", "66248\n", "6113465\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n" ]
1
stdio
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap yea...
[ "1900:01:01\n2038:12:31\n", "1996:03:09\n1991:11:12\n", "1999:12:31\n2000:02:29\n", "1903:09:27\n1988:06:15\n", "1913:11:14\n1901:05:11\n", "1915:01:01\n2007:07:01\n", "1925:07:15\n2010:06:22\n", "1935:10:08\n1923:01:07\n", "1986:08:24\n1926:04:13\n", "1932:11:18\n2028:09:25\n" ]
[ "50768\n", "1579\n", "60\n", "30943\n", "4570\n", "33784\n", "31023\n", "4657\n", "22048\n", "35010\n" ]
1
stdio
-----Input----- The input contains a single integer a (1 ≤ a ≤ 40). -----Output----- Output a single string. -----Examples----- Input 2 Output Adams Input 8 Output Van Buren Input 29 Output Harding
[ "2\n", "8\n", "29\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "9\n" ]
[ "Adams\n", "Van Buren\n", "Harding\n", "Washington\n", "Jefferson\n", "Madison\n", "Monroe\n", "Adams\n", "Jackson\n", "Harrison\n" ]
1
stdio
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: To make a "red bouquet", it needs 3 red flowers. To make a "green bouquet", it needs 3 green flowers. To make a "blue bouquet", it needs 3 blue flowe...
[ "3 6 9\n", "4 4 4\n", "0 0 0\n", "0 3 6\n", "7 8 9\n", "8 8 9\n", "15 3 999\n", "32 62 92\n", "123456789 123456789 123456789\n", "3 5 5\n" ]
[ "6\n", "4\n", "0\n", "3\n", "7\n", "8\n", "339\n", "62\n", "123456789\n", "4\n" ]
1
stdio
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n", "5\nliiil\nilili\niilii\nilili\nliiil\n", "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt\n", "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo...
[ "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
1
stdio
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his fr...
[ "2 2 2\n", "2 3 3\n", "1 1 1\n", "3 5 10\n", "2 3 1000000000000000000\n", "7 8 9\n", "8 10 11\n", "5 30 930\n", "3 3 3\n", "1 5 5\n" ]
[ "2\n", "1\n", "inf\n", "0\n", "0\n", "1\n", "0\n", "1\n", "2\n", "1\n" ]
1
stdio
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as us...
[ "1 1\n2 1\n", "2 2\n1 3\n2 2\n", "4 3\n3 10\n2 7\n2 8\n1 1\n", "5 5\n3 5\n2 6\n3 2\n1 1\n1 6\n", "6 6\n1 6\n1 4\n1 8\n3 2\n3 2\n2 8\n", "6 12\n1 7\n1 10\n2 8\n1 2\n2 9\n3 5\n", "6 18\n3 3\n1 10\n2 10\n3 6\n1 3\n2 3\n", "20 25\n2 13\n3 11\n1 32\n1 43\n3 85\n1 14\n2 57\n1 54\n1 38\n2 96\n2 89\n3 64\n1 7...
[ "0\n", "3\n", "10\n", "13\n", "26\n", "41\n", "35\n", "990\n", "1605\n", "22\n" ]
1
stdio
Snuke has an integer sequence A of length N. He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen. Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is happier when the absolute difference of the maxi...
[ "5\n3 2 4 1 2\n", "10\n10 71 84 33 6 47 23 25 52 64\n", "7\n1 2 3 1000000000 4 5 6\n", "4\n877914575 602436426 24979445 861648772\n", "179931\n433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 91028...
[ "2\n", "36\n", "999999994\n", "852935130\n", "226008843\n", "325361182\n", "549938604\n", "218707676\n", "728856976\n", "36328\n" ]
1
stdio
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium ...
[ "AC|T\nL\n", "|ABC\nXYZ\n", "W|T\nF\n", "ABC|\nD\n", "A|BC\nDEF\n", "|\nABC\n", "|\nZXCVBANMIO\n", "|C\nA\n", "|\nAB\n", "A|XYZ\nUIOPL\n" ]
[ "AC|TL\n", "XYZ|ABC\n", "Impossible\n", "Impossible\n", "ADF|BCE\n", "Impossible\n", "XVAMO|ZCBNI\n", "A|C\n", "B|A\n", "Impossible\n" ]
1
stdio
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis...
[ "0 0\n1 0\n0 1\n", "0 -1\n-1 0\n1 1\n", "-1 -1\n0 1\n1 1\n", "1000 1000\n-1000 -1000\n-1000 1000\n", "-1000 1000\n1000 -1000\n-1000 -1000\n", "-4 -5\n7 10\n3 -10\n", "-86 25\n-55 18\n58 24\n", "-301 -397\n192 317\n-98 729\n", "1000 1000\n999 1000\n-1000 -1000\n", "-1000 0\n999 0\n1000 1\n" ]
[ "3\n1 -1\n-1 1\n1 1\n", "3\n-2 -2\n2 0\n0 2\n", "3\n-2 -1\n0 -1\n2 3\n", "3\n1000 -1000\n1000 3000\n-3000 -1000\n", "3\n1000 1000\n-3000 1000\n1000 -3000\n", "3\n0 15\n-8 -25\n14 5\n", "3\n-199 19\n27 31\n89 17\n", "3\n-11 -809\n-591 15\n395 1443\n", "3\n2999 3000\n-999 -1000\n-1001 -1000\n", "3\n...
1
stdio
For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + .. + ( - 1)^{n}n Your task is to calculate f(n) for a given integer n. -----Input----- The single line contains the positive integer n (1 ≤ n ≤ 10^15). -----Output----- Print f(n) in a single line. -----Examples----- Input 4 Output 2 ...
[ "4\n", "5\n", "1000000000\n", "1000000001\n", "1000000000000000\n", "100\n", "101\n", "102\n", "103\n", "104\n" ]
[ "2\n", "-3\n", "500000000\n", "-500000001\n", "500000000000000\n", "50\n", "-51\n", "51\n", "-52\n", "52\n" ]
1
stdio
You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation. String $s = s_1 s_2 \dots s_n$ is le...
[ "3\naaa\n", "5\nabcda\n", "2\nzz\n", "2\nok\n", "4\nabcd\n", "5\naabbb\n", "2\nas\n", "7\nabcdeef\n", "2\nab\n", "3\nabc\n" ]
[ "aa\n", "abca\n", "z\n", "k\n", "abc\n", "aabb\n", "a\n", "abcdee\n", "a\n", "ab\n" ]
1
stdio
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number a, the second player wrote number b. How many ways ...
[ "2 5\n", "2 4\n", "5 3\n", "1 6\n", "5 1\n", "6 3\n", "2 3\n", "5 6\n", "4 4\n", "1 1\n" ]
[ "3 0 3\n", "2 1 3\n", "2 1 3\n", "3 0 3\n", "3 1 2\n", "2 0 4\n", "2 0 4\n", "5 0 1\n", "0 6 0\n", "0 6 0\n" ]
1
stdio
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. No...
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n", "10 9\n2 3 4 5 6 7 8 9 10\n", "5 2\n4 5\n", "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37\n", "10 10\n7 6 4 2 5 10 8 3 9 1\n", "12312 0\n", "9817239 1\n6323187\n", "1 1\n1\n", "5 4\n4 2 5 1\n" ]
[ "NO", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO" ]
1
stdio
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other point...
[ "1 5\n", "2 3\n", "4 6\n", "6 3\n", "1 1\n", "10 1\n", "20 10\n", "1000 10000\n", "139 9252\n", "859 8096\n" ]
[ "30\n", "25\n", "459\n", "171\n", "1\n", "55\n", "40326\n", "74133360011484445\n", "1137907933561080\n", "29032056230649780\n" ]
1
stdio
-----Input----- The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. -----Output----- Output "YES" or "NO". -----Examples----- Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI ...
[ "NEAT\n", "WORD\n", "CODER\n", "APRILFOOL\n", "AI\n", "JUROR\n", "YES\n", "Q\n", "PUG\n", "SOURPUSS\n" ]
[ "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n" ]
1
stdio
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. -----Input----- The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points. Each of the next n lines contains t...
[ "4\n0 1\n1 0\n1 1\n2 0\n", "1\n0 0\n", "1\n6 6\n", "5\n1 5\n4 2\n4 4\n8 1\n8 2\n", "10\n1 7\n2 14\n3 7\n3 13\n5 13\n13 10\n15 12\n17 1\n18 8\n19 0\n", "20\n0 17\n1 8\n1 9\n2 5\n2 11\n3 0\n5 10\n5 13\n6 7\n7 3\n12 13\n13 7\n14 16\n15 10\n15 18\n17 2\n17 12\n18 14\n19 18\n20 17\n", "2\n2 5\n10 7\n", "4\...
[ "1\n", "0\n", "0\n", "0\n", "2\n", "18\n", "0\n", "1\n", "10\n", "1\n" ]
1
stdio
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...
[ "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n" ]
[ "1\n", "3\n", "9\n", "27\n", "84\n", "270\n", "892\n", "3012\n", "10350\n", "36074\n" ]
1
stdio
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n", "12 12\n3 5 2\n", "770 1390\n170 442 311\n", "3555165 6693472\n1499112 556941 3075290\n", "0 0\n1000000000 1000000000 1000000000\n", "1 1\n0 1 0\n", "117708228 562858833\n118004008 360437130 154015822\n", "9999981...
[ "2\n", "1\n", "2147483648\n", "0\n", "12\n", "3089339\n", "7000000000\n", "0\n", "738362681\n", "1753877029\n" ]
1
stdio
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n", "10 20 0 40 0\n", "9 20 0 40 0\n", "5 -1 -6 -5 1\n", "99125 26876 -21414 14176 17443\n", "8066 7339 19155 -90534 -60666\n", "100000 -100000 -100000 100000 100000\n", "10 20 0 41 0\n" ]
[ "1\n", "3\n", "0\n", "1\n", "2\n", "1\n", "1\n", "8\n", "2\n", "2\n" ]
1
stdio
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d...
[ "3\n", "5\n", "10\n", "55\n", "56\n", "1000000000000\n", "847194127849\n", "294719472984\n", "999999911791\n", "999999911792\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n", "88209\n", "255708\n", "593358\n", "1414213\n", "1\n" ]
1
stdio
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them. -----Input----- The first line of the input contains a single integer N (3 ≤ N...
[ "3\n0 1 1\n1 0 4\n1 4 0\n", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n", "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 58\n...
[ "2\n", "5\n", "64\n", "2\n", "9\n", "1\n", "48\n", "87\n", "31\n", "63\n" ]
1
stdio
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b_1, b_2, ..., b_{k} (1 ≤ b_1 < b_2 < ... < b_{k} ≤ n) in such a way that the value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$ is maximized. Chosen sequence can be empty. Print the ma...
[ "4 4\n5 2 4 1\n", "3 20\n199 41 299\n", "5 10\n47 100 49 2 56\n", "5 1000\n38361 75847 14913 11499 8297\n", "10 10\n48 33 96 77 67 59 35 15 14 86\n", "10 1000\n16140 63909 7177 99953 35627 40994 29288 7324 44476 36738\n", "30 10\n99 44 42 36 43 82 99 99 10 79 97 84 5 78 37 45 87 87 11 11 79 66 47 100 8 ...
[ "3\n", "19\n", "9\n", "917\n", "9\n", "999\n", "9\n", "999\n", "9\n", "999\n" ]
1
stdio
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
[ "3\n", "11\n", "12\n", "13\n", "29\n", "30\n", "1000\n", "999\n", "100\n", "123\n" ]
[ "3\n", "0\n", "1\n", "1\n", "9\n", "2\n", "3\n", "9\n", "5\n", "6\n" ]
1
stdio
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by $i \operatorname{mod} j$. A Modular Equation, as Hamed's teacher described, is an equation of the form $a \operatorname{mod} x = b$ in which a...
[ "21 5\n", "9435152 272\n", "10 10\n", "0 1000000000\n", "11 2\n", "1 0\n", "0 0\n", "121 0\n", "772930485 686893955\n", "257424 24\n" ]
[ "2\n", "282\n", "infinity\n", "0\n", "2\n", "1\n", "infinity\n", "3\n", "0\n", "127\n" ]
1
stdio
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. -----Input----- The only line contains two integers n and k (1 ≤ n, k ≤ 10^9). -----Output----- Print the smallest integer x > n, so it is divisible by the number k. -----Exa...
[ "5 3\n", "25 13\n", "26 13\n", "1 1\n", "8 8\n", "14 15\n", "197 894\n", "6058 8581\n", "97259 41764\n", "453145 333625\n" ]
[ "6\n", "26\n", "39\n", "2\n", "16\n", "15\n", "894\n", "8581\n", "125292\n", "667250\n" ]
1
stdio
You are given $q$ queries in the following form: Given three integers $l_i$, $r_i$ and $d_i$, find minimum positive integer $x_i$ such that it is divisible by $d_i$ and it does not belong to the segment $[l_i, r_i]$. Can you answer all the queries? Recall that a number $x$ belongs to segment $[l, r]$ if $l \le x \le...
[ "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n", "1\n1 1 1\n", "1\n2 5 6\n", "1\n80 100 80\n", "10\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 10...
[ "6\n4\n1\n3\n10\n", "1000000001\n2000000000\n1\n1000000000\n10\n", "2\n", "6\n", "160\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n10000...
1
stdio
HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODU...
[ "3\n0\n1\n1\n", "1\n0\n", "1\n1\n", "2\n0\n1\n", "9\n0\n0\n0\n0\n0\n0\n0\n0\n1\n", "5\n1\n1\n1\n0\n1\n", "9\n1\n0\n0\n1\n0\n1\n1\n1\n1\n", "9\n1\n1\n1\n0\n0\n1\n1\n1\n0\n", "9\n1\n0\n0\n0\n0\n1\n1\n1\n1\n", "6\n0\n0\n1\n1\n1\n0\n" ]
[ "0.666667\n", "0\n", "1\n", "0.5\n", "0.111111\n", "1\n", "1\n", "1\n", "1\n", "0.6\n" ]
1
stdio
-----Input----- The input contains a single integer a (0 ≤ a ≤ 35). -----Output----- Output a single integer. -----Examples----- Input 3 Output 8 Input 10 Output 1024
[ "3\n", "10\n", "35\n", "0\n", "1\n", "2\n", "4\n", "5\n", "6\n", "7\n" ]
[ "8\n", "1024\n", "33940307968\n", "1\n", "2\n", "4\n", "16\n", "32\n", "64\n", "128\n" ]
1
stdio
Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation $a + 1 = b$ with positive integers $a$ and $b$, but Kolya forgot the numbers $a$ and $b$. He does, however, remember that the first (leftmost) digit of $a$ was $d_a$, and the first (leftmost) digit of $b$ was $d_b$...
[ "1 2\n", "4 4\n", "5 7\n", "6 2\n", "9 1\n", "1 1\n", "8 9\n", "9 8\n", "9 9\n", "2 4\n" ]
[ "1 2\n", "40 41\n", "-1\n", "-1\n", "9 10\n", "10 11\n", "8 9\n", "-1\n", "90 91\n", "-1\n" ]
1
stdio
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
[ "42\n23454\n", "169\n12118999\n", "1\n1\n", "7\n777\n", "18\n8118\n", "33\n33333333\n", "1780\n8170880870810081711018110878070777078711\n", "2\n5255\n", "5\n22252\n", "9\n666969\n" ]
[ "2\n", "1\n", "1\n", "3\n", "2\n", "4\n", "10\n", "4\n", "5\n", "6\n" ]
1
stdio
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to f...
[ "5 5\n", "3 6\n", "3 0\n", "1 0\n", "3 3\n", "32 32\n", "32 31\n", "1 1\n", "2 0\n", "3 1\n" ]
[ "YES\n1 2 131072 131078 0 \n", "YES\n131072 131078 0 \n", "YES\n393216 131072 262144\n", "YES\n0\n", "YES\n131072 131075 0 \n", "YES\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 131072 131105 0 \n", "YES\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...
1
stdio
[Image] -----Input----- The input contains two integers a_1, a_2 (0 ≤ a_{i} ≤ 32), separated by a single space. -----Output----- Output a single integer. -----Examples----- Input 1 1 Output 0 Input 3 7 Output 0 Input 13 10 Output 1
[ "1 1\n", "3 7\n", "13 10\n", "6 12\n", "14 14\n", "19 14\n", "21 18\n", "29 18\n", "0 24\n", "16 24\n" ]
[ "0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "1\n" ]
1
stdio
The cows have just learned what a primitive root is! Given a prime p, a primitive root $\operatorname{mod} p$ is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p} - 2 - 1 are divisible by p, but x^{p} - 1 - 1 is. Unfortunately, computing primitive roots can be time consuming, so the cows ...
[ "3\n", "5\n", "7\n", "11\n", "17\n", "19\n", "1583\n", "997\n", "2\n", "1987\n" ]
[ "1\n", "2\n", "2\n", "4\n", "8\n", "6\n", "672\n", "328\n", "1\n", "660\n" ]
1
stdio
Consider a linear function f(x) = Ax + B. Let's define g^{(0)}(x) = x and g^{(}n)(x) = f(g^{(}n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g^{(}n)(x) modulo 10^9 + 7. -----Input----- The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 10^9, 1 ≤ n ≤ 10^18) — the par...
[ "3 4 1 1\n", "3 4 2 1\n", "3 4 3 1\n", "1 1 1 1\n", "3 10 723 6\n", "14 81 51 82\n", "826504481 101791432 76 486624528\n", "475965351 844435993 96338 972382431\n", "528774798 650132512 6406119 36569714\n", "632656975 851906850 1 310973933\n" ]
[ "7\n", "25\n", "79\n", "2\n", "443623217\n", "908370438\n", "621999403\n", "83709654\n", "505858307\n", "230360736\n" ]
1
stdio
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue ente...
[ "1 0.50 1\n", "1 0.50 4\n", "4 0.20 2\n", "2000 0.61 2000\n", "100 1.00 200\n", "417 0.57 742\n", "100 0.01 53\n", "300 0.05 55\n", "1400 0.02 200\n", "2000 0.01 234\n" ]
[ "0.500000000000000\n", "0.937500000000000\n", "0.400000000000000\n", "1219.999999999999545\n", "100.000000000000000\n", "414.074442142061741\n", "0.530000000000000\n", "2.750000000000001\n", "3.999999999999999\n", "2.340000000000000\n" ]
1
stdio
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 ...
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n", "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "4\n82 46 8 44\n", "2\n35 50\n", "8\n24 39 49 38 44 64 4...
[ "1 3\n6 2\n4 5\n", "1 4\n2 3\n", "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\...
1
stdio
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the...
[ "3\n2 2\n1 2\n2 2\n", "2\n10 1\n6 5\n", "3\n6 10\n3 3\n8 2\n", "4\n4 8\n10 10\n4 2\n8 2\n", "5\n7 1\n5 1\n6 1\n1 6\n6 8\n", "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8\n", "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9\n", "1\n1 1\n", "1\n1000 1000\n", "42\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2...
[ "4\n", "11\n", "10\n", "14\n", "14\n", "16\n", "34\n", "1\n", "1000\n", "83\n" ]
1
stdio
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. -----Input----- A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). -----Output----- A single number, deno...
[ "1\n", "2\n", "13\n", "101\n", "1023\n", "9999\n", "10000\n", "2333\n", "9139\n", "9859\n" ]
[ "19\n", "28\n", "136\n", "1432\n", "100270\n", "10800010\n", "10800100\n", "310060\n", "10134010\n", "10422001\n" ]
1
stdio
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
[ "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n", "1\nIAO'111110\n", "2\nIAO'0\nIAO'00\n", "1\nIAO'111111\n", "1\nIAO'111111111\n", "1\nIAO'001\n", "1\nIAO'2000\n", "1\nIAO'11109999\n", "1\nIAO'11111\n" ]
[ "2015\n12015\n1991\n1989\n1990\n", "1989\n1999\n2999\n9999\n", "1111110\n", "1990\n2000\n", "1111111\n", "1111111111\n", "3001\n", "12000\n", "111109999\n", "111111\n" ]
1
stdio
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$ divers...
[ "10\ncodeforces\n", "5\naaaaa\n", "5\noomph\n", "1\ng\n", "2\nab\n", "3\naab\n", "3\nabb\n", "7\naaabaaa\n", "9\naabbccaab\n", "2\naz\n" ]
[ "YES\nco\n", "NO\n", "YES\nom\n", "NO\n", "YES\nab\n", "YES\nab\n", "YES\nab\n", "YES\nab\n", "YES\nab\n", "YES\naz\n" ]
1
stdio
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. Let's call a positive integer a undoubtedly lucky, if there are suc...
[ "10\n", "123\n", "1\n", "2\n", "1000\n", "1000000000\n", "999999999\n", "999999998\n", "999999997\n", "909090901\n" ]
[ "10\n", "113\n", "1\n", "2\n", "352\n", "40744\n", "40743\n", "40742\n", "40741\n", "38532\n" ]
1
stdio
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy...
[ "4\n", "11\n", "22\n", "3\n", "1024\n", "101\n", "30\n", "1000000\n", "1\n", "2\n" ]
[ "8\n", "14\n", "20\n", "8\n", "128\n", "42\n", "22\n", "4000\n", "4\n", "6\n" ]
1
stdio
You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}. The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds. Consider the integer o...
[ "5 3 4 10007\n", "4 8 1 1000000\n", "107 10000000000007 1000000000000007 998244353\n", "2500000000000 4 4 998244353\n", "99982444353 100 4 998244353\n", "333333333333333333 3 3 998244353\n", "1 999999999999999999 999999999999999999 998244353\n", "998244353 629149506971940504 319836804 14876851\n", "...
[ "5563\n", "891011\n", "39122908\n", "900161126\n", "658481246\n", "521296277\n", "716070897\n", "9086340\n", "822961451\n", "12975\n" ]
1
stdio
You are given a sequence $b_1, b_2, \ldots, b_n$. Find the lexicographically minimal permutation $a_1, a_2, \ldots, a_{2n}$ such that $b_i = \min(a_{2i-1}, a_{2i})$, or determine that it is impossible. -----Input----- Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1...
[ "5\n1\n1\n2\n4 1\n3\n4 1 3\n4\n2 3 4 5\n5\n1 5 7 2 8\n", "33\n3\n1 2 3\n3\n1 2 4\n3\n1 2 5\n3\n1 2 6\n3\n1 3 2\n3\n1 3 4\n3\n1 3 5\n3\n1 3 6\n3\n1 4 2\n3\n1 4 3\n3\n1 4 5\n3\n1 4 6\n3\n1 5 2\n3\n1 5 3\n3\n1 5 4\n3\n1 5 6\n3\n1 6 2\n3\n1 6 3\n3\n1 6 4\n3\n1 6 5\n3\n2 1 3\n3\n2 1 4\n3\n2 1 5\n3\n2 1 6\n3\n2 3 1\n3\...
[ "1 2 \n-1\n4 5 1 2 3 6 \n-1\n1 3 5 6 7 9 2 4 8 10 \n", "1 4 2 5 3 6 \n1 3 2 5 4 6 \n1 3 2 4 5 6 \n-1\n1 4 3 5 2 6 \n1 2 3 5 4 6 \n1 2 3 4 5 6 \n-1\n1 3 4 5 2 6 \n1 2 4 5 3 6 \n-1\n-1\n1 3 5 6 2 4 \n1 2 5 6 3 4 \n-1\n-1\n-1\n-1\n-1\n-1\n2 4 1 5 3 6 \n2 3 1 5 4 6 \n2 3 1 4 5 6 \n-1\n2 4 3 5 1 6 \n-1\n-1\n-1\n2 3 4 ...
1
stdio
Calculate the number of ways to place $n$ rooks on $n \times 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. ...
[ "3 2\n", "3 3\n", "4 0\n", "1337 42\n", "1 0\n", "2 0\n", "2 1\n", "3 0\n", "3 1\n", "4 1\n" ]
[ "6\n", "0\n", "24\n", "807905441\n", "1\n", "2\n", "4\n", "6\n", "36\n", "288\n" ]
1
stdio
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: a < b < c; a divides b, b divides c. Naturally, Xenia wants each elem...
[ "6\n1 1 1 2 2 2\n", "6\n2 2 1 1 4 6\n", "3\n1 2 3\n", "3\n7 5 7\n", "3\n1 3 4\n", "3\n1 1 1\n", "9\n1 3 6 6 3 1 3 1 6\n", "6\n1 2 4 1 3 5\n", "3\n1 3 7\n", "3\n1 1 1\n" ]
[ "-1\n", "1 2 4\n1 2 6\n", "-1\n", "-1\n", "-1\n", "-1\n", "1 3 6\n1 3 6\n1 3 6\n", "-1\n", "-1\n", "-1\n" ]
1
stdio
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant character. -----Input----- The first line contains string s consisting ...
[ "abacaba\n", "zzzzz\n", "abcde\n", "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\n", "daabcdabbabbacacbaacabacbcaabaacac\n", "abghim\n", "gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech\n", "a\n", ...
[ "2\n", "1\n", "3\n", "8\n", "4\n", "4\n", "17\n", "1\n", "4\n", "2\n" ]
1
stdio
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. -----Input----- The first line con...
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n", "1\nB\n", "2\nBG\n", "3\nBGB\n", "4\nRBBR\n", "5\nRGGBG\n", "10\nGGBRBRGGRB\n", "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB\n" ]
[ "1\n", "4\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "2\n", "18\n" ]
1
stdio
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 t_1, t_2, ..., t_{n...
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n", "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88\n", "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64...
[ "35\n", "15\n", "90\n", "90\n", "90\n", "90\n", "16\n", "90\n", "58\n", "30\n" ]
1
stdio
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. ...
[ "aaba\n2\n", "aaabbbb\n2\n", "abracadabra\n10\n", "zwvrx\n3\n", "ayi\n10\n", "eexlzphiay\n1\n", "zumtumtlitf\n2\n", "xbmrxbmrkzovhb\n3\n", "ijtvifbuajod\n5\n", "jhfwjyyzwrjiyrrgveiqkoltivghgkontrqragikttxxuwszjwqhwxindyrdqhucnbwgwrppgqmsasrzohezjlfmkzsqptwpratprcrxyxecnlsaiqrvimihmhjfgzwdtvmfhgbuo...
[ "6\n", "6\n", "20\n", "6\n", "12\n", "2\n", "6\n", "8\n", "10\n", "400\n" ]
1
stdio
There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears...
[ "4\n2 1 2 1\n", "5\n0 -1 -1 -1 -1\n", "2\n10 8\n", "5\n-14 -2 0 -19 -12\n", "6\n-15 2 -19 20 0 9\n", "3\n17 4 -1\n", "4\n20 3 -15 7\n", "1\n11\n", "1\n-10\n", "7\n-8 9 0 -10 -20 -8 3\n" ]
[ "4", "4", "2", "47", "65", "22", "45", "11", "-10", "58" ]
1
stdio
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a gr...
[ "ababa\n", "zzcxx\n", "yeee\n", "a\n", "bbab\n", "abcd\n", "abc\n", "abcdaaaa\n", "aaaaaaaaaaaaaaa\n", "adb\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n" ]
1
stdio
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? ...
[ "4 2\n1 3 3 7\n", "5 5\n10 9 5 8 7\n", "3 2\n1 4 7\n", "6 4\n17 13 16 12 15 11\n", "6 5\n17 13 16 12 15 11\n", "2 1\n2 2\n", "14 16\n27 37 50 11 16 42 45 43 31 42 40 29 42 32\n", "10 1\n3 1 3 4 5 3 2 4 1 4\n", "12 15\n12 17 28 14 32 40 33 18 28 10 40 50\n", "5 1\n5 4 3 2 4\n" ]
[ "2\n", "1\n", "1\n", "3\n", "2\n", "0\n", "5\n", "5\n", "6\n", "2\n" ]
1
stdio
You have a fraction $\frac{a}{b}$. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. -----Input----- The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 10^5, 0 ≤ c ≤ 9). -----Output----- Print position of the first occurrence of digit c...
[ "1 2 0\n", "2 3 7\n", "1 100000 1\n", "1 7 7\n", "99999 100000 8\n", "44102 73848 2\n", "7 31 3\n", "8880 81608 9\n", "4942 62768 5\n", "69168 84860 4\n" ]
[ "2", "-1", "5", "6", "-1", "132", "15", "161", "122", "107" ]
1
stdio
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
[ "a\n", "hi\n", "y\n", "kgan\n", "zoabkyuvus\n", "spyemhyznjieyhhbk\n", "xulsyfkuizjauadjjopu\n", "e\n", "zv\n", "jgv\n" ]
[ "51\n", "76\n", "51\n", "126\n", "276\n", "451\n", "526\n", "51\n", "76\n", "101\n" ]
1
stdio
Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employ...
[ "2\n", "10\n", "3\n", "4\n", "6\n", "13\n", "100000\n", "1024\n", "99999\n", "10007\n" ]
[ "1\n", "3\n", "1\n", "2\n", "3\n", "1\n", "35\n", "10\n", "11\n", "1\n" ]
1
stdio
The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is,...
[ "3 3 5\n", "2 4 4\n", "1 1 1\n", "1 1000000000 1000000000\n", "8 7 5\n", "1000000000 1 1\n", "1000000000 1000000000 1000000000\n", "800000003 7 7\n", "11 7 7\n", "1000000000 1 1\n" ]
[ "18\n3 6\n", "16\n4 4\n", "6\n1 6\n", "1000000000000000000\n1000000000 1000000000\n", "48\n8 6\n", "6000000000\n1 6000000000\n", "1000000000000000000\n1000000000 1000000000\n", "4800000018\n11 436363638\n", "70\n7 10\n", "6000000000\n1 6000000000\n" ]
1
stdio
-----Input----- The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). -----Output----- Output a single integer. -----Examples----- Input A221033 Output 21 Input A223635 Output 22 I...
[ "A221033\n", "A223635\n", "A232726\n", "A102210\n", "A231010\n", "A222222\n", "A555555\n", "A102222\n", "A234567\n", "A987654\n" ]
[ "21\n", "22\n", "23\n", "25\n", "26\n", "13\n", "31\n", "19\n", "28\n", "40\n" ]
1
stdio
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." [Image] The problem is:...
[ "4\n", "7\n", "77\n", "4\n", "474744\n", "777774\n", "447\n", "774\n", "4\n", "4447747\n" ]
[ "1\n", "2\n", "6\n", "1\n", "83\n", "125\n", "8\n", "13\n", "1\n", "140\n" ]
1
stdio
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in ...
[ "4\n1100\n", "4\n1111\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n01\n", "2\n10\n", "2\n11\n", "10\n0000000000\n", "20\n11111111110110001100\n" ]
[ "3\n", "4\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "11\n" ]
1
stdio
You're given an array $a$ of length $2n$. Is it possible to reorder it in such way so that the sum of the first $n$ elements isn't equal to the sum of the last $n$ elements? -----Input----- The first line contains an integer $n$ ($1 \le n \le 1000$), where $2n$ is the number of elements in the array $a$. The second...
[ "3\n1 2 2 1 3 1\n", "1\n1 1\n", "10\n3 10 5 5 8 6 6 9 9 3 1 7 10 2 4 9 3 8 2 2\n", "2\n1 4 2 3\n", "2\n1 1 2 2\n", "1\n79808 79808\n", "4\n56 14 77 12 87 55 31 46\n", "10\n859983 998985 909455 4688 549610 325108 492856 2751 734117 162579 97740 703983 356830 17839 881224 458713 233429 269974 351504 595...
[ "2 1 3 1 1 2", "-1", "1 2 2 2 3 3 3 4 5 5 6 6 7 8 8 9 9 9 10 10 ", "1 2 3 4 ", "1 1 2 2 ", "-1", "12 14 31 46 55 56 77 87 ", "2751 4688 17839 97740 162579 233429 269974 325108 351504 356830 458713 492856 549610 595389 703983 734117 859983 881224 909455 998985 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1
stdio
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s...
[ "5\n", "74\n", "1000\n", "586\n", "2\n", "362\n", "778\n", "194\n", "906\n", "659\n" ]
[ "1\n", "35\n", "881\n", "472\n", "0\n", "258\n", "653\n", "120\n", "786\n", "535\n" ]
1
stdio
You have $n \times n$ square grid and an integer $k$. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between $1$ and $k$ inclusive. Minimum number of the $i$-th row is $1$ ($1 \le i \le n$). Minimum number of the $j$-th column is $1$ ($1 \le j \le n$). Find the...
[ "2 2\n", "123 456789\n", "250 1000000000\n", "250 1\n", "1 3\n", "3 497285769\n", "3 212096267\n", "4 221874066\n", "244 315404017\n", "218 325181815\n" ]
[ "7\n", "689974806\n", "770503193\n", "1\n", "1\n", "790515254\n", "501206544\n", "274467242\n", "868949606\n", "230476135\n" ]
1
stdio
In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array $a$ of length $n$. Lesha considers all the non-e...
[ "3\n1 3 2\n", "5\n1 4 3 1 2\n", "51\n45 37 1 8 4 41 35 15 17 2 7 48 20 42 41 5 26 25 37 1 19 43 3 49 33 2 45 43 39 14 1 21 22 17 18 8 49 24 35 26 22 43 45 1 3 17 1 16 35 33 5\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...
[ "3\n", "6\n", "5\n", "102\n", "3\n", "16\n", "1\n", "4\n", "3\n", "2\n" ]
1
stdio
Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly $\frac{n}{2}$ hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some ham...
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n", "4\nxXXX\n", "2\nXx\n", "22\nXXxXXxxXxXxXXXXXXXXXxx\n", "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx\n", "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX\n", "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXx...
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n", "1\nxxXX\n", "0\nXx\n", "4\nxxxxxxxXxXxXXXXXXXXXxx\n", "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx\n", "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX\n", "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXx...
1
stdio
Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. -----Input----- First line o...
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n", "a\n1\n", "z\n2\n", "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26\n", "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26\n", "a\n3\n", "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxe...
[ "0\n", "1\n", "impossible\n", "0\n", "impossible\n", "14\n", "12\n", "impossible\n", "0\n", "1\n" ]
1
stdio
Ayoub had an array $a$ of integers of size $n$ and this array had two interesting properties: All the integers in the array were between $l$ and $r$ (inclusive). The sum of all the elements was divisible by $3$. Unfortunately, Ayoub has lost his array, but he remembers the size of the array $n$ and the numbers $l$...
[ "2 1 3\n", "3 2 2\n", "9 9 99\n", "1000 562 6782363\n", "200000 1 1000000000\n", "1 1 1\n", "3 1000000000 1000000000\n", "120881 536336525 585696606\n", "7884 43814 254290\n", "3895 1 564243401\n" ]
[ "3\n", "1\n", "711426616\n", "710038164\n", "69063912\n", "0\n", "1\n", "915864703\n", "104223746\n", "169725536\n" ]
1
stdio
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black. Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing...
[ "5 1 3 2\n", "7 2 2 5\n", "4 3 4 0\n", "2 2 0 2\n", "3 2 0 3\n", "1 1 0 1\n", "1 1 1 0\n", "11 2 3 8\n", "2 2 2 0\n", "2 2 1 1\n" ]
[ "GBGBG\n", "BBGBBGB\n", "NO\n", "BB\n", "NO\n", "B\n", "G\n", "BBGBBGBBGBB\n", "GG\n", "GB\n" ]
1
stdio
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are ...
[ "1 3 3\n", "2 3 10\n", "6 8 14215\n", "4 9 104671\n", "6 7 78755\n", "1 8 265\n", "3 9 37413\n", "1 7 49055\n", "3 4 11028\n", "2 6 32377\n" ]
[ "1\n", "165\n", "651581472\n", "329390901\n", "0\n", "461320265\n", "461358757\n", "461364774\n", "461668105\n", "887598327\n" ]
1
stdio
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like...
[ "4 2\n", "6 3\n", "1000 1000\n", "123 5\n", "1000 2\n", "1 2\n", "1 3\n", "1 4\n", "2 2\n", "3 2\n" ]
[ "7\n", "8\n", "1001\n", "153\n", "1999\n", "1\n", "1\n", "1\n", "3\n", "5\n" ]
1
stdio
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th column contains a_{i} cubes. At first, the gravity in the box is pull...
[ "4\n3 2 1 2\n", "3\n2 3 8\n", "5\n2 1 2 1 2\n", "1\n1\n", "2\n4 3\n", "6\n100 40 60 20 1 80\n", "10\n10 8 6 7 5 3 4 2 9 1\n", "10\n1 2 3 4 5 6 7 8 9 10\n", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 7...
[ "1 2 2 3 \n", "2 3 8 \n", "1 1 2 2 2 \n", "1 \n", "3 4 \n", "1 20 40 60 80 100 \n", "1 2 3 4 5 6 7 8 9 10 \n", "1 2 3 4 5 6 7 8 9 10 \n", "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 ...
1
stdio
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length n, such that it is simultaneously...
[ "1\n", "5\n", "6\n", "4\n", "15\n", "16\n", "17\n", "7\n", "120\n", "8\n" ]
[ "-1\n", "10080", "100170", "1050", "100000000000110", "1000000000000050", "10000000000000080", "1000020", "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000170", "10000200" ]
1
stdio
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...
[ "1 1 10\n", "1 2 5\n", "2 3 9\n", "4 8 9\n", "7 9 2\n", "10000 10000 10000\n", "24 22 9235\n", "74 8 417\n", "972 1 203\n", "550 1 754\n" ]
[ "10\n", "2\n", "1\n", "1\n", "0\n", "1\n", "34\n", "1\n", "0\n", "1\n" ]
1
stdio
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
[ "0 0\n", "1 0\n", "0 1\n", "-1 -1\n", "10 10\n", "0 6\n", "-7 -13\n", "37 -100\n", "99 100\n", "16 -32\n" ]
[ "0\n", "0\n", "2\n", "3\n", "37\n", "22\n", "52\n", "400\n", "398\n", "128\n" ]
1
stdio