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 number in range [1, a].
By $\operatorname{div}(x, y)$ we denote the quotient of integer division of x and y. By $\operatorname{mod}(x, y)$ we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (10^9 + 7). Can you compute it faster than Dreamoon?
-----Input-----
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 10^7).
-----Output-----
Print a single integer representing the answer modulo 1 000 000 007 (10^9 + 7).
-----Examples-----
Input
1 1
Output
0
Input
2 2
Output
8
-----Note-----
For the first sample, there are no nice integers because $\operatorname{mod}(x, 1)$ is always zero.
For the second sample, the set of nice integers is {3, 5}. | [
"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 the problem to show that it's not a NP problem.
-----Input-----
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 10^9).
-----Output-----
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
-----Examples-----
Input
19 29
Output
2
Input
3 6
Output
3
-----Note-----
Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | [
"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
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
-----Input-----
The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.
-----Output-----
Print a single integer — the number of subsequences "QAQ" in the string.
-----Examples-----
Input
QAQAQYSYIOIWIN
Output
4
Input
QAQQQZZYNOIWIN
Output
3
-----Note-----
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | [
"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 the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
-----Input-----
The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 10^5 digits.
-----Output-----
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
-----Examples-----
Input
101
Output
11
Input
110010
Output
11010
-----Note-----
In the first sample the best strategy is to delete the second digit. That results in number 11_2 = 3_10.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010_2 = 26_10. | [
"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 distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.
-----Input-----
The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the set.
-----Output-----
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
-----Examples-----
Input
2
2 3
Output
Alice
Input
2
5 3
Output
Alice
Input
3
5 6 7
Output
Bob
-----Note-----
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | [
"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 if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 10^5).
The second line contains n space-separated integers h_1, h_2, ..., h_{n} (1 ≤ h_{i} ≤ 10^9) — sizes of towers.
-----Output-----
Print the number of operations needed to destroy all towers.
-----Examples-----
Input
6
2 1 4 6 2 2
Output
3
Input
7
3 3 3 1 3 3 3
Output
2
-----Note-----
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. [Image] After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation. | [
"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 positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.
Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 10^9).
-----Output-----
In the first line print one integer k — number of different values of x satisfying the condition.
In next k lines print these values in ascending order.
-----Examples-----
Input
21
Output
1
15
Input
20
Output
0
-----Note-----
In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such x. | [
"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 the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
-----Input-----
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
-----Output-----
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
-----Examples-----
Input
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
-----Note-----
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s_1 = t_1, s_2 = t_2, ..., s_{i} - 1 = t_{i} - 1, and s_{i} < t_{i}. | [
"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).
[Image]
Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.
-----Input-----
The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers a_{i} — the quantity of beads of i-th color. It is guaranteed that the sum of a_{i} is at least 2 and does not exceed 100 000.
-----Output-----
In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.
Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.
-----Examples-----
Input
3
4 2 1
Output
1
abacaba
Input
1
4
Output
4
aaaa
Input
2
1 1
Output
0
ab
-----Note-----
In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.
In the second sample there is only one way to compose a necklace. | [
"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 columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.
Let's enumerate students from 1 to n·m in order of rows. So a student who initially sits in the cell in row i and column j has a number (i - 1)·m + j. You have to find a matrix with n rows and m columns in which all numbers from 1 to n·m appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.
-----Input-----
The only line contains two integers n and m (1 ≤ n, m ≤ 10^5; n·m ≤ 10^5) — the number of rows and the number of columns in the required matrix.
-----Output-----
If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next n lines output m integers which form the required matrix.
-----Examples-----
Input
2 4
Output
YES
5 4 7 2
3 6 1 8
Input
2 1
Output
NO
-----Note-----
In the first test case the matrix initially looks like this:
1 2 3 4
5 6 7 8
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | [
"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 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
-----Input-----
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 10^6.
-----Output-----
Print the minimum number of steps modulo 10^9 + 7.
-----Examples-----
Input
ab
Output
1
Input
aab
Output
3
-----Note-----
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | [
"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 operations. You are allowed to change elements in any way, they can become negative or equal to 0.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.
Next line contains n integer a_{i} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
Print the minimum number of operation required to make the array strictly increasing.
-----Examples-----
Input
7
2 1 5 11 5 9 11
Output
9
Input
5
5 4 3 2 1
Output
12
-----Note-----
In the first sample, the array is going to look as follows:
2 3 5 6 7 9 11
|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9
And for the second sample:
1 2 3 4 5
|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12 | [
"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 can be proven that it is always possible to make all elements of $a$ equal to zero.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 100\,000$): the number of elements of the array.
The second line contains $n$ elements of an array $a$ separated by spaces: $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
The output should contain six lines representing three operations.
For each operation, print two lines:
The first line contains two integers $l$, $r$ ($1 \le l \le r \le n$): the bounds of the selected segment.
The second line contains $r-l+1$ integers $b_l, b_{l+1}, \dots, b_r$ ($-10^{18} \le b_i \le 10^{18}$): the numbers to add to $a_l, a_{l+1}, \ldots, a_r$, respectively; $b_i$ should be divisible by $r - l + 1$.
-----Example-----
Input
4
1 3 2 4
Output
1 1
-1
3 4
4 2
2 4
-3 -6 -6 | [
"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 Little X divide the numbers into two sets or determine that it's impossible.
-----Input-----
The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 10^5; 1 ≤ a, b ≤ 10^9). The next line contains n space-separated distinct integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ 10^9).
-----Output-----
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b_1, b_2, ..., b_{n} (b_{i} equals either 0, or 1), describing the division. If b_{i} equals to 0, then p_{i} belongs to set A, otherwise it belongs to set B.
If it's impossible, print "NO" (without the quotes).
-----Examples-----
Input
4 5 9
2 3 4 5
Output
YES
0 0 1 1
Input
3 3 4
1 2 4
Output
NO
-----Note-----
It's OK if all the numbers are in the same set, and the other one is empty. | [
"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 the number of segments of a given array such that there are exactly $k$ numbers of this segment which are less than $x$.
Nikita wants to get answer for this question for each $k$ from $0$ to $n$, where $n$ is the size of the array.
-----Input-----
The first line contains two integers $n$ and $x$ $(1 \le n \le 2 \cdot 10^5, -10^9 \le x \le 10^9)$.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(-10^9 \le a_i \le 10^9)$ — the given array.
-----Output-----
Print $n+1$ integers, where the $i$-th number is the answer for Nikita's question for $k=i-1$.
-----Examples-----
Input
5 3
1 2 3 4 5
Output
6 5 4 0 0 0
Input
2 6
-5 9
Output
1 2 0
Input
6 99
-1 -1 -1 -1 -1 -1
Output
0 6 5 4 3 2 1 | [
"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 to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.
-----Input-----
The first line contains a single integer $n$ ($1 \leqslant n \leqslant 10^5$) — the length of the string. The second line contains a string consisting of English lowercase letters: 'z', 'e', 'r', 'o' and 'n'.
It is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either "zero" which corresponds to the digit $0$ or "one" which corresponds to the digit $1$.
-----Output-----
Print the maximum possible number in binary notation. Print binary digits separated by a space. The leading zeroes are allowed.
-----Examples-----
Input
4
ezor
Output
0
Input
10
nznooeeoer
Output
1 1 0
-----Note-----
In the first example, the correct initial ordering is "zero".
In the second example, the correct initial ordering is "oneonezero". | [
"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_{n} - 1 - p_{n}| has exactly k distinct elements.
-----Input-----
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 10^5).
-----Output-----
Print n integers forming the permutation. If there are multiple answers, print any of them.
-----Examples-----
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
-----Note-----
By |x| we denote the absolute value of number x. | [
"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 points doesn't matter.
-----Input-----
The first line contains two integers: n and d (1 ≤ n ≤ 10^5; 1 ≤ d ≤ 10^9). The next line contains n integers x_1, x_2, ..., x_{n}, their absolute value doesn't exceed 10^9 — the x-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input strictly increase.
-----Output-----
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
-----Examples-----
Input
4 3
1 2 3 4
Output
4
Input
4 2
-3 -2 -1 0
Output
2
Input
5 19
1 10 20 30 50
Output
1
-----Note-----
In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | [
"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 size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.
Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.
-----Input-----
The first line of input contains integer n (1 ≤ n ≤ 2 × 10^5), the number of bears.
The second line contains n integers separated by space, a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), heights of bears.
-----Output-----
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
-----Examples-----
Input
10
1 2 3 4 5 4 3 2 1 6
Output
6 4 4 3 3 2 2 1 1 1 | [
"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 + 1 for all i from 1 to k - 1. Now he wonders how many different ways this can happen.
-----Input-----
The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain c_{i}, the number of balls of the i-th color (1 ≤ c_{i} ≤ 1000).
The total number of balls doesn't exceed 1000.
-----Output-----
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.
-----Examples-----
Input
3
2
2
1
Output
3
Input
4
1
2
3
4
Output
1680
-----Note-----
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
1 2 1 2 3
1 1 2 2 3
2 1 1 2 3 | [
"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 it such that each of them contains string t as a substring? More formally, you need to calculate the number of ways to choose two sequences a_1, a_2, ..., a_{k} and b_1, b_2, ..., b_{k} satisfying the following requirements:
k ≥ 1 $\forall i(1 \leq i \leq k) 1 \leq a_{i}, b_{i} \leq|s|$ $\forall i(1 \leq i \leq k) b_{i} \geq a_{i}$ $\forall i(2 \leq i \leq k) a_{i} > b_{i - 1}$ $\forall i(1 \leq i \leq k)$ t is a substring of string s_{a}_{i}s_{a}_{i} + 1... s_{b}_{i} (string s is considered as 1-indexed).
As the number of ways can be rather large print it modulo 10^9 + 7.
-----Input-----
Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 10^5). Each string consists of lowercase Latin letters.
-----Output-----
Print the answer in a single line.
-----Examples-----
Input
ababa
aba
Output
5
Input
welcometoroundtwohundredandeightytwo
d
Output
274201
Input
ddd
d
Output
12 | [
"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 a fraction has zero numerals after the decimal point.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$.
-----Output-----
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
-----Examples-----
Input
2
6 12 10
4 3 10
Output
Finite
Infinite
Input
4
1 1 2
9 36 2
4 12 3
3 5 4
Output
Finite
Finite
Finite
Infinite
-----Note-----
$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | [
"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 in that graph.
-----Input-----
In the first line of input there are two integers $n$ and $m$ ($0 \le n \le 22$, $1 \le m \le 2^{n}$).
In the second line there are $m$ integers $a_1, a_2, \ldots, a_m$ ($0 \le a_{i} < 2^{n}$) — the elements of the set. All $a_{i}$ are distinct.
-----Output-----
Print the number of connected components.
-----Examples-----
Input
2 3
1 2 3
Output
2
Input
5 5
5 19 10 20 12
Output
2
-----Note-----
Graph from first sample:
$0$
Graph from second sample:
[Image] | [
"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 Moon. Will you?
-----Input-----
The only line contains single integer n (3 ≤ n ≤ 300).
-----Output-----
If there is no answer, print -1.
Otherwise, in the first line print k (1 ≤ k ≤ n^2) — the number of cycles in your solution.
In each of the next k lines print description of one cycle in the following format: first print integer m (3 ≤ m ≤ 4) — the length of the cycle, then print m integers v_1, v_2, ..., v_{m} (1 ≤ v_{i} ≤ n) — the vertices in the cycle in the traverse order. Each edge should be in exactly two cycles.
-----Examples-----
Input
3
Output
2
3 1 2 3
3 1 2 3
Input
5
Output
6
3 5 4 2
3 3 1 5
4 4 5 2 3
4 4 3 2 1
3 4 2 1
3 3 1 5 | [
"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 wants to know the minimum number of days he should wait before sending a ranger to collect the orbs such that the probability of him getting at least one of each kind of orb is at least $\frac{p_{i} - \epsilon}{2000}$, where ε < 10^{ - 7}.
To better prepare himself, he wants to know the answer for q different values of p_{i}. Since he is busy designing the battle strategy with Sam, he asks you for your help.
-----Input-----
First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively.
Each of the next q lines contain a single integer p_{i} (1 ≤ p_{i} ≤ 1000) — i-th query.
-----Output-----
Output q lines. On i-th of them output single integer — answer for i-th query.
-----Examples-----
Input
1 1
1
Output
1
Input
2 2
1
2
Output
2
2 | [
"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, ..., n - 1].
-----Input-----
The only input line contains an integer n (1 ≤ n ≤ 10^5).
-----Output-----
In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output n more lines. i-th line contains only an integer a_{i}. The elements of the sequence should be different positive integers no larger than n.
If there are multiple solutions, you are allowed to print any of them.
-----Examples-----
Input
7
Output
YES
1
4
3
6
5
2
7
Input
6
Output
NO
-----Note-----
For the second sample, there are no valid sequences. | [
"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 \le 10^9$, $0 \le k \le p-1$). $p$ is guaranteed to be prime.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le p-1$). It is guaranteed that all elements are different.
-----Output-----
Output a single integer — answer to the problem.
-----Examples-----
Input
3 3 0
0 1 2
Output
1
Input
6 7 2
1 2 3 4 5 6
Output
3
-----Note-----
In the first example:
$(0+1)(0^2 + 1^2) = 1 \equiv 1 \bmod 3$.
$(0+2)(0^2 + 2^2) = 8 \equiv 2 \bmod 3$.
$(1+2)(1^2 + 2^2) = 15 \equiv 0 \bmod 3$.
So only $1$ pair satisfies the condition.
In the second example, there are $3$ such pairs: $(1, 5)$, $(2, 3)$, $(4, 6)$. | [
"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 input contains integer n (2 ≤ n ≤ 10^9).
-----Output-----
Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.
-----Examples-----
Input
2
2
3
Output
1/6
7/30 | [
"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 than 1. Of course, each apple can be part of at most one group.
Jzzhu wonders how to get the maximum possible number of groups. Can you help him?
-----Input-----
A single integer n (1 ≤ n ≤ 10^5), the number of the apples.
-----Output-----
The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.
If there are several optimal answers you can print any of them.
-----Examples-----
Input
6
Output
2
6 3
2 4
Input
9
Output
3
9 3
2 4
6 8
Input
2
Output
0 | [
"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 line contains n space-separated integers a_{i} (1 ≤ a_{i} ≤ 10^6).
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
3
3 4 5
Output
2 | [
"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 of two strings S and T is the longest string C such that C both in S and T as a subsequence.
-----Input-----
The first line contains two numbers n and m denoting the length of string S and number of first English lowercase characters forming the character set for strings (1 ≤ n ≤ 100 000, 2 ≤ m ≤ 26).
The second line contains string S.
-----Output-----
Print the only line containing the answer.
-----Examples-----
Input
3 3
aaa
Output
6
Input
3 3
aab
Output
11
Input
1 2
a
Output
1
Input
10 9
abacadefgh
Output
789
-----Note-----
For the first sample, the 6 possible strings T are: aab, aac, aba, aca, baa, caa.
For the second sample, the 11 possible strings T are: aaa, aac, aba, abb, abc, aca, acb, baa, bab, caa, cab.
For the third sample, the only possible string T is b. | [
"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 a and b, that is, the number of i such that a_i \neq b_i, by performing some of the Q operations.
-----Constraints-----
- 1 \leq N \leq 200,000
- b consists of 0 and 1.
- 1 \leq Q \leq 200,000
- 1 \leq l_i \leq r_i \leq N
- If i \neq j, either l_i \neq l_j or r_i \neq r_j.
-----Input-----
Input is given from Standard Input in the following format:
N
b_1 b_2 ... b_N
Q
l_1 r_1
l_2 r_2
:
l_Q r_Q
-----Output-----
Print the minimum possible hamming distance.
-----Sample Input-----
3
1 0 1
1
1 3
-----Sample Output-----
1
If you choose to perform the operation, a will become \{1, 1, 1\}, for a hamming distance of 1. | [
"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 $\oplus$ denotes the bitwise XOR operation.
You are given three integers $a$, $b$, and $n$, calculate $f(n)$.
You have to answer for $T$ independent test cases.
-----Input-----
The input contains one or more independent test cases.
The first line of input contains a single integer $T$ ($1 \le T \le 10^3$), the number of test cases.
Each of the $T$ following lines contains three space-separated integers $a$, $b$, and $n$ ($0 \le a, b, n \le 10^9$) respectively.
-----Output-----
For each test case, output $f(n)$.
-----Example-----
Input
3
3 4 2
4 5 0
325 265 1231232
Output
7
4
76
-----Note-----
In the first example, $f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$. | [
"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 the citizens are happy about road improvement if the path from the capital located in city x to any other city contains at most one bad road.
Your task is — for every possible x determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1 000 000 007 (10^9 + 7).
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 2·10^5) — the number of cities in the country. Next line contains n - 1 positive integers p_2, p_3, p_4, ..., p_{n} (1 ≤ p_{i} ≤ i - 1) — the description of the roads in the country. Number p_{i} means that the country has a road connecting city p_{i} and city i.
-----Output-----
Print n integers a_1, a_2, ..., a_{n}, where a_{i} is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (10^9 + 7), if the capital of the country is at city number i.
-----Examples-----
Input
3
1 1
Output
4 3 3
Input
5
1 2 3 4
Output
5 8 9 8 5 | [
"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 two distinct strings in S are prefix-free.
We have a good string set S = \{ s_1, s_2, ..., s_N \}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:
- Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.
-----Constraints-----
- 1 \leq N \leq 10^5
- 1 \leq L \leq 10^{18}
- s_1, s_2, ..., s_N are all distinct.
- { s_1, s_2, ..., s_N } is a good string set.
- |s_1| + |s_2| + ... + |s_N| \leq 10^5
-----Input-----
Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N
-----Output-----
If Alice will win, print Alice; if Bob will win, print Bob.
-----Sample Input-----
2 2
00
01
-----Sample Output-----
Alice
If Alice adds 1, Bob will be unable to add a new string. | [
"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 regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
You are given a regular bracket sequence $s$ and an integer number $k$. Your task is to find a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
It is guaranteed that such sequence always exists.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \le k \le n \le 2 \cdot 10^5$, both $n$ and $k$ are even) — the length of $s$ and the length of the sequence you are asked to find.
The second line is a string $s$ — regular bracket sequence of length $n$.
-----Output-----
Print a single string — a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
It is guaranteed that such sequence always exists.
-----Examples-----
Input
6 4
()(())
Output
()()
Input
8 8
(()(()))
Output
(()(())) | [
"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,3,4,5,6,7\}}$ have: $P(2)=m$?
Help Jerry Mao solve the long standing problem!
-----Input-----
The first line contains a single integer $t$ $(1 \leq t \leq 5\cdot 10^5)$ - number of test cases.
On next line there are $t$ numbers, $m_i$ $(1 \leq m_i \leq 10^{18})$ - meaning that in case $i$ you should solve for number $m_i$.
-----Output-----
For each test case $i$, print the answer on separate lines: number of polynomials $P$ as described in statement such that $P(2)=m_i$, modulo $10^9 + 7$.
-----Example-----
Input
2
2 4
Output
2
4
-----Note-----
In first case, for $m=2$, polynomials that satisfy the constraint are $x$ and $2$.
In second case, for $m=4$, polynomials that satisfy the constraint are $x^2$, $x + 2$, $2x$ and $4$. | [
"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 such numbers find the smallest of them.
-----Input-----
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers l_{i}, r_{i} — the arguments for the corresponding query (0 ≤ l_{i} ≤ r_{i} ≤ 10^18).
-----Output-----
For each query print the answer in a separate line.
-----Examples-----
Input
3
1 2
2 4
1 10
Output
1
3
7
-----Note-----
The binary representations of numbers from 1 to 10 are listed below:
1_10 = 1_2
2_10 = 10_2
3_10 = 11_2
4_10 = 100_2
5_10 = 101_2
6_10 = 110_2
7_10 = 111_2
8_10 = 1000_2
9_10 = 1001_2
10_10 = 1010_2 | [
"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 horizontally so that all the rectangles are connected.
For each rectangle, the cost to move it horizontally by a distance of x, is x.
Find the minimum cost to achieve connectivity.
It can be proved that this value is always an integer under the constraints of the problem.
-----Constraints-----
- All input values are integers.
- 1≤N≤10^5
- 1≤l_i<r_i≤10^9
-----Partial Score-----
- 300 points will be awarded for passing the test set satisfying 1≤N≤400 and 1≤l_i<r_i≤400.
-----Input-----
The input is given from Standard Input in the following format:
N
l_1 r_1
l_2 r_2
:
l_N r_N
-----Output-----
Print the minimum cost to achieve connectivity.
-----Sample Input-----
3
1 3
5 7
1 3
-----Sample Output-----
2
The second rectangle should be moved to the left by a distance of 2. | [
"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 triangle if $a + b > c$, $b + c > a$ and $c + a > b$.
In a group of numbers, a number is lonely if it doesn't have any friends in that group.
Given a group of numbers containing all numbers from $1, 2, 3, ..., n$, how many numbers in that group are lonely?
-----Input-----
The first line contains a single integer $t$ $(1 \leq t \leq 10^6)$ - number of test cases.
On next line there are $t$ numbers, $n_i$ $(1 \leq n_i \leq 10^6)$ - meaning that in case $i$ you should solve for numbers $1, 2, 3, ..., n_i$.
-----Output-----
For each test case, print the answer on separate lines: number of lonely numbers in group $1, 2, 3, ..., n_i$.
-----Example-----
Input
3
1 5 10
Output
1
3
3
-----Note-----
For first test case, $1$ is the only number and therefore lonely.
For second test case where $n=5$, numbers $1$, $3$ and $5$ are lonely.
For third test case where $n=10$, numbers $1$, $5$ and $7$ are lonely. | [
"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}}$
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.
The second line contains n space-separated distinct integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
If there is no such array b, print -1.
Otherwise in the only line print n space-separated integers b_1, b_2, ..., b_{n}. Note that b must be a permutation of a.
If there are multiple answers, print any of them.
-----Examples-----
Input
2
1 2
Output
2 1
Input
4
1000 100 10 1
Output
100 1 1000 10
-----Note-----
An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.
Note that the empty subset and the subset containing all indices are not counted. | [
"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, respectively.
The barriers may overlap or contain each other.
A point on the plane is exposed to cosmic rays if the point is not within any of the barriers.
Snuke wants to avoid exposure to cosmic rays as much as possible during the travel.
Find the minimum possible duration of time he is exposed to cosmic rays during the travel.
-----Constraints-----
- All input values are integers.
- -10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9
- (x_s, y_s) ≠ (x_t, y_t)
- 1≤N≤1,000
- -10^9 ≤ x_i, y_i ≤ 10^9
- 1 ≤ r_i ≤ 10^9
-----Input-----
The input is given from Standard Input in the following format:
x_s y_s x_t y_t
N
x_1 y_1 r_1
x_2 y_2 r_2
:
x_N y_N r_N
-----Output-----
Print the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.
The output is considered correct if the absolute or relative error is at most 10^{-9}.
-----Sample Input-----
-2 -2 2 2
1
0 0 1
-----Sample Output-----
3.6568542495
An optimal route is as follows: | [
"-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-----
- 1 \leq N, K \leq 100
- 10^8 \leq M \leq 10^9 + 9
- M is prime.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K M
-----Output-----
Use the following format:
c_1
c_2
:
c_N
Here, c_x should be the number, modulo M, of multisets such that the average of the elements is x.
-----Sample Input-----
3 1 998244353
-----Sample Output-----
1
3
1
Consider non-empty multisets containing between 0 and 1 instance(s) of each of the integers between 1 and 3. Among them, there are:
- one multiset such that the average of the elements is k = 1: \{1\};
- three multisets such that the average of the elements is k = 2: \{2\}, \{1, 3\}, \{1, 2, 3\};
- one multiset such that the average of the elements is k = 3: \{3\}. | [
"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, and a closing bracket (ASCII code $093$). The length of the accordion is the number of characters in it.
For example, [::], [:||:] and [:|||:] are accordions having length $4$, $6$ and $7$. (:|:), {:||:}, [:], ]:||:[ are not accordions.
You are given a string $s$. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from $s$, and if so, what is the maximum possible length of the result?
-----Input-----
The only line contains one string $s$ ($1 \le |s| \le 500000$). It consists of lowercase Latin letters and characters [, ], : and |.
-----Output-----
If it is not possible to obtain an accordion by removing some characters from $s$, print $-1$. Otherwise print maximum possible length of the resulting accordion.
-----Examples-----
Input
|[a:b:|]
Output
4
Input
|]:[|:]
Output
-1 | [
"|[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 integer x (1 ≤ x ≤ 10^18) — the integer which Anton has.
-----Output-----
Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
-----Examples-----
Input
100
Output
99
Input
48
Output
48
Input
521
Output
499 | [
"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 will residents of Berland wait till the next lucky year.
-----Input-----
The first line contains integer number n (1 ≤ n ≤ 10^9) — current year in Berland.
-----Output-----
Output amount of years from the current year to the next lucky one.
-----Examples-----
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
-----Note-----
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | [
"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 contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.
-----Output-----
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
-----Examples-----
Input
14
Output
4 4
Input
2
Output
0 2
-----Note-----
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | [
"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 is, there exists a positive integer i, such that s_{i} = b. Of course, you are the person he asks for a help.
-----Input-----
The first line of the input contain three integers a, b and c ( - 10^9 ≤ a, b, c ≤ 10^9) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
-----Output-----
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
-----Examples-----
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
-----Note-----
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | [
"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 character.
Petya wants to get strings s and t empty and string u lexicographically minimal.
You should write a program that will help Petya win the game.
-----Input-----
First line contains non-empty string s (1 ≤ |s| ≤ 10^5), consisting of lowercase English letters.
-----Output-----
Print resulting string u.
-----Examples-----
Input
cab
Output
abc
Input
acdb
Output
abdc | [
"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 is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
-----Input-----
The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
-----Output-----
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
-----Examples-----
Input
05:39
Output
11
Input
13:31
Output
0
Input
23:59
Output
1
-----Note-----
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome. | [
"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 a string s. Check if the string is "s-palindrome".
-----Input-----
The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.
-----Output-----
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
-----Examples-----
Input
oXoxoXo
Output
TAK
Input
bod
Output
TAK
Input
ER
Output
NIE | [
"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 line contains integer b (1 ≤ b ≤ 10^18). Numbers don't have leading zeroes. It is guaranteed that answer exists.
-----Output-----
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
-----Examples-----
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940 | [
"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 greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
-----Input-----
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10^6).
-----Output-----
If the answer exists then output resulting matrix. Otherwise output -1.
-----Examples-----
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1 | [
"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·10^9, L ≤ R).
-----Output-----
Print the desired number of integers x.
-----Examples-----
Input
2 0 3 3 5 21
Output
3
Input
2 4 3 0 6 17
Output
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 color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
-----Input-----
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
-----Output-----
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
-----Examples-----
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
-----Note-----
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | [
"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 (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.
-----Input-----
The only line of the input contains integer n (0 ≤ n ≤ 10^18) — the number of Ayrat's moves.
-----Output-----
Print two integers x and y — current coordinates of Ayrat coordinates.
-----Examples-----
Input
3
Output
-2 0
Input
7
Output
3 2 | [
"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 damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.
-----Input-----
The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
-----Output-----
Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise.
-----Examples-----
Input
4 6 15
Output
No
Input
3 2 7
Output
Yes
Input
6 11 6
Output
Yes
-----Note-----
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | [
"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 and π. For example, opposite directions vectors have angle equals to π.
-----Input-----
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers x_{i} and y_{i} (|x|, |y| ≤ 10 000, x^2 + y^2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
-----Output-----
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
-----Examples-----
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5 | [
"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 them.
If there is no possible sequence then output -1.
-----Input-----
The first line consists of two numbers n and k (1 ≤ n, k ≤ 10^10).
-----Output-----
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
-----Examples-----
Input
6 3
Output
1 2 3
Input
8 2
Output
2 6
Input
5 3
Output
-1 | [
"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 columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.
-----Input-----
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m).
-----Output-----
Print the k-th largest number in a n × m multiplication table.
-----Examples-----
Input
2 2 2
Output
2
Input
2 3 4
Output
3
Input
1 10 5
Output
5
-----Note-----
A 2 × 3 multiplication table looks like this:
1 2 3
2 4 6 | [
"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 first and only line contains integer $k$ ($1 \le k \le 10^{12}$) — the position to process ($1$-based index).
-----Output-----
Print the $k$-th digit of the resulting infinite sequence.
-----Examples-----
Input
7
Output
7
Input
21
Output
5 | [
"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}, and the beauty of t as the sum of b_{i} among all indices i such that s_{i} = t_{i}.
Help Ivan to determine maximum possible beauty of t he can get.
-----Input-----
The first line contains one integer n (2 ≤ n ≤ 100, n is even) — the number of characters in s.
The second line contains the string s itself. It consists of only lowercase Latin letters, and it is guaranteed that its letters can be reordered to form an antipalindromic string.
The third line contains n integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 100), where b_{i} is the beauty of index i.
-----Output-----
Print one number — the maximum possible beauty of t.
-----Examples-----
Input
8
abacabac
1 1 1 1 1 1 1 1
Output
8
Input
8
abaccaba
1 2 3 4 5 6 7 8
Output
26
Input
8
abacabca
1 2 3 4 4 3 2 1
Output
17 | [
"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 speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
-----Input-----
The first line contains two integers w, m (2 ≤ w ≤ 10^9, 1 ≤ m ≤ 10^9) — the number defining the masses of the weights and the mass of the item.
-----Output-----
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
-----Examples-----
Input
3 7
Output
YES
Input
100 99
Output
YES
Input
100 50
Output
NO
-----Note-----
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input. | [
"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 pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers x_{i} and y_{i} ( - 1000 ≤ x_{i}, y_{i} ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
-----Output-----
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
-----Examples-----
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
-----Note-----
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | [
"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 number of times you swap i-th element with (i + 1)-th (if the position is not forbidden).
Can you make this array sorted in ascending order performing some sequence of swapping operations?
-----Input-----
The first line contains one integer n (2 ≤ n ≤ 200000) — the number of elements in the array.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 200000) — the elements of the array. Each integer from 1 to n appears exactly once.
The third line contains a string of n - 1 characters, each character is either 0 or 1. If i-th character is 1, then you can swap i-th element with (i + 1)-th any number of times, otherwise it is forbidden to swap i-th element with (i + 1)-th.
-----Output-----
If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO.
-----Examples-----
Input
6
1 2 5 3 4 6
01110
Output
YES
Input
6
1 2 5 3 4 6
01010
Output
NO
-----Note-----
In the first example you may swap a_3 and a_4, and then swap a_4 and a_5. | [
"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 baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
-----Output-----
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
-----Note-----
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | [
"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 line contains n integers a_0, a_1, ..., a_{n} - 1 (1 ≤ a_{i} ≤ 10^9) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
-----Output-----
Print the only number — distance between two nearest minimums in the array.
-----Examples-----
Input
2
3 3
Output
1
Input
3
5 6 5
Output
2
Input
9
2 1 3 5 4 1 2 3 1
Output
3 | [
"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_{i} is a prime
$\sum_{i = 1}^{k} p_{i} = n$
The numbers p_{i} do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
-----Input-----
The single line contains an odd number n (3 ≤ n < 10^9).
-----Output-----
In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.
In the second line print numbers p_{i} in any order. If there are multiple possible solutions, you can print any of them.
-----Examples-----
Input
27
Output
3
5 11 11
-----Note-----
A prime is an integer strictly larger than one that is divisible only by one and by itself. | [
"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 y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
-----Input-----
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.
The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
-----Output-----
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
-----Examples-----
Input
3 4
.*..
....
.*..
Output
YES
1 2
Input
3 3
..*
.*.
*..
Output
NO
Input
6 5
..*..
..*..
*****
..*..
..*..
..*..
Output
YES
3 3 | [
"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$, he needs to choose the smallest one.
Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?
-----Input-----
The only line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
Print the smallest non-negative integer $k$ ($k \ge 0$) such that the lowest common multiple of $a+k$ and $b+k$ is the smallest possible.
If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one.
-----Examples-----
Input
6 10
Output
2
Input
21 31
Output
9
Input
5 10
Output
0
-----Note-----
In the first test, one should choose $k = 2$, as the least common multiple of $6 + 2$ and $10 + 2$ is $24$, which is the smallest least common multiple possible. | [
"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 space-separated integers a, b and c (1 ≤ a, b, c ≤ 100).
-----Output-----
Print a single integer — the required sum modulo 1073741824 (2^30).
-----Examples-----
Input
2 2 2
Output
20
Input
5 6 7
Output
1520
-----Note-----
For the first example.
d(1·1·1) = d(1) = 1; d(1·1·2) = d(2) = 2; d(1·2·1) = d(2) = 2; d(1·2·2) = d(4) = 3; d(2·1·1) = d(2) = 2; d(2·1·2) = d(4) = 3; d(2·2·1) = d(4) = 3; d(2·2·2) = d(8) = 4.
So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20. | [
"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.
Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?
-----Input-----
The first line contains two space-separated numbers a_1 and b_1 — the sides of the board. Next two lines contain numbers a_2, b_2, a_3 and b_3 — the sides of the paintings. All numbers a_{i}, b_{i} in the input are integers and fit into the range from 1 to 1000.
-----Output-----
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
-----Examples-----
Input
3 2
1 3
2 1
Output
YES
Input
5 5
3 3
3 3
Output
NO
Input
4 2
2 3
1 2
Output
YES
-----Note-----
That's how we can place the pictures in the first test:
[Image]
And that's how we can do it in the third one.
[Image] | [
"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 mix without water again, so right now he's really messed up and can't think.
Your task is to help him by telling him what to type.
-----Input-----
The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.
-----Output-----
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
-----Examples-----
Input
6
Output
six
Input
99
Output
ninety-nine
Input
20
Output
twenty
-----Note-----
You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals . | [
"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, divisible by 64, in the binary numerical system.
-----Input-----
In the only line given a non-empty binary string s with length up to 100.
-----Output-----
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
-----Examples-----
Input
100010001
Output
yes
Input
100
Output
no
-----Note-----
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system | [
"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 moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
-----Input-----
The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 10^5) small english letters.
-----Output-----
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
-----Examples-----
Input
aacceeggiikkmmooqqssuuwwyy
Output
abcdefghijklmnopqrstuvwxyz
Input
thereisnoanswer
Output
-1 | [
"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 than k divisors, output -1.
Otherwise, output the k-th smallest divisor of n.
-----Examples-----
Input
4 2
Output
2
Input
5 3
Output
-1
Input
12 5
Output
6
-----Note-----
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | [
"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. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
-----Input-----
In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.
Each of next n lines contains 6 integers a_{i}_{j} (0 ≤ a_{i}_{j} ≤ 9) — number on j-th face of i-th cube.
-----Output-----
Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.
-----Examples-----
Input
3
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7
Output
87
Input
3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
Output
98
-----Note-----
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | [
"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 that will perform the k-rounding of n.
-----Input-----
The only line contains two integers n and k (1 ≤ n ≤ 10^9, 0 ≤ k ≤ 8).
-----Output-----
Print the k-rounding of n.
-----Examples-----
Input
375 4
Output
30000
Input
10000 1
Output
10000
Input
38101 0
Output
38101
Input
123456789 8
Output
12345678900000000 | [
"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, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
-----Input-----
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
-----Output-----
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10^{ - 9}.
-----Examples-----
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714 | [
"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 visit Sonya from minute l_2 to minute r_2 inclusive.
Calculate the number of minutes they will be able to spend together.
-----Input-----
The only line of the input contains integers l_1, r_1, l_2, r_2 and k (1 ≤ l_1, r_1, l_2, r_2, k ≤ 10^18, l_1 ≤ r_1, l_2 ≤ r_2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
-----Output-----
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
-----Examples-----
Input
1 10 9 20 1
Output
2
Input
1 100 50 200 75
Output
50
-----Note-----
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | [
"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 before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a_1, a_2... a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
-----Examples-----
Input
3
1 3 2
Output
YES
Input
5
1 2 3 4 5
Output
NO
Input
5
2 2 3 4 5
Output
YES
-----Note-----
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [
"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 contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image]
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
-----Input-----
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
-----Output-----
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
-----Examples-----
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
-----Note-----
You can find the picture clarifying the first sample case in the statement above. | [
"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 than $L$ coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
-----Input-----
The only line of input contains 4 integers $N$, $M$, $K$, $L$ ($1 \le K \le N \le 10^{18}$; $1 \le M, \,\, L \le 10^{18}$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
-----Output-----
Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
-----Examples-----
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
-----Note-----
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | [
"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, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
-----Input-----
The only line of the input contains single integer n (1 ≤ n ≤ 10^9) — the length of some side of a right triangle.
-----Output-----
Print two integers m and k (1 ≤ m, k ≤ 10^18), such that n, m and k form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer n, print - 1 in the only line. If there are many answers, print any of them.
-----Examples-----
Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245
-----Note-----[Image]
Illustration for the first sample. | [
"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 wants you to check whether all these remainders are distinct. Formally, he wants to check, if all $n \text{mod} i$, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 1 ≤ i < j ≤ k, $n \operatorname{mod} i = n \operatorname{mod} j$, where $x \operatorname{mod} y$ is the remainder of division x by y.
-----Input-----
The only line contains two integers n, k (1 ≤ n, k ≤ 10^18).
-----Output-----
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
-----Examples-----
Input
4 4
Output
No
Input
5 3
Output
Yes
-----Note-----
In the first sample remainders modulo 1 and 4 coincide. | [
"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 set when calculating the answer.
-----Input-----
The first line contains one integer $W$ ($0 \le W \le 10^{18}$) — the maximum total weight of a good subset.
The second line denotes the set of items you have. It contains $8$ integers $cnt_1$, $cnt_2$, ..., $cnt_8$ ($0 \le cnt_i \le 10^{16}$), where $cnt_i$ is the number of items having weight $i$ in the set.
-----Output-----
Print one integer — the maximum possible weight of a good subset of items.
-----Examples-----
Input
10
1 2 3 4 5 6 7 8
Output
10
Input
0
0 0 0 0 0 0 0 0
Output
0
Input
3
0 4 1 0 0 9 8 3
Output
3 | [
"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$: $3+5+0=1+7=8$. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 100$) — the number of digits in the ticket.
The second line contains $n$ digits $a_1 a_2 \dots a_n$ ($0 \le a_i \le 9$) — the golden ticket. Digits are printed without spaces.
-----Output-----
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
-----Examples-----
Input
5
73452
Output
YES
Input
4
1248
Output
NO
-----Note-----
In the first example the ticket can be divided into $7$, $34$ and $52$: $7=3+4=5+2$.
In the second example it is impossible to divide ticket into segments with equal sum. | [
"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.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
-----Input-----
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
-----Output-----
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
-----Examples-----
Input
wjmzbmr
Output
CHAT WITH HER!
Input
xiaodao
Output
IGNORE HIM!
Input
sevenkplus
Output
CHAT WITH HER!
-----Note-----
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | [
"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) = 12$, $LCM(2, 3) = 6$.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
-----Input-----
The first and only line contains an integer $X$ ($1 \le X \le 10^{12}$).
-----Output-----
Print two positive integers, $a$ and $b$, such that the value of $max(a, b)$ is minimum possible and $LCM(a, b)$ equals $X$. If there are several possible such pairs, you can print any.
-----Examples-----
Input
2
Output
1 2
Input
6
Output
2 3
Input
4
Output
1 4
Input
1
Output
1 1 | [
"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 should divide all 2·n players into two teams with n people each in such a way that the first team always wins.
Every chess player has its rating r_{i}. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a_1, a_2, ... a_2n (1 ≤ a_{i} ≤ 1000).
-----Output-----
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
-----Examples-----
Input
2
1 3 2 4
Output
YES
Input
1
3 3
Output
NO | [
"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 integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers a_{j} — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
-----Example-----
Input
3
2 7 28
Output
1
2 7 9 28 | [
"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 positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
-----Constraints-----
- 2 \leq N \leq 500
- 1 \leq A_i \leq 10^6
- 0 \leq K \leq 10^9
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \cdots A_{N-1} A_{N}
-----Output-----
Print the maximum possible positive integer that divides every element of A after the operations.
-----Sample Input-----
2 3
8 20
-----Sample Output-----
7
7 will divide every element of A if, for example, we perform the following operation:
- Choose i = 2, j = 1. A becomes (7, 21).
We cannot reach the situation where 8 or greater integer divides every element of A. | [
"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 the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b. | [
"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 check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q.
-----Input-----
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
-----Output-----
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
-----Examples-----
Input
abacaba
Output
Too weak
Input
X12345
Output
Too weak
Input
CONTEST_is_STARTED!!11
Output
Correct | [
"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 step 1. Otherwise, end the process.
Initially the values of a and b are positive integers, and so the process will be finite.
You have to determine the values of a and b after the process ends.
-----Input-----
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18). n is the initial value of variable a, and m is the initial value of variable b.
-----Output-----
Print two integers — the values of a and b after the end of the process.
-----Examples-----
Input
12 5
Output
0 1
Input
31 12
Output
7 12
-----Note-----
Explanations to the samples: a = 12, b = 5 $\rightarrow$ a = 2, b = 5 $\rightarrow$ a = 2, b = 1 $\rightarrow$ a = 0, b = 1; a = 31, b = 12 $\rightarrow$ a = 7, b = 12. | [
"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-----
Print the required number.
-----Examples-----
Input
1 1 10
Output
10
Input
2 -4 4
Output
5 | [
"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 first and only line contains integer $k$ ($1 \le k \le 10000$) — the position to process ($1$-based index).
-----Output-----
Print the $k$-th digit of the resulting infinite sequence.
-----Examples-----
Input
7
Output
7
Input
21
Output
5 | [
"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 actions)?
-----Input-----
The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.
-----Output-----
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
-----Examples-----
Input
4 4 0
2 1 2
Output
Yes
Input
5 6 1
2 7 2
Output
No
Input
3 3 3
2 2 2
Output
Yes
-----Note-----
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. | [
"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: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y > 0 such that: $y \operatorname{mod} k = 0$; decimal representation of y is a suffix of decimal representation of x.
As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.
Can you help Amr escape this embarrassing situation?
-----Input-----
Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 10^9).
-----Output-----
Print the required number modulo m.
-----Examples-----
Input
1 2 1000
Output
4
Input
2 2 1000
Output
45
Input
5 3 1103
Output
590
-----Note-----
A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S. | [
"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 unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
-----Input-----
The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
-----Output-----
Print a single integer, denoting the minimum possible height of the tallest tower.
-----Examples-----
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
-----Note-----
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks. | [
"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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.