Dataset Viewer
Auto-converted to Parquet
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", "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA\n", "W\n", "DBA\n" ]
[ "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", "2\n1 1\n", "2\n1049 1098\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", "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe\n", "aaaaaaaaaa\n", "abbabaaaaa\n" ]
[ "bncdenqbdr\n", "aaacaba\n", "aabbbabaababbaa\n", "abaacaabcababaccccaaaabacbbcbbaa\n", "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n", "z\n", "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec\n", "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe\n", "aaaaaaaaaz\n", "aaaabaaaaa\n" ]
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", "aaabaaaabbababbaabbababbbbaaaaaaabbabbba\n", "abbbbababbabbbbbabaabbbaabbbbbbbaaab\n" ]
[ "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 469225525 -933496047 -592182543 -29674334 -268378634 -985852520 -225395842\n", "3\n390029247 153996608 -918017777\n", "5\n450402558 -840167367 -231820501 586187125 -627664644\n", "6\n-76959846 -779700294 380306679 -340361999 58979764 -392237502\n", "7\n805743163 -181176136 454376774 681211377 988713965 -599336611 -823748404\n" ]
[ "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 14343092320 -14467076736 14922282304 -2771988832 -6435316288 5269175968 -8603136720 14387734816 -14437567712 9529436064 0\n1 15\n-226623555 7338911130 10227155355 -1182920475 -6247016145 -13446649050 13562884440 -13989639660 2598739530 6033109020 -4939852470 8065440675 -13488501390 13535219730 -8933846310 \n16 16\n480337024\n", "1 8\n2492430632 -3753804200 7467968376 4737460344 237394672 2147029072 7886820160 0\n1 7\n-2180876803 3284578675 -6534472329 -4145277801 -207720338 -1878650438 -6900967640 \n8 8\n225395842\n", "1 3\n-1170087741 -461989824 0\n1 2\n780058494 307993216 \n3 3\n918017777\n", "1 5\n-2252012790 4200836835 1159102505 -2930935625 0\n1 4\n1801610232 -3360669468 -927282004 2344748500 \n5 5\n627664644\n", "1 6\n461759076 4678201764 -2281840074 2042171994 -353878584 0\n1 5\n-384799230 -3898501470 1901533395 -1701809995 294898820 \n6 6\n392237502\n", "1 7\n-5640202141 1268232952 -3180637418 -4768479639 -6920997755 4195356277 0\n1 6\n4834458978 -1087056816 2726260644 4087268262 5932283790 -3596019666 \n7 7\n823748404\n" ]
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 2539 1056 1837 477 1894 1762 1835 3577 2730 950 2960 1004 3293 2401 1271 2388 3950 1908 2804 2011 4952 3075 2507 2992 1883 1591 1095 959 1611 4749 3717 2245 207 814 4862 3525 2371 3277 817 701 574 2964 1278 705 1397 415 2892\n", "53 7311 233\n163 70 172 6330 5670 33 59 7 3432 199 197 3879 145 226 117 26 116 98 981 6054 114 48 36 135 174 185 7249 192 150 11 65 83 62 61 88 7291 222 41 1257 20 6551 119 34 7246 6830 200 760 207 1641 97 118 115 481\n", "70 416035 416023\n70034 70322 345689 345965 345701 70046 345737 345713 70166 345821 70010 345749 345677 345725 69962 345869 70178 70310 345785 69998 70070 69974 70058 346001 70106 345953 70226 70154 345929 69950 70298 346049 70346 345989 70286 69986 345893 70082 70238 345797 70250 345833 70334 345845 70094 70118 70202 345977 70262 70274 70190 345941 346025 345761 345773 70142 70022 70130 345881 345917 70358 345905 345665 346013 346061 345809 345857 346037 346073 70214\n", "1 2 2\n1\n", "1 2 3\n1\n", "2 2 3\n1 2\n", "1 527802320 589732288\n418859112\n", "1 1 1\n1\n" ]
[ "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\nzzzerrzrzzrozrezooreroeoeezerrzeerooereezeeererrezrororoorrzezoeerrorzrezzrzoerrzorrooerzrzeozrrorzzzzeoeereeroeozezeozoozooereoeorrzoroeoezooeerorreeorezeozeroerezoerooooeerozrrorzozeroereerozeozeoerroroereeeerzzrzeeozrezzozeoooeerzzzorozrzezrrorozezoorzzerzroeeeerorreeoezoeroeeezerrzeorzoeorzoeeororzezrzzorrreozzorzroozzoereorzzroozoreorrrorezzozzzzezorzzrzoooorzzzrrozeezrzzzezzoezeozoooezroozez\n", "356\neeroooreoeoeroenezononnenonrnrzenonooozrznrezonezeeoeezeoroenoezrrrzoeoeooeeeezrrorzrooorrenznoororoozzrezeroerzrnnoreoeoznezrznorznozoozeoneeezerrnronrernzzrneoeroezoorerzrneoeoozerenreeozrneoeozeoeonzernneoeozooeeoezoroeroeorzeeeeooozooorzeeorzreezeezooeeezeooeozreooeoooeoenzrezonrnzoezooeoneneeozrnozooooeoeozreezerzooroooernzneozzznnezeneennerzereonee\n" ]
[ "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n", "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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" ]
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 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99\n", "1 14751211\n847188590\n", "2 1000000000\n-907894512 -289906312\n", "2 1000000000\n-14348867 1760823\n" ]
[ "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 717802881 588066499\n", "1\n1376\n", "2\n10 10\n", "2\n10 9\n", "3\n1 2 3\n", "3\n1 3 2\n", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n" ]
[ "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 \n", "1376 \n", "10 10 \n", "10 9 \n", "3 2 1 \n", "3 2 1 \n", "983359971 640274071 598196518 598196518 96204862 71550121 71550121 71550121 71550121 71550121 \n" ]
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\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n", "47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n21\n25\n28\n24\n21\n21\n17\n28\n20\n20\n31\n19\n", "3\n343\n317\n337\n" ]
[ "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", "ababababab\nabab\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", "10\n5 8 2\n0 5 8\n5 9 7\n0 7 2\n6 7 2\n10 3 7\n8 1 10\n9 1 8\n0 7 10\n9 1 4\n", "1\n1 864691128455135232 2\n", "11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14 19 23\n3 21914624432020321 23\n3 21914624432020321 46\n3 21914624432020321 47\n", "1\n1 100000000000000000 10000000000000000\n", "1\n1 4294967297 4294967296\n" ]
[ "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\nFinite\nInfinite\nFinite\n", "Finite\nFinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite\n", "Infinite\n", "Finite\nInfinite\nFinite\nFinite\nFinite\nFinite\nFinite\nInfinite\nFinite\nFinite\nInfinite\n", "Finite\n", "Infinite\n" ]
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 63\n", "6 22\n21 23 26 28 31 35 38 39 41 42 44 45 47 50 51 52 54 55 56 59 62 63\n", "6 19\n15 23 27 29 30 31 43 46 47 51 53 55 57 58 59 60 61 62 63\n" ]
[ "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\n4 3 4 2 5\n4 4 5 3 6\n4 5 6 4 7\n4 6 7 5 1\n4 7 1 6 2\n3 2 5 6\n3 1 5 4\n3 3 6 7\n3 7 4 3\n3 3 2 1\n3 7 1 2\n", "16\n3 8 1 2\n4 8 2 7 3\n4 7 3 6 4\n3 4 5 6\n3 1 2 3\n4 1 3 8 4\n4 8 4 7 5\n3 5 6 7\n3 2 3 4\n4 2 4 1 5\n4 1 5 8 6\n3 6 7 8\n3 3 4 5\n4 3 5 2 6\n4 2 6 1 7\n3 7 8 1\n", "20\n3 1 2 3\n4 1 3 9 4\n3 2 3 4\n4 2 4 1 5\n3 3 4 5\n4 3 5 2 6\n3 4 5 6\n4 4 6 3 7\n3 5 6 7\n4 5 7 4 8\n3 6 7 8\n4 6 8 5 9\n3 7 8 9\n4 7 9 6 1\n3 8 9 1\n4 8 1 7 2\n4 2 1 5 9\n4 9 1 6 2\n4 3 9 4 8\n4 8 2 7 3\n", "25\n3 10 1 2\n4 10 2 9 3\n4 9 3 8 4\n4 8 4 7 5\n3 5 6 7\n3 1 2 3\n4 1 3 10 4\n4 10 4 9 5\n4 9 5 8 6\n3 6 7 8\n3 2 3 4\n4 2 4 1 5\n4 1 5 10 6\n4 10 6 9 7\n3 7 8 9\n3 3 4 5\n4 3 5 2 6\n4 2 6 1 7\n4 1 7 10 8\n3 8 9 10\n3 4 5 6\n4 4 6 3 7\n4 3 7 2 8\n4 2 8 1 9\n3 9 10 1\n", "30\n4 2 3 1 4\n4 1 4 11 5\n4 3 4 2 5\n4 2 5 1 6\n4 4 5 3 6\n4 3 6 2 7\n4 5 6 4 7\n4 4 7 3 8\n4 6 7 5 8\n4 5 8 4 9\n4 7 8 6 9\n4 6 9 5 10\n4 8 9 7 10\n4 7 10 6 11\n4 9 10 8 11\n4 8 11 7 1\n4 10 11 9 1\n4 9 1 8 2\n4 11 1 10 2\n4 10 2 9 3\n3 2 7 8\n3 1 7 6\n3 3 8 9\n3 11 6 5\n3 4 9 10\n3 10 5 4\n3 3 2 1\n3 11 1 2\n3 4 3 11\n3 10 11 3\n" ]
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", "781453/1566442\n175559/352798\n674039/1351366\n403199/808942\n3959/8174\n232303/466546\n", "421954771415489597/843909545429301074\n" ]
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 9\n32 30\n91 77\n70 68\n63 69\n2 4\n57 51\n82 41\n17 34\n13 26\n96 98\n", "0\n", "0\n", "1\n2 4\n" ]
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 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 178762989 799964854\n825160173 502080627 608216046\n", "1\n1 2 3\n" ]
[ "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 536870913 536870913", "191 380 191 470 236 506 254 506 504 500 494 486 476 464 450 434 416 396 374 350 324 296 266 234 200 164 126 86 44", "2 2", "3 4 3" ]
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", "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000\n", "3\n0 0\n1 3\n2 4\n", "17\n0 0\n0 8\n1 8\n36 39\n3 4\n3 7\n2 17\n8 12\n9 12\n10 12\n10 15\n6 14\n8 15\n9 15\n15 15\n100000000000000000 1000000000000000000\n99999999999999999 1000000000000000000\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\n70368744177663\n562949953421311\n9007199254740991\n72057594037927935\n576460752303423487\n", "0\n3\n3\n", "0\n7\n7\n39\n3\n7\n15\n11\n11\n11\n15\n7\n15\n15\n15\n576460752303423487\n576460752303423487\n" ]
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 732 751 557 779 329 39 213 844 289 137 50 951 284 671 474 829 906 736 395 366 22 133 418 552 649 636 109 974 775 852 971 384 945 335 961 472 651 335 543 560 135 85 952 558\n", "100\n838 147 644 688 727 940 991 309 705 409 27 774 951 92 277 835 804 589 103 529 11 304 171 655 378 792 679 590 36 65 378 152 958 746 980 434 139 222 26 349 473 300 781 394 960 918 242 768 246 607 429 971 534 44 430 198 901 624 781 657 428 366 652 558 570 490 623 46 606 375 302 867 384 32 601 46 376 223 688 509 290 739 54 2 445 966 907 792 146 468 732 908 673 506 825 424 325 624 836 524\n", "100\n324 624 954 469 621 255 536 588 821 334 231 20 850 642 5 735 199 506 97 358 554 589 344 513 456 226 472 625 601 816 813 297 609 819 38 185 493 646 557 305 45 204 209 687 966 198 835 911 176 523 219 637 297 76 349 669 389 891 894 462 899 163 868 418 903 31 333 670 32 705 561 505 920 414 81 723 603 513 25 896 879 703 415 799 271 440 8 596 207 296 116 458 646 781 842 963 174 157 747 207\n", "100\n996 361 371 721 447 566 438 566 449 522 176 79 740 757 156 436 296 23 704 542 572 455 886 962 194 219 301 437 315 122 513 299 468 760 133 713 348 692 792 276 318 380 217 74 913 819 834 966 318 784 350 578 670 11 482 149 220 243 137 164 541 471 185 477 57 681 319 466 271 45 181 540 750 670 200 322 479 51 171 33 806 915 976 399 213 629 504 419 324 850 364 900 397 180 845 99 495 326 526 186\n", "100\n791 303 765 671 210 999 106 489 243 635 807 104 558 628 545 926 35 3 75 196 35 460 523 621 748 45 501 143 240 318 78 908 207 369 436 6 285 200 236 864 731 786 915 672 293 563 141 708 698 646 48 128 603 716 681 329 389 489 683 616 875 510 20 493 141 176 803 106 92 928 20 762 203 336 586 258 56 781 172 115 890 104 595 491 607 489 628 653 635 960 449 549 909 977 124 621 741 275 206 558\n" ]
[ "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\n117\n130\n13\n141\n121\n125\n94\n129\n60\n10\n42\n137\n55\n29\n12\n152\n56\n113\n84\n137\n145\n122\n70\n65\n7\n28\n73\n93\n110\n107\n26\n154\n129\n137\n154\n69\n151\n61\n152\n84\n110\n61\n92\n94\n28\n20\n152\n94\n", "137\n30\n109\n116\n121\n150\n157\n57\n118\n73\n7\n129\n152\n21\n54\n137\n131\n99\n24\n91\n4\n56\n34\n111\n67\n130\n115\n99\n9\n15\n67\n32\n153\n124\n155\n77\n30\n42\n7\n64\n84\n56\n129\n70\n153\n147\n48\n127\n48\n103\n75\n154\n91\n12\n75\n40\n145\n106\n129\n111\n75\n65\n110\n94\n96\n86\n106\n12\n102\n67\n56\n141\n69\n9\n102\n12\n67\n43\n116\n90\n55\n123\n13\n2\n79\n152\n146\n130\n30\n84\n121\n146\n114\n89\n135\n75\n60\n106\n137\n92\n", "60\n106\n153\n84\n106\n49\n91\n99\n134\n61\n45\n7\n137\n108\n3\n122\n41\n89\n22\n65\n93\n99\n62\n90\n80\n43\n84\n106\n102\n133\n133\n56\n103\n133\n10\n37\n87\n109\n94\n56\n12\n41\n41\n116\n152\n40\n137\n147\n35\n92\n42\n107\n56\n18\n64\n113\n70\n145\n145\n82\n145\n34\n141\n73\n145\n9\n61\n113\n9\n118\n94\n89\n148\n73\n19\n120\n102\n90\n7\n145\n142\n118\n73\n131\n53\n78\n4\n100\n41\n56\n27\n81\n109\n129\n137\n152\n35\n33\n124\n41\n", "157\n65\n66\n120\n79\n95\n77\n95\n80\n91\n35\n19\n123\n126\n32\n77\n56\n8\n118\n92\n97\n80\n144\n152\n39\n42\n56\n77\n59\n26\n90\n56\n84\n126\n28\n119\n63\n117\n130\n53\n60\n68\n42\n18\n147\n133\n137\n152\n60\n129\n64\n98\n113\n4\n85\n31\n42\n48\n29\n34\n92\n84\n37\n84\n13\n115\n60\n83\n53\n12\n37\n91\n124\n113\n41\n60\n85\n12\n34\n9\n131\n147\n154\n71\n42\n106\n89\n74\n60\n137\n65\n145\n71\n36\n137\n22\n87\n60\n92\n37\n", "130\n56\n127\n113\n41\n158\n24\n86\n48\n107\n131\n24\n94\n106\n92\n148\n9\n3\n18\n39\n9\n81\n92\n106\n124\n12\n88\n30\n47\n60\n18\n146\n41\n66\n77\n3\n56\n41\n46\n141\n121\n129\n147\n113\n56\n95\n30\n118\n117\n109\n13\n27\n102\n119\n115\n60\n70\n86\n116\n104\n141\n90\n7\n87\n30\n35\n131\n24\n21\n148\n7\n127\n41\n61\n98\n50\n13\n129\n34\n27\n145\n24\n100\n87\n103\n86\n106\n111\n107\n153\n80\n93\n146\n155\n26\n106\n123\n53\n41\n94\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
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
95

Collection including Gen-Verse/PrimeIntellect