question_text
stringlengths 2
3.82k
| input_outputs
stringlengths 23
941
| algo_tags
sequence |
---|---|---|
A binary string is a string that consists of characters 0 and 1. A bi-table is a table that has exactly two rows of equal length, each being a binary string.Let \operatorname{MEX} of a bi-table be the smallest digit among 0, 1, or 2 that does not occur in the bi-table. For example, \operatorname{MEX} for \begin{bmatrix} 0011\\ 1010 \end{bmatrix} is 2, because 0 and 1 occur in the bi-table at least once. \operatorname{MEX} for \begin{bmatrix} 111\\ 111 \end{bmatrix} is 0, because 0 and 2 do not occur in the bi-table, and 0 < 2.You are given a bi-table with n columns. You should cut it into any number of bi-tables (each consisting of consecutive columns) so that each column is in exactly one bi-table. It is possible to cut the bi-table into a single bi-table β the whole bi-table.What is the maximal sum of \operatorname{MEX} of all resulting bi-tables can be? | Input: ['4', '7', '0101000', '1101100', '5', '01100', '10101', '2', '01', '01', '6', '000000', '111111', ''] Output:['8', '8', '2', '12', ''] | [
2
] |
A binary string is a string that consists of characters 0 and 1.Let \operatorname{MEX} of a binary string be the smallest digit among 0, 1, or 2 that does not occur in the string. For example, \operatorname{MEX} of 001011 is 2, because 0 and 1 occur in the string at least once, \operatorname{MEX} of 1111 is 0, because 0 and 2 do not occur in the string and 0 < 2.A binary string s is given. You should cut it into any number of substrings such that each character is in exactly one substring. It is possible to cut the string into a single substring β the whole string.A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.What is the minimal sum of \operatorname{MEX} of all substrings pieces can be? | Input: ['6', '01', '1111', '01100', '101', '0000', '01010', ''] Output:['1', '0', '2', '1', '1', '2', ''] | [
2
] |
You are given two positive integers n and s. Find the maximum possible median of an array of n non-negative integers (not necessarily distinct), such that the sum of its elements is equal to s.A median of an array of integers of length m is the number standing on the \lceil {\frac{m}{2}} \rceil-th (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting from 1. For example, a median of the array [20,40,20,50,50,30] is the \lceil \frac{m}{2} \rceil-th element of [20,20,30,40,50,50], so it is 30. There exist other definitions of the median, but in this problem we use the described definition. | Input: ['8', '1 5', '2 5', '3 5', '2 1', '7 17', '4 14', '1 1000000000', '1000000000 1', ''] Output:['5', '2', '2', '0', '4', '4', '1000000000', '0', ''] | [
2,
3,
4
] |
Do you know what tubular bells are? They are a musical instrument made up of cylindrical metal tubes. In an orchestra, tubular bells are used to mimic the ringing of bells.Mike has tubular bells, too! They consist of n tubes, and each of the tubes has a length that can be expressed by a integer from l to r inclusive. It is clear that the lengths of all the tubes are different (it makes no sense to make the same tubes). It is also known that r-l+1 = n.Formally, we can say that Mike's tubular bells are described by a permutation a of length n that contains all numbers from l to r inclusive, with a_i denoting the length of the i-th tube.You are offered an interesting task: to guess what Mike's instrument looks like. Simply, you must guess the permutation.Mike won't tell you l or r. He will only tell you n, and will allow you to ask no more than n + 5000 queries.In each query, you name two positive integers x, y such that 1 <= x, y <= n, x \neq y. In response to this query, the program written by Mike will give you \mathrm{lcm}(a_x, a_y), where \mathrm{lcm}(c,d) denotes the least common multiple of c and d.Solve Mike's problem! | Input: ['3', '5', '8 10 7 6 9', '5', '24 25 28 27 26', '7', '1 2 3 4 5 6 7', ''] Output:['? 1 2', '40', '? 2 5', '90', '? 3 1', '56', '? 4 5', '18', '! 8 10 7 6 9', '? 1 5', '312', '? 2 4', '675', '! 24 25 28 27 26', '? 1 4', '4', '? 2 5', '10', '? 3 7', '21', '? 6 2', '6', '? 2 5', '10', '? 1 2', '2', '? 1 2', '2', '? 1 2', '2', '? 1 2', '2', '? 1 2', '2', '! 1 2 3 4 5 6 7'] | [
3
] |
Morning desert sun horizonRise above the sands of time...Fates Warning, "Exodus"After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this priceless Willow light did not want to open!Ori was taken aback, but the Voice of the Forest explained to him that the cunning Gorleks had decided to add protection to the repository.The Gorleks were very fond of the "string expansion" operation. They were also very fond of increasing subsequences.Suppose a string s_1s_2s_3 ... s_n is given. Then its "expansion" is defined as the sequence of strings s_1, s_1 s_2, ..., s_1 s_2 ... s_n, s_2, s_2 s_3, ..., s_2 s_3 ... s_n, s_3, s_3 s_4, ..., s_{n-1} s_n, s_n. For example, the "expansion" the string 'abcd' will be the following sequence of strings: 'a', 'ab', 'abc', 'abcd', 'b', 'bc', 'bcd', 'c', 'cd', 'd'. To open the ancient repository, Ori must find the size of the largest increasing subsequence of the "expansion" of the string s. Here, strings are compared lexicographically.Help Ori with this task!A string a is lexicographically smaller than a string b if and only if one of the following holds: a is a prefix of b, but a!=b; in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. | Input: ['7', '5', 'acbac', '8', 'acabacba', '12', 'aaaaaaaaaaaa', '10', 'abacabadac', '8', 'dcbaabcd', '3', 'cba', '6', 'sparky', ''] Output:['9', '17', '12', '29', '14', '3', '9', ''] | [
2
] |
This is the hard version of the problem. The difference between the versions is that the hard version does require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.The main element of this machine are n rods arranged along one straight line and numbered from 1 to n inclusive. Each of these rods must carry an electric charge quantitatively equal to either 1 or -1 (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.More formally, the rods can be represented as an array of n numbers characterizing the charge: either 1 or -1. Then the condition must hold: a_1 - a_2 + a_3 - a_4 + ... = 0, or \sum\limits_{i=1}^n (-1)^{i-1} \cdot a_i = 0.Sparky charged all n rods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has q questions. In the ith question Sparky asks: if the machine consisted only of rods with numbers l_i to r_i inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Also Sparky wants to know the numbers of these rods. Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don't have to remove the rods at all.If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.Help your friends and answer all of Sparky's questions! | Input: ['3', '14 1', '+--++---++-++-', '1 14', '14 3', '+--++---+++---', '1 14', '6 12', '3 10', '4 10', '+-+-', '1 1', '1 2', '1 3', '1 4', '2 2', '2 3', '2 4', '3 3', '3 4', '4 4', ''] Output:['2', '5 8', '2', '1 11', '1', '9', '0', '1', '1', '2', '1 2', '1', '2', '2', '1 3', '1', '2', '2', '2 3', '1', '3', '1', '3', '2', '3 4', '1', '4'] | [
3
] |
This is the easy version of the problem. The difference between the versions is that the easy version does not require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.The main element of this machine are n rods arranged along one straight line and numbered from 1 to n inclusive. Each of these rods must carry an electric charge quantitatively equal to either 1 or -1 (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.More formally, the rods can be represented as an array of n numbers characterizing the charge: either 1 or -1. Then the condition must hold: a_1 - a_2 + a_3 - a_4 + ... = 0, or \sum\limits_{i=1}^n (-1)^{i-1} \cdot a_i = 0.Sparky charged all n rods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has q questions. In the ith question Sparky asks: if the machine consisted only of rods with numbers l_i to r_i inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don't have to remove the rods at all.If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.Help your friends and answer all of Sparky's questions! | Input: ['3', '14 1', '+--++---++-++-', '1 14', '14 3', '+--++---+++---', '1 14', '6 12', '3 10', '4 10', '+-+-', '1 1', '1 2', '1 3', '1 4', '2 2', '2 3', '2 4', '3 3', '3 4', '4 4', ''] Output:['2', '2', '1', '0', '1', '2', '1', '2', '1', '2', '1', '1', '2', '1', ''] | [
3
] |
Frodo was caught by Saruman. He tore a pouch from Frodo's neck, shook out its contents βthere was a pile of different rings: gold and silver..."How am I to tell which is the One?!" the mage howled."Throw them one by one into the Cracks of Doom and watch when Mordor falls!" Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found n rings. And the i-th ring was either gold or silver. For convenience Saruman wrote down a binary string s of n characters, where the i-th character was 0 if the i-th ring was gold, and 1 if it was silver.Saruman has a magic function f, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, f(001010) = 10, f(111) = 7, f(11011101) = 221.Saruman, however, thinks that the order of the rings plays some important role. He wants to find 2 pairs of integers (l_1, r_1), (l_2, r_2), such that: 1 <= l_1 <= n, 1 <= r_1 <= n, r_1-l_1+1>= \lfloor \frac{n}{2} \rfloor 1 <= l_2 <= n, 1 <= r_2 <= n, r_2-l_2+1>= \lfloor \frac{n}{2} \rfloor Pairs (l_1, r_1) and (l_2, r_2) are distinct. That is, at least one of l_1 \neq l_2 and r_1 \neq r_2 must hold. Let t be the substring s[l_1:r_1] of s, and w be the substring s[l_2:r_2] of s. Then there exists non-negative integer k, such that f(t) = f(w) \cdot k.Here substring s[l:r] denotes s_ls_{l+1}... s_{r-1}s_r, and \lfloor x \rfloor denotes rounding the number down to the nearest integer.Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists. | Input: ['7', '6', '101111', '9', '111000111', '8', '10000000', '5', '11011', '6', '001111', '3', '101', '30', '100000000000000100000000000000', ''] Output:['3 6 1 3', '1 9 4 9', '5 8 1 4', '1 5 3 5', '1 6 2 4', '1 2 2 3', '1 15 16 30'] | [
3
] |
During the hypnosis session, Nicholas suddenly remembered a positive integer n, which doesn't contain zeros in decimal notation. Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or equal to one?For some numbers doing so is impossible: for example, for number 53 it's impossible to delete some of its digits to obtain a not prime integer. However, for all n in the test cases of this problem, it's guaranteed that it's possible to delete some of their digits to obtain a not prime number.Note that you cannot remove all the digits from the number.A prime number is a number that has no divisors except one and itself. A composite is a number that has more than two divisors. 1 is neither a prime nor a composite number. | Input: ['7', '3', '237', '5', '44444', '3', '221', '2', '35', '3', '773', '1', '4', '30', '626221626221626221626221626221', ''] Output:['2', '27', '1', '4', '1', '1', '2', '35', '2', '77', '1', '4', '1', '6', ''] | [
0,
3
] |
You are given two integers l and r, l<= r. Find the largest possible value of a \bmod b over all pairs (a, b) of integers for which r>= a >= b >= l.As a reminder, a \bmod b is a remainder we get when dividing a by b. For example, 26 \bmod 8 = 2. | Input: ['4', '1 1', '999999999 1000000000', '8 26', '1 999999999', ''] Output:['0', '1', '12', '499999999', ''] | [
2,
3
] |
This version of the problem differs from the next one only in the constraint on n.Note that the memory limit in this problem is lower than in others.You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom.You also have a token that is initially placed in cell n. You will move the token up until it arrives at cell 1.Let the token be in cell x > 1 at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer y between 1 and x-1, inclusive, and move the token from cell x to cell x - y. Floored division: you choose an integer z between 2 and x, inclusive, and move the token from cell x to cell \lfloor \frac{x}{z} \rfloor (x divided by z rounded down). Find the number of ways to move the token from cell n to cell 1 using one or more shifts, and print it modulo m. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding). | Input: ['3 998244353', ''] Output:['5', ''] | [
0,
3
] |
In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor.On the current level, the hero is facing n caves. To pass the level, the hero must enter all the caves in some order, each cave exactly once, and exit every cave safe and sound. When the hero enters cave i, he will have to fight k_i monsters in a row: first a monster with armor a_{i, 1}, then a monster with armor a_{i, 2} and so on, finally, a monster with armor a_{i, k_i}.The hero can beat a monster if and only if the hero's power is strictly greater than the monster's armor. If the hero can't beat the monster he's fighting, the game ends and the player loses. Note that once the hero enters a cave, he can't exit it before he fights all the monsters in it, strictly in the given order.Each time the hero beats a monster, the hero's power increases by 1.Find the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters. | Input: ['2', '1', '1 42', '2', '3 10 15 8', '2 12 11', ''] Output:['43', '13', ''] | [
2,
4
] |
You have a permutation: an array a = [a_1, a_2, ..., a_n] of distinct integers from 1 to n. The length of the permutation n is odd.Consider the following algorithm of sorting the permutation in increasing order.A helper procedure of the algorithm, f(i), takes a single argument i (1 <= i <= n-1) and does the following. If a_i > a_{i+1}, the values of a_i and a_{i+1} are exchanged. Otherwise, the permutation doesn't change.The algorithm consists of iterations, numbered with consecutive integers starting with 1. On the i-th iteration, the algorithm does the following: if i is odd, call f(1), f(3), ..., f(n - 2); if i is even, call f(2), f(4), ..., f(n - 1). It can be proven that after a finite number of iterations the permutation will be sorted in increasing order.After how many iterations will this happen for the first time? | Input: ['3', '3', '3 2 1', '7', '4 5 7 1 3 2 6', '5', '1 2 3 4 5', ''] Output:['3', '5', '0', ''] | [
0
] |
It is a complicated version of problem F1. The difference between them is the constraints (F1: k <= 2, F2: k <= 10).You are given an integer n. Find the minimum integer x such that x >= n and the number x is k-beautiful.A number is called k-beautiful if its decimal representation having no leading zeroes contains no more than k different digits. E.g. if k = 2, the numbers 3434443, 55550, 777 and 21 are k-beautiful whereas the numbers 120, 445435 and 998244353 are not. | Input: ['6', '2021 3', '177890 2', '34512 3', '724533 4', '998244353 1', '12345678 10', ''] Output:['2021', '181111', '34533', '724542', '999999999', '12345678', ''] | [
0,
2
] |
It is a simplified version of problem F2. The difference between them is the constraints (F1: k <= 2, F2: k <= 10).You are given an integer n. Find the minimum integer x such that x >= n and the number x is k-beautiful.A number is called k-beautiful if its decimal representation having no leading zeroes contains no more than k different digits. E.g. if k = 2, the numbers 3434443, 55550, 777 and 21 are k-beautiful whereas the numbers 120, 445435 and 998244353 are not. | Input: ['4', '1 1', '221 2', '177890 2', '998244353 1', ''] Output:['1', '221', '181111', '999999999', ''] | [
0,
2,
4
] |
Polycarp has a string s. Polycarp performs the following actions until the string s is empty (t is initially an empty string): he adds to the right to the string t the string s, i.e. he does t = t + s, where t + s is a concatenation of the strings t and s; he selects an arbitrary letter of s and removes from s all its occurrences (the selected letter must occur in the string s at the moment of performing this action). Polycarp performs this sequence of actions strictly in this order.Note that after Polycarp finishes the actions, the string s will be empty and the string t will be equal to some value (that is undefined and depends on the order of removing).E.g. consider s="abacaba" so the actions may be performed as follows: t="abacaba", the letter 'b' is selected, then s="aacaa"; t="abacabaaacaa", the letter 'a' is selected, then s="c"; t="abacabaaacaac", the letter 'c' is selected, then s="" (the empty string). You need to restore the initial value of the string s using only the final value of t and find the order of removing letters from s. | Input: ['7', 'abacabaaacaac', 'nowyouknowthat', 'polycarppoycarppoyarppyarppyrpprppp', 'isi', 'everywherevrywhrvryhrvrhrvhv', 'haaha', 'qweqeewew', ''] Output:['abacaba bac', '-1', 'polycarp lcoayrp', 'is si', 'everywhere ewyrhv', '-1', '-1', ''] | [
4
] |
You are given an integer n. In 1 move, you can do one of the following actions: erase any digit of the number (it's acceptable that the number before the operation has exactly one digit and after the operation, it is "empty"); add one digit to the right. The actions may be performed in any order any number of times.Note that if, after deleting some digit from a number, it will contain leading zeroes, they will not be deleted. E.g. if you delete from the number 301 the digit 3, the result is the number 01 (not 1).You need to perform the minimum number of actions to make the number any power of 2 (i.e. there's an integer k (k >= 0) such that the resulting number is equal to 2^k). The resulting number must not have leading zeroes.E.g. consider n=1052. The answer is equal to 2. First, let's add to the right one digit 4 (the result will be 10524). Then let's erase the digit 5, so the result will be 1024 which is a power of 2.E.g. consider n=8888. The answer is equal to 3. Let's erase any of the digits 8 three times. The result will be 8 which is a power of 2. | Input: ['12', '1052', '8888', '6', '75', '128', '1', '301', '12048', '1504', '6656', '1000000000', '687194767', ''] Output:['2', '3', '1', '3', '0', '0', '2', '1', '3', '4', '9', '2', ''] | [
2,
3
] |
Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from 1, starting from the topmost one. The columns are numbered from 1, starting from the leftmost one.Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from 1 and so on to the table as follows. The figure shows the placement of the numbers from 1 to 10. The following actions are denoted by the arrows. The leftmost topmost cell of the table is filled with the number 1. Then he writes in the table all positive integers beginning from 2 sequentially using the following algorithm.First, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above).After that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on.A friend of Polycarp has a favorite number k. He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number k. | Input: ['7', '11', '14', '5', '4', '1', '2', '1000000000', ''] Output:['2 4', '4 3', '1 3', '2 1', '1 1', '1 2', '31623 14130', ''] | [
3
] |
Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number 1. Each person is looking through the circle's center at the opposite person. A sample of a circle of 6 persons. The orange arrows indicate who is looking at whom. You don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number a is looking at the person with the number b (and vice versa, of course). What is the number associated with a person being looked at by the person with the number c? If, for the specified a, b, and c, no such circle exists, output -1. | Input: ['7', '6 2 4', '2 3 1', '2 4 10', '5 3 4', '1 3 2', '2 5 4', '4 3 2', ''] Output:['8', '-1', '-1', '-1', '4', '1', '-1', ''] | [
3
] |
Mocha wants to be an astrologer. There are n stars which can be seen in Zhijiang, and the brightness of the i-th star is a_i. Mocha considers that these n stars form a constellation, and she uses (a_1,a_2,...,a_n) to show its state. A state is called mathematical if all of the following three conditions are satisfied: For all i (1<= i<= n), a_i is an integer in the range [l_i, r_i]. \sum \limits _{i=1} ^ n a_i <= m. \gcd(a_1,a_2,...,a_n)=1. Here, \gcd(a_1,a_2,...,a_n) denotes the greatest common divisor (GCD) of integers a_1,a_2,...,a_n.Mocha is wondering how many different mathematical states of this constellation exist. Because the answer may be large, you must find it modulo 998\,244\,353.Two states (a_1,a_2,...,a_n) and (b_1,b_2,...,b_n) are considered different if there exists i (1<= i<= n) such that a_i!=b_i. | Input: ['2 4', '1 3', '1 2', ''] Output:['4'] | [
3
] |
This is the hard version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.A forest is an undirected graph without cycles (not necessarily connected).Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: After adding edges, both of their graphs are still forests. They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. Mocha and Diana want to know the maximum number of edges they can add, and which edges to add. | Input: ['3 2 2', '1 2', '2 3', '1 2', '1 3', ''] Output:['0', ''] | [
0,
2
] |
This is the easy version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.A forest is an undirected graph without cycles (not necessarily connected).Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: After adding edges, both of their graphs are still forests. They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. Mocha and Diana want to know the maximum number of edges they can add, and which edges to add. | Input: ['3 2 2', '1 2', '2 3', '1 2', '1 3', ''] Output:['0', ''] | [
0,
2
] |
As their story unravels, a timeless tale is told once again...Shirahime, a friend of Mocha's, is keen on playing the music game Arcaea and sharing Mocha interesting puzzles to solve. This day, Shirahime comes up with a new simple puzzle and wants Mocha to solve them. However, these puzzles are too easy for Mocha to solve, so she wants you to solve them and tell her the answers. The puzzles are described as follow.There are n squares arranged in a row, and each of them can be painted either red or blue.Among these squares, some of them have been painted already, and the others are blank. You can decide which color to paint on each blank square.Some pairs of adjacent squares may have the same color, which is imperfect. We define the imperfectness as the number of pairs of adjacent squares that share the same color.For example, the imperfectness of "BRRRBBR" is 3, with "BB" occurred once and "RR" occurred twice.Your goal is to minimize the imperfectness and print out the colors of the squares after painting. | Input: ['5', '7', '?R???BR', '7', '???R???', '1', '?', '1', 'B', '10', '?R??RB??B?', ''] Output:['BRRBRBR', 'BRBRBRB', 'B', 'B', 'BRRBRBBRBR'] | [
2
] |
Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.This day, Mocha got a sequence a of length n. In each operation, she can select an arbitrary interval [l, r] and for all values i (0<=q i <=q r-l), replace a_{l+i} with a_{l+i} \,\&\, a_{r-i} at the same time, where \& denotes the bitwise AND operation. This operation can be performed any number of times.For example, if n=5, the array is [a_1,a_2,a_3,a_4,a_5], and Mocha selects the interval [2,5], then the new array is [a_1,a_2\,\&\, a_5, a_3\,\&\, a_4, a_4\,\&\, a_3, a_5\,\&\, a_2].Now Mocha wants to minimize the maximum value in the sequence. As her best friend, can you help her to get the answer? | Input: ['4', '2', '1 2', '3', '1 1 3', '4', '3 11 3 7', '5', '11 7 15 3 7', ''] Output:['0', '1', '3', '3', ''] | [
3
] |
In a certain video game, the player controls a hero characterized by a single integer value: power.On the current level, the hero got into a system of n caves numbered from 1 to n, and m tunnels between them. Each tunnel connects two distinct caves. Any two caves are connected with at most one tunnel. Any cave can be reached from any other cave by moving via tunnels.The hero starts the level in cave 1, and every other cave contains a monster.The hero can move between caves via tunnels. If the hero leaves a cave and enters a tunnel, he must finish his movement and arrive at the opposite end of the tunnel.The hero can use each tunnel to move in both directions. However, the hero can not use the same tunnel twice in a row. Formally, if the hero has just moved from cave i to cave j via a tunnel, he can not head back to cave i immediately after, but he can head to any other cave connected to cave j with a tunnel.It is known that at least two tunnels come out of every cave, thus, the hero will never find himself in a dead end even considering the above requirement.To pass the level, the hero must beat the monsters in all the caves. When the hero enters a cave for the first time, he will have to fight the monster in it. The hero can beat the monster in cave i if and only if the hero's power is strictly greater than a_i. In case of beating the monster, the hero's power increases by b_i. If the hero can't beat the monster he's fighting, the game ends and the player loses.After the hero beats the monster in cave i, all subsequent visits to cave i won't have any consequences: the cave won't have any monsters, and the hero's power won't change either.Find the smallest possible power the hero must start the level with to be able to beat all the monsters and pass the level. | Input: ['3', '4 4', '11 22 13', '8 7 5', '1 2', '2 3', '3 4', '4 1', '4 4', '11 22 13', '5 7 8', '1 2', '2 3', '3 4', '4 1', '5 7', '10 40 20 30', '7 2 10 5', '1 2', '1 5', '2 3', '2 4', '2 5', '3 4', '4 5', ''] Output:['15', '15', '19', ''] | [
2,
4
] |
You have a permutation: an array a = [a_1, a_2, ..., a_n] of distinct integers from 1 to n. The length of the permutation n is odd.You need to sort the permutation in increasing order.In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if a = [a_1, a_2, ..., a_n], you can choose any odd integer p between 1 and n, inclusive, and set a to [a_p, a_{p-1}, ..., a_1, a_{p+1}, a_{p+2}, ..., a_n].Find a way to sort a using no more than \frac{5n}{2} reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized. | Input: ['3', '3', '1 2 3', '5', '3 4 5 2 1', '3', '2 1 3', ''] Output:['4', '3 3 3 3', '2', '3 5', '-1', ''] | [
2
] |
Note that the memory limit in this problem is lower than in others.You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom.You also have a token that is initially placed in cell n. You will move the token up until it arrives at cell 1.Let the token be in cell x > 1 at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer y between 1 and x-1, inclusive, and move the token from cell x to cell x - y. Floored division: you choose an integer z between 2 and x, inclusive, and move the token from cell x to cell \lfloor \frac{x}{z} \rfloor (x divided by z rounded down). Find the number of ways to move the token from cell n to cell 1 using one or more shifts, and print it modulo m. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding). | Input: ['3 998244353', ''] Output:['5', ''] | [
0,
3
] |
Alice and Borys are playing tennis.A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vice versa.Each game ends with a victory of one of the players. If a game is won by the serving player, it's said that this player holds serve. If a game is won by the receiving player, it's said that this player breaks serve.It is known that Alice won a games and Borys won b games during the match. It is unknown who served first and who won which games.Find all values of k such that exactly k breaks could happen during the match between Alice and Borys in total. | Input: ['3', '2 1', '1 1', '0 5', ''] Output:['4', '0 1 2 3', '2', '0 2', '2', '2 3', ''] | [
0,
3
] |
This is an interactive problem.ICPC Assiut Community decided to hold a unique chess contest, and you were chosen to control a queen and hunt down the hidden king, while a member of ICPC Assiut Community controls this king.You compete on an 8*8 chessboard, the rows are numerated from top to bottom, and the columns are numerated left to right, and the cell in row x and column y is denoted as (x, y).In one turn you can move the queen to any of the squares on the same horizontal line, vertical line, or any of the diagonals. For example, if the queen was on square (4, 5), you can move to (q_1, 5), (4, q_1), (q_1, 9-q_1), or (q_2, q_2+1) where (1 <= q_1 <= 8, q_1!=4, 1 <= q_2 <= 7, q_2!=4). Note that the queen cannot stay on its current cell. In one turn, the king can move "Right", "Left", "Up", "Down", "Down-Right", "Down-Left", "Up-Left", or "Up-Right" such that he doesn't get out of the board. The king cannot move into a cell that is on the same row, column or diagonal with the queen (including the position of the queen itself). For example, if the king was on square (4, 5), he can move to (4+k_1, 5+k_2) where (-1 <= k_1,k_2 <= 1, (k_1, k_2)!=(0, 0)). At the start of the game, you should place the queen at any location on the board, and this is done once per game. After that the king is secretly placed at any cell different from the queen's location. You do not know the position of the king. Then, the king and the queen take turns with the king moving first. The king moves to one of the possible directions ("Right", "Down", "Up-Left", etc.), and you are only given the direction it moves to. After that, you should move your queen by declaring the square to which your queen will move. The game follows like this until you win the game or run out of moves.You win if the king has no valid moves. You lose if after 130 moves of the queen the king still has valid moves. | Input: ['1', 'Left', 'Right', 'Done'] Output:['7 5', '7 6', '7 7'] | [
0
] |
Moamen was drawing a grid of n rows and 10^9 columns containing only digits 0 and 1. Ezzat noticed what Moamen was drawing and became interested in the minimum number of rows one needs to remove to make the grid beautiful.A grid is beautiful if and only if for every two consecutive rows there is at least one column containing 1 in these two rows.Ezzat will give you the number of rows n, and m segments of the grid that contain digits 1. Every segment is represented with three integers i, l, and r, where i represents the row number, and l and r represent the first and the last column of the segment in that row.For example, if n = 3, m = 6, and the segments are (1,1,1), (1,7,8), (2,7,7), (2,15,15), (3,1,1), (3,15,15), then the grid is: Your task is to tell Ezzat the minimum number of rows that should be removed to make the grid beautiful. | Input: ['3 6', '1 1 1', '1 7 8', '2 7 7', '2 15 15', '3 1 1', '3 15 15', ''] Output:['0', ''] | [
2
] |
Moamen and Ezzat are playing a game. They create an array a of n non-negative integers where every element is less than 2^k.Moamen wins if a_1 \,\&\, a_2 \,\&\, a_3 \,\&\, ... \,\&\, a_n >= a_1 \oplus a_2 \oplus a_3 \oplus ... \oplus a_n.Here \& denotes the bitwise AND operation, and \oplus denotes the bitwise XOR operation.Please calculate the number of winning for Moamen arrays a.As the result may be very large, print the value modulo 1\,000\,000\,007 (10^9 + 7). | Input: ['3', '3 1', '2 1', '4 0', ''] Output:['5', '2', '1', ''] | [
3
] |
Moamen has an array of n distinct integers. He wants to sort that array in non-decreasing order by doing the following operations in order exactly once: Split the array into exactly k non-empty subarrays such that each element belongs to exactly one subarray. Reorder these subarrays arbitrary. Merge the subarrays in their new order. A sequence a is a subarray of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Can you tell Moamen if there is a way to sort the array in non-decreasing order using the operations written above? | Input: ['3', '5 4', '6 3 4 2 1', '4 2', '1 -4 0 -2', '5 1', '1 2 3 4 5', ''] Output:['Yes', 'No', 'Yes', ''] | [
2
] |
Ezzat has an array of n integers (maybe negative). He wants to split it into two non-empty subsequences a and b, such that every element from the array belongs to exactly one subsequence, and the value of f(a) + f(b) is the maximum possible value, where f(x) is the average of the subsequence x. A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.The average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence.For example, the average of [1,5,6] is (1+5+6)/3 = 12/3 = 4, so f([1,5,6]) = 4. | Input: ['4', '3', '3 1 2', '3', '-7 -6 -6', '3', '2 2 2', '4', '17 3 5 -3', ''] Output:['4.500000000', '-12.500000000', '4.000000000', '18.666666667', ''] | [
0,
3
] |
William really likes puzzle kits. For one of his birthdays, his friends gifted him a complete undirected edge-weighted graph consisting of n vertices.He wants to build a spanning tree of this graph, such that for the first k vertices the following condition is satisfied: the degree of a vertex with index i does not exceed d_i. Vertices from k + 1 to n may have any degree.William wants you to find the minimum weight of a spanning tree that satisfies all the conditions.A spanning tree is a subset of edges of a graph that forms a tree on all n vertices of the graph. The weight of a spanning tree is defined as the sum of weights of all the edges included in a spanning tree. | Input: ['10 5', '5 3 4 2 1', '29 49 33 12 55 15 32 62 37', '61 26 15 58 15 22 8 58', '37 16 9 39 20 14 58', '10 15 40 3 19 55', '53 13 37 44 52', '23 59 58 4', '69 80 29', '89 28', '48', ''] Output:['95', ''] | [
2,
3
] |
William is not only interested in trading but also in betting on sports matches. n teams participate in each match. Each team is characterized by strength a_i. Each two teams i < j play with each other exactly once. Team i wins with probability \frac{a_i}{a_i + a_j} and team j wins with probability \frac{a_j}{a_i + a_j}.The team is called a winner if it directly or indirectly defeated all other teams. Team a defeated (directly or indirectly) team b if there is a sequence of teams c_1, c_2, ... c_k such that c_1 = a, c_k = b and team c_i defeated team c_{i + 1} for all i from 1 to k - 1. Note that it is possible that team a defeated team b and in the same time team b defeated team a.William wants you to find the expected value of the number of winners. | Input: ['2', '1 2', ''] Output:['1', ''] | [
3
] |
William has two arrays a and b, each consisting of n items.For some segments l..r of these arrays William wants to know if it is possible to equalize the values of items in these segments using a balancing operation. Formally, the values are equalized if for each i from l to r holds a_i = b_i.To perform a balancing operation an even number of indices must be selected, such that l <= pos_1 < pos_2 < ... < pos_k <= r. Next the items of array a at positions pos_1, pos_3, pos_5, ... get incremented by one and the items of array b at positions pos_2, pos_4, pos_6, ... get incremented by one.William wants to find out if it is possible to equalize the values of elements in two arrays for each segment using some number of balancing operations, and what is the minimal number of operations required for that. Note that for each segment the operations are performed independently. | Input: ['8 5', '0 1 2 9 3 2 7 5', '2 2 1 9 4 1 5 8', '2 6', '1 7', '2 4', '7 8', '5 8', ''] Output:['1', '3', '1', '-1', '-1', ''] | [
2
] |
This is an interactive taskWilliam has a certain sequence of integers a_1, a_2, ..., a_n in his mind, but due to security concerns, he does not want to reveal it to you completely. William is ready to respond to no more than 2 \cdot n of the following questions: What is the result of a bitwise AND of two items with indices i and j (i \neq j) What is the result of a bitwise OR of two items with indices i and j (i \neq j) You can ask William these questions and you need to find the k-th smallest number of the sequence.Formally the k-th smallest number is equal to the number at the k-th place in a 1-indexed array sorted in non-decreasing order. For example in array [5, 3, 3, 10, 1] 4th smallest number is equal to 5, and 2nd and 3rd are 3. | Input: ['7 6', '', '2', '', '7'] Output:['and 2 5', '', 'or 5 6', '', 'finish 5'] | [
3
] |
William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers c_1, c_2, ..., c_n where c_i is the number of consecutive brackets "(" if i is an odd number or the number of consecutive brackets ")" if i is an even number.For example for a bracket sequence "((())()))" a corresponding sequence of numbers is [3, 2, 1, 3].You need to find the total number of continuous subsequences (subsegments) [l, r] (l <= r) of the original bracket sequence, which are regular bracket sequences.A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. | Input: ['5', '4 1 2 3 1', ''] Output:['5', ''] | [
0
] |
William has two numbers a and b initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer k is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer k) add number k to both a and b, or add number k to a and subtract k from b, or add number k to b and subtract k from a. Note that after performing operations, numbers a and b may become negative as well.William wants to find out the minimal number of operations he would have to perform to make a equal to his favorite number c and b equal to his second favorite number d. | Input: ['6', '1 2', '3 5', '5 3', '6 6', '8 0', '0 0', ''] Output:['-1', '2', '2', '1', '2', '0', ''] | [
3
] |
Let's call the string beautiful if it does not contain a substring of length at least 2, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, but the strings ab, abbbaa, cccb are not.Let's define cost of a string as the minimum number of operations so that the string becomes beautiful, if in one operation it is allowed to change any character of the string to one of the first 3 letters of the Latin alphabet (in lowercase).You are given a string s of length n, each character of the string is one of the first 3 letters of the Latin alphabet (in lowercase).You have to answer m queries β calculate the cost of the substring of the string s from l_i-th to r_i-th position, inclusive. | Input: ['5 4', 'baacb', '1 3', '1 5', '4 5', '2 3', ''] Output:['1', '2', '0', '1', ''] | [
0
] |
Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the i-th row in the j-th column contains a_{i, j} coins in it.Initially, both Alice and Bob are standing in a cell (1, 1). They are going to perform a sequence of moves to reach a cell (2, m).The possible moves are: Move right β from some cell (x, y) to (x, y + 1); Move down β from some cell (x, y) to (x + 1, y). First, Alice makes all her moves until she reaches (2, m). She collects the coins in all cells she visit (including the starting cell).When Alice finishes, Bob starts his journey. He also performs the moves to reach (2, m) and collects the coins in all cells that he visited, but Alice didn't.The score of the game is the total number of coins Bob collects.Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally? | Input: ['3', '3', '1 3 7', '3 5 1', '3', '1 3 9', '3 5 1', '1', '4', '7', ''] Output:['7', '8', '0', ''] | [
0
] |
You have an axis-aligned rectangle room with width W and height H, so the lower left corner is in point (0, 0) and the upper right corner is in (W, H).There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in (x_1, y_1), and the upper right corner in (x_2, y_2).You want to place another rectangular table in this room with width w and height h with the width of the table parallel to the width of the room.The problem is that sometimes there is not enough space to place the second table without intersecting with the first one (there are no problems with tables touching, though).You can't rotate any of the tables, but you can move the first table inside the room. Example of how you may move the first table. What is the minimum distance you should move the first table to free enough space for the second one? | Input: ['5', '8 5', '2 1 7 4', '4 2', '5 4', '2 2 5 4', '3 3', '1 8', '0 3 1 6', '1 5', '8 1', '3 0 6 1', '5 1', '8 10', '4 5 7 8', '8 5', ''] Output:['1.000000000', '-1', '2.000000000', '2.000000000', '0.000000000', ''] | [
0
] |
PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of 6 slices, medium ones consist of 8 slices, and large pizzas consist of 10 slices each. Baking them takes 15, 20 and 25 minutes, respectively.Petya's birthday is today, and n of his friends will come, so he decided to make an order from his favorite pizzeria. Petya wants to order so much pizza that each of his friends gets at least one slice of pizza. The cooking time of the order is the total baking time of all the pizzas in the order.Your task is to determine the minimum number of minutes that is needed to make pizzas containing at least n slices in total. For example: if 12 friends come to Petya's birthday, he has to order pizzas containing at least 12 slices in total. He can order two small pizzas, containing exactly 12 slices, and the time to bake them is 30 minutes; if 15 friends come to Petya's birthday, he has to order pizzas containing at least 15 slices in total. He can order a small pizza and a large pizza, containing 16 slices, and the time to bake them is 40 minutes; if 300 friends come to Petya's birthday, he has to order pizzas containing at least 300 slices in total. He can order 15 small pizzas, 10 medium pizzas and 13 large pizzas, in total they contain 15 \cdot 6 + 10 \cdot 8 + 13 \cdot 10 = 300 slices, and the total time to bake them is 15 \cdot 15 + 10 \cdot 20 + 13 \cdot 25 = 750 minutes; if only one friend comes to Petya's birthday, he can order a small pizza, and the time to bake it is 15 minutes. | Input: ['6', '12', '15', '300', '1', '9999999999999999', '3', ''] Output:['30', '40', '750', '15', '25000000000000000', '15', ''] | [
0,
3
] |
You are given a tree with n nodes. As a reminder, a tree is a connected undirected graph without cycles.Let a_1, a_2, ..., a_n be a sequence of integers. Perform the following operation exactly n times: Select an unerased node u. Assign a_u := number of unerased nodes adjacent to u. Then, erase the node u along with all edges that have it as an endpoint. For each integer k from 1 to n, find the number, modulo 998\,244\,353, of different sequences a_1, a_2, ..., a_n that satisfy the following conditions: it is possible to obtain a by performing the aforementioned operations exactly n times in some order. \operatorname{gcd}(a_1, a_2, ..., a_n) = k. Here, \operatorname{gcd} means the greatest common divisor of the elements in a. | Input: ['2', '3', '2 1', '1 3', '2', '1 2', ''] Output:['3 1 0', '2 0', ''] | [
3
] |
You are given an integer n. Find any string s of length n consisting only of English lowercase letters such that each non-empty substring of s occurs in s an odd number of times. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. | Input: ['4', '3', '5', '9', '19', ''] Output:['abc', 'diane', 'bbcaabbba', 'youarethecutestuwuu', ''] | [
2
] |
You are given two integers n and m. Find the \operatorname{MEX} of the sequence n \oplus 0, n \oplus 1, ..., n \oplus m. Here, \oplus is the bitwise XOR operator.\operatorname{MEX} of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, \operatorname{MEX}(0, 1, 2, 4) = 3, and \operatorname{MEX}(1, 2021) = 0. | Input: ['5', '3 5', '4 6', '3 2', '69 696', '123456 654321', ''] Output:['4', '3', '0', '640', '530866', ''] | [
2,
4
] |
You are given n integers a_1, a_2, ..., a_n and an integer k. Find the maximum value of i \cdot j - k \cdot (a_i | a_j) over all pairs (i, j) of integers with 1 <= i < j <= n. Here, | is the bitwise OR operator. | Input: ['4', '3 3', '1 1 3', '2 2', '1 2', '4 3', '0 1 2 3', '6 6', '3 2 0 0 5 6', ''] Output:['-1', '-4', '3', '12', ''] | [
0,
2,
3
] |
You are given n integers a_1, a_2, ..., a_n. Find the maximum value of max(a_l, a_{l + 1}, ..., a_r) \cdot min(a_l, a_{l + 1}, ..., a_r) over all pairs (l, r) of integers for which 1 <= l < r <= n. | Input: ['4', '3', '2 4 3', '4', '3 2 3 1', '2', '69 69', '6', '719313 273225 402638 473783 804745 323328', ''] Output:['12', '6', '4761', '381274500335', ''] | [
2
] |
For a permutation p of numbers 1 through n, we define a stair array a as follows: a_i is length of the longest segment of permutation which contains position i and is made of consecutive values in sorted order: [x, x+1, ..., y-1, y] or [y, y-1, ..., x+1, x] for some x <=q y. For example, for permutation p = [4, 1, 2, 3, 7, 6, 5] we have a = [1, 3, 3, 3, 3, 3, 3]. You are given the stair array a. Your task is to calculate the number of permutations which have stair array equal to a. Since the number can be big, compute it modulo 998\,244\,353. Note that this number can be equal to zero. | Input: ['6', '3 3 3 1 1 1', ''] Output:['6', ''] | [
3
] |
Consider a sequence of distinct integers a_1, ..., a_n, each representing one node of a graph. There is an edge between two nodes if the two values are not coprime, i. e. they have a common divisor greater than 1.There are q queries, in each query, you want to get from one given node a_s to another a_t. In order to achieve that, you can choose an existing value a_i and create new value a_{n+1} = a_i \cdot (1 + a_i), with edges to all values that are not coprime with a_{n+1}. Also, n gets increased by 1. You can repeat that operation multiple times, possibly making the sequence much longer and getting huge or repeated values. What's the minimum possible number of newly created nodes so that a_t is reachable from a_s?Queries are independent. In each query, you start with the initial sequence a given in the input. | Input: ['3 3', '2 10 3', '1 2', '1 3', '2 3', ''] Output:['0', '1', '1', ''] | [
0,
3
] |
You have an array a consisting of n distinct positive integers, numbered from 1 to n. Define p_k as p_k = \sum_{1 <= i, j <= k} a_i \bmod a_j, where x \bmod y denotes the remainder when x is divided by y. You have to find and print p_1, p_2, ..., p_n. | Input: ['4', '6 2 7 3', ''] Output:['0 2 12 22', ''] | [
3
] |
An identity permutation of length n is an array [1, 2, 3, ..., n].We performed the following operations to an identity permutation of length n: firstly, we cyclically shifted it to the right by k positions, where k is unknown to you (the only thing you know is that 0 <= k <= n - 1). When an array is cyclically shifted to the right by k positions, the resulting array is formed by taking k last elements of the original array (without changing their relative order), and then appending n - k first elements to the right of them (without changing relative order of the first n - k elements as well). For example, if we cyclically shift the identity permutation of length 6 by 2 positions, we get the array [5, 6, 1, 2, 3, 4]; secondly, we performed the following operation at most m times: pick any two elements of the array and swap them. You are given the values of n and m, and the resulting array. Your task is to find all possible values of k in the cyclic shift operation. | Input: ['4', '4 1', '2 3 1 4', '3 1', '1 2 3', '3 1', '3 2 1', '6 0', '1 2 3 4 6 5', ''] Output:['1 3', '1 0', '3 0 1 2', '0', ''] | [
0,
3
] |
You are given two strings s and t, both consisting of lowercase English letters. You are going to type the string s character by character, from the first character to the last one.When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the last character you have typed among those that aren't deleted yet (or does nothing if there are no characters in the current string). For example, if s is "abcbd" and you press Backspace instead of typing the first and the fourth characters, you will get the string "bd" (the first press of Backspace deletes no character, and the second press deletes the character 'c'). Another example, if s is "abcaa" and you press Backspace instead of the last two letters, then the resulting text is "a".Your task is to determine whether you can obtain the string t, if you type the string s and press "Backspace" instead of typing several (maybe zero) characters of s. | Input: ['4', 'ababa', 'ba', 'ababa', 'bb', 'aaa', 'aaaa', 'aababa', 'ababa', ''] Output:['YES', 'NO', 'NO', 'YES', ''] | [
2
] |
Consider a simplified penalty phase at the end of a football match.A penalty phase consists of at most 10 kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the 7-th kick the first team has scored 1 goal, and the second team has scored 3 goals, the penalty phase ends β the first team cannot reach 3 goals.You know which player will be taking each kick, so you have your predictions for each of the 10 kicks. These predictions are represented by a string s consisting of 10 characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way: if s_i is 1, then the i-th kick will definitely score a goal; if s_i is 0, then the i-th kick definitely won't score a goal; if s_i is ?, then the i-th kick could go either way. Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase β you may know that some kick will/won't be scored, but the referee doesn't. | Input: ['4', '1?0???1001', '1111111111', '??????????', '0100000000', ''] Output:['7', '10', '6', '9', ''] | [
0,
2
] |
You have a string s and a chip, which you can place onto any character of this string. After placing the chip, you move it to the right several (maybe zero) times, i. e. you perform the following operation several times: if the current position of the chip is i, you move it to the position i + 1. Of course, moving the chip to the right is impossible if it is already in the last position.After moving the chip to the right, you move it to the left several (maybe zero) times, i. e. you perform the following operation several times: if the current position of the chip is i, you move it to the position i - 1. Of course, moving the chip to the left is impossible if it is already in the first position.When you place a chip or move it, you write down the character where the chip ends up after your action. For example, if s is abcdef, you place the chip onto the 3-rd character, move it to the right 2 times and then move it to the left 3 times, you write down the string cdedcb.You are given two strings s and t. Your task is to determine whether it's possible to perform the described operations with s so that you write down the string t as a result. | Input: ['6', 'abcdef', 'cdedcb', 'aaa', 'aaaaa', 'aab', 'baaa', 'ab', 'b', 'abcdef', 'abcdef', 'ba', 'baa', ''] Output:['YES', 'YES', 'NO', 'YES', 'YES', 'NO', ''] | [
0
] |
Let's define S(x) to be the sum of digits of number x written in decimal system. For example, S(5) = 5, S(10) = 1, S(322) = 7.We will call an integer x interesting if S(x + 1) < S(x). In each test you will be given one integer n. Your task is to calculate the number of integers x such that 1 <= x <= n and x is interesting. | Input: ['5', '1', '9', '10', '34', '880055535', ''] Output:['0', '1', '1', '3', '88005553', ''] | [
3
] |
You are the organizer of the famous "Zurich Music Festival". There will be n singers who will perform at the festival, identified by the integers 1, 2, ..., n. You must choose in which order they are going to perform on stage. You have m friends and each of them has a set of favourite singers. More precisely, for each 1<= i<= m, the i-th friend likes singers s_{i,1}, \, s_{i, 2}, \, ..., \,s_{i, q_i}.A friend of yours is happy if the singers he likes perform consecutively (in an arbitrary order). An ordering of the singers is valid if it makes all your friends happy.Compute the number of valid orderings modulo 998\,244\,353. | Input: ['3 1', '2 1 3', ''] Output:['4', ''] | [
3
] |
Let us call a point of the plane admissible if its coordinates are positive integers less than or equal to 200.There is an invisible rectangle such that: its vertices are all admissible; its sides are parallel to the coordinate axes; its area is strictly positive. Your task is to guess the perimeter of this rectangle.In order to guess it, you may ask at most 4 queries. In each query, you choose a nonempty subset of the admissible points and you are told how many of the chosen points are inside or on the boundary of the invisible rectangle. | Input: ['13 5 123 80', ''] Output:[''] | [
4
] |
Andrea has come up with what he believes to be a novel sorting algorithm for arrays of length n. The algorithm works as follows.Initially there is an array of n integers a_1,\, a_2,\, ...,\, a_n. Then, k steps are executed.For each 1<= i<= k, during the i-th step the subsequence of the array a with indexes j_{i,1}< j_{i,2}< ...< j_{i, q_i} is sorted, without changing the values with the remaining indexes. So, the subsequence a_{j_{i,1}},\, a_{j_{i,2}},\, ...,\, a_{j_{i,q_i}} is sorted and all other elements of a are left untouched.Andrea, being eager to share his discovery with the academic community, sent a short paper describing his algorithm to the journal "Annals of Sorting Algorithms" and you are the referee of the paper (that is, the person who must judge the correctness of the paper). You must decide whether Andrea's algorithm is correct, that is, if it sorts any array a of n integers. | Input: ['4 3', '3 1 2 3', '3 2 3 4', '2 1 2', ''] Output:['ACCEPTED', ''] | [
0
] |
An ant moves on the real line with constant speed of 1 unit per second. It starts at 0 and always moves to the right (so its position increases by 1 each second).There are n portals, the i-th of which is located at position x_i and teleports to position y_i < x_i. Each portal can be either active or inactive. The initial state of the i-th portal is determined by s_i: if s_i=0 then the i-th portal is initially inactive, if s_i=1 then the i-th portal is initially active. When the ant travels through a portal (i.e., when its position coincides with the position of a portal): if the portal is inactive, it becomes active (in this case the path of the ant is not affected); if the portal is active, it becomes inactive and the ant is instantly teleported to the position y_i, where it keeps on moving as normal. How long (from the instant it starts moving) does it take for the ant to reach the position x_n + 1? It can be shown that this happens in a finite amount of time. Since the answer may be very large, compute it modulo 998\,244\,353. | Input: ['4', '3 2 0', '6 5 1', '7 4 0', '8 1 1', ''] Output:['23', ''] | [
4
] |
The numbers 1, \, 2, \, ..., \, n \cdot k are colored with n colors. These colors are indexed by 1, \, 2, \, ..., \, n. For each 1 <= i <= n, there are exactly k numbers colored with color i.Let [a, \, b] denote the interval of integers between a and b inclusive, that is, the set \{a, \, a + 1, \, ..., \, b\}. You must choose n intervals [a_1, \, b_1], \, [a_2, \, b_2], \, ..., [a_n, \, b_n] such that: for each 1 <= i <= n, it holds 1 <= a_i < b_i <= n \cdot k; for each 1 <= i <= n, the numbers a_i and b_i are colored with color i; each number 1 <= x <= n \cdot k belongs to at most <=ft\lceil \frac{n}{k - 1} \right\rceil intervals. One can show that such a family of intervals always exists under the given constraints. | Input: ['4 3', '2 4 3 1 1 4 2 3 2 1 3 4', ''] Output:['4 5', '1 7', '8 11', '6 12'] | [
2
] |
You are given a sequence of n integers a_1, \, a_2, \, ..., \, a_n.Does there exist a sequence of n integers b_1, \, b_2, \, ..., \, b_n such that the following property holds? For each 1 <= i <= n, there exist two (not necessarily distinct) indices j and k (1 <= j, \, k <= n) such that a_i = b_j - b_k. | Input: ['5', '5', '4 -7 -1 5 10', '1', '0', '3', '1 10 100', '4', '-3 2 10 2', '9', '25 -171 250 174 152 242 100 -205 -258', ''] Output:['YES', 'YES', 'NO', 'YES', 'YES', ''] | [
0,
3
] |
On a circle lie 2n distinct points, with the following property: however you choose 3 chords that connect 3 disjoint pairs of points, no point strictly inside the circle belongs to all 3 chords. The points are numbered 1, \, 2, \, ..., \, 2n in clockwise order.Initially, k chords connect k pairs of points, in such a way that all the 2k endpoints of these chords are distinct.You want to draw n - k additional chords that connect the remaining 2(n - k) points (each point must be an endpoint of exactly one chord).In the end, let x be the total number of intersections among all n chords. Compute the maximum value that x can attain if you choose the n - k chords optimally.Note that the exact position of the 2n points is not relevant, as long as the property stated in the first paragraph holds. | Input: ['4', '4 2', '8 2', '1 5', '1 1', '2 1', '2 0', '10 6', '14 6', '2 20', '9 10', '13 18', '15 12', '11 7', ''] Output:['4', '0', '1', '14', ''] | [
2
] |
The Olympic Games have just started and Federico is eager to watch the marathon race.There will be n athletes, numbered from 1 to n, competing in the marathon, and all of them have taken part in 5 important marathons, numbered from 1 to 5, in the past. For each 1<= i<= n and 1<= j<= 5, Federico remembers that athlete i ranked r_{i,j}-th in marathon j (e.g., r_{2,4}=3 means that athlete 2 was third in marathon 4).Federico considers athlete x superior to athlete y if athlete x ranked better than athlete y in at least 3 past marathons, i.e., r_{x,j}<r_{y,j} for at least 3 distinct values of j.Federico believes that an athlete is likely to get the gold medal at the Olympics if he is superior to all other athletes.Find any athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes), or determine that there is no such athlete. | Input: ['4', '1', '50000 1 50000 50000 50000', '3', '10 10 20 30 30', '20 20 30 10 10', '30 30 10 20 20', '3', '1 1 1 1 1', '2 2 2 2 2', '3 3 3 3 3', '6', '9 5 3 7 1', '7 4 1 6 8', '5 6 7 3 2', '6 7 8 8 6', '4 2 2 4 5', '8 3 6 9 4', ''] Output:['1', '-1', '1', '5', ''] | [
2
] |
A tree is an undirected connected graph without cycles.You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i.βe. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words, there exists an integer c such that for all u, v (u!=v, u, v are in selected vertices) d_{u,v}=c, where d_{u,v} is the distance from u to v).Since the answer may be very large, you need to output it modulo 10^9 + 7. | Input: ['3', '', '4 2', '1 2', '2 3', '2 4', '', '3 3', '1 2', '2 3', '', '5 3', '1 2', '2 3', '2 4', '4 5', ''] Output:['6', '0', '1', ''] | [
0
] |
Consider a sequence of integers a_1, a_2, ..., a_n. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by 1 position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by 1. The indices of the elements after the move are recalculated.E.βg. let the sequence be a=[3, 2, 2, 1, 5]. Let's select the element a_3=2 in a move. Then after the move the sequence will be equal to a=[3, 2, 1, 5], so the 3-rd element of the new sequence will be a_3=1 and the 4-th element will be a_4=5.You are given a sequence a_1, a_2, ..., a_n and a number k. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least k elements that are equal to their indices, i.βe. the resulting sequence b_1, b_2, ..., b_m will contain at least k indices i such that b_i = i. | Input: ['4', '7 6', '1 1 2 3 4 5 6', '5 2', '5 1 3 2 3', '5 2', '5 5 5 5 4', '8 4', '1 2 3 3 2 2 5 5', ''] Output:['1', '2', '-1', '2', ''] | [
0,
4
] |
The only difference between this problem and D1 is that you don't have to provide the way to construct the answer in D1, but you have to do it in this problem.There's a table of n * m cells (n rows and m columns). The value of n \cdot m is even.A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).You need to place \frac{nm}{2} dominoes on the table so that exactly k of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table. | Input: ['8', '4 4 2', '2 3 0', '3 2 3', '1 2 0', '2 4 2', '5 2 2', '2 17 16', '2 1 1', ''] Output:['YES', 'accx', 'aegx', 'bega', 'bdda', 'YES', 'aha', 'aha', 'YES', 'zz', 'aa', 'zz', 'NO', 'YES', 'aaza', 'bbza', 'NO', 'YES', 'bbaabbaabbaabbaay', 'ddccddccddccddccy', 'NO', ''] | [
3
] |
The only difference between this problem and D2 is that you don't have to provide the way to construct the answer in this problem, but you have to do it in D2.There's a table of n * m cells (n rows and m columns). The value of n \cdot m is even.A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).You need to find out whether it is possible to place \frac{nm}{2} dominoes on the table so that exactly k of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table. | Input: ['8', '4 4 2', '2 3 0', '3 2 3', '1 2 0', '2 4 2', '5 2 2', '2 17 16', '2 1 1', ''] Output:['YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', ''] | [
3
] |
Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!To compose a story, Stephen wrote out n words consisting of the first 5 lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story.Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.For example, the story consisting of three words "bac", "aaada", "e" is interesting (the letter 'a' occurs 5 times, all other letters occur 4 times in total). But the story consisting of two words "aba", "abcde" is not (no such letter that it occurs more than all other letters in total).You are given a sequence of n words consisting of letters 'a', 'b', 'c', 'd' and 'e'. Your task is to choose the maximum number of them to make an interesting story. If there's no way to make a non-empty story, output 0. | Input: ['6', '3', 'bac', 'aaada', 'e', '3', 'aba', 'abcde', 'aba', '2', 'baba', 'baba', '4', 'ab', 'ab', 'c', 'bc', '5', 'cbdca', 'd', 'a', 'd', 'e', '3', 'b', 'c', 'ca', ''] Output:['3', '2', '0', '2', '3', '2', ''] | [
2
] |
This problem is an extension of the problem "Wonderful Coloring - 1". It has quite many differences, so you should read this statement completely.Recently, Paul and Mary have found a new favorite sequence of integers a_1, a_2, ..., a_n. They want to paint it using pieces of chalk of k colors. The coloring of a sequence is called wonderful if the following conditions are met: each element of the sequence is either painted in one of k colors or isn't painted; each two elements which are painted in the same color are different (i.βe. there's no two equal values painted in the same color); let's calculate for each of k colors the number of elements painted in the color β all calculated numbers must be equal; the total number of painted elements of the sequence is the maximum among all colorings of the sequence which meet the first three conditions. E.βg. consider a sequence a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2] and k=3. One of the wonderful colorings of the sequence is shown in the figure. The example of a wonderful coloring of the sequence a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2] and k=3. Note that one of the elements isn't painted. Help Paul and Mary to find a wonderful coloring of a given sequence a. | Input: ['6', '10 3', '3 1 1 1 1 10 3 10 10 2', '4 4', '1 1 1 1', '1 1', '1', '13 1', '3 1 4 1 5 9 2 6 5 3 5 8 9', '13 2', '3 1 4 1 5 9 2 6 5 3 5 8 9', '13 3', '3 1 4 1 5 9 2 6 5 3 5 8 9', ''] Output:['1 1 0 2 3 2 2 1 3 3', '4 2 1 3', '1', '0 0 1 1 0 1 1 1 0 1 1 1 0', '2 1 2 2 1 1 1 1 2 1 0 2 2', '1 1 3 2 1 3 3 1 2 2 3 2 0', ''] | [
2,
4
] |
This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.Paul and Mary have a favorite string s which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met: each letter of the string is either painted in exactly one color (red or green) or isn't painted; each two letters which are painted in the same color are different; the number of letters painted in red is equal to the number of letters painted in green; the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions. E.βg. consider a string s equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure. The example of a wonderful coloring of the string "kzaaa". Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find k β the number of red (or green, these numbers are equal) letters in a wonderful coloring. | Input: ['5', 'kzaaa', 'codeforces', 'archive', 'y', 'xxxxxx', ''] Output:['2', '5', '3', '0', '1', ''] | [
2
] |
Polycarp must pay exactly n burles at the checkout. He has coins of two nominal values: 1 burle and 2 burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.Thus, Polycarp wants to minimize the difference between the count of coins of 1 burle and 2 burles being used. Help him by determining two non-negative integer values c_1 and c_2 which are the number of coins of 1 burle and 2 burles, respectively, so that the total value of that number of coins is exactly n (i.βe. c_1 + 2 \cdot c_2 = n), and the absolute value of the difference between c_1 and c_2 is as little as possible (i.βe. you must minimize |c_1-c_2|). | Input: ['6', '1000', '30', '1', '32', '1000000000', '5', ''] Output:['334 333', '10 10', '1 0', '10 11', '333333334 333333333', '1 2', ''] | [
2,
3
] |
There is an infinite pond that can be represented with a number line. There are n rocks in the pond, numbered from 1 to n. The i-th rock is located at an integer coordinate a_i. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of the coordinate, so a_1 < a_2 < ... < a_n.A robot frog sits on the rock number s. The frog is programmable. It has a base jumping distance parameter d. There also is a setting for the jumping distance range. If the jumping distance range is set to some integer k, then the frog can jump from some rock to any rock at a distance from d - k to d + k inclusive in any direction. The distance between two rocks is an absolute difference between their coordinates.You are assigned a task to implement a feature for the frog. Given two integers i and k determine if the frog can reach a rock number i from a rock number s performing a sequence of jumps with the jumping distance range set to k. The sequence can be arbitrarily long or empty.You will be given q testcases for that feature, the j-th testcase consists of two integers i and k. Print "Yes" if the i-th rock is reachable and "No" otherwise.You can output "YES" and "NO" in any case (for example, strings "yEs", "yes", "Yes" and 'YES"' will be recognized as a positive answer). | Input: ['7 4 4 5', '1 5 10 13 20 22 28', '4 1', '7 2', '7 3', '3 2', ''] Output:['Yes', 'No', 'Yes', 'Yes', ''] | [
4
] |
You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark.You are asked to replace every question mark with one of the first k lowercase Latin letters in such a way that the following value is maximized.Let f_i be the maximum length substring of string s, which consists entirely of the i-th Latin letter. A substring of a string is a contiguous subsequence of that string. If the i-th letter doesn't appear in a string, then f_i is equal to 0.The value of a string s is the minimum value among f_i for all i from 1 to k.What is the maximum value the string can have? | Input: ['10 2', 'a??ab????b', ''] Output:['4', ''] | [
0,
4
] |
Let's call an integer array a_1, a_2, ..., a_n good if a_i \neq i for each i.Let F(a) be the number of pairs (i, j) (1 <= i < j <= n) such that a_i + a_j = i + j.Let's say that an array a_1, a_2, ..., a_n is excellent if: a is good; l <= a_i <= r for each i; F(a) is the maximum possible among all good arrays of size n. Given n, l and r, calculate the number of excellent arrays modulo 10^9 + 7. | Input: ['4', '3 0 3', '4 -3 5', '42 -33 55', '69 -42 146', ''] Output:['4', '10', '143922563', '698570404', ''] | [
3,
4
] |
Suppose you have two points p = (x_p, y_p) and q = (x_q, y_q). Let's denote the Manhattan distance between them as d(p, q) = |x_p - x_q| + |y_p - y_q|.Let's say that three points p, q, r form a bad triple if d(p, r) = d(p, q) + d(q, r).Let's say that an array b_1, b_2, ..., b_m is good if it is impossible to choose three distinct indices i, j, k such that the points (b_i, i), (b_j, j) and (b_k, k) form a bad triple.You are given an array a_1, a_2, ..., a_n. Calculate the number of good subarrays of a. A subarray of the array a is the array a_l, a_{l + 1}, ..., a_r for some 1 <= l <= r <= n.Note that, according to the definition, subarrays of length 1 and 2 are good. | Input: ['3', '4', '2 4 1 3', '5', '6 9 1 9 6', '2', '13 37', ''] Output:['10', '12', '3', ''] | [
0,
2
] |
You are given a string s of length n consisting only of the characters 0 and 1.You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same order. For example, if you erase the substring 111 from the string 111110, you will get the string 110. When you delete a substring of length l, you get a \cdot l + b points.Your task is to calculate the maximum number of points that you can score in total, if you have to make the given string empty. | Input: ['3', '3 2 0', '000', '5 -2 5', '11001', '6 1 -4', '100111', ''] Output:['6', '15', '-2', ''] | [
2,
3
] |
Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well.For example: the array [5, 3, 1] is beautiful: for a_1, the number a_1 - 2 = 3 exists in the array; for a_2, the number a_2 - 2 = 1 exists in the array; for a_3, the condition a_3 = 1 holds; the array [1, 2, 2, 2, 2] is beautiful: for a_1, the condition a_1 = 1 holds; for every other number a_i, the number a_i - 1 = 1 exists in the array; the array [1, 4] is not beautiful: for a_2, neither a_2 - 2 = 2 nor a_2 - 1 = 3 exists in the array, and a_2!=1; the array [2] is not beautiful: for a_1, neither a_1 - 1 = 1 nor a_1 - 2 = 0 exists in the array, and a_1!=1; the array [2, 1, 3] is beautiful: for a_1, the number a_1 - 1 = 1 exists in the array; for a_2, the condition a_2 = 1 holds; for a_3, the number a_3 - 2 = 1 exists in the array. You are given a positive integer s. Find the minimum possible size of a beautiful array with the sum of elements equal to s. | Input: ['4', '1', '8', '7', '42', ''] Output:['1', '3', '3', '7', ''] | [
2,
3
] |
There is a chessboard of size n by n. The square in the i-th row from top and j-th column from the left is labelled (i,j).Currently, Gregor has some pawns in the n-th row. There are also enemy pawns in the 1-st row. On one turn, Gregor moves one of his pawns. A pawn can move one square up (from (i,j) to (i-1,j)) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from (i,j) to either (i-1,j-1) or (i-1,j+1)) if and only if there is an enemy pawn in that square. The enemy pawn is also removed.Gregor wants to know what is the maximum number of his pawns that can reach row 1?Note that only Gregor takes turns in this game, and the enemy pawns never move. Also, when Gregor's pawn reaches row 1, it is stuck and cannot make any further moves. | Input: ['4', '3', '000', '111', '4', '1111', '1111', '3', '010', '010', '5', '11001', '00000', ''] Output:['3', '4', '0', '0', ''] | [
2
] |
Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is P. Gregor wants to find two bases of P. Formally, Gregor is looking for two integers a and b which satisfy both of the following properties. P \bmod a = P \bmod b, where x \bmod y denotes the remainder when x is divided by y, and 2 <= a < b <= P. Help Gregor find two bases of his favorite prime number! | Input: ['2', '17', '5', ''] Output:['3 5', '2 4'] | [
3
] |
Two painters, Amin and Benj, are repainting Gregor's living room ceiling! The ceiling can be modeled as an n * m grid.For each i between 1 and n, inclusive, painter Amin applies a_i layers of paint to the entire i-th row. For each j between 1 and m, inclusive, painter Benj applies b_j layers of paint to the entire j-th column. Therefore, the cell (i,j) ends up with a_i+b_j layers of paint.Gregor considers the cell (i,j) to be badly painted if a_i+b_j <= x. Define a badly painted region to be a maximal connected component of badly painted cells, i. e. a connected component of badly painted cells such that all adjacent to the component cells are not badly painted. Two cells are considered adjacent if they share a side.Gregor is appalled by the state of the finished ceiling, and wants to know the number of badly painted regions. | Input: ['3 4 11', '9 8 5', '10 6 7 2', ''] Output:['2', ''] | [
2,
3
] |
This is the hard version of the problem. The only difference from the easy version is that in this version the coordinates can be both odd and even.There are n fence-posts at distinct coordinates on a plane. It is guaranteed that no three fence posts lie on the same line.There are an infinite number of cows on the plane, one at every point with integer coordinates.Gregor is a member of the Illuminati, and wants to build a triangular fence, connecting 3 distinct existing fence posts. A cow strictly inside the fence is said to be enclosed. If there are an odd number of enclosed cows and the area of the fence is an integer, the fence is said to be interesting.Find the number of interesting fences. | Input: ['3', '0 0', '2 0', '0 4', ''] Output:['1', ''] | [
0,
3
] |
This is the easy version of the problem. The only difference from the hard version is that in this version all coordinates are even.There are n fence-posts at distinct coordinates on a plane. It is guaranteed that no three fence posts lie on the same line.There are an infinite number of cows on the plane, one at every point with integer coordinates.Gregor is a member of the Illuminati, and wants to build a triangular fence, connecting 3 distinct existing fence posts. A cow strictly inside the fence is said to be enclosed. If there are an odd number of enclosed cows and the area of the fence is an integer, the fence is said to be interesting.Find the number of interesting fences. | Input: ['3', '0 0', '2 0', '0 4', ''] Output:['1', ''] | [
3
] |
Three little pigs from all over the world are meeting for a convention! Every minute, a triple of 3 new pigs arrives on the convention floor. After the n-th minute, the convention ends.The big bad wolf has learned about this convention, and he has an attack plan. At some minute in the convention, he will arrive and eat exactly x pigs. Then he will get away.The wolf wants Gregor to help him figure out the number of possible attack plans that involve eating exactly x pigs for various values of x (1 <= x <= 3n). Two attack plans are considered different, if they occur at different times or if the sets of little pigs to eat are different.Note that all queries are independent, that is, the wolf does not eat the little pigs, he only makes plans! | Input: ['2 3', '1', '5', '6', ''] Output:['9', '6', '1', ''] | [
3
] |
British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."It turns out that positive integers can also be friends with each other! You are given an array a of distinct positive integers. Define a subarray a_i, a_{i+1}, ..., a_j to be a friend group if and only if there exists an integer m >= 2 such that a_i \bmod m = a_{i+1} \bmod m = ... = a_j \bmod m, where x \bmod y denotes the remainder when x is divided by y.Your friend Gregor wants to know the size of the largest friend group in a. | Input: ['4', '5', '1 5 2 4 6', '4', '8 2 5 10', '2', '1000 2000', '8', '465 55 3 54 234 12 45 78', ''] Output:['3', '3', '2', '6', ''] | [
3,
4
] |
When you play the game of thrones, you win, or you die. There is no middle ground.Cersei Lannister, A Game of Thrones by George R. R. MartinThere are n nobles, numbered from 1 to n. Noble i has a power of i. There are also m "friendships". A friendship between nobles a and b is always mutual.A noble is defined to be vulnerable if both of the following conditions are satisfied: the noble has at least one friend, and all of that noble's friends have a higher power. You will have to process the following three types of queries. Add a friendship between nobles u and v. Remove a friendship between nobles u and v. Calculate the answer to the following process. The process: all vulnerable nobles are simultaneously killed, and all their friendships end. Then, it is possible that new nobles become vulnerable. The process repeats itself until no nobles are vulnerable. It can be proven that the process will end in finite time. After the process is complete, you need to calculate the number of remaining nobles.Note that the results of the process are not carried over between queries, that is, every process starts with all nobles being alive! | Input: ['4 3', '2 1', '1 3', '3 4', '4', '3', '1 2 3', '2 3 1', '3', ''] Output:['2', '1', ''] | [
0,
2
] |
You are given an array of positive integers a = [a_0, a_1, ..., a_{n - 1}] (n >= 2).In one step, the array a is replaced with another array of length n, in which each element is the greatest common divisor (GCD) of two neighboring elements (the element itself and its right neighbor; consider that the right neighbor of the (n - 1)-th element is the 0-th element).Formally speaking, a new array b = [b_0, b_1, ..., b_{n - 1}] is being built from array a = [a_0, a_1, ..., a_{n - 1}] such that b_i = \gcd(a_i, a_{(i + 1) \mod n}), where \gcd(x, y) is the greatest common divisor of x and y, and x \mod y is the remainder of x dividing by y. In one step the array b is built and then the array a is replaced with b (that is, the assignment a := b is taking place).For example, if a = [16, 24, 10, 5] then b = [\gcd(16, 24), \gcd(24, 10), \gcd(10, 5), \gcd(5, 16)] = [8, 2, 5, 1]. Thus, after one step the array a = [16, 24, 10, 5] will be equal to [8, 2, 5, 1].For a given array a, find the minimum number of steps after which all values a_i become equal (that is, a_0 = a_1 = ... = a_{n - 1}). If the original array a consists of identical elements then consider the number of steps is equal to 0. | Input: ['5', '4', '16 24 10 5', '4', '42 42 42 42', '3', '4 6 4', '5', '1 2 3 4 5', '6', '9 9 27 9 9 63', ''] Output:['3', '0', '2', '1', '1', ''] | [
0,
4
] |
A sequence of non-negative integers a_1, a_2, ..., a_n is called growing if for all i from 1 to n - 1 all ones (of binary representation) in a_i are in the places of ones (of binary representation) in a_{i + 1} (in other words, a_i \:\&\: a_{i + 1} = a_i, where \& denotes bitwise AND). If n = 1 then the sequence is considered growing as well.For example, the following four sequences are growing: [2, 3, 15, 175] β in binary it's [10_2, 11_2, 1111_2, 10101111_2]; [5] β in binary it's [101_2]; [1, 3, 7, 15] β in binary it's [1_2, 11_2, 111_2, 1111_2]; [0, 0, 0] β in binary it's [0_2, 0_2, 0_2]. The following three sequences are non-growing: [3, 4, 5] β in binary it's [11_2, 100_2, 101_2]; [5, 4, 3] β in binary it's [101_2, 100_2, 011_2]; [1, 2, 4, 8] β in binary it's [0001_2, 0010_2, 0100_2, 1000_2]. Consider two sequences of non-negative integers x_1, x_2, ..., x_n and y_1, y_2, ..., y_n. Let's call this pair of sequences co-growing if the sequence x_1 \oplus y_1, x_2 \oplus y_2, ..., x_n \oplus y_n is growing where \oplus denotes bitwise XOR.You are given a sequence of integers x_1, x_2, ..., x_n. Find the lexicographically minimal sequence y_1, y_2, ..., y_n such that sequences x_i and y_i are co-growing.The sequence a_1, a_2, ..., a_n is lexicographically smaller than the sequence b_1, b_2, ..., b_n if there exists 1 <= k <= n such that a_i = b_i for any 1 <= i < k but a_k < b_k. | Input: ['5', '4', '1 3 7 15', '4', '1 2 4 8', '5', '1 2 3 4 5', '4', '11 13 15 1', '1', '0', ''] Output:['0 0 0 0 ', '0 1 3 7 ', '0 1 0 3 2 ', '0 2 0 14 ', '0 ', ''] | [
2
] |
Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.Every minute exactly one of them does one of two actions: adds a new line to the end of the file or changes one of its lines.Monocarp worked in total for n minutes and performed the sequence of actions [a_1, a_2, ..., a_n]. If a_i = 0, then he adds a new line to the end of the file. If a_i > 0, then he changes the line with the number a_i. Monocarp performed actions strictly in this order: a_1, then a_2, ..., a_n.Polycarp worked in total for m minutes and performed the sequence of actions [b_1, b_2, ..., b_m]. If b_j = 0, then he adds a new line to the end of the file. If b_j > 0, then he changes the line with the number b_j. Polycarp performed actions strictly in this order: b_1, then b_2, ..., b_m.Restore their common sequence of actions of length n + m such that all actions would be correct β there should be no changes to lines that do not yet exist. Keep in mind that in the common sequence Monocarp's actions should form the subsequence [a_1, a_2, ..., a_n] and Polycarp's β subsequence [b_1, b_2, ..., b_m]. They can replace each other at the computer any number of times.Let's look at an example. Suppose k = 3. Monocarp first changed the line with the number 2 and then added a new line (thus, n = 2, \: a = [2, 0]). Polycarp first added a new line and then changed the line with the number 5 (thus, m = 2, \: b = [0, 5]).Since the initial length of the file was 3, in order for Polycarp to change line number 5 two new lines must be added beforehand. Examples of correct sequences of changes, in this case, would be [0, 2, 0, 5] and [2, 0, 0, 5]. Changes [0, 0, 5, 2] (wrong order of actions) and [0, 5, 2, 0] (line 5 cannot be edited yet) are not correct. | Input: ['5', '', '3 2 2', '2 0', '0 5', '', '4 3 2', '2 0 5', '0 6', '', '0 2 2', '1 0', '2 3', '', '5 4 4', '6 0 8 0', '0 7 0 9', '', '5 4 1', '8 7 8 0', '0', ''] Output:['2 0 0 5 ', '0 2 0 6 5 ', '-1', '0 6 0 7 0 8 0 9', '-1', ''] | [
2
] |
A string s of length n (1 <= n <= 26) is called alphabetical if it can be obtained using the following algorithm: first, write an empty string to s (i.e. perform the assignment s := ""); then perform the next step n times; at the i-th step take i-th lowercase letter of the Latin alphabet and write it either to the left of the string s or to the right of the string s (i.e. perform the assignment s := c+s or s := s+c, where c is the i-th letter of the Latin alphabet). In other words, iterate over the n first letters of the Latin alphabet starting from 'a' and etc. Each time we prepend a letter to the left of the string s or append a letter to the right of the string s. Strings that can be obtained in that way are alphabetical.For example, the following strings are alphabetical: "a", "ba", "ab", "bac" and "ihfcbadeg". The following strings are not alphabetical: "z", "aa", "ca", "acb", "xyz" and "ddcba".From the given string, determine if it is alphabetical. | Input: ['11', 'a', 'ba', 'ab', 'bac', 'ihfcbadeg', 'z', 'aa', 'ca', 'acb', 'xyz', 'ddcba', ''] Output:['YES', 'YES', 'YES', 'YES', 'YES', 'NO', 'NO', 'NO', 'NO', 'NO', 'NO', ''] | [
2
] |
There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if: in one move you can go to any of the four adjacent cells sharing a side; visiting the cell F is forbidden (it is an obstacle). | Input: ['7', '', '1 1', '3 3', '2 2', '', '2 5', '2 1', '2 3', '', '1000 42', '1000 1', '1000 1000', '', '1 10', '3 10', '2 10', '', '3 8', '7 8', '3 7', '', '2 1', '4 1', '1 1', '', '1 344', '1 10', '1 1', ''] Output:['4', '6', '41', '4', '4', '2', '334', ''] | [
3
] |
AquaMoon had n strings of length m each. n is an odd number.When AquaMoon was gone, Cirno tried to pair these n strings together. After making \frac{n-1}{2} pairs, she found out that there was exactly one string without the pair!In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions.For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf".Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order.AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? | Input: ['3', '3 5', 'aaaaa', 'bbbbb', 'ccccc', 'aaaaa', 'bbbbb', '3 4', 'aaaa', 'bbbb', 'cccc', 'aabb', 'bbaa', '5 6', 'abcdef', 'uuuuuu', 'kekeke', 'ekekek', 'xyzklm', 'xbcklf', 'eueueu', 'ayzdem', 'ukukuk', ''] Output:['ccccc', 'cccc', 'kekeke', ''] | [
3
] |
AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): She chooses two indices i and j (1 <= i, j <= n), then decreases the i-th element of array a by 1, and increases the j-th element of array a by 1. The resulting values at i-th and j-th index of array a are a_i - 1 and a_j + 1, respectively. Each element of array a must be non-negative after each operation. If i = j this operation doesn't change the array a. AquaMoon wants to make some operations to make arrays a and b equal. Two arrays a and b are considered equal if and only if a_i = b_i for all 1 <=q i <=q n.Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays a and b equal.Please note, that you don't have to minimize the number of operations. | Input: ['4', '4', '1 2 3 4', '3 1 2 4', '2', '1 3', '2 1', '1', '0', '0', '5', '4 3 2 1 0', '0 1 2 3 4', ''] Output:['2', '2 1', '3 1', '-1', '0', '6', '1 4', '1 4', '1 5', '1 5', '2 5', '2 5', ''] | [
0,
2
] |
AquaMoon has three integer arrays a, b, c of length n, where 1 <=q a_i, b_i, c_i <=q n for all i.In order to accelerate her potato farming, she organizes her farm in a manner based on these three arrays. She is now going to complete m operations to count how many potatoes she can get. Each operation will have one of the two types: AquaMoon reorganizes their farm and makes the k-th element of the array a equal to x. In other words, perform the assignment a_k := x. Given a positive integer r, AquaMoon receives a potato for each triplet (i,j,k), such that 1<= i<j<k<= r, and b_{a_i}=a_j=c_{a_k}. Count the number of such triplets. As AquaMoon is busy finding the library, help her complete all of their operations. | Input: ['5 4', '1 2 3 4 5', '2 3 4 5 1', '5 1 2 3 4', '2 5', '1 2 3', '2 4', '2 5', ''] Output:['3', '0', '2', ''] | [
0
] |
Cirno gives AquaMoon a problem. There are m people numbered from 0 to m - 1. They are standing on a coordinate axis in points with positive integer coordinates. They are facing right (i.e. in the direction of the coordinate increase). At this moment everyone will start running with the constant speed in the direction of coordinate increasing. The initial coordinate of the i-th person on the line is x_i, and the speed of the i-th person is v_i. So the coordinate of the i-th person at the moment t will be x_i + t \cdot v_i.Cirno captured the coordinates of m people in k consecutive integer moments from 0 to k - 1. In every moment, the coordinates of m people were recorded in arbitrary order.To make the problem more funny, Cirno modified one coordinate at the moment y (0 < y < k-1) to a different integer.AquaMoon wants to find the moment y and the original coordinate p before the modification. Actually, she is not a programmer at all. So she wasn't able to solve it. Can you help her? | Input: ['5 7', '6 9 9 6 9', '10 7 10 8 10', '11 11 11 10 8', '12 12 12 12 9', '14 13 12 10 13', '11 14 16 14 14', '12 15 18 15 15', ''] Output:['4 13', ''] | [
3
] |
Cirno has prepared n arrays of length n each. Each array is a permutation of n integers from 1 to n. These arrays are special: for all 1 <=q i <=q n, if we take the i-th element of each array and form another array of length n with these elements, the resultant array is also a permutation of n integers from 1 to n. In the other words, if you put these n arrays under each other to form a matrix with n rows and n columns, this matrix is a Latin square.Afterwards, Cirno added additional n arrays, each array is a permutation of n integers from 1 to n. For all 1 <=q i <=q n, there exists at least one position 1 <=q k <=q n, such that for the i-th array and the (n + i)-th array, the k-th element of both arrays is the same. Notice that the arrays indexed from n + 1 to 2n don't have to form a Latin square. Also, Cirno made sure that for all 2n arrays, no two arrays are completely equal, i. e. for all pair of indices 1 <=q i < j <=q 2n, there exists at least one position 1 <=q k <=q n, such that the k-th elements of the i-th and j-th array are different.Finally, Cirno arbitrarily changed the order of 2n arrays.AquaMoon calls a subset of all 2n arrays of size n good if these arrays from a Latin square.AquaMoon wants to know how many good subsets exist. Because this number may be particularly large, find it modulo 998\,244\,353. Also, she wants to find any good subset. Can you help her? | Input: ['3', '7', '1 2 3 4 5 6 7', '2 3 4 5 6 7 1', '3 4 5 6 7 1 2', '4 5 6 7 1 2 3', '5 6 7 1 2 3 4', '6 7 1 2 3 4 5', '7 1 2 3 4 5 6', '1 2 3 4 5 7 6', '1 3 4 5 6 7 2', '1 4 5 6 7 3 2', '1 5 6 7 4 2 3', '1 6 7 5 2 3 4', '1 7 6 2 3 4 5', '1 7 2 3 4 5 6', '5', '4 5 1 2 3', '3 5 2 4 1', '1 2 3 4 5', '5 2 4 1 3', '3 4 5 1 2', '2 3 4 5 1', '1 3 5 2 4', '4 1 3 5 2', '2 4 1 3 5', '5 1 2 3 4', '6', '2 3 4 5 6 1', '3 1 2 6 4 5', '6 1 2 3 4 5', '5 6 1 3 2 4', '4 3 6 5 2 1', '5 6 1 2 3 4', '4 5 6 1 2 3', '3 4 5 6 1 2', '1 2 3 4 5 6', '2 5 4 1 6 3', '3 2 5 4 1 6', '1 4 3 6 5 2', ''] Output:['1', '1 2 3 4 5 6 7', '2', '1 3 5 6 10', '4', '1 3 6 7 8 9', ''] | [
0
] |
Cirno gave AquaMoon a chessboard of size 1 * n. Its cells are numbered with integers from 1 to n from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied.In each operation, AquaMoon can choose a cell i with a pawn, and do either of the following (if possible): Move pawn from it to the (i+2)-th cell, if i+2 <=q n and the (i+1)-th cell is occupied and the (i+2)-th cell is unoccupied. Move pawn from it to the (i-2)-th cell, if i-2 >=q 1 and the (i-1)-th cell is occupied and the (i-2)-th cell is unoccupied. You are given an initial state of the chessboard. AquaMoon wants to count the number of states reachable from the initial state with some sequence of operations. But she is not good at programming. Can you help her? As the answer can be large find it modulo 998\,244\,353. | Input: ['6', '4', '0110', '6', '011011', '5', '01010', '20', '10001111110110111000', '20', '00110110100110111101', '20', '11101111011000100010', ''] Output:['3', '6', '1', '1287', '1287', '715', ''] | [
3
] |
Finally, you have defeated Razor and now, you are the Most Wanted street racer. Sergeant Cross has sent the full police force after you in a deadly pursuit. Fortunately, you have found a hiding spot but you fear that Cross and his force will eventually find you. To increase your chances of survival, you want to tune and repaint your BMW M3 GTR.The car can be imagined as a permuted n-dimensional hypercube. A simple n-dimensional hypercube is an undirected unweighted graph built recursively as follows: Take two simple (n-1)-dimensional hypercubes one having vertices numbered from 0 to 2^{n-1}-1 and the other having vertices numbered from 2^{n-1} to 2^{n}-1. A simple 0-dimensional Hypercube is just a single vertex. Add an edge between the vertices i and i+2^{n-1} for each 0<=q i < 2^{n-1}. A permuted n-dimensional hypercube is formed by permuting the vertex numbers of a simple n-dimensional hypercube in any arbitrary manner.Examples of a simple and permuted 3-dimensional hypercubes are given below: Note that a permuted n-dimensional hypercube has the following properties: There are exactly 2^n vertices. There are exactly n\cdot 2^{n-1} edges. Each vertex is connected to exactly n other vertices. There are no self-loops or duplicate edges. Let's denote the permutation used to generate the permuted n-dimensional hypercube, representing your car, from a simple n-dimensional hypercube by P. Before messing up the functionalities of the car, you want to find this permutation so that you can restore the car if anything goes wrong. But the job isn't done yet.You have n different colours numbered from 0 to n-1. You want to colour the vertices of this permuted n-dimensional hypercube in such a way that for each and every vertex u satisfying 0<=q u < 2^n and for each and every colour c satisfying 0<=q c < n, there is at least one vertex v adjacent to u having a colour c. In other words, from each and every vertex, it must be possible to reach a vertex of any colour by just moving to an adjacent vertex. Given the permuted n-dimensional hypercube, find any valid permutation P and colouring. | Input: ['3', '1', '0 1', '2', '0 1', '1 2', '2 3', '3 0', '3', '0 1', '0 5', '0 7', '1 2', '1 4', '2 5', '2 6', '3 5', '3 6', '3 7', '4 6', '4 7', ''] Output:['0 1', '0 0', '0 1 3 2', '0 0 1 1', '5 3 0 7 2 6 1 4', '-1', ''] | [
2,
3
] |
This is the hard version of the problem. The only difference is that here 2<=q k<=q 100. You can make hacks only if both the versions of the problem are solved.This is an interactive problem!Every decimal number has a base k equivalent. The individual digits of a base k number are called k-its. Let's define the k-itwise XOR of two k-its a and b as (a + b)\bmod k.The k-itwise XOR of two base k numbers is equal to the new number formed by taking the k-itwise XOR of their corresponding k-its. The k-itwise XOR of two decimal numbers a and b is denoted by a\oplus_{k} b and is equal to the decimal representation of the k-itwise XOR of the base k representations of a and b. All further numbers used in the statement below are in decimal unless specified.You have hacked the criminal database of Rockport Police Department (RPD), also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between 0 and n-1 inclusive. So, you have decided to guess it. Luckily, you can try at most n times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was x, and you guess a different number y, then the system changes the password to a number z such that x\oplus_{k} z=y. Guess the password and break into the system. | Input: ['2', '5 2', '', '0', '', '0', '', '1', '5 3', '', '0', '', '0', '', '1', ''] Output:['3', '', '4', '', '5', '', '', '1', '', '4', '', '6', '', ''] | [
0,
3
] |
This is the easy version of the problem. The only difference is that here k=2. You can make hacks only if both the versions of the problem are solved.This is an interactive problem.Every decimal number has a base k equivalent. The individual digits of a base k number are called k-its. Let's define the k-itwise XOR of two k-its a and b as (a + b)\bmod k.The k-itwise XOR of two base k numbers is equal to the new number formed by taking the k-itwise XOR of their corresponding k-its. The k-itwise XOR of two decimal numbers a and b is denoted by a\oplus_{k} b and is equal to the decimal representation of the k-itwise XOR of the base k representations of a and b. All further numbers used in the statement below are in decimal unless specified. When k = 2 (it is always true in this version), the k-itwise XOR is the same as the bitwise XOR.You have hacked the criminal database of Rockport Police Department (RPD), also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between 0 and n-1 inclusive. So, you have decided to guess it. Luckily, you can try at most n times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was x, and you guess a different number y, then the system changes the password to a number z such that x\oplus_{k} z=y. Guess the password and break into the system. | Input: ['1', '5 2', '', '0', '', '0', '', '1', ''] Output:['3', '', '4', '', '5', '', ''] | [
3
] |