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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1110D | You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have $$$n$$$ tiles in your hand. Each tile has an integer between $$$1$$$ and $$$m$$$ written on it. To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tiles are either all the same or consecutive. For example, $$$7, 7, 7$$$ is a valid triple, and so is $$$12, 13, 14$$$, but $$$2,2,3$$$ or $$$2,4,6$$$ are not. You can only use the tiles in your hand to form triples. Each tile can be used in at most one triple. To determine how close you are to the win, you want to know the maximum number of triples you can form from the tiles in your hand. Input The first line contains two integers integer $$$n$$$ and $$$m$$$ ($$$1 le n, m le 10^6$$$)xa0— the number of tiles in your hand and the number of tiles types. The second line contains integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le m$$$), where $$$a_i$$$ denotes the number written on the $$$i$$$-th tile. Output Print one integer: the maximum number of triples you can form. Examples Input 10 6 2 3 3 3 4 4 4 5 5 6 Input 12 6 1 5 3 3 3 4 3 5 3 2 3 3 Input 13 5 1 1 5 1 2 3 3 2 4 2 3 4 5 Note In the first example, we have tiles $$$2, 3, 3, 3, 4, 4, 4, 5, 5, 6$$$. We can form three triples in the following way: $$$2, 3, 4$$$; $$$3, 4, 5$$$; $$$4, 5, 6$$$. Since there are only $$$10$$$ tiles, there is no way we could form $$$4$$$ triples, so the answer is $$$3$$$. In the second example, we have tiles $$$1$$$, $$$2$$$, $$$3$$$ ($$$7$$$ times), $$$4$$$, $$$5$$$ ($$$2$$$ times). We can form $$$3$$$ triples as follows: $$$1, 2, 3$$$; $$$3, 3, 3$$$; $$$3, 4, 5$$$. One can show that forming $$$4$$$ triples is not possible. | 2,200 | false | false | false | true | false | false | false | false | false | false | 5,146 |
1930E | Stack has an array $$$a$$$ of length $$$n$$$ such that $$$a_i = i$$$ for all $$$i$$$ ($$$1 leq i leq n$$$). He will select a positive integer $$$k$$$ ($$$1 leq k leq lfloor frac{n-1}{2} floor$$$) and do the following operation on $$$a$$$ any number (possibly $$$0$$$) of times. Select a subsequence$$$^dagger$$$ $$$s$$$ of length $$$2 cdot k + 1$$$ from $$$a$$$. Now, he will delete the first $$$k$$$ elements of $$$s$$$ from $$$a$$$. To keep things perfectly balanced (as all things should be), he will also delete the last $$$k$$$ elements of $$$s$$$ from $$$a$$$. Stack wonders how many arrays $$$a$$$ can he end up with for each $$$k$$$ ($$$1 leq k leq lfloor frac{n-1}{2} floor$$$). As Stack is weak at counting problems, he needs your help. Since the number of arrays might be too large, please print it modulo $$$998,244,353$$$. $$$^dagger$$$ A sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by deleting several (possibly, zero or all) elements. For example, $$$[1, 3]$$$, $$$[1, 2, 3]$$$ and $$$[2, 3]$$$ are subsequences of $$$[1, 2, 3]$$$. On the other hand, $$$[3, 1]$$$ and $$$[2, 1, 3]$$$ are not subsequences of $$$[1, 2, 3]$$$. Input Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 2 cdot 10^3$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 leq n leq 10^6$$$)xa0— the length of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. Output For each test, on a new line, print $$$lfloor frac{n-1}{2} floor$$$ space-separated integersxa0— the $$$i$$$-th integer representing the number of arrays modulo $$$998,244,353$$$ that Stack can get if he selects $$$k=i$$$. Note In the first test case, two $$$a$$$ are possible for $$$k=1$$$: $$$[1,2,3]$$$; $$$[2]$$$. In the second test case, four $$$a$$$ are possible for $$$k=1$$$: $$$[1,2,3,4]$$$; $$$[1,3]$$$; $$$[2,3]$$$; $$$[2,4]$$$. In the third test case, two $$$a$$$ are possible for $$$k=2$$$: $$$[1,2,3,4,5]$$$; $$$[3]$$$. | 2,400 | true | false | false | true | false | false | false | false | false | false | 706 |
59B | Problem - 59B - 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 number theory *1200 No tag edit access → Contest materials ") ") , which is the number of flowers growing in the field. The second line contains _n_ integers _a__i_ (1u2009≤u2009_a__i_u2009≤u2009100) which represent the number of petals on a given _i_-th camomile. Output Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. Examples Input 1 1 Output 1 Input 1 2 Output 0 Input 3 5 6 7 Output 13 | 1,200 | false | false | true | false | false | false | false | false | false | false | 9,679 |
803G | You are given an array _a_ consisting of positive integers and _q_ queries to this array. There are two types of queries: 1 _l_ _r_ _x_ — for each index _i_ such that _l_u2009≤u2009_i_u2009≤u2009_r_ set _a__i_u2009=u2009_x_. 2 _l_ _r_ — find the minimum among such _a__i_ that _l_u2009≤u2009_i_u2009≤u2009_r_. We decided that this problem is too easy. So the array _a_ is given in a compressed form: there is an array _b_ consisting of _n_ elements and a number _k_ in the input, and before all queries _a_ is equal to the concatenation of _k_ arrays _b_ (so the size of _a_ is _n_·_k_). Input The first line contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u2009105, 1u2009≤u2009_k_u2009≤u2009104). The second line contains _n_ integers — elements of the array _b_ (1u2009≤u2009_b__i_u2009≤u2009109). The third line contains one integer _q_ (1u2009≤u2009_q_u2009≤u2009105). Then _q_ lines follow, each representing a query. Each query is given either as 1 _l_ _r_ _x_ — set all elements in the segment from _l_ till _r_ (including borders) to _x_ (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_·_k_, 1u2009≤u2009_x_u2009≤u2009109) or as 2 _l_ _r_ — find the minimum among all elements in the segment from _l_ till _r_ (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_·_k_). Output For each query of type 2 print the answer to this query — the minimum on the corresponding segment. Examples Input 3 1 1 2 3 3 2 1 3 1 1 2 4 2 1 3 Input 3 2 1 2 3 5 2 4 4 1 4 4 5 2 4 4 1 1 6 1 2 6 6 | 2,300 | false | false | false | false | true | false | false | false | false | false | 6,546 |
691A | Problem - 691A - Codeforces =============== xa0 — the number of buttons on the jacket. The second line contains _n_ integers _a__i_ (0u2009≤u2009_a__i_u2009≤u20091). The number _a__i_u2009=u20090 if the _i_-th button is not fastened. Otherwise _a__i_u2009=u20091. Output In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Examples Input 3 1 0 1 Output YES Input 3 1 0 0 Output NO | 1,000 | false | false | true | false | false | false | false | false | false | false | 7,047 |
1397B | Let's call a list of positive integers $$$a_0, a_1, ..., a_{n-1}$$$ a power sequence if there is a positive integer $$$c$$$, so that for every $$$0 le i le n-1$$$ then $$$a_i = c^i$$$. Given a list of $$$n$$$ positive integers $$$a_0, a_1, ..., a_{n-1}$$$, you are allowed to: Reorder the list (i.e. pick a permutation $$$p$$$ of $$${0,1,...,n - 1}$$$ and change $$$a_i$$$ to $$$a_{p_i}$$$), then Do the following operation any number of times: pick an index $$$i$$$ and change $$$a_i$$$ to $$$a_i - 1$$$ or $$$a_i + 1$$$ (i.e. increment or decrement $$$a_i$$$ by $$$1$$$) with a cost of $$$1$$$. Find the minimum cost to transform $$$a_0, a_1, ..., a_{n-1}$$$ into a power sequence. Input The first line contains an integer $$$n$$$ ($$$3 le n le 10^5$$$). The second line contains $$$n$$$ integers $$$a_0, a_1, ..., a_{n-1}$$$ ($$$1 le a_i le 10^9$$$). Output Print the minimum cost to transform $$$a_0, a_1, ..., a_{n-1}$$$ into a power sequence. Examples Input 3 1000000000 1000000000 1000000000 Note In the first example, we first reorder $$${1, 3, 2}$$$ into $$${1, 2, 3}$$$, then increment $$$a_2$$$ to $$$4$$$ with cost $$$1$$$ to get a power sequence $$${1, 2, 4}$$$. | 1,500 | true | false | false | false | false | false | true | false | true | false | 3,687 |
479A | Problem - 479A - 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 *1000 No tag edit access → Contest materials =5 1*2*3=6 (1+2)*3=9 Note that you can insert operation signs only between _a_ and _b_, and between _b_ and _c_, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given _a_, _b_ and _c_ print the maximum value that you can get. Input The input contains three integers _a_, _b_ and _c_, each on a single line (1u2009≤u2009_a_,u2009_b_,u2009_c_u2009≤u200910). Output Print the maximum value of the expression that you can obtain. Examples Input 1 2 3 Output 9 Input 2 10 3 Output 60 | 1,000 | true | false | false | false | false | false | true | false | false | false | 7,916 |
1496B | You are given a multiset $$$S$$$ initially consisting of $$$n$$$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times. You will perform the following operation $$$k$$$ times: Add the element $$$lceilfrac{a+b}{2} ceil$$$ (rounded up) into $$$S$$$, where $$$a = operatorname{mex}(S)$$$ and $$$b = max(S)$$$. If this number is already in the set, it is added again. Here $$$operatorname{max}$$$ of a multiset denotes the maximum integer in the multiset, and $$$operatorname{mex}$$$ of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example: $$$operatorname{mex}({1,4,0,2})=3$$$; $$$operatorname{mex}({2,5,1})=0$$$. Your task is to calculate the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done. Input The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1le tle 100$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1le nle 10^5$$$, $$$0le kle 10^9$$$)xa0— the initial size of the multiset $$$S$$$ and how many operations you need to perform. The second line of each test case contains $$$n$$$ distinct integers $$$a_1,a_2,dots,a_n$$$ ($$$0le a_ile 10^9$$$)xa0— the numbers in the initial multiset. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, print the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done. Example Input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 3 2 0 1 2 3 2 1 2 3 Note In the first test case, $$$S={0,1,3,4}$$$, $$$a=operatorname{mex}(S)=2$$$, $$$b=max(S)=4$$$, $$$lceilfrac{a+b}{2} ceil=3$$$. So $$$3$$$ is added into $$$S$$$, and $$$S$$$ becomes $$${0,1,3,3,4}$$$. The answer is $$$4$$$. In the second test case, $$$S={0,1,4}$$$, $$$a=operatorname{mex}(S)=2$$$, $$$b=max(S)=4$$$, $$$lceilfrac{a+b}{2} ceil=3$$$. So $$$3$$$ is added into $$$S$$$, and $$$S$$$ becomes $$${0,1,3,4}$$$. The answer is $$$4$$$. | 1,100 | true | false | false | false | false | false | false | false | false | false | 3,189 |
123B | Problem - 123B - 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 *1800 No tag edit access → Contest materials to a square (_x_2; _y_2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (_x_; _y_) is considered bad, if at least one of the two conditions is fulfilled: _x_u2009+u2009_y_u2009≡u20090 (_mod_xa02_a_), _x_u2009-u2009_y_u2009≡u20090 (_mod_xa02_b_). Your task is to find the minimum number of bad cells one will have to visit on the way from (_x_1; _y_1) to (_x_2; _y_2). Input The only line contains integers _a_, _b_, _x_1, _y_1, _x_2 and _y_2 — the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2u2009≤u2009_a_,u2009_b_u2009≤u2009109 and _x_1,_y_1,_x_2,_y_2u2009≤u2009109). It is guaranteed that the initial and the final square aren't bad. Output Print a single number — the minimum number of bad cells that one will have to visit in order to travel from square (_x_1; _y_1) to square (_x_2; _y_2). Examples Input 2 2 1 0 0 1 Output 1 Input 2 2 10 11 0 1 Output 5 Input 2 4 3 -1 3 7 Output 2 Note In the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad. | 1,800 | true | false | false | false | false | false | false | false | false | false | 9,388 |
1090A | A conglomerate consists of $$$n$$$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continue doing so until there is only one company left. But anti-monopoly service forbids to merge companies if they suspect unfriendly absorption. The criterion they use is the difference in maximum salaries between two companies. Merging is allowed only if the maximum salaries are equal. To fulfill the anti-monopoly requirements, the owners can change salaries in their companies before merging. But the labor union insists on two conditions: it is only allowed to increase salaries, moreover all the employees in one company must get the same increase. Sure enough, the owners want to minimize the total increase of all salaries in all companies. Help them find the minimal possible increase that will allow them to merge companies into one. Input The first line contains a single integer $$$n$$$xa0— the number of companies in the conglomerate ($$$1 le n le 2 cdot 10^5$$$). Each of the next $$$n$$$ lines describes a company. A company description start with an integer $$$m_i$$$xa0— the number of its employees ($$$1 le m_i le 2 cdot 10^5$$$). Then $$$m_i$$$ integers follow: the salaries of the employees. All salaries are positive and do not exceed $$$10^9$$$. The total number of employees in all companies does not exceed $$$2 cdot 10^5$$$. Output Output a single integer — the minimal total increase of all employees that allows to merge all companies. Example Input 3 2 4 3 2 2 1 3 1 1 1 Note One of the optimal merging strategies is the following. First increase all salaries in the second company by $$$2$$$, and merge the first and the second companies. Now the conglomerate consists of two companies with salaries $$$[4, 3, 4, 3]$$$ and $$$[1, 1, 1]$$$. To merge them, increase the salaries in the second of those by $$$3$$$. The total increase is $$$2 + 2 + 3 + 3 + 3 = 13$$$. | 1,300 | false | true | false | false | false | false | false | false | false | false | 5,272 |
1585B | Problem - 1585B - Codeforces =============== xa0 ") Editorial") . The right part contains the elements of $$$a$$$ that are strictly greater than $$$x$$$ ($$$> x$$$). The order of elements in each part is kept the same as before the operation, i.xa0e. the partition is stable. Then the array is replaced with the concatenation of the left and the right parts. For example, if the array $$$a$$$ is $$$ | 900 | false | true | false | false | false | false | false | false | false | false | 2,701 |
101C | Problem - 101C - 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 *2000 No tag edit access → Contest materials . The second and the third line contain in the similar manner vectors _B_ and _C_ (their coordinates are integers; their absolute value does not exceed 108). Output Print "YES" (without the quotes) if it is possible to get vector _B_ using the given operations. Otherwise print "NO" (without the quotes). Examples Input 0 0 1 1 0 1 Output YES Input 0 0 1 1 1 1 Output YES Input 0 0 1 1 2 2 Output NO | 2,000 | true | false | true | false | false | false | false | false | false | false | 9,477 |
980C | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the $$$i$$$-th integer represents the color of the $$$i$$$-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive). To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than $$$k$$$, and each color should belong to exactly one group. Finally, the students will replace the color of each pixel in the array with that color’s assigned group key. To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing $$$k$$$ to the right. To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array. Input The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 leq n leq 10^5$$$, $$$1 leq k leq 256$$$), the number of pixels in the image, and the maximum size of a group, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, dots, p_n$$$ ($$$0 leq p_i leq 255$$$), where $$$p_i$$$ is the color of the $$$i$$$-th pixel. Output Print $$$n$$$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter. Note One possible way to group colors and assign keys for the first sample: Color $$$2$$$ belongs to the group $$$[0,2]$$$, with group key $$$0$$$. Color $$$14$$$ belongs to the group $$$[12,14]$$$, with group key $$$12$$$. Colors $$$3$$$ and $$$4$$$ belong to group $$$[3, 5]$$$, with group key $$$3$$$. Other groups won't affect the result so they are not listed here. | 1,700 | false | true | false | false | false | false | false | false | false | false | 5,804 |
471B | It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are _n_ tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary. Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the _n_ tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks. Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u20092000) — the number of tasks. The second line contains _n_ integers _h_1,u2009_h_2,u2009...,u2009_h__n_ (1u2009≤u2009_h__i_u2009≤u20092000), where _h__i_ is the difficulty of the _i_-th task. The larger number _h__i_ is, the more difficult the _i_-th task is. Output In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line _n_ distinct integers that represent the numbers of the tasks in the order they are done according to the first plan. In the third and fourth line print two remaining plans in the same form. If there are multiple possible answers, you can print any of them. Examples Output YES 1 4 2 3 4 1 2 3 4 1 3 2 Note In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only two sequences of tasks that meet the conditions — [3, 1, 2, 4, 5] and [3, 1, 4, 2, 5]. Consequently, it is impossible to make three distinct sequences of tasks. | 1,300 | false | false | true | false | false | false | false | false | true | false | 7,951 |
3A | Problem - 3A - Codeforces =============== xa0 . Input The first line contains the chessboard coordinates of square _s_, the second line — of square _t_. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output In the first line print _n_ — minimum number of the king's moves. Then in _n_ lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Examples Input a8 h1 Output 7 RD RD RD RD RD RD RD | 1,000 | false | true | false | false | false | false | false | false | false | false | 9,978 |
1267E | Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected. There are $$$n$$$ candidates, numbered from 1 to $$$n$$$. Candidate $$$n$$$ is the opposition candidate. There are $$$m$$$xa0polling stations in the constituency, numbered from 1 to $$$m$$$. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate. Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected. Input The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2le nle 100$$$; $$$1le m le 100$$$)xa0— the number of candidates and the number of polling stations. The next $$$m$$$ lines contain the election results at each polling station with $$$n$$$ numbers on each line. In the $$$i$$$-th line the $$$j$$$-th number is $$$a_{i,j}$$$xa0— the number of votes cast for the candidate $$$j$$$ at the station $$$i$$$ ($$$0le a_{i,j} le 1,000$$$). Output In the first line output integer $$$k$$$xa0— the minimal number of the polling stations in which you need to cancel the election results. In the second line output $$$k$$$ integersxa0— the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at $$$k$$$ stations, output any one of them. Examples Input 5 3 6 3 4 2 8 3 7 5 6 7 5 2 4 7 9 Input 3 3 2 3 8 4 2 9 3 1 7 Note In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore. | 1,700 | false | true | false | false | false | false | false | false | false | false | 4,359 |
1284C | Recall that the permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array). A sequence $$$a$$$ is a subsegment of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as $$$[l, r]$$$, where $$$l, r$$$ are two integers with $$$1 le l le r le n$$$. This indicates the subsegment where $$$l-1$$$ elements from the beginning and $$$n-r$$$ elements from the end are deleted from the sequence. For a permutation $$$p_1, p_2, ldots, p_n$$$, we define a framed segment as a subsegment $$$[l,r]$$$ where $$$max{p_l, p_{l+1}, dots, p_r} - min{p_l, p_{l+1}, dots, p_r} = r - l$$$. For example, for the permutation $$$(6, 7, 1, 8, 5, 3, 2, 4)$$$ some of its framed segments are: $$$[1, 2], [5, 8], [6, 7], [3, 3], [8, 8]$$$. In particular, a subsegment $$$[i,i]$$$ is always a framed segments for any $$$i$$$ between $$$1$$$ and $$$n$$$, inclusive. We define the happiness of a permutation $$$p$$$ as the number of pairs $$$(l, r)$$$ such that $$$1 le l le r le n$$$, and $$$[l, r]$$$ is a framed segment. For example, the permutation $$$[3, 1, 2]$$$ has happiness $$$5$$$: all segments except $$$[1, 2]$$$ are framed segments. Given integers $$$n$$$ and $$$m$$$, Jongwon wants to compute the sum of happiness for all permutations of length $$$n$$$, modulo the prime number $$$m$$$. Note that there exist $$$n!$$$ (factorial of $$$n$$$) different permutations of length $$$n$$$. | 1,600 | true | false | false | false | false | false | false | false | false | false | 4,272 |
1668A | You are given a grid with $$$n$$$ rows and $$$m$$$ columns. Rows and columns are numbered from $$$1$$$ to $$$n$$$, and from $$$1$$$ to $$$m$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$. Initially, you are standing in the top left corner $$$(1, 1)$$$. Your goal is to reach the bottom right corner $$$(n, m)$$$. You can move in four directions from $$$(a, b)$$$: up to $$$(a-1, b)$$$, down to $$$(a+1, b)$$$, left to $$$(a, b-1)$$$ or right to $$$(a, b+1)$$$. You cannot move in the same direction in two consecutive moves, and you cannot leave the grid. What is the minimum number of moves to reach $$$(n, m)$$$? Input The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 10^3$$$) — the number of the test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 10^9$$$) — the size of the grid. Output For each test case, print a single integer: $$$-1$$$ if it is impossible to reach $$$(n, m)$$$ under the given conditions, otherwise the minimum number of moves. Example Input 6 1 1 2 1 1 3 4 2 4 6 10 5 Note Test case $$$1$$$: $$$n=1$$$, $$$m=1$$$, and initially you are standing in $$$(1, 1)$$$ so $$$0$$$ move is required to reach $$$(n, m) = (1, 1)$$$. Test case $$$2$$$: you should go down to reach $$$(2, 1)$$$. Test case $$$3$$$: it is impossible to reach $$$(1, 3)$$$ without moving right two consecutive times, or without leaving the grid. Test case $$$4$$$: an optimal moving sequence could be: $$$(1, 1) o (1, 2) o (2, 2) o (2, 1) o (3, 1) o (3, 2) o (4, 2)$$$. It can be proved that this is the optimal solution. So the answer is $$$6$$$. | 800 | true | false | true | false | false | false | false | false | false | false | 2,267 |
1924A | You are given two integers $$$n$$$ and $$$k$$$ along with a string $$$s$$$. Your task is to check whether all possible strings of length $$$n$$$ that can be formed using the first $$$k$$$ lowercase English alphabets occur as a subsequence of $$$s$$$. If the answer is NO, you also need to print a string of length $$$n$$$ that can be formed using the first $$$k$$$ lowercase English alphabets which does not occur as a subsequence of $$$s$$$. If there are multiple answers, you may print any of them. Note: A string $$$a$$$ is called a subsequence of another string $$$b$$$ if $$$a$$$ can be obtained by deleting some (possibly zero) characters from $$$b$$$ without changing the order of the remaining characters. Input The first line of input contains a single integer $$$t , (1 le t le 10^5)$$$, the number of test cases. The first line of each test case contains $$$3$$$ integers $$$n , (1 le n le 26), : k , (1 le k le 26), : m , (1 le m le 1000)$$$, where $$$n$$$ and $$$k$$$ are the same as described in the input and $$$m$$$ is the length of the string $$$s$$$. The second line of each test case contains a single string $$$s$$$ of length $$$m$$$, comprising only of the first $$$k$$$ lowercase English alphabets. It is guaranteed that the sum of $$$m$$$ and the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. Output For each test case, print YES if all possible strings of length $$$n$$$ that can be formed using the first $$$k$$$ lowercase English alphabets occur as a subsequence of $$$s$$$, else print NO. If your answer is NO, print a string of length $$$n$$$ that can be formed using the first $$$k$$$ lowercase English alphabets which does not occur as a subsequence of $$$s$$$ in the next line. You may print each letter of YES or NO in any case (for example, YES, yES, YeS will all be recognized as a positive answer). Example Input 3 2 2 4 abba 2 2 3 abb 3 3 10 aabbccabab Note For the first test case, all possible strings (aa, ab, ba, bb) of length $$$2$$$ that can be formed using the first $$$2$$$ English alphabets occur as a subsequence of abba. For the second test case, the string aa is not a subsequence of abb. | 1,500 | false | true | false | true | false | true | false | false | false | false | 746 |
696B | Barney lives in country USC (United States of Charzeh). USC has _n_ cities numbered from 1 through _n_ and _n_u2009-u20091 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads. Some girl has stolen Barney's heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows: let starting_time be an array of length n current_time = 0 dfs(v): current_time = current_time + 1 starting_time[v] = current_time shuffle children[v] randomly (each permutation with equal possibility) // children[v] is vector of children cities of city v for u in children[v]: dfs(u) As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)). Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city _i_, Barney wants to know the expected value of starting_time[i]. He's a friend of Jon Snow and knows nothing, that's why he asked for your help. Input The first line of input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u2009105)xa0— the number of cities in USC. The second line contains _n_u2009-u20091 integers _p_2,u2009_p_3,u2009...,u2009_p__n_ (1u2009≤u2009_p__i_u2009<u2009_i_), where _p__i_ is the number of the parent city of city number _i_ in the tree, meaning there is a road between cities numbered _p__i_ and _i_ in USC. Output In the first and only line of output print _n_ numbers, where _i_-th number is the expected value of starting_time[i]. Your answer for each city will be considered correct if its absolute or relative error does not exceed 10u2009-u20096. Examples Output 1.0 4.0 5.0 3.5 4.5 5.0 5.0 Input 12 1 1 2 2 4 4 3 3 1 10 8 Output 1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 | 1,700 | true | false | false | false | false | false | false | false | false | false | 7,040 |
1446B | You are given two strings $$$A$$$ and $$$B$$$ representing essays of two students who are suspected cheaters. For any two strings $$$C$$$, $$$D$$$ we define their similarity score $$$S(C,D)$$$ as $$$4cdot LCS(C,D) - C - D$$$, where $$$LCS(C,D)$$$ denotes the length of the Longest Common Subsequence of strings $$$C$$$ and $$$D$$$. You believe that only some part of the essays could have been copied, therefore you're interested in their substrings. Calculate the maximal similarity score over all pairs of substrings. More formally, output maximal $$$S(C, D)$$$ over all pairs $$$(C, D)$$$, where $$$C$$$ is some substring of $$$A$$$, and $$$D$$$ is some substring of $$$B$$$. If $$$X$$$ is a string, $$$X$$$ denotes its length. A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters. Pay attention to the difference between the substring and subsequence, as they both appear in the problem statement. You may wish to read the xa0— lengths of the two strings $$$A$$$ and $$$B$$$. The second line contains a string consisting of $$$n$$$ lowercase Latin lettersxa0— string $$$A$$$. The third line contains a string consisting of $$$m$$$ lowercase Latin lettersxa0— string $$$B$$$. Output Output maximal $$$S(C, D)$$$ over all pairs $$$(C, D)$$$, where $$$C$$$ is some substring of $$$A$$$, and $$$D$$$ is some substring of $$$B$$$. Note For the first case: abb from the first string and abab from the second string have LCS equal to abb. The result is $$$S(abb, abab) = (4 cdot abb$$$) - $$$abb$$$ - $$$abab$$$ = $$$4 cdot 3 - 3 - 4 = 5$$$. | 1,800 | false | false | false | true | false | false | false | false | false | false | 3,446 |
508B | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer _n_. Help Anton to determine the exchange rate of currency you all know for tomorrow! Input The first line contains an odd positive integer _n_xa0— the exchange rate of currency you all know for today. The length of number _n_'s representation is within range from 2 to 105, inclusive. The representation of _n_ doesn't contain any leading zeroes. Output If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print u2009-u20091. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. | 1,300 | true | true | false | false | false | false | false | false | false | false | 7,810 |
639A | Limak is a little polar bear. He loves connecting with other bears via social networks. He has _n_ friends and his relation with the _i_-th of them is described by a unique integer _t__i_. The bigger this value is, the better the friendship is. No two friends have the same value _t__i_. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most _k_ friends. If there are more than _k_ friends online then the system displays only _k_ best of themxa0— those with biggest _t__i_. Your task is to handle queries of two types: "1 id"xa0— Friend _id_ becomes online. It's guaranteed that he wasn't online before. "2 id"xa0— Check whether friend _id_ is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers _n_, _k_ and _q_ (1u2009≤u2009_n_,u2009_q_u2009≤u2009150u2009000,u20091u2009≤u2009_k_u2009≤u2009_min_(6,u2009_n_))xa0— the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains _n_ integers _t_1,u2009_t_2,u2009...,u2009_t__n_ (1u2009≤u2009_t__i_u2009≤u2009109) where _t__i_ describes how good is Limak's relation with the _i_-th friend. The _i_-th of the following _q_ lines contains two integers _type__i_ and _id__i_ (1u2009≤u2009_type__i_u2009≤u20092,u20091u2009≤u2009_id__i_u2009≤u2009_n_)xa0— the _i_-th query. If _type__i_u2009=u20091 then a friend _id__i_ becomes online. If _type__i_u2009=u20092 then you should check whether a friend _id__i_ is displayed. It's guaranteed that no two queries of the first type will have the same _id__i_ becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (_type__i_u2009=u20092) so the output won't be empty. Output For each query of the second type print one line with the answerxa0— "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3"xa0— Friend 3 becomes online. 2. "2 4"xa0— We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3"xa0— We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1"xa0— Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2"xa0— Friend 2 becomes online. There are 3 friends online now but we were given _k_u2009=u20092 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (_t_1u2009<u2009_t_2,u2009_t_3) so friend 1 won't be displayed 6. "2 1"xa0— Print "NO". 7. "2 2"xa0— Print "YES". 8. "2 3"xa0— Print "YES". | 1,200 | false | false | true | false | false | false | false | false | false | false | 7,257 |
350A | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written _n_ correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote _m_ wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set _v_ seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most _v_ seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, _a_ seconds, an inequality 2_a_u2009≤u2009_v_ holds. As a result, Valera decided to set _v_ seconds TL, that the following conditions are met: 1. _v_ is a positive integer; 2. all correct solutions pass the system testing; 3. at least one correct solution passes the system testing with some "extra" time; 4. all wrong solutions do not pass the system testing; 5. value _v_ is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input The first line contains two integers _n_, _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100). The second line contains _n_ space-separated positive integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u2009100) — the running time of each of the _n_ correct solutions in seconds. The third line contains _m_ space-separated positive integers _b_1,u2009_b_2,u2009...,u2009_b__m_ (1u2009≤u2009_b__i_u2009≤u2009100) — the running time of each of _m_ wrong solutions in seconds. Output If there is a valid TL value, print it. Otherwise, print -1. Examples Input 3 6 4 5 2 8 9 6 10 7 11 | 1,200 | false | true | true | false | false | false | true | false | false | false | 8,435 |
1264B | An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, ldots, s_{n}$$$ is beautiful if $$$s_i - s_{i+1} = 1$$$ for all $$$1 leq i leq n - 1$$$. Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers. However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans? Input The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 < a+b+c+d leq 10^5$$$). Output If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesxa0— a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them. Note In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$. It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | 1,900 | false | true | false | false | false | true | true | false | false | false | 4,380 |
1527B1 | The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version. A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is not. Alice and Bob are playing a game on a string $$$s$$$ (which is initially a palindrome in this version) of length $$$n$$$ consisting of the characters '0' and '1'. Both players take alternate turns with Alice going first. In each turn, the player can perform one of the following operations: 1. Choose any $$$i$$$ ($$$1 le i le n$$$), where $$$s[i] =$$$ '0' and change $$$s[i]$$$ to '1'. Pay 1 dollar. 2. Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. Reversing a string means reordering its letters from the last to the first. For example, "01001" becomes "10010" after reversing. The game ends when every character of string becomes '1'. The player who spends minimum dollars till this point wins the game and it is a draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, or if it is a draw. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1'. It is guaranteed that the string $$$s$$$ is a palindrome and contains at least one '0'. Note that there is no limit on the sum of $$$n$$$ over test cases. Output For each test case print a single word in a new line: "ALICE", if Alice will win the game, "BOB", if Bob will win the game, "DRAW", if the game ends in a draw. Note In the first test case of the example, in the $$$1$$$-st move Alice has to perform the $$$1$$$-st operation, since the string is currently a palindrome. in the $$$2$$$-nd move Bob reverses the string. in the $$$3$$$-rd move Alice again has to perform the $$$1$$$-st operation. All characters of the string are '1', game over. Alice spends $$$2$$$ dollars while Bob spends $$$0$$$ dollars. Hence, Bob always wins. | 1,200 | false | false | false | false | false | true | false | false | false | false | 3,028 |
1352D | There are $$$n$$$ candies in a row, they are numbered from left to right from $$$1$$$ to $$$n$$$. The size of the $$$i$$$-th candy is $$$a_i$$$. Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten. The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right). Alice makes the first move. During the first move, she will eat $$$1$$$ candy (its size is $$$a_1$$$). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on. On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends. For example, if $$$n=11$$$ and $$$a=[3,1,4,1,5,9,2,6,5,3,5]$$$, then: move 1: Alice eats one candy of size $$$3$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3,5]$$$. move 2: Alice ate $$$3$$$ on the previous move, which means Bob must eat $$$4$$$ or more. Bob eats one candy of size $$$5$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3]$$$. move 3: Bob ate $$$5$$$ on the previous move, which means Alice must eat $$$6$$$ or more. Alice eats three candies with the total size of $$$1+4+1=6$$$ and the sequence of candies becomes $$$[5,9,2,6,5,3]$$$. move 4: Alice ate $$$6$$$ on the previous move, which means Bob must eat $$$7$$$ or more. Bob eats two candies with the total size of $$$3+5=8$$$ and the sequence of candies becomes $$$[5,9,2,6]$$$. move 5: Bob ate $$$8$$$ on the previous move, which means Alice must eat $$$9$$$ or more. Alice eats two candies with the total size of $$$5+9=14$$$ and the sequence of candies becomes $$$[2,6]$$$. move 6 (the last): Alice ate $$$14$$$ on the previous move, which means Bob must eat $$$15$$$ or more. It is impossible, so Bob eats the two remaining candies and the game ends. Print the number of moves in the game and two numbers: $$$a$$$ — the total size of all sweets eaten by Alice during the game; $$$b$$$ — the total size of all sweets eaten by Bob during the game. Input The first line contains an integer $$$t$$$ ($$$1 le t le 5000$$$) — the number of test cases in the input. The following are descriptions of the $$$t$$$ test cases. Each test case consists of two lines. The first line contains an integer $$$n$$$ ($$$1 le n le 1000$$$) — the number of candies. The second line contains a sequence of integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 1000$$$) — the sizes of candies in the order they are arranged from left to right. It is guaranteed that the sum of the values of $$$n$$$ for all sets of input data in a test does not exceed $$$2cdot10^5$$$. | 1,300 | false | false | true | false | false | false | false | false | false | false | 3,949 |
748C | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of _m_ points _p_1,u2009_p_2,u2009...,u2009_p__m_ with integer coordinates, do the following: denote its initial location by _p_0. First, the robot will move from _p_0 to _p_1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches _p_1, it'll move to _p_2, again, choosing one of the shortest ways, then to _p_3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order. While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence. Input The first line of input contains the only positive integer _n_ (1u2009≤u2009_n_u2009≤u20092·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of _n_ letters, each being equal either L, or R, or U, or D. _k_-th letter stands for the direction which Robot traveled the _k_-th unit segment in: L means that it moved to the left, Rxa0— to the right, Uxa0— to the top and Dxa0— to the bottom. Have a look at the illustrations for better explanation. Output The only line of input should contain the minimum possible length of the sequence. Examples Input 26 RRRULURURUULULLLDLDDRDRDLD Note The illustrations to the first three tests are given below. The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence. | 1,400 | true | false | false | false | false | true | false | false | false | false | 6,802 |
1073F | You are given an undirected unweighted tree consisting of $$$n$$$ vertices. An undirected tree is a connected undirected graph with $$$n - 1$$$ edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinct) $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ in such a way that neither $$$x_1$$$ nor $$$y_1$$$ belong to the simple path from $$$x_2$$$ to $$$y_2$$$ and vice versa (neither $$$x_2$$$ nor $$$y_2$$$ should not belong to the simple path from $$$x_1$$$ to $$$y_1$$$). It is guaranteed that it is possible to choose such pairs for the given tree. Among all possible ways to choose such pairs you have to choose one with the maximum number of common vertices between paths from $$$x_1$$$ to $$$y_1$$$ and from $$$x_2$$$ to $$$y_2$$$. And among all such pairs you have to choose one with the maximum total length of these two paths. It is guaranteed that the answer with at least two common vertices exists for the given tree. The length of the path is the number of edges in it. The simple path is the path that visits each vertex at most once. Input The first line contains an integer $$$n$$$ — the number of vertices in the tree ($$$6 le n le 2 cdot 10^5$$$). Each of the next $$$n - 1$$$ lines describes the edges of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects ($$$1 le u_i, v_i le n$$$, $$$u_i e v_i$$$). It is guaranteed that the given edges form a tree. It is guaranteed that the answer with at least two common vertices exists for the given tree. Output Print any two pairs of vertices satisfying the conditions described in the problem statement. It is guaranteed that it is possible to choose such pairs for the given tree. Examples Input 9 9 3 3 5 1 2 4 3 4 7 1 7 4 6 3 8 Input 10 6 8 10 3 3 7 5 8 1 7 7 2 2 9 2 8 1 4 Input 11 1 2 2 3 3 4 1 5 1 6 6 7 5 8 5 9 4 10 4 11 Note The picture corresponding to the first example: The intersection of two paths is $$$2$$$ (vertices $$$1$$$ and $$$4$$$) and the total length is $$$4 + 3 = 7$$$. The picture corresponding to the second example: The intersection of two paths is $$$2$$$ (vertices $$$3$$$ and $$$4$$$) and the total length is $$$5 + 3 = 8$$$. The picture corresponding to the third example: The intersection of two paths is $$$3$$$ (vertices $$$2$$$, $$$7$$$ and $$$8$$$) and the total length is $$$5 + 5 = 10$$$. The picture corresponding to the fourth example: The intersection of two paths is $$$5$$$ (vertices $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$ and $$$5$$$) and the total length is $$$6 + 6 = 12$$$. | 2,500 | false | true | false | true | false | false | false | false | false | false | 5,348 |
822C | It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly _x_ days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that _n_ vouchers left. _i_-th voucher is characterized by three integers _l__i_, _r__i_, _cost__i_ — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the _i_-th voucher is a value _r__i_u2009-u2009_l__i_u2009+u20091. At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers _i_ and _j_ (_i_u2009≠u2009_j_) so that they don't intersect, sum of their durations is exactly _x_ and their total cost is as minimal as possible. Two vouchers _i_ and _j_ don't intersect if only at least one of the following conditions is fulfilled: _r__i_u2009<u2009_l__j_ or _r__j_u2009<u2009_l__i_. Help Leha to choose the necessary vouchers! Input The first line contains two integers _n_ and _x_ (2u2009≤u2009_n_,u2009_x_u2009≤u20092·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly. Each of the next _n_ lines contains three integers _l__i_, _r__i_ and _cost__i_ (1u2009≤u2009_l__i_u2009≤u2009_r__i_u2009≤u20092·105,u20091u2009≤u2009_cost__i_u2009≤u2009109) — description of the voucher. Output Print a single integer — a minimal amount of money that Leha will spend, or print u2009-u20091 if it's impossible to choose two disjoint vouchers with the total duration exactly _x_. Examples Input 4 5 1 3 4 1 2 5 5 6 1 1 2 4 Note In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3u2009-u20091u2009+u20091)u2009+u2009(6u2009-u20095u2009+u20091)u2009=u20095 and the total cost will be 4u2009+u20091u2009=u20095. In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2. | 1,600 | false | true | true | false | false | false | false | true | true | false | 6,466 |
1154E | There are $$$n$$$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team. The $$$i$$$-th student has integer programming skill $$$a_i$$$. All programming skills are distinct and between $$$1$$$ and $$$n$$$, inclusive. Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $$$k$$$ closest students to the left of him and $$$k$$$ closest students to the right of him (if there are less than $$$k$$$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i.u2009e. the process ends when each student becomes to some team). Your problem is to determine which students will be taken into the first team and which students will be taken into the second team. 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 students and the value determining the range of chosen students during each move, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le n$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student. It is guaranteed that all programming skills are distinct. Note In the first example the first coach chooses the student on a position $$$3$$$, and the row becomes empty (all students join the first team). In the second example the first coach chooses the student on position $$$4$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team). In the third example the first coach chooses the student on position $$$1$$$, and the row becomes $$$[1, 3, 5, 4, 6]$$$ (students with programming skills $$$[2, 7]$$$ join the first team). Then the second coach chooses the student on position $$$5$$$, and the row becomes $$$[1, 3, 5]$$$ (students with programming skills $$$[4, 6]$$$ join the second team). Then the first coach chooses the student on position $$$3$$$, and the row becomes $$$[1]$$$ (students with programming skills $$$[3, 5]$$$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $$$1$$$ joins the second team). In the fourth example the first coach chooses the student on position $$$3$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team). | 1,800 | false | false | true | false | true | false | false | false | true | false | 4,939 |
862C | Problem - 862C - 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 *1900 No tag edit access → Contest materials ") xa0— the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print _n_ distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: | 1,900 | false | false | false | false | false | true | false | false | false | false | 6,298 |
1271C | The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in $$$(s_x, s_y)$$$. There are $$$n$$$ students attending this school, the $$$i$$$-th of them lives in the house located in $$$(x_i, y_i)$$$. It is possible that some students live in the same house, but no student lives in $$$(s_x, s_y)$$$. After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the $$$i$$$-th student goes from the school to his house is $$$s_x - x_i + s_y - y_i$$$. The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the $$$i$$$-th student will buy a shawarma if at least one of the shortest paths from the school to the $$$i$$$-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students). You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself. Input The first line contains three integers $$$n$$$, $$$s_x$$$, $$$s_y$$$ ($$$1 le n le 200,000$$$, $$$0 le s_x, s_y le 10^{9}$$$) — the number of students and the coordinates of the school, respectively. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 le x_i, y_i le 10^{9}$$$) — the location of the house where the $$$i$$$-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated. Output The output should consist of two lines. The first of them should contain one integer $$$c$$$ — the maximum number of students that will buy shawarmas at the tent. The second line should contain two integers $$$p_x$$$ and $$$p_y$$$ — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of $$$p_x$$$ and $$$p_y$$$ should be not less than $$$0$$$ and not greater than $$$10^{9}$$$. Examples Input 4 3 2 1 3 4 2 5 1 4 1 Input 3 100 100 0 0 0 0 100 200 Input 7 10 12 5 6 20 23 15 4 16 5 4 54 12 1 4 15 Note In the first example, If we build the shawarma tent in $$$(4, 2)$$$, then the students living in $$$(4, 2)$$$, $$$(4, 1)$$$ and $$$(5, 1)$$$ will visit it. In the second example, it is possible to build the shawarma tent in $$$(1, 1)$$$, then both students living in $$$(0, 0)$$$ will visit it. | 1,300 | false | true | true | false | false | false | true | false | false | false | 4,333 |
1651D | You are given $$$n$$$ distinct points on a plane. The coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$. For each point $$$i$$$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $$$n$$$ points. If there are multiple such points — you can choose any of them. The Manhattan distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$x_1 - x_2 + y_1 - y_2$$$. Input The first line of the input contains one integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) — the number of points in the set. The next $$$n$$$ lines describe points. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 le x_i, y_i le 2 cdot 10^5$$$) — coordinates of the $$$i$$$-th point. It is guaranteed that all points in the input are distinct. Output Print $$$n$$$ lines. In the $$$i$$$-th line, print the point with integer coordinates that is not among the given $$$n$$$ points and is the nearest (in terms of Manhattan distance) to the $$$i$$$-th point from the input. Output coordinates should be in range $$$[-10^6; 10^6]$$$. It can be shown that any optimal answer meets these constraints. If there are several answers, you can print any of them. Examples Input 6 2 2 1 2 2 1 3 2 2 3 5 5 Output 1 1 1 1 2 0 3 1 2 4 5 4 Input 8 4 4 2 4 2 2 2 3 1 4 4 2 1 3 3 3 Output 4 3 2 5 2 1 2 5 1 5 4 1 1 2 3 2 | 1,900 | false | false | false | false | true | false | false | true | false | true | 2,365 |
1A | Problem - 1A - Codeforces =============== xa0 ]( "85") . Output Write the needed number of flagstones. Examples Input 6 6 4 Output 4 | 1,000 | true | false | false | false | false | false | false | false | false | false | 9,984 |
1629A | Did you know you can download more RAM? There is a shop with $$$n$$$ different pieces of software that increase your RAM. The $$$i$$$-th RAM increasing software takes $$$a_i$$$ GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional $$$b_i$$$ GB of RAM (permanently). Each software can only be used once. Your PC currently has $$$k$$$ GB of RAM. Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have. Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable? Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 le n le 100$$$, $$$1 le k le 1000$$$). Then two lines follow, each containing $$$n$$$ integers describing the arrays $$$a$$$ and $$$b$$$ ($$$1 le a_i, b_i le 1000$$$). Output For each test case, output a single line containing the largest amount of RAM you can achieve. Example Input 4 3 10 20 30 10 9 100 10 5 1 1 1 5 1 1 1 1 1 1 1 5 1 2 2 2 2 2 100 100 100 100 100 5 8 128 64 32 16 8 128 64 32 16 8 Note In the first test case, you only have enough RAM to run the third software initially, but that increases your RAM to $$$20$$$ GB, which allows you to use the first software, increasing your RAM to $$$29$$$ GB. The only software left needs $$$30$$$ GB of RAM, so you have to stop here. In the second test case, you can use the first, second, fourth and fifth software that need only $$$1$$$ GB of RAM per software to run to increase your RAM to $$$5$$$ GB, and then use the last remaining one to increase your RAM to $$$6$$$ GB. In the third test case, all the software need more than $$$1$$$ GB of RAM to run, so the amount of RAM you have stays at $$$1$$$ GB. | 800 | false | true | false | false | false | false | true | false | true | false | 2,468 |
1089H | , # Problem A. Harder Satisfiability Time limit: 2 seconds A fully quantified boolean 2-CNF formula is a formula in the following form: Q1x1 . . . Q nxn F (x1, . . . , x n).Each Qi is one of two quantifiers: a universal quantifier 8 (“for all”), or an existential quantifier 9 (“exists”); and F is a conjunction (boolean AND ) of m clauses s _ t (boolean OR ), where s and t are some variables (not necessarily different) with or without negation. This formula has no free variables, so it evaluates to either true or false . We can evaluate a given fully quantified formula with a simple recursive algorithm: 1. If there are no quantifiers, return the remaining expression’s value of true or false .2. Otherwise, recursively evaluate formulas: Fz = Q2x2 . . . Q nxn F (z, x 2, . . . , x n) for z = 0 , 1.3. If Q1 = 9 return F0 _ F1; otherwise if Q1 = 8 return F0 ^ F1.You are given some fully quantified boolean 2-CNF formulas. Find out if they are true or not. # Input The first line of the input contains a single integer t (1 x14 t x14 10 5) — the number of test cases. The first line of a test case contains two integers n and m (1 x14 n, m x14 10 5) — the number of variables and the number of clauses in F . The next line contains a string s with n characters describing the quantifiers. If si = ‘A’ then Qi is a universal quantifier 8, otherwise if si = ‘E’ then si is an existential quantifier 9.Next m lines describe clauses in F . Each line contains two integers ui and vi (x00n x14 ui, v i x14 n; ui, v i̸ = 0 ). If ui x15 1 then the first variable in the i-th clause is xui . Otherwise, if ui x14 x00 1 then the first variable is x−ui (negation of x−ui ). The second variable in the i-th clause is similarly described by vi.The sum of values of n for all test cases does not exceed 10 5; the sum of values of m does not exceed 10 5. # Output For each test case output “ TRUE ” if the given formula is true or “ FALSE ” otherwise. # Example standard input standard output 32 2 AE 1 -2 -1 2 2 2 EA 1 -2 -1 2 3 2 AEA 1 -2 -1 -3 TRUE FALSE FALSE # Note The first sample corresponds to a formula 8x1 9x2 (x1 _ x2) ^ (x1 _ x2) = 8x1 9x2 x1 x08 x2. For any x1 we can choose x2 = x1 making it true, hence the formula is true. The second sample changes the order of quantifiers. Now the answer is “ FALSE ”, because for any value of x1 we can choose x2 = x1 and the formula becomes false. The third formula is 8x1 9x2 8x3 (x1 _ x2) ^ (x1 _ x3). If we substitute x1 = 1 , x3 = 1 then no assignment of x2 can make the second clause true, so the formula is false. Page 1 of 1 | 3,400 | false | false | false | false | false | false | false | false | false | true | 5,278 |
1955C | $$$n$$$ ships set out to explore the depths of the ocean. The ships are numbered from $$$1$$$ to $$$n$$$ and follow each other in ascending order; the $$$i$$$-th ship has a durability of $$$a_i$$$. The Kraken attacked the ships $$$k$$$ times in a specific order. First, it attacks the first of the ships, then the last, then the first again, and so on. Each attack by the Kraken reduces the durability of the ship by $$$1$$$. When the durability of the ship drops to $$$0$$$, it sinks and is no longer subjected to attacks (thus the ship ceases to be the first or last, and the Kraken only attacks the ships that have not yet sunk). If all the ships have sunk, the Kraken has nothing to attack and it swims away. For example, if $$$n=4$$$, $$$k=5$$$, and $$$a=[1, 2, 4, 3]$$$, the following will happen: 1. The Kraken attacks the first ship, its durability becomes zero and now $$$a = [2, 4, 3]$$$; 2. The Kraken attacks the last ship, now $$$a = [2, 4, 2]$$$; 3. The Kraken attacks the first ship, now $$$a = [1, 4, 2]$$$; 4. The Kraken attacks the last ship, now $$$a = [1, 4, 1]$$$; 5. The Kraken attacks the first ship, its durability becomes zero and now $$$a = [4, 1]$$$. How many ships were sunk after the Kraken's attack? Input The first line contains an 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 le 2 cdot 10^5$$$, $$$1 le k le 10^{15}$$$)xa0— the number of ships and how many times the Kraken will attack the ships. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^9$$$)xa0— the durability of the ships. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 cdot 10^5$$$. | 1,300 | true | true | true | false | false | false | false | false | false | false | 546 |
1955B | A progressive square of size $$$n$$$ is an $$$n imes n$$$ matrix. Maxim chooses three integers $$$a_{1,1}$$$, $$$c$$$, and $$$d$$$ and constructs a progressive square according to the following rules: $$$$$$a_{i+1,j} = a_{i,j} + c$$$$$$ $$$$$$a_{i,j+1} = a_{i,j} + d$$$$$$ For example, if $$$n = 3$$$, $$$a_{1,1} = 1$$$, $$$c=2$$$, and $$$d=3$$$, then the progressive square looks as follows: $$$$$$ begin{pmatrix} 1 & 4 & 7 3 & 6 & 9 5 & 8 & 11 end{pmatrix} $$$$$$ Last month Maxim constructed a progressive square and remembered the values of $$$n$$$, $$$c$$$, and $$$d$$$. Recently, he found an array $$$b$$$ of $$$n^2$$$ integers in random order and wants to make sure that these elements are the elements of that specific square. It can be shown that for any values of $$$n$$$, $$$a_{1,1}$$$, $$$c$$$, and $$$d$$$, there exists exactly one progressive square that satisfies all the rules. Input The first line contains an integer $$$t$$$ ($$$1 le t le {10} ^ 4$$$)xa0— the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$c$$$, and $$$d$$$ ($$$2 le n le 500$$$, $$$1 le c, d le 10^6$$$)xa0— the size of the square and the values of $$$c$$$ and $$$d$$$ as described in the statement. The second line of each test case contains $$$n cdot n$$$ integers $$$b_1, b_2, dots, b_{n cdot n}$$$ ($$$1 le b_i le 10^9$$$)xa0— the elements found by Maxim. It is guaranteed that the sum of $$$n ^ 2$$$ over all test cases does not exceed $$$25 cdot {10} ^ 4$$$. Output For each test case, output "YES" in a separate line if a progressive square for the given $$$n$$$, $$$c$$$, and $$$d$$$ can be constructed from the array elements $$$a$$$, otherwise output "NO". You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer. | 1,000 | false | false | true | false | true | true | false | false | true | false | 547 |
979D | Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day. Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him. Initally, there is an empty array $$$a$$$. The game consists of $$$q$$$ tasks of two types. The first type asks Katie to add a number $$$u_i$$$ to $$$a$$$. The second type asks Katie to find a number $$$v$$$ existing in $$$a$$$ such that $$$k_i mid GCD(x_i, v)$$$, $$$x_i + v leq s_i$$$, and $$$x_i oplus v$$$ is maximized, where $$$oplus$$$ denotes the $$$ denotes the — the number of tasks the game wants you to perform. $$$q$$$ lines follow, each line begins with an integer $$$t_i$$$ — the type of the task: If $$$t_i = 1$$$, an integer $$$u_i$$$ follow ($$$1 leq u_i leq 10^{5}$$$) — you have to add $$$u_i$$$ to the array $$$a$$$. If $$$t_i = 2$$$, three integers $$$x_i$$$, $$$k_i$$$, and $$$s_i$$$ follow ($$$1 leq x_i, k_i, s_i leq 10^{5}$$$) — you must find a number $$$v$$$ existing in the array $$$a$$$ such that $$$k_i mid GCD(x_i, v)$$$, $$$x_i + v leq s_i$$$, and $$$x_i oplus v$$$ is maximized, where $$$oplus$$$ denotes the XOR operation, or report -1 if no such numbers are found. It is guaranteed that the type of the first task is type $$$1$$$, and there exists at least one task of type $$$2$$$. Output For each task of type $$$2$$$, output on one line the desired number $$$v$$$, or -1 if no such numbers are found. | 2,200 | true | true | false | true | true | false | true | true | false | false | 5,808 |
331D3 | Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a _b_u2009×u2009_b_ square on a plane. Each point _x_,u2009_y_ (0u2009≤u2009_x_,u2009_y_u2009≤u2009_b_) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfortable types of transport. The campus obeys traffic rules: there are _n_ arrows, parallel to the coordinate axes. The arrows do not intersect and do not touch each other. When the Beaveractor reaches some arrow, it turns in the arrow's direction and moves on until it either reaches the next arrow or gets outside the campus. The Beaveractor covers exactly one unit of space per one unit of time. You can assume that there are no obstacles to the Beaveractor. The BSA scientists want to transport the brand new Beaveractor to the "Academic Tractor" research institute and send the Smart Beaver to do his postgraduate studies and sharpen pencils. They have _q_ plans, representing the Beaveractor's initial position (_x__i_,u2009_y__i_), the initial motion vector _w__i_ and the time _t__i_ that have passed after the escape started. Your task is for each of the _q_ plans to determine the Smart Beaver's position after the given time. Input The first line contains two integers: the number of traffic rules _n_ and the size of the campus _b_, 0u2009≤u2009_n_, 1u2009≤u2009_b_. Next _n_ lines contain the rules. Each line of the rules contains four space-separated integers _x_0, _y_0, _x_1, _y_1 — the beginning and the end of the arrow. It is guaranteed that all arrows are parallel to the coordinate axes and have no common points. All arrows are located inside the campus, that is, 0u2009≤u2009_x_0,u2009_y_0,u2009_x_1,u2009_y_1u2009≤u2009_b_ holds. Next line contains integer _q_ — the number of plans the scientists have, 1u2009≤u2009_q_u2009≤u2009105. The _i_-th plan is represented by two integers, _x__i_, _y__i_ are the Beaveractor's coordinates at the initial time, 0u2009≤u2009_x__i_,u2009_y__i_u2009≤u2009_b_, character _w__i_, that takes value U, D, L, R and sets the initial direction up, down, to the left or to the right correspondingly (the Y axis is directed upwards), and _t__i_ — the time passed after the escape started, 0u2009≤u2009_t__i_u2009≤u20091015. to get 30 points you need to solve the problem with constraints _n_,u2009_b_u2009≤u200930 (subproblem D1); to get 60 points you need to solve the problem with constraints _n_,u2009_b_u2009≤u20091000 (subproblems D1+D2); to get 100 points you need to solve the problem with constraints _n_,u2009_b_u2009≤u2009105 (subproblems D1+D2+D3). Output Print _q_ lines. Each line should contain two integers — the Beaveractor's coordinates at the final moment of time for each plan. If the Smart Beaver manages to leave the campus in time _t__i_, print the coordinates of the last point in the campus he visited. Examples Input 3 3 0 0 0 1 0 2 2 2 3 3 2 3 12 0 0 L 0 0 0 L 1 0 0 L 2 0 0 L 3 0 0 L 4 0 0 L 5 0 0 L 6 2 0 U 2 2 0 U 3 3 0 U 5 1 3 D 2 1 3 R 2 Output 0 0 0 1 0 2 1 2 2 2 3 2 3 2 2 2 3 2 1 3 2 2 1 3 | 3,000 | false | false | true | false | true | false | false | false | false | false | 8,513 |
19D | Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0,u20090) is located in the bottom-left corner, _Ox_ axis is directed right, _Oy_ axis is directed up. Pete gives Bob requests of three types: add x y — on the sheet of paper Bob marks a point with coordinates (_x_,u2009_y_). For each request of this type it's guaranteed that point (_x_,u2009_y_) is not yet marked on Bob's sheet at the time of the request. remove x y — on the sheet of paper Bob erases the previously marked point with coordinates (_x_,u2009_y_). For each request of this type it's guaranteed that point (_x_,u2009_y_) is already marked on Bob's sheet at the time of the request. find x y — on the sheet of paper Bob finds all the marked points, lying strictly above and strictly to the right of point (_x_,u2009_y_). Among these points Bob chooses the leftmost one, if it is not unique, he chooses the bottommost one, and gives its coordinates to Pete. Bob managed to answer the requests, when they were 10, 100 or 1000, but when their amount grew up to 2·105, Bob failed to cope. Now he needs a program that will answer all Pete's requests. Help Bob, please! Input The first input line contains number _n_ (1u2009≤u2009_n_u2009≤u20092·105) — amount of requests. Then there follow _n_ lines — descriptions of the requests. add x y describes the request to add a point, remove x y — the request to erase a point, find x y — the request to find the bottom-left point. All the coordinates in the input file are non-negative and don't exceed 109. Output For each request of type find x y output in a separate line the answer to it — coordinates of the bottommost among the leftmost marked points, lying strictly above and to the right of point (_x_,u2009_y_). If there are no points strictly above and to the right of point (_x_,u2009_y_), output -1. Examples Input 7 add 1 1 add 3 4 find 0 0 remove 1 1 find 0 0 add 1 1 find 0 0 Input 13 add 5 5 add 5 6 add 5 7 add 6 5 add 6 6 add 6 7 add 7 5 add 7 6 add 7 7 find 6 6 remove 7 7 find 6 6 find 4 4 | 2,800 | false | false | false | false | true | false | false | false | false | false | 9,897 |
89A | It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has _n_ cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to _n_ from the left to the right. Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works. Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an _n_u2009-u20091 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered. Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than _m_ times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check. In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only _k_ minutes left before morning, and on each of these _k_ minutes he can perform no more than _m_ operations. All that remains in Joe's pocket, is considered his loot. Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning. Input The first line contains integers _n_, _m_ and _k_ (1u2009≤u2009_n_u2009≤u2009104, 1u2009≤u2009_m_,u2009_k_u2009≤u2009109). The next line contains _n_ numbers. The _i_-th number is equal to the amount of diamonds in the _i_-th cell — it is an integer from 0 to 105. Note In the second sample Joe can act like this: The diamonds' initial positions are 4 1 3. During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket. By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off. During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket. By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off. Now Joe leaves with 2 diamonds in his pocket. | 1,800 | false | true | false | false | false | false | false | false | false | false | 9,529 |
86B | Physicist Woll likes to play one relaxing game in between his search of the theory of everything. Game interface consists of a rectangular _n_u2009×u2009_m_ playing field and a dashboard. Initially some cells of the playing field are filled while others are empty. Dashboard contains images of all various connected (we mean connectivity by side) figures of 2, 3, 4 and 5 cells, with all their rotations and reflections. Player can copy any figure from the dashboard and place it anywhere at the still empty cells of the playing field. Of course any figure can be used as many times as needed. Woll's aim is to fill the whole field in such a way that there are no empty cells left, and also... just have some fun. Every initially empty cell should be filled with exactly one cell of some figure. Every figure should be entirely inside the board. In the picture black cells stand for initially filled cells of the field, and one-colour regions represent the figures. Input First line contains integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u20091000) — the height and the width of the field correspondingly. Next _n_ lines contain _m_ symbols each. They represent the field in a natural way: _j_-th character of the _i_-th line is "#" if the corresponding cell is filled, and "." if it is empty. Output If there is no chance to win the game output the only number "-1" (without the quotes). Otherwise output any filling of the field by the figures in the following format: each figure should be represented by some digit and figures that touch each other by side should be represented by distinct digits. Every initially filled cell should be represented by "#". Note In the third sample, there is no way to fill a cell with no empty neighbours. In the forth sample, Woll does not have to fill anything, so we should output the field from the input. | 2,200 | true | true | false | false | false | true | false | false | false | false | 9,540 |
72A | Goshtasp was known to be a good programmer in his school. One day Vishtasp, Goshtasp's friend, asked him to solve this task: Given a positive integer _n_, you should determine whether _n_ is rich. The positive integer _x_ is rich, if there exists some set of distinct numbers _a_1,u2009_a_2,u2009...,u2009_a__m_ such that . In addition: every _a__i_ should be either a prime number, or equal to 1. Vishtasp said that he would share his Eidi 50u2009/u200950 with Goshtasp, if he could solve the task. Eidi is money given to children for Noruz by their parents and/or relatives. Goshtasp needs to solve this problem to get money, you need to solve it to get score! Input Input contains a single positive integer _n_ (1u2009≤u2009_n_u2009≤u200910000). Output If the number is not rich print 0. Otherwise print the numbers _a_1,u2009...,u2009_a__m_. If several solutions exist print the lexicographically latest solution. Answers are compared as sequences of numbers, not as strings. For comparing two sequences _a_1,u2009...,u2009_a__m_ and _b_1,u2009...,u2009_b__n_ we first find the first index _i_ such that _a__i_u2009≠u2009_b__i_, if _a__i_u2009<u2009_b__i_ then _a_ is lexicographically earlier and if _b__i_u2009<u2009_a__i_ then _b_ is lexicographically earlier. If _m_u2009≠u2009_n_ we add zeroes at the end of the smaller sequence (only for the moment of comparison) and then perform the comparison. You do not need to minimize the number of elements in sequence (i.e. _m_). You just need to print the lexicographically latest solution. See samples to find out how to print the sequence. | 1,800 | true | true | false | false | false | false | false | false | false | false | 9,611 |
1910A | On the official website of Berland, each account has two parameters: username and ID. Username is a string consisting of lowercase Latin letters and/or digits, which contains at least one letter. For example, user0, 1fox1, zzzz are correct usernames, but 1337 and User22 are not. The ID of the account for a given username is generated as follows: a positive integer without leading zeroes is appended to the end of the username. For example, the ID user0125 can be generated by the following usernames: user012, user01, user0; but neither by user nor us. You are given a string $$$s$$$xa0— a valid ID. Your task is to determine any valid username that can generate the given ID. If there are several correct usernames, you can print any of them. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^3$$$)xa0— the number of test cases. The only line of each test case contains a string $$$s$$$ ($$$2 le s le 50$$$), consisting of lowercase Latin letters and/or digits. Additional constraint on input: there is at least one valid username that can generate the given ID. Output For each test case on a separate line, print a stringxa0— any valid username that can generate the given ID. If there are multiple correct usernames, you can print any of them. Example Input 4 user0125 a1 kotlin990000 1code0forces101 Output user0 a kotlin9 1code0forces | 1,100 | false | false | true | false | false | false | false | false | false | false | 847 |
329C | I have an undirected graph consisting of _n_ nodes, numbered 1 through _n_. Each node has at most two incident edges. For each pair of nodes, there is at most an edge connecting them. No edge connects a node to itself. I would like to create a new graph in such a way that: The new graph consists of the same number of nodes and edges as the old graph. The properties in the first paragraph still hold. For each two nodes _u_ and _v_, if there is an edge connecting them in the old graph, there is no edge connecting them in the new graph. Help me construct the new graph, or tell me if it is impossible. Input The first line consists of two space-separated integers: _n_ and _m_ (1u2009≤u2009_m_u2009≤u2009_n_u2009≤u2009105), denoting the number of nodes and edges, respectively. Then _m_ lines follow. Each of the _m_ lines consists of two space-separated integers _u_ and _v_ (1u2009≤u2009_u_,u2009_v_u2009≤u2009_n_;xa0_u_u2009≠u2009_v_), denoting an edge between nodes _u_ and _v_. Output If it is not possible to construct a new graph with the mentioned properties, output a single line consisting of -1. Otherwise, output exactly _m_ lines. Each line should contain a description of edge in the same way as used in the input format. Examples Input 8 7 1 2 2 3 4 5 5 6 6 8 8 7 7 4 Output 1 4 4 6 1 6 2 7 7 5 8 5 2 8 Note The old graph of the first example: A possible new graph for the first example: In the second example, we cannot create any new graph. The old graph of the third example: A possible new graph for the third example: | 2,400 | false | false | false | false | false | true | false | false | false | false | 8,527 |
621A | Problem - 621A - 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 *900 No tag edit access → Contest materials sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the _n_ integers, the sum is an even integer 0. Input The first line of the input contains one integer, _n_ (1u2009≤u2009_n_u2009≤u2009100u2009000). The next line contains _n_ space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Print the maximum possible even sum that can be obtained if we use some of the given integers. Examples Input 3 1 2 3 Output 6 Input 5 999999999 999999999 999999999 999999999 999999999 Output 3999999996 Note In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999u2009999u2009999. | 900 | false | false | true | false | false | false | false | false | false | false | 7,351 |
909B | Problem - 909B - 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 math *1300 No tag edit access → Contest materials ") Editorial") . You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given _N_. Input The only input line contains a single integer _N_ (1u2009≤u2009_N_u2009≤u2009100). Output Output a single integer - the minimal number of layers required to draw the segments for the given _N_. Examples Input 2 Output 2 Input 3 Output 4 Input 4 Output 6 Note As an example, here are the segments and their optimal arrangement into layers for _N_u2009=u20094. | 1,300 | true | false | false | false | false | true | false | false | false | false | 6,111 |
815A | On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with _n_ rows and _m_ columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the _i_-th row and _j_-th column should be equal to _g__i_,u2009_j_. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100), the number of rows and the number of columns in the grid, respectively. The next _n_ lines each contain _m_ integers. In particular, the _j_-th integer in the _i_-th of these rows contains _g__i_,u2009_j_ (0u2009≤u2009_g__i_,u2009_j_u2009≤u2009500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer _k_, the minimum number of moves necessary to beat the level. The next _k_ lines should each contain one of the following, describing the moves in the order they must be done: row _x_, (1u2009≤u2009_x_u2009≤u2009_n_) describing a move of the form "choose the _x_-th row". col _x_, (1u2009≤u2009_x_u2009≤u2009_m_) describing a move of the form "choose the _x_-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3. | 1,700 | false | true | true | false | false | false | true | false | false | false | 6,500 |
1930A | There are $$$2n$$$ positive integers written on a whiteboard. Being bored, you decided to play a one-player game with the numbers on the whiteboard. You start with a score of $$$0$$$. You will increase your score by performing the following move exactly $$$n$$$ times: Choose two integers $$$x$$$ and $$$y$$$ that are written on the whiteboard. Add $$$min(x,y)$$$ to your score. Erase $$$x$$$ and $$$y$$$ from the whiteboard. Note that after performing the move $$$n$$$ times, there will be no more integers written on the whiteboard. Find the maximum final score you can achieve if you optimally perform the $$$n$$$ moves. Input Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 5000$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 leq n leq 50$$$)xa0— the number of integers written on the whiteboard is $$$2n$$$. The second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,ldots,a_{2n}$$$ ($$$1 leq a_i leq 10^7$$$)xa0— the numbers written on the whiteboard. Output For each test case, output the maximum final score that you can achieve. Example Input 3 1 2 3 2 1 1 2 1 3 1 1 1 1 1 1 Note In the first test case, you can only make one move. You select $$$x=2$$$ and $$$y=3$$$, and your score will be $$$min(x,y)=2$$$. In the second test case, the following is a sequence of moves that achieves a final score of $$$2$$$: In the first move, select $$$x=1$$$ and $$$y=1$$$. Then, add $$$min(x,y)=1$$$ to the score. After erasing $$$x$$$ and $$$y$$$, the integers left on the whiteboard are $$$1$$$ and $$$2$$$. In the second move, select $$$x=1$$$ and $$$y=2$$$. Then, add $$$min(x,y)=1$$$ to the score. After removing $$$x$$$ and $$$y$$$, no more integers will be left on the whiteboard. It can be proved that it is not possible to get a score greater than $$$2$$$. In the third test case, you will perform the move thrice, adding $$$1$$$ to the score each time. | 800 | false | true | false | false | false | false | false | false | true | false | 711 |
436B | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular _n_u2009×u2009_m_ field. The park has _k_ spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time. Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries. Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. Input The first line contains three integers _n_,u2009_m_,u2009_k_ (2u2009≤u2009_n_,u2009_m_u2009≤u20092000;xa00u2009≤u2009_k_u2009≤u2009_m_(_n_u2009-u20091)). Each of the next _n_ lines contains _m_ characters — the description of the park. The characters in the _i_-th line describe the _i_-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly _k_ spiders. Output Print _m_ integers: the _j_-th integer must show the number of spiders Om Nom will see if he starts his walk from the _j_-th cell of the first row. The cells in any row of the field are numbered from left to right. Note Consider the first sample. The notes below show how the spider arrangement changes on the field over time: ... ... ..U ... R.L -> .*U -> L.R -> ... R.U .R. ..R ... Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | 1,400 | true | false | true | false | false | false | false | false | false | false | 8,096 |
1659C | You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $$$0$$$. There are $$$n$$$ unconquered kingdoms at positions $$$0<x_1<x_2<ldots<x_n$$$. You want to conquer all other kingdoms. There are two actions available to you: You can change the location of your capital (let its current position be $$$c_1$$$) to any other conquered kingdom (let its position be $$$c_2$$$) at a cost of $$$acdot c_1-c_2$$$. From the current capital (let its current position be $$$c_1$$$) you can conquer an unconquered kingdom (let its position be $$$c_2$$$) at a cost of $$$bcdot c_1-c_2$$$. You cannot conquer a kingdom if there is an unconquered kingdom between the target and your capital. Note that you cannot place the capital at a point without a kingdom. In other words, at any point, your capital can only be at $$$0$$$ or one of $$$x_1,x_2,ldots,x_n$$$. Also note that conquering a kingdom does not change the position of your capital. Find the minimum total cost to conquer all kingdoms. Your capital can be anywhere at the end. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$) xa0— the number of test cases. The description of each test case follows. The first line of each test case contains $$$3$$$ integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 leq n leq 2 cdot 10^5$$$; $$$1 leq a,b leq 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, ldots, x_n$$$ ($$$1 leq x_1 < x_2 < ldots < x_n leq 10^8$$$). The sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output a single integer xa0— the minimum cost to conquer all kingdoms. Example Input 4 5 2 7 3 5 12 13 21 5 6 3 1 5 6 21 30 2 9 3 10 15 11 27182 31415 16 18 33 98 874 989 4848 20458 34365 38117 72030 Output 173 171 75 3298918744 Note Here is an optimal sequence of moves for the second test case: 1. Conquer the kingdom at position $$$1$$$ with cost $$$3cdot(1-0)=3$$$. 2. Move the capital to the kingdom at position $$$1$$$ with cost $$$6cdot(1-0)=6$$$. 3. Conquer the kingdom at position $$$5$$$ with cost $$$3cdot(5-1)=12$$$. 4. Move the capital to the kingdom at position $$$5$$$ with cost $$$6cdot(5-1)=24$$$. 5. Conquer the kingdom at position $$$6$$$ with cost $$$3cdot(6-5)=3$$$. 6. Conquer the kingdom at position $$$21$$$ with cost $$$3cdot(21-5)=48$$$. 7. Conquer the kingdom at position $$$30$$$ with cost $$$3cdot(30-5)=75$$$. The total cost is $$$3+6+12+24+3+48+75=171$$$. You cannot get a lower cost than this. | 1,500 | true | true | true | true | false | false | true | true | false | false | 2,330 |
356C | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of _n_ compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip. The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student. However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number. After all the swaps each compartment should either have no student left, or have a company of three or four students. Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u2009106) — the number of compartments in the carriage. The second line contains _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_ showing how many students ride in each compartment (0u2009≤u2009_a__i_u2009≤u20094). It is guaranteed that at least one student is riding in the train. Output If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. | 2,100 | false | true | true | false | false | true | false | false | false | false | 8,409 |
1983F | You have an array of non-negative integers $$$a_1, a_2, ldots, a_n$$$. The value of a sub-array of length $$$ge 2$$$, $$$a[l, r] = [a_l, a_{l+1}, ldots, a_r]$$$ is the minimum value of $$$a_i oplus a_j$$$ such that $$$l le i < j le r$$$, where $$$oplus$$$ is the xor (exclusive-or) operator. You have to find the $$$k$$$-th smallest value over all sub-arrays of length $$$ge 2$$$. Input The first line of the input contains multiple test cases $$$t$$$ ($$$1 le t le 2 cdot 10^4$$$). The first line of each test case contains integer numbers $$$n$$$ and $$$k$$$ ($$$2 le n le 10^5$$$, $$$1 le k le frac{ncdot(n-1)}{2}$$$). The second line of the input contains $$$n$$$ non-negative integer numbers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^9$$$) — the array itself. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Output Print the $$$k$$$-th smallest value obtained over all subarrays of length at least $$$2$$$. Example Input 4 5 2 1 2 3 4 5 2 1 4 3 4 6 1 2 4 8 5 9 1 2 3 4 5 Note In the first testcase, we have subarrays with their smallest exclusive-or pair as: $$$[1,2]: 3$$$ $$$[2,3]: 1$$$ $$$[3,4]: 7$$$ $$$[4,5]: 1$$$ $$$[1,2,3]: 1$$$ $$$[2,3,4]: 1$$$ $$$[3,4,5]: 1$$$ $$$[1,2,3,4]: 1$$$ $$$[2,3,4,5]: 1$$$ $$$[1,2,3,4,5]: 1$$$ The sorted order would be: $$$1, 1, 1, 1, 1, 1, 1, 1, 3, 7$$$. Therefore, the second smallest element would be $$$1$$$. | 2,500 | false | true | false | false | true | false | false | true | false | false | 385 |
679E | Limak, a bear, isn't good at handling queries. So, he asks you to do it. We say that powers of 42 (numbers 1,u200942,u20091764,u2009...) are bad. Other numbers are good. You are given a sequence of _n_ good integers _t_1,u2009_t_2,u2009...,u2009_t__n_. Your task is to handle _q_ queries of three types: 1. 1 ixa0— print _t__i_ in a separate line. 2. 2 a b xxa0— for set _t__i_ to _x_. It's guaranteed that _x_ is a good number. 3. 3 a b xxa0— for increase _t__i_ by _x_. After this repeat the process while at least one _t__i_ is bad. You can note that after each query all _t__i_ are good. Input The first line of the input contains two integers _n_ and _q_ (1u2009≤u2009_n_,u2009_q_u2009≤u2009100u2009000)xa0— the size of Limak's sequence and the number of queries, respectively. The second line of the input contains _n_ integers _t_1,u2009_t_2,u2009...,u2009_t__n_ (2u2009≤u2009_t__i_u2009≤u2009109)xa0— initial elements of Limak's sequence. All _t__i_ are good. Then, _q_ lines follow. The _i_-th of them describes the _i_-th query. The first number in the line is an integer _type__i_ (1u2009≤u2009_type__i_u2009≤u20093)xa0— the type of the query. There is at least one query of the first type, so the output won't be empty. In queries of the second and the third type there is 1u2009≤u2009_a_u2009≤u2009_b_u2009≤u2009_n_. In queries of the second type an integer _x_ (2u2009≤u2009_x_u2009≤u2009109) is guaranteed to be good. In queries of the third type an integer _x_ (1u2009≤u2009_x_u2009≤u2009109) may be bad. Output For each query of the first type, print the answer in a separate line. Example Input 6 12 40 1700 7 1672 4 1722 3 2 4 42 1 2 1 3 3 2 6 50 1 2 1 4 1 6 2 3 4 41 3 1 5 1 1 1 1 3 1 5 Output 1742 49 1842 1814 1822 43 44 107 Note After a query 3 2 4 42 the sequence is 40,u20091742,u200949,u20091714,u20094,u20091722. After a query 3 2 6 50 the sequence is 40,u20091842,u2009149,u20091814,u2009104,u20091822. After a query 2 3 4 41 the sequence is 40,u20091842,u200941,u200941,u2009104,u20091822. After a query 3 1 5 1 the sequence is 43,u20091845,u200944,u200944,u2009107,u20091822. | 3,100 | false | false | false | false | true | false | false | false | false | false | 7,106 |
1227G | You are given an integer array $$$a_1, a_2, dots, a_n$$$, where $$$a_i$$$ represents the number of blocks at the $$$i$$$-th position. It is guaranteed that $$$1 le a_i le n$$$. In one operation you can choose a subset of indices of the given array and remove one block in each of these indices. You can't remove a block from a position without blocks. All subsets that you choose should be different (unique). You need to remove all blocks in the array using at most $$$n+1$$$ operations. It can be proved that the answer always exists. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 10^3$$$)xa0— length of the given array. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le n$$$)xa0— numbers of blocks at positions $$$1, 2, dots, n$$$. Output In the first line print an integer $$$op$$$ ($$$0 le op le n+1$$$). In each of the following $$$op$$$ lines, print a binary string $$$s$$$ of length $$$n$$$. If $$$s_i=$$$'0', it means that the position $$$i$$$ is not in the chosen subset. Otherwise, $$$s_i$$$ should be equal to '1' and the position $$$i$$$ is in the chosen subset. All binary strings should be distinct (unique) and $$$a_i$$$ should be equal to the sum of $$$s_i$$$ among all chosen binary strings. If there are multiple possible answers, you can print any. It can be proved that an answer always exists. Examples Output 6 11111 01111 10111 11011 11101 11110 Output 5 11000 10000 10100 10010 10001 Output 5 11111 10111 10101 00111 10100 Note In the first example, the number of blocks decrease like that: $$$lbrace 5,5,5,5,5 brace o lbrace 4,4,4,4,4 brace o lbrace 4,3,3,3,3 brace o lbrace 3,3,2,2,2 brace o lbrace 2,2,2,1,1 brace o lbrace 1,1,1,1,0 brace o lbrace 0,0,0,0,0 brace$$$. And we can note that each operation differs from others. | 2,600 | false | false | false | false | false | true | false | false | false | false | 4,536 |
1982D | Nikita loves mountains and has finally decided to visit the Berlyand mountain range! The range was so beautiful that Nikita decided to capture it on a map. The map is a table of $$$n$$$ rows and $$$m$$$ columns, with each cell containing a non-negative integer representing the height of the mountain. He also noticed that mountains come in two types: With snowy caps. Without snowy caps. Nikita is a very pragmatic person. He wants the sum of the heights of the mountains with snowy caps to be equal to the sum of the heights of the mountains without them. He has arranged with the mayor of Berlyand, Polikarp Polikarpovich, to allow him to transform the landscape. Nikita can perform transformations on submatrices of size $$$k imes k$$$ as follows: he can add an integer constant $$$c$$$ to the heights of the mountains within this area, but the type of the mountain remains unchanged. Nikita can choose the constant $$$c$$$ independently for each transformation. Note that $$$c$$$ can be negative. Before making the transformations, Nikita asks you to find out if it is possible to achieve equality of the sums, or if it is impossible. It doesn't matter at what cost, even if the mountains turn into canyons and have negative heights. If only one type of mountain is represented on the map, then the sum of the heights of the other type of mountain is considered to be zero. Input Each test consists of several test cases. The first line contains an integer $$$t$$$ ($$$1 le t le 10^{4}$$$)xa0— the number of test cases. This is followed by a description of test cases. The first line of each test case contains three integers $$$n, m, k$$$ ($$$1 le n, m le 500, 1 le k le min(n, m)$$$). The next $$$n$$$ lines of each test case contain $$$m$$$ integers $$$a_{i j}$$$ ($$$0 le a_{i j} le 10^{9}$$$)xa0— the initial heights of the mountains. The next $$$n$$$ binary strings of length $$$m$$$ for each test case determine the type of mountain, '$$$0$$$'xa0— with snowy caps, '$$$1$$$'xa0— without them. It is guaranteed that the sum of $$$n cdot m$$$ for all test cases does not exceed $$$250,000$$$. Output For each test case, output "YES" without quotes if it is possible to equalize the sums of the mountain heights, otherwise output "NO" without quotes. You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer). Example Input 8 3 3 2 7 11 3 4 2 3 0 1 15 100 010 000 4 4 3 123 413 24 233 123 42 0 216 22 1 1 53 427 763 22 6 0101 1111 1010 0101 3 3 2 2 1 1 1 1 2 1 5 4 010 101 010 3 3 2 2 1 1 1 1 2 1 5 3 010 101 010 3 4 3 46 49 50 1 19 30 23 12 30 25 1 46 1000 0100 0010 5 4 4 39 30 0 17 22 42 30 13 10 44 46 35 12 19 9 39 21 0 45 40 1000 1111 0011 0111 1100 2 2 2 3 4 6 7 00 00 2 2 2 0 0 2 0 01 00 Output YES NO YES NO YES NO YES YES Note The mountain array from the first test case looks like this: Initially, the sum of the heights of the mountains with snowy caps is $$$11 + 3 + 4 + 3 + 0 + 1 + 15 = 37$$$, and without them is $$$7 + 2 = 9$$$. To equalize these sums, we can perform two transformations: First transformation: Note that the constant $$$c$$$ can be negative. After the first transformation, the mountain array looks like this: Second transformation: As a result, the mountain array looks like this: The sum of the heights of the mountains with snowy caps is $$$17 + 9 + 9 - 16 - 20 - 19 + 15 = -5$$$, and without them is $$$7 - 12 = -5$$$, thus the answer is YES. | 1,700 | true | false | true | false | true | false | true | false | false | false | 393 |
550E | Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '', and the arguments and the result of the implication are written as '0' (_false_) and '1' (_true_). According to the definition of the implication: When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example, . When there are brackets, we first calculate the expression in brackets. For example, . For the given logical expression determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets. Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u2009100u2009000) — the number of arguments in a logical expression. The second line contains _n_ numbers _a_1,u2009_a_2,u2009...,u2009_a__n_ (), which means the values of arguments in the expression in the order they occur. Output Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0. Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line. The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to _n_. The order in which the digits follow in the expression from left to right must coincide with _a_1,u2009_a_2,u2009...,u2009_a__n_. The expression should be correct. More formally, a correct expression is determined as follows: Expressions "0", "1" (without the quotes) are correct. If _v_1, _v_2 are correct, then _v_1->_v_2 is a correct expression. If _v_ is a correct expression, then (_v_) is a correct expression. The total number of characters in the resulting expression mustn't exceed 106. If there are multiple possible answers, you are allowed to print any of them. Examples Output YES (((0)->1)->(1->0)) | 2,200 | true | true | true | false | false | true | false | false | false | false | 7,633 |
1656E | You are given an undirected unrooted tree, i.e. a connected undirected graph without cycles. You must assign a nonzero integer weight to each vertex so that the following is satisfied: if any vertex of the tree is removed, then each of the remaining connected components has the same sum of weights in its vertices. Input The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 leq n leq 10^5$$$) — the number of vertices of the tree. The next $$$n-1$$$ lines of each case contain each two integers $$$u, v$$$ ($$$1 leq u,v leq n$$$) denoting that there is an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree. The sum of $$$n$$$ for all test cases is at most $$$10^5$$$. Output For each test case, you must output one line with $$$n$$$ space separated integers $$$a_1, a_2, ldots, a_n$$$, where $$$a_i$$$ is the weight assigned to vertex $$$i$$$. The weights must satisfy $$$-10^5 leq a_i leq 10^5$$$ and $$$a_i eq 0$$$. It can be shown that there always exists a solution satisfying these constraints. If there are multiple possible solutions, output any of them. Example Input 2 5 1 2 1 3 3 4 3 5 3 1 2 1 3 Note In the first case, when removing vertex $$$1$$$ all remaining connected components have sum $$$5$$$ and when removing vertex $$$3$$$ all remaining connected components have sum $$$2$$$. When removing other vertices, there is only one remaining connected component so all remaining connected components have the same sum. | 2,200 | true | false | false | false | false | true | false | false | false | false | 2,350 |
120D | Three sons inherited from their father a rectangular corn fiend divided into _n_u2009×u2009_m_ squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, which is why he bequeathed to divide his field into three parts containing _A_, _B_ and _C_ tons of corn. The field should be divided by two parallel lines. The lines should be parallel to one side of the field and to each other. The lines should go strictly between the squares of the field. Each resulting part of the field should consist of at least one square. Your task is to find the number of ways to divide the field as is described above, that is, to mark two lines, dividing the field in three parts so that on one of the resulting parts grew _A_ tons of corn, _B_ on another one and _C_ on the remaining one. Input The first line contains space-separated integers _n_ and _m_ — the sizes of the original (1u2009≤u2009_n_,u2009_m_u2009≤u200950,u2009_max_(_n_,u2009_m_)u2009≥u20093). Then the field's description follows: _n_ lines, each containing _m_ space-separated integers _c__ij_, (0u2009≤u2009_c__ij_u2009≤u2009100) — the number of tons of corn each square contains. The last line contains space-separated integers _A_,u2009_B_,u2009_C_ (0u2009≤u2009_A_,u2009_B_,u2009_C_u2009≤u2009106). Output Print the answer to the problem: the number of ways to divide the father's field so that one of the resulting parts contained _A_ tons of corn, another one contained _B_ tons, and the remaining one contained _C_ tons. If no such way exists, print 0. Examples Input 3 3 1 1 1 1 1 1 1 1 1 3 3 3 Input 2 5 1 1 1 1 1 2 2 2 2 2 3 6 6 Input 3 3 1 2 3 3 1 2 2 3 1 5 6 7 Note The lines dividing the field can be horizontal or vertical, but they should be parallel to each other. | 1,400 | false | false | false | false | false | false | true | false | false | false | 9,403 |
1765E | Monocarp is playing a MMORPG. There are two commonly used types of currency in this MMORPG — gold coins and silver coins. Monocarp wants to buy a new weapon for his character, and that weapon costs $$$n$$$ silver coins. Unfortunately, right now, Monocarp has no coins at all. Monocarp can earn gold coins by completing quests in the game. Each quest yields exactly one gold coin. Monocarp can also exchange coins via the in-game trading system. Monocarp has spent days analyzing the in-game economy; he came to the following conclusion: it is possible to sell one gold coin for $$$a$$$ silver coins (i.u2009e. Monocarp can lose one gold coin to gain $$$a$$$ silver coins), or buy one gold coin for $$$b$$$ silver coins (i.u2009e. Monocarp can lose $$$b$$$ silver coins to gain one gold coin). Now Monocarp wants to calculate the minimum number of quests that he has to complete in order to have at least $$$n$$$ silver coins after some abuse of the in-game economy. Note that Monocarp can perform exchanges of both types (selling and buying gold coins for silver coins) any number of times. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10^4$$$) — the number of test cases. Each test case consists of one line containing three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 le n le 10^7$$$; $$$1 le a, b le 50$$$). Output For each test case, print one integer — the minimum possible number of quests Monocarp has to complete. Example Input 4 100 25 30 9999997 25 50 52 50 48 49 50 1 Note In the first test case of the example, Monocarp should complete $$$4$$$ quests, and then sell $$$4$$$ gold coins for $$$100$$$ silver coins. In the second test case, Monocarp should complete $$$400000$$$ quests, and then sell $$$400000$$$ gold coins for $$$10$$$ million silver coins. In the third test case, Monocarp should complete $$$1$$$ quest, sell the gold coin for $$$50$$$ silver coins, buy a gold coin for $$$48$$$ silver coins, and then sell it again for $$$50$$$ coins. So, he will have $$$52$$$ silver coins. In the fourth test case, Monocarp should complete $$$1$$$ quest and then sell the gold coin he has obtained for $$$50$$$ silver coins. | 1,000 | true | false | false | false | false | false | true | false | false | false | 1,713 |
1726C | Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $$$s$$$ of length $$$2 n$$$. Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $$$2 n$$$ vertices using the balanced bracket sequence $$$s$$$. For any two distinct vertices $$$i$$$ and $$$j$$$ ($$$1 le i < j le 2 n$$$), Topshe draws an edge (undirected and unweighted) between these two nodes if and only if the subsegment $$$s[i ldots j]$$$ forms a balanced bracket sequence. Determine the number of connected components in Topshe's graph. See the Notes section for definitions of the underlined terms. Input Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^5$$$) — the number of opening brackets in string $$$s$$$. The second line of each test case contains a string $$$s$$$ of length $$$2 n$$$xa0— a balanced bracket sequence consisting of $$$n$$$ opening brackets "(", and $$$n$$$ closing brackets ")". It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output a single integerxa0— the number of connected components in Topshe's graph. Example Input 4 1 () 3 ()(()) 3 ((())) 4 (())(()) Note Sample explanation: In the first test case, the graph constructed from the bracket sequence (), is just a graph containing nodes $$$1$$$ and $$$2$$$ connected by a single edge. In the second test case, the graph constructed from the bracket sequence ()(()) would be the following (containing two connected components): Definition of Underlined Terms: A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters $$$+$$$ and $$$1$$$. For example, sequences (())(), (), and (()(())) are balanced, while )(, ((), and (()))( are not. The subsegment $$$s[l ldots r]$$$ denotes the sequence $$$[s_l, s_{l + 1}, ldots, s_r]$$$. 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 these vertices, but adding any other vertex to $$$X$$$ violates this rule. | 1,300 | false | true | false | false | true | false | false | false | false | true | 1,931 |
1365C | # Rotation Matching Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n.Let’s call them a and b.Note that a permutation of n elements is a sequence of numbers a1, a 2, . . . , a n, in which every number from 1 to n appears exactly once. The message can be decoded by an arrangement of sequence a and b, such that the number of matching pairs of elements between them is maximum. A pair of elements ai and bj is said to match if: • i = j, that is, they are at the same index. • ai = bj His two disciples are allowed to perform the following operation any number of times: • choose a number k and cyclically shift one of the permutations to the left or right k times. A single cyclic shift to the left on any permutation c is an operation that sets c1 := c2, c 2 := c3, . . . , c n := c1 simultaneously. Likewise, a single cyclic shift to the right on any permutation c is an operation that sets c1 := cn, c 2 := c1, . . . , c n := cn−1 simultaneously. Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times. # Input The first line of the input contains a single integer n (1 ≤ n ≤ 2 · 10 5) x16 the size of the arrays. The second line contains n integers a1, a2, . . . , an (1 ≤ ai ≤ n) x16 the elements of the first permutation. The third line contains n integers b1, b2, . . . , bn (1 ≤ bi ≤ n) x16 the elements of the second permutation. # Output Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times. # Examples standard input standard output 51 2 3 4 5 2 3 4 5 1 555 4 3 2 1 1 2 3 4 5 141 3 2 4 4 2 3 1 2 Page 1 of 2 Note For the first case: b can be shifted to the right by k = 1 . The resulting permutations will be {1, 2, 3, 4, 5} and {1, 2, 3, 4, 5}.For the second case: The operation is not required. For all possible rotations of a and b, the number of matching pairs won’t exceed 1.For the third case: b can be shifted to the left by k = 1 . The resulting permutations will be {1, 3, 2, 4} and {2, 3, 1, 4}. Positions 2 and 4 have matching pairs of elements. For all possible rotations of a and b,the number of matching pairs won’t exceed 2. Page 2 of 2 | 1,400 | false | true | true | false | true | true | false | false | false | false | 3,855 |
1874A | Jellyfish has $$$n$$$ green apples with values $$$a_1, a_2, dots, a_n$$$ and Gellyfish has $$$m$$$ green apples with values $$$b_1,b_2,ldots,b_m$$$. They will play a game with $$$k$$$ rounds. For $$$i=1,2,ldots,k$$$ in this order, they will perform the following actions: If $$$i$$$ is odd, Jellyfish can choose to swap one of her apples with one of Gellyfish's apples or do nothing. If $$$i$$$ is even, Gellyfish can choose to swap one of his apples with one of Jellyfish's apples or do nothing. Both players want to maximize the sum of the values of their apples. Since you are one of the smartest people in the world, Jellyfish wants you to tell her the final sum of the value of her apples after all $$$k$$$ rounds of the game. Assume that both Jellyfish and Gellyfish play optimally to maximize the sum of values of their apples. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 leq t leq 2000$$$). The description of the test cases follows. The first line of each test case contains three integers, $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 leq n, m leq 50$$$, $$$1 leq k leq 10^9$$$)xa0— the number of green apples Jellyfish has, the number of green apples Gellyfish has and the number of rounds of the game respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 leq a_i leq 10^9$$$)xa0— the values of Jellyfish's green apples. The third line of each test case contains $$$m$$$ integers $$$b_1, b_2, dots, b_m$$$ ($$$1 leq b_i leq 10^9$$$)xa0— the values of Gellyfish's green apples. Do note that the sum of $$$n$$$ and $$$m$$$ over all test cases are both not bounded. Output For each test case, output a single integerxa0— the final sum of the values of Jellyfish's apples. Example Input 4 2 2 1 1 2 3 4 1 1 10000 1 2 4 5 11037 1 1 4 5 1 9 1 9 8 1 1 1 2 1 Note In the first test case, Jellyfish will swap the apple of value $$$1$$$ and $$$4$$$. In the second test case, both players will swap the two apples $$$10,000$$$ times. In the fourth test case, Jellyfish will do nothing. | 1,200 | false | true | true | false | false | false | true | false | false | false | 1,036 |
1495E | Qingshan and Daniel are going to play a card game. But it will be so boring if only two persons play this. So they will make $$$n$$$ robots in total to play this game automatically. Robots made by Qingshan belong to the team $$$1$$$, and robots made by Daniel belong to the team $$$2$$$. Robot $$$i$$$ belongs to team $$$t_i$$$. Before the game starts, $$$a_i$$$ cards are given for robot $$$i$$$. The rules for this card game are simple: Before the start, the robots are arranged in a circle in the order or their indices. The robots will discard cards in some order, in each step one robot discards a single card. When the game starts, robot $$$1$$$ will discard one of its cards. After that, robots will follow the following rules: If robot $$$i$$$ discards the card last, the nearest robot whose team is opposite from $$$i$$$'s will discard the card next. In another word $$$j$$$ will discard a card right after $$$i$$$, if and only if among all $$$j$$$ that satisfy $$$t_i e t_j$$$, $$$dist(i,j)$$$ (definition is below) is minimum. The robot who has no cards should quit the game immediately. This robot won't be considered in the next steps. When no robot can discard the card next, the game ends. We define the distance from robot $$$x$$$ to robot $$$y$$$ as $$$dist(x,y)=(y-x+n)bmod n$$$. It is similar to the oriented distance on the circle. For example, when $$$n=5$$$, the distance from $$$1$$$ to $$$3$$$ is $$$dist(1,3)=(3-1+5)bmod 5=2$$$, the distance from $$$3$$$ to $$$1$$$ is $$$dist(3,1)=(1-3+5)bmod 5 =3$$$. Later, Qingshan finds out that it will take so much time to see how robots play. She wants to know the result as quickly as possible. You, as Qingshan's fan, are asked to calculate an array $$$<dist(1,3)$$$. Then robot $$$1$$$ discards the card next. Robot $$$3$$$ doesn't discard the card next because $$$t_2=t_3$$$. If we write down the index of the robot who discards a card in time order, it will be the sequence $$$[1,2,1,2,1,2,1,2]$$$. So robots $$$1$$$, $$$2$$$ and $$$3$$$ discard $$$5$$$, $$$5$$$ and $$$0$$$ cards, respectively. And the answer is $$$(((5 oplus 1^2)+1) imes((5 oplus 2^2)+1) imes((0 oplus 3^2)+1)) bmod 10^9+7=(5 imes 2 imes 10)bmod 10^9+7=100$$$. | 3,200 | false | true | true | false | true | false | true | false | false | false | 3,192 |
64E | Problem - 64E - Codeforces =============== xa0 and _a_,u2009_b_ are primes. Input The only given line contains an integer number _n_ (2u2009≤u2009_n_u2009≤u200910000). Output Print the space separated pair of the required numbers _a_, _b_. Examples Input 10 Output 7 11 Input 97 Output 97 97 | 1,800 | true | false | false | false | false | false | true | false | false | false | 9,651 |
379E | Due to atheistic Soviet past, Christmas wasn't officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tree, a Santa-like 'Grandfather Frost', presents and huge family reunions and dinner parties all over the country. Bying a Tree at the New Year and installing it in the house is a tradition. Usually the whole family decorates the tree on the New Year Eve. We hope that Codeforces is a big and loving family, so in this problem we are going to decorate a tree as well. So, our decoration consists of _n_ pieces, each piece is a piece of colored paper, its border is a closed polyline of a special shape. The pieces go one by one as is shown on the picture. The _i_-th piece is a polyline that goes through points: (0,u20090), (0,u2009_y_0), (1,u2009_y_1), (2,u2009_y_2), ..., (_k_,u2009_y__k_), (_k_,u20090). The width of each piece equals _k_. The figure to the left shows the decoration, the figure to the right shows the individual pieces it consists of. The piece number 1 (shown red on the figure) is the outer piece (we see it completely), piece number 2 (shown yellow) follows it (we don't see it completely as it is partially closed by the first piece) and so on. The programmers are quite curious guys, so the moment we hung a decoration on the New Year tree we started to wonder: what area of each piece can people see? Input The first line contains two integers, _n_ and _k_ (1u2009≤u2009_n_,u2009_k_u2009≤u2009300). Each of the following _n_ lines contains _k_u2009+u20091 integers — the description of the polyline. If the _i_-th line contains ontegers _y__i_,u20090,u2009_y__i_,u20091,u2009...,u2009_y__i_,u2009_k_, that means that the polyline of the _i_-th piece goes through points (0,u20090), (0,u2009_y__i_,u20090), (1,u2009_y__i_,u20091), (2,u2009_y__i_,u20092), ..., (_k_,u2009_y__i_,u2009_k_), (_k_,u20090) (1u2009≤u2009_y__i_,u2009_j_u2009≤u20091000). Output Print _n_ real numbers — for each polyline, the area of its visible part. The answer will be considered correct if its relative or absolute error do not exceed 10u2009-u20094. Examples Output 3.000000000000 0.500000000000 Output 4.500000000000 1.250000000000 0.050000000000 0.016666666667 | 2,500 | false | false | false | false | false | false | false | false | true | false | 8,313 |
620F | You are given an array with _n_ integers _a__i_ and _m_ queries. Each query is described by two integers (_l__j_,u2009_r__j_). Let's define the function . The function is defined for only _u_u2009≤u2009_v_. For each query print the maximal value of the function _f_(_a__x_,u2009_a__y_) over all _l__j_u2009≤u2009_x_,u2009_y_u2009≤u2009_r__j_,u2009 _a__x_u2009≤u2009_a__y_. Input The first line contains two integers _n_,u2009_m_ (1u2009≤u2009_n_u2009≤u20095·104,u2009 1u2009≤u2009_m_u2009≤u20095·103) — the size of the array and the number of the queries. The second line contains _n_ integers _a__i_ (1u2009≤u2009_a__i_u2009≤u2009106) — the elements of the array _a_. Each of the next _m_ lines contains two integers _l__j_,u2009_r__j_ (1u2009≤u2009_l__j_u2009≤u2009_r__j_u2009≤u2009_n_) – the parameters of the _j_-th query. Output For each query print the value _a__j_ on a separate line — the maximal value of the function _f_(_a__x_,u2009_a__y_) over all _l__j_u2009≤u2009_x_,u2009_y_u2009≤u2009_r__j_,u2009 _a__x_u2009≤u2009_a__y_. Examples Input 6 3 1 2 3 4 5 6 1 6 2 5 3 4 Input 6 20 10 21312 2314 214 1 322 1 1 1 2 1 3 1 4 1 5 1 6 2 2 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 4 4 5 4 6 5 5 5 6 6 6 Output 10 21313 21313 21313 21313 21313 21312 21313 21313 21313 21313 2314 2315 2315 214 215 323 1 323 322 | 2,800 | false | false | false | false | true | false | false | false | false | false | 7,352 |
1984H | There are $$$n$$$ towers at $$$n$$$ distinct points $$$(x_1, y_1), (x_2, y_2), ldots, (x_n, y_n)$$$, such that no three are collinear and no four are concyclic. Initially, you own towers $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, and you want to capture all of them. To do this, you can do the following operation any number of times: Pick two towers $$$P$$$ and $$$Q$$$ you own and one tower $$$R$$$ you don't own, such that the circle through $$$P$$$, $$$Q$$$, and $$$R$$$ contains all $$$n$$$ towers inside of it. Afterwards, capture all towers in or on triangle $$$ riangle PQR$$$, including $$$R$$$ itself. An attack plan is a series of choices of $$$R$$$ ($$$R_1, R_2, ldots, R_k$$$) using the above operations after which you capture all towers. Note that two attack plans are considered different only if they differ in their choice of $$$R$$$ in some operation; in particular, two attack plans using the same choices of $$$R$$$ but different choices of $$$P$$$ and $$$Q$$$ are considered the same. Count the number of attack plans of minimal length. Note that it might not be possible to capture all towers, in which case the answer is $$$0$$$. Since the answer may be large, output it modulo $$$998,244,353$$$. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 250$$$)xa0— the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$4 leq n leq 100$$$)xa0— the number of towers. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^4 leq x_i, y_i leq 10^4$$$)xa0— the location of the $$$i$$$-th tower. Initially, you own towers $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$. All towers are at distinct locations, no three towers are collinear, and no four towers are concyclic. The sum of $$$n$$$ over all test cases does not exceed $$$1000$$$. Output For each test case, output a single integerxa0— the number of attack plans of minimal length after which you capture all towers, modulo $$$998,244,353$$$. Example Input 3 5 1 1 2 5 3 3 4 2 5 4 6 1 1 3 3 1 2 2 1 3 10000 19 84 7 2 7 -4 -3 -3 6 3 1 -5 2 1 -4 -1 7 Note In the first test case, there is only one possible attack plan of shortest length, shown below. Use the operation with $$$P =$$$ tower $$$1$$$, $$$Q =$$$ tower $$$2$$$, and $$$R =$$$ tower $$$5$$$. The circle through these three towers contains all towers inside of it, and as a result towers $$$3$$$ and $$$5$$$ are captured. Use the operation with $$$P =$$$ tower $$$5$$$, $$$Q =$$$ tower $$$1$$$, and $$$R =$$$ tower $$$4$$$. The circle through these three towers contains all towers inside of it, and as a result tower $$$4$$$ is captured. In the second case, for example, you can never capture the tower at $$$(3, 10,000)$$$. | 3,300 | false | false | false | true | false | false | false | false | false | false | 375 |
1323A | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 leq n leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 leq a_i leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates). Output For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 leq p_i leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. | 800 | false | true | true | true | false | false | true | false | false | false | 4,101 |
637A | After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first. Help guys determine the winner photo by the records of likes. Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u20091000) — the total likes to the published photoes. The second line contains _n_ positive integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u20091u2009000u2009000), where _a__i_ is the identifier of the photo which got the _i_-th like. Output Print the identifier of the photo which won the elections. Examples Input 9 100 200 300 200 100 300 300 100 200 Note In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). Thus, the winner is the photo with identifier 2, as it got: more likes than the photo with id 3; as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier. | 1,000 | false | false | true | false | false | true | false | false | false | false | 7,265 |
1826E | A fashion tour consists of $$$m$$$ identical runway shows in different cities. There are $$$n$$$ models willing to participate in the tour, numbered from $$$1$$$ to $$$n$$$. People in different cities have different views on the fashion industry, so they rate each model differently. In particular, people in city $$$i$$$ rate model $$$j$$$ with rating $$$r_{i, j}$$$. You are to choose some number of $$$k$$$ models, and their order, let the chosen models have indices $$$j_1, j_2, dots, j_k$$$ in the chosen order. In each city, these $$$k$$$ models will walk the runway one after another in this order. To make the show exciting, in each city, the ratings of models should be strictly increasing in the order of their performance. More formally, for any city $$$i$$$ and index $$$t$$$ ($$$2 leq t leq k$$$), the ratings must satisfy $$$r_{i,j_{t - 1}} < r_{i,j_t}$$$. After all, the fashion industry is all about money, so choosing model $$$j$$$ to participate in the tour profits you $$$p_j$$$ money. Compute the maximum total profit you can make by choosing the models and their order while satisfying all the requirements. Input The first line contains two integers $$$m$$$ and $$$n$$$ ($$$1 leq m leq 500$$$, $$$1 leq n leq 5000$$$) — the number of shows and the number of models willing to participate respectively. The second line contains $$$n$$$ integers $$$p_j$$$ ($$$1 leq p_j leq 10^9$$$) — the profit you get inviting the $$$j$$$-th model to the tour. The next $$$m$$$ lines each contain $$$n$$$ integers. Line number $$$i$$$ contains $$$n$$$ integers $$$r_{i, j}$$$ ($$$1 leq r_{i, j} leq n$$$) — the ratings of models in city $$$i$$$. Output Output a single integer — the largest total amount of money you can get. Examples Input 3 5 10 10 10 10 10 1 2 3 4 5 1 5 2 3 4 2 3 4 5 1 Input 3 5 10 10 10 10 50 1 2 3 4 5 1 5 2 3 4 2 3 4 5 1 Input 5 5 1000000000 1000000000 1000000000 1000000000 1000000000 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 Note In the first example, there are $$$3$$$ invited models. The show consists of models in the order $$$[1, 3, 4]$$$. Then, the corresponding ratings in the cities are as follows: City $$$1$$$ — $$$[ 1, 3, 4 ]$$$. City $$$2$$$ — $$$[ 1, 2, 3 ]$$$. City $$$3$$$ — $$$[ 2, 4, 5 ]$$$. You can see that the ratings are increasing. So the total profit is $$$10 + 10 + 10 = 30$$$. It can be proven that we can't achieve a bigger profit. In the second example, we can invite the fifth model to the tour, which would result in a total profit of $$$50$$$. It can be proven that we can't achieve a bigger profit. In the third example, we invite the single model to the tour, which results in a total profit of $$$1,000,000,000$$$. In the fourth test case, we can invite all the models and make the show in the order $$$[ 5, 4, 3, 2, 1 ]$$$. The total profit is $$$5 cdot 1,000,000,000 = 5,000,000,000$$$. | 2,400 | false | false | true | true | true | false | true | false | true | true | 1,325 |
570A | The country of Byalechinsk is running elections involving _n_ candidates. The country consists of _m_ cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers _n_, _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100) — the number of candidates and of cities, respectively. Each of the next _m_ lines contains _n_ non-negative integers, the _j_-th number in the _i_-th line _a__ij_ (1u2009≤u2009_j_u2009≤u2009_n_, 1u2009≤u2009_i_u2009≤u2009_m_, 0u2009≤u2009_a__ij_u2009≤u2009109) denotes the number of votes for candidate _j_ in city _i_. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index. | 1,100 | false | false | true | false | false | false | false | false | false | false | 7,571 |
1038C | Two players A and B have a list of $$$n$$$ integers each. They both want to maximize the subtraction between their score and their opponent's score. In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty). Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements $$${1, 2, 2, 3}$$$ in a list and you decided to choose $$$2$$$ for the next turn, only a single instance of $$$2$$$ will be deleted (and added to the score, if necessary). The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally. Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same. Input The first line of input contains an integer $$$n$$$ ($$$1 le n le 100,000$$$)xa0— the sizes of the list. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 le a_i le 10^6$$$), describing the list of the player A, who starts the game. The third line contains $$$n$$$ integers $$$b_i$$$ ($$$1 le b_i le 10^6$$$), describing the list of the player B. Note In the first example, the game could have gone as follows: A removes $$$5$$$ from B's list. B removes $$$4$$$ from A's list. A takes his $$$1$$$. B takes his $$$1$$$. Hence, A's score is $$$1$$$, B's score is $$$1$$$ and difference is $$$0$$$. There is also another optimal way of playing: A removes $$$5$$$ from B's list. B removes $$$4$$$ from A's list. A removes $$$1$$$ from B's list. B removes $$$1$$$ from A's list. The difference in the scores is still $$$0$$$. In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be $$$0$$$. | 1,300 | false | true | false | false | false | false | false | false | true | false | 5,506 |
1352G | A permutation of length $$$n$$$ is an array $$$p=[p_1,p_2,dots,p_n]$$$, which contains every integer from $$$1$$$ to $$$n$$$ (inclusive) and, moreover, each number appears exactly once. For example, $$$p=[3,1,4,2,5]$$$ is a permutation of length $$$5$$$. For a given number $$$n$$$ ($$$n ge 2$$$), find a permutation $$$p$$$ in which absolute difference (that is, the absolute value of difference) of any two neighboring (adjacent) elements is between $$$2$$$ and $$$4$$$, inclusive. Formally, find such permutation $$$p$$$ that $$$2 le p_i - p_{i+1} le 4$$$ for each $$$i$$$ ($$$1 le i < n$$$). Print any such permutation for the given integer $$$n$$$ or determine that it does not exist. Input The first line contains an integer $$$t$$$ ($$$1 le t le 100$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is described by a single line containing an integer $$$n$$$ ($$$2 le n le 1000$$$). Output Print $$$t$$$ lines. Print a permutation that meets the given requirements. If there are several such permutations, then print any of them. If no such permutation exists, print -1. Example Output 9 6 10 8 4 7 3 1 5 2 -1 3 1 4 2 5 3 6 2 4 1 5 1 3 6 2 4 7 13 9 7 11 8 4 1 3 5 2 6 10 12 | 1,600 | false | false | false | false | false | true | false | false | false | false | 3,946 |
1770F | Mari has three integers $$$n$$$, $$$x$$$, and $$$y$$$. Call an array $$$a$$$ of $$$n$$$ non-negative integers good if it satisfies the following conditions: $$$a_1+a_2+ldots+a_n=x$$$, and $$$a_1 , , a_2 , , ldots , , a_n=y$$$, where $$$$$$ denotes the . Output Output a single integer — the total bitwise XOR of the scores of all good arrays. Examples Input 79877974817 749875791743978 982783 Note In the first test case, there are $$$12$$$ good arrays totally as follows. $$$[0,2,3]$$$, $$$[0,3,2]$$$, $$$[2,0,3]$$$, $$$[2,3,0]$$$, $$$[3,0,2]$$$ and $$$[3,2,0]$$$ — the score is $$$0 oplus 2 oplus 3 = 1$$$; $$$[1, 2, 2]$$$, $$$[2, 1, 2]$$$ and $$$[2, 2, 1]$$$ — the score is $$$1 oplus 2 oplus 2 = 1$$$; $$$[1, 1, 3]$$$, $$$[1, 3, 1]$$$ and $$$[3, 1, 1]$$$ — the score is $$$1 oplus 1 oplus 3 = 3$$$. Therefore, the total bitwise xor of the scores is $$$underbrace{1 oplus ldots oplus 1}_{9 ext{ times}} oplus 3 oplus 3 oplus 3 = 2$$$. In the second test case, there are no good sequences. The output should be $$$0$$$. | 3,100 | true | false | false | true | false | false | false | false | false | false | 1,672 |
746B | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva. You are given an encoding _s_ of some word, your task is to decode it. Input The first line contains a positive integer _n_ (1u2009≤u2009_n_u2009≤u20092000)xa0— the length of the encoded word. The second line contains the string _s_ of length _n_ consisting of lowercase English lettersxa0— the encoding. Note In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva. In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same. In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | 900 | false | false | true | false | false | false | false | false | false | false | 6,816 |
468C | Problem - 468C - 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 binary search constructive algorithms math *2500 No tag edit access → Contest materials as the sum of digits in decimal representation of number _x_ (for example, _f_(1234)u2009=u20091u2009+u20092u2009+u20093u2009+u20094). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with . You are given number _a_, help Little X to find a proper test for hack. Input The first line contains a single integer _a_xa0(1u2009≤u2009_a_u2009≤u20091018). Output Print two integers: _l_,u2009_r_xa0(1u2009≤u2009_l_u2009≤u2009_r_u2009<u200910200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333 | 2,500 | true | false | false | false | false | true | false | true | false | false | 7,965 |
1582A | Luntik has decided to try singing. He has $$$a$$$ one-minute songs, $$$b$$$ two-minute songs and $$$c$$$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert. He wants to make the absolute difference of durations of the concerts as small as possible. The duration of the concert is the sum of durations of all songs in that concert. Please help Luntik and find the minimal possible difference in minutes between the concerts durations. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of test cases. Each test case consists of one line containing three integers $$$a, b, c$$$ $$$(1 le a, b, c le 10^9)$$$xa0— the number of one-minute, two-minute and three-minute songs. Output For each test case print the minimal possible difference in minutes between the concerts durations. Example Input 4 1 1 1 2 1 3 5 5 5 1 1 2 Note In the first test case, Luntik can include a one-minute song and a two-minute song into the first concert, and a three-minute song into the second concert. Then the difference will be equal to $$$0$$$. In the second test case, Luntik can include two one-minute songs and a two-minute song and a three-minute song into the first concert, and two three-minute songs into the second concert. The duration of the first concert will be $$$1 + 1 + 2 + 3 = 7$$$, the duration of the second concert will be $$$6$$$. The difference of them is $$$7-6 = 1$$$. | 800 | true | false | false | false | false | false | false | false | false | false | 2,725 |
1406E | This is an interactive problem. There is an unknown integer $$$x$$$ ($$$1le xle n$$$). You want to find $$$x$$$. At first, you have a set of integers $$${1, 2, ldots, n}$$$. You can perform the following operations no more than $$$10000$$$ times: A $$$a$$$: find how many numbers are multiples of $$$a$$$ in the current set. B $$$a$$$: find how many numbers are multiples of $$$a$$$ in this set, and then delete all multiples of $$$a$$$, but $$$x$$$ will never be deleted (even if it is a multiple of $$$a$$$). In this operation, $$$a$$$ must be greater than $$$1$$$. C $$$a$$$: it means that you know that $$$x=a$$$. This operation can be only performed once. Remember that in the operation of type B $$$a>1$$$ must hold. Write a program, that will find the value of $$$x$$$. Interaction In each round, your program needs to print a line containing one uppercase letter A, B or C and an integer $$$a$$$ ($$$1le ale n$$$ for operations A and C, $$$2le ale n$$$ for operation B). This line desribes operation you make. If your operation has type C your program should terminate immediately. Else your program should read one line containing a single integer, which is the answer to your operation. After outputting each line, don't forget to flush the output. To do it use: fflush(stdout) in C/C++; System.out.flush() in Java; sys.stdout.flush() in Python; flush(output) in Pascal; See the documentation for other languages. It is guaranteed, that the number $$$x$$$ is fixed and won't change during the interaction process. Hacks: To make a hack, use such input format: The only line should contain two integers $$$n$$$, $$$x$$$ ($$$1 leq x leq n leq 10^5$$$). Note Note that to make the sample more clear, we added extra empty lines. You shouldn't print any extra empty lines during the interaction process. In the first test $$$n=10$$$ and $$$x=4$$$. Initially the set is: $$${1,2,3,4,5,6,7,8,9,10}$$$. In the first operation, you ask how many numbers are multiples of $$$4$$$ and delete them. The answer is $$$2$$$ because there are two numbers divisible by $$$4$$$: $$${4,8}$$$. $$$8$$$ will be deleted but $$$4$$$ won't, because the number $$$x$$$ will never be deleted. Now the set is $$${1,2,3,4,5,6,7,9,10}$$$. In the second operation, you ask how many numbers are multiples of $$$2$$$. The answer is $$$4$$$ because there are four numbers divisible by $$$2$$$: $$${2,4,6,10}$$$. In the third operation, you ask how many numbers are multiples of $$$8$$$. The answer is $$$0$$$ because there isn't any number divisible by $$$8$$$ in the current set. In the fourth operation, you know that $$$x=4$$$, which is the right answer. | 2,600 | true | false | false | false | false | false | false | false | false | false | 3,642 |
1689E | Bit Lightyear, to the ANDfinity and beyond! After graduating from computer sciences, Vlad has been awarded an array $$$a_1,a_2,ldots,a_n$$$ of $$$n$$$ non-negative integers. As it is natural, he wanted to construct a graph consisting of $$$n$$$ vertices, numbered $$$1, 2,ldots, n$$$. He decided to add an edge between $$$i$$$ and $$$j$$$ if and only if $$$a_i & a_j > 0$$$, where $$$&$$$ denotes the . It can be proven that there exists a finite sequence of operations such that the graph will be connected. So, can you please help Vlad find the minimum possible number of operations to do that and also provide the way how to do that? Input There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0— the number of test cases. This is followed by the test cases description. The first line of each test case contains an integer $$$n$$$ ($$$2leq n leq 2000$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0leq a_i < 2^{30}$$$)xa0— the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$. Output For each test case, print a single integer $$$m$$$ in the first linexa0— the minimum number of operations. In the second line print the array after a valid sequence of operations that have been done such that the graph from the task becomes connected. If there are multiple solutions, output any. Example Input 4 5 1 2 3 4 5 2 0 2 2 3 12 4 3 0 0 0 Output 0 1 2 3 4 5 2 2 2 1 3 11 3 3 1 1 1 Note In the first test case, the graph is already connected. In the second test case, we can increment $$$0$$$ twice and end up with the array $$$[2,2]$$$. Since $$$2 & 2 = 2 > 0$$$, the graph is connected. It can be shown that one operation is not enough. In the third test case, we can decrement $$$12$$$ once and we end up with an array $$$[3,11]$$$. $$$3 & 11 = 3 > 0$$$ hence the graph is connected. One operation has to be done since the graph is not connected at the beginning. | 2,500 | false | false | false | false | false | true | true | false | false | true | 2,144 |
1910I | Consider the following problem. You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters, and an integer $$$k$$$ ($$$n$$$ is not divisible by $$$k$$$). Each letter is one of the first $$$c$$$ letters of the alphabet. You apply the following operation until the length of the string is less than $$$k$$$: choose a contiguous substring of the string of length exactly $$$k$$$, remove it from the string and glue the resulting parts together without changing the order. Let the resulting string of length smaller than $$$k$$$ be $$$t$$$. What is lexicographically smallest string $$$t$$$ that can obtained? You are asked the inverse of this problem. Given two integers $$$n$$$ and $$$k$$$ ($$$n$$$ is not divisible by $$$k$$$) and a string $$$t$$$, consisting of ($$$n bmod k$$$) lowercase Latin letters, count the number of strings $$$s$$$ that produce $$$t$$$ as the lexicographically smallest solution. Print that number modulo $$$998,244,353$$$. Input The first line contains three integers $$$n, k$$$ and $$$c$$$ ($$$1 le n le 10^6$$$; $$$2 le k le 10^6$$$; $$$1 le c le 26$$$; $$$n$$$ is not divisible by $$$k$$$)xa0— the length of string $$$s$$$, the length of the substring that is being removed and the number of first letters from the alphabet. The second line contains string $$$t$$$, consisting of exactly ($$$n bmod k$$$) lowercase Latin letters. Each letter is one of the first $$$c$$$ letters of the alphabet. Output Print a single integerxa0— the number of strings $$$s$$$ that produce $$$t$$$ as the lexicographically smallest solution. Note The strings $$$s$$$ in the first example: "aaa", "aab", "aba", "abb", "baa", "bba". The strings $$$s$$$ in the second example: "bcabc", "bcacc", "bcbbc", "bcbcc", "bccbc", "bcccc", "caabc", "cabbc", "cacbc", "cbabc", "cbbbc", "cbcbc", "ccabc", "ccbbc", "cccbc". | 2,700 | false | false | false | true | false | false | false | false | false | false | 839 |
963C | A rectangle with sides $$$A$$$ and $$$B$$$ is cut into rectangles with cuts parallel to its sides. For example, if $$$p$$$ horizontal and $$$q$$$ vertical cuts were made, $$$(p + 1) cdot (q + 1)$$$ rectangles were left after the cutting. After the cutting, rectangles were of $$$n$$$ different types. Two rectangles are different if at least one side of one rectangle isn't equal to the corresponding side of the other. Note that the rectangle can't be rotated, this means that rectangles $$$a imes b$$$ and $$$b imes a$$$ are considered different if $$$a eq b$$$. For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle. Calculate the amount of pairs $$$(A; B)$$$ such as the given rectangles could be created by cutting the rectangle with sides of lengths $$$A$$$ and $$$B$$$. Note that pairs $$$(A; B)$$$ and $$$(B; A)$$$ are considered different when $$$A eq B$$$. Input The first line consists of a single integer $$$n$$$ ($$$1 leq n leq 2 cdot 10^{5}$$$)xa0— amount of different types of rectangles left after cutting the initial rectangle. The next $$$n$$$ lines each consist of three integers $$$w_{i}, h_{i}, c_{i}$$$ $$$(1 leq w_{i}, h_{i}, c_{i} leq 10^{12})$$$xa0— the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type. It is guaranteed that the rectangles of the different types are different. Output Output one integerxa0— the answer to the problem. Note In the first sample there are three suitable pairs: $$$(1; 9)$$$, $$$(3; 3)$$$ and $$$(9; 1)$$$. In the second sample case there are 6 suitable pairs: $$$(2; 220)$$$, $$$(4; 110)$$$, $$$(8; 55)$$$, $$$(10; 44)$$$, $$$(20; 22)$$$ and $$$(40; 11)$$$. Here the sample of cut for $$$(20; 22)$$$. The third sample has no suitable pairs. | 2,600 | true | false | false | false | false | false | true | false | false | false | 5,847 |
85B | In an embassy of a well-known kingdom an electronic queue is organised. Every person who comes to the embassy, needs to make the following three actions: show the ID, pay money to the cashier and be fingerprinted. Besides, the actions should be performed in the given order. For each action several separate windows are singled out: _k_1 separate windows for the first action (the first type windows), _k_2 windows for the second one (the second type windows), and _k_3 for the third one (the third type windows). The service time for one person in any of the first type window equals to _t_1. Similarly, it takes _t_2 time to serve a person in any of the second type windows. And it takes _t_3 to serve one person in any of the third type windows. Thus, the service time depends only on the window type and is independent from the person who is applying for visa. At some moment _n_ people come to the embassy, the _i_-th person comes at the moment of time _c__i_. The person is registered under some number. After that he sits in the hall and waits for his number to be shown on a special board. Besides the person's number the board shows the number of the window where one should go and the person goes there immediately. Let's consider that the time needed to approach the window is negligible. The table can show information for no more than one person at a time. The electronic queue works so as to immediately start working with the person who has approached the window, as there are no other people in front of the window. The Client Service Quality inspectors noticed that several people spend too much time in the embassy (this is particularly tiresome as the embassy has no mobile phone reception and 3G). It was decided to organise the system so that the largest time a person spends in the embassy were minimum. Help the inspectors organise the queue. Consider that all actions except for being served in at the window, happen instantly. Input The first line contains three space-separated integers _k_1, _k_2, _k_3 (1u2009≤u2009_k__i_u2009≤u2009109), they are the number of windows of the first, second and third type correspondingly. The second line contains three space-separated integers _t_1, _t_2, _t_3 (1u2009≤u2009_t__i_u2009≤u2009105), they are the periods of time needed to serve one person in the window of the first, second and third type correspondingly. The third line contains an integer _n_ (1u2009≤u2009_n_u2009≤u2009105), it is the number of people. The fourth line contains _n_ space-separated integers _c__i_ (1u2009≤u2009_c__i_u2009≤u2009109) in the non-decreasing order; _c__i_ is the time when the person number _i_ comes to the embassy. Output Print the single number, the maximum time a person will spend in the embassy if the queue is organized optimally. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams (also you may use the %I64d specificator). Examples Input 1 1 1 1 1 1 5 1 1 1 1 1 Input 2 1 1 5 1 1 5 1 2 3 3 5 Note In the first test 5 people come simultaneously at the moment of time equal to 1. There is one window of every type, it takes 1 unit of time to be served at each window. That's why the maximal time a person spends in the embassy is the time needed to be served at the windows (3 units of time) plus the time the last person who comes to the first window waits (4 units of time). Windows in the second test work like this: The first window of the first type: [1,u20096) — the first person, [6,u200911) — third person, [11,u200916) — fifth person The second window of the first type: [2,u20097) — the second person, [7,u200912) — the fourth person The only second type window: [6,u20097) — first, [7,u20098) — second, [11,u200912) — third, [12,u200913) — fourth, [16,u200917) — fifth The only third type window: [7,u20098) — first, [8,u20099) — second, [12,u200913) — third, [13,u200914) — fourth, [17,u200918) — fifth We can see that it takes most time to serve the fifth person. | 1,800 | false | true | false | false | true | false | false | false | false | false | 9,545 |
1375E | # Inversion SwapSort Input file: standard input Output file: standard output Time limit: 2 seconds Memory limit: 256 megabytes Madeline has an array a of n integers. A pair (u, v ) of integers forms an inversion in a if: • 1 ≤ u < v ≤ n. • au > a v.Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values au and av. Being bored, she decided to write a list of pairs (ui, v i) with the following conditions: • all the pairs in the list are distinct and form an inversion in a. • all the pairs that form an inversion in a are in the list. • Starting from the given array, if you swap the values at indices u1 and v1, then the values at indices u2 and v2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order .Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them. # Input The first line of the input contains a single integer n (1 ≤ n ≤ 1000 ) x16 the length of the array. Next line contains n integers a1, a 2, ..., a n (1 ≤ ai ≤ 10 9) x16 elements of the array. # Output Print -1 if no such list exists. Otherwise in the first line you should print a single integer m (0 ≤ m ≤ n(n − 1) 2 ) x16 number of pairs in the list. The i-th of the following m lines should contain two integers ui, v i (1 ≤ ui < v i ≤ n). If there are multiple possible answers, you may find any of them. # Examples standard input standard output 33 1 2 21 3 1 2 41 8 1 6 22 4 2 3 51 1 1 2 2 0 # Note In the first sample test case the array will change in this order [3 , 1, 2] → [2 , 1, 3] → [1 , 2, 3] .In the second sample test case it will be [1 , 8, 1, 6] → [1 , 6, 1, 8] → [1 , 1, 6, 8] .In the third sample test case the array is already sorted. Page 1 of 1 | 2,500 | false | true | false | false | false | true | false | false | true | false | 3,783 |
1948B | You are given an integer array $$$a$$$ of length $$$n$$$. You can perform the following operation any number of times (possibly zero): take any element of the array $$$a$$$, which is at least $$$10$$$, delete it, and instead insert the digits that element consisted of in the same position, in order they appear in that element. For example: if we apply this operation to the $$$3$$$-rd element of the array $$$[12, 3, 45, 67]$$$, then the array becomes $$$[12, 3, 4, 5, 67]$$$. if we apply this operation to the $$$2$$$-nd element of the array $$$[2, 10]$$$, then the array becomes $$$[2, 1, 0]$$$. Your task is to determine whether it is possible to make $$$a$$$ sorted in non-descending order using the aforementioned operation any number of times (possibly zero). In other words, you have to determine if it is possible to transform the array $$$a$$$ in such a way that $$$a_1 le a_2 le dots le a_k$$$, where $$$k$$$ is the current length of the array $$$a$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^3$$$)xa0— the number of test cases. Each test case consists of two lines: the first line contains a single integer $$$n$$$ ($$$2 le n le 50$$$). the second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$0 le a_i le 99$$$). Output For each test case, print YES if it is possible to make $$$a$$$ sorted in non-decreasing order using the aforementioned operation; otherwise, print NO. You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as a positive answer. Example Input 3 4 12 3 45 67 3 12 28 5 2 0 0 Note In the first example, you can split the first element, then the array becomes $$$[1, 2, 3, 45, 67]$$$. In the second example, there is no way to get a sorted array. In the third example, the array is already sorted. | 1,100 | false | true | true | true | false | false | true | false | false | false | 598 |
1584F | You are given $$$n$$$ strings $$$s_1, s_2, ldots, s_n$$$, each consisting of lowercase and uppercase English letters. In addition, it's guaranteed that each character occurs in each string at most twice. Find the longest common subsequence of these strings. A string $$$t$$$ is a subsequence of a string $$$s$$$ if $$$t$$$ can be obtained from $$$s$$$ by deletion of several (possibly, zero or all) symbols. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 leq n leq 10$$$) — the number of strings. Each of the next $$$n$$$ lines contains the corresponding string $$$s_i$$$. Each $$$s_i$$$ is non-empty, consists only of uppercase and lowercase English letters, and no character appears more than twice in each string. Output For each test case print the answer in two lines: In the first line print the length of the longest common subsequence. In the second line print the longest common subsequence. If there are multiple such subsequences, print any of them. Example Input 4 2 ABC CBA 2 bacab defed 3 abcde aBcDe ace 2 codeforces technocup Note In the first test case, the longest common subsequence is "A". There are no common subsequences of length $$$2$$$. In the second test case, sets of characters of strings don't intersect, so any non-empty string can't be a common subsequence. | 2,600 | false | true | false | true | false | false | false | false | false | true | 2,704 |
928C | Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with length not exceeding 10 and version — positive integer from 1 to 106. Each project (keep in mind that it is determined by both its name and version) might depend on other projects. For sure, there are no cyclic dependencies. You're given a list of project descriptions. The first of the given projects is the one being developed by Polycarp at this moment. Help Polycarp determine all projects that his project depends on (directly or via a certain chain). It's possible that Polycarp's project depends on two different versions of some project. In this case collision resolving is applied, i.e. for each such project the system chooses the version that minimizes the distance from it to Polycarp's project. If there are several options, the newer (with the maximum version) is preferred. This version is considered actual; other versions and their dependencies are ignored. More formal, choose such a set of projects of minimum possible size that the following conditions hold: Polycarp's project is chosen; Polycarp's project depends (directly or indirectly) on all other projects in the set; no two projects share the name; for each project _x_ that some other project in the set depends on we have either _x_ or some _y_ with other version and shorter chain to Polycarp's project chosen. In case of ties the newer one is chosen. Output all Polycarp's project's dependencies (Polycarp's project itself should't be printed) in lexicographical order. Input The first line contains an only integer _n_ (1u2009≤u2009_n_u2009≤u20091u2009000) — the number of projects in Vaja. The following lines contain the project descriptions. Each project is described by a line consisting of its name and version separated by space. The next line gives the number of direct dependencies (from 0 to _n_u2009-u20091) and the dependencies themselves (one in a line) in arbitrary order. Each dependency is specified by its name and version. The projects are also given in arbitrary order, but the first of them is always Polycarp's. Project descriptions are separated by one empty line. Refer to samples for better understanding. It's guaranteed that there are no cyclic dependencies. Output Output all Polycarp's project's dependencies in lexicographical order. Examples Input 4 a 3 2 b 1 c 1b 2 0 b 1 1 b 2 c 1 1 b 2 Input 9 codehorses 5 3 webfrmk 6 mashadb 1 mashadb 2commons 2 0 mashadb 3 0 webfrmk 6 2 mashadb 3 commons 2 extra 4 1 extra 3 extra 3 0 extra 1 0 mashadb 1 1 extra 3 mashadb 2 1 extra 1 Output 4 commons 2 extra 1 mashadb 2 webfrmk 6 Input 3 abc 1 2 abc 3 cba 2abc 3 0 cba 2 0 Note The first sample is given in the pic below. Arrow from _A_ to _B_ means that _B_ directly depends on _A_. Projects that Polycarp's project «a» (version 3) depends on are painted black. The second sample is again given in the pic below. Arrow from _A_ to _B_ means that _B_ directly depends on _A_. Projects that Polycarp's project «codehorses» (version 5) depends on are paint it black. Note that «extra 1» is chosen instead of «extra 3» since «mashadb 1» and all of its dependencies are ignored due to «mashadb 2». | 1,900 | false | false | true | false | false | false | false | false | false | true | 5,992 |
981H | You are given a tree of $$$n$$$ vertices. You are to select $$$k$$$ (not necessarily distinct) simple paths in such a way that it is possible to split all edges of the tree into three sets: edges not contained in any path, edges that are a part of exactly one of these paths, and edges that are parts of all selected paths, and the latter set should be non-empty. Compute the number of ways to select $$$k$$$ paths modulo $$$998244353$$$. The paths are enumerated, in other words, two ways are considered distinct if there are such $$$i$$$ ($$$1 leq i leq k$$$) and an edge that the $$$i$$$-th path contains the edge in one way and does not contain it in the other. Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 leq n, k leq 10^{5}$$$)xa0— the number of vertices in the tree and the desired number of paths. The next $$$n - 1$$$ lines describe edges of the tree. Each line contains two integers $$$a$$$ and $$$b$$$ ($$$1 le a, b le n$$$, $$$a e b$$$)xa0— the endpoints of an edge. It is guaranteed that the given edges form a tree. Output Print the number of ways to select $$$k$$$ enumerated not necessarily distinct simple paths in such a way that for each edge either it is not contained in any path, or it is contained in exactly one path, or it is contained in all $$$k$$$ paths, and the intersection of all paths is non-empty. As the answer can be large, print it modulo $$$998244353$$$. Examples Input 29 29 1 2 1 3 1 4 1 5 5 6 5 7 5 8 8 9 8 10 8 11 11 12 11 13 11 14 14 15 14 16 14 17 17 18 17 19 17 20 20 21 20 22 20 23 23 24 23 25 23 26 26 27 26 28 26 29 Note In the first example the following ways are valid: $$$((1,2), (1,2))$$$, $$$((1,2), (1,3))$$$, $$$((1,3), (1,2))$$$, $$$((1,3), (1,3))$$$, $$$((1,3), (2,3))$$$, $$$((2,3), (1,3))$$$, $$$((2,3), (2,3))$$$. In the second example $$$k=1$$$, so all $$$n cdot (n - 1) / 2 = 5 cdot 4 / 2 = 10$$$ paths are valid. In the third example, the answer is $$$geq 998244353$$$, so it was taken modulo $$$998244353$$$, don't forget it! | 3,100 | true | false | false | true | true | false | false | false | false | false | 5,793 |
622D | Problem - 622D - Codeforces =============== xa0 ]( "Educational Codeforces Round 7") in the permuted array _a_. Let's define the value _d__i_u2009=u2009_y__i_u2009-u2009_x__i_ — the distance between the positions of the number _i_. Permute the numbers in array _a_ to minimize the value of the sum . Input The only line contains integer _n_ (1u2009≤u2009_n_u2009≤u20095·105). Output Print 2_n_ integers — the permuted array _a_ that minimizes the value of the sum _s_. Examples Input 2 Output 1 1 2 2 Input 1 Output 1 1 | 1,900 | false | false | false | false | false | true | false | false | false | false | 7,343 |
1166E | Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia? There are $$$n$$$ stores numbered from $$$1$$$ to $$$n$$$ in Nlogonia. The $$$i$$$-th of these stores offers a positive integer $$$a_i$$$. Each day among the last $$$m$$$ days Dora bought a single integer from some of the stores. The same day, Swiper the fox bought a single integer from all the stores that Dora did not buy an integer from on that day. Dora considers Swiper to be her rival, and she considers that she beat Swiper on day $$$i$$$ if and only if the least common multiple of the numbers she bought on day $$$i$$$ is strictly greater than the least common multiple of the numbers that Swiper bought on day $$$i$$$. The least common multiple (LCM) of a collection of integers is the smallest positive integer that is divisible by all the integers in the collection. However, Dora forgot the values of $$$a_i$$$. Help Dora find out if there are positive integer values of $$$a_i$$$ such that she beat Swiper on every day. You don't need to find what are the possible values of $$$a_i$$$ though. Note that it is possible for some values of $$$a_i$$$ to coincide in a solution. Input The first line contains integers $$$m$$$ and $$$n$$$ ($$$1leq m leq 50$$$, $$$1leq n leq 10^4$$$)xa0— the number of days and the number of stores. After this $$$m$$$ lines follow, the $$$i$$$-th line starts with an integer $$$s_i$$$ ($$$1leq s_i leq n-1$$$), the number of integers Dora bought on day $$$i$$$, followed by $$$s_i$$$ distinct integers, the indices of the stores where Dora bought an integer on the $$$i$$$-th day. The indices are between $$$1$$$ and $$$n$$$. Output Output must consist of a single line containing "possible" if there exist positive integers $$$a_i$$$ such that for each day the least common multiple of the integers bought by Dora is strictly greater than the least common multiple of the integers bought by Swiper on that day. Otherwise, print "impossible". Note that you don't have to restore the integers themselves. Examples Input 10 10 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 Note In the first sample, a possible choice for the values of the $$$a_i$$$ is $$$3, 4, 3, 5, 2$$$. On the first day, Dora buys the integers $$$3, 4$$$ and $$$3$$$, whose LCM is $$$12$$$, while Swiper buys integers $$$5$$$ and $$$2$$$, whose LCM is $$$10$$$. On the second day, Dora buys $$$3, 5$$$ and $$$2$$$, whose LCM is $$$30$$$, and Swiper buys integers $$$3$$$ and $$$4$$$, whose LCM is $$$12$$$. | 2,100 | true | false | false | false | false | true | true | false | false | false | 4,885 |
1753A2 | This is the hard version of the problem. The difference is that in this version the array contains zeros. You can make hacks only if both versions of the problem are solved. You are given an array $$$[a_1, a_2, ldots a_n]$$$ consisting of integers $$$-1$$$, $$$0$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], ldots, [l_k, r_k]$$$ with the following property: Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + ldots pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$. The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition. The set of segments $$$[l_1, r_1], [l_2, r_2], ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 le r_1, l_2 le r_2, ldots, l_k le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, ldots k-1$$$. In other words, each element of the array must belong to exactly one segment. You have to build a partition of the given array with properties described above or determine that such partition does not exist. Note that it is not required to minimize the number of segments in the partition. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10,000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 le n le 200,000$$$)xa0— the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$a_i$$$ is $$$-1$$$, $$$0$$$, or $$$1$$$)xa0— the elements of the given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200,000$$$. Output For each test case print an integer $$$k$$$xa0— the number of segments in the partition. If required partition does not exist, print $$$-1$$$. If partition exists, in the $$$i$$$-th of the following $$$k$$$ lines print two integers $$$l_i$$$ and $$$r_i$$$xa0— description of the $$$i$$$-th segment. The following conditions should be satisfied: $$$l_i le r_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k$$$. $$$l_{i + 1} = r_i + 1$$$ for each $$$i$$$ from $$$1$$$ to $$$(k - 1)$$$. $$$l_1 = 1, r_k = n$$$. If there are multiple correct partitions of the array, print any of them. Example Input 5 4 0 0 0 0 7 -1 1 0 1 0 1 0 5 0 -1 1 0 1 3 1 0 1 1 1 Output 4 1 1 2 2 3 3 4 4 4 1 1 2 2 3 5 6 7 -1 2 1 1 2 3 -1 Note In the first test case we can build a partition of $$$4$$$ segmentsxa0— each of them will contain only one element of the array equals to $$$0$$$. So the sum will be equal to $$$0 + 0 + 0 + 0 = 0$$$. In the second test case we can build a partition of $$$4$$$ segments. The alternating sum of the first segment will be equal to $$$-1$$$, the alternating sum of the second segment will be equal to $$$1$$$, of the third segmentxa0— $$$0 - 1 + 0 = -1$$$, of the fourth segmentxa0— $$$1 - 0 = 1$$$. The sum will be equal to $$$-1 + 1 -1 + 1 = 0$$$. In the third test case it can be proved that the required partition does not exist. | 1,500 | false | true | false | true | false | true | false | false | false | false | 1,776 |
1984C1 | The two versions of the problem are different. You may want to read both versions. You can make hacks only if both versions are solved. You are given an array $$$a$$$ of length $$$n$$$. Start with $$$c = 0$$$. Then, for each $$$i$$$ from $$$1$$$ to $$$n$$$ (in increasing order) do exactly one of the following: Option $$$1$$$: set $$$c$$$ to $$$c + a_i$$$. Option $$$2$$$: set $$$c$$$ to $$$c + a_i$$$, where $$$x$$$ is the absolute value of $$$x$$$. Let the maximum final value of $$$c$$$ after the procedure described above be equal to $$$k$$$. Find $$$k$$$. 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 each test case contains a single integer $$$n$$$ ($$$2 leq n leq 2 cdot 10^5$$$). The second line of each case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, $$$ldots$$$, $$$a_n$$$ ($$$-10^9 leq a_i leq 10^9$$$). 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 value of $$$k$$$. Example Input 5 4 10 -9 -3 4 8 1 4 3 4 1 4 3 4 3 -1 -2 -3 4 -1000000000 1000000000 1000000000 1000000000 4 1 9 8 4 Output 6 24 6 4000000000 22 Note In the first test case, if we set $$$c$$$ to its absolute value every time we add to it, we end up with $$$6$$$. It can be shown that this is the maximum result. In the second test case, taking the absolute value will never change anything, so we can just sum the array without doing anything to get $$$24$$$. In the third test case, it is optimal to wait until the end to set $$$c$$$ to its absolute value, resulting in an answer of $$$6$$$. | 1,300 | true | true | false | true | false | false | false | false | false | false | 381 |
677E | Vanya plays a game of balloons on the field of size _n_u2009×u2009_n_, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. There are two types of crosses: normal and rotated. For example: **o* **o* ooooo **o* **o* or o***o *o*o **o* *o*o o***o Formally, the cross is given by three integers _r_, _c_ and _d_, such that _d_u2009≤u2009_r_,u2009_c_u2009≤u2009_n_u2009-u2009_d_u2009+u20091. The normal cross consists of balloons located in cells (_x_,u2009_y_) (where _x_ stay for the number of the row and _y_ for the number of the column), such that _x_u2009-u2009_r_·_y_u2009-u2009_c_u2009=u20090 and _x_u2009-u2009_r_u2009+u2009_y_u2009-u2009_c_u2009<u2009_d_. Rotated cross consists of balloons located in cells (_x_,u2009_y_), such that _x_u2009-u2009_r_u2009=u2009_y_u2009-u2009_c_ and _x_u2009-u2009_r_u2009<u2009_d_. Vanya wants to know the maximum possible product of the values of balls forming one cross. As this value can be large, output it modulo 109u2009+u20097. Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u20091000)xa0— the number of rows and columns in the table with balloons. The each of the following _n_ lines contains _n_ characters '0', '1', '2' or '3'xa0— the description of the values in balloons. Output Print the maximum possible product modulo 109u2009+u20097. Note, that you are not asked to maximize the remainder modulo 109u2009+u20097, but to find the maximum value and print it this modulo. Note In the first sample, the maximum product is achieved for a rotated cross with a center in the cell (3,u20093) and radius 1: 2·2·3·3·3u2009=u2009108. | 2,300 | false | false | true | true | false | false | true | true | false | false | 7,117 |
606B | The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (_x_0,u2009_y_0) of a rectangular squared field of size _x_u2009×u2009_y_, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly _x_·_y_ tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string _s_, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate _y_, and moving to the right increases it. Similarly, moving up decreases the _x_ coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each _k_ from 0 to _length_(_s_) your task is to find in how many tests the robot will run exactly _k_ commands before it blows up. Input The first line of the input contains four integers _x_, _y_, _x_0, _y_0 (1u2009≤u2009_x_,u2009_y_u2009≤u2009500,u20091u2009≤u2009_x_0u2009≤u2009_x_,u20091u2009≤u2009_y_0u2009≤u2009_y_)xa0— the sizes of the field and the starting coordinates of the robot. The coordinate axis _X_ is directed downwards and axis _Y_ is directed to the right. The second line contains a sequence of commands _s_, which should be fulfilled by the robot. It has length from 1 to 100u2009000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (_length_(_s_)u2009+u20091) numbers. On the _k_-th position, starting with zero, print the number of tests where the robot will run exactly _k_ commands before it blows up. Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: . | 1,600 | false | false | true | false | false | false | false | false | false | false | 7,420 |
1207F | Problem - 1207F - 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 data structures implementation *2100 No tag edit access → Contest materials . Initially all elements of $$$a$$$ are zero. You have to process two types of queries to this array: $$$1$$$ $$$x$$$ $$$y$$$xa0— increase $$$a_x$$$ by $$$y$$$; $$$2$$$ $$$x$$$ $$$y$$$xa0— compute $$$sumlimits_{i in R(x, y)} a_i$$$, where $$$R(x, y)$$$ is the set of all integers from $$$1$$$ to $$$500000$$$ which have remainder $$$y$$$ modulo $$$x$$$. Can you process all the queries? Input The first line contains one integer $$$q$$$ ($$$1 le q le 500000$$$) — the number of queries. Then $$$q$$$ lines follow, each describing a query. The $$$i$$$-th line contains three integers $$$t_i$$$, $$$x_i$$$ and $$$y_i$$$ ($$$1 le t_i le 2$$$). If $$$t_i = 1$$$, then it is a query of the first type, $$$1 le x_i le 500000$$$, and $$$-1000 le y_i le 1000$$$. If $$$t_i = 2$$$, then it it a query of the second type, $$$1 le x_i le 500000$$$, and $$$0 le y_i < x_i$$$. It is guaranteed that there will be at least one query of type $$$2$$$. Output For each query of type $$$2$$$ print one integer — the answer to it. Example Input 5 1 3 4 2 3 0 2 4 3 1 4 -4 2 1 0 Output 4 4 0 | 2,100 | false | false | true | false | true | false | true | false | false | false | 4,656 |
2020B | Imagine you have $$$n$$$ light bulbs numbered $$$1, 2, ldots, n$$$. Initially, all bulbs are on. To flip the state of a bulb means to turn it off if it used to be on, and to turn it on otherwise. Next, you do the following: for each $$$i = 1, 2, ldots, n$$$, flip the state of all bulbs $$$j$$$ such that $$$j$$$ is divisible by $$$i^dagger$$$. After performing all operations, there will be several bulbs that are still on. Your goal is to make this number exactly $$$k$$$. Find the smallest suitable $$$n$$$ such that after performing the operations there will be exactly $$$k$$$ bulbs on. We can show that an answer always exists. $$$^dagger$$$ An integer $$$x$$$ is divisible by $$$y$$$ if there exists an integer $$$z$$$ such that $$$x = ycdot z$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10^4$$$). The description of the test cases follows. The only line of each test case contains a single integer $$$k$$$ ($$$1 le k le 10^{18}$$$). Output For each test case, output $$$n$$$xa0— the minimum number of bulbs. Note In the first test case, the minimum number of bulbs is $$$2$$$. Let's denote the state of all bulbs with an array, where $$$1$$$ corresponds to a turned on bulb, and $$$0$$$ corresponds to a turned off bulb. Initially, the array is $$$[1, 1]$$$. After performing the operation with $$$i = 1$$$, the array becomes $$$[underline{0}, underline{0}]$$$. After performing the operation with $$$i = 2$$$, the array becomes $$$[0, underline{1}]$$$. In the end, there are $$$k = 1$$$ bulbs on. We can also show that the answer cannot be less than $$$2$$$. In the second test case, the minimum number of bulbs is $$$5$$$. Initially, the array is $$$[1, 1, 1, 1, 1]$$$. After performing the operation with $$$i = 1$$$, the array becomes $$$[underline{0}, underline{0}, underline{0}, underline{0}, underline{0}]$$$. After performing the operation with $$$i = 2$$$, the array becomes $$$[0, underline{1}, 0, underline{1}, 0]$$$. After performing the operation with $$$i = 3$$$, the array becomes $$$[0, 1, underline{1}, 1, 0]$$$. After performing the operation with $$$i = 4$$$, the array becomes $$$[0, 1, 1, underline{0}, 0]$$$. After performing the operation with $$$i = 5$$$, the array becomes $$$[0, 1, 1, 0, underline{1}]$$$. In the end, there are $$$k = 3$$$ bulbs on. We can also show that the answer cannot be smaller than $$$5$$$. | 1,200 | true | false | false | false | false | false | false | true | false | false | 151 |
1754A | You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved. Today you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by one or several messages, which are the answer of a support manager. However, sometimes clients ask questions so quickly that some of the manager's answers to old questions appear after the client has asked some new questions. Due to the privacy policy, the full text of messages is not available to you, only the order of messages is visible, as well as the type of each message: a customer question or a response from the technical support manager. It is guaranteed that the dialog begins with the question of the client. You have to determine, if this dialog may correspond to the rules of work described above, or the rules are certainly breached. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 500$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 le n le 100$$$)xa0— the total number of messages in the dialog. The second line of each test case consists of $$$n$$$ characters "Q" and "A", describing types of messages in the dialog in chronological order. Character "Q" denotes the message with client question, and character "A"xa0— the message with technical support manager answer. It is guaranteed that the first character in the line equals to "Q". Output For each test case print "Yes" (without quotes) if dialog may correspond to the rules of work, or "No" (without quotes) otherwise. Example Input 5 4 QQAA 4 QQAQ 3 QAA 1 Q 14 QAQQAQAAQQQAAA Note In the first test case the two questions from the client are followed with two specialist's answers. So this dialog may correspond to the rules of work. In the second test case one of the first two questions was not answered. In the third test case the technical support manager sent two messaged as the answer to the only message of the client. | 800 | false | true | false | false | false | false | false | false | false | false | 1,770 |
1477B | Nezzar has a binary string $$$s$$$ of length $$$n$$$ that he wants to share with his best friend, Nanako. Nanako will spend $$$q$$$ days inspecting the binary string. At the same time, Nezzar wants to change the string $$$s$$$ into string $$$f$$$ during these $$$q$$$ days, because it looks better. It is known that Nanako loves consistency so much. On the $$$i$$$-th day, Nanako will inspect a segment of string $$$s$$$ from position $$$l_i$$$ to position $$$r_i$$$ inclusive. If the segment contains both characters '0' and '1', Nanako becomes unhappy and throws away the string. After this inspection, at the $$$i$$$-th night, Nezzar can secretly change strictly less than half of the characters in the segment from $$$l_i$$$ to $$$r_i$$$ inclusive, otherwise the change will be too obvious. Now Nezzar wonders, if it is possible to avoid Nanako being unhappy and at the same time have the string become equal to the string $$$f$$$ at the end of these $$$q$$$ days and nights. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 2 cdot 10^5$$$) — the number of test cases. The first line of each test case contains two integers $$$n,q$$$ ($$$1 le n le 2 cdot 10^5$$$, $$$0 le q le 2 cdot 10^5$$$). The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$. The third line of each test case contains a binary string $$$f$$$ of length $$$n$$$. Then $$$q$$$ lines follow, $$$i$$$-th of them contains two integers $$$l_i,r_i$$$ ($$$1 le l_i le r_i le n$$$) xa0— bounds of the segment, that Nanako will inspect on the $$$i$$$-th day. It is guaranteed that the sum of $$$n$$$ for all test cases doesn't exceed $$$2 cdot 10^5$$$, and the sum of $$$q$$$ for all test cases doesn't exceed $$$2 cdot 10^5$$$. Output For each test case, print "YES" on the single line if it is possible to avoid Nanako being unhappy and have the string $$$f$$$ at the end of $$$q$$$ days and nights. Otherwise, print "NO". You can print each letter in any case (upper or lower). Example Input 4 5 2 00000 00111 1 5 1 3 2 1 00 01 1 2 10 6 1111111111 0110001110 1 10 5 9 7 10 1 7 3 5 6 10 5 2 10000 11000 2 5 1 3 Note In the first test case, $$$underline{00000} ightarrow underline{000}11 ightarrow 00111$$$ is one of the possible sequences of string changes. In the second test case, it can be shown that it is impossible to have the string $$$f$$$ at the end. | 1,900 | false | true | false | false | true | false | false | false | false | false | 3,289 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.