Problem ID
stringlengths
2
6
Problem Description
stringlengths
0
7.52k
Rating
float64
800
3.5k
math
bool
2 classes
greedy
bool
2 classes
implementation
bool
2 classes
dp
bool
2 classes
data structures
bool
2 classes
constructive algorithms
bool
2 classes
brute force
bool
2 classes
binary search
bool
2 classes
sortings
bool
2 classes
graphs
bool
2 classes
__index_level_0__
int64
3
9.98k
56C
Problem - 56C - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags data structures expression parsing implementation *1700 No tag edit access β†’ Contest materials ") , the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description. For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself. In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is _s_ writes a letter to another person whose name is also _s_. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates). Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it. Input The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length. Output Print a single number β€” the number of uncomfortable situations in the company. Examples Input MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... Output 3 Input A:A.. Output 1 Input A:C:C:C:C..... Output 6
1,700
false
false
true
false
true
false
false
false
false
false
9,693
23C
Problem - 23C - Codeforces =============== xa0 . The sum of _N_ in all the tests in the input doesn't exceed 105. All the input numbers are integer. Output For each test output two lines. In the first line output YES, if it's possible to choose _N_ boxes, or NO otherwise. If the answer is positive output in the second line _N_ numbers β€” indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space. Examples Input 2 2 10 15 5 7 20 18 1 0 0 Output YES 1 3 YES 1
2,500
false
false
false
false
false
true
false
false
true
false
9,881
1886A
Monocarp has an integer $$$n$$$. He wants to represent his number as a sum of three distinct positive integers $$$x$$$, $$$y$$$, and $$$z$$$. Additionally, Monocarp wants none of the numbers $$$x$$$, $$$y$$$, and $$$z$$$ to be divisible by $$$3$$$. Your task is to help Monocarp to find any valid triplet of distinct positive integers $$$x$$$, $$$y$$$, and $$$z$$$, or report that such a triplet does not exist. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of testcases. The only line of each testcase contains a single integer $$$n$$$ ($$$1 le n le 10^{9}$$$). Output For each testcase, if there is no valid triplet $$$x$$$, $$$y$$$, and $$$z$$$, print NO on the first line. Otherwise, print YES on the first line. On the second line, print any valid triplet of distinct positive integers $$$x$$$, $$$y$$$, and $$$z$$$ such that $$$x + y + z = n$$$, and none of the printed numbers are divisible by $$$3$$$. If there are multiple valid triplets, you can print any of them. Example Output YES 4 5 1 NO YES 2 8 5 NO Note In the first testcase, one of the valid triplets is $$$x = 4$$$, $$$y = 5$$$, $$$z = 1$$$. None of these numbers are divisible by three, and $$$4 + 5 + 1 = 10$$$. In the second testcase, there is no valid triplet. In the third testcase, one of the valid triplets is $$$x = 2$$$, $$$y = 8$$$, $$$z = 5$$$. None of these numbers are divisible by three, and $$$2 + 8 + 5 = 15$$$. In the fourth testcase, there is no valid triplet.
800
true
false
false
false
false
true
true
false
false
false
977
2038G
This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin β€” System.out.flush(), and in Python β€” sys.stdout.flush(). The jury has a string $$$s$$$ consisting of characters 0 and/or 1. The length of this string is $$$n$$$. You can ask the following queries: $$$1$$$ $$$t$$$ β€” "how many times does $$$t$$$ appear in $$$s$$$ as a contiguous substring?" Here, $$$t$$$ should be a string consisting of characters 0 and/or 1; its length should be at least $$$1$$$ and at most $$$n$$$. For example, if the string $$$s$$$ is 111011 and the string $$$t$$$ is 11, the response to the query is $$$3$$$. You have to guess at least one character in the string $$$s$$$ by asking no more than $$$3$$$ queries. Note that giving the answer does not count as a query. In every test and in every test case, the string $$$s$$$ is fixed beforehand. Interaction Initially, the jury program sends one integer $$$t$$$ ($$$1 le t le 1000$$$) β€” the number of test cases. At the start of each test case, the jury program sends one integer $$$n$$$ ($$$2 le n le 50$$$) β€” the length of the string. After that, your program can submit queries to the jury program by printing the following line (do not forget to flush the output after printing a line!): $$$1$$$ $$$t$$$ means asking a query "how many times does $$$t$$$ appear in $$$s$$$ as a contiguous substring?" For every query, the jury prints one integer on a separate line. It is either: the answer to your query, if the query is correct, and you haven't exceeded the query limit; or the integer $$$-1$$$, if your query is incorrect (for example, the constraint $$$1 le t le n$$$ is not met or the string $$$t$$$ contains characters other than 0 and 1) or if you have asked too many queries while processing the current test case. To submit the answer, your program should send a line in the following format (do not forget to flush the output after printing a line!): $$$0$$$ $$$i$$$ $$$c$$$, where $$$1 le i le n$$$ and $$$c$$$ is either 0 or 1, meaning that $$$s_i = c$$$. If your guess is correct, the jury program will print one integer $$$1$$$ on a separate line, indicating that you may proceed to the next test case (or terminate the program, if it was the last test case) and that the number of queries you have asked is reset. If it is not correct, the jury program will print one integer $$$-1$$$ on a separate line. After your program receives $$$-1$$$ as the response, it should immediately terminate. This will lead to your submission receiving the verdict "Wrong Answer". If your program does not terminate, the verdict of your submission is undefined. Note In the example, there are $$$3$$$ test cases: 101, 11 and 10. Note that everything after the // sign is a comment that explains which line means what in the interaction. The jury program won't print these comments in the actual problem, and you shouldn't print them. The empty lines are also added for your convenience, the jury program won't print them, and your solution should not print any empty lines.
1,900
false
false
true
false
false
true
false
false
false
false
32
171C
Problem - 171C - Codeforces =============== xa0 . Output Output a single integer. Examples Input 4 1 2 3 4 Output 30
2,000
false
false
true
false
false
false
false
false
false
false
9,184
1599A
You are given an array $$$A$$$ of length $$$N$$$ weights of masses $$$A_1$$$, $$$A_2$$$...$$$A_N$$$.u202fNo two weights have the same mass. You can put every weight on one side of the balance (left or right).u202fYouu202fdon't have to putu202fweightsu202fin order $$$A_1$$$,...,$$$A_N$$$.u202fThere is also au202fstring $$$S$$$u202fconsisting of characters "L" and "R",u202fmeaning that after putting theu202f$$$i-th$$$u202fweight (not $$$A_i$$$, butu202f$$$i-th$$$u202fweight of your choice) left or right side of the balance should be heavier. Find the order of putting the weights on the balance such that rules of string $$$S$$$ are satisfied. Input The first line contains one integer $$$N$$$ ($$$1 leq N leq 2*10^5$$$) - the length of the array $$$A$$$ The second line contains $$$N$$$ distinct integers: $$$A_1$$$, $$$A_2$$$,...,$$$A_N$$$ ($$$1 leq A_i leq 10^9$$$) - the weights given Theu202fthirdu202flineu202fcontainsu202fstringu202f$$$S$$$u202fofu202flengthu202f$$$N$$$u202fconsistingu202fonlyu202fofu202flettersu202f"L"u202fandu202f"R"u202f- string determining which side of the balance should be heavier after putting the $$$i-th$$$ weight of your choice Output The output contains $$$N$$$ lines. In every line, you should print one integer and one letter - integer representing the weight you are putting on the balance in that move and the letter representing the side of the balance where you are putting the weight. If there is no solution, printu202f$$$-1$$$. Example Output 3 L 2 R 8 R 13 L 7 L Note Explanation for the test case: afteru202fthe 1st weight: 3 Lu202f(leftu202fside is heavier) after the 2nd weight: 2 R (leftu202fside is heavier) after the 3rd weight: 8 R (rightu202fside is heavier) after the 4th weight: 13 L (leftu202fside is heavier) after the 5th weight: 7 L (leftu202fside is heavier) So, the rules given by stringu202f$$$S$$$u202fare fulfilled and our order of putting the weights is correct.
2,600
false
true
false
false
false
true
false
false
false
false
2,664
1612G
You are given an array $$$c = [c_1, c_2, dots, c_m]$$$. An array $$$a = [a_1, a_2, dots, a_n]$$$ is constructed in such a way that it consists of integers $$$1, 2, dots, m$$$, and for each $$$i in [1,m]$$$, there are exactly $$$c_i$$$ occurrences of integer $$$i$$$ in $$$a$$$. So, the number of elements in $$$a$$$ is exactly $$$sumlimits_{i=1}^{m} c_i$$$. Let's define for such array $$$a$$$ the value $$$f(a)$$$ as $$$$$$f(a) = sum_{substack{1 le i < j le n a_i = a_j}}{j - i}.$$$$$$ In other words, $$$f(a)$$$ is the total sum of distances between all pairs of equal elements. Your task is to calculate the maximum possible value of $$$f(a)$$$ and the number of arrays yielding the maximum possible value of $$$f(a)$$$. Two arrays are considered different, if elements at some position differ. Input The first line contains a single integer $$$m$$$ ($$$1 le m le 5 cdot 10^5$$$)xa0β€” the size of the array $$$c$$$. The second line contains $$$m$$$ integers $$$c_1, c_2, dots, c_m$$$ ($$$1 le c_i le 10^6$$$)xa0β€” the array $$$c$$$. Output Print two integersxa0β€” the maximum possible value of $$$f(a)$$$ and the number of arrays $$$a$$$ with such value. Since both answers may be too large, print them modulo $$$10^9 + 7$$$. Examples Input 7 123 451 234 512 345 123 451 Output 339854850 882811119 Note In the first example, all possible arrays $$$a$$$ are permutations of $$$[1, 2, 3, 4, 5, 6]$$$. Since each array $$$a$$$ will have $$$f(a) = 0$$$, so maximum value is $$$f(a) = 0$$$ and there are $$$6! = 720$$$ such arrays. In the second example, the only possible array consists of $$$10^6$$$ ones and its $$$f(a) = sumlimits_{1 le i < j le 10^6}{j - i} = 166,666,666,666,500,000$$$ and $$$166,666,666,666,500,000 bmod{10^9 + 7} = 499,833,345$$$.
2,500
false
true
false
false
false
true
false
false
true
false
2,577
1046F
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency. These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal. Input First line contains number $$$N$$$ ($$$1 leq N leq 200,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 leq a_i leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains two numbers $$$x$$$, $$$f$$$ ($$$1 leq f < x leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction. Output Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal. Note Alice can make two transactions in a following way: 0. 13 7 6 (initial state) 1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies) 2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi) Since cost per transaction is 2 satoshies, total fee is 4.
1,400
false
false
true
false
false
false
false
false
false
false
5,459
979B
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons. A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice. The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure. Could you find out who is going to be the winner if they all play optimally? Input The first line contains an integer $$$n$$$ ($$$0 leq n leq 10^{9}$$$)xa0β€” the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors. Output Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". Examples Input 7 treasurehunt threefriends hiCodeforces Input 15 foPaErcvJ mZaxowpbt mkuOlaHRE Note In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro. In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
1,800
false
true
false
false
false
false
false
false
false
false
5,810
1913A
Monocarp is a great solver of adhoc problems. Recently, he participated in an Educational Codeforces Round, and gained rating! Monocarp knew that, before the round, his rating was $$$a$$$. After the round, it increased to $$$b$$$ ($$$b > a$$$). He wrote both values one after another to not forget them. However, he wrote them so close to each other, that he can't tell now where the first value ends and the second value starts. Please, help him find some values $$$a$$$ and $$$b$$$ such that: neither of them has a leading zero; both of them are strictly greater than $$$0$$$; $$$b > a$$$; they produce the given value $$$ab$$$ when written one after another. If there are multiple answers, you can print any of them. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of testcases. The only line of each testcase consists of a single string $$$ab$$$ of length from $$$2$$$ to $$$8$$$ that: consists only of digits; doesn't start with a zero. Output For each testcase, determine if such values $$$a$$$ and $$$b$$$ exist. If they don't, print -1. Otherwise, print two integers $$$a$$$ and $$$b$$$. If there are multiple answers, you can print any of them. Example Input 5 20002001 391125 200200 2001000 12 Output 2000 2001 39 1125 -1 200 1000 1 2 Note In the second testcase, printing $$$3$$$ and $$$91125$$$ is also valid. In the third testcase, $$$20$$$ and $$$0200$$$ is not valid, because $$$b$$$ has a leading zero. $$$200$$$ and $$$200$$$ is not valid, because $$$200$$$ is not strictly greater than $$$200$$$.
800
false
false
true
false
false
false
false
false
false
false
825
1341B
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $$$k$$$ ($$$k ge 3$$$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights $$$a_1, a_2, dots, a_n$$$ in order from left to right ($$$k le n$$$). It is guaranteed that neighboring heights are not equal to each other (that is, $$$a_i e a_{i+1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n-1$$$). Peaks of mountains on the segment $$$[l,r]$$$ (from $$$l$$$ to $$$r$$$) are called indexes $$$i$$$ such that $$$l < i < r$$$, $$$a_{i - 1} < a_i$$$ and $$$a_i > a_{i + 1}$$$. It is worth noting that the boundary indexes $$$l$$$ and $$$r$$$ for the segment are not peaks. For example, if $$$n=8$$$ and $$$a=[3,1,4,1,5,9,2,6]$$$, then the segment $$$[1,8]$$$ has only two peaks (with indexes $$$3$$$ and $$$6$$$), and there are no peaks on the segment $$$[3, 6]$$$. To break the door, Nastya throws it to a segment $$$[l,l+k-1]$$$ of consecutive mountains of length $$$k$$$ ($$$1 le l le n-k+1$$$). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to $$$p+1$$$, where $$$p$$$ is the number of peaks on the segment $$$[l,l+k-1]$$$. Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains $$$[l, l+k-1]$$$ that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value $$$l$$$ is minimal. Formally, you need to choose a segment of mountains $$$[l, l+k-1]$$$ that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value $$$l$$$. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$) xa0β€” the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 leq k leq n leq 2 cdot 10^5$$$) xa0β€” the number of mountains and the length of the door. The second line of the input data set contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$0 leq a_i leq 10 ^ 9$$$, $$$a_i eq a_{i + 1}$$$) xa0β€” the heights of mountains. It is guaranteed that the sum of $$$n$$$ over all the test cases will not exceed $$$2 cdot 10^5$$$. Output For each test case, output two integers $$$t$$$ and $$$l$$$ xa0β€” the maximum number of parts that the door can split into, and the left border of the segment of length $$$k$$$ that the door should be reset to. Example Input 5 8 6 1 2 4 1 2 4 1 2 5 3 3 2 3 2 1 10 4 4 3 4 3 2 3 2 1 0 1 15 7 3 7 4 8 2 3 4 5 21 2 3 4 2 1 3 7 5 1 2 3 4 5 6 1 Output 3 2 2 2 2 1 3 1 2 3 Note In the first example, you need to select a segment of mountains from $$$2$$$ to $$$7$$$. In this segment, the indexes $$$3$$$ and $$$6$$$ are peaks, so the answer is $$$3$$$ (only $$$2$$$ peaks, so the door will break into $$$3$$$ parts). It is not difficult to notice that the mountain segments $$$[1, 6]$$$ and $$$[3, 8]$$$ are not suitable since they only have a $$$1$$$ peak (for the first segment, the $$$6$$$ index is not a peak, and for the second segment, the $$$3$$$ index is not a peak). In the second example, you need to select a segment of mountains from $$$2$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts). In the third example, you need to select a segment of mountains from $$$1$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts). You can see that on the segments $$$[2, 5]$$$, $$$[4, 7]$$$ and $$$[5, 8]$$$ the number of peaks is also $$$1$$$, but these segments have a left border greater than the segment $$$[1, 4]$$$, so they are not the correct answer.
1,300
false
true
true
false
false
false
false
false
false
false
4,000
1101A
Problem - 1101A - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags math *1000 No tag edit access β†’ Contest materials β€” the number of queries. Then $$$q$$$ lines follow, each containing a query given in the format $$$l_i$$$ $$$r_i$$$ $$$d_i$$$ ($$$1 le l_i le r_i le 10^9$$$, $$$1 le d_i le 10^9$$$). $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$ are integers. Output For each query print one integer: the answer to this query. Example Input 5 2 4 2 5 10 4 3 10 1 1 2 3 4 6 5 Output 6 4 1 3 10
1,000
true
false
false
false
false
false
false
false
false
false
5,200
1994G
After winning another Bed Wars game, Masha and Olya wanted to relax and decided to play a new game. Masha gives Olya an array $$$a$$$ of length $$$n$$$ and a number $$$s$$$. Now Olya's task is to find a non-negative number $$$x$$$ such that $$$displaystylesum_{i=1}^{n} a_i oplus x = s$$$. But she is very tired after a tight round, so please help her with this. But this task seemed too simple to them, so they decided to make the numbers larger (up to $$$2^k$$$) and provide you with their binary representation. Input Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of test cases. Then follows the description of the test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n, k, n cdot k le 2 cdot 10^6$$$)xa0β€” the length of the array $$$a$$$ and the length of the binary representation of all numbers. The second line contains a string of length $$$k$$$, consisting of zeros and onesxa0β€” the binary representation of the number $$$s$$$, starting from the most significant bits. The next $$$n$$$ lines also contain strings of length $$$k$$$, consisting of zeros and ones, the $$$i$$$-th of these strings contains the binary representation of the number $$$a_i$$$, starting from the most significant bits. It is guaranteed that the sum of the values $$$n cdot k$$$ for all test cases does not exceed $$$2 cdot 10^6$$$. Output For each test case, output a string of length $$$k$$$ on a separate line, consisting of zeros or onesxa0β€” the binary representation of any suitable number $$$x$$$ ($$$x ge 0$$$), starting from the most significant bits, or $$$-1$$$ if such $$$x$$$ does not exist. Example Input 4 4 5 01011 01110 00110 01100 01111 2 8 00101001 10111111 10011110 5 4 0101 0010 0000 0000 0010 0011 6 5 00011 10110 11001 01010 11100 10011 10000 Output 01110 10011010 0010 -1 Note In the first test case, $$$s = 11, a = [14, 6, 12, 15]$$$, if $$$x = 14$$$, then $$$displaystylesum_{i=1}^{n} a_i oplus x = (14 oplus 14) + (6 oplus 14) + (12 oplus 14) + (15 oplus 14) = 0 + 8 + 2 + 1 = 11 = s$$$. In the second test case, $$$s = 41, a = [191, 158]$$$, if $$$x = 154$$$, then $$$displaystylesum_{i=1}^{n} a_i oplus x = (191 oplus 154) + (158 oplus 154) = 37 + 4 = 41 = s$$$.
2,600
true
false
false
true
false
false
true
false
false
true
299
1923F
You are given a binary string $$$s$$$ of length $$$n$$$ (a string consisting of $$$n$$$ characters, and each character is either 0 or 1). Let's look at $$$s$$$ as at a binary representation of some integer, and name that integer as the value of string $$$s$$$. For example, the value of 000 is $$$0$$$, the value of 01101 is $$$13$$$, "100000" is $$$32$$$ and so on. You can perform at most $$$k$$$ operations on $$$s$$$. Each operation should have one of the two following types: SWAP: choose two indices $$$i < j$$$ in $$$s$$$ and swap $$$s_i$$$ with $$$s_j$$$; SHRINK-REVERSE: delete all leading zeroes from $$$s$$$ and reverse $$$s$$$. For example, after you perform SHRINK-REVERSE on 000101100, you'll get 001101. What is the minimum value of $$$s$$$ you can achieve by performing at most $$$k$$$ operations on $$$s$$$? Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 le n le 5 cdot 10^5$$$; $$$1 le k le n$$$)xa0β€” the length of the string $$$s$$$ and the maximum number of operations. The second line contains the string $$$s$$$ of length $$$n$$$ consisting of characters 0 and/or 1. Additional constraint on the input: $$$s$$$ contains at least one 1. Output Print a single integerxa0β€” the minimum value of $$$s$$$ you can achieve using no more than $$$k$$$ operations. Since the answer may be too large, print it modulo $$$10^{9} + 7$$$. Note that you need to minimize the original value, not the remainder. Examples Input 30 30 111111111111111111111111111111 Note In the first example, one of the optimal strategies is the following: 1. 10010010 $$$xrightarrow{ exttt{SWAP}}$$$ 00010110; 2. 00010110 $$$xrightarrow{ exttt{SWAP}}$$$ 00000111. The value of 00000111 is $$$7$$$. In the second example, one of the optimal strategies is the following: 1. 01101000 $$$xrightarrow{ exttt{SHRINK}}$$$ 1101000 $$$xrightarrow{ exttt{REVERSE}}$$$ 0001011; 2. 0001011 $$$xrightarrow{ exttt{SWAP}}$$$ 0000111. The value of 0000111 is $$$7$$$.
2,800
false
true
true
false
false
false
true
true
false
false
747
1103A
Problem - 1103A - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags constructive algorithms implementation *1400 No tag edit access β†’ Contest materials . You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time. Input The only line contains a string $$$s$$$ consisting of zeroes and ones ($$$1 le s le 1000$$$). Zero describes vertical tile, one describes horizontal tile. Output Output $$$s$$$ linesxa0β€” for each tile you should output two positive integers $$$r,c$$$, not exceeding $$$4$$$, representing numbers of smallest row and column intersecting with it. If there exist multiple solutions, print any of them. Example Input 010 Output 1 1 1 2 1 4 Note Following image illustrates the example after placing all three tiles: Then the first row is deleted:
1,400
false
false
true
false
false
true
false
false
false
false
5,187
1623E
A binary tree of $$$n$$$ nodes is given. Nodes of the tree are numbered from $$$1$$$ to $$$n$$$ and the root is the node $$$1$$$. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote $$$l_u$$$ and $$$r_u$$$ as the left and the right child of the node $$$u$$$ respectively, $$$l_u = 0$$$ if $$$u$$$ does not have the left child, and $$$r_u = 0$$$ if the node $$$u$$$ does not have the right child. Each node has a string label, initially is a single character $$$c_u$$$. Let's define the string representation of the binary tree as the concatenation of the labels of the nodes in the in-order. Formally, let $$$f(u)$$$ be the string representation of the tree rooted at the node $$$u$$$. $$$f(u)$$$ is defined as follows: $$$$$$ f(u) = begin{cases} exttt{<empty string>}, & ext{if }u = 0; f(l_u) + c_u + f(r_u) & ext{otherwise}, end{cases} $$$$$$ where $$$+$$$ denotes the string concatenation operation. This way, the string representation of the tree is $$$f(1)$$$. For each node, we can duplicate its label at most once, that is, assign $$$c_u$$$ with $$$c_u + c_u$$$, but only if $$$u$$$ is the root of the tree, or if its parent also has its label duplicated. You are given the tree and an integer $$$k$$$. What is the lexicographically smallest string representation of the tree, if we can duplicate labels of at most $$$k$$$ nodes? 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 e 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 The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k le n le 2 cdot 10^5$$$). The second line contains a string $$$c$$$ of $$$n$$$ lower-case English letters, where $$$c_i$$$ is the initial label of the node $$$i$$$ for $$$1 le i le n$$$. Note that the given string $$$c$$$ is not the initial string representation of the tree. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 le l_i, r_i le n$$$). If the node $$$i$$$ does not have the left child, $$$l_i = 0$$$, and if the node $$$i$$$ does not have the right child, $$$r_i = 0$$$. It is guaranteed that the given input forms a binary tree, rooted at $$$1$$$. Output Print a single line, containing the lexicographically smallest string representation of the tree if at most $$$k$$$ nodes have their labels duplicated. Examples Input 4 3 abab 2 3 0 0 0 4 0 0 Input 8 2 kadracyn 2 5 3 4 0 0 0 0 6 8 0 7 0 0 0 0 Input 8 3 kdaracyn 2 5 0 3 0 4 0 0 6 8 0 7 0 0 0 0 Note The images below present the tree for the examples. The number in each node is the node number, while the subscripted letter is its label. To the right is the string representation of the tree, with each letter having the same color as the corresponding node. Here is the tree for the first example. Here we duplicated the labels of nodes $$$1$$$ and $$$3$$$. We should not duplicate the label of node $$$2$$$ because it would give us the string "bbaaab", which is lexicographically greater than "baaaab". In the second example, we can duplicate the labels of nodes $$$1$$$ and $$$2$$$. Note that only duplicating the label of the root will produce a worse result than the initial string. In the third example, we should not duplicate any character at all. Even though we would want to duplicate the label of the node $$$3$$$, by duplicating it we must also duplicate the label of the node $$$2$$$, which produces a worse result. There is no way to produce string "darkkcyan" from a tree with the initial string representation "darkcyan" :(.
2,500
false
true
false
false
true
false
false
false
false
false
2,501
729B
Theater stage is a rectangular field of size _n_u2009Γ—u2009_m_. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above)xa0β€” left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: there is no actor in the cell the spotlight is placed to; there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. Input The first line contains two positive integers _n_ and _m_ (1u2009≀u2009_n_,u2009_m_u2009≀u20091000)xa0β€” the number of rows and the number of columns in the plan. The next _n_ lines contain _m_ integers, 0 or 1 eachxa0β€” the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. Output Print one integerxa0β€” the number of good positions for placing the spotlight. Examples Input 4 4 0 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 Note In the first example the following positions are good: 1. the (1, 1) cell and right direction; 2. the (1, 1) cell and down direction; 3. the (1, 3) cell and left direction; 4. the (1, 3) cell and down direction; 5. the (1, 4) cell and left direction; 6. the (2, 2) cell and left direction; 7. the (2, 2) cell and up direction; 8. the (2, 2) and right direction; 9. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
1,200
false
false
true
true
false
false
false
false
false
false
6,893
266C
You are given a square matrix consisting of _n_ rows and _n_ columns. We assume that the rows are numbered from 1 to _n_ from top to bottom and the columns are numbered from 1 to _n_ from left to right. Some cells (_n_u2009-u20091 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can apply the following operations to the matrix: 1. Swap _i_-th and _j_-th rows of the matrix; 2. Swap _i_-th and _j_-th columns of the matrix. You are asked to transform the matrix into a special form using these operations. In that special form all the ones must be in the cells that lie below the main diagonal. Cell of the matrix, which is located on the intersection of the _i_-th row and of the _j_-th column, lies below the main diagonal if _i_u2009>u2009_j_. Input The first line contains an integer _n_ (2u2009≀u2009_n_u2009≀u20091000) β€” the number of rows and columns. Then follow _n_u2009-u20091 lines that contain one's positions, one per line. Each position is described by two integers _x__k_,u2009_y__k_ (1u2009≀u2009_x__k_,u2009_y__k_u2009≀u2009_n_), separated by a space. A pair (_x__k_,u2009_y__k_) means that the cell, which is located on the intersection of the _x__k_-th row and of the _y__k_-th column, contains one. It is guaranteed that all positions are distinct. Output Print the description of your actions. These actions should transform the matrix to the described special form. In the first line you should print a non-negative integer _m_ (_m_u2009≀u2009105) β€” the number of actions. In each of the next _m_ lines print three space-separated integers _t_,u2009_i_,u2009_j_ (1u2009≀u2009_t_u2009≀u20092,u20091u2009≀u2009_i_,u2009_j_u2009≀u2009_n_,u2009_i_u2009β‰ u2009_j_), where _t_u2009=u20091 if you want to swap rows, _t_u2009=u20092 if you want to swap columns, and _i_ and _j_ denote the numbers of rows or columns respectively. Please note, that you do not need to minimize the number of operations, but their number should not exceed 105. If there are several solutions, you may print any of them.
2,100
true
true
false
false
false
true
false
false
false
false
8,769
1156G
Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $$$1$$$ to $$$4$$$ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit. There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &. Each line of the program has one of the following formats: <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names; <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program. Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently). You are given a program consisting of $$$n$$$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given. Input The first line contains one integer $$$n$$$ ($$$1 le n le 1000$$$) β€” the number of lines in the program. Then $$$n$$$ lines follow β€” the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces. Output In the first line print $$$k$$$ β€” the minimum number of lines in the equivalent program. Then print $$$k$$$ lines without any whitespaces β€” an equivalent program having exactly $$$k$$$ lines, in the same format it is described in the statement.
2,700
false
true
true
false
false
false
false
false
false
true
4,924
2039A
Shohag has an integer $$$n$$$. Please help him find an increasing integer sequence $$$1 le a_1 lt a_2 lt ldots lt a_n le 100$$$ such that $$$a_i bmod i eq a_j bmod j$$$ $$$^{ ext{βˆ—}}$$$ is satisfied over all pairs $$$1 le i lt j le n$$$. It can be shown that such a sequence always exists under the given constraints. $$$^{ ext{βˆ—}}$$$$$$a bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. For example, $$$7 bmod 3 = 1, 8 bmod 4 = 0$$$ and $$$69 bmod 10 = 9$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 50$$$)xa0β€” the number of test cases. The first and only line of each test case contains an integer $$$n$$$ ($$$2 le n le 50$$$). Output For each test case, print $$$n$$$ integersxa0β€” the integer sequence that satisfies the conditions mentioned in the statement. If there are multiple such sequences, output any. Example Output 2 7 8 2 3 32 35 69 95 Note In the first test case, the sequence is increasing, values are from $$$1$$$ to $$$100$$$ and each pair of indices satisfies the condition mentioned in the statement: For pair $$$(1, 2)$$$, $$$a_1 bmod 1 = 2 bmod 1 = 0$$$, and $$$a_2 bmod 2 = 7 bmod 2 = 1$$$. So they are different. For pair $$$(1, 3)$$$, $$$a_1 bmod 1 = 2 bmod 1 = 0$$$, and $$$a_3 bmod 3 = 8 bmod 3 = 2$$$. So they are different. For pair $$$(2, 3)$$$, $$$a_2 bmod 2 = 7 bmod 2 = 1$$$, and $$$a_3 bmod 3 = 8 bmod 3 = 2$$$. So they are different. Note that you do not necessarily have to print the exact same sequence, you can print any other sequence as long as it satisfies the necessary conditions.
800
false
false
false
false
false
true
false
false
false
false
24
1545D
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 This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the β€” the number of people and the number of recorded moments. The next $$$k$$$ lines contain captured positions. $$$i$$$-th of these lines contains $$$m$$$ integers between $$$1$$$ and $$$10^6$$$ (inclusive), representing positions captured by Cirno at the moment $$$i-1$$$. The input is guaranteed to be valid (i.e. only one integer was modified to a different value according to the problem statement). Also, it is guaranteed, that $$$1 le v_i le 1000$$$ for all $$$1 leq i leq m$$$. Hack format: The first line should contain two integers $$$m$$$ and $$$k$$$ ($$$5 leq m leq 1000$$$, $$$7 leq k leq 1000$$$) β€” the number of people and the number of moments. In the second line, there should be $$$m$$$ integers $$$x_0, x_1, dots,x_{m - 1}$$$ ($$$1 le x_i le 10^6$$$), where $$$x_i$$$ is the initial coordinate of the $$$i$$$-th person. In the third line, there should be $$$m$$$ integers $$$v_0, v_1, dots,v_{m - 1}$$$ ($$$1 le v_i le 1000$$$), where $$$v_i$$$ is the speed of the $$$i$$$-th person. It should be true that $$$x_i + (k-1) v_i leq 10^6$$$ for each $$$0 leq i < m$$$. In the next $$$k$$$ lines, each line should contain $$$m$$$ integers. $$$i$$$-th line should contain $$$m$$$ distinct integers $$$p_0, p_1, ldots, p_{m-1}$$$ ($$$0 leq p_j < m$$$). The meaning of these numbers: $$$j$$$-th integer in the input in the $$$i$$$-th moment is the coordinate of the $$$p_{j}$$$-th person. In the last line, there should be three integers $$$y$$$, $$$i$$$, $$$c$$$. Cirno modified the coordinate of the $$$i$$$-th person at the moment $$$y$$$ to $$$c$$$ ($$$1 leq y leq k-2$$$, $$$0 leq i leq m - 1$$$, $$$1 leq c leq 10^6$$$, $$$c eq x_i + y cdot v_i$$$). Note In the first test the initial coordinates of people are $$$9$$$, $$$6$$$, $$$6$$$, $$$9$$$, $$$9$$$ and their speeds are $$$1$$$, $$$2$$$, $$$1$$$, $$$1$$$, $$$1$$$. So, it's easy to see, that at the moment $$$4$$$ one coordinate was modified from $$$13$$$ to $$$12$$$. This is the first test in the hack format: 5 7 9 6 6 9 9 1 2 1 1 1 2 3 4 1 0 0 2 3 1 4 4 3 0 1 2 1 3 4 0 2 1 4 0 2 3 2 4 1 3 0 2 4 1 3 0 4 0 12
3,000
true
false
false
false
false
true
false
false
false
false
2,919
1891B
You are given an array $$$a$$$ of length $$$n$$$, consisting of positive integers, and an array $$$x$$$ of length $$$q$$$, also consisting of positive integers. There are $$$q$$$ modification. On the $$$i$$$-th modification ($$$1 leq i leq q$$$), for each $$$j$$$ ($$$1 leq j leq n$$$), such that $$$a_j$$$ is divisible by $$$2^{x_i}$$$, you add $$$2^{x_i-1}$$$ to $$$a_j$$$. Note that $$$x_i$$$ ($$$1 leq x_i leq 30$$$) is a positive integer not exceeding 30. After all modification queries, you need to output the final array. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 leq n, q leq 10^5$$$) β€”the length of the array $$$a$$$ and the number of queries respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, a_3, ldots, a_n$$$ β€” the elements of the array $$$a$$$ ($$$1 leq a_i leq 10^9$$$). The third line of each test case contains $$$q$$$ integers $$$x_1, x_2, x_3, ldots, x_q$$$ β€” the elements of the array $$$x$$$ ($$$1 leq x_i leq 30$$$), which are the modification queries. It is guaranteed that the sum of $$$n$$$ and the sum of $$$q$$$ across all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output the array after all of the modification queries. Example Input 4 5 3 1 2 3 4 4 2 3 4 7 3 7 8 12 36 48 6 3 10 4 2 5 4 2 2 2 2 2 1 1 1 1 5 5 1 2 4 8 16 5 2 3 4 1 Output 1 2 3 6 6 7 10 14 38 58 6 3 3 3 3 3 3 1 3 7 11 19 Note In the first test case, the first query will add $$$2$$$ to the integers in positions $$$4$$$ and $$$5$$$. After this addition, the array would be $$$[1, 2, 3, 6, 6]$$$. Other operations will not modify the array. In the second test case, the first modification query does not change the array. The second modification query will add $$$8$$$ to the integer in position $$$5$$$, so that the array would look like this: $$$[7, 8, 12, 36, 56, 6, 3]$$$. The third modification query will add $$$2$$$ to the integers in positions $$$2, 3$$$, $$$4$$$ and $$$5$$$. The array would then look like this: $$$[7, 10, 14, 38, 58, 6, 3]$$$.
1,100
true
false
false
false
false
false
true
false
true
false
956
146B
Problem - 146B - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags brute force implementation *1300 No tag edit access β†’ Contest materials ") such that the mask of number _c_ equals _b_. Input The only line contains two integers _a_ and _b_ (1u2009≀u2009_a_,u2009_b_u2009≀u2009105). It is guaranteed that number _b_ is lucky. Output In the only line print a single number β€” the number _c_ that is sought by Petya. Examples Input 1 7 Output 7 Input 100 47 Output 147
1,300
false
false
true
false
false
false
true
false
false
false
9,289
1883C
You are given an array of integers $$$a_1, a_2, ldots, a_n$$$ and a number $$$k$$$ ($$$2 leq k leq 5$$$). In one operation, you can do the following: Choose an index $$$1 leq i leq n$$$, Set $$$a_i = a_i + 1$$$. Find the minimum number of operations needed to make the product of all the numbers in the array $$$a_1 cdot a_2 cdot ldots cdot a_n$$$ divisible by $$$k$$$. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) β€” the number of test cases. Then follows the description of the test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 leq n leq 10^5$$$, $$$2 leq k leq 5$$$) β€” the size of the array $$$a$$$ and the number $$$k$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 leq a_i leq 10$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output the minimum number of operations needed to make the product of all the numbers in the array divisible by $$$k$$$. Example Input 15 2 5 7 3 3 3 7 4 1 5 2 9 7 7 3 9 5 5 5 4 1 2 3 7 4 9 5 1 5 9 5 1 3 4 6 3 6 3 4 6 1 5 3 4 1 5 9 4 4 1 4 1 1 3 4 3 5 3 4 5 8 9 9 3 2 5 1 6 2 5 10 10 4 5 1 6 1 1 2 5 7 7 Output 2 2 1 0 2 0 1 2 0 1 1 4 0 4 3 Note In the first test case, we need to choose the index $$$i = 2$$$ twice. After that, the array will be $$$a = [7, 5]$$$. The product of all the numbers in the array is $$$35$$$. In the fourth test case, the product of the numbers in the array is $$$120$$$, which is already divisible by $$$5$$$, so no operations are needed. In the eighth test case, we can perform two operations by choosing $$$i = 2$$$ and $$$i = 3$$$ in any order. After that, the array will be $$$a = [1, 6, 10]$$$. The product of the numbers in the array is $$$60$$$.
1,000
true
false
false
true
false
false
false
false
false
false
989
201D
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem β€” a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept. You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs. You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words. The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as , where _n_ is the number of words in Lesha's problem and _x_ is the number of inversions in the chosen permutation. Note that the "similarity" _p_ is always a positive integer. The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence. Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise. Input The first line contains a single integer _n_ (1u2009≀u2009_n_u2009≀u200915) β€” the number of words in Lesha's problem. The second line contains _n_ space-separated words β€” the short description of the problem. The third line contains a single integer _m_ (1u2009≀u2009_m_u2009≀u200910) β€” the number of problems in the Torcoder.com archive. Next _m_ lines contain the descriptions of the problems as "_k_ _s_1 _s_2 ... _s__k_", where _k_ (1u2009≀u2009_k_u2009≀u2009500000) is the number of words in the problem and _s__i_ is a word of the problem description. All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015. Output If Lesha's problem is brand new, print string "Brand new problem!" (without quotes). Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character repeated _p_ times, and characters :], where _p_ is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input. Examples Input 4 find the next palindrome 1 10 find the previous palindrome or print better luck next time Input 3 add two numbers 3 1 add 2 two two 3 numbers numbers numbers Input 4 these papers are formulas 3 6 what are these formulas and papers 5 papers are driving me crazy 4 crazy into the night Input 3 add two decimals 5 4 please two decimals add 5 decimals want to be added 4 two add decimals add 4 add one two three 7 one plus two plus three equals six Note Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions β€” pairs of words "numbers" and "add", "numbers" and "two". Sequence _b_1,u2009u2009_b_2,u2009u2009...,u2009u2009_b__k_ is a subsequence of sequence _a_1,u2009_a_2,u2009u2009...,u2009u2009_a__n_ if there exists such a set of indices 1u2009≀u2009_i_1u2009<u2009u2009_i_2u2009<u2009... u2009u2009<u2009_i__k_u2009≀u2009_n_ that _a__i__j_u2009u2009=u2009u2009_b__j_ (in other words, if sequence _b_ can be obtained from _a_ by deleting some of its elements). In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next"). In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence.
2,600
false
false
false
true
false
false
true
false
false
false
9,036
1861E
Problem - 1861E - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags combinatorics dp implementation math *2300 No tag edit access β†’ Contest materials . Output Print one integer β€” the sum of costs of all arrays of length $$$n$$$ consisting of integers from $$$1$$$ to $$$k$$$ taken modulo $$$998244353$$$. Examples Input 10 3 Output 71712 Input 2 2 Output 2 Input 1337 42 Output 524933698
2,300
true
false
true
true
false
false
false
false
false
false
1,115
731C
Arseniy is already grown-up and independent. His mother decided to leave him alone for _m_ days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's _n_ socks is assigned a unique integer from 1 to _n_. Thus, the only thing his mother had to do was to write down two integers _l__i_ and _r__i_ for each of the daysxa0β€” the indices of socks to wear on the day _i_ (obviously, _l__i_ stands for the left foot and _r__i_ for the right). Each sock is painted in one of _k_ colors. When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses _k_ jars with the paintxa0β€” one for each of _k_ colors. Arseniy wants to repaint some of the socks in such a way, that for each of _m_ days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now. The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of _m_ days. Input The first line of input contains three integers _n_, _m_ and _k_ (2u2009≀u2009_n_u2009≀u2009200u2009000, 0u2009≀u2009_m_u2009≀u2009200u2009000, 1u2009≀u2009_k_u2009≀u2009200u2009000)xa0β€” the number of socks, the number of days and the number of available colors respectively. The second line contain _n_ integers _c_1, _c_2, ..., _c__n_ (1u2009≀u2009_c__i_u2009≀u2009_k_)xa0β€” current colors of Arseniy's socks. Each of the following _m_ lines contains two integers _l__i_ and _r__i_ (1u2009≀u2009_l__i_,u2009_r__i_u2009≀u2009_n_, _l__i_u2009β‰ u2009_r__i_)xa0β€” indices of socks which Arseniy should wear during the _i_-th day. Note In the first sample, Arseniy can repaint the first and the third socks to the second color. In the second sample, there is no need to change any colors.
1,600
false
true
false
false
false
false
false
false
false
true
6,874
295B
Greg has a weighed directed graph, consisting of _n_ vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of _n_ steps. On the _i_-th step Greg removes vertex number _x__i_ from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex. Before executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that _d_(_i_,u2009_v_,u2009_u_) is the shortest path between vertices _v_ and _u_ in the graph that formed before deleting vertex _x__i_, then Greg wants to know the value of the following sum: . Help Greg, print the value of the required sum before each step. Input The first line contains integer _n_ (1u2009≀u2009_n_u2009≀u2009500) β€” the number of vertices in the graph. Next _n_ lines contain _n_ integers each β€” the graph adjacency matrix: the _j_-th number in the _i_-th line _a__ij_ (1u2009≀u2009_a__ij_u2009≀u2009105,u2009_a__ii_u2009=u20090) represents the weight of the edge that goes from vertex _i_ to vertex _j_. The next line contains _n_ distinct integers: _x_1,u2009_x_2,u2009...,u2009_x__n_ (1u2009≀u2009_x__i_u2009≀u2009_n_) β€” the vertices that Greg deletes. Output Print _n_ integers β€” the _i_-th number equals the required sum before the _i_-th step. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. Examples Input 4 0 3 1 1 6 0 400 1 2 4 0 1 1 1 1 0 4 1 2 3
1,700
false
false
false
true
false
false
false
false
false
true
8,650
1822G2
This is the hard version of the problem. The only difference is that in this version, $$$a_i le 10^9$$$. For a given sequence of $$$n$$$ integers $$$a$$$, a triple $$$(i, j, k)$$$ is called magic if: $$$1 le i, j, k le n$$$. $$$i$$$, $$$j$$$, $$$k$$$ are pairwise distinct. there exists a positive integer $$$b$$$ such that $$$a_i cdot b = a_j$$$ and $$$a_j cdot b = a_k$$$. Kolya received a sequence of integers $$$a$$$ as a gift and now wants to count the number of magic triples for it. Help him with this task! Note that there are no constraints on the order of integers $$$i$$$, $$$j$$$ and $$$k$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of test cases. The description of the test cases follows. The first line of the test case contains a single integer $$$n$$$ ($$$3 le n le 2 cdot 10^5$$$)xa0β€” the length of the sequence. The second line of the test contains $$$n$$$ integers $$$a_1, a_2, a_3, dots, a_n$$$ ($$$1 le a_i le 10^9$$$)xa0β€” the elements of the sequence $$$a$$$. The sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output a single integerxa0β€” the number of magic triples for the sequence $$$a$$$. Example Input 7 5 1 7 7 2 7 3 6 2 18 9 1 2 3 4 5 6 7 8 9 4 1000 993 986 179 7 1 10 100 1000 10000 100000 1000000 8 1 1 2 2 4 4 8 8 9 1 1 1 2 2 2 4 4 4 Note In the first example, there are $$$6$$$ magic triples for the sequence $$$a$$$xa0β€” $$$(2, 3, 5)$$$, $$$(2, 5, 3)$$$, $$$(3, 2, 5)$$$, $$$(3, 5, 2)$$$, $$$(5, 2, 3)$$$, $$$(5, 3, 2)$$$. In the second example, there is a single magic triple for the sequence $$$a$$$xa0β€” $$$(2, 1, 3)$$$.
2,200
true
false
false
false
true
false
true
false
false
false
1,344
1155B
A telephone number is a sequence of exactly $$$11$$$ digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string $$$s$$$ of length $$$n$$$ ($$$n$$$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $$$s$$$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins. You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves). Input The first line contains one integer $$$n$$$ ($$$13 le n < 10^5$$$, $$$n$$$ is odd) β€” the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$s = n$$$) consisting only of decimal digits. Output If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO. Note In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number. In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.
1,200
false
true
true
false
false
false
false
false
false
false
4,935
160B
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches the sum of digits in its second half. But of course, not every ticket can be lucky. Far from it! Moreover, sometimes one look at a ticket can be enough to say right away that the ticket is not lucky. So, let's consider the following unluckiness criterion that can definitely determine an unlucky ticket. We'll say that a ticket is definitely unlucky if each digit from the first half corresponds to some digit from the second half so that each digit from the first half is strictly less than the corresponding digit from the second one or each digit from the first half is strictly more than the corresponding digit from the second one. Each digit should be used exactly once in the comparisons. In other words, there is such bijective correspondence between the digits of the first and the second half of the ticket, that either each digit of the first half turns out strictly less than the corresponding digit of the second half or each digit of the first half turns out strictly more than the corresponding digit from the second half. For example, ticket 2421 meets the following unluckiness criterion and will not be considered lucky (the sought correspondence is 2u2009>u20091 and 4u2009>u20092), ticket 0135 also meets the criterion (the sought correspondence is 0u2009<u20093 and 1u2009<u20095), and ticket 3754 does not meet the criterion. You have a ticket in your hands, it contains 2_n_ digits. Your task is to check whether it meets the unluckiness criterion. Input The first line contains an integer _n_ (1u2009≀u2009_n_u2009≀u2009100). The second line contains a string that consists of 2_n_ digits and defines your ticket. Output In the first line print "YES" if the ticket meets the unluckiness criterion. Otherwise, print "NO" (without the quotes).
1,100
false
true
false
false
false
false
false
false
true
false
9,234
538C
A tourist hiked along the mountain range. The hike lasted for _n_ days, during each day the tourist noted height above the sea level. On the _i_-th day height was equal to some integer _h__i_. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all _i_'s from 1 to _n_u2009-u20091 the inequality _h__i_u2009-u2009_h__i_u2009+u20091u2009≀u20091 holds. At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits _h__i_u2009-u2009_h__i_u2009+u20091u2009≀u20091. Input The first line contains two space-separated numbers, _n_ and _m_ (1u2009≀u2009_n_u2009≀u2009108, 1u2009≀u2009_m_u2009≀u2009105)xa0β€” the number of days of the hike and the number of notes left in the journal. Next _m_ lines contain two space-separated integers _d__i_ and _h__d__i_ (1u2009≀u2009_d__i_u2009≀u2009_n_, 0u2009≀u2009_h__d__i_u2009≀u2009108)xa0β€” the number of the day when the _i_-th note was made and height on the _d__i_-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all _i_ from 1 to _m_u2009-u20091 the following condition holds: _d__i_u2009<u2009_d__i_u2009+u20091. Output If the notes aren't contradictory, print a single integer β€” the maximum possible height value throughout the whole route. If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes). Note For the first sample, an example of a correct height sequence with a maximum of 2: (0,u20090,u20091,u20092,u20091,u20091,u20090,u20091). In the second sample the inequality between _h_7 and _h_8 does not hold, thus the information is inconsistent.
1,600
true
true
true
false
false
false
true
true
false
false
7,686
73B
Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! _n_ racers take part in the championship, which consists of a number of races. After each race racers are arranged from place first to _n_-th (no two racers share the same place) and first _m_ places are awarded. Racer gains _b__i_ points for _i_-th awarded place, which are added to total points, obtained by him for previous races. It is known that current summary score of racer _i_ is _a__i_ points. In the final standings of championship all the racers will be sorted in descending order of points. Racers with an equal amount of points are sorted by increasing of the name in lexicographical order. Unfortunately, the championship has come to an end, and there is only one race left. Vasya decided to find out what the highest and lowest place he can take up as a result of the championship. Input The first line contains number _n_ (1u2009≀u2009_n_u2009≀u2009105) β€” number of racers. Each of the next _n_ lines contains _s__i_ and _a__i_ β€” nick of the racer (nonempty string, which consist of no more than 20 lowercase Latin letters) and the racer's points (0u2009≀u2009_a__i_u2009≀u2009106). Racers are given in the arbitrary order. The next line contains the number _m_ (0u2009≀u2009_m_u2009≀u2009_n_). Then _m_ nonnegative integer numbers _b__i_ follow. _i_-th number is equal to amount of points for the _i_-th awarded place (0u2009≀u2009_b__i_u2009≀u2009106). The last line contains Vasya's racer nick. Output Output two numbers β€” the highest and the lowest place Vasya can take up as a result of the championship. Examples Input 3 teama 10 teamb 20 teamc 40 2 10 20 teama Input 2 teama 10 teamb 10 2 10 10 teamb
2,000
false
true
false
false
false
false
false
true
true
false
9,601
1995E1
This is the easy version of a problem. The only difference between an easy and a hard version is the constraints on $$$t$$$ and $$$n$$$. You can make hacks only if both versions of the problem are solved. Arthur is giving a lesson to his famous $$$2 n$$$ knights. Like any other students, they're sitting at the desks in pairs, but out of habit in a circle. The knight $$$2 i - 1$$$ is sitting at the desk with the knight $$$2 i$$$. Each knight has intelligence, which can be measured by an integer. Let's denote the intelligence of the $$$i$$$-th knight as $$$a_i$$$. Arthur wants the maximal difference in total intelligence over all pairs of desks to be as small as possible. More formally, he wants to minimize $$$maxlimits_{1 le i le n} (a_{2 i - 1} + a_{2 i}) - minlimits_{1 le i le n} (a_{2 i - 1} + a_{2 i})$$$. However, the Code of Chivalry only allows swapping the opposite knights in the circle, i.e., Arthur can simultaneously perform $$$a_i := a_{i + n}$$$, $$$a_{i + n} := a_i$$$ for any $$$1 le i le n$$$. Arthur can make any number of such swaps. What is the best result he can achieve? Input Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0β€” the number of test cases. It is followed by descriptions of the test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 2000$$$)xa0β€” the number of desks. The second line consists of $$$2n$$$ integers $$$a_1, a_2, ldots, a_{2 n}$$$ ($$$1 le a_i le 10^9$$$)xa0β€” the intelligence values of the knights. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$. Output For each test case, output a single line containing one integerxa0β€” the minimal difference Arthur can achieve. Example Input 5 2 6 6 4 4 1 10 17 3 1 10 1 10 1 10 3 3 3 4 5 5 4 5 1 2 3 4 5 6 7 8 9 10 Note In the first test case, Arthur can swap the second and the fourth knights. Then the total intelligence at both desks will be $$$10$$$. In the third test case, Arthur can make $$$0$$$ operations, which will result in the total intelligence of $$$11$$$ at each of the desks. In the fourth test case, Arthur can swap knights with indices $$$2$$$ and $$$5$$$ and achieve the difference of $$$2$$$. It can be proven that he cannot improve his result any further.
2,700
false
false
false
true
true
false
false
false
false
false
292
1038F
You are given a binary string $$$s$$$. Find the number of distinct cyclical binary strings of length $$$n$$$ which contain $$$s$$$ as a substring. The cyclical string $$$t$$$ contains $$$s$$$ as a substring if there is some cyclical shift of string $$$t$$$, such that $$$s$$$ is a substring of this cyclical shift of $$$t$$$. For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110". Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 40$$$)xa0β€” the length of the target string $$$t$$$. The next line contains the string $$$s$$$ ($$$1 le s le n$$$)xa0β€” the string which must be a substring of cyclical string $$$t$$$. String $$$s$$$ contains only characters '0' and '1'. Output Print the only integerxa0β€” the number of distinct cyclical binary strings $$$t$$$, which contain $$$s$$$ as a substring. Note In the first example, there are three cyclical strings, which contain "0"xa0β€” "00", "01" and "10". In the second example, there are only two such stringsxa0β€” "1010", "0101".
2,900
false
false
false
true
false
false
false
false
false
false
5,503
1680A
An array is beautiful if both of the following two conditions meet: there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum; there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$$$ elements equal to its minimum ($$$1$$$-st, $$$3$$$-rd and $$$7$$$-th) and $$$2$$$ elements equal to its maximum ($$$4$$$-th and $$$5$$$-th). Another example: the array $$$[42, 42, 42]$$$ has $$$3$$$ elements equal to its minimum and $$$3$$$ elements equal to its maximum. Your task is to calculate the minimum possible number of elements in a beautiful array. Input The first line contains one integer $$$t$$$ ($$$1 le t le 5000$$$)xa0β€” the number of test cases. Each test case consists of one line containing four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 le l_1 le r_1 le 50$$$; $$$1 le l_2 le r_2 le 50$$$). Output For each test case, print one integerxa0β€” the minimum possible number of elements in a beautiful array. Example Input 7 3 5 4 6 5 8 5 5 3 3 10 12 1 5 3 3 1 1 2 2 2 2 1 1 6 6 6 6 Note Optimal arrays in the test cases of the example: 1. $$$[1, 1, 1, 1]$$$, it has $$$4$$$ minimums and $$$4$$$ maximums; 2. $$$[4, 4, 4, 4, 4]$$$, it has $$$5$$$ minimums and $$$5$$$ maximums; 3. $$$[1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2]$$$, it has $$$3$$$ minimums and $$$10$$$ maximums; 4. $$$[8, 8, 8]$$$, it has $$$3$$$ minimums and $$$3$$$ maximums; 5. $$$[4, 6, 6]$$$, it has $$$1$$$ minimum and $$$2$$$ maximums; 6. $$$[3, 4, 3]$$$, it has $$$2$$$ minimums and $$$1$$$ maximum; 7. $$$[5, 5, 5, 5, 5, 5]$$$, it has $$$6$$$ minimums and $$$6$$$ maximums.
800
true
false
false
false
false
false
true
false
false
false
2,191
1826F
This is an interactive problem. There are $$$n$$$ distinct hidden points with real coordinates on a two-dimensional Euclidean plane. In one query, you can ask some line $$$ax + by + c = 0$$$ and get the projections of all $$$n$$$ points to this line in some order. The given projections are not exact, please read the interaction section for more clarity. Using the minimum number of queries, guess all $$$n$$$ points and output them in some order. Here minimality means the minimum number of queries required to solve any possible test case with $$$n$$$ points. The hidden points are fixed in advance and do not change throughout the interaction. In other words, the interactor is not adaptive. A projection of point $$$A$$$ to line $$$ax + by + c = 0$$$ is the point on the line closest to $$$A$$$. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 50$$$) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 leq n leq 25$$$) β€” the number of hidden points. For each test case, it is guaranteed that for any pair of hidden points, their $$$x$$$ coordinates differ by at least $$$1$$$. Analogously, $$$y$$$ coordinates of any pair also differ by at least $$$1$$$. Coordinates $$$x$$$ and $$$y$$$ of all hidden points do not exceed $$$100$$$ by absolute value. Interaction To query a line $$$ax + by + c = 0$$$ you should print "? a b c" where all a, b and c are real numbers up to $$$100$$$ by absolute value. For less precision issues numbers $$$a$$$ and $$$b$$$ must satisfy the condition $$$a + b geq 0.1$$$, where $$$a$$$ is the absolute value of $$$a$$$. As an answer to the query you will get $$$n$$$ points in the form "x_1 y_1 ... x_n y_n", where points $$$(x_i, y_i)$$$ are projections to the line $$$ax + by + c = 0$$$. It is guaranteed that each printed point is no more than $$$10^{-4}$$$ away from the real projection point. Every coordinate is printed with at most 9 decimal places. See the interaction example for more clarity. If you ask too many queries, you will get Wrong answer. To output an answer you should print "! x_1 y_1 ... x_n y_n", where $$$(x_i, y_i)$$$ are coordinates of the hidden points. You could output the hidden points in any order. The answer would be considered correct if each of the printed points is no more than $$$10^{-3}$$$ away from the corresponding hidden point. Printing the answer doesn't count as a query. After printing a query or the answer, do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see the documentation for other languages Hacks To make a hack, use the following test format. In the first line output a single integer $$$t$$$ ($$$1 leq t leq 50$$$) β€” the number of test cases. The description of the test cases follows. In the first line of each test case output a single integer $$$n$$$ ($$$2 leq n leq 25$$$). In the next $$$n$$$ lines output two rational numbers each. The numbers in line $$$i$$$ should correspond to $$$x_i$$$ and $$$y_i$$$ respectively. Printed points must comply with all constraints from the input section. Example Input 1 2 1 1 2.5 1 1.500000001 1.500000000 2 2 Output ? 0 1 -1 ? 0.2 -0.2 0 ! 1 3 2.5 0.500000001 Note In the sample the hidden points are $$$(1, 3)$$$ and $$$(2.5, 0.5)$$$ A picture, which describes the first query: A picture, which describes the second query:
2,800
true
false
false
false
false
false
false
false
false
false
1,324
1619F
The Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table and everyone plays individually (i.e. not teams, but individual gamers play). $$$n$$$ people gathered in a room with $$$m$$$ tables ($$$n ge 2m$$$). They want to play the Hat $$$k$$$ times. Thus, $$$k$$$ games will be played at each table. Each player will play in $$$k$$$ games. To do this, they are distributed among the tables for each game. During each game, one player plays at exactly one table. A player can play at different tables. Players want to have the most "fair" schedule of games. For this reason, they are looking for a schedule (table distribution for each game) such that: At any table in each game there are either $$$lfloorfrac{n}{m} floor$$$ people or $$$lceilfrac{n}{m} ceil$$$ people (that is, either $$$n/m$$$ rounded down, or $$$n/m$$$ rounded up). Different numbers of people can play different games at the same table. Let's calculate for each player the value $$$b_i$$$ β€” the number of times the $$$i$$$-th player played at a table with $$$lceilfrac{n}{m} ceil$$$ persons ($$$n/m$$$ rounded up). Any two values of $$$b_i$$$must differ by no more than $$$1$$$. In other words, for any two players $$$i$$$ and $$$j$$$, it must be true $$$b_i - b_j le 1$$$. For example, if $$$n=5$$$, $$$m=2$$$ and $$$k=2$$$, then at the request of the first item either two players or three players should play at each table. Consider the following schedules: First game: $$$1, 2, 3$$$ are played at the first table, and $$$4, 5$$$ at the second one. The second game: at the first table they play $$$5, 1$$$, and at the second xa0β€” $$$2, 3, 4$$$. This schedule is not "fair" since $$$b_2=2$$$ (the second player played twice at a big table) and $$$b_5=0$$$ (the fifth player did not play at a big table). First game: $$$1, 2, 3$$$ are played at the first table, and $$$4, 5$$$ at the second one. The second game: at the first table they play $$$4, 5, 2$$$, and at the second one xa0β€” $$$1, 3$$$. This schedule is "fair": $$$b=[1,2,1,1,1]$$$ (any two values of $$$b_i$$$ differ by no more than $$$1$$$). Find any "fair" game schedule for $$$n$$$ people if they play on the $$$m$$$ tables of $$$k$$$ games. Input The first line of the input contains an integer $$$t$$$ ($$$1 le t le 10^4$$$) β€” the number of test cases in the test. Each test case consists of one line that contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 le n le 2cdot10^5$$$, $$$1 le m le lfloorfrac{n}{2} floor$$$, $$$1 le k le 10^5$$$) β€” the number of people, tables and games, respectively. It is guaranteed that the sum of $$$nk$$$ ($$$n$$$ multiplied by $$$k$$$) over all test cases does not exceed $$$2cdot10^5$$$. Output For each test case print a required schedule xa0β€” a sequence of $$$k$$$ blocks of $$$m$$$ lines. Each block corresponds to one game, a line in a block corresponds to one table. In each line print the number of players at the table and the indices of the players (numbers from $$$1$$$ to $$$n$$$) who should play at this table. If there are several required schedules, then output any of them. We can show that a valid solution always exists. You can output additional blank lines to separate responses to different sets of inputs. Example Output 3 1 2 3 2 4 5 3 4 5 2 2 1 3 2 6 2 3 3 5 1 3 4 7 8 2 2 1 2 2 1 2 2 1
2,000
true
true
false
false
false
true
true
false
false
false
2,530
1945G
Finally, lunchtime! $$$n$$$ schoolchildren have lined up in a long queue at the cook's tent for porridge. The cook will be serving porridge for $$$D$$$ minutes. The schoolchild standing in the $$$i$$$-th position in the queue has a priority of $$$k_i$$$ and eats one portion of porridge in $$$s_i$$$ minutes. At the beginning of each minute of the break, the cook serves the first schoolchild in the queue one portion of porridge, after which the schoolchild goes to eat their portion. If the $$$i$$$-th schoolchild is served a portion at the beginning of the $$$x$$$-th minute, then they will return to the queue at the end of the $$$(x + s_i)$$$-th minute. When the $$$i$$$-th schoolchild returns to the queue, the schoolchildren at the end of the queue whose priority is strictly lower than that of the $$$i$$$-th schoolchild must let them pass. Thus, they will stand in the queue behind the last schoolchild whose priority is not lower than their own. That is, behind the last schoolchild $$$j$$$ with $$$k_j ge k_i$$$. If there is no such schoolchild in the queue, the $$$i$$$-th schoolchild will stand at the front of the queue. If several schoolchildren return at the same time, they will return to the queue in ascending order of their $$$s_i$$$. For example, if $$$n = 3$$$, $$$D = 3$$$, $$$k = [2, 3, 2]$$$, and $$$s = [2, 1, 3]$$$, the serving will occur as follows: At the beginning of minute $$$1$$$, the students in the queue are $$$[1, 2, 3]$$$, and student $$$1$$$ is served porridge; at the beginning of minute $$$2$$$, the students in the queue are $$$[2, 3]$$$, and student $$$2$$$ is served porridge; at the beginning of minute $$$3$$$, the student in the queue is $$$[3]$$$, and student $$$3$$$ is served porridge; at the end of minute $$$3$$$, student $$$2$$$ returns to the queue, and the queue becomes $$$[2]$$$; at the end of minute $$$3$$$, student $$$1$$$ returns to the queue, and the queue becomes $$$[2, 1]$$$, as his priority is lower. Determine the minimum number of minutes after the start of the break that each schoolchild will receive porridge at least once, or report that this will not happen within $$$D$$$ minutes. Input Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0β€” the number of test cases. This is followed by a description of the test cases. The first line of each test case contains two integers $$$n$$$ and $$$D$$$ ($$$1 le n le 2 cdot 10^5$$$, $$$1 le D le 3cdot 10^5$$$)xa0β€” the number of schoolchildren in the queue and the break time, respectively. The next $$$n$$$ lines contain two integers $$$k_i$$$ and $$$s_i$$$ ($$$1 le k_i, s_i, le 10^9$$$)xa0β€” the priority and the time to eat one portion of porridge for the respective schoolchild. The schoolchildren are given in the order they stand in the queue (from the front to the end). It is guaranteed that the sum of the values of $$$n$$$ for all input data sets does not exceed $$$2cdot 10^5$$$. Similarly, it is guaranteed that the sum of the values of $$$D$$$ for all input data sets does not exceed $$$3cdot 10^5$$$. Output For each test case, output the minimum number of minutes after which each schoolchild will receive porridge at least once. If this does not happen within the break time, output $$$-1$$$.
2,500
false
false
true
false
true
true
false
true
false
false
607
1792A
Monocarp is playing a computer game. He's going to kill $$$n$$$ monsters, the $$$i$$$-th of them has $$$h_i$$$ health. Monocarp's character has two spells, either of which he can cast an arbitrary number of times (possibly, zero) and in an arbitrary order: choose exactly two alive monsters and decrease their health by $$$1$$$; choose a single monster and kill it. When a monster's health becomes $$$0$$$, it dies. What's the minimum number of spell casts Monocarp should perform in order to kill all monsters? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 le n le 100$$$)xa0β€” the number of monsters. The second line contains $$$n$$$ integers $$$h_1, h_2, dots, h_n$$$ ($$$1 le h_i le 100$$$)xa0β€” the health of each monster. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 cdot 10^4$$$. Note In the first testcase, the initial health list is $$$[1, 2, 1, 2]$$$. Three spells are casted: the first spell on monsters $$$1$$$ and $$$2$$$xa0β€” monster $$$1$$$ dies, monster $$$2$$$ has now health $$$1$$$, new health list is $$$[0, 1, 1, 2]$$$; the first spell on monsters $$$3$$$ and $$$4$$$xa0β€” monster $$$3$$$ dies, monster $$$4$$$ has now health $$$1$$$, new health list is $$$[0, 1, 0, 1]$$$; the first spell on monsters $$$2$$$ and $$$4$$$xa0β€” both monsters $$$2$$$ and $$$4$$$ die. In the second testcase, the initial health list is $$$[2, 4, 2]$$$. Three spells are casted: the first spell on monsters $$$1$$$ and $$$3$$$xa0β€” both monsters have health $$$1$$$ now, new health list is $$$[1, 4, 1]$$$; the second spell on monster $$$2$$$xa0β€” monster $$$2$$$ dies, new health list is $$$[1, 0, 1]$$$; the first spell on monsters $$$1$$$ and $$$3$$$xa0β€” both monsters $$$1$$$ and $$$3$$$ die. In the third testcase, the initial health list is $$$[1, 2, 3, 4, 5]$$$. Five spells are casted. The $$$i$$$-th of them kills the $$$i$$$-th monster with the second spell. Health list sequence: $$$[1, 2, 3, 4, 5]$$$ $$$ ightarrow$$$ $$$[0, 2, 3, 4, 5]$$$ $$$ ightarrow$$$ $$$[0, 0, 3, 4, 5]$$$ $$$ ightarrow$$$ $$$[0, 0, 0, 4, 5]$$$ $$$ ightarrow$$$ $$$[0, 0, 0, 0, 5]$$$ $$$ ightarrow$$$ $$$[0, 0, 0, 0, 0]$$$.
800
false
true
false
false
false
false
false
false
true
false
1,527
1304F1
The only difference between easy and hard versions is the constraint on $$$k$$$. Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue. Gildong is going to take videos for $$$n$$$ days, starting from day $$$1$$$ to day $$$n$$$. The forest can be divided into $$$m$$$ areas, numbered from $$$1$$$ to $$$m$$$. He'll use the cameras in the following way: On every odd day ($$$1$$$-st, $$$3$$$-rd, $$$5$$$-th, ...), bring the red camera to the forest and record a video for $$$2$$$ days. On every even day ($$$2$$$-nd, $$$4$$$-th, $$$6$$$-th, ...), bring the blue camera to the forest and record a video for $$$2$$$ days. If he starts recording on the $$$n$$$-th day with one of the cameras, the camera records for only one day. Each camera can observe $$$k$$$ consecutive areas of the forest. For example, if $$$m=5$$$ and $$$k=3$$$, he can put a camera to observe one of these three ranges of areas for two days: $$$[1,3]$$$, $$$[2,4]$$$, and $$$[3,5]$$$. Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for $$$n$$$ days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once. Input The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 le n le 50$$$, $$$1 le m le 2 cdot 10^4$$$, $$$1 le k le min(m,20)$$$) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next $$$n$$$ lines contain $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i+1$$$-st line is the number of animals that can be seen on the $$$i$$$-th day in the $$$j$$$-th area. Each number of animals is between $$$0$$$ and $$$1000$$$, inclusive.
2,300
false
false
false
true
true
false
false
false
false
false
4,166
1038A
You are given a string $$$s$$$ of length $$$n$$$, which consists only of the first $$$k$$$ letters of the Latin alphabet. All letters in string $$$s$$$ are uppercase. A subsequence of string $$$s$$$ is a string that can be derived from $$$s$$$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not. A subsequence of $$$s$$$ called good if the number of occurences of each of the first $$$k$$$ letters of the alphabet is the same. Find the length of the longest good subsequence of $$$s$$$. Input The first line of the input contains integers $$$n$$$ ($$$1le n le 10^5$$$) and $$$k$$$ ($$$1 le k le 26$$$). The second line of the input contains the string $$$s$$$ of length $$$n$$$. String $$$s$$$ only contains uppercase letters from 'A' to the $$$k$$$-th letter of Latin alphabet. Output Print the only integerxa0β€” the length of the longest good subsequence of string $$$s$$$. Note In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length. In the second example, none of the subsequences can have 'D', hence the answer is $$$0$$$.
800
false
false
true
false
false
false
false
false
false
false
5,508
1826D
There is a street with $$$n$$$ sights, with sight number $$$i$$$ being $$$i$$$ miles from the beginning of the street. Sight number $$$i$$$ has beauty $$$b_i$$$. You want to start your morning jog $$$l$$$ miles and end it $$$r$$$ miles from the beginning of the street. By the time you run, you will see sights you run by (including sights at $$$l$$$ and $$$r$$$ miles from the start). You are interested in the $$$3$$$ most beautiful sights along your jog, but every mile you run, you get more and more tired. So choose $$$l$$$ and $$$r$$$, such that there are at least $$$3$$$ sights you run by, and the sum of beauties of the $$$3$$$ most beautiful sights minus the distance in miles you have to run is maximized. More formally, choose $$$l$$$ and $$$r$$$, such that $$$b_{i_1} + b_{i_2} + b_{i_3} - (r - l)$$$ is maximum possible, where $$$i_1, i_2, i_3$$$ are the indices of the three maximum elements in range $$$[l, r]$$$. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^5$$$) β€” the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$3 leq n leq 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$b_i$$$ ($$$1 leq b_i leq 10^8$$$) β€” beauties of sights $$$i$$$ miles from the beginning of the street. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^5$$$. Output For each test case output a single integer equal to the maximum value $$$b_{i_1} + b_{i_2} + b_{i_3} - (r - l)$$$ for some running range $$$[l, r]$$$. Example Input 4 5 5 1 4 2 3 4 1 1 1 1 6 9 8 7 6 5 4 7 100000000 1 100000000 1 100000000 1 100000000 Note In the first example, we can choose $$$l$$$ and $$$r$$$ to be $$$1$$$ and $$$5$$$. So we visit all the sights and the three sights with the maximum beauty are the sights with indices $$$1$$$, $$$3$$$, and $$$5$$$ with beauties $$$5$$$, $$$4$$$, and $$$3$$$, respectively. So the total value is $$$5 + 4 + 3 - (5 - 1) = 8$$$. In the second example, the range $$$[l, r]$$$ can be $$$[1, 3]$$$ or $$$[2, 4]$$$, the total value is $$$1 + 1 + 1 - (3 - 1) = 1$$$.
1,700
false
true
false
true
false
false
true
false
false
false
1,326
420B
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat. One day the director of the F company got hold of the records of a part of an online meeting of one successful team. The director watched the record and wanted to talk to the team leader. But how can he tell who the leader is? The director logically supposed that the leader is the person who is present at any conversation during a chat meeting. In other words, if at some moment of time at least one person is present on the meeting, then the leader is present on the meeting. You are the assistant director. Given the 'user logged on'/'user logged off' messages of the meeting in the chronological order, help the director determine who can be the leader. Note that the director has the record of only a continuous part of the meeting (probably, it's not the whole meeting). Input The first line contains integers _n_ and _m_ (1u2009≀u2009_n_,u2009_m_u2009≀u2009105) β€” the number of team participants and the number of messages. Each of the next _m_ lines contains a message in the format: '+ _id_': the record means that the person with number _id_ (1u2009≀u2009_id_u2009≀u2009_n_) has logged on to the meeting. '- _id_': the record means that the person with number _id_ (1u2009≀u2009_id_u2009≀u2009_n_) has logged off from the meeting. Assume that all the people of the team are numbered from 1 to _n_ and the messages are given in the chronological order. It is guaranteed that the given sequence is the correct record of a continuous part of the meeting. It is guaranteed that no two log on/log off events occurred simultaneously. Output In the first line print integer _k_ (0u2009≀u2009_k_u2009≀u2009_n_) β€” how many people can be leaders. In the next line, print _k_ integers in the increasing order β€” the numbers of the people who can be leaders. If the data is such that no member of the team can be a leader, print a single number 0. Examples Input 5 6 + 1 - 1 - 3 + 3 + 4 - 4
1,800
false
false
true
false
false
false
false
false
false
false
8,149
1133F1
You are given an undirected unweighted connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible. Recall that the degree of a vertex is the number of edges incident to it. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 le n le 2 cdot 10^5$$$, $$$n - 1 le m le min(2 cdot 10^5, frac{n(n-1)}{2})$$$) β€” the number of vertices and edges, respectively. The following $$$m$$$ lines denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 le v_i, u_i le n$$$, $$$u_i e v_i$$$), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i.u2009e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the list of edges, and for each pair $$$(v_i, u_i)$$$ the condition $$$v_i e u_i$$$ is satisfied. Output Print $$$n-1$$$ lines describing the edges of a spanning tree such that the maximum degree over all vertices is maximum possible. Make sure that the edges of the printed spanning tree form some subset of the input edges (order doesn't matter and edge $$$(v, u)$$$ is considered the same as the edge $$$(u, v)$$$). If there are multiple possible answers, print any of them. Examples Input 5 5 1 2 2 3 3 5 4 3 1 5 Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Input 8 9 1 2 2 3 2 5 1 6 3 4 6 5 4 5 2 7 5 8 Output 3 2 2 5 8 5 6 1 2 7 1 2 3 4 Note Picture corresponding to the first example: In this example the number of edges of spanning tree incident to the vertex $$$3$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. Picture corresponding to the second example: In this example the number of edges of spanning tree incident to the vertex $$$1$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. Picture corresponding to the third example: In this example the number of edges of spanning tree incident to the vertex $$$2$$$ is $$$4$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. But because this example is symmetric, we can choose almost the same spanning tree but with vertex $$$5$$$ instead of $$$2$$$.
1,600
false
false
false
false
false
false
false
false
false
true
5,049
1385A
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$. Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = max(a, b)$$$, $$$y = max(a, c)$$$ and $$$z = max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$. You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order. Input The first line of the input contains one integer $$$t$$$ ($$$1 le t le 2 cdot 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 le x, y, z le 10^9$$$). Output For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 le a, b, c le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. Example Input 5 3 2 3 100 100 100 50 49 49 10 30 20 1 1000000000 1000000000 Output YES 3 2 1 YES 100 100 100 NO NO YES 1 1 1000000000
800
true
false
false
false
false
false
false
false
false
false
3,747
675A
Vasya likes everything infinite. Now he is studying the properties of a sequence _s_, such that its first element is equal to _a_ (_s_1u2009=u2009_a_), and the difference between any two neighbouring elements is equal to _c_ (_s__i_u2009-u2009_s__i_u2009-u20091u2009=u2009_c_). In particular, Vasya wonders if his favourite integer _b_ appears in this sequence, that is, there exists a positive integer _i_, such that _s__i_u2009=u2009_b_. Of course, you are the person he asks for a help. Input The first line of the input contain three integers _a_, _b_ and _c_ (u2009-u2009109u2009≀u2009_a_,u2009_b_,u2009_c_u2009≀u2009109)xa0β€” the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output If _b_ appears in the sequence _s_ print "YES" (without quotes), otherwise print "NO" (without quotes). Note In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
1,100
true
false
false
false
false
false
false
false
false
false
7,131
1598A
Monocarp is playing a computer game. Now he wants to complete the first level of this game. A level is a rectangular grid of $$$2$$$ rows and $$$n$$$ columns. Monocarp controls a character, which starts in cell $$$(1, 1)$$$xa0β€” at the intersection of the $$$1$$$-st row and the $$$1$$$-st column. Monocarp's character can move from one cell to another in one step if the cells are adjacent by side and/or corner. Formally, it is possible to move from cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ in one step if $$$x_1 - x_2 le 1$$$ and $$$y_1 - y_2 le 1$$$. Obviously, it is prohibited to go outside the grid. There are traps in some cells. If Monocarp's character finds himself in such a cell, he dies, and the game ends. To complete a level, Monocarp's character should reach cell $$$(2, n)$$$xa0β€” at the intersection of row $$$2$$$ and column $$$n$$$. Help Monocarp determine if it is possible to complete the level. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 100$$$) β€” the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$3 le n le 100$$$)xa0β€” the number of columns. The next two lines describe the level. The $$$i$$$-th of these lines describes the $$$i$$$-th line of the levelxa0β€” the line consists of the characters '0' and '1'. The character '0' corresponds to a safe cell, the character '1' corresponds to a trap cell. Additional constraint on the input: cells $$$(1, 1)$$$ and $$$(2, n)$$$ are safe. Output For each test case, output YES if it is possible to complete the level, and NO otherwise. Example Input 4 3 000 000 4 0011 1100 4 0111 1110 6 010101 101010 Note Consider the example from the statement. In the first test case, one of the possible paths is $$$(1, 1) ightarrow (2, 2) ightarrow (2, 3)$$$. In the second test case, one of the possible paths is $$$(1, 1) ightarrow (1, 2) ightarrow (2, 3) ightarrow (2, 4)$$$. In the fourth test case, one of the possible paths is $$$(1, 1) ightarrow (2, 2) ightarrow (1, 3) ightarrow (2, 4) ightarrow (1, 5) ightarrow (2, 6)$$$.
800
false
false
true
true
false
false
true
false
false
false
2,671
949B
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm. Let's consider that initially array contains _n_ numbers from 1 to _n_ and the number _i_ is located in the cell with the index 2_i_u2009-u20091 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all _n_ numbers will appear in the first _n_ cells of the array. For example if _n_u2009=u20094, the array is changing as follows: You have to write a program that allows you to determine what number will be in the cell with index _x_ (1u2009≀u2009_x_u2009≀u2009_n_) after Dima's algorithm finishes. Input The first line contains two integers _n_ and _q_ (1u2009≀u2009_n_u2009≀u20091018, 1u2009≀u2009_q_u2009≀u2009200u2009000), the number of elements in the array and the number of queries for which it is needed to find the answer. Next _q_ lines contain integers _x__i_ (1u2009≀u2009_x__i_u2009≀u2009_n_), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes. Output For each of _q_ queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes. Note The first example is shown in the picture. In the second example the final array is [1,u200912,u20092,u20098,u20093,u200911,u20094,u20099,u20095,u200913,u20096,u200910,u20097].
1,700
true
false
false
false
false
true
false
false
false
false
5,923
1866G
Pak Chanek observes that the carriages of a train is always full on morning departure hours and afternoon departure hours. Therefore, the balance between carriages is needed so that it is not too crowded in only a few carriages. A train contains $$$N$$$ carriages that are numbered from $$$1$$$ to $$$N$$$ from left to right. Carriage $$$i$$$ initially contains $$$A_i$$$ passengers. All carriages are connected by carriage doors, namely for each $$$i$$$ ($$$1leq ileq N-1$$$), carriage $$$i$$$ and carriage $$$i+1$$$ are connected by a two-way door. Each passenger can move between carriages, but train regulation regulates that for each $$$i$$$, a passenger that starts from carriage $$$i$$$ cannot go through more than $$$D_i$$$ doors. Define $$$Z$$$ as the most number of passengers in one same carriage after moving. Pak Chanek asks, what is the minimum possible value of $$$Z$$$? Input The first line contains a single integer $$$N$$$ ($$$1 leq N leq 2cdot10^5$$$) β€” the number of carriages. The second line contains $$$N$$$ integers $$$A_1, A_2, A_3, ldots, A_N$$$ ($$$0 leq A_i leq 10^9$$$) β€” the initial number of passengers in each carriage. The third line contains $$$N$$$ integers $$$D_1, D_2, D_3, ldots, D_N$$$ ($$$0 leq D_i leq N-1$$$) β€” the maximum limit of the number of doors for each starting carriage. Output An integer representing the minimum possible value of $$$Z$$$. Example Input 7 7 4 2 0 5 8 3 4 0 0 1 3 1 3 Note One strategy that is optimal is as follows: $$$5$$$ people in carriage $$$1$$$ move to carriage $$$4$$$ (going through $$$3$$$ doors). $$$3$$$ people in carriage $$$5$$$ move to carriage $$$3$$$ (going through $$$2$$$ doors). $$$2$$$ people in carriage $$$6$$$ move to carriage $$$5$$$ (going through $$$1$$$ door). $$$1$$$ person in carriage $$$6$$$ moves to carriage $$$7$$$ (going through $$$1$$$ door). The number of passengers in each carriage becomes $$$[2,4,5,5,4,5,4]$$$.
2,100
false
true
false
true
true
false
false
true
false
false
1,082
1108E1
The only difference between easy and hard versions is a number of elements in the array. You are given an array $$$a$$$ consisting of $$$n$$$ integers. The value of the $$$i$$$-th element of the array is $$$a_i$$$. You are also given a set of $$$m$$$ segments. The $$$j$$$-th segment is $$$[l_j; r_j]$$$, where $$$1 le l_j le r_j le n$$$. You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $$$a = [0, 0, 0, 0, 0]$$$ and the given segments are $$$[1; 3]$$$ and $$$[2; 4]$$$ then you can choose both of them and the array will become $$$b = [-1, -2, -2, -1, 0]$$$. You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $$$a$$$ and obtain the array $$$b$$$ then the value $$$maxlimits_{i=1}^{n}b_i - minlimits_{i=1}^{n}b_i$$$ will be maximum possible. Note that you can choose the empty set. If there are multiple answers, you can print any. If you are Python programmer, consider using PyPy instead of Python when you submit your code. Input The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 300, 0 le m le 300$$$) β€” the length of the array $$$a$$$ and the number of segments, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$-10^6 le a_i le 10^6$$$), where $$$a_i$$$ is the value of the $$$i$$$-th element of the array $$$a$$$. The next $$$m$$$ lines are contain two integers each. The $$$j$$$-th of them contains two integers $$$l_j$$$ and $$$r_j$$$ ($$$1 le l_j le r_j le n$$$), where $$$l_j$$$ and $$$r_j$$$ are the ends of the $$$j$$$-th segment. Output In the first line of the output print one integer $$$d$$$ β€” the maximum possible value $$$maxlimits_{i=1}^{n}b_i - minlimits_{i=1}^{n}b_i$$$ if $$$b$$$ is the array obtained by applying some subset of the given segments to the array $$$a$$$. In the second line of the output print one integer $$$q$$$ ($$$0 le q le m$$$) β€” the number of segments you apply. In the third line print $$$q$$$ distinct integers $$$c_1, c_2, dots, c_q$$$ in any order ($$$1 le c_k le m$$$) β€” indices of segments you apply to the array $$$a$$$ in such a way that the value $$$maxlimits_{i=1}^{n}b_i - minlimits_{i=1}^{n}b_i$$$ of the obtained array $$$b$$$ is maximum possible. If there are multiple answers, you can print any. Examples Input 5 4 2 -2 3 1 2 1 3 4 5 2 5 1 3 Input 5 4 2 -2 3 1 4 3 5 3 4 2 4 2 5 Note In the first example the obtained array $$$b$$$ will be $$$[0, -4, 1, 1, 2]$$$ so the answer is $$$6$$$. In the second example the obtained array $$$b$$$ will be $$$[2, -3, 1, -1, 4]$$$ so the answer is $$$7$$$. In the third example you cannot do anything so the answer is $$$0$$$.
1,800
false
true
true
false
false
false
true
false
false
false
5,158
687D
Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves. The great kingdom consisted of _n_ cities numbered from 1 to _n_ and _m_ bidirectional roads between these cities, numbered from 1 to _m_. The _i_-th road had length equal to _w__i_. The Great Arya and Pari The Great were discussing about destructing some prefix (all road with numbers less than some _x_) and suffix (all roads with numbers greater than some _x_) of the roads so there will remain only the roads with numbers _l_,u2009_l_u2009+u20091,u2009...,u2009_r_u2009-u20091 and _r_. After that they will divide the great kingdom into two pieces (with each city belonging to exactly one piece) such that the hardness of the division is minimized. The hardness of a division is the maximum length of a road such that its both endpoints are in the same piece of the kingdom. In case there is no such road, the hardness of the division is considered to be equal to u2009-u20091. Historians found the map of the great kingdom, and they have _q_ guesses about the _l_ and _r_ chosen by those great rulers. Given these data, for each guess _l__i_ and _r__i_ print the minimum possible hardness of the division of the kingdom. Input The first line of the input contains three integers _n_, _m_ and _q_ (1u2009≀u2009_n_,u2009_q_u2009≀u20091000, )xa0β€” the number of cities and roads in the great kingdom, and the number of guesses, respectively. The _i_-th line of the following _m_ lines contains three integers _u__i_,u2009_v__i_ and _w__i_ (1u2009u2009≀u2009u2009_u__i_,u2009u2009_v__i_u2009u2009≀u2009u2009_n_,u20090u2009≀u2009_w__i_u2009≀u2009109), denoting the road number _i_ connects cities _u__i_ and _v__i_ and its length is equal _w__i_. It's guaranteed that no road connects the city to itself and no pair of cities is connected by more than one road. Each of the next _q_ lines contains a pair of integers _l__i_ andu2009_r__i_ (1u2009u2009≀u2009_l__i_u2009≀u2009_r__i_u2009≀u2009_m_)xa0β€” a guess from the historians about the remaining roads in the kingdom. Output For each guess print the minimum possible hardness of the division in described scenario. Example Input 5 6 5 5 4 86 5 1 0 1 3 38 2 1 33 2 4 28 2 3 40 3 5 2 6 1 3 2 3 1 6
2,500
false
false
false
false
true
false
true
false
true
true
7,073
552D
Problem - 552D - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags brute force combinatorics data structures geometry math sortings *1900 No tag edit access β†’ Contest materials ") Editorial ") β€” the number of the points painted on the plane. Next _n_ lines contain two integers each _x__i_,u2009_y__i_ (u2009-u2009100u2009≀u2009_x__i_,u2009_y__i_u2009≀u2009100) β€” the coordinates of the _i_-th point. It is guaranteed that no two given points coincide. Output In the first line print an integer β€” the number of triangles with the non-zero area among the painted points. Examples Input 4 0 0 1 1 2 0 2 2 Output 3 Input 3 0 0 1 1 2 0 Output 1 Input 1 1 1 Output 0 Note Note to the first sample test. There are 3 triangles formed: (0,u20090)u2009-u2009(1,u20091)u2009-u2009(2,u20090); (0,u20090)u2009-u2009(2,u20092)u2009-u2009(2,u20090); (1,u20091)u2009-u2009(2,u20092)u2009-u2009(2,u20090). Note to the second sample test. There is 1 triangle formed: (0,u20090)u2009-u2009(1,u20091)u2009-u2009(2,u20090). Note to the third sample test. A single point doesn't form a single triangle.
1,900
true
false
false
false
true
false
true
false
true
false
7,624
1163F
In the city of Capypaland where Kuro and Shiro resides, there are $$$n$$$ towns numbered from $$$1$$$ to $$$n$$$ and there are $$$m$$$ bidirectional roads numbered from $$$1$$$ to $$$m$$$ connecting them. The $$$i$$$-th road connects towns $$$u_i$$$ and $$$v_i$$$. Since traveling between the towns is quite difficult, the taxi industry is really popular here. To survive the harsh competition, each taxi company has to find a distinctive trait for their customers. Kuro is the owner of a taxi company. He has decided to introduce a new fee model for his taxi brand, where the fee for each ride is not calculated based on the trip length, but on the sum of the prices of the roads traveled. The price for each of the $$$m$$$ roads has been decided by Kuro himself. As of now, the price for the road $$$i$$$ is $$$w_i$$$ and hence the fee for a taxi ride traveling through roads $$$e_1, e_2, ldots, e_k$$$ is $$$sum_{i=1}^k w_{e_i}$$$. However, Kuro himself is an indecisive person, so he has drafted $$$q$$$ plans to change the road price. Each of the plans will be based on the original prices $$$w_i$$$, except for a single road $$$t_j$$$, the price of which is changed to $$$x_j$$$. Note, that the plans are independent of each other. Shiro is a regular customer of the Kuro's taxi brand since she uses the taxi to travel from town $$$1$$$ to town $$$n$$$ every day. Since she's so a regular customer, Kuro decided to show her all his $$$q$$$ plans before publishing them to the public. Now, Shiro wants to know the lowest fee she must pay to travel from the town $$$1$$$ to the town $$$n$$$ for each Kuro's plan. Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$2 le n le 2 cdot 10^5$$$, $$$1 le m, q le 2 cdot 10^5$$$)xa0β€” the number of towns, the number of roads, and the number of plans that Kuro has drafted respectively. The $$$i$$$-th of the next $$$m$$$ contains three integers $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$ ($$$1 le u_i, v_i le n$$$, $$$1 le w_i le 10^9$$$, $$$u_i e v_i$$$)xa0β€” two endpoints and the original price of the $$$i$$$-th road. It is guaranteed, that there is at least one way to travel from town $$$1$$$ to town $$$n$$$ using these $$$m$$$ bidirectional roads. Each of the next $$$q$$$ lines contains two integers $$$t_j$$$ and $$$x_j$$$ ($$$1 leq t_j leq m, 1 leq x_j leq 10^9$$$)xa0β€” the index of the road Kuro has planned to change and its new price respectively. Output Print $$$q$$$ integersxa0β€” the lowest fee Shiro must pay to get from town $$$1$$$ to town $$$n$$$ in each of those $$$q$$$ plans. Examples Input 4 5 6 1 2 2 2 4 3 1 4 7 1 3 1 3 4 5 3 4 5 1 3 8 1 4 2 1 3 1 Input 2 4 4 1 2 2 1 2 3 1 2 4 1 2 5 2 1 3 2 4 3 1 5 Note In the first example, the original overview of Capypaland looks like this, where the number next to each road denotes the original prices of the roads, The overview of the first plan, The lowest fee Shiro must pay in this plan is $$$4$$$, which corresponds to the path $$$1 ightarrow 4$$$. The overview of the second plan, The lowest fee Shiro must pay in this plan is $$$2$$$, which corresponds to the path $$$1 ightarrow 3 ightarrow 4$$$. The overview of the third plan, The lowest fee Shiro must pay in this plan is $$$5$$$, which corresponds to the path $$$1 ightarrow 2 ightarrow 4$$$.
3,000
false
false
false
false
true
false
false
false
false
true
4,897
412A
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of _n_ characters, so the decorators hung a large banner, _n_ meters wide and 1 meter high, divided into _n_ equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on. Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the _k_-th square of the poster. To draw the _i_-th character of the slogan on the poster, you need to climb the ladder, standing in front of the _i_-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the _i_-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left. Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan! Input The first line contains two integers, _n_ and _k_ (1u2009≀u2009_k_u2009≀u2009_n_u2009≀u2009100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as _n_ characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'. Output In _t_ lines, print the actions the programmers need to make. In the _i_-th line print: "LEFT" (without the quotes), if the _i_-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the _i_-th action was "move the ladder to the right"; "PRINT _x_" (without the quotes), if the _i_-th action was to "go up the ladder, paint character _x_, go down the ladder". The painting time (variable _t_) must be minimum possible. If there are multiple optimal painting plans, you can print any of them. Note Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
900
false
true
true
false
false
false
false
false
false
false
8,179
78B
Problem - 78B - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags constructive algorithms implementation *1200 No tag edit access β†’ Contest materials ") ") . Output Print one line consisting of _n_ characters. The _i_-th character should describe the color of the _i_-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Examples Input 8 Output ROYGRBIV Input 13 Output ROYGBIVGBIVYG Note The way the eggs will be painted in the first sample is shown on the picture:
1,200
false
false
true
false
false
true
false
false
false
false
9,574
44D
In a far away galaxy there are _n_ inhabited planets, numbered with numbers from 1 to _n_. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, _n_u2009-u20091 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention. Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That's why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of _s_ hyperyears in _s_ years). When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make _n_u2009-u20092 identical to it ships with a hyperdrive and send them to other _n_u2009-u20092 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new _n_u2009-u20092 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues. However the hyperdrive creators hurried to spread the news about their invention so much that they didn't study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy! Your task is to find the time the galaxy will continue to exist from the moment of the ships' launch from the first planet. Input The first line contains a number _n_ (3u2009≀u2009_n_u2009≀u20095000) β€” the number of inhabited planets in the galaxy. The next _n_ lines contain integer coordinates of the planets in format "_x__i_ _y__i_ _z__i_" (u2009-u2009104u2009≀u2009_x__i_,u2009_y__i_,u2009_z__i_u2009≀u2009104).
1,800
true
false
false
false
false
false
false
false
false
false
9,766
1183D
This problem is actually a subproblem of problem G from the same contest. There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 le a_i le n$$$). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i.u2009e. for example, a gift having two candies of type $$$1$$$ and two candies of type $$$2$$$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift. Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have. You have to answer $$$q$$$ independent queries. If you are Python programmer, consider using PyPy instead of Python when you submit your code. Input The first line of the input contains one integer $$$q$$$ ($$$1 le q le 2 cdot 10^5$$$) β€” the number of queries. Each query is represented by two lines. The first line of each query contains one integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) β€” the number of candies. The second line of each query contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le n$$$), where $$$a_i$$$ is the type of the $$$i$$$-th candy in the box. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 cdot 10^5$$$. Output For each query print one integer β€” the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement. Example Input 3 8 1 4 8 4 5 6 3 8 16 2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1 9 2 2 4 4 4 7 7 7 7 Note In the first query, you can prepare a gift with two candies of type $$$8$$$ and one candy of type $$$5$$$, totalling to $$$3$$$ candies. Note that this is not the only possible solution β€” taking two candies of type $$$4$$$ and one candy of type $$$6$$$ is also valid.
1,400
false
true
false
false
false
false
false
false
true
false
4,799
1684C
You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $$$1 le i le n$$$ and $$$2 le j le m$$$ the following holds: $$$a_{i,j} ge a_{i, j-1}$$$. You have to to do the following operation exactly once: choose two columns with indexes $$$i$$$ and $$$j$$$ (not necessarily different), $$$1 le i, j le m$$$, and swap them. You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 2 cdot 10^5$$$)xa0β€” the number of rows and columns respectively. Each of the next $$$n$$$ rows contains $$$m$$$ integers, $$$j$$$-th element of $$$i$$$-th row is $$$a_{i,j}$$$ ($$$1 le a_{i,j} le 10^9$$$)xa0β€” the number written in the $$$j$$$-th cell of the $$$i$$$-th row. It's guaranteed that the sum of $$$n cdot m$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output If after the swap it is impossible to get a good grid, output $$$-1$$$. In the other case output $$$2$$$ integersxa0β€” the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any. Example Input 5 2 3 1 2 3 1 1 1 2 2 4 1 2 3 2 2 2 1 1 1 2 3 6 2 1 5 4 3 2 1 1 2 Note In the first test case the grid is initially good, so we can, for example, swap the first column with itself. In the second test case it is impossible to make the grid good. In the third test case it is needed to swap the first and the second column, then the grid becomes good.
1,400
false
true
true
false
false
true
true
false
true
false
2,171
978B
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $$$1$$$. For example, if you delete the character in the position $$$2$$$ from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer $$$n$$$ $$$(3 le n le 100)$$$ β€” the length of the file name. The second line contains a string of length $$$n$$$ consisting of lowercase Latin letters only β€” the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Note In the first example Polycarp tried to send a file with name contains number $$$33$$$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
800
false
true
false
false
false
false
false
false
false
false
5,817
27E
. Output Output the smallest positive integer with exactly _n_ divisors.
2,000
false
false
false
true
false
false
true
false
false
false
9,859
1748F
You have an array $$$a_0, a_1, ldots, a_{n-1}$$$ of length $$$n$$$. Initially, $$$a_i = 2^i$$$ for all $$$0 le i lt n$$$. Note that array $$$a$$$ is zero-indexed. You want to reverse this array (that is, make $$$a_i$$$ equal to $$$2^{n-1-i}$$$ for all $$$0 le i lt n$$$). To do this, you can perform the following operation no more than $$$250,000$$$ times: Select an integer $$$i$$$ ($$$0 le i lt n$$$) and replace $$$a_i$$$ by $$$a_i oplus a_{(i+1)bmod n}$$$. Here, $$$oplus$$$ denotes the xa0β€” the number of operations performed. On the second line print $$$k$$$ integers $$$i_1,i_2,ldots,i_k$$$ ($$$0 le i_j lt n$$$). Here, $$$i_j$$$ should be the integer selected on the $$$j$$$-th operation. Note that you don't need to minimize the number of operations. Note In the notes, the elements on which the operations are performed are colored red. In the first test case, array $$$a$$$ will change in the following way: $$$[1,color{red}{2}] ightarrow [color{red}{1},3] ightarrow [2,color{red}{3}] ightarrow [2,1]$$$. In the second test case, array $$$a$$$ will change in the following way: $$$[1,color{red}{2},4] ightarrow [color{red}{1},6,4] ightarrow [7,color{red}{6},4] ightarrow [color{red}{7},2,4] ightarrow [5,2,color{red}{4}] ightarrow [5,color{red}{2},1] ightarrow [color{red}{5},3,1] ightarrow [6,color{red}{3},1] ightarrow [color{red}{6},2,1] ightarrow [4,2,1]$$$.
3,000
false
false
false
false
false
true
false
false
false
false
1,792
1472G
There are $$$n$$$ cities in Berland. The city numbered $$$1$$$ is the capital. Some pairs of cities are connected by a one-way road of length 1. Before the trip, Polycarp for each city found out the value of $$$d_i$$$xa0β€” the shortest distance from the capital (the $$$1$$$-st city) to the $$$i$$$-th city. Polycarp begins his journey in the city with number $$$s$$$ and, being in the $$$i$$$-th city, chooses one of the following actions: 1. Travel from the $$$i$$$-th city to the $$$j$$$-th city if there is a road from the $$$i$$$-th city to the $$$j$$$-th and $$$d_i < d_j$$$; 2. Travel from the $$$i$$$-th city to the $$$j$$$-th city if there is a road from the $$$i$$$-th city to the $$$j$$$-th and $$$d_i geq d_j$$$; 3. Stop traveling. Since the government of Berland does not want all people to come to the capital, so Polycarp no more than once can take the second action from the list. in other words, he can perform the second action $$$0$$$ or $$$1$$$ time during his journey. Polycarp, on the other hand, wants to be as close to the capital as possible. For example, if $$$n = 6$$$ and the cities are connected, as in the picture above, then Polycarp could have made the following travels (not all possible options): $$$2 ightarrow 5 ightarrow 1 ightarrow 2 ightarrow 5$$$; $$$3 ightarrow 6 ightarrow 2$$$; $$$1 ightarrow 3 ightarrow 6 ightarrow 2 ightarrow 5$$$. Polycarp wants for each starting city $$$i$$$ to find out how close he can get to the capital. More formally: he wants to find the minimal value of $$$d_j$$$ that Polycarp can get from the city $$$i$$$ to the city $$$j$$$ according to the rules described above. Input The first line contains one integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case is preceded by an empty line. The first line of each test case contains two integers $$$n$$$ ($$$2 leq n leq 2 cdot 10^5$$$) and $$$m$$$ ($$$1 leq m leq 2 cdot 10^5$$$)xa0β€” number of cities and roads, respectively. This is followed by $$$m$$$ lines describing the roads. Each road is characterized by two integers $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n, u e v$$$)xa0β€” the numbers of cities connected by a one-way road. It is guaranteed that the sums of $$$n$$$ and $$$m$$$ over all test cases do not exceed $$$2 cdot 10^5$$$. It is guaranteed that for each pair of different cities $$$(u, v)$$$ there is at most one road from $$$u$$$ to $$$v$$$ (but a pair of roads from $$$u$$$ to $$$v$$$ and from $$$v$$$ to $$$u$$$xa0β€” is valid). It is guaranteed that there is a path from the capital to all cities. Output For each test case, on a separate line output $$$n$$$ numbers, the $$$i$$$-th of which is equal to the minimum possible distance from the capital to the city where Polycarp ended his journey. Example Input 3 6 7 1 2 1 3 2 5 2 4 5 1 3 6 6 2 2 2 1 2 2 1 6 8 1 2 1 5 2 6 6 1 2 3 3 4 4 2 5 4 Output 0 0 1 2 0 1 0 0 0 0 2 1 1 0
2,100
false
false
false
true
false
false
false
false
false
true
3,318
100B
Problem - 100B - Codeforces =============== xa0 , where _n_ β€” the number of integers in the group. The next line contains the elements, sorted in the non-decreasing order. The numbers are comma separated, they have at most 7 digits in their decimal notation and do not have any leading zeros. Output If the group is friendly write "FRIENDS", else write "NOT FRIENDS". Examples Input 4 1,3,6,12 Output FRIENDS Input 3 1,2,9 Output NOT FRIENDS
1,500
false
false
true
false
false
false
false
false
false
false
9,488
980A
Problem - 980A - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags implementation math *900 No tag edit access β†’ Contest materials ") and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. Input The only line of input contains a string $$$s$$$ ($$$3 leq s leq 100$$$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. Output Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). Examples Input -o-o-- Output YES Input -o--- Output YES Input -o---o- Output NO Input ooo Output YES
900
true
false
true
false
false
false
false
false
false
false
5,806
1698D
Enter Register HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN Codeforces Round 803 (Div. 2) Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags binary search constructive algorithms interactive *1600 No tag edit access β†’ Contest materials Announcement (en) Tutorial (en) PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST D. Fixed Point Guessing time limit per test1 second memory limit per test256 megabytes This is an interactive problem. Initially, there is an array $$$a = [1, 2, ldots, n]$$$, where $$$n$$$ is an odd positive integer. The jury has selected $$$frac{n-1}{2}$$$ disjoint pairs of elements, and then the elements in those pairs are swapped. For example, if $$$a=[1,2,3,4,5]$$$, and the pairs $$$1 leftrightarrow 4$$$ and $$$3 leftrightarrow 5$$$ are swapped, then the resulting array is $$$[4, 2, 5, 1, 3]$$$. As a result of these swaps, exactly one element will not change position. You need to find this element. To do this, you can ask several queries. In each query, you can pick two integers $$$l$$$ and $$$r$$$ ($$$1 leq l leq r leq n$$$). In return, you will be given the elements of the subarray $$$[a_l, a_{l + 1}, dots, a_r]$$$ sorted in increasing order. Find the element which did not change position. You can make at most $$$mathbf{15}$$$ queries. The array $$$a$$$ is fixed before the interaction and does not change after your queries. Recall that an array $$$b$$$ is a subarray of the array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Input Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 leq t leq 500$$$)xa0β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 leq n < 10^4$$$; $$$n$$$ is odd)xa0β€” the length of the array $$$a$$$. After reading the first line of each test case, you should begin the interaction. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. Interaction For each test case, begin the interaction by reading the integer $$$n$$$. To make a query, output "$$$ exttt{?};l;r$$$" ($$$1 leq l leq r leq n$$$) without quotes. Afterwards, you should read in $$$r-l+1$$$ integersxa0β€” the integers $$$a_l, a_{l + 1}, dots, a_r$$$, in increasing order. You can make at most $$$15$$$ such queries in a single test case. If you receive the integer $$$-1$$$ instead of an answer or the integer $$$n$$$, it means your program has made an invalid query, has exceed the limit of queries, or has given incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. When you are ready to give the final answer, output "$$$ exttt{!};x$$$" ($$$1 leq x leq n$$$) without quotesxa0β€” the element that did not change position. Giving this answer does not count towards the limit of $$$15$$$ queries. Afterwards, your program must continue to solve the remaining test cases, or exit if all test cases have been solved. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see documentation for other languages. Hacks To make a hack, use the following format. The first line must contain an integer $$$t$$$ ($$$1 leq t leq 500$$$)xa0β€” the number of test cases. The description of the test cases follows. The first line of each test case must contain an integer $$$n$$$ ($$$3 leq n < 10^4$$$; $$$n$$$ is odd)xa0β€” the length of the array $$$a$$$. The second line of each test case must contain $$$n$$$ space-separated integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le n$$$)xa0β€” the elements of $$$a$$$. The array $$$a$$$ should be the result of $$$frac{n-1}{2}$$$ disjoint swaps on the array $$$[1,2,dots,n]$$$. Example input 2 5 1 2 4 5 1 3 5 3 1 output ? 1 4 ? 3 5 ! 2 ? 1 1 ! 1 Note In the first test, the interaction proceeds as follows. Solution Jury Explanation $$$ exttt{2}$$$ There are 2 test cases. $$$ exttt{5}$$$ In the first test case, the hidden array is $$$[4,2,5,1,3]$$$, with length $$$5$$$. $$$ exttt{? 1 4}$$$ $$$ exttt{1 2 4 5}$$$ The solution requests the subarray $$$[4,2,5,1]$$$ in increasing order, and the jury responds with $$$[1,2,4,5]$$$. $$$ exttt{? 3 5}$$$ $$$ exttt{1 3 5}$$$ The solution requests the subarray $$$[5,1,3]$$$ in increasing order, and the jury responds with $$$[1,3,5]$$$. $$$ exttt{! 2}$$$ The solution has somehow determined that $$$a_2=2$$$, and outputs it. Since the output is correct, the jury continues to the next test case. $$$ exttt{3}$$$ In the second test case, the hidden array is $$$[1,3,2]$$$, with length $$$3$$$. $$$ exttt{? 1 1}$$$ $$$ exttt{1}$$$ The solution requests the number $$$[1]$$$ only, and the jury responds with $$$[1]$$$. $$$ exttt{! 1}$$$ The solution has determined that $$$a_1=1$$$, and outputs it. Since the output is correct and there are no more test cases, the jury and the solution exit. Note that the line breaks in the example input and output are for the sake of clarity, and do not occur in the real interaction. Codeforces (c)
1,600
false
false
false
false
false
true
false
true
false
false
2,091
1993D
Given two positive integers $$$n$$$ and $$$k$$$, and another array $$$a$$$ of $$$n$$$ integers. In one operation, you can select any subarray of size $$$k$$$ of $$$a$$$, then remove it from the array without changing the order of other elements. More formally, let $$$(l, r)$$$ be an operation on subarray $$$a_l, a_{l+1}, ldots, a_r$$$ such that $$$r-l+1=k$$$, then performing this operation means replacing $$$a$$$ with $$$[a_1, ldots, a_{l-1}, a_{r+1}, ldots, a_n]$$$. For example, if $$$a=[1,2,3,4,5]$$$ and we perform operation $$$(3,5)$$$ on this array, it will become $$$a=[1,2]$$$. Moreover, operation $$$(2, 4)$$$ results in $$$a=[1,5]$$$, and operation $$$(1,3)$$$ results in $$$a=[4,5]$$$. You have to repeat the operation while the length of $$$a$$$ is greater than $$$k$$$ (which means $$$a gt k$$$). What is the largest possible median$$$^dagger$$$ of all remaining elements of the array $$$a$$$ after the process? $$$^dagger$$$The median of an array of length $$$n$$$ is the element whose index is $$$left lfloor (n+1)/2 ight floor$$$ after we sort the elements in non-decreasing order. For example: $$$median([2,1,5,4,3]) = 3$$$, $$$median([5]) = 5$$$, and $$$median([6,8,2,4]) = 4$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β€” the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n, k le 5 cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^9$$$)xa0β€” the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 cdot 10^5$$$. Note In the first test case, you can select a subarray $$$(l, r)$$$ which can be either $$$(1, 3)$$$ or $$$(2, 4)$$$. Thus, two obtainable final arrays are $$$[3]$$$ and $$$[2]$$$. The former one has the larger median ($$$3 > 2$$$) so the answer is $$$3$$$. In the second test case, three obtainable final arrays are $$$[6, 4]$$$, $$$[3, 4]$$$, and $$$[3, 2]$$$. Their medians are $$$4$$$, $$$3$$$, and $$$2$$$ respectively. The answer is $$$4$$$. In the third test case, only one element is left in the final array and it can be any element of the initial array. The largest one among them is $$$9$$$, so the answer is $$$9$$$.
2,200
false
true
false
true
false
false
false
true
false
false
309
1774B
Cirno_9baka has a paper tape with $$$n$$$ cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with $$$m$$$ kinds of colors. For some aesthetic reasons, he thinks that the $$$i$$$-th color must be used exactly $$$a_i$$$ times, and for every $$$k$$$ consecutive cells, their colors have to be distinct. Help Cirno_9baka to figure out if there is such a way to paint the cells. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10,000$$$) xa0β€” the number of test cases. The description of test cases follows. The first line of each test case contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 leq k leq n leq 10^9$$$, $$$1 leq m leq 10^5$$$, $$$m leq n$$$). Here $$$n$$$ denotes the number of cells, $$$m$$$ denotes the number of colors, and $$$k$$$ means that for every $$$k$$$ consecutive cells, their colors have to be distinct. The second line of each test case contains $$$m$$$ integers $$$a_1, a_2, cdots , a_m$$$ ($$$1 leq a_i leq n$$$) xa0β€” the numbers of times that colors have to be used. It's guaranteed that $$$a_1 + a_2 + ldots + a_m = n$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output "YES" if there is at least one possible coloring scheme; otherwise, output "NO". You may print each letter in any case (for example, "YES", "Yes", "yes", and "yEs" will all be recognized as positive answers). Example Input 2 12 6 2 1 1 1 1 1 7 12 6 2 2 2 2 2 2 2 Note In the first test case, there is no way to color the cells satisfying all the conditions. In the second test case, we can color the cells as follows: $$$(1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6)$$$. For any $$$2$$$ consecutive cells, their colors are distinct.
1,500
true
true
false
false
false
true
false
false
false
false
1,643
1693D
Let's call an array $$$a$$$ of $$$m$$$ integers $$$a_1, a_2, ldots, a_m$$$ Decinc if $$$a$$$ can be made increasing by removing a decreasing subsequence (possibly empty) from it. For example, if $$$a = [3, 2, 4, 1, 5]$$$, we can remove the decreasing subsequence $$$[a_1, a_4]$$$ from $$$a$$$ and obtain $$$a = [2, 4, 5]$$$, which is increasing. You are given a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$. Find the number of pairs of integers $$$(l, r)$$$ with $$$1 le l le r le n$$$ such that $$$p[l ldots r]$$$ (the subarray of $$$p$$$ from $$$l$$$ to $$$r$$$) is a Decinc array. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) xa0β€” the size of $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, ldots, p_n$$$ ($$$1 le p_i le n$$$, all $$$p_i$$$ are distinct) xa0β€” elements of the permutation. Output Output the number of pairs of integers $$$(l, r)$$$ such that $$$p[l ldots r]$$$ (the subarray of $$$p$$$ from $$$l$$$ to $$$r$$$) is a Decinc array. $$$(1 le l le r le n)$$$ Examples Input 10 7 10 1 8 3 9 2 4 6 5 Note In the first sample, all subarrays are Decinc. In the second sample, all subarrays except $$$p[1 ldots 6]$$$ and $$$p[2 ldots 6]$$$ are Decinc.
2,800
false
true
false
true
true
false
true
false
false
false
2,119
1942H
Ruby just won an internship position at Farmer John's farm by winning a coding competition! As the newly recruited intern, Ruby is tasked with maintaining Farmer John's peach tree, a tree consisting of $$$n$$$ nodes rooted at node $$$1$$$. Each node initially contains $$$a_i = 0$$$ peaches, and there are two types of events that can happen: 1. Growth event at some node $$$x$$$: Ruby must choose either the parent of $$$x$$$ or any node in the subtree of $$$x$$$ and increase the amount of peaches it contains by one. 2. Harvest event at some node $$$x$$$: Ruby must choose a single node that is in the subtree of $$$x$$$ and decrease the amount of peaches it contains by one. Note that this is not the same set of nodes as the growth event. Note that the subtree of $$$x$$$ includes the node $$$x$$$ as well. Ruby is also given an array $$$b$$$ of length $$$n$$$. The peach tree is deemed healthy if $$$a_i ge b_i$$$ for every node $$$i$$$. Ruby is asked to perform $$$q$$$ operations of two types: 1 x vxa0β€” Perform $$$v$$$ growth events on node $$$x$$$. Ruby does not have to choose the same node to increase in every growth event. 2 x vxa0β€” Perform $$$v$$$ harvest events on node $$$x$$$. Ruby does not have to choose the same node to decrease in every harvest event. For every prefix of operations, Ruby asks you to find if she can perform these operations in some order such that the resulting peach tree (at the end of these operations) is healthy. Note that Ruby can't perform a harvest event that makes any $$$a_i$$$ negative. Every prefix is independent, meaning that for a given operation, Ruby may choose different nodes to perform events on for every prefix that contains that operation. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$) xa0β€” the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 le n, q le 2 cdot 10^5$$$) xa0β€” the size of the tree and the number of operations. The second line contains $$$n - 1$$$ integers $$$p_2, p_3, ldots, p_n$$$ ($$$1 le p_i < i$$$) xa0β€” the parent of each node. The third line contains $$$n$$$ integers $$$b_1, b_2, ldots, b_n$$$ ($$$0 le b_i le 10^6$$$) xa0β€” the minimum number of peaches each node needs for the peach tree to be considered healthy. The next $$$q$$$ lines describe the operations Ruby will perform. Each line contains three integers $$$t$$$, $$$x$$$, and $$$v$$$ ($$$1 le t le 2$$$, $$$1 le x le n$$$, $$$1 le v le 10^6$$$). If $$$t = 1$$$, this denotes that Ruby must perform $$$v$$$ growth events on node $$$x$$$. If $$$t = 2$$$, this denotes that Ruby must perform $$$v$$$ harvest events on node $$$x$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 cdot 10^5$$$ and the sum of $$$q$$$ does not exceed $$$2 cdot 10^5$$$ Output For each test case, output $$$q$$$ lines. The $$$i$$$-th line should contain "YES" if Ruby can make the peach tree healthy after performing operations $$$1, 2, ldots, i$$$ in some order. Otherwise, it should contain "NO". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. Example Input 2 8 8 1 1 1 4 3 6 6 5 6 2 9 8 4 1 3 1 3 14 1 4 17 1 2 7 2 2 1 1 6 1 2 1 1000000 1 4 999999 1 3 1 10 20 1 1 1 2 5 2 4 7 2 311353 270334 74853 385085 315501 183346 234819 417314 103862 429437 1 1 837541 1 10 933876 1 1 565958 1 4 791455 2 3 85054 2 3 440978 1 4 981040 1 5 68522 2 1 858305 2 4 184308 1 4 905081 2 8 519626 2 2 269090 1 1 43016 2 2 517644 1 5 355792 1 9 319241 2 10 125447 2 10 523890 1 10 241045 Output NO NO YES NO YES NO NO YES NO NO NO YES YES NO NO YES YES NO YES YES NO YES NO NO YES YES NO NO Note For the prefix containing operations $$$1, 2, ldots, 5$$$ in the first test case, Ruby may perform the operations in the following order: 1. Ruby performs operation $$$2$$$ and chooses to increase $$$a_4$$$ by $$$9$$$ and $$$a_5$$$ by $$$8$$$. 2. Ruby performs operation $$$1$$$ and chooses to increase $$$a_1$$$ by $$$5$$$, $$$a_3$$$ by $$$2$$$, $$$a_6$$$ by $$$4$$$, and $$$a_8$$$ by $$$3$$$. 3. Ruby performs operation $$$3$$$ and chooses to increase $$$a_2$$$ by $$$7$$$. 4. Ruby performs operation $$$4$$$ and chooses to decrease $$$a_2$$$ by $$$1$$$. 5. Ruby performs operation $$$5$$$ and chooses to increase $$$a_7$$$ by $$$1$$$.
3,500
false
false
false
true
true
false
false
false
false
false
624
1426B
Masha has $$$n$$$ types of tiles of size $$$2 imes 2$$$. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type. Masha decides to construct the square of size $$$m imes m$$$ consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, and each cell of this square has to be covered with exactly one tile cell, and also sides of tiles should be parallel to the sides of the square. All placed tiles cannot intersect with each other. Also, each tile should lie inside the square. See the picture in Notes section for better understanding. Symmetric with respect to the main diagonal matrix is such a square $$$s$$$ that for each pair $$$(i, j)$$$ the condition $$$s[i][j] = s[j][i]$$$ holds. I.e. it is true that the element written in the $$$i$$$-row and $$$j$$$-th column equals to the element written in the $$$j$$$-th row and $$$i$$$-th column. Your task is to determine if Masha can construct a square of size $$$m imes m$$$ which is a symmetric matrix and consists of tiles she has. Masha can use any number of tiles of each type she has to construct the square. Note that she can not rotate tiles, she can only place them in the orientation they have in the input. You have to answer $$$t$$$ independent test cases. Input The first line of the input contains one integer $$$t$$$ ($$$1 le t le 100$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 100$$$, $$$1 le m le 100$$$) β€” the number of types of tiles and the size of the square Masha wants to construct. The next $$$2n$$$ lines of the test case contain descriptions of tiles types. Types of tiles are written one after another, each type is written on two lines. The first line of the description contains two positive (greater than zero) integers not exceeding $$$100$$$ β€” the number written in the top left corner of the tile and the number written in the top right corner of the tile of the current type. The second line of the description contains two positive (greater than zero) integers not exceeding $$$100$$$ β€” the number written in the bottom left corner of the tile and the number written in the bottom right corner of the tile of the current type. It is forbidden to rotate tiles, it is only allowed to place them in the orientation they have in the input. Output For each test case print the answer: "YES" (without quotes) if Masha can construct the square of size $$$m imes m$$$ which is a symmetric matrix. Otherwise, print "NO" (withtout quotes). Example Input 6 3 4 1 2 5 6 5 7 7 4 8 9 9 8 2 5 1 1 1 1 2 2 2 2 1 100 10 10 10 10 1 2 4 5 8 4 2 2 1 1 1 1 1 2 3 4 1 2 1 1 1 1 Output YES NO YES NO YES YES Note The first test case of the input has three types of tiles, they are shown on the picture below. Masha can construct, for example, the following square of size $$$4 imes 4$$$ which is a symmetric matrix:
900
false
false
true
false
false
false
false
false
false
false
3,538
1616F
You are given a simple undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Edge $$$i$$$ is colored in the color $$$c_i$$$, which is either $$$1$$$, $$$2$$$, or $$$3$$$, or left uncolored (in this case, $$$c_i = -1$$$). You need to color all of the uncolored edges in such a way that for any three pairwise adjacent vertices $$$1 leq a < b < c leq n$$$, the colors of the edges $$$a leftrightarrow b$$$, $$$b leftrightarrow c$$$, and $$$a leftrightarrow c$$$ are either pairwise different, or all equal. In case no such coloring exists, you need to determine that. Input The first line of input contains one integer $$$t$$$ ($$$1 leq t leq 10$$$): the number of test cases. The following lines contain the description of the test cases. In the first line you are given two integers $$$n$$$ and $$$m$$$ ($$$3 leq n leq 64$$$, $$$0 leq m leq min(256, frac{n(n-1)}{2})$$$): the number of vertices and edges in the graph. Each of the next $$$m$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$, and $$$c_i$$$ ($$$1 leq a_i, b_i leq n$$$, $$$a_i e b_i$$$, $$$c_i$$$ is either $$$-1$$$, $$$1$$$, $$$2$$$, or $$$3$$$), denoting an edge between $$$a_i$$$ and $$$b_i$$$ with color $$$c_i$$$. It is guaranteed that no two edges share the same endpoints. Output For each test case, print $$$m$$$ integers $$$d_1, d_2, ldots, d_m$$$, where $$$d_i$$$ is the color of the $$$i$$$-th edge in your final coloring. If there is no valid way to finish the coloring, print $$$-1$$$. Example Input 4 3 3 1 2 1 2 3 2 3 1 -1 3 3 1 2 1 2 3 1 3 1 -1 4 4 1 2 -1 2 3 -1 3 4 -1 4 1 -1 3 3 1 2 1 2 3 1 3 1 2 Output 1 2 3 1 1 1 1 2 2 3 -1
2,900
true
false
false
false
false
false
true
false
false
true
2,551
1672I
You have a permutation $$$p$$$ of integers from $$$1$$$ to $$$n$$$. You have a strength of $$$s$$$ and will perform the following operation some times: Choose an index $$$i$$$ such that $$$1 leq i leq p$$$ and $$$i-p_i leq s$$$. For all $$$j$$$ such that $$$1 leq j leq p$$$ and $$$p_i<p_j$$$, update $$$p_j$$$ to $$$p_j-1$$$. Delete the $$$i$$$-th element from $$$p$$$. Formally, update $$$p$$$ to $$$[p_1,ldots,p_{i-1},p_{i+1},ldots,p_n]$$$. It can be shown that no matter what $$$i$$$ you have chosen, $$$p$$$ will be a permutation of integers from $$$1$$$ to $$$p$$$ after all operations. You want to be able to transform $$$p$$$ into the empty permutation. Find the minimum strength $$$s$$$ that will allow you to do so. Input The first line of input contains a single integer $$$n$$$ ($$$1 leq n leq 5 cdot 10^5$$$) xa0β€” the length of the permutation $$$p$$$. The second line of input conatains $$$n$$$ integers $$$p_1, p_2, ldots, p_n$$$ ($$$1 leq p_i leq n$$$) xa0β€” the elements of the permutation $$$p$$$. It is guaranteed that all elements in $$$p$$$ are distinct. Output Print the minimum strength $$$s$$$ required. Examples Input 10 1 8 4 3 7 10 6 5 9 2 Note In the first test case, the minimum $$$s$$$ required is $$$1$$$. Here is how we can transform $$$p$$$ into the empty permutation with $$$s=1$$$: In the first move, you can only choose $$$i=2$$$ as choosing any other value of $$$i$$$ will result in $$$i-p_i leq s$$$ being false. With $$$i=2$$$, $$$p$$$ will be changed to $$$[2,1]$$$. In the second move, you choose $$$i=1$$$, then $$$p$$$ will be changed to $$$[1]$$$. In the third move, you choose $$$i=1$$$, then $$$p$$$ will be changed to $$$[~]$$$. It can be shown that with $$$s=0$$$, it is impossible to transform $$$p$$$ into the empty permutation.
3,000
false
true
false
false
true
false
false
false
false
false
2,236
1282D
This is an interactive problem. After completing the last level of the enchanted temple, you received a powerful artifact of the 255th level. Do not rush to celebrate, because this artifact has a powerful rune that can be destroyed with a single spell $$$s$$$, which you are going to find. We define the spell as some non-empty string consisting only of the letters a and b. At any time, you can cast an arbitrary non-empty spell $$$t$$$, and the rune on the artifact will begin to resist. Resistance of the rune is the edit distance between the strings that specify the casted spell $$$t$$$ and the rune-destroying spell $$$s$$$. ), otherwise, the testing system may issue an arbitrary verdict. If the number of spells exceeds limit ($$$n + 2$$$, where $$$n$$$ is the length of the spell $$$s$$$, which is unknown to you), you will get the Wrong Answer verdict. Your solution may receive the verdict Idleness Limit Exceeded if you don't output anything or forget to flush the output buffer. To flush the output buffer, you need to do the following immediately after printing the query and the line end: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; for other languages see documentation. Hacks For hacks, use the following format: In a single line print the string $$$s$$$ ($$$1 le s le 300$$$) of letters a and b, which defines the rune-destroying spell. The hacked solution will not have direct access to the unknown spell.
2,300
false
false
false
false
false
true
false
false
false
false
4,282
1770E
Imi has an undirected tree with $$$n$$$ vertices where edges are numbered from $$$1$$$ to $$$n-1$$$. The $$$i$$$-th edge connects vertices $$$u_i$$$ and $$$v_i$$$. There are also $$$k$$$ butterflies on the tree. Initially, the $$$i$$$-th butterfly is on vertex $$$a_i$$$. All values of $$$a$$$ are pairwise distinct. Koxia plays a game as follows: For $$$i = 1, 2, dots, n - 1$$$, Koxia set the direction of the $$$i$$$-th edge as $$$u_i ightarrow v_i$$$ or $$$v_i ightarrow u_i$$$ with equal probability. For $$$i = 1, 2, dots, n - 1$$$, if a butterfly is on the initial vertex of $$$i$$$-th edge and there is no butterfly on the terminal vertex, then this butterfly flies to the terminal vertex. Note that operations are sequentially in order of $$$1, 2, dots, n - 1$$$ instead of simultaneously. Koxia chooses two butterflies from the $$$k$$$ butterflies with equal probability from all possible $$$frac{k(k-1)}{2}$$$ ways to select two butterflies, then she takes the distance$$$^dagger$$$ between the two chosen vertices as her score. Now, Koxia wants you to find the expected value of her score, modulo $$$998,244,353^ddagger$$$. $$$^dagger$$$ The distance between two vertices on a tree is the number of edges on the (unique) simple path between them. $$$^ddagger$$$ Formally, let $$$M = 998,244,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q ot equiv 0 pmod{M}$$$. Output the integer equal to $$$p cdot q^{-1} bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 le x < M$$$ and $$$x cdot q equiv p pmod{M}$$$. Input The first line contains two integers $$$n$$$, $$$k$$$ ($$$2 leq k leq n leq 3 cdot {10}^5$$$) β€” the size of the tree and the number of butterflies. The second line contains $$$k$$$ integers $$$a_1, a_2, dots, a_k$$$ ($$$1 leq a_i leq n$$$) β€” the initial position of butterflies. It's guaranteed that all positions are distinct. The $$$i$$$-th line in following $$$n βˆ’ 1$$$ lines contains two integers $$$u_i$$$, $$$v_i$$$ ($$$1 leq u_i, v_i leq n$$$, $$$u_i eq v_i$$$) β€” the vertices the $$$i$$$-th edge connects. It is guaranteed that the given edges form a tree. Output Output a single integer β€” the expected value of Koxia's score, modulo $$$998,244,353$$$. Examples Input 5 3 3 4 5 1 2 1 3 2 4 2 5 Note In the first test case, the tree is shown below. Vertices containing butterflies are noted as bold. There are only $$$2$$$ butterflies so the choice of butterflies is fixed. Let's consider the following $$$4$$$ cases: Edges are $$$1 ightarrow 2$$$ and $$$2 ightarrow 3$$$: butterfly on vertex $$$1$$$ moves to vertex $$$2$$$, but butterfly on vertex $$$3$$$ doesn't move. The distance between vertices $$$2$$$ and $$$3$$$ is $$$1$$$. Edges are $$$1 ightarrow 2$$$ and $$$3 ightarrow 2$$$: butterfly on vertex $$$1$$$ moves to vertex $$$2$$$, but butterfly on vertex $$$3$$$ can't move to vertex $$$2$$$ because it's occupied. The distance between vertices $$$2$$$ and $$$3$$$ is $$$1$$$. Edges are $$$2 ightarrow 1$$$ and $$$2 ightarrow 3$$$: butterflies on both vertex $$$1$$$ and vertex $$$3$$$ don't move. The distance between vertices $$$1$$$ and $$$3$$$ is $$$2$$$. Edges are $$$2 ightarrow 1$$$ and $$$3 ightarrow 2$$$: butterfly on vertex $$$1$$$ doesn't move, but butterfly on vertex $$$3$$$ move to vertex $$$2$$$. The distance between vertices $$$1$$$ and $$$2$$$ is $$$1$$$. Therefore, the expected value of Koxia's score is $$$frac {1+1+2+1} {4} = frac {5} {4}$$$, which is $$$748,683,266$$$ after modulo $$$998,244,353$$$. In the second test case, the tree is shown below. Vertices containing butterflies are noted as bold. The expected value of Koxia's score is $$$frac {11} {6}$$$, which is $$$831,870,296$$$ after modulo $$$998,244,353$$$.
2,400
true
false
false
true
false
false
false
false
false
false
1,673
1342F
You are given an array $$$a$$$ consisting of $$$n$$$ elements. You may apply several operations (possibly zero) to it. During each operation, you choose two indices $$$i$$$ and $$$j$$$ ($$$1 le i, j le n$$$; $$$i e j$$$), increase $$$a_j$$$ by $$$a_i$$$, and remove the $$$i$$$-th element from the array (so the indices of all elements to the right to it decrease by $$$1$$$, and $$$n$$$ also decreases by $$$1$$$). Your goal is to make the array $$$a$$$ strictly ascending. That is, the condition $$$a_1 < a_2 < dots < a_n$$$ should hold (where $$$n$$$ is the resulting size of the array). Calculate the minimum number of actions required to make the array strictly ascending. Input The first line contains one integer $$$T$$$ ($$$1 le T le 10000$$$) β€” the number of test cases. Each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$1 le n le 15$$$) β€” the number of elements in the initial array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 le a_i le 10^6$$$). It is guaranteed that: the number of test cases having $$$n ge 5$$$ is not greater than $$$5000$$$; the number of test cases having $$$n ge 8$$$ is not greater than $$$500$$$; the number of test cases having $$$n ge 10$$$ is not greater than $$$100$$$; the number of test cases having $$$n ge 11$$$ is not greater than $$$50$$$; the number of test cases having $$$n ge 12$$$ is not greater than $$$25$$$; the number of test cases having $$$n ge 13$$$ is not greater than $$$10$$$; the number of test cases having $$$n ge 14$$$ is not greater than $$$3$$$; the number of test cases having $$$n ge 15$$$ is not greater than $$$1$$$. Output For each test case, print the answer as follows: In the first line, print $$$k$$$ β€” the minimum number of operations you have to perform. Then print $$$k$$$ lines, each containing two indices $$$i$$$ and $$$j$$$ for the corresponding operation. Note that the numeration of elements in the array changes after removing elements from it. If there are multiple optimal sequences of operations, print any one of them. Example Input 4 8 2 1 3 5 1 2 4 5 15 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 2 3 3 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Output 3 6 8 1 6 4 1 7 1 15 1 13 1 11 1 9 1 7 1 5 1 3 1 2 1 0 Note In the first test case, the sequence of operations changes $$$a$$$ as follows: $$$[2, 1, 3, 5, 1, 2, 4, 5] ightarrow [2, 1, 3, 5, 1, 4, 7] ightarrow [1, 3, 5, 1, 6, 7] ightarrow [2, 3, 5, 6, 7]$$$.
3,000
false
false
false
true
false
false
true
false
false
false
3,994
1389A
Problem - 1389A - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags constructive algorithms greedy math number theory *800 No tag edit access β†’ Contest materials $$$ be the minimum positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(13, 37) = 481$$$, $$$LCM(9, 6) = 18$$$. You are given two integers $$$l$$$ and $$$r$$$. Find two integers $$$x$$$ and $$$y$$$ such that $$$l le x < y le r$$$ and $$$l le LCM(x, y) le r$$$. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10000$$$) β€” the number of test cases. Each test case is represented by one line containing two integers $$$l$$$ and $$$r$$$ ($$$1 le l < r le 10^9$$$). Output For each test case, print two integers: if it is impossible to find integers $$$x$$$ and $$$y$$$ meeting the constraints in the statement, print two integers equal to $$$-1$$$; otherwise, print the values of $$$x$$$ and $$$y$$$ (if there are multiple valid answers, you may print any of them). Example Input 4 1 1337 13 69 2 4 88 89 Output 6 7 14 21 2 4 -1 -1
800
true
true
false
false
false
true
false
false
false
false
3,728
172B
Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for _i_u2009β‰₯u20091). Here _a_, _b_, _m_ are constants, fixed for the given realization of the pseudorandom numbers generator, _r_0 is the so-called _randseed_ (this value can be set from the program using functions like RandSeed(r) or srand(n)), and denotes the operation of taking the remainder of division. For example, if _a_u2009=u20092,u2009_b_u2009=u20096,u2009_m_u2009=u200912,u2009_r_0u2009=u200911, the generated sequence will be: 4,u20092,u200910,u20092,u200910,u20092,u200910,u20092,u200910,u20092,u200910,u2009.... Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2. Your task is to find the period of a sequence defined by the given values of _a_,u2009_b_,u2009_m_ and _r_0. Formally, you have to find such minimum positive integer _t_, for which exists such positive integer _k_, that for any _i_u2009β‰₯u2009_k_: _r__i_u2009=u2009_r__i_u2009+u2009_t_. Input The single line of the input contains four integers _a_, _b_, _m_ and _r_0 (1u2009≀u2009_m_u2009≀u2009105,u20090u2009≀u2009_a_,u2009_b_u2009≀u20091000,u20090u2009≀u2009_r_0u2009<u2009_m_), separated by single spaces. Note The first sample is described above. In the second sample the sequence is (starting from the first element): 0,u20093,u20094,u20091,u20090,u20093,u20094,u20091,u20090,u2009... In the third sample the sequence is (starting from the first element): 33,u200924,u200978,u200978,u200978,u200978,u2009...
1,200
false
false
true
false
false
false
false
false
false
false
9,177
1551E
Consider a sequence of integers $$$a_1, a_2, ldots, 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.u2009g. 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, ldots, 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.u2009e. the resulting sequence $$$b_1, b_2, ldots, b_m$$$ will contain at least $$$k$$$ indices $$$i$$$ such that $$$b_i = i$$$. Input The first line contains one integer $$$t$$$ ($$$1 le t le 100$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two consecutive lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k le n le 2000$$$). The second line contains a sequence of integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le n$$$). The numbers in the sequence are not necessarily different. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2000$$$. Note In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $$$[1, 2, 3, 4, 5, 6]$$$ and $$$6$$$ elements will be equal to their indices. In the second test case there are two ways to get the desired result in $$$2$$$ moves: the first one is to delete the $$$1$$$-st and the $$$3$$$-rd elements so that the sequence will be $$$[1, 2, 3]$$$ and have $$$3$$$ elements equal to their indices; the second way is to delete the $$$2$$$-nd and the $$$3$$$-rd elements to get the sequence $$$[5, 2, 3]$$$ with $$$2$$$ desired elements.
2,000
false
false
false
true
false
false
true
true
false
false
2,886
1168B
Problem - 1168B - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags brute force two pointers *1900 No tag edit access β†’ Contest materials , consisting of zeros and ones. Output Output one integer: the number of such pairs of integers $$$l$$$, $$$r$$$ that $$$1 leq l leq r leq n$$$ and there is at least one pair of integers $$$x$$$, $$$k$$$ such that $$$1 leq x, k leq n$$$, $$$l leq x < x + 2k leq r$$$, and $$$s_x = s_{x+k} = s_{x+2k}$$$. Examples Input 010101 Output 3 Input 11001100 Output 0 Note In the first example, there are three $$$l$$$, $$$r$$$ pairs we need to count: $$$1$$$, $$$6$$$; $$$2$$$, $$$6$$$; and $$$1$$$, $$$5$$$. In the second example, there are no values $$$x$$$, $$$k$$$ for the initial string, so the answer is $$$0$$$.
1,900
false
false
false
false
false
false
true
false
false
false
4,875
633C
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique. For a given sentence, the cipher is processed as: 1. Convert all letters of the sentence to lowercase. 2. Reverse each of the words of the sentence individually. 3. Remove all the spaces in the sentence. For example, when this cipher is applied to the sentence Kira is childish and he hates losing the resulting string is ariksihsidlihcdnaehsetahgnisol Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times. Input The first line of the input contains a single integer _n_ (1u2009≀u2009_n_u2009≀u200910u2009000)xa0β€” the length of the ciphered text. The second line consists of _n_ lowercase English lettersxa0β€” the ciphered text _t_. The third line contains a single integer _m_ (1u2009≀u2009_m_u2009≀u2009100u2009000)xa0β€” the number of words which will be considered while deciphering the text. Each of the next _m_ lines contains a non-empty word _w__i_ (_w__i_u2009≀u20091u2009000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1u2009000u2009000. Output Print one line β€” the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. Examples Input 30 ariksihsidlihcdnaehsetahgnisol 10 Kira hates is he losing death childish L and Note Output Kira is childish and he hates losing Input 12 iherehtolleh 5 HI Ho there HeLLo hello Note In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.
1,900
false
false
true
true
true
false
false
false
true
false
7,273
1025C
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra. Before assembling the zebra Grisha can make the following operation $$$0$$$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bwbbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb". Determine the maximum possible length of the zebra that Grisha can produce. Input The only line contains a string $$$s$$$ ($$$1 le s le 10^5$$$, where $$$s$$$ denotes the length of the string $$$s$$$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece. Output Print a single integerxa0β€” the maximum possible zebra length. Note In the first example one of the possible sequence of operations is bwwwbwwbw $$$ o$$$ wwbwwwbwb $$$ o$$$ wbwbwwwbw, that gives the answer equal to $$$5$$$. In the second example no operation can increase the answer.
1,600
false
false
true
false
false
true
false
false
false
false
5,581
1534H
This is an interactive problem. As he qualified for IOI this year, Little Ericyi was given a gift from all his friends: a tree of $$$n$$$ nodes! On the flight to IOI Little Ericyi was very bored, so he decided to play a game with Little Yvonne with his new tree. First, Little Yvonne selects two (not necessarily different) nodes $$$a$$$ and $$$b$$$ on the tree (without telling Ericyi), and then gives him a hint $$$f$$$ (which is some node on the path from $$$a$$$ to $$$b$$$). Then, Little Ericyi is able to ask the following question repeatedly: If I rooted the tree at node $$$r$$$ (Ericyi gets to choose $$$r$$$), what would be the , the number of nodes in the tree. The next $$$nβˆ’1$$$ lines describe Little Ericyi's tree. These lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 le u,v le n$$$) denoting an edge between $$$u$$$ and $$$v$$$ ($$$u eq v$$$). It is guaranteed that these edges form a tree. After that you should output $$$k$$$, the maximum number of queries needed to determine $$$a$$$ and $$$b$$$ over all possibilities of $$$a$$$, $$$b$$$, and $$$f$$$ assuming Little Ericyi plays optimally. You should output end of line and flush the output after printing $$$k$$$. After that read a line containing the integer $$$f$$$ ($$$1 le f le n$$$)xa0β€” the hint: a node on the path from $$$a$$$ to $$$b$$$, inclusive. After that, you can start making queries. You will be limited to making at most $$$k$$$ queries, where $$$k$$$ is the number you printed. Each query is made in the format "? r", where $$$r$$$ is an integer $$$1 le r le n$$$ denoting the root node you want for the query. You will then receive an integer $$$x$$$ ($$$1 le x le n$$$), the Lowest Common Ancestor of $$$a$$$ and $$$b$$$ if the tree was rooted at $$$r$$$. When your program has found the nodes $$$a$$$, $$$b$$$, report the answer in the following format: "! a b", where $$$a$$$ and $$$b$$$ are the two hidden nodes and terminate your program normally immediately after flushing the output stream. You may output $$$a$$$ and $$$b$$$ in any order. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see documentation for other languages. If at any point you make an invalid output or make more than $$$k$$$ queries, the interaction will terminate and you will receive a Wrong Answer verdict. An invalid output is defined as either an invalid query or a value of $$$k$$$ less than $$$0$$$ or greater than $$$n$$$. Hacks To hack a solution, use the following format: The first line contains the integer $$$n$$$ ($$$1 le n le 10^5$$$). The next $$$nβˆ’1$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 le u,v le n$$$) denoting an edge between $$$u$$$ and $$$v$$$ ($$$u eq v$$$). These $$$n-1$$$ edges must form a tree. The next line of input contains the nodes $$$a$$$ and $$$b$$$ ($$$1 le a,b le n$$$), separated by a space. The final line of input contains the integer $$$f$$$ ($$$1 le f le n$$$). Node $$$f$$$ should be on the simple path from $$$a$$$ to $$$b$$$ (inclusive). Note Here is the the tree from the first sample interaction. Nodes $$$a$$$ and $$$b$$$ are highlighted. Notice that $$$a$$$ and $$$b$$$ can be output in any order. Additionally, here are the answers to querying every single node $$$1,2,ldots,n$$$ for your convenience: $$$1$$$: $$$1$$$ $$$2$$$: $$$2$$$ $$$3$$$: $$$2$$$ $$$4$$$: $$$4$$$ __________________________________________ Here is the the tree from the second sample interaction. Again, nodes $$$a$$$ and $$$b$$$ are highlighted. Lastly, here are the answers to querying every single node $$$1,2,ldots,n$$$ (in example $$$2$$$) for your convenience: $$$1$$$: $$$1$$$ $$$2$$$: $$$4$$$ $$$3$$$: $$$1$$$ $$$4$$$: $$$4$$$ $$$5$$$: $$$4$$$
3,500
false
false
false
true
false
true
false
false
true
true
2,975
93C
After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "Azembler. Principally New Approach". Having carefully thumbed through the book, Igor K. realised that, as it turns out, you can multiply the numbers dozens of times faster. "Search Ultimate will be faster than it has ever been!" β€” the fellow shouted happily and set to work. Let us now clarify what Igor's idea was. The thing is that the code that was generated by a compiler was far from perfect. Standard multiplying does work slower than with the trick the book mentioned. The Azembler language operates with 26 registers (eax, ebx, ..., ezx) and two commands: [_x_] β€” returns the value located in the address _x_. For example, [eax] returns the value that was located in the address, equal to the value in the register eax. lea _x_, _y_ β€” assigns to the register _x_, indicated as the first operand, the second operand's address. Thus, for example, the "lea ebx, [eax]" command will write in the ebx register the content of the eax register: first the [eax] operation will be fulfilled, the result of it will be some value that lies in the address written in eax. But we do not need the value β€” the next operation will be lea, that will take the [eax] address, i.e., the value in the eax register, and will write it in ebx. On the first thought the second operation seems meaningless, but as it turns out, it is acceptable to write the operation as lea ecx, [eax + ebx], lea ecx, [k*eax] or even lea ecx, [ebx + k*eax], where k = 1, 2, 4 or 8. As a result, the register ecx will be equal to the numbers eax + ebx, k*eax and ebx + k*eax correspondingly. However, such operation is fulfilled many times, dozens of times faster that the usual multiplying of numbers. And using several such operations, one can very quickly multiply some number by some other one. Of course, instead of eax, ebx and ecx you are allowed to use any registers. For example, let the eax register contain some number that we should multiply by 41. It takes us 2 lines: lea ebx, [eax + 4*eax] // now ebx = 5*eax lea eax, [eax + 8*ebx] // now eax = eax + 8*ebx = 41*eax Igor K. got interested in the following question: what is the minimum number of lea operations needed to multiply by the given number _n_ and how to do it? Your task is to help him. Consider that at the initial moment of time eax contains a number that Igor K. was about to multiply by _n_, and the registers from ebx to ezx contain number 0. At the final moment of time the result can be located in any register. Output On the first line print number _p_, which represents the minimum number of lea operations, needed to do that. Then print the program consisting of _p_ commands, performing the operations. It is guaranteed that such program exists for any _n_ from 1 to 255. Use precisely the following format of commands (here _k_ is equal to 1, 2, 4 or 8, and _x_, _y_ and _z_ are any, even coinciding registers): lea x, [y] lea x, [y + z] lea x, [k*y] lea x, [y + k*z] Please note that extra spaces at the end of a command are unacceptable.
2,500
false
false
true
false
false
false
true
false
false
false
9,513
1949A
You want to plant trees in a square lawn of size $$$n imes n$$$ whose corners have Cartesian coordinates $$$(0, 0)$$$, $$$(n, 0)$$$, $$$(0, n)$$$, and $$$(n, n)$$$. Trees can only be planted at locations with integer coordinates. Every tree will grow roots within a disk of radius $$$r$$$ centered at the location where the tree was planted; such disks must be fully contained in the lawn (possibly touching the boundary of the lawn) and can only intersect each other on their boundaries. Find a configuration that maximizes the number of trees. Input The first and only line contains an integer $$$n$$$ ($$$1 leq n leq 20$$$) and a real number $$$r$$$ ($$$0 < r leq n/2$$$) β€” the length of the sides of the lawn, and the radius of the disks where each tree will grow roots. The real number $$$r$$$ is given in decimal notation with at least $$$1$$$ and at most $$$3$$$ digits after the decimal point. Output In the first line, print the maximum number $$$m$$$ of trees that can be planted. In the next $$$m$$$ lines, print a configuration that maximizes the number of trees. Specifically, in the $$$(i+1)$$$-th line, print two integers $$$x$$$ and $$$y$$$ β€” the coordinates of the location where the $$$i$$$-th tree should be planted. You can print the trees in any order. If there are multiple solutions, print any of them. Note For the first sample, the sample output is shown in the following figure. Note that this is not the only configuration that maximizes the number of trees. For the second sample, the sample output is shown in the following figure. Note that this is not the only configuration that maximizes the number of trees.
3,300
false
false
false
true
false
false
true
false
false
false
592
746G
There are _n_ cities in Berland, each of them has a unique idxa0β€” an integer from 1 to _n_, the capital is the one with id 1. Now there is a serious problem in Berland with roadsxa0β€” there are no roads. That is why there was a decision to build _n_u2009-u20091 roads so that there will be exactly one simple path between each pair of cities. In the construction plan _t_ integers _a_1,u2009_a_2,u2009...,u2009_a__t_ were stated, where _t_ equals to the distance from the capital to the most distant city, concerning new roads. _a__i_ equals the number of cities which should be at the distance _i_ from the capital. The distance between two cities is the number of roads one has to pass on the way from one city to another. Also, it was decided that among all the cities except the capital there should be exactly _k_ cities with exactly one road going from each of them. Such cities are dead-ends and can't be economically attractive. In calculation of these cities the capital is not taken into consideration regardless of the number of roads from it. Your task is to offer a plan of road's construction which satisfies all the described conditions or to inform that it is impossible. Input The first line contains three positive numbers _n_, _t_ and _k_ (2u2009≀u2009_n_u2009≀u20092Β·105, 1u2009≀u2009_t_,u2009_k_u2009<u2009_n_)xa0β€” the distance to the most distant city from the capital and the number of cities which should be dead-ends (the capital in this number is not taken into consideration). The second line contains a sequence of _t_ integers _a_1,u2009_a_2,u2009...,u2009_a__t_ (1u2009≀u2009_a__i_u2009<u2009_n_), the _i_-th number is the number of cities which should be at the distance _i_ from the capital. It is guaranteed that the sum of all the values _a__i_ equals _n_u2009-u20091. Output If it is impossible to built roads which satisfy all conditions, print -1. Otherwise, in the first line print one integer _n_xa0β€” the number of cities in Berland. In the each of the next _n_u2009-u20091 line print two integersxa0β€” the ids of cities that are connected by a road. Each road should be printed exactly once. You can print the roads and the cities connected by a road in any order. If there are multiple answers, print any of them. Remember that the capital has id 1. Examples Output 7 1 3 2 1 2 6 2 4 7 4 3 5 Output 14 3 1 1 4 11 6 1 2 10 13 6 10 10 12 14 12 8 4 5 1 3 7 2 6 5 9
2,100
false
false
false
false
false
true
false
false
false
true
6,811
269D
Emuskald was hired to design an artificial waterfall according to the latest trends in landscape architecture. A modern artificial waterfall consists of multiple horizontal panels affixed to a wide flat wall. The water flows down the top of the wall from panel to panel until it reaches the bottom of the wall. The wall has height _t_ and has _n_ panels on the wall. Each panel is a horizontal segment at height _h__i_ which begins at _l__i_ and ends at _r__i_. The _i_-th panel connects the points (_l__i_,u2009_h__i_) and (_r__i_,u2009_h__i_) of the plane. The top of the wall can be considered a panel connecting the points (u2009-u2009109,u2009_t_) and (109,u2009_t_). Similarly, the bottom of the wall can be considered a panel connecting the points (u2009-u2009109,u20090) and (109,u20090). No two panels share a common point. Emuskald knows that for the waterfall to be aesthetically pleasing, it can flow from panel _i_ to panel _j_ () only if the following conditions hold: 1. _max_(_l__i_,u2009_l__j_)u2009<u2009_min_(_r__i_,u2009_r__j_) (horizontal projections of the panels overlap); 2. _h__j_u2009<u2009_h__i_ (panel _j_ is below panel _i_); 3. there is no such panel _k_ (_h__j_u2009<u2009_h__k_u2009<u2009_h__i_) that the first two conditions hold for the pairs (_i_,u2009_k_) and (_k_,u2009_j_). Then the flow for is equal to _min_(_r__i_,u2009_r__j_)u2009-u2009_max_(_l__i_,u2009_l__j_), the length of their horizontal projection overlap. Emuskald has decided that in his waterfall the water will flow in a single path from top to bottom. If water flows to a panel (except the bottom of the wall), the water will fall further to exactly one lower panel. The total amount of water flow in the waterfall is then defined as the minimum horizontal projection overlap between two consecutive panels in the path of the waterfall. Formally: 1. the waterfall consists of a single path of panels ; 2. the flow of the waterfall is the minimum flow in the path . To make a truly great waterfall Emuskald must maximize this water flow, but there are too many panels and he is having a hard time planning his creation. Below is an example of a waterfall Emuskald wants: Help Emuskald maintain his reputation and find the value of the maximum possible water flow. Input The first line of input contains two space-separated integers _n_ and _t_ (1u2009≀u2009_n_u2009≀u2009105, 2u2009≀u2009_t_u2009≀u2009109), the number of the panels excluding the top and the bottom panels, and the height of the wall. Each of the _n_ following lines contain three space-separated integers _h__i_, _l__i_ and _r__i_ (0u2009<u2009_h__i_u2009<u2009_t_, u2009-u2009109u2009≀u2009_l__i_u2009<u2009_r__i_u2009≀u2009109), the height, left and right ends of the _i_-th panel segment. It is guaranteed that no two segments share a common point.
2,600
false
false
false
true
true
false
false
false
true
true
8,755
1103E
Let's define radix sum of number $$$a$$$ consisting of digits $$$a_1, ldots ,a_k$$$ and number $$$b$$$ consisting of digits $$$b_1, ldots ,b_k$$$(we add leading zeroes to the shorter number to match longer length) as number $$$s(a,b)$$$ consisting of digits $$$(a_1+b_1)mod 10, ldots ,(a_k+b_k)mod 10$$$. The radix sum of several integers is defined as follows: $$$s(t_1, ldots ,t_n)=s(t_1,s(t_2, ldots ,t_n))$$$ You are given an array $$$x_1, ldots ,x_n$$$. The task is to compute for each integer $$$i (0 le i < n)$$$ number of ways to consequently choose one of the integers from the array $$$n$$$ times, so that the radix sum of these integers is equal to $$$i$$$. Calculate these values modulo $$$2^{58}$$$. Input The first line contains integer $$$n$$$xa0β€” the length of the array($$$1 leq n leq 100000$$$). The second line contains $$$n$$$ integers $$$x_1, ldots x_n$$$xa0β€” array elements($$$0 leq x_i < 100000$$$). Output Output $$$n$$$ integers $$$y_0, ldots, y_{n-1}$$$xa0β€” $$$y_i$$$ should be equal to corresponding number of ways modulo $$$2^{58}$$$. Note In the first example there exist sequences: sequence $$$(5,5)$$$ with radix sum $$$0$$$, sequence $$$(5,6)$$$ with radix sum $$$1$$$, sequence $$$(6,5)$$$ with radix sum $$$1$$$, sequence $$$(6,6)$$$ with radix sum $$$2$$$.
3,400
true
false
false
false
false
false
false
false
false
false
5,183
1607D
You are given an array of integers $$$a$$$ of length $$$n$$$. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step: either you can select any blue element and decrease its value by $$$1$$$; or you can select any red element and increase its value by $$$1$$$. Situations in which there are no elements of some color at all are also possible. For example, if the whole array is colored blue or red, one of the operations becomes unavailable. Determine whether it is possible to make $$$0$$$ or more steps such that the resulting array is a permutation of numbers from $$$1$$$ to $$$n$$$? In other words, check whether there exists a sequence of steps (possibly empty) such that after applying it, the array $$$a$$$ contains in some order all numbers from $$$1$$$ to $$$n$$$ (inclusive), each exactly once. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0β€” the number of input data sets in the test. The description of each set of input data consists of three lines. The first line contains an integer $$$n$$$ ($$$1 leq n leq 2 cdot 10^5$$$)xa0β€” the length of the original array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$-10^9 leq a_i leq 10^9$$$)xa0β€” the array elements themselves. The third line has length $$$n$$$ and consists exclusively of the letters 'B' and/or 'R': $$$i$$$th character is 'B' if $$$a_i$$$ is colored blue, and is 'R' if colored red. It is guaranteed that the sum of $$$n$$$ over all input sets does not exceed $$$2 cdot 10^5$$$. Output Print $$$t$$$ lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise. You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer). Example Input 8 4 1 2 5 2 BRBR 2 1 1 BB 5 3 1 4 2 5 RBRRB 5 3 1 3 1 3 RBRRB 5 5 1 5 1 5 RBRRB 4 2 2 2 2 BRBR 2 1 -2 BR 4 -2 -1 4 0 RRRR Output YES NO YES YES NO YES YES YES Note In the first test case of the example, the following sequence of moves can be performed: choose $$$i=3$$$, element $$$a_3=5$$$ is blue, so we decrease it, we get $$$a=[1,2,4,2]$$$; choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,3,4,2]$$$; choose $$$i=3$$$, element $$$a_3=4$$$ is blue, so we decrease it, we get $$$a=[1,3,3,2]$$$; choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,4,3,2]$$$. We got that $$$a$$$ is a permutation. Hence the answer is YES.
1,300
true
true
false
false
false
false
false
false
true
false
2,620
1343C
Recall that the sequence $$$b$$$ is a a subsequence of the sequence $$$a$$$ if $$$b$$$ can be derived from $$$a$$$ by removing zero or more elements without changing the order of the remaining elements. For example, if $$$a=[1, 2, 1, 3, 1, 2, 1]$$$, then possible subsequences are: $$$[1, 1, 1, 1]$$$, $$$[3]$$$ and $$$[1, 2, 1, 3, 1, 2, 1]$$$, but not $$$[3, 2, 3]$$$ and $$$[1, 1, 1, 1, 2]$$$. You are given a sequence $$$a$$$ consisting of $$$n$$$ positive and negative elements (there is no zeros in the sequence). Your task is to choose maximum by size (length) alternating subsequence of the given sequence (i.e. the sign of each next element is the opposite from the sign of the current element, like positive-negative-positive and so on or negative-positive-negative and so on). Among all such subsequences, you have to choose one which has the maximum sum of elements. In other words, if the maximum length of alternating subsequence is $$$k$$$ then your task is to find the maximum sum of elements of some alternating subsequence of length $$$k$$$. You have to answer $$$t$$$ independent test cases. Input The first line of the input contains one integer $$$t$$$ ($$$1 le t le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) β€” the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$-10^9 le a_i le 10^9, a_i e 0$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$ ($$$sum n le 2 cdot 10^5$$$). Output For each test case, print the answer β€” the maximum sum of the maximum by size (length) alternating subsequence of $$$a$$$. Example Input 4 5 1 2 3 -1 -2 4 -1 -2 -1 -3 10 -2 8 3 8 -4 -15 5 -2 -3 1 6 1 -1000000000 1 -1000000000 1 -1000000000 Note In the first test case of the example, one of the possible answers is $$$[1, 2, underline{3}, underline{-1}, -2]$$$. In the second test case of the example, one of the possible answers is $$$[-1, -2, underline{-1}, -3]$$$. In the third test case of the example, one of the possible answers is $$$[underline{-2}, 8, 3, underline{8}, underline{-4}, -15, underline{5}, underline{-2}, -3, underline{1}]$$$. In the fourth test case of the example, one of the possible answers is $$$[underline{1}, underline{-1000000000}, underline{1}, underline{-1000000000}, underline{1}, underline{-1000000000}]$$$.
1,200
false
true
false
true
false
false
false
false
false
false
3,991
1213D2
Problem - 1213D2 - Codeforces =============== xa0 ]( --- Finished β†’ Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β†’ Problem tags brute force math sortings *1600 No tag edit access β†’ Contest materials ") Editorial") time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the number of elements in the array. You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := lfloorfrac{a_i}{2} floor$$$). You can perform such an operation any (possibly, zero) number of times with any $$$a_i$$$. Your task is to calculate the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array. Don't forget that it is possible to have $$$a_i = 0$$$ after some operations, thus the answer always exists. Input The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k le n le 2 cdot 10^5$$$) β€” the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 2 cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. Output Print one integer β€” the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array. Examples Input 5 3 1 2 2 4 5 Output 1 Input 5 3 1 2 3 4 5 Output 2 Input 5 3 1 2 3 3 3 Output 0
1,600
true
false
false
false
false
false
true
false
true
false
4,615
219E
A parking lot in the City consists of _n_ parking spaces, standing in a line. The parking spaces are numbered from 1 to _n_ from left to right. When a car arrives at the lot, the operator determines an empty parking space for it. For the safety's sake the chosen place should be located as far from the already occupied places as possible. That is, the closest occupied parking space must be as far away as possible. If there are several such places, then the operator chooses the place with the minimum index from them. If all parking lot places are empty, then the car gets place number 1. We consider the distance between the _i_-th and the _j_-th parking spaces equal to 4Β·_i_u2009-u2009_j_ meters. You are given the parking lot records of arriving and departing cars in the chronological order. For each record of an arriving car print the number of the parking lot that was given to this car. Input The first line contains two space-separated integers _n_ and _m_ (1u2009≀u2009_n_,u2009_m_u2009≀u20092Β·105) β€” the number of parking places and the number of records correspondingly. Next _m_ lines contain the descriptions of the records, one per line. The _i_-th line contains numbers _t__i_, _id__i_ (1u2009≀u2009_t__i_u2009≀u20092;xa01u2009≀u2009_id__i_u2009≀u2009106). If _t__i_ equals 1, then the corresponding record says that the car number _id__i_ arrived at the parking lot. If _t__i_ equals 2, then the corresponding record says that the car number _id__i_ departed from the parking lot. Records about arriving to the parking lot and departing from the parking lot are given chronologically. All events occurred consecutively, no two events occurred simultaneously. It is guaranteed that all entries are correct: each car arrived at the parking lot at most once and departed from the parking lot at most once, there is no record of a departing car if it didn't arrive at the parking lot earlier, there are no more than _n_ cars on the parking lot at any moment. You can consider the cars arbitrarily numbered from 1 to 106, all numbers are distinct. Initially all places in the parking lot are empty. Output For each entry of an arriving car print the number of its parking space. Print the numbers of the spaces in the order, in which the cars arrive to the parking lot. Examples Input 7 11 1 15 1 123123 1 3 1 5 2 123123 2 15 1 21 2 3 1 6 1 7 1 8
2,200
false
false
false
false
true
false
false
false
false
false
8,960
990D
Given three numbers $$$n, a, b$$$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $$$a$$$, and the number of components in its complement is $$$b$$$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes. In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices. The adjacency matrix of an undirected graph is a square matrix of size $$$n$$$ consisting only of "0" and "1", where $$$n$$$ is the number of vertices of the graph and the $$$i$$$-th row and the $$$i$$$-th column correspond to the $$$i$$$-th vertex of the graph. The cell $$$(i,j)$$$ of the adjacency matrix contains $$$1$$$ if and only if the $$$i$$$-th and $$$j$$$-th vertices in the graph are connected by an edge. A connected component is a set of vertices $$$X$$$ such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to $$$X$$$ violates this rule. The complement or inverse of a graph $$$G$$$ is a graph $$$H$$$ on the same vertices such that two distinct vertices of $$$H$$$ are adjacent if and only if they are not adjacent in $$$G$$$. Input In a single line, three numbers are given $$$n, a, b ,(1 le n le 1000, 1 le a, b le n)$$$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. Output If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes). Otherwise, on the first line, print "YES"(without quotes). In each of the next $$$n$$$ lines, output $$$n$$$ digits such that $$$j$$$-th digit of $$$i$$$-th line must be $$$1$$$ if and only if there is an edge between vertices $$$i$$$ and $$$j$$$ in $$$G$$$ (and $$$0$$$ otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes. If there are several matrices that satisfy the conditions β€” output any of them.
1,700
false
false
true
false
false
true
false
false
false
true
5,749
1743F
You are given $$$n$$$ segments on the coordinate axis. The $$$i$$$-th segment is $$$[l_i, r_i]$$$. Let's denote the set of all integer points belonging to the $$$i$$$-th segment as $$$S_i$$$. Let $$$A cup B$$$ be the union of two sets $$$A$$$ and $$$B$$$, $$$A cap B$$$ be the intersection of two sets $$$A$$$ and $$$B$$$, and $$$A oplus B$$$ be the symmetric difference of $$$A$$$ and $$$B$$$ (a set which contains all elements of $$$A$$$ and all elements of $$$B$$$, except for the ones that belong to both sets). Let $$$[mathbin{op}_1, mathbin{op}_2, dots, mathbin{op}_{n-1}]$$$ be an array where each element is either $$$cup$$$, $$$oplus$$$, or $$$cap$$$. Over all $$$3^{n-1}$$$ ways to choose this array, calculate the sum of the following values: $$$$$$(((S_1 mathbin{op}_1 S_2) mathbin{op}_2 S_3) mathbin{op}_3 S_4) dots mathbin{op}_{n-1} S_n$$$$$$ In this expression, $$$S$$$ denotes the size of the set $$$S$$$. Input The first line contains one integer $$$n$$$ ($$$2 le n le 3 cdot 10^5$$$). Then, $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 le l_i le r_i le 3 cdot 10^5$$$). Output Print one integer β€” the sum of $$$(((S_1 mathbin{op}_1 S_2) mathbin{op}_2 S_3) mathbin{op}_3 S_4) dots mathbin{op}_{n-1} S_n$$$ over all possible ways to choose $$$[mathbin{op}_1, mathbin{op}_2, dots, mathbin{op}_{n-1}]$$$. Since the answer can be huge, print it modulo $$$998244353$$$.
2,300
false
false
false
true
true
false
false
false
false
false
1,819
1575B
Mr. Chanek lives in a city represented as a plane. He wants to build an amusement park in the shape of a circle of radius $$$r$$$. The circle must touch the origin (point $$$(0, 0)$$$). There are $$$n$$$ bird habitats that can be a photo spot for the tourists in the park. The $$$i$$$-th bird habitat is at point $$$p_i = (x_i, y_i)$$$. Find the minimum radius $$$r$$$ of a park with at least $$$k$$$ bird habitats inside. A point is considered to be inside the park if and only if the distance between $$$p_i$$$ and the center of the park is less than or equal to the radius of the park. Note that the center and the radius of the park do not need to be integers. In this problem, it is guaranteed that the given input always has a solution with $$$r leq 2 cdot 10^5$$$. Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 leq n leq 10^5$$$, $$$1 leq k leq n$$$) β€” the number of bird habitats in the city and the number of bird habitats required to be inside the park. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 leq x_i, y_i leq 10^5$$$) β€” the position of the $$$i$$$-th bird habitat. Output Output a single real number $$$r$$$ denoting the minimum radius of a park with at least $$$k$$$ bird habitats inside. It is guaranteed that the given input always has a solution with $$$r leq 2 cdot 10^5$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$frac{a - b}{max{(1, b)}} le 10^{-4}$$$. Examples Input 8 4 -3 1 -4 4 1 5 2 2 2 -2 -2 -4 -1 -1 -6 0 Note In the first example, Mr. Chanek can put the center of the park at $$$(-3, -1)$$$ with radius $$$sqrt{10} approx 3.162$$$. It can be proven this is the minimum $$$r$$$. The following illustrates the first example. The blue points represent bird habitats and the red circle represents the amusement park.
2,300
false
false
false
false
false
false
false
true
false
false
2,767
1984E
Two hungry red pandas, Oscar and Lura, have a tree $$$T$$$ with $$$n$$$ nodes. They are willing to perform the following shuffle procedure on the whole tree $$$T$$$ exactly once. With this shuffle procedure, they will create a new tree out of the nodes of the old tree. 1. Choose any node $$$V$$$ from the original tree $$$T$$$. Create a new tree $$$T_2$$$, with $$$V$$$ as the root. 2. Remove $$$V$$$ from $$$T$$$, such that the original tree is split into one or more subtrees (or zero subtrees, if $$$V$$$ is the only node in $$$T$$$). 3. Shuffle each subtree with the same procedure (again choosing any node as the root), then connect all shuffled subtrees' roots back to $$$V$$$ to finish constructing $$$T_2$$$. After this, Oscar and Lura are left with a new tree $$$T_2$$$. They can only eat leaves and are very hungry, so please find the maximum number of leaves over all trees that can be created in exactly one shuffle. Note that leaves are all nodes with degree $$$1$$$. Thus, the root may be considered as a leaf if it has only one child. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0β€” the number of test cases. The first line of every test case contains a single integer $$$n$$$ ($$$2 leq n leq 2 cdot 10^5$$$)xa0β€” the number of nodes within the original tree $$$T$$$. The next $$$n - 1$$$ lines each contain two integers $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n$$$)xa0β€” an edge within the original tree $$$T$$$. The given edges form a tree. The sum of $$$n$$$ over all test cases does not exceed $$$3 cdot 10^5$$$. Output For each test case, output a single integerxa0β€” the maximum number of leaves achievable with exactly one shuffle procedure on the whole tree. Example Input 4 5 1 2 1 3 2 4 2 5 5 1 2 2 3 3 4 4 5 6 1 2 1 3 1 4 1 5 1 6 10 9 3 8 1 10 6 8 5 7 8 4 6 1 3 10 1 2 7 Note In the first test case, it can be shown that the maximum number of leaves is $$$4$$$. To accomplish this, we can start our shuffle with selecting node $$$3$$$ as the new root. Next, we are left only with one subtree, in which we can select node $$$2$$$ to be the new root of that subtree. This will force all $$$3$$$ remaining nodes to be leaves, and once we connect them back to our new root, the shuffled subtree looks like this: We connect the shuffled subtree back to our new root of our new tree. Our final tree has four leaves (including the root), and looks like this: In our second test case, we have a line of five nodes. It can be shown that the maximum number of leaves after one shuffle is $$$3$$$. We can start off with node $$$2$$$, which forces node $$$1$$$ to become a leaf. Then, if we select node $$$4$$$ on the right side, we will also have nodes $$$3$$$ and $$$5$$$ as leaves. The third test case is a star graph with six nodes. The number of leaves cannot increase, thus our answer will be $$$5$$$ (if we start the shuffling with the original root node).
2,400
false
true
false
true
false
false
false
false
false
false
378
576A
Vasya and Petya are playing a simple game. Vasya thought of number _x_ between 1 and _n_, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number _y_?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of. Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers _y__i_, he should ask the questions about. Input A single line contains number _n_ (1u2009≀u2009_n_u2009≀u2009103). Output Print the length of the sequence of questions _k_ (0u2009≀u2009_k_u2009≀u2009_n_), followed by _k_ numbers β€” the questions _y__i_ (1u2009≀u2009_y__i_u2009≀u2009_n_). If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. Note The sequence from the answer to the first sample test is actually correct. If the unknown number is not divisible by one of the sequence numbers, it is equal to 1. If the unknown number is divisible by 4, it is 4. If the unknown number is divisible by 3, then the unknown number is 3. Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
1,500
true
false
false
false
false
false
false
false
false
false
7,543
1746D
You are given a rooted tree consisting of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$, and the root is the vertex $$$1$$$. You are also given a score array $$$s_1, s_2, ldots, s_n$$$. A multiset of $$$k$$$ simple paths is called valid if the following two conditions are both true. Each path starts from $$$1$$$. Let $$$c_i$$$ be the number of paths covering vertex $$$i$$$. For each pair of vertices $$$(u,v)$$$ ($$$2le u,vle n$$$) that have the same parent, $$$c_u-c_vle 1$$$ holds. The value of the path multiset is defined as $$$sumlimits_{i=1}^n c_i s_i$$$. It can be shown that it is always possible to find at least one valid multiset. Find the maximum value among all valid multisets. Input Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) β€” the number of test cases. The description of the test cases follows. The first line of each test case contains two space-separated integers $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$) and $$$k$$$ ($$$1 le k le 10^9$$$) β€” the size of the tree and the required number of paths. The second line contains $$$n - 1$$$ space-separated integers $$$p_2,p_3,ldots,p_n$$$ ($$$1le p_ile n$$$), where $$$p_i$$$ is the parent of the $$$i$$$-th vertex. It is guaranteed that this value describe a valid tree with root $$$1$$$. The third line contains $$$n$$$ space-separated integers $$$s_1,s_2,ldots,s_n$$$ ($$$0 le s_i le 10^4$$$) β€” the scores of the vertices. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10 ^ 5$$$. Output For each test case, print a single integer β€” the maximum value of a path multiset. Example Input 2 5 4 1 2 1 3 6 2 1 5 7 5 3 1 2 1 3 6 6 1 4 10 Note In the first test case, one of optimal solutions is four paths $$$1 o 2 o 3 o 5$$$, $$$1 o 2 o 3 o 5$$$, $$$1 o 4$$$, $$$1 o 4$$$, here $$$c=[4,2,2,2,2]$$$. The value equals to $$$4cdot 6+ 2cdot 2+2cdot 1+2cdot 5+2cdot 7=54$$$. In the second test case, one of optimal solution is three paths $$$1 o 2 o 3 o 5$$$, $$$1 o 2 o 3 o 5$$$, $$$1 o 4$$$, here $$$c=[3,2,2,1,2]$$$. The value equals to $$$3cdot 6+ 2cdot 6+2cdot 1+1cdot 4+2cdot 10=56$$$.
1,900
false
true
false
true
false
false
false
false
true
false
1,807
567E
Berland has _n_ cities, the capital is located in city _s_, and the historic home town of the President is in city _t_ (_s_u2009β‰ u2009_t_). The cities are connected by one-way roads, the travel time for each of the road is a positive integer. Once a year the President visited his historic home town _t_, for which his motorcade passes along some path from _s_ to _t_ (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from _s_ to _t_, along which he will travel the fastest. The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer. Input The first lines contain four integers _n_, _m_, _s_ and _t_ (2u2009≀u2009_n_u2009≀u2009105;xa01u2009≀u2009_m_u2009≀u2009105;xa01u2009≀u2009_s_,u2009_t_u2009≀u2009_n_) β€” the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (_s_u2009β‰ u2009_t_). Next _m_ lines contain the roads. Each road is given as a group of three integers _a__i_,u2009_b__i_,u2009_l__i_ (1u2009≀u2009_a__i_,u2009_b__i_u2009≀u2009_n_;xa0_a__i_u2009β‰ u2009_b__i_;xa01u2009≀u2009_l__i_u2009≀u2009106) β€” the cities that are connected by the _i_-th road and the time needed to ride along it. The road is directed from city _a__i_ to city _b__i_. The cities are numbered from 1 to _n_. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from _s_ to _t_ along the roads. Output Print _m_ lines. The _i_-th line should contain information about the _i_-th road (the roads are numbered in the order of appearance in the input). If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes). Otherwise, if the _i_-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing. If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes). Examples Input 6 7 1 6 1 2 2 1 3 10 2 3 7 2 4 8 3 5 3 4 5 2 5 6 1 Output YES CAN 2 CAN 1 CAN 1 CAN 1 CAN 1 YES Input 3 3 1 3 1 2 10 2 3 10 1 3 100 Note The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing. In the first sample president initially may choose one of the two following ways for a ride: 1u2009β†’u20092u2009β†’u20094u2009β†’u20095u2009β†’u20096 or 1u2009β†’u20092u2009β†’u20093u2009β†’u20095u2009β†’u20096.
2,200
false
false
false
false
false
false
false
false
false
true
7,580
628C
Problem - 628C - Codeforces =============== xa0 . The second line contains a string _s_ of length _n_, consisting of lowercase English letters. Output If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string _s_' that . Examples Input 4 26 bear Output roar Input 2 7 af Output db Input 3 1000 hey Output -1
1,300
false
true
false
false
false
false
false
false
false
false
7,313