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
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{div}(x, b)}{\operatorname{mod}(x, b)} = k$, where k is some integer...
[ "1 1\n", "2 2\n", "4 1\n", "4 2\n", "4 3\n", "4 4\n", "3 4\n", "2 4\n", "1 4\n", "1000 1000\n" ]
[ "0\n", "8\n", "0\n", "24\n", "102\n", "264\n", "162\n", "84\n", "30\n", "247750000\n" ]
1
stdio
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve...
[ "19 29\n", "3 6\n", "39 91\n", "76 134\n", "93 95\n", "17 35\n", "94 95\n", "51 52\n", "47 52\n", "38 98\n" ]
[ "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n" ]
1
stdio
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). $8$ illustration by 猫屋 https://twitter.com/nekoyaliu ...
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n", "QA\n", "IAQVAQZLQBQVQFTQQQADAQJA\n", "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ\n", "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ\n", "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA\n", "KAZXAVLPJQBQVQQQQQ...
[ "4\n", "3\n", "0\n", "24\n", "378\n", "1077\n", "568\n", "70\n", "0\n", "0\n" ]
1
stdio
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ...
[ "101\n", "110010\n", "10000\n", "1111111110\n", "10100101011110101\n", "111010010111\n", "11110111011100000000\n", "11110010010100001110110101110011110110100111101\n", "1001011111010010100111111\n", "1111111111\n" ]
[ "11\n", "11010\n", "1000\n", "111111111\n", "1100101011110101\n", "11110010111\n", "1111111011100000000\n", "1111010010100001110110101110011110110100111101\n", "101011111010010100111111\n", "111111111\n" ]
1
stdio
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...
[ "2\n2 3\n", "2\n5 3\n", "3\n5 6 7\n", "10\n72 96 24 66 6 18 12 30 60 48\n", "10\n78 66 6 60 18 84 36 96 72 48\n", "10\n98 63 42 56 14 77 70 35 84 21\n", "2\n1 1000000000\n", "2\n1000000000 999999999\n", "3\n2 4 6\n", "2\n4 6\n" ]
[ "Alice\n", "Alice\n", "Bob\n", "Bob\n", "Bob\n", "Bob\n", "Bob\n", "Bob\n", "Bob\n", "Alice\n" ]
1
stdio
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal i...
[ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n", "7\n5128 5672 5805 5452 5882 5567 5032\n", "10\n1 2 2 3 5 5 5 4 2 1\n", "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\n", "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4\n", "1\n1\n", "1\n1000000000\n", ...
[ "3\n", "2\n", "4\n", "5\n", "5\n", "4\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi...
[ "21\n", "20\n", "1\n", "2\n", "3\n", "100000001\n", "1000000000\n", "999999979\n", "9\n", "10\n" ]
[ "1\n15\n", "0\n", "0\n", "1\n1\n", "0\n", "2\n99999937\n100000000\n", "1\n999999932\n", "2\n999999899\n999999908\n", "0\n", "1\n5\n" ]
1
stdio
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $\rightarrow$ 'y' $\rightarrow$ 'x' $\rightarrow \ldots \rightarrow$ 'b' $\rightarrow$ 'a' $\rightarrow$ 'z'. In other words, each character is replaced with th...
[ "codeforces\n", "abacaba\n", "babbbabaababbaa\n", "bcbacaabcababaccccaaaabacbbcbbaa\n", "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n", "a\n", "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec\n", "fd...
[ "bncdenqbdr\n", "aaacaba\n", "aabbbabaababbaa\n", "abaacaabcababaccccaaaabacbbcbbaa\n", "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n", "z\n", "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec\n", "ec...
1
stdio
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward). ...
[ "3\n4 2 1\n", "1\n4\n", "2\n1 1\n", "1\n2\n", "1\n3\n", "1\n5\n", "2\n2 2\n", "3\n1 2 4\n", "3\n3 3 3\n", "3\n3 3 6\n" ]
[ "1\naabcbaa\n", "4\naaaa\n", "0\nab\n", "2\naa\n", "3\naaa\n", "5\naaaaa\n", "2\nabba\n", "1\nbccaccb\n", "0\naaabbbccc\n", "0\naaabbbcccccc\n" ]
1
stdio
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m col...
[ "2 4\n", "2 1\n", "1 1\n", "1 2\n", "1 3\n", "2 2\n", "2 3\n", "3 1\n", "3 2\n", "3 3\n" ]
[ "YES\n5 4 7 2 \n3 6 1 8 \n", "NO\n", "YES\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n6 1 8\n7 5 3\n2 9 4\n" ]
1
stdio
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 10^9 + ...
[ "ab\n", "aab\n", "aaaaabaabababaaaaaba\n", "abaabaaabbabaabab\n", "abbaa\n", "abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb\n", "aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba\n", "aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb\n", "aaabaaaabbababbaabbababbbbaaaaaaabbabbb...
[ "1\n", "3\n", "17307\n", "1795\n", "2\n", "690283580\n", "2183418\n", "436420225\n", "8431094\n", "8180\n" ]
1
stdio
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati...
[ "7\n2 1 5 11 5 9 11\n", "5\n5 4 3 2 1\n", "2\n1 1000\n", "2\n1000 1\n", "5\n100 80 60 70 90\n", "10\n10 16 17 11 1213 1216 1216 1209 3061 3062\n", "20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158\n", "1\n1\n", "5\n1 1 1 2 3\n", "1\n1000\n" ]
[ "9\n", "12\n", "0\n", "1000\n", "54\n", "16\n", "43\n", "0\n", "3\n", "0\n" ]
1
stdio
You are given an array $a$ of $n$ integers. You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where $len$ is the length of this segment (added integers can be different). It...
[ "4\n1 3 2 4\n", "1\n34688642\n", "2\n-492673762 -496405053\n", "4\n-432300451 509430974 -600857890 -140418957\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "8\n-311553829 4...
[ "1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n", "1 1\n-34688642\n1 1\n0\n1 1\n0\n", "1 2\n985347524 0\n1 1\n-492673762 \n2 2\n496405053\n", "1 4\n1729201804 -2037723896 2403431560 0\n1 3\n-1296901353 1528292922 -1802573670 \n4 4\n140418957\n", "1 16\n241731792 -7828171872 -10908965712 1261781840 6663483888 1434...
1
stdio
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number x belongs to set B, then number b - x must also belong to set B. Help Lit...
[ "4 5 9\n2 3 4 5\n", "3 3 4\n1 2 4\n", "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 2420 3361 3035 956 253...
[ "YES\n0 0 1 1\n", "NO\n", "NO\n", "NO\n", "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "YES\n0\n", "YES\n0\n", "YES\n1 1\n", "NO\n", "NO\n" ]
1
stdio
Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th number in increasing order on this segment. In other words, you should find th...
[ "5 3\n1 2 3 4 5\n", "2 6\n-5 9\n", "6 99\n-1 -1 -1 -1 -1 -1\n", "5 -2\n-1 -1 -4 -5 1\n", "5 -6\n-4 2 -7 -1 -5\n", "10 29\n88 57 -3 -9 16 48 -84 80 -73 -46\n", "1 1000000000\n1\n", "2 -1000000000\n465132 210\n", "10 -8\n7 -1 0 -8 8 -1 -10 -7 4 0\n", "10 9\n-2 6 0 -6 7 -8 -5 4 -3 3\n" ]
[ "6 5 4 0 0 0 ", "1 2 0 ", "0 6 5 4 3 2 1 ", "4 5 6 0 0 0 ", "6 9 0 0 0 0 ", "5 13 11 11 8 4 3 0 0 0 0 ", "0 1 ", "3 0 0 ", "27 28 0 0 0 0 0 0 0 0 0 ", "0 10 9 8 7 6 5 4 3 2 1 " ]
1
stdio
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t...
[ "4\nezor\n", "10\nnznooeeoer\n", "4\neorz\n", "3\nnoe\n", "40\noeerzzozozzrezeezzzoroozrrreorrreereooeo\n", "32\noeonznzneeononnerooooooeeeneenre\n", "35\nozrorrooeoeeeozonoenzoeoreenzrzenen\n", "30\nooeoeneenneooeennnoeeonnooneno\n", "400\nzzzerrzrzzrozrezooreroeoeezerrzeerooereezeeererrezrororoorr...
[ "0 \n", "1 1 0 \n", "0 \n", "1 \n", "0 0 0 0 0 0 0 0 0 0 \n", "1 1 1 1 1 1 1 1 0 0 \n", "1 1 1 1 1 0 0 0 0 0 \n", "1 1 1 1 1 1 1 1 1 1 \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...
1
stdio
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}. Your task is to find such permutation p of length n, that the group of numbers |p_1 - p_2|, |p_2 - p_3|, ..., |p_...
[ "3 2\n", "3 1\n", "5 2\n", "5 4\n", "10 4\n", "10 3\n", "10 9\n", "2 1\n", "4 1\n", "4 2\n" ]
[ "1 3 2\n", "1 2 3\n", "1 3 2 4 5\n", "1 5 2 4 3\n", "1 10 2 9 8 7 6 5 4 3\n", "1 10 2 3 4 5 6 7 8 9\n", "1 10 2 9 3 8 4 7 5 6\n", "1 2\n", "1 2 3 4\n", "1 4 3 2\n" ]
1
stdio
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d. Note that the order of the points inside the group of three chosen point...
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n", "10 90\n24 27 40 41 61 69 73 87 95 97\n", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -5...
[ "4\n", "2\n", "1\n", "2\n", "25\n", "120\n", "79351\n", "0\n", "0\n", "0\n" ]
1
stdio
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high. [Image] A group of bears is a non-empty contiguous segment of the line. The siz...
[ "10\n1 2 3 4 5 4 3 2 1 6\n", "3\n524125987 923264237 374288891\n", "5\n585325539 365329221 412106895 291882089 564718673\n", "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717...
[ "6 4 4 3 3 2 2 1 1 1 \n", "923264237 524125987 374288891 \n", "585325539 365329221 365329221 291882089 291882089 \n", "954478790 641889899 519361360 452405440 346543678 346543678 208050516 208050516 208050516 208050516 80960260 80960260 80960260 66743034 66743034 16115810 16115810 16115810 16115810 16115810 \...
1
stdio
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i...
[ "3\n2\n2\n1\n", "4\n1\n2\n3\n4\n", "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "5\n10\n10\n10\n10\n10\n", "11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2\n", "1\n1\n", "13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76\n", "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\...
[ "3\n", "1680\n", "12520708\n", "425711769\n", "902382672\n", "1\n", "232242896\n", "362689152\n", "295545118\n", "691446102\n" ]
1
stdio
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from...
[ "ababa\naba\n", "welcometoroundtwohundredandeightytwo\nd\n", "ddd\nd\n", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa\n", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n", "a\na\n", "a\naa\n", "a\nb\n"...
[ "5\n", "274201\n", "12\n", "943392\n", "834052\n", "2728075\n", "1\n", "0\n", "0\n", "35\n" ]
1
stdio
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...
[ "2\n6 12 10\n4 3 10\n", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\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", "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10\n", "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4\n", "1...
[ "Finite\nInfinite\n", "Finite\nFinite\nFinite\nInfinite\n", "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite\n", "Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\n", "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nF...
1
stdio
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\&$ is the bitwise AND operation. Count the number of connected components i...
[ "2 3\n1 2 3\n", "5 5\n5 19 10 20 12\n", "3 5\n3 5 0 6 7\n", "0 1\n0\n", "1 1\n1\n", "1 1\n0\n", "6 30\n3 8 13 16 18 19 21 22 24 25 26 28 29 31 33 42 44 46 49 50 51 53 54 57 58 59 60 61 62 63\n", "6 35\n5 7 10 11 13 14 17 18 25 27 28 29 30 31 33 35 36 37 39 40 41 43 46 47 50 52 55 56 57 58 59 60 61 62 ...
[ "2\n", "2\n", "1\n", "1\n", "1\n", "1\n", "10\n", "13\n", "20\n", "19\n" ]
1
stdio
In order to fly to the Moon Mister B just needs to solve the following problem. There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles. We are sure that Mister B will solve the problem soon and will fly to the Mo...
[ "3\n", "5\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n" ]
[ "2\n3 1 2 3\n3 1 2 3\n", "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n", "4\n3 4 1 2\n3 2 3 4\n3 1 2 3\n3 3 4 1\n", "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n", "9\n3 6 1 2\n4 6 2 5 3\n3 3 4 5\n3 1 2 3\n4 1 3 6 4\n3 4 5 6\n3 2 3 4\n4 2 4 1 5\n3 5 6 1\n", "12\n4 2 3 1 4...
1
stdio
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he...
[ "1 1\n1\n", "2 2\n1\n2\n", "3 5\n1\n4\n20\n50\n300\n", "4 5\n2\n4\n30\n100\n1000\n", "5 6\n1\n2\n3\n4\n5\n6\n", "6 6\n10\n20\n30\n40\n50\n60\n", "990 1\n990\n", "7 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\n", "8 10\n50\n150\n250\n350\n450\n550\n650\n750\n850\n950\n", "1 1\n1000\n" ]
[ "1\n", "2\n2\n", "3\n3\n3\n3\n3\n", "4\n4\n4\n4\n7\n", "5\n5\n5\n5\n5\n5\n", "6\n6\n6\n7\n7\n7\n", "7177\n", "9\n10\n11\n12\n13\n14\n14\n15\n16\n17\n", "10\n12\n13\n14\n15\n16\n17\n18\n19\n19\n", "1\n" ]
1
stdio
Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$. Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1...
[ "7\n", "6\n", "7137\n", "1941\n", "55004\n", "1\n", "2\n", "3\n", "4\n", "5\n" ]
[ "YES\n1\n2\n5\n6\n3\n4\n7\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n1\n", "YES\n1\n2\n", "YES\n1\n2\n3\n", "YES\n1\n3\n2\n4", "YES\n1\n2\n4\n3\n5\n" ]
1
stdio
You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$. Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$. -----Input----- The first line contains integers $n, p, k$ ($2 \le n \le 3 \cdot 10^5$, $2 \le p \l...
[ "3 3 0\n0 1 2\n", "6 7 2\n1 2 3 4 5 6\n", "5 5 3\n3 0 4 1 2\n", "7 7 3\n4 0 5 3 1 2 6\n", "2 2 1\n1 0\n", "3 3 0\n0 2 1\n", "2 2 0\n1 0\n", "3 3 1\n0 2 1\n", "3 3 2\n0 1 2\n" ]
[ "1", "3", "1", "0", "1", "1", "0", "1", "1" ]
1
stdio
Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$. -----Input----- The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t lines of the ...
[ "2\n2\n3\n", "1\n1000000000\n", "5\n3\n6\n9\n10\n5\n", "5\n5\n8\n18\n17\n17\n", "5\n7\n40\n37\n25\n4\n", "5\n72\n72\n30\n75\n11\n", "5\n79\n149\n136\n194\n124\n", "6\n885\n419\n821\n635\n63\n480\n", "1\n649580447\n" ]
[ "1/6\n7/30\n", "999999941999999673/1999999887999999118\n", "7/30\n5/14\n61/154\n9/22\n23/70\n", "23/70\n59/154\n17/38\n287/646\n287/646\n", "57/154\n39/82\n1437/3034\n615/1334\n3/10\n", "71/146\n71/146\n29/62\n5615/11534\n119/286\n", "6393/13114\n22199/44998\n135/274\n37631/76042\n14121/28702\n", "781...
1
stdio
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater...
[ "6\n", "9\n", "2\n", "10\n", "100\n", "1\n", "3\n", "5\n" ]
[ "2\n6 3\n2 4\n", "3\n9 3\n2 4\n6 8\n", "0\n", "4\n2 4\n6 8\n10 5\n9 3\n", "44\n33 27\n22 11\n25 5\n64 66\n42 44\n31 62\n58 29\n43 86\n15 21\n6 99\n8 12\n85 65\n7 49\n23 46\n16 14\n20 18\n90 92\n48 50\n40 36\n74 37\n35 55\n10 95\n56 60\n47 94\n45 39\n93 87\n88 84\n72 76\n28 24\n75 81\n78 80\n54 52\n38 19\n3 ...
1
stdio
You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}. -----Input----- The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·10^5). The second l...
[ "3\n3 4 5\n", "3\n1 2 4\n", "1\n1\n", "1\n1000000\n", "2\n1000000 999999\n", "12\n4 4 10 13 28 30 41 43 58 61 70 88\n", "7\n2 13 22 32 72 91 96\n", "5\n5 11 12 109 110\n" ]
[ "2\n", "0\n", "0\n", "0\n", "1\n", "30\n", "27\n", "10\n" ]
1
stdio
You are given a string S of length n with each character being one of the first m lowercase English letters. Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longest common subsequence) between S and T is n - 1. Recall that LCS ...
[ "3 3\naaa\n", "3 3\naab\n", "1 2\na\n", "10 9\nabacadefgh\n", "15 3\nabababababababa\n", "100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n", "1 26\nz\n" ]
[ "6\n", "11\n", "1\n", "789\n", "345\n", "237400\n", "25\n" ]
1
stdio
You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: - Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1. Minimize the hamming distance between...
[ "3\n1 0 1\n1\n1 3\n", "3\n1 0 1\n2\n1 1\n3 3\n", "3\n1 0 1\n2\n1 1\n2 3\n", "5\n0 1 0 1 0\n1\n1 5\n", "9\n0 1 0 1 1 1 0 1 0\n3\n1 4\n5 8\n6 7\n", "15\n1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n9\n4 10\n13 14\n1 7\n4 14\n9 11\n2 6\n7 8\n3 12\n7 13\n", "10\n0 0 0 1 0 0 1 1 1 0\n7\n1 4\n2 5\n1 3\n6 7\n9 9\n1 5\n7 9\n...
[ "1\n", "0\n", "1\n", "2\n", "3\n", "5\n", "1\n" ]
1
stdio
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $f(0) = a$; $f(1) = b$; $f(n) = f(n-1) \oplus f(n-2)$ when $n > 1$, where $\o...
[ "3\n3 4 2\n4 5 0\n325 265 1231232\n", "10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 1000000000 1000000000\n", "1\n25369 85223 58963241\n", "2\n168342 440469 517112\n841620 806560 140538\n", "10\n669924290 40...
[ "7\n4\n76\n", "0\n2003\n233\n0\n2132\n442567\n1213\n1\n1\n1000000000\n", "77822\n", "272643\n841620\n", "1069371953\n696139211\n286024744\n189259304\n707829111\n54555019\n578351356\n463366171\n178762989\n825160173\n", "1\n" ]
1
stdio
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that...
[ "3\n1 1\n", "5\n1 2 3 4\n", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "29\n1 2 2 4 4 6 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\n", "2\n1\n", "3\n1 2\n" ]
[ "4 3 3", "5 8 9 8 5", "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 ...
1
stdio
For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other. Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true: - Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1. - Any t...
[ "2 2\n00\n01\n", "2 2\n00\n11\n", "3 3\n0\n10\n110\n", "2 1\n0\n1\n", "1 2\n11\n", "2 3\n101\n11\n" ]
[ "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n" ]
1
stdio
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 characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r...
[ "6 4\n()(())\n", "8 8\n(()(()))\n", "20 10\n((()))()((()()(())))\n", "40 30\n((((((((()()()))))))))((())((()())))(())\n", "2 2\n()\n" ]
[ "()()\n", "(()(()))\n", "((()))()()\n", "((((((((()()()))))))))(())()()\n", "()\n" ]
1
stdio
The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Given a number $m$, how many polynomials $P$ with coefficients in set ${\{0,1,2...
[ "2\n2 4\n", "1\n9\n", "5\n4 1 8 3 9\n", "6\n8 7 8 6 8 9\n", "8\n1 1 7 6 1 5 8 7\n", "7\n9 6 3 1 3 1 7\n", "3\n9 2 8\n", "5\n3 7 3 4 7\n", "5\n4 8 3 2 6\n", "5\n2 7 4 8 3\n" ]
[ "2\n4\n", "9\n", "4\n1\n9\n2\n9\n", "9\n6\n9\n6\n9\n9\n", "1\n1\n6\n6\n1\n4\n9\n6\n", "9\n6\n2\n1\n2\n1\n6\n", "9\n2\n9\n", "2\n6\n2\n4\n6\n", "4\n9\n2\n2\n6\n", "2\n6\n4\n9\n2\n" ]
1
stdio
Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and $\text{popcount}(x)$ is maximum possible. If there are multiple...
[ "3\n1 2\n2 4\n1 10\n", "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10\n...
[ "1\n3\n7\n", "1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10\n", "7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177...
1
stdio
AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure: AtCoDeer will move these rectangles ho...
[ "3\n1 3\n5 7\n1 3\n", "3\n2 5\n4 6\n1 4\n", "5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 1000000000\n", "5\n123456 789012\n123 456\n12 345678901\n123456 789012\n1 23\n", "1\n1 400\n" ]
[ "2\n", "0\n", "1999999680\n", "246433\n", "0\n" ]
1
stdio
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)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can form sides of a triangle. Three numbers $a$, $b$ and $c$ can form sides of a ...
[ "3\n1 5 10\n", "6\n12 432 21 199 7 1\n", "7\n1 10 100 1000 10000 100000 1000000\n", "100\n42 486 341 527 189 740 490 388 989 489 711 174 305 844 971 492 998 954 832 442 424 619 906 154 293 395 439 735 738 915 453 748 786 550 871 932 693 326 53 904 732 835 354 364 691 669 157 719 282 875 573 672 695 790 58 872...
[ "1\n3\n3\n", "4\n76\n7\n41\n4\n1\n", "1\n3\n22\n158\n1205\n9528\n78331\n", "11\n85\n62\n92\n37\n123\n86\n69\n156\n86\n119\n35\n56\n137\n154\n87\n158\n153\n137\n78\n75\n106\n145\n32\n56\n70\n78\n122\n122\n147\n80\n124\n129\n93\n141\n149\n117\n60\n13\n145\n121\n137\n65\n65\n117\n113\n33\n120\n55\n141\n97\n113\n...
1
stdio
You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e. $\sum_{i = 1}^{k} a_{x_{i}} \neq \sum_{i = 1}^{k} b_{x_{i}}$...
[ "2\n1 2\n", "4\n1000 100 10 1\n", "5\n1 3 4 5 2\n", "1\n10000000\n", "4\n1 5 8 4\n", "3\n1 3 2\n", "4\n3 1 2 4\n", "12\n7 1 62 12 3 5 8 9 10 22 23 0\n", "17\n1 3 2 5 4 6 7 8 10 9 13 11 12 14 15 16 18\n", "22\n1 3 5 7 22 2 4 6 8 9 10 11 12 13 15 14 17 18 16 20 19 23\n" ]
[ "2 1 \n", "100 1 1000 10\n", "5 2 3 4 1 \n", "10000000 \n", "8 4 5 1 \n", "3 2 1 \n", "2 4 1 3 \n", "5 0 23 10 1 3 7 8 9 12 22 62 \n", "18 2 1 4 3 5 6 7 9 8 12 10 11 13 14 15 16 \n", "23 2 4 6 20 1 3 5 7 8 9 10 11 12 14 13 16 17 15 19 18 22 \n" ]
1
stdio
On the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t). He can move in arbitrary directions with speed 1. Here, we will consider him as a point without size. There are N circular barriers deployed on the plane. The center and the radius of the i-th barrier are (x_i, y_i) and r_i, re...
[ "-2 -2 2 2\n1\n0 0 1\n", "-2 0 2 0\n2\n-1 0 2\n1 0 2\n", "4 -2 -2 4\n3\n0 0 2\n4 0 1\n0 4 1\n", "-1000000000 -1000000000 1000000000 1000000000\n1\n-1000000000 1000000000 1\n", "-1000000000 -1000000000 1000000000 1000000000\n1\n0 0 1\n", "-79535040 915543494 814343766 427961683\n983\n793251728 432429299 21...
[ "3.6568542495\n", "0.0000000000\n", "4.0000000000\n", "2828427124.7461901000\n", "2828427122.7461901000\n", "425674041.2906273600\n", "32149365.5833579970\n", "0.0000000000\n", "27033675.3832434190\n", "0.0000000000\n" ]
1
stdio
Given positive integers N, K and M, solve the following problem for every integer x between 1 and N (inclusive): - Find the number, modulo M, of non-empty multisets containing between 0 and K (inclusive) instances of each of the integers 1, 2, 3 \cdots, N such that the average of the elements is x. -----Constraints--...
[ "3 1 998244353\n", "1 2 1000000007\n", "10 8 861271909\n", "2 1 905589253\n", "14 19 964292983\n", "24 26 804695321\n", "39 36 991399517\n", "46 46 961455263\n", "60 55 931711961\n", "64 64 879068783\n" ]
[ "1\n3\n1\n", "2\n", "8\n602\n81827\n4054238\n41331779\n41331779\n4054238\n81827\n602\n8\n", "1\n1\n", "19\n40239\n116285439\n44188045\n615501833\n534054421\n694441861\n694441861\n534054421\n615501833\n44188045\n116285439\n40239\n19\n", "26\n316385\n587325446\n562348028\n259395159\n735586658\n540711096\n44...
1
stdio
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, ...
[ "|[a:b:|]\n", "|]:[|:]\n", ":][:\n", ":[]:\n", "[[:]]\n", "[::]\n", "]:|:[\n", ":::::]\n", "::::]\n", "::[]\n" ]
[ "4\n", "-1\n", "-1\n", "-1\n", "-1\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
1
stdio
Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. -----Input----- The first line contains the positive inte...
[ "100\n", "48\n", "521\n", "1\n", "2\n", "3\n", "39188\n", "5\n", "6\n", "7\n" ]
[ "99\n", "48\n", "499\n", "1\n", "2\n", "3\n", "38999\n", "5\n", "6\n", "7\n" ]
1
stdio
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
[ "4\n", "201\n", "4000\n", "9\n", "10\n", "1\n", "100000000\n", "900000000\n", "999999999\n", "1000000000\n" ]
[ "1\n", "99\n", "1000\n", "1\n", "10\n", "1\n", "100000000\n", "100000000\n", "1\n", "1000000000\n" ]
1
stdio
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. -----Input----- The first line of the input ...
[ "14\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n" ]
[ "4 4\n", "0 2\n", "0 1\n", "0 2\n", "0 2\n", "0 2\n", "1 2\n", "2 2\n", "2 3\n", "2 4\n" ]
1
stdio
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that ...
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n", "1 -4 -5\n", "0 1 0\n", "10 10 42\n", "-1000000000 1000000000 -1\n", "10 16 4\n", "-1000000000 1000000000 5\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n" ]
1
stdio
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this charact...
[ "cab\n", "acdb\n", "a\n", "ab\n", "ba\n", "dijee\n", "bhrmc\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba\n", "bccbbcccbccbacacbacca...
[ "abc\n", "abdc\n", "a\n", "ab\n", "ab\n", "deeji\n", "bcmrh\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "aaaaaaaaaaaaaaaaaaaaa...
1
stdio
Karen is getting ready for a new school day! [Image] It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time...
[ "05:39\n", "13:31\n", "23:59\n", "13:32\n", "14:40\n", "14:00\n", "05:50\n", "12:22\n", "12:34\n", "05:30\n" ]
[ "11\n", "0\n", "1\n", "69\n", "1\n", "41\n", "0\n", "69\n", "57\n", "20\n" ]
1
stdio
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. [Image] English alphabet You are given...
[ "oXoxoXo\n", "bod\n", "ER\n", "o\n", "a\n", "opo\n", "HCMoxkgbNb\n", "vMhhXCMWDe\n", "iIcamjTRFH\n", "WvoWvvWovW\n" ]
[ "TAK\n", "TAK\n", "NIE\n", "TAK\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "TAK\n" ]
1
stdio
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n", "23923472834\n23589234723\n", "102391019\n491010301\n", "123456789123456789\n276193619183618162\n", "1000000000000000000\n1000000000000000000\n", "1\n1000000000000000000\n", "999999999999999999\n1000000000000000000\n", "2475345634895\n3455834583479\n"...
[ "213\n", "9321\n", "4940\n", "23498743322\n", "399211100\n", "276193618987554432\n", "1000000000000000000\n", "1\n", "999999999999999999\n", "3455834579642\n" ]
1
stdio
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically...
[ "2 1\n", "3 2\n", "2 5\n", "1 0\n", "1 1\n", "20 401\n", "100 10001\n", "2 3\n", "4 5\n", "5 6\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n", "0 \n", "1 \n", "-1\n", "-1\n", "1 1 \n1 0 \n", "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 \n", "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n" ]
1
stdio
You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0. -----Input----- The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 ≤ 2·10^9, - 2·10^9 ≤ b_1, b_2, L, R ≤ 2·...
[ "2 0 3 3 5 21\n", "2 4 3 0 6 17\n", "2 0 4 2 -39 -37\n", "1 9 3 11 49 109\n", "3 81 5 72 -1761 501\n", "8 -89 20 67 8771 35222\n", "1 -221 894 86403 -687111 141371\n", "1 -1074 271 17741 -2062230 1866217\n", "3 2408 819 119198 -8585197 7878219\n", "1 341 8581 3946733 -59420141 33253737\n" ]
[ "3\n", "2\n", "0\n", "20\n", "28\n", "661\n", "62\n", "6821\n", "9474\n", "3416\n" ]
1
stdio
The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each col...
[ "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n", "4 3\nBRG\nBRG\nBRG\nBRG\n", "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n", "4 4\nRRRR\nRRRR\nBBBB\nGGGG\n", "1 3\nGRB\n", "3 1\nR\nG\nB\n", "4 3\nRGB\nGRB\nGRB\nGRB\n", "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB\n", "100 3\nRGB\nRGB\nRGB\...
[ "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
1
stdio
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: [Image] [Image] Ayrat is searching through the field. He started at point (...
[ "3\n", "7\n", "39\n", "14\n", "94\n", "60\n", "60\n", "59\n", "181994\n", "486639\n" ]
[ "-2 0\n", "3 2\n", "5 6\n", "-2 -4\n", "8 8\n", "8 0\n", "8 0\n", "7 -2\n", "154 -492\n", "-33 806\n" ]
1
stdio
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
[ "4 6 15\n", "3 2 7\n", "6 11 6\n", "3 12 15\n", "5 5 10\n", "6 6 7\n", "1 1 20\n", "12 14 19\n", "15 12 26\n", "2 4 8\n" ]
[ "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n" ]
1
stdio
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ...
[ "4\n-1 0\n0 -1\n1 0\n1 1\n", "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n", "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7\n", "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2\n", "2\n351 -4175\n-328 -657\n", "3\n620...
[ "3 4\n", "5 6\n", "1 3\n", "13 16\n", "2 1\n", "1 2\n", "1 2\n", "3 1\n", "1 6\n", "1 6\n" ]
1
stdio
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by the...
[ "6 3\n", "8 2\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "2 10000000000\n", "5 1\n", "6 2\n", "24 2\n" ]
[ "1 2 3\n", "2 6\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "5\n", "2 4\n", "8 16\n" ]
1
stdio
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
[ "2 2 2\n", "2 3 4\n", "1 10 5\n", "1 1 1\n", "10 1 7\n", "10 10 33\n", "500000 500000 1\n", "500000 500000 250000000000\n", "3 3 1\n", "3 3 2\n" ]
[ "2\n", "3\n", "5\n", "1\n", "7\n", "14\n", "1\n", "250000000000\n", "1\n", "2\n" ]
1
stdio
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The fir...
[ "7\n", "21\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n" ]
[ "7\n", "5\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n" ]
1
stdio
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}...
[ "8\nabacabac\n1 1 1 1 1 1 1 1\n", "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "8\nabacabca\n1 2 3 4 4 3 2 1\n", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 74 ...
[ "8\n", "26\n", "17\n", "4382\n", "4494\n", "4540\n", "4466\n", "4425\n", "486\n", "5112\n" ]
1
stdio
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
[ "3 7\n", "100 99\n", "100 50\n", "1000000000 1\n", "100 10002\n", "4 7\n", "4 11\n", "5 781\n", "7 9\n", "5077 5988\n" ]
[ "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n" ]
1
stdio
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
[ "2\n0 0\n1 1\n", "1\n1 1\n", "1\n-188 17\n", "1\n71 -740\n", "4\n-56 -858\n-56 -174\n778 -858\n778 -174\n", "2\n14 153\n566 -13\n", "2\n-559 894\n314 127\n", "1\n-227 -825\n", "2\n-187 583\n25 13\n", "2\n-337 451\n32 -395\n" ]
[ "1\n", "-1\n", "-1\n", "-1\n", "570456\n", "91632\n", "669591\n", "-1\n", "120840\n", "312174\n" ]
1
stdio
You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the ...
[ "6\n1 2 5 3 4 6\n01110\n", "6\n1 2 5 3 4 6\n01010\n", "6\n1 6 3 4 5 2\n01101\n", "6\n2 3 1 4 5 6\n01111\n", "4\n2 3 1 4\n011\n", "2\n2 1\n0\n", "5\n1 2 4 5 3\n0101\n", "5\n1 2 4 5 3\n0001\n", "5\n1 4 5 2 3\n0110\n", "5\n4 5 1 2 3\n0111\n" ]
[ "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
1
stdio
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloon...
[ "4 2\naabb\n", "6 3\naacaab\n", "2 2\nlu\n", "5 3\novvoo\n", "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf\n", "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv\n", "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
[ "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n" ]
1
stdio
You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line contains positive integer n (2 ≤ n ≤ 10^5) — size of the given array. The second...
[ "2\n3 3\n", "3\n5 6 5\n", "9\n2 1 3 5 4 1 2 3 1\n", "6\n4 6 7 8 6 4\n", "2\n1000000000 1000000000\n", "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "2\n10000000 10000000\n", "5\n100000000 100000001 100000000 100000001 100000000\n", "9\n4 3 4 3 4 1 3 3 1...
[ "1\n", "2\n", "3\n", "5\n", "1\n", "1\n", "1\n", "2\n", "3\n", "2\n" ]
1
stdio
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 ≤ i ≤ k), such that 1 ≤ k ≤ 3 p_...
[ "27\n", "3\n", "25\n", "9\n", "91\n", "57\n", "31\n", "555\n", "700000001\n", "5\n" ]
[ "3\n2 2 23", "1\n3", "2\n2 23", "2\n2 7", "2\n2 89", "3\n2 2 53", "1\n31", "3\n3 5 547", "1\n700000001", "1\n5" ]
1
stdio
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column...
[ "3 4\n.*..\n....\n.*..\n", "3 3\n..*\n.*.\n*..\n", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "1 10\n**********\n", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n", "10 10\n....
[ "YES\n1 2\n", "NO\n", "YES\n3 3\n", "YES\n1 1\n", "YES\n1 1\n", "YES\n3 10\n", "YES\n6 5\n", "YES\n1 10\n", "YES\n1 5\n", "YES\n3 2\n" ]
1
stdio
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k...
[ "6 10\n", "21 31\n", "5 10\n", "1924 5834\n", "9911 666013\n", "1 1\n", "69 4295\n", "948248258 533435433\n", "953 1349\n", "999999973 800000007\n" ]
[ "2", "9", "0", "31", "318140", "0", "2044", "296190217", "235", "199999823" ]
1
stdio
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: $\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$ Find the sum modulo 1073741824 (2^30). -----Input----- The first line contains three s...
[ "2 2 2\n", "5 6 7\n", "91 42 25\n", "38 47 5\n", "82 29 45\n", "40 15 33\n", "35 5 21\n", "71 2 1\n", "22 44 41\n", "73 19 29\n" ]
[ "20\n", "1520\n", "3076687\n", "160665\n", "3504808\n", "460153\n", "55282\n", "811\n", "1063829\n", "1047494\n" ]
1
stdio
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a_1 × b_1 rectangle, the paintings have shape of a a_2 × b_2 and a_3 × b_3 rectangles. Si...
[ "3 2\n1 3\n2 1\n", "5 5\n3 3\n3 3\n", "4 2\n2 3\n1 2\n", "3 3\n1 1\n1 1\n", "1000 1000\n999 999\n1 1000\n", "7 7\n5 5\n2 4\n", "3 3\n2 2\n2 2\n", "2 9\n5 1\n3 2\n", "9 9\n3 8\n5 2\n", "10 10\n10 5\n4 3\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n" ]
1
stdio
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. [Image] He ate coffee mi...
[ "6\n", "99\n", "20\n", "10\n", "15\n", "27\n", "40\n", "63\n", "0\n", "1\n" ]
[ "six\n", "ninety-nine\n", "twenty\n", "ten\n", "fifteen\n", "twenty-seven\n", "forty\n", "sixty-three\n", "zero\n", "one\n" ]
1
stdio
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
[ "100010001\n", "100\n", "0000001000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111\n", "01111111011111111111111111111111111111111111111111...
[ "yes", "no", "yes", "no", "no", "no", "no", "yes", "yes", "yes" ]
1
stdio
You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of ...
[ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n", "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs\n", "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "abcdefghijklmnopqrstuvwxxx\n", "abcdefghijklmnopqrstuvwxya\n", ...
[ "abcdefghijklmnopqrstuvwxyz\n", "-1\n", "-1\n", "-1\n", "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa\n", "abcdefghijklmnopqrstuvwxyz\n", "abcdefghijklmnopqrstuvwxyz\n", "abcdefghijklmnopqrstuvwxyz\n", "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n", "zazbcdefghijklmnopqrstuvwxy...
1
stdio
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, that n can be divided by it without remainder. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9). -----Output----- If n has less ...
[ "4 2\n", "5 3\n", "12 5\n", "1 1\n", "866421317361600 26880\n", "866421317361600 26881\n", "1000000000000000 1000000000\n", "1000000000000000 100\n", "1 2\n", "4 3\n" ]
[ "2\n", "-1\n", "6\n", "1\n", "866421317361600\n", "-1\n", "-1\n", "1953125\n", "-1\n", "4\n" ]
1
stdio
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
[ "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5\n", "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8\n", "1\n5 2 2 5 6 7\n", "1\n7 6 5 8 9 0\n", "1\n2 5 9 6 7 9\n", "1\n6 3 1 9 4 9\n", "1\n1 9 8 3 7 8\n", "2\n1 7 2 0 4 ...
[ "87", "98", "5", "3", "0", "0", "0", "1", "1", "7" ]
1
stdio
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program...
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n", "1 0\n", "2 0\n", "100 0\n", "1000000000 0\n", "160 2\n", "3 0\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n", "1\n", "2\n", "100\n", "1000000000\n", "800\n", "3\n" ]
1
stdio
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper...
[ "2 2 2\n", "2 1 2\n", "1 1 3\n", "3 2 1\n", "100 100 100\n", "1 100 100\n", "100 1 100\n", "100 100 1\n", "1 100 99\n", "99 1 100\n" ]
[ "0.333333333333 0.333333333333 0.333333333333\n", "0.150000000000 0.300000000000 0.550000000000\n", "0.057142857143 0.657142857143 0.285714285714\n", "0.487662337662 0.072077922078 0.440259740260\n", "0.333333333333 0.333333333333 0.333333333333\n", "0.366003713151 0.633996286849 0.000000000000\n", "0.0...
1
stdio
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visi...
[ "1 10 9 20 1\n", "1 100 50 200 75\n", "6 6 5 8 9\n", "1 1000000000 1 1000000000 1\n", "5 100 8 8 8\n", "1 1000000000000000000 2 99999999999999999 1000000000\n", "1 1 1 1 1\n", "1 2 3 4 5\n", "1 1000000000 2 999999999 3141592\n", "24648817341102 41165114064236 88046848035 13602161452932 10000831349...
[ "2\n", "50\n", "1\n", "999999999\n", "0\n", "99999999999999997\n", "0\n", "0\n", "999999997\n", "0\n" ]
1
stdio
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be...
[ "3\n1 3 2\n", "5\n1 2 3 4 5\n", "5\n2 2 3 4 5\n", "5\n72 32 17 46 82\n", "6\n26 10 70 11 69 57\n", "7\n4 7 10 7 5 5 1\n", "8\n9 5 5 10 4 9 5 8\n", "10\n9 6 8 5 5 2 8 9 2 2\n", "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\n", "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n" ]
1
stdio
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his cont...
[ "3\n586\n", "2\n09\n", "9\n123456789\n", "3\n911\n", "3\n089\n", "3\n159\n", "9\n000000000\n", "4\n0874\n", "6\n235689\n", "2\n10\n" ]
[ "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n" ]
1
stdio
Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins as others. All coins given to Ivan must be different. Not less tha...
[ "20 15 2 3\n", "10 11 2 4\n", "2 1 1 1\n", "10 2 9 7\n", "530897800469409942 582203276934671957 137373076313041391 377446491430894140\n", "1000000000000000000 1 1 1000000000000000000\n", "48295947839584738 12 49503958 47108947578469711\n", "100 20 98 2\n", "1000000000000000000 1000000000000000000 10...
[ "1", "-1", "2", "-1", "-1", "-1", "3925745635664473", "5", "-1", "1" ]
1
stdio
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, tripl...
[ "3\n", "6\n", "1\n", "17\n", "67\n", "10\n", "14\n", "22\n", "23\n", "246\n" ]
[ "4 5", "8 10", "-1", "144 145", "2244 2245", "24 26", "48 50", "120 122", "264 265", "15128 15130" ]
1
stdio
Imp is watching a documentary about cave painting. [Image] Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp. Imp ...
[ "4 4\n", "5 3\n", "1 1\n", "744 18\n", "47879 10\n", "1000000000000000000 1000000000000000000\n", "657180569218773599 42\n", "442762254977842799 30\n", "474158606260730555 1\n", "807873101233533988 39\n" ]
[ "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "No\n" ]
1
stdio
You have a set of items, each having some integer weight not greater than $8$. You denote that a subset of items is good if total weight of items in the subset does not exceed $W$. You want to calculate the maximum possible weight of a good subset of items. Note that you have to consider the empty set and the original...
[ "10\n1 2 3 4 5 6 7 8\n", "0\n0 0 0 0 0 0 0 0\n", "3\n0 4 1 0 0 9 8 3\n", "27\n0 0 0 0 0 5 0 0\n", "178\n731 0 0 0 0 0 0 0\n", "9890292762705840\n0 0 0 0 7807819738278974 0 0 0\n", "11994176272990019\n0 6395394930893349 0 0 0 0 0 0\n", "7517891175237043\n0 0 0 0 0 0 0 1985236500005094\n", "0\n0 10 0 ...
[ "10\n", "0\n", "3\n", "24\n", "178\n", "9890292762705840\n", "11994176272990018\n", "7517891175237040\n", "0\n", "10\n" ]
1
stdio
Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky since it can be divided into three segments $350$, $17$ and $8$: $...
[ "5\n73452\n", "4\n1248\n", "2\n00\n", "3\n555\n", "8\n00020200\n", "4\n7435\n", "99\n999999999999999999999999999999999999999999999918888888888888888888888888888888888888888888888888887\n", "5\n11980\n", "4\n2680\n", "15\n333703919182090\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n" ]
1
stdio
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n", "pezu\n", "wnemlgppy\n", "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn\n", "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx\n", "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswh...
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n", "IGNORE HIM!\n", "IGNORE HIM!\n", "IGNORE HIM!\n" ]
1
stdio
Today, Osama gave Fadi an integer $X$, and Fadi was wondering about the minimum possible value of $max(a, b)$ such that $LCM(a, b)$ equals $X$. Both $a$ and $b$ should be positive integers. $LCM(a, b)$ is the smallest positive integer that is divisible by both $a$ and $b$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = ...
[ "2\n", "6\n", "4\n", "1\n", "24\n", "200560490130\n", "999999999989\n", "1000000000000\n", "999966000289\n", "991921850317\n" ]
[ "1 2\n", "2 3\n", "1 4\n", "1 1\n", "8 3\n", "448630 447051\n", "1 999999999989\n", "4096 244140625\n", "1 999966000289\n", "1 991921850317\n" ]
1
stdio
Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers sh...
[ "2\n1 3 2 4\n", "1\n3 3\n", "5\n1 1 1 1 2 2 3 3 3 3\n", "5\n1 1 1 1 1 2 2 2 2 2\n", "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "1\n2 3\n", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
[ "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n" ]
1
stdio
You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 10^9 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two intege...
[ "3\n2 7 28\n", "1\n1\n", "1\n548\n", "1\n963837006\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "10\n26 723 970 13 422 968 875 329 234 983\n", "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\n", "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 ...
[ "1\n2 7 1 28\n", "0\n1\n", "0\n548\n", "0\n963837006\n", "0\n1 1 1 1 1 1 1 1 1 1\n", "2\n26 723 970 13 422 1 968 875 1 329 234 983\n", "7\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\n", "19\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 ...
1
stdio
We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): - Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element. Compute the maximum possible positiv...
[ "2 3\n8 20\n", "2 10\n3 5\n", "4 5\n10 1 2 22\n", "8 7\n1 7 5 6 8 2 6 5\n", "2 1\n1 1\n", "500 1000000000\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000...
[ "7\n", "8\n", "7\n", "5\n", "2\n", "500000000\n", "1699747\n", "6\n", "582198\n", "2\n" ]
1
stdio
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
[ "hi\nbob\n", "abca\naccepted\n", "abacaba\nabcdcba\n", "lo\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\n", "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\n", "npnkmawey\nareakefvowledfriyjejqnnaeqheoh\n", "fdtffutxkujflswyddvhusfcook\nkavkhnhphcvckogqqqqhdmgwjdfenzizr...
[ "-\n", "ac\n", "abcba\n", "-\n", "ouypvk\n", "a\n", "kvc\n", "aa\n", "d\n", "abc\n" ]
1
stdio
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n", "1zA__\n", "1zA_\n", "zA___\n", "1A___\n", "z1___\n", "0\n", "_\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n", "Correct\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n", "Too weak\n" ]
1
stdio
You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat s...
[ "12 5\n", "31 12\n", "1000000000000000000 7\n", "31960284556200 8515664064180\n", "1000000000000000000 1000000000000000000\n", "1 1000\n", "1 1000000\n", "1 1000000000000000\n", "1 99999999999999999\n", "1 4\n" ]
[ "0 1\n", "7 12\n", "8 7\n", "14928956427840 8515664064180\n", "1000000000000000000 1000000000000000000\n", "1 0\n", "1 0\n", "1 0\n", "1 1\n", "1 0\n" ]
1
stdio
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k. -----Input----- The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 10^18; - 10^18 ≤ a ≤ b ≤ 10^18). -----Output----- Prin...
[ "1 1 10\n", "2 -4 4\n", "1 1 1\n", "1 0 0\n", "1 0 1\n", "1 10181 10182\n", "1 10182 10183\n", "1 -191 1011\n", "2 0 0\n", "2 0 1\n" ]
[ "10\n", "5\n", "1\n", "1\n", "2\n", "2\n", "2\n", "1203\n", "1\n", "1\n" ]
1
stdio
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The fir...
[ "7\n", "21\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n" ]
[ "7\n", "5\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n", "9\n" ]
1
stdio
Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple...
[ "4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n", "0 0 0\n0 0 0\n", "0 0 0\n0 0 1\n", "0 1 0\n0 0 0\n", "1 0 0\n1 0 0\n", "2 2 1\n1 1 2\n", "1 3 1\n2 1 1\n", "1000000 1000000 1000000\n1000000 1000000 1000000\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n" ]
1
stdio
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't. First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that: Decim...
[ "1 2 1000\n", "2 2 1000\n", "5 3 1103\n", "2 17 10000\n", "3 9 10000\n", "6 64 941761822\n", "183 3 46847167\n", "472 44 364550669\n", "510 76 811693420\n", "783 30 602209107\n" ]
[ "4", "45", "590", "5", "252", "46530", "29891566", "122479316", "546301720", "279682329" ]
1
stdio
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be uniq...
[ "1 3\n", "3 2\n", "5 0\n", "4 2\n", "0 1000000\n", "1000000 1\n", "1083 724\n", "1184 868\n", "1285 877\n", "820189 548173\n" ]
[ "9\n", "8\n", "10\n", "9\n", "3000000\n", "2000000\n", "2710\n", "3078\n", "3243\n", "2052543\n" ]
1
stdio