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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1971E | Timur is in a car traveling on the number line from point $$$0$$$ to point $$$n$$$. The car starts moving from point $$$0$$$ at minute $$$0$$$. There are $$$k+1$$$ signs on the line at points $$$0, a_1, a_2, dots, a_k$$$, and Timur knows that the car will arrive there at minutes $$$0, b_1, b_2, dots, b_k$$$, respectively. The sequences $$$a$$$ and $$$b$$$ are strictly increasing with $$$a_k = n$$$. Between any two adjacent signs, the car travels with a constant speed. Timur has $$$q$$$ queries: each query will be an integer $$$d$$$, and Timur wants you to output how many minutes it takes the car to reach point $$$d$$$, rounded down to the nearest integer. 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 three integers $$$n$$$, $$$k$$$, and $$$q$$$, ($$$k leq n leq 10^9$$$; $$$1 leq k, q leq 10^5$$$)xa0— the final destination, the number of points Timur knows the time for, and the number of queries respectively. The second line of each test case contains $$$k$$$ integers $$$a_i$$$ ($$$1 leq a_i leq n$$$; $$$a_i < a_{i+1}$$$ for every $$$1 leq i leq k-1$$$; $$$a_k = n$$$). The third line of each test case contains $$$k$$$ integers $$$b_i$$$ ($$$1 leq b_i leq 10^9$$$; $$$b_i < b_{i+1}$$$ for every $$$1 leq i leq k-1$$$). Each of the following $$$q$$$ lines contains a single integer $$$d$$$ ($$$0 leq d leq n$$$)xa0— the distance that Timur asks the minutes passed for. The sum of $$$k$$$ over all test cases doesn't exceed $$$10^5$$$, and the sum of $$$q$$$ over all test cases doesn't exceed $$$10^5$$$. Output For each query, output a single integerxa0— the number of minutes passed until the car reaches the point $$$d$$$, rounded down. Example Input 4 10 1 3 10 10 0 6 7 10 2 4 4 10 4 7 6 4 2 7 1000000000 1 1 1000000000 1000000000 99999999 6 1 3 6 5 2 6 5 Output 0 6 7 5 4 2 5 99999999 1 5 4 Note For the first test case, the car goes from point $$$0$$$ to point $$$10$$$ in $$$10$$$ minutes, so the speed is $$$1$$$ unit per minute and: At point $$$0$$$, the time will be $$$0$$$ minutes. At point $$$6$$$, the time will be $$$6$$$ minutes. At point $$$7$$$, the time will be $$$7$$$ minutes. For the second test case, between points $$$0$$$ and $$$4$$$, the car travels at a speed of $$$1$$$ unit per minute and between $$$4$$$ and $$$10$$$ with a speed of $$$2$$$ units per minute and: At point $$$6$$$, the time will be $$$5$$$ minutes. At point $$$4$$$, the time will be $$$4$$$ minutes. At point $$$2$$$, the time will be $$$2$$$ minutes. At point $$$7$$$, the time will be $$$5.5$$$ minutes, so the answer is $$$5$$$. For the fourth test case, the car travels with $$$1.2$$$ units per minute, so the answers to the queries are: At point $$$2$$$, the time will be $$$1.66dots$$$ minutes, so the answer is $$$1$$$. At point $$$6$$$, the time will be $$$5$$$ minutes. At point $$$5$$$, the time will be $$$4.16dots$$$ minutes, so the answer is $$$4$$$. | 1,500 | true | false | false | false | false | false | false | true | true | false | 461 |
1622E | Petya is a math teacher. $$$n$$$ of his students has written a test consisting of $$$m$$$ questions. For each student, it is known which questions he has answered correctly and which he has not. If the student answers the $$$j$$$-th question correctly, he gets $$$p_j$$$ points (otherwise, he gets $$$0$$$ points). Moreover, the points for the questions are distributed in such a way that the array $$$p$$$ is a permutation of numbers from $$$1$$$ to $$$m$$$. For the $$$i$$$-th student, Petya knows that he expects to get $$$x_i$$$ points for the test. Petya wonders how unexpected the results could be. Petya believes that the surprise value of the results for students is equal to $$$sumlimits_{i=1}^{n} x_i - r_i$$$, where $$$r_i$$$ is the number of points that the $$$i$$$-th student has got for the test. Your task is to help Petya find such a permutation $$$p$$$ for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 10$$$; $$$1 le m le 10^4$$$)xa0— the number of students and the number of questions, respectively. The second line contains $$$n$$$ integers $$$x_1, x_2, dots, x_n$$$ ($$$0 le x_i le frac{m(m+1)}{2}$$$), where $$$x_i$$$ is the number of points that the $$$i$$$-th student expects to get. This is followed by $$$n$$$ lines, the $$$i$$$-th line contains the string $$$s_i$$$ ($$$s_i = m; s_{i, j} in {0, 1}$$$), where $$$s_{i, j}$$$ is $$$1$$$ if the $$$i$$$-th student has answered the $$$j$$$-th question correctly, and $$$0$$$ otherwise. The sum of $$$m$$$ for all test cases does not exceed $$$10^4$$$. Output For each test case, print $$$m$$$ integersxa0— a permutation $$$p$$$ for which the surprise value of the results is maximum possible. If there are multiple answers, print any of them. Example Input 3 4 3 5 1 2 2 110 100 101 100 4 4 6 2 0 10 1001 0010 0110 0101 3 6 20 3 15 010110 000101 111111 Output 3 1 2 2 3 4 1 3 1 4 5 2 6 | 2,200 | false | true | false | false | false | false | true | false | false | false | 2,507 |
1360H | # Binary Median Input file: standard input Output file: standard output Time limit: 2 seconds Memory limit: 256 megabytes Consider all binary strings of length m (1 ≤ m ≤ 60 ). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly 2m such strings in total. The string s is lexicographically smaller than the string t (both have the same length m) if in the first position i from the left in which they differ, we have s[i] < t [i]. This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100 , because the first two characters are the same, and the third character in the first string is less than that in the second. We remove from this set n (1 ≤ n ≤ min(2 m − 1, 100) ) distinct binary strings a1, a 2, . . . , a n, each of length m. Thus, the set will have k = 2 m − n strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary). We number all the strings after sorting from 0 to k − 1. Print the string whose index is b k−12 c (such an element is called median ), where bxc is the rounding of the number down to the nearest integer. For example, if n = 3 , m = 3 and a = [ 010 , 111 , 001 ], then after removing the strings ai and sorting, the result will take the form: [000 , 011 , 100 , 101 , 110 ]. Thus, the desired median is 100 . # Input The first line contains an integer t (1 ≤ t ≤ 1000 ) x16 the number of test cases. Then, t test cases follow. The first line of each test case contains integers n (1 ≤ n ≤ min(2 m − 1, 100) ) and m (1 ≤ m ≤ 60 ), where n is the number of strings to remove, and m is the length of binary strings. The next n lines contain a1, a 2, . . . , a n x16 distinct binary strings of length m.The total length of all given binary strings in all test cases in one test does not exceed 10 5. # Output Print t answers to the test cases. For each test case, print a string of length m x16 the median of the sorted sequence of remaining strings in the corresponding test case. Page 1 of 2 Example standard input standard output 53 3 010 001 111 4 3 000 111 100 011 1 1 11 1 03 2 00 01 10 100 010 0111 # Note The first test case is explained in the statement. In the second test case, the result after removing strings and sorting is [001 , 010 , 101 , 110 ]. Therefore, the desired median is 010 . Page 2 of 2 | 2,100 | false | false | false | false | false | true | true | true | false | false | 3,878 |
739C | Alyona has built _n_ towers by putting small cubes some on the top of others. Each cube has size 1u2009×u20091u2009×u20091. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next to each other, forming a row. Sometimes Alyona chooses some segment towers, and put on the top of each tower several cubes. Formally, Alyouna chooses some segment of towers from _l__i_ to _r__i_ and adds _d__i_ cubes on the top of them. Let the sequence _a_1,u2009_a_2,u2009...,u2009_a__n_ be the heights of the towers from left to right. Let's call as a segment of towers _a__l_,u2009_a__l_u2009+u20091,u2009...,u2009_a__r_ a hill if the following condition holds: there is integer _k_ (_l_u2009≤u2009_k_u2009≤u2009_r_) such that _a__l_u2009<u2009_a__l_u2009+u20091u2009<u2009_a__l_u2009+u20092u2009<u2009...u2009<u2009_a__k_u2009>u2009_a__k_u2009+u20091u2009>u2009_a__k_u2009+u20092u2009>u2009...u2009>u2009_a__r_. After each addition of _d__i_ cubes on the top of the towers from _l__i_ to _r__i_, Alyona wants to know the maximum width among all hills. The width of a hill is the number of towers in it. Input The first line contain single integer _n_ (1u2009≤u2009_n_u2009≤u20093·105)xa0— the number of towers. The second line contain _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u2009109)xa0— the number of cubes in each tower. The third line contain single integer _m_ (1u2009≤u2009_m_u2009≤u20093·105)xa0— the number of additions. The next _m_ lines contain 3 integers each. The _i_-th of these lines contains integers _l__i_, _r__i_ and _d__i_ (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_, 1u2009≤u2009_d__i_u2009≤u2009109), that mean that Alyona puts _d__i_ cubes on the tio of each of the towers from _l__i_ to _r__i_. Output Print _m_ lines. In _i_-th line print the maximum width of the hills after the _i_-th addition. Example Input 5 5 5 5 5 5 3 1 3 2 2 2 1 4 4 1 Note The first sample is as follows: After addition of 2 cubes on the top of each towers from the first to the third, the number of cubes in the towers become equal to [7,u20097,u20097,u20095,u20095]. The hill with maximum width is [7,u20095], thus the maximum width is 2. After addition of 1 cube on the second tower, the number of cubes in the towers become equal to [7,u20098,u20097,u20095,u20095]. The hill with maximum width is now [7,u20098,u20097,u20095], thus the maximum width is 4. After addition of 1 cube on the fourth tower, the number of cubes in the towers become equal to [7,u20098,u20097,u20096,u20095]. The hill with maximum width is now [7,u20098,u20097,u20096,u20095], thus the maximum width is 5. | 2,500 | false | false | false | false | true | false | false | false | false | false | 6,841 |
317D | Problem - 317D - 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 dp games *2300 No tag edit access → Contest materials ") . Players choose numbers in turn (Vasya chooses first). If some number _x_ is chosen at the current turn, it is forbidden to choose _x_ or all of its other positive integer powers (that is, _x_2, _x_3, ...) at the next turns. For instance, if the number 9 is chosen at the first turn, one cannot choose 9 or 81 later, while it is still allowed to choose 3 or 27. The one who cannot make a move loses. Who wins if both Vasya and Petya play optimally? Input Input contains single integer _n_ (1u2009≤u2009_n_u2009≤u2009109). Output Print the name of the winner — "Vasya" or "Petya" (without quotes). Examples Input 1 Output Vasya Input 2 Output Petya Input 8 Output Petya Note In the first sample Vasya will choose 1 and win immediately. In the second sample no matter which number Vasya chooses during his first turn, Petya can choose the remaining number and win. | 2,300 | false | false | false | true | false | false | false | false | false | false | 8,562 |
1461E | In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras. Originally the cooler contained exactly $$$k$$$ liters of water. John decided that the amount of water must always be at least $$$l$$$ liters of water but no more than $$$r$$$ liters. John will stay at the office for exactly $$$t$$$ days. He knows that each day exactly $$$x$$$ liters of water will be used by his colleagues. At the beginning of each day he can add exactly $$$y$$$ liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range $$$[l, r]$$$. Now John wants to find out whether he will be able to maintain the water level at the necessary level for $$$t$$$ days. Help him answer this question! Input The first line of the input contains six integers $$$k$$$, $$$l$$$, $$$r$$$, $$$t$$$, $$$x$$$ and $$$y$$$ ($$$1 le l le k le r le 10^{18}; 1 le t le 10^{18}; 1 le x le 10^6; 1 le y le 10^{18}$$$)xa0— initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively. Note In the first example, John can't increase the amount of water at the beginning of the first day, since it would exceed the limit $$$r$$$. That is why after the first day the cooler will contain $$$2$$$ liters of water. The next day John adds $$$4$$$ liters to the cooler but loses $$$6$$$ liters, leaving John with $$$0$$$ liters, which is outside the range $$$[1, 10]$$$. In the second example, after the first day John is left with $$$2$$$ liters of water. At the beginning of the next day he adds $$$5$$$ liters, then $$$6$$$ liters get used, leaving John with $$$1$$$ liter of water which is in range $$$[1, 10]$$$. In the third example, after the first day John is left with $$$7$$$ liters, after the second dayxa0— $$$5$$$ liters, after the fourthxa0— $$$1$$$ liter. At the beginning of the fifth day John will add $$$9$$$ liters and lose $$$2$$$ liters. Meaning, after the fifth day he will have $$$8$$$ liters left. Then each day the water level will decrease by $$$2$$$ liters and after the eighth day John will have $$$2$$$ liters and after the ninth dayxa0— $$$0$$$ liters. $$$0$$$ is outside range $$$[1, 10]$$$, so the answer is "No". In the fourth example, after the first day John is left with $$$15$$$ liters of water. At the beginning of the second day he adds $$$7$$$ liters and loses $$$5$$$, so after the second day he is left with $$$17$$$ liters. At the beginning of the third day he adds $$$7$$$ more liters of water and loses $$$5$$$, so after the third day he is left with $$$19$$$ liters. $$$19$$$ is in range $$$[15, 25]$$$ so the answer is "Yes". | 2,200 | true | true | true | false | false | false | true | false | false | true | 3,382 |
1819A | As you know, any problem that does not require the use of complex data structures is considered constructive. You are offered to solve one of such problems. You are given an array $$$a$$$ of $$$n$$$ non-negative integers. You are allowed to perform the following operation exactly once: choose some non-empty subsegment $$$a_l, a_{l+1}, ldots, a_r$$$ of the array $$$a$$$ and a non-negative integer $$$k$$$, and assign value $$$k$$$ to all elements of the array on the chosen subsegment. The task is to find out whether $$$operatorname{MEX}(a)$$$ can be increased by exactly one by performing such an operation. In other words, if before the operation $$$operatorname{MEX}(a) = m$$$ held, then after the operation it must hold that $$$operatorname{MEX}(a) = m + 1$$$. Recall that $$$operatorname{MEX}$$$ of a set of integers $$$c_1, c_2, ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the set $$$c$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 50,000$$$)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 le n le 200,000$$$)xa0— the number of elements of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^9$$$)xa0— elements of array $$$a$$$. It is guaranteed that the sum $$$n$$$ over all test cases does not exceed $$$200,000$$$. Output For each test case, print "Yes" if you can increase $$$operatorname{MEX}(a)$$$ by exactly one by performing the operation from the statement exactly once, otherwise print "No". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. Example Input 4 3 1 2 1 4 0 2 2 0 4 3 2 0 2 1 0 Note In the first test case, $$$operatorname{MEX}(a) = 0$$$. If you set all elements of $$$a$$$ to $$$0$$$, then $$$operatorname{MEX}$$$ of the resulting array will be $$$1$$$, and thus will increase by one. In the second test case, $$$operatorname{MEX}(a) = 1$$$. If we assign a value of $$$1$$$ to the elements of $$$a$$$ on a subsegment from $$$2$$$ to $$$3$$$, we get an array $$$[0, 1, 1, 0]$$$ for which $$$operatorname{MEX}$$$ is $$$2$$$, and thus is increased by one compared to the original. It can be shown that in the third and fourth test cases it is impossible to perform an operation so that the value of $$$operatorname{MEX}(a)$$$ increases by exactly one. | 1,300 | false | true | false | false | false | false | true | false | false | false | 1,365 |
446D | Today DZY begins to play an old game. In this game, he is in a big maze with _n_ rooms connected by _m_ corridors (each corridor allows to move in both directions). You can assume that all the rooms are connected with corridors directly or indirectly. DZY has got lost in the maze. Currently he is in the first room and has _k_ lives. He will act like the follows: Firstly he will randomly pick one of the corridors going from his current room. Each outgoing corridor has the same probability to be picked. Then he will go through the corridor and then the process repeats. There are some rooms which have traps in them. The first room definitely has no trap, the _n_-th room definitely has a trap. Each time DZY enters one of these rooms, he will lost one life. Now, DZY knows that if he enters the _n_-th room with exactly 2 lives, firstly he will lost one live, but then he will open a bonus round. He wants to know the probability for him to open the bonus round. Please, help him. Input The first line contains three integers _n_,u2009_m_,u2009_k_xa0(2u2009≤u2009_n_u2009≤u2009500;xa01u2009≤u2009_m_u2009≤u2009105;xa02u2009≤u2009_k_u2009≤u2009109). The second line contains _n_ integers, each of them is either 0 or 1. If the _i_-th number is 1, then the _i_-th room has a trap, otherwise it has not a trap. Please note, that the number of rooms with a trap is no more than 101. It is guaranteed that the first room has no trap, and the _n_-th room has a trap. Then _m_ lines follows. Each of them contains two integers _u__i_,u2009_v__i_xa0(1u2009≤u2009_u__i_,u2009_v__i_u2009≤u2009_n_;xa0_u__i_u2009≠u2009_v__i_), meaning that current corridor connects two rooms _u__i_ and _v__i_. It is guaranteed that the corridor system is connected. Output Print the only real number — the probability for DZY to open the bonus round. The answer will be considered correct if its relative or absolute error doesn't exceed 10u2009-u20094. Examples Input 5 5 3 0 0 1 0 1 1 2 2 3 3 4 4 5 1 2 | 2,800 | true | false | false | false | false | false | false | false | false | false | 8,053 |
1184C1 | The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives! The funny part is that these tasks would be very easy for a human to solve. The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point. Input The first line contains an integer $$$n$$$ ($$$2 le n le 10$$$). Each of the following $$$4n + 1$$$ lines contains two integers $$$x_i, y_i$$$ ($$$0 leq x_i, y_i leq 50$$$), describing the coordinates of the next point. It is guaranteed that there are at least $$$n$$$ points on each side of the square and all $$$4n + 1$$$ points are distinct. Output Print two integersxa0— the coordinates of the point that is not on the boundary of the square. Examples Input 2 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 Input 2 0 0 0 1 0 2 0 3 1 0 1 2 2 0 2 1 2 2 Note In both examples, the square has four sides $$$x=0$$$, $$$x=2$$$, $$$y=0$$$, $$$y=2$$$. | 1,600 | false | false | true | false | false | false | false | false | false | false | 4,788 |
1408B | You are given a non-decreasing array of non-negative integers $$$a_1, a_2, ldots, a_n$$$. Also you are given a positive integer $$$k$$$. You want to find $$$m$$$ non-decreasing arrays of non-negative integers $$$b_1, b_2, ldots, b_m$$$, such that: The size of $$$b_i$$$ is equal to $$$n$$$ for all $$$1 leq i leq m$$$. For all $$$1 leq j leq n$$$, $$$a_j = b_{1, j} + b_{2, j} + ldots + b_{m, j}$$$. In the other word, array $$$a$$$ is the sum of arrays $$$b_i$$$. The number of different elements in the array $$$b_i$$$ is at most $$$k$$$ for all $$$1 leq i leq m$$$. Find the minimum possible value of $$$m$$$, or report that there is no possible $$$m$$$. Input The first line contains one integer $$$t$$$ ($$$1 leq t leq 100$$$): the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 leq n leq 100$$$, $$$1 leq k leq n$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 leq a_1 leq a_2 leq ldots leq a_n leq 100$$$, $$$a_n > 0$$$). Note In the first test case, there is no possible $$$m$$$, because all elements of all arrays should be equal to $$$0$$$. But in this case, it is impossible to get $$$a_4 = 1$$$ as the sum of zeros. In the second test case, we can take $$$b_1 = [3, 3, 3]$$$. $$$1$$$ is the smallest possible value of $$$m$$$. In the third test case, we can take $$$b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$$$ and $$$b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$$$. It's easy to see, that $$$a_i = b_{1, i} + b_{2, i}$$$ for all $$$i$$$ and the number of different elements in $$$b_1$$$ and in $$$b_2$$$ is equal to $$$3$$$ (so it is at most $$$3$$$). It can be proven that $$$2$$$ is the smallest possible value of $$$m$$$. | 1,400 | true | true | false | false | false | true | false | false | false | false | 3,635 |
1672B | Let's call a string good if its length is at least $$$2$$$ and all of its characters are $$$ exttt{A}$$$ except for the last character which is $$$ exttt{B}$$$. The good strings are $$$ exttt{AB}, exttt{AAB}, exttt{AAAB},ldots$$$. Note that $$$ exttt{B}$$$ is not a good string. You are given an initially empty string $$$s_1$$$. You can perform the following operation any number of times: Choose any position of $$$s_1$$$ and insert some good string in that position. Given a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations? Input Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single string $$$s_2$$$ ($$$1 leq s_2 leq 2 cdot 10^5$$$). It is guaranteed that $$$s_2$$$ consists of only the characters $$$ exttt{A}$$$ and $$$ exttt{B}$$$. It is guaranteed that the sum of $$$s_2$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, print "YES" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response). Note In the first test case, we transform $$$s_1$$$ as such: $$$varnothing o color{red}{ exttt{AAB}} o exttt{A}color{red}{ exttt{AB}} exttt{AB}$$$. In the third test case, we transform $$$s_1$$$ as such: $$$varnothing o color{red}{ exttt{AAAAAAAAB}}$$$. In the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$. | 800 | false | false | true | false | false | true | false | false | false | false | 2,244 |
612E | Problem - 612E - Codeforces =============== xa0 ]( "Educational Codeforces Round 4") — the number of elements in permutation _p_. The second line contains _n_ distinct integers _p_1,u2009_p_2,u2009...,u2009_p__n_ (1u2009≤u2009_p__i_u2009≤u2009_n_) — the elements of permutation _p_. Output If there is no permutation _q_ such that _q_2u2009=u2009_p_ print the number "-1". If the answer exists print it. The only line should contain _n_ different integers _q__i_ (1u2009≤u2009_q__i_u2009≤u2009_n_) — the elements of the permutation _q_. If there are several solutions print any of them. Examples Input 4 2 1 4 3 Output 3 4 2 1 Input 4 2 1 3 4 Output -1 Input 5 2 3 4 5 1 Output 4 5 1 2 3 | 2,200 | true | false | false | false | false | true | false | false | false | true | 7,389 |
1567C | Alice has just learned addition. However, she hasn't learned the concept of "carrying" fullyxa0— instead of carrying to the next column, she carries to the column two columns to the left. For example, the regular way to evaluate the sum $$$2039 + 2976$$$ would be as shown: However, Alice evaluates it as shown: In particular, this is what she does: add $$$9$$$ and $$$6$$$ to make $$$15$$$, and carry the $$$1$$$ to the column two columns to the left, i.xa0e. to the column "$$$0$$$ $$$9$$$"; add $$$3$$$ and $$$7$$$ to make $$$10$$$ and carry the $$$1$$$ to the column two columns to the left, i.xa0e. to the column "$$$2$$$ $$$2$$$"; add $$$1$$$, $$$0$$$, and $$$9$$$ to make $$$10$$$ and carry the $$$1$$$ to the column two columns to the left, i.xa0e. to the column above the plus sign; add $$$1$$$, $$$2$$$ and $$$2$$$ to make $$$5$$$; add $$$1$$$ to make $$$1$$$. Thus, she ends up with the incorrect result of $$$15005$$$. Alice comes up to Bob and says that she has added two numbers to get a result of $$$n$$$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $$$n$$$. Note that pairs $$$(a, b)$$$ and $$$(b, a)$$$ are considered different if $$$a e b$$$. Input The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0— the number of test cases. The description of the test cases follows. The only line of each test case contains an integer $$$n$$$ ($$$2 leq n leq 10^9$$$)xa0— the number Alice shows Bob. Output For each test case, output one integerxa0— the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $$$n$$$. Example Input 5 100 12 8 2021 10000 Note In the first test case, when Alice evaluates any of the sums $$$1 + 9$$$, $$$2 + 8$$$, $$$3 + 7$$$, $$$4 + 6$$$, $$$5 + 5$$$, $$$6 + 4$$$, $$$7 + 3$$$, $$$8 + 2$$$, or $$$9 + 1$$$, she will get a result of $$$100$$$. The picture below shows how Alice evaluates $$$6 + 4$$$: | 1,600 | true | false | false | true | false | false | false | false | false | false | 2,802 |
1279A | Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands. The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland! For example, if you provide $$$3$$$ red, $$$3$$$ green and $$$3$$$ blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland. However, if you provide, say, $$$1$$$ red, $$$10$$$ green and $$$2$$$ blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided. So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 100$$$) — the number of sets of lamps Polycarp has bought. Each of the next $$$t$$$ lines contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 le r, g, b le 10^9$$$) — the number of red, green and blue lamps in the set, respectively. Note The first two sets are desribed in the statement. The third set produces garland "RBRG", for example. | 900 | true | false | false | false | false | false | false | false | false | false | 4,300 |
1260A | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house. Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles. Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. Input The first line contains single integer $$$n$$$ ($$$1 le n le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 le c_i, sum_i le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. Note In the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$. In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section. In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | 1,000 | true | false | false | false | false | false | false | false | false | false | 4,394 |
1750C | You have two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$. You would like to make all the elements of both strings equal to $$$0$$$. Unfortunately, you can modify the contents of these strings using only the following operation: You choose two indices $$$l$$$ and $$$r$$$ ($$$1 le l le r le n$$$); For every $$$i$$$ that respects $$$l le i le r$$$, change $$$a_i$$$ to the opposite. That is, $$$a_i := 1 - a_i$$$; For every $$$i$$$ that respects either $$$1 le i < l$$$ or $$$r < i le n$$$, change $$$b_i$$$ to the opposite. That is, $$$b_i := 1 - b_i$$$. Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed $$$n + 5$$$. It can be proven that if such chain of operations exists, one exists with at most $$$n + 5$$$ operations. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$) — the length of the strings. The second line of each test case contains a binary string $$$a$$$, consisting only of characters 0 and 1, of length $$$n$$$. The third line of each test case contains a binary string $$$b$$$, consisting only of characters 0 and 1, of length $$$n$$$. It is guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 cdot 10^5$$$. Output For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to $$$0$$$. Otherwise, print "NO". If the answer is "YES", on the next line print a single integer $$$k$$$ ($$$0 le k le n + 5$$$) — the number of operations. Then $$$k$$$ lines follows, each contains two integers $$$l$$$ and $$$r$$$ ($$$1 le l le r le n$$$) — the description of the operation. If there are several correct answers, print any of them. Example Input 5 3 010 101 2 11 10 4 1000 0011 2 10 10 3 111 111 Output YES 1 2 2 NO NO YES 2 1 2 2 2 YES 2 1 1 2 3 Note In the first test case, we can perform one operation with $$$l = 2$$$ and $$$r = 2$$$. So $$$a_2 := 1 - 1 = 0$$$ and string $$$a$$$ became equal to 000. $$$b_1 := 1 - 1 = 0$$$, $$$b_3 := 1 - 1 = 0$$$ and string $$$b$$$ became equal to 000. In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to $$$0$$$. In the fourth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 2$$$, then string $$$a$$$ became equal to 01, and string $$$b$$$ doesn't change. Then we perform an operation with $$$l = 2$$$ and $$$r = 2$$$, then $$$a_2 := 1 - 1 = 0$$$ and $$$b_1 = 1 - 1 = 0$$$. So both of string $$$a$$$ and $$$b$$$ became equal to 00. In the fifth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 1$$$. Then string $$$a$$$ became equal to 011 and string $$$b$$$ became equal to 100. Then we can perform an operation with $$$l = 2$$$ and $$$r = 3$$$, so both of string $$$a$$$ and $$$b$$$ became equal to 000. | 1,400 | false | false | true | false | false | true | false | false | false | false | 1,783 |
607B | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of _n_ gemstones, the _i_-th of which has color _c__i_. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line? Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on. Input The first line of input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u2009500)xa0— the number of gemstones. The second line contains _n_ space-separated integers, the _i_-th of which is _c__i_ (1u2009≤u2009_c__i_u2009≤u2009_n_)xa0— the color of the _i_-th gemstone in a line. Output Print a single integerxa0— the minimum number of seconds needed to destroy the entire line. Note In the first sample, Genos can destroy the entire line in one second. In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds. In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1. | 1,900 | false | false | false | true | false | false | false | false | false | false | 7,418 |
48D | A permutation is a sequence of integers from 1 to _n_ of length _n_ containing each number exactly once. For example, (1), (4,u20093,u20095,u20091,u20092), (3,u20092,u20091) are permutations, and (1,u20091), (4,u20093,u20091), (2,u20093,u20094) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took several permutations (perhaps, with a different number of elements), wrote them down consecutively as one array and then shuffled the resulting array. The task is to restore the initial permutations if it is possible. Input The first line contains an integer _n_ (1u2009≤u2009_n_u2009≤u2009105). The next line contains the mixed array of _n_ integers, divided with a single space. The numbers in the array are from 1 to 105. Output If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain _n_ numbers, corresponding to the elements of the given array. If the _i_-th element belongs to the first permutation, the _i_-th number should be 1, if it belongs to the second one, then its number should be 2 and so on. The order of the permutations’ numbering is free. If several solutions are possible, print any one of them. If there’s no solution, print in the first line u2009-u20091. Note In the first sample test the array is split into three permutations: (2,u20091), (3,u20092,u20091,u20094,u20095), (1,u20092). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth elements. Clearly, there are other splitting variants possible. | 1,500 | false | true | false | false | false | false | false | false | false | false | 9,734 |
484C | How many specific orders do you know? Ascending order, descending order, order of ascending length, order of ascending polar angle... Let's have a look at another specific order: _d_-sorting. This sorting is applied to the strings of length at least _d_, where _d_ is some positive integer. The characters of the string are sorted in following manner: first come all the 0-th characters of the initial string, then the 1-st ones, then the 2-nd ones and so on, in the end go all the (_d_u2009-u20091)-th characters of the initial string. By the _i_-th characters we mean all the character whose positions are exactly _i_ modulo _d_. If two characters stand on the positions with the same remainder of integer division by _d_, their relative order after the sorting shouldn't be changed. The string is zero-indexed. For example, for string 'qwerty': Its 1-sorting is the string 'qwerty' (all characters stand on 0 positions), Its 2-sorting is the string 'qetwry' (characters 'q', 'e' and 't' stand on 0 positions and characters 'w', 'r' and 'y' are on 1 positions), Its 3-sorting is the string 'qrwtey' (characters 'q' and 'r' stand on 0 positions, characters 'w' and 't' stand on 1 positions and characters 'e' and 'y' stand on 2 positions), Its 4-sorting is the string 'qtwyer', Its 5-sorting is the string 'qywert'. You are given string _S_ of length _n_ and _m_ shuffling operations of this string. Each shuffling operation accepts two integer arguments _k_ and _d_ and transforms string _S_ as follows. For each _i_ from 0 to _n_u2009-u2009_k_ in the increasing order we apply the operation of _d_-sorting to the substring _S_[_i_.._i_u2009+u2009_k_u2009-u20091]. Here _S_[_a_.._b_] represents a substring that consists of characters on positions from _a_ to _b_ inclusive. After each shuffling operation you need to print string _S_. Input The first line of the input contains a non-empty string _S_ of length _n_, consisting of lowercase and uppercase English letters and digits from 0 to 9. The second line of the input contains integer _m_xa0– the number of shuffling operations (1u2009≤u2009_m_·_n_u2009≤u2009106). Following _m_ lines contain the descriptions of the operations consisting of two integers _k_ and _d_ (1u2009≤u2009_d_u2009≤u2009_k_u2009≤u2009_n_). Note Here is detailed explanation of the sample. The first modification is executed with arguments _k_u2009=u20094, _d_u2009=u20092. That means that you need to apply 2-sorting for each substring of length 4 one by one moving from the left to the right. The string will transform in the following manner: qwerty u2009→u2009 qewrty u2009→u2009 qerwty u2009→u2009 qertwy Thus, string _S_ equals 'qertwy' at the end of first query. The second modification is executed with arguments _k_u2009=u20096, _d_u2009=u20093. As a result of this operation the whole string _S_ is replaced by its 3-sorting: qertwy u2009→u2009 qtewry The third modification is executed with arguments _k_u2009=u20095, _d_u2009=u20092. qtewry u2009→u2009 qertwy u2009→u2009 qetyrw | 2,600 | true | false | true | false | false | false | false | false | false | false | 7,900 |
865C | You're trying to set the record on your favorite video game. The game consists of _N_ levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Specifically, you will complete the _i_-th level in either _F__i_ seconds or _S__i_ seconds, where _F__i_u2009<u2009_S__i_, and there's a _P__i_ percent chance of completing it in _F__i_ seconds. After completing a level, you may decide to either continue the game and play the next level, or reset the game and start again from the first level. Both the decision and the action are instant. Your goal is to complete all the levels sequentially in at most _R_ total seconds. You want to minimize the expected amount of time playing before achieving that goal. If you continue and reset optimally, how much total time can you expect to spend playing? Input The first line of input contains integers _N_ and _R_ , the number of levels and number of seconds you want to complete the game in, respectively. _N_ lines follow. The _i_th such line contains integers _F__i_,u2009_S__i_,u2009_P__i_ (1u2009≤u2009_F__i_u2009<u2009_S__i_u2009≤u2009100,u200980u2009≤u2009_P__i_u2009≤u200999), the fast time for level _i_, the slow time for level _i_, and the probability (as a percentage) of completing level _i_ with the fast time. Output Print the total expected time. Your answer must be correct within an absolute or relative error of 10u2009-u20099. Formally, let your answer be _a_, and the jury's answer be _b_. Your answer will be considered correct, if . Examples Input 4 319 63 79 89 79 97 91 75 87 88 75 90 83 Note In the first example, you never need to reset. There's an 81% chance of completing the level in 2 seconds and a 19% chance of needing 8 seconds, both of which are within the goal time. The expected time is 0.81·2u2009+u20090.19·8u2009=u20093.14. In the second example, you should reset after the first level if you complete it slowly. On average it will take 0.25 slow attempts before your first fast attempt. Then it doesn't matter whether you complete the second level fast or slow. The expected time is 0.25·30u2009+u200920u2009+u20090.85·3u2009+u20090.15·9u2009=u200931.4. | 2,400 | false | false | false | true | false | false | false | true | false | false | 6,279 |
581F | It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on _n_ main squares of the capital of Berland. Each of the _n_ squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties. Some pairs of squares are connected by (_n_u2009-u20091) bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares. The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even. To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number. Input The first line of the input contains a single integer _n_ (2u2009≤u2009_n_u2009≤u20095000) — the number of squares in the capital of Berland. Next _n_u2009-u20091 lines contain the pairs of integers _x_,u2009_y_ (1u2009≤u2009_x_,u2009_y_u2009≤u2009_n_,u2009_x_u2009≠u2009_y_) — the numbers of the squares connected by the road. All squares are numbered with integers from 1 to _n_. It is guaranteed that the number of dead end squares of the city is even. Output Print a single number — the minimum number of roads connecting the squares with demonstrations of different parties. Examples Input 8 1 4 2 4 3 4 6 5 7 5 8 5 4 5 | 2,400 | false | false | false | true | false | false | false | false | false | false | 7,518 |
993A | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$. Output Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples Input 0 0 6 0 6 6 0 6 1 3 3 5 5 3 3 1 Input 0 0 6 0 6 6 0 6 7 3 9 5 11 3 9 1 Input 6 0 6 6 0 6 0 0 7 4 4 7 7 10 10 7 Note In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples: | 1,600 | false | false | true | false | false | false | false | false | false | false | 5,734 |
1748D | You are given three integers $$$a$$$, $$$b$$$, and $$$d$$$. Your task is to find any integer $$$x$$$ which satisfies all of the following conditions, or determine that no such integers exist: $$$0 le x lt 2^{60}$$$; $$$ax$$$ is divisible by $$$d$$$; $$$bx$$$ is divisible by $$$d$$$. Here, $$$$$$ denotes the xa0— the number of test cases. Each test case consists of one line, containing three integers $$$a$$$, $$$b$$$, and $$$d$$$ ($$$1 le a,b,d lt 2^{30}$$$). Output For each test case print one integer. If there exists an integer $$$x$$$ which satisfies all of the conditions from the statement, print $$$x$$$. Otherwise, print $$$-1$$$. If there are multiple solutions, you may print any of them. Example Input 8 12 39 5 6 8 14 100 200 200 3 4 6 2 2 2 18 27 3 420 666 69 987654321 123456789 999999999 Output 18 14 -1 -1 0 11 25599 184470016815529983 Note In the first test case, $$$x=18$$$ is one of the possible solutions, since $$$3918=55$$$ and $$$1218=30$$$, both of which are multiples of $$$d=5$$$. In the second test case, $$$x=14$$$ is one of the possible solutions, since $$$814=614=14$$$, which is a multiple of $$$d=14$$$. In the third and fourth test cases, we can show that there are no solutions. | 2,100 | true | false | false | false | false | true | false | false | false | false | 1,794 |
455A | Problem - 455A - 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 dp *1500 No tag edit access → Contest materials and delete it, at that all elements equal to _a__k_u2009+u20091 and _a__k_u2009-u20091 also must be deleted from the sequence. That step brings _a__k_ points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u2009105) that shows how many numbers are in Alex's sequence. The second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (1u2009≤u2009_a__i_u2009≤u2009105). Output Print a single integer — the maximum number of points that Alex can earn. Examples Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 Note Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this | 1,500 | false | false | false | true | false | false | false | false | false | false | 8,019 |
287A | In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4u2009×u20094 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2u2009×u20092 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2u2009×u20092 square, consisting of cells of the same color. Input Four lines contain four characters each: the _j_-th character of the _i_-th line equals "." if the cell in the _i_-th row and the _j_-th column of the square is painted white, and "#", if the cell is black. Output Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. Note In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2u2009×u20092 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 1,100 | false | false | true | false | false | false | true | false | false | false | 8,686 |
1364E | 2,700 | false | false | false | false | false | true | false | false | false | false | 3,858 | |
1983C | Alice, Bob and Charlie want to share a rectangular cake cut into $$$n$$$ pieces. Each person considers every piece to be worth a different value. The $$$i$$$-th piece is considered to be of value $$$a_i$$$ by Alice, $$$b_i$$$ by Bob and $$$c_i$$$ by Charlie. The sum over all $$$a_i$$$, all $$$b_i$$$ and all $$$c_i$$$ individually is the same, equal to $$$tot$$$. Given the values of each piece of the cake for each person, you need to give each person a contiguous slice of cake. In other words, the indices at the left and right ends of these subarrays (the slices given to each person) can be represented as $$$(l_a, r_a)$$$, $$$(l_b, r_b)$$$ and $$$(l_c, r_c)$$$ respectively for Alice, Bob and Charlie. The division needs to satisfy the following constraints: No piece is assigned to more than one person, i.e., no two subarrays among $$$[l_a,ldots,r_a]$$$, $$$[l_b, ldots, r_b]$$$ and $$$[l_c, ldots, r_c]$$$ intersect. $$$ sum_{i = l_a}^{r_a} a_i, sum_{i = l_b}^{r_b} b_i, sum_{i = l_c}^{r_c} c_i geq lceil frac{tot}{3} ceil$$$. Here, the notation $$$lceil frac{a}{b} ceil$$$ represents ceiling division. It is defined as the smallest integer greater than or equal to the exact division of $$$a$$$ by $$$b$$$. In other words, it rounds up the division result to the nearest integer. For instance $$$lceil frac{10}{3} ceil = 4$$$ and $$$lceil frac{15}{3} ceil = 5$$$. Input The first line contains an integer $$$t$$$, the number of testcases, ($$$1 le t le 10^4$$$) For each testcase: The first line contains the integer $$$n$$$ ($$$3 le n le 2 cdot 10^5$$$). The following three lines contain $$$n$$$ integers each: One line with $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ represents the values for Alice ($$$1 le a_i le 10^6$$$). The next line with $$$n$$$ integers $$$b_1, b_2, ldots, b_n$$$ represents the values for Bob ($$$1 le b_i le 10^6$$$). The next line with $$$n$$$ integers $$$c_1, c_2, ldots, c_n$$$ represents the values for Charlie ($$$1 le c_i le 10^6$$$). It is guaranteed that $$$ sum_{i = 1}^{n} a_i = sum_{i = 1}^{n} b_i = sum_{i = 1}^{n} c_i$$$. The sum of $$$n$$$ over all testcases does not exceed $$$2 cdot 10^5$$$. Output For each testcase, output $$$-1$$$ if the required condition is impossible. Otherwise, output six numbers – $$$l_a, r_a, l_b, r_b, l_c, r_c$$$, the respective starting and ending indices ($$$1$$$-indexed) of the subarrays for Alice, Bob and Charlie, respectively. Example Input 10 5 5 1 1 1 1 1 1 5 1 1 1 1 1 1 5 6 1 2 3 4 5 6 5 6 1 2 3 4 3 4 5 6 1 2 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 10 5 2 10 9 6 9 7 1 10 7 10 2 3 3 4 5 2 6 1 4 1 8 2 3 10 4 10 8 7 9 10 4 10 7 57113 65383 19795 53580 74452 3879 23255 12917 16782 89147 93107 27365 15044 43095 33518 63581 33565 34112 46774 44151 41756 6 6 3 1 8 7 1 10 2 6 2 2 4 10 9 2 1 2 2 5 5 5 4 5 5 1 6 3 8 6 2 4 1 9 8 10 1 1 1 1 1001 1 1 1001 1 1 1 1 1 1 1 1 2001 1 1 1 1 1 1 1 1 1001 1 1 1 1001 Output 1 1 2 3 4 5 5 6 1 2 3 4 -1 -1 1 1 3 3 2 2 -1 1 2 3 4 5 7 3 6 1 1 2 2 1 2 3 4 5 5 1 5 6 7 8 10 Note In the first testcase, the sum of either of the three arrays is $$$9$$$. Each person needs a cake slice corresponding to a subarray with a total value of at least $$$lceil frac{9}{3} ceil = 3$$$. If we assign the subarray ($$$1$$$,$$$1$$$) to Alice, its total value to her is $$$5$$$, which is $$$ge 3$$$; the subarray ($$$2$$$,$$$3$$$) to Bob, its total value to him is $$$1 + 5 = 6$$$, which is $$$ge 3$$$; and the subarray ($$$4$$$,$$$5$$$) to Charlie, its total value to him $$$1 + 5 = 6$$$, which is also $$$ge 3$$$. Each person gets their own separate pieces of the cake, and no piece is common to two or more people. It can be shown that for the third test case, it is not possible to give slices of the cake in a way that satisfies the given constraints. | 1,400 | false | true | true | false | false | false | true | true | false | false | 388 |
11A | Problem - 11A - Codeforces =============== xa0 ]( "Codeforces Beta Round #11") . The second line contains space separated sequence _b_0,u2009_b_1,u2009...,u2009_b__n_u2009-u20091 (1u2009≤u2009_b__i_u2009≤u2009106). Output Output the minimal number of moves needed to make the sequence increasing. Examples Input 4 2 1 3 3 2 Output 3 | 900 | true | false | true | false | false | true | false | false | false | false | 9,940 |
808A | Problem - 808A - Codeforces =============== xa0 ]( "52010") — current year in Berland. Output Output amount of years from the current year to the next lucky one. Examples Input 4 Output 1 Input 201 Output 99 Input 4000 Output 1000 Note In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 900 | false | false | true | false | false | false | false | false | false | false | 6,535 |
946B | Problem - 946B - 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 number theory *1100 No tag edit access → Contest materials . _n_ is the initial value of variable _a_, and _m_ is the initial value of variable _b_. Output Print two integers — the values of _a_ and _b_ after the end of the process. Examples Input 12 5 Output 0 1 Input 31 12 Output 7 12 Note Explanations to the samples: 1. _a_u2009=u200912, _b_u2009=u20095 _a_u2009=u20092, _b_u2009=u20095 _a_u2009=u20092, _b_u2009=u20091 _a_u2009=u20090, _b_u2009=u20091; 2. _a_u2009=u200931, _b_u2009=u200912 _a_u2009=u20097, _b_u2009=u200912. | 1,100 | true | false | false | false | false | false | false | false | false | false | 5,931 |
831B | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string _s_ consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of _s_ does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 | 800 | false | false | true | false | false | false | false | false | false | false | 6,441 |
1089A | Alice is a big fan of volleyball and especially of the very strong "Team A". Volleyball match consists of up to five sets. During each set teams score one point for winning axa0ball. The first four sets are played until one of the teams scores at least 25xa0points and the fifth set is played until one of the teams scores at least 15 points. Moreover, if one of the teams scores 25 (or 15 in the fifth set) points while the other team scores 24 (or 14 in the fifth set), the set is played until the absolute difference between teams' points becomes two. The match ends when one of the teams wins three sets. The match score is the number of sets won by each team. Alice found a book containing all the results of all matches played by "Team A". The book is old, and some parts of the book became unreadable. Alice can not read the information on how many sets each of the teams won, she can not read the information on how many points each of the teams scored in each set, she even does not know the number of sets played in a match. The only information she has is the total number of points scored by each of the teams in all the sets during a single match. Alice wonders what is the best match score "Team A" could achieve in each of the matches. The bigger is the difference between the number of sets won by "Team A" and their opponent, the better is the match score. Find the best match score or conclude that no match could end like that. If there is a solution, then find any possible score for each set that results in the best match score. Input The first line contains a single integer $$$m$$$ ($$$1 le m le 50,000$$$)xa0— the number of matches found by Alice in the book. Each of the next $$$m$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$0 le a, b le 200$$$)xa0— the number of points scored by "Team A" and the number of points scored by their opponents respectively. Output Output the solution for every match in the same order as they are given in the input. If the teams could not score $$$a$$$ and $$$b$$$ points respectively, output "Impossible". Otherwise, output the match score formatted as "$$$x$$$:$$$y$$$", where $$$x$$$ is the number of sets won by "Team A" and $$$y$$$ is the number of sets won by their opponent. The next line should contain the set scores in the order they were played. Each set score should be printed in the same format as the match score, with $$$x$$$ being the number of points scored by "Team A" in this set, and $$$y$$$ being the number of points scored by their opponent. Example Input 6 75 0 90 90 20 0 0 75 78 50 80 100 Output 3:0 25:0 25:0 25:0 3:1 25:22 25:22 15:25 25:21 Impossible 0:3 0:25 0:25 0:25 3:0 25:11 28:26 25:13 3:2 25:17 0:25 25:22 15:25 15:11 | 2,200 | false | false | false | true | false | false | false | false | false | false | 5,285 |
1157C2 | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $$$a$$$ consisting of $$$n$$$ integers. You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the rightmost element of the sequence, write it down and remove it from the sequence. Your task is to write down a strictly increasing sequence, and among all such sequences you should take the longest (the length of the sequence is the number of elements in it). For example, for the sequence $$$[1, 2, 4, 3, 2]$$$ the answer is $$$4$$$ (you take $$$1$$$ and the sequence becomes $$$[2, 4, 3, 2]$$$, then you take the rightmost element $$$2$$$ and the sequence becomes $$$[2, 4, 3]$$$, then you take $$$3$$$ and the sequence becomes $$$[2, 4]$$$ and then you take $$$4$$$ and the sequence becomes $$$[2]$$$, the obtained increasing sequence is $$$[1, 2, 3, 4]$$$). Input The first line of the input contains one integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 2 cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. Output In the first line of the output print $$$k$$$ — the maximum number of elements in a strictly increasing sequence you can obtain. In the second line print a string $$$s$$$ of length $$$k$$$, where the $$$j$$$-th character of this string $$$s_j$$$ should be 'L' if you take the leftmost element during the $$$j$$$-th move and 'R' otherwise. If there are multiple answers, you can print any. | 1,700 | false | true | false | false | false | false | false | false | false | false | 4,920 |
2021C1 | This is the easy version of the problem. In the two versions, the constraints on $$$q$$$ and the time limit are different. In this version, $$$q=0$$$. You can make hacks only if all the versions of the problem are solved. A team consisting of $$$n$$$ members, numbered from $$$1$$$ to $$$n$$$, is set to present a slide show at a large meeting. The slide show contains $$$m$$$ slides. There is an array $$$a$$$ of length $$$n$$$. Initially, the members are standing in a line in the order of $$$a_1, a_2, ldots, a_n$$$ from front to back. The slide show will be presented in order from slide $$$1$$$ to slide $$$m$$$. Each section will be presented by the member at the front of the line. After each slide is presented, you can move the member at the front of the line to any position in the lineup (without changing the order of the rest of the members). For example, suppose the line of members is $$$[color{red}{3},1,2,4]$$$. After member $$$3$$$ presents the current slide, you can change the line of members into either $$$[color{red}{3},1,2,4]$$$, $$$[1,color{red}{3},2,4]$$$, $$$[1,2,color{red}{3},4]$$$ or $$$[1,2,4,color{red}{3}]$$$. There is also an array $$$b$$$ of length $$$m$$$. The slide show is considered good if it is possible to make member $$$b_i$$$ present slide $$$i$$$ for all $$$i$$$ from $$$1$$$ to $$$m$$$ under these constraints. However, your annoying boss wants to make $$$q$$$ updates to the array $$$b$$$. In the $$$i$$$-th update, he will choose a slide $$$s_i$$$ and a member $$$t_i$$$ and set $$$b_{s_i} := t_i$$$. Note that these updates are persistent, that is changes made to the array $$$b$$$ will apply when processing future updates. For each of the $$$q+1$$$ states of array $$$b$$$, the initial state and after each of the $$$q$$$ updates, determine if the slideshow is good. 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 first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 le n, m le 2 cdot 10^5$$$; $$$q=0$$$)xa0— the number of members, the number of sections and the number of updates. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,ldots,a_n$$$ ($$$1 le a_i le n$$$)xa0— the initial order of the members from front to back. It is guaranteed that each integer from $$$1$$$ to $$$n$$$ appears exactly once in $$$a$$$. The third line of each test case contains $$$m$$$ integers $$$b_1, b_2, ldots, b_m$$$ ($$$1 le b_i le n$$$)xa0— the members who should present each section. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$2 cdot 10^5$$$ respectively. Output For each test case, output $$$q+1$$$ lines corresponding to the $$$q+1$$$ states of the array $$$b$$$. Output "YA" if the slide show is good, and "TIDAK" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yA", "Ya", "ya", and "YA" will be recognized as positive responses. Note For the first test case, you do not need to move the members as both slides are presented by member $$$1$$$, who is already at the front of the line. For the second test case, the following is a possible way to move members so that the presentation is good: 1. $$$[1,2,3]$$$, do not move member $$$1$$$. 2. $$$[1,2,3]$$$, move member $$$1$$$ after member $$$3$$$. 3. $$$[2,3,1]$$$, move member $$$2$$$ after member $$$3$$$. 4. $$$[3,2,1]$$$, do not move member $$$3$$$. 5. $$$[3,2,1]$$$, move member $$$3$$$ after member $$$1$$$. 6. $$$[2,1,3]$$$, do not move member $$$2$$$. | 1,300 | false | true | false | false | false | true | false | false | false | false | 144 |
1088E | You're given a tree consisting of $$$n$$$ nodes. Every node $$$u$$$ has a weight $$$a_u$$$. You want to choose an integer $$$k$$$ $$$(1 le k le n)$$$ and then choose $$$k$$$ connected components of nodes that don't overlap (i.e every node is in at most 1 component). Let the set of nodes you chose be $$$s$$$. You want to maximize: $$$$$$frac{sumlimits_{u in s} a_u}{k}$$$$$$ In other words, you want to maximize the sum of weights of nodes in $$$s$$$ divided by the number of connected components you chose. Also, if there are several solutions, you want to maximize $$$k$$$. Note that adjacent nodes can belong to different components. Refer to the third sample. Input The first line contains the integer $$$n$$$ $$$(1 le n le 3 cdot 10^5)$$$, the number of nodes in the tree. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$dots$$$, $$$a_n$$$ $$$(a_i le 10^9)$$$, the weights of the nodes. The next $$$n-1$$$ lines, each contains 2 space-separated integers $$$u$$$ and $$$v$$$ $$$(1 le u,v le n)$$$ which means there's an edge between $$$u$$$ and $$$v$$$. Output Print the answer as a non-reduced fraction represented by 2 space-separated integers. The fraction itself should be maximized and if there are several possible ways, you should maximize the denominator. See the samples for a better understanding. Note A connected component is a set of nodes such that for any node in the set, you can reach all other nodes in the set passing only nodes in the set. In the first sample, it's optimal to choose the whole tree. In the second sample, you only have one choice (to choose node 1) because you can't choose 0 components. In the third sample, notice that we could've, for example, chosen only node 1, or node 1 and node 3, or even the whole tree, and the fraction would've had the same value (-1), but we want to maximize $$$k$$$. In the fourth sample, we'll just choose nodes 1 and 3. | 2,400 | true | true | false | true | false | false | false | false | false | false | 5,287 |
1187F | Let $$$x$$$ be an array of integers $$$x = [x_1, x_2, dots, x_n]$$$. Let's define $$$B(x)$$$ as a minimal size of a partition of $$$x$$$ into subsegments such that all elements in each subsegment are equal. For example, $$$B([3, 3, 6, 1, 6, 6, 6]) = 4$$$ using next partition: $$$[3, 3 6 1 6, 6, 6]$$$. Now you don't have any exact values of $$$x$$$, but you know that $$$x_i$$$ can be any integer value from $$$[l_i, r_i]$$$ ($$$l_i le r_i$$$) uniformly at random. All $$$x_i$$$ are independent. Calculate expected value of $$$(B(x))^2$$$, or $$$E((B(x))^2)$$$. It's guaranteed that the expected value can be represented as rational fraction $$$frac{P}{Q}$$$ where $$$(P, Q) = 1$$$, so print the value $$$P cdot Q^{-1} mod 10^9 + 7$$$. Input The first line contains the single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) — the size of the array $$$x$$$. The second line contains $$$n$$$ integers $$$l_1, l_2, dots, l_n$$$ ($$$1 le l_i le 10^9$$$). The third line contains $$$n$$$ integers $$$r_1, r_2, dots, r_n$$$ ($$$l_i le r_i le 10^9$$$). Note Let's describe all possible values of $$$x$$$ for the first sample: $$$[1, 1, 1]$$$: $$$B(x) = 1$$$, $$$B^2(x) = 1$$$; $$$[1, 1, 2]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[1, 1, 3]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[1, 2, 1]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; $$$[1, 2, 2]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[1, 2, 3]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; So $$$E = frac{1}{6} (1 + 4 + 4 + 9 + 4 + 9) = frac{31}{6}$$$ or $$$31 cdot 6^{-1} = 166666673$$$. All possible values of $$$x$$$ for the second sample: $$$[3, 4, 5]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; $$$[3, 4, 6]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; $$$[3, 5, 5]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[3, 5, 6]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; $$$[4, 4, 5]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[4, 4, 6]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[4, 5, 5]$$$: $$$B(x) = 2$$$, $$$B^2(x) = 4$$$; $$$[4, 5, 6]$$$: $$$B(x) = 3$$$, $$$B^2(x) = 9$$$; So $$$E = frac{1}{8} (9 + 9 + 4 + 9 + 4 + 4 + 4 + 9) = frac{52}{8}$$$ or $$$13 cdot 2^{-1} = 500000010$$$. | 2,500 | true | false | false | true | false | false | false | false | false | false | 4,761 |
72C | Problem - 72C - Codeforces =============== xa0 → 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 *special problem math *1200 No tag edit access → Contest materials . Output Write a single yes or no. Write yes if the number is extraordinarily nice and no otherwise. You don't need to care about capital or small letters. The output is case-insensitive. Examples Input 2 Output yes Input 3 Output no | 1,200 | true | false | false | false | false | false | false | false | false | false | 9,609 |
223C | Problem - 223C - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags combinatorics math number theory *1900 No tag edit access → Contest materials of array _s_ equals . The operation _x_xa0_mod_xa0_y_ means that we take the remainder of the division of number _x_ by number _y_. 2. Then we write the contents of the array _s_ to the array _a_. Element number _i_ (1u2009≤u2009_i_u2009≤u2009_n_) of the array _s_ becomes the _i_-th element of the array _a_ (_a__i_u2009=u2009_s__i_). You task is to find array _a_ after exactly _k_ described operations are applied. Input The first line contains two space-separated integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u20092000, 0u2009≤u2009_k_u2009≤u2009109). The next line contains _n_ space-separated integers _a_1,u2009_a_2,u2009...,u2009_a__n_xa0— elements of the array _a_ (0u2009≤u2009_a__i_u2009≤u2009109). Output Print _n_ integers xa0— elements of the array _a_ after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array _a_. Separate the printed numbers by spaces. Examples Input 3 1 1 2 3 Output 1 3 6 Input 5 0 3 14 15 92 6 Output 3 14 15 92 6 | 1,900 | true | false | false | false | false | false | false | false | false | false | 8,945 |
1919F1 | This is the easy version of the problem. The only difference between the two versions is the constraint on $$$c_i$$$ and $$$z$$$. You can make hacks only if both versions of the problem are solved. There are three arrays $$$a$$$, $$$b$$$ and $$$c$$$. $$$a$$$ and $$$b$$$ have length $$$n$$$ and $$$c$$$ has length $$$n-1$$$. Let $$$W(a,b,c)$$$ denote the liters of wine created from the following process. Create $$$n$$$ water towers. The $$$i$$$-th water tower initially has $$$a_i$$$ liters of water and has a wizard with power $$$b_i$$$ in front of it. Furthermore, for each $$$1 le i le n - 1$$$, there is a valve connecting water tower $$$i$$$ to $$$i + 1$$$ with capacity $$$c_i$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$ in this order, the following happens: 1. The wizard in front of water tower $$$i$$$ removes at most $$$b_i$$$ liters of water from the tower and turns the removed water into wine. 2. If $$$i eq n$$$, at most $$$c_i$$$ liters of the remaining water left in water tower $$$i$$$ flows through the valve into water tower $$$i + 1$$$. There are $$$q$$$ updates. In each update, you will be given integers $$$p$$$, $$$x$$$, $$$y$$$ and $$$z$$$ and you will update $$$a_p := x$$$, $$$b_p := y$$$ and $$$c_p := z$$$. After each update, find the value of $$$W(a,b,c)$$$. Note that previous updates to arrays $$$a$$$, $$$b$$$ and $$$c$$$ persist throughout future updates. Input The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 le n le 5cdot 10^5$$$, $$$1 le q le 5cdot 10^5$$$)xa0— the number of water towers and the number of updates. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^9$$$)xa0— the number of liters of water in water tower $$$i$$$. The third line contains $$$n$$$ integers $$$b_1, b_2, ldots, b_n$$$ ($$$0 le b_i le 10^9$$$)xa0— the power of the wizard in front of water tower $$$i$$$. The fourth line contains $$$n - 1$$$ integers $$$c_1, c_2, ldots, c_{n - 1}$$$ ($$$c_i color{red}{=} 10^{18}$$$)xa0— the capacity of the pipe connecting water tower $$$i$$$ to $$$i + 1$$$. Each of the next $$$q$$$ lines contains four integers $$$p$$$, $$$x$$$, $$$y$$$ and $$$z$$$ ($$$1 le p le n$$$, $$$0 le x, y le 10^9$$$, $$$z color{red}{=} 10^{18}$$$)xa0— the updates done to arrays $$$a$$$, $$$b$$$ and $$$c$$$. Note that $$$c_n$$$ does not exist, so the value of $$$z$$$ does not matter when $$$p = n$$$. Output Print $$$q$$$ lines, each line containing a single integer representing $$$W(a, b, c)$$$ after each update. Examples Input 4 3 3 3 3 3 1 4 2 8 1000000000000000000 1000000000000000000 1000000000000000000 4 3 8 1000000000000000000 2 5 1 1000000000000000000 3 0 0 1000000000000000000 Input 5 5 10 3 8 9 2 3 4 10 8 1 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 5 4 9 1000000000000000000 1 1 1 1000000000000000000 2 7 4 1000000000000000000 4 1 1 1000000000000000000 1 8 3 1000000000000000000 Note The first update does not make any modifications to the arrays. When $$$i = 1$$$, there are $$$3$$$ liters of water in tower 1 and $$$1$$$ liter of water is turned into wine. The remaining $$$2$$$ liters of water flow into tower 2. When $$$i = 2$$$, there are $$$5$$$ liters of water in tower 2 and $$$4$$$ liters of water is turned into wine. The remaining $$$1$$$ liter of water flows into tower 3. When $$$i = 3$$$, there are $$$4$$$ liters of water in tower 3 and $$$2$$$ liters of water is turned into wine. The remaining $$$2$$$ liters of water flows into tower 4. When $$$i = 4$$$, there are $$$5$$$ liters of water in tower 4. All $$$5$$$ liters of water are turned into wine. Hence, $$$W(a,b,c)=1 + 4 + 2 + 5 = 12$$$ after the first update. The second update modifies the arrays to $$$a = [3, 5, 3, 3]$$$, $$$b = [1, 1, 2, 8]$$$, and $$$c = [10^{18}, 10^{18}, 10^{18}]$$$. When $$$i = 1$$$, there are $$$3$$$ liters of water in tower 1 and $$$1$$$ liter of water is turned into wine. The remaining $$$2$$$ liters of water flow into tower 2. When $$$i = 2$$$, there are $$$7$$$ liters of water in tower 2 and $$$1$$$ liter of water is turned into wine. The remaining $$$6$$$ liters of water flow into tower 3. When $$$i = 3$$$, there are $$$9$$$ liters of water in tower 3 and $$$2$$$ liters of water is turned into wine. The remaining $$$7$$$ liters of water flow into tower 4. When $$$i = 4$$$, there are $$$10$$$ liters of water in tower 4. Only $$$8$$$ liters of water is turned into wine. Hence, $$$W(a,b,c)=1 + 1 + 2 + 8 = 12$$$ after the second update. The third update modifies the arrays to $$$a = [3, 5, 0, 3]$$$, $$$b = [1, 1, 0, 8]$$$, and $$$c = [10^{18}, 10^{18}, 10^{18}]$$$. When $$$i = 1$$$, there are $$$3$$$ liters of water in tower 1 and $$$1$$$ liter of water is turned into wine. The remaining $$$2$$$ liters of water flow into tower 2. When $$$i = 2$$$, there are $$$7$$$ liters of water in tower 2 and $$$1$$$ liter of water is turned into wine. The remaining $$$6$$$ liters of water flow into tower 3. When $$$i = 3$$$, there are $$$6$$$ liters of water in tower 3 and $$$0$$$ liters of water is turned into wine. The remaining $$$6$$$ liters of water flow into tower 4. When $$$i = 4$$$, there are $$$9$$$ liters of water in tower 4. Only $$$8$$$ liters of water is turned into wine. Hence, $$$W(a,b,c)=1 + 1 + 0 + 8 = 10$$$ after the third update. | 2,300 | false | true | false | false | true | false | false | false | false | false | 776 |
830E | Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way. Each element has one controller that can be set to any non-negative real value. If a controller is set on some value _x_, then the controller consumes _x_2 energy units per second. At the same time, any two elements connected by a wire produce _y_·_z_ energy units per second, where _y_ and _z_ are the values set on their controllers. Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set. It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106. Input There are several (at least one) test cases in the input. The first line contains single integerxa0— the number of test cases. There is an empty line before each test case. The first line of test case contains two integers _n_ and _m_ (1u2009≤u2009_n_u2009≤u2009105, 0u2009≤u2009_m_u2009≤u2009105)xa0— the number of elements in the scheme and the number of wires. After that, _m_ lines follow, each of them contains two integers _a_ and _b_ (1u2009≤u2009_a_,u2009_b_u2009≤u2009_n_)xa0— two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire. It is guaranteed that the sum of _n_ and the sum of _m_ over all test cases do not exceed 105. For hacks you can only use tests with one test case. Output Print answer for each test case. For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them. If it's not possible to set the controllers in the required way, print one line "NO". Example Input 44 4 1 2 2 3 3 4 4 2 3 2 2 3 3 1 4 6 1 2 3 4 4 2 1 4 1 3 3 2 10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2 Output YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1 Note In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12u2009+u200922u2009+u200922u2009+u200912u2009=u200910 energy units per second, the produced power is equal to 1·2u2009+u20092·2u2009+u20092·1u2009+u20092·1u2009=u200910 energy units per second. Thus the answer is "YES". In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second. | 3,100 | true | false | true | true | false | true | false | false | false | true | 6,443 |
678A | . Output Print the smallest integer _x_u2009>u2009_n_, so it is divisible by the number _k_. | 800 | true | false | true | false | false | false | false | false | false | false | 7,116 |
1000F | You are given an array $$$a$$$ consisting of $$$n$$$ integers, and $$$q$$$ queries to it. $$$i$$$-th query is denoted by two integers $$$l_i$$$ and $$$r_i$$$. For each query, you have to find any integer that occurs exactly once in the subarray of $$$a$$$ from index $$$l_i$$$ to index $$$r_i$$$ (a subarray is a contiguous subsegment of an array). For example, if $$$a = [1, 1, 2, 3, 2, 4]$$$, then for query $$$(l_i = 2, r_i = 6)$$$ the subarray we are interested in is $$$[1, 2, 3, 2, 4]$$$, and possible answers are $$$1$$$, $$$3$$$ and $$$4$$$; for query $$$(l_i = 1, r_i = 2)$$$ the subarray we are interested in is $$$[1, 1]$$$, and there is no such element that occurs exactly once. Can you answer all of the queries? Input The first line contains one integer $$$n$$$ ($$$1 le n le 5 cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 5 cdot 10^5$$$). The third line contains one integer $$$q$$$ ($$$1 le q le 5 cdot 10^5$$$). Then $$$q$$$ lines follow, $$$i$$$-th line containing two integers $$$l_i$$$ and $$$r_i$$$ representing $$$i$$$-th query ($$$1 le l_i le r_i le n$$$). Output Answer the queries as follows: If there is no integer such that it occurs in the subarray from index $$$l_i$$$ to index $$$r_i$$$ exactly once, print $$$0$$$. Otherwise print any such integer. | 2,400 | false | false | false | false | true | false | false | false | false | false | 5,700 |
1458D | You are given a string $$$s$$$ of 0's and 1's. You are allowed to perform the following operation: choose a non-empty contiguous substring of $$$s$$$ that contains an equal number of 0's and 1's; flip all characters in the substring, that is, replace all 0's with 1's, and vice versa; reverse the substring. For example, consider $$$s$$$ = 00111011, and the following operation: Choose the first six characters as the substring to act upon: 00111011. Note that the number of 0's and 1's are equal, so this is a legal choice. Choosing substrings 0, 110, or the entire string would not be possible. Flip all characters in the substring: 11000111. Reverse the substring: 10001111. Find the lexicographically smallest string that can be obtained from $$$s$$$ after zero or more operations. Input The first line contains a single integer $$$T$$$ ($$$1 leq T leq 5 cdot 10^5$$$)xa0— the number of test cases. Each of the following $$$T$$$ lines contains a single non-empty stringxa0— the input string $$$s$$$ for the respective test case. All strings consist of characters 0 and 1, and their total length does not exceed $$$5 cdot 10^5$$$. Output For each test case, on a separate line print the lexicographically smallest string that can be obtained from $$$s$$$ after zero or more operations. Example Input 3 100101 1100011 10101010 Output 010110 0110110 10101010 Note In the first test case a single operation should be applied to the entire string. In the second test case two operations are needed: 0111001, 0110110. In the third test case the string stays the same after any operation. | 3,100 | false | true | false | false | true | false | false | false | false | true | 3,391 |
134A | Problem - 134A - Codeforces =============== xa0 . Input The first line contains the integer _n_ (2u2009≤u2009_n_u2009≤u20092·105). The second line contains elements of the sequence _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u20091000). All the elements are positive integers. Output Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to _n_. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line. Examples Input 5 1 2 3 4 5 Output 1 3 Input 4 50 50 50 50 Output 4 1 2 3 4 | 1,200 | false | false | true | false | false | false | true | false | false | false | 9,340 |
1185G1 | The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $$$T$$$ minutes. In the player, Polycarp stores $$$n$$$ songs, each of which is characterized by two parameters: $$$t_i$$$ and $$$g_i$$$, where $$$t_i$$$ is the length of the song in minutes ($$$1 le t_i le 15$$$), $$$g_i$$$ is its genre ($$$1 le g_i le 3$$$). Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $$$i$$$-th song, he would spend exactly $$$t_i$$$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated. Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Input The first line of the input contains two integers $$$n$$$ and $$$T$$$ ($$$1 le n le 15, 1 le T le 225$$$) — the number of songs in the player and the required total duration, respectively. Next, the $$$n$$$ lines contain descriptions of songs: the $$$i$$$-th line contains two integers $$$t_i$$$ and $$$g_i$$$ ($$$1 le t_i le 15, 1 le g_i le 3$$$) — the duration of the $$$i$$$-th song and its genre, respectively. Output Output one integer — the number of different sequences of songs, the total length of exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo $$$10^9 + 7$$$ (that is, the remainder when dividing the quantity by $$$10^9 + 7$$$). Note In the first example, Polycarp can make any of the $$$6$$$ possible playlist by rearranging the available songs: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$ and $$$[3, 2, 1]$$$ (indices of the songs are given). In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of $$$2$$$ possible ways: $$$[1, 3, 2]$$$ and $$$[2, 3, 1]$$$ (indices of the songs are given). In the third example, Polycarp can make the following playlists: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$, $$$[3, 2, 1]$$$, $$$[1, 4]$$$, $$$[4, 1]$$$, $$$[2, 3, 4]$$$ and $$$[4, 3, 2]$$$ (indices of the songs are given). | 2,100 | false | false | false | true | false | false | false | false | false | false | 4,773 |
62B | Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome! The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac after you buy Tyndex.Bottles and insert in into a USB port). It is highly popular due to the well-thought interaction with the user. Let us take, for example, the system of automatic address correction. Have you entered codehorses instead of codeforces? The gloomy Zoozle Chrome will sadly say that the address does not exist. Tyndex.Brome at the same time will automatically find the closest address and sent you there. That's brilliant! How does this splendid function work? That's simple! For each potential address a function of the _F_ error is calculated by the following rules: for every letter _c__i_ from the potential address _c_ the closest position _j_ of the letter _c__i_ in the address (_s_) entered by the user is found. The absolute difference _i_u2009-u2009_j_ of these positions is added to _F_. So for every _i_ (1u2009≤u2009_i_u2009≤u2009_c_) the position _j_ is chosen such, that _c__i_u2009=u2009_s__j_, and _i_u2009-u2009_j_ is minimal possible. if no such letter _c__i_ exists in the address entered by the user, then the length of the potential address _c_ is added to _F_. After the values of the error function have been calculated for all the potential addresses the most suitable one is found. To understand the special features of the above described method better, it is recommended to realize the algorithm of calculating the _F_ function for an address given by the user and some set of potential addresses. Good luck! Input The first line contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u2009105,u20091u2009≤u2009_k_u2009≤u2009105). They are the number of potential addresses and the length of the address entered by the user. The next line contains _k_ lowercase Latin letters. They are the address entered by the user (_s_). Each next _i_-th (1u2009≤u2009_i_u2009≤u2009_n_) line contains a non-empty sequence of lowercase Latin letters. They are the potential address. It is guaranteed that the total length of all the lines does not exceed 2·105. Output On each _n_ line of the output file print a single number: the value of the error function when the current potential address is chosen. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Examples Input 2 10 codeforces codeforces codehorses Input 9 9 vkontakte vcontacte vkontrakte vkollapse vkrokodile vtopke vkapuste vpechke vk vcodeforcese | 1,800 | false | false | true | false | false | false | false | true | false | false | 9,664 |
618C | Cat Noku has obtained a map of the night sky. On this map, he found a constellation with _n_ stars numbered from 1 to _n_. For each _i_, the _i_-th star is located at coordinates (_x__i_,u2009_y__i_). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions. It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem. Input The first line of the input contains a single integer _n_ (3u2009≤u2009_n_u2009≤u2009100u2009000). Each of the next _n_ lines contains two integers _x__i_ and _y__i_ (u2009-u2009109u2009≤u2009_x__i_,u2009_y__i_u2009≤u2009109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line. Output Print three distinct integers on a single linexa0— the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them. Note In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border). | 1,600 | false | false | true | false | false | false | false | false | false | false | 7,362 |
1978A | Alice has $$$n$$$ books. The $$$1$$$-st book contains $$$a_1$$$ pages, the $$$2$$$-nd book contains $$$a_2$$$ pages, $$$ldots$$$, the $$$n$$$-th book contains $$$a_n$$$ pages. Alice does the following: She divides all the books into two non-empty piles. Thus, each book ends up in exactly one of the two piles. Alice reads one book with the highest number in each pile. Alice loves reading very much. Help her find the maximum total number of pages she can read by dividing the books into two piles. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 500$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 le n le 100$$$) — the number of books Alice has. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^9$$$) — the number of pages in each book. Output For each test case, output a single integer — the maximum number of pages Alice can read. Example Input 5 2 1 1 4 2 3 3 1 5 2 2 3 2 2 2 10 3 3 1 2 3 Note In the first test case, Alice can put book number $$$1$$$ in the first pile, and book number $$$2$$$ in the second pile. Then she will read $$$a_1 + a_2 = 1 + 1 = 2$$$ pages. In the second test case, Alice can put books with numbers $$$2$$$ and $$$3$$$ in the first pile, and books with numbers $$$1$$$ and $$$4$$$ in the second pile. Then she will read the book with the highest number $$$3$$$ from the first pile, and the book with the highest number $$$4$$$ from the second pile. Then she will read $$$a_3 + a_4 = 3 + 1 = 4$$$ pages. | 800 | false | true | false | false | false | true | false | false | true | false | 422 |
2039B | For a string $$$p$$$, let $$$f(p)$$$ be the number of distinct non-empty substrings$$$^{ ext{∗}}$$$ of $$$p$$$. Shohag has a string $$$s$$$. Help him find a non-empty string $$$p$$$ such that $$$p$$$ is a substring of $$$s$$$ and $$$f(p)$$$ is even or state that no such string exists. $$$^{ ext{∗}}$$$A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The first and only line of each test case contains a string $$$s$$$ ($$$1 le s le 10^5$$$) consisting of lowercase English letters. It is guaranteed that the sum of the length of $$$s$$$ over all test cases doesn't exceed $$$3 cdot 10^5$$$. Output For each test case, print a non-empty string that satisfies the conditions mentioned in the statement, or $$$-1$$$ if no such string exists. If there are multiple solutions, output any. Example Input 5 dcabaac a youknowwho codeforces bangladesh Output abaa -1 youknowwho eforce bang Note In the first test case, we can set $$$p = $$$ abaa because it is a substring of $$$s$$$ and the distinct non-empty substrings of $$$p$$$ are a, b, aa, ab, ba, aba, baa and abaa, so it has a total of $$$8$$$ distinct substrings which is even. In the second test case, we can only set $$$p = $$$ a but it has one distinct non-empty substring but this number is odd, so not valid. In the third test case, the whole string contains $$$52$$$ distinct non-empty substrings, so the string itself is a valid solution. | 1,000 | false | true | true | false | false | true | false | false | false | false | 23 |
1866K | There is a tree of $$$N$$$ vertices and $$$N-1$$$ edges. The $$$i$$$-th edge connects vertices $$$U_i$$$ and $$$V_i$$$ and has a length of $$$W_i$$$. Chaneka, the owner of the tree, asks you $$$Q$$$ times. For the $$$j$$$-th question, the following is the question format: $$$X_j$$$ $$$K_j$$$ – If each edge that contains vertex $$$X_j$$$ has its length multiplied by $$$K_j$$$, what is the diameter of the tree? Notes: Each of Chaneka's question is independent, which means the changes in edge length do not influence the next questions. The diameter of a tree is the maximum possible distance between two different vertices in the tree. Input The first line contains a single integer $$$N$$$ ($$$2leq Nleq10^5$$$) — the number of vertices in the tree. The $$$i$$$-th of the next $$$N-1$$$ lines contains three integers $$$U_i$$$, $$$V_i$$$, and $$$W_i$$$ ($$$1 leq U_i,V_i leq N$$$; $$$1leq W_ileq10^9$$$) — an edge that connects vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$$$. The edges form a tree. The $$$(N+1)$$$-th line contains a single integer $$$Q$$$ ($$$1leq Qleq10^5$$$) — the number of questions. The $$$j$$$-th of the next $$$Q$$$ lines contains two integers $$$X_j$$$ and $$$K_j$$$ as described ($$$1 leq X_j leq N$$$; $$$1 leq K_j leq 10^9$$$). Output Output $$$Q$$$ lines with an integer in each line. The integer in the $$$j$$$-th line represents the diameter of the tree on the $$$j$$$-th question. Examples Input 7 5 1 2 1 4 2 3 4 1 2 5 3 6 1 6 4 7 2 2 4 3 3 2 Input 3 1 2 1000000000 2 3 1000000000 1 2 1000000000 Output 2000000000000000000 Note In the first example, the following is the tree without any changes. The following is the tree on the $$$1$$$-st question. The maximum distance is between vertices $$$6$$$ and $$$7$$$, which is $$$6+6+6=18$$$, so the diameter is $$$18$$$. The following is the tree on the $$$2$$$-nd question. The maximum distance is between vertices $$$2$$$ and $$$6$$$, which is $$$3+2+6=11$$$, so the diameter is $$$11$$$. | 2,500 | false | false | true | true | true | false | false | true | false | true | 1,078 |
551E | Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called _GukiZiana_. For given array _a_, indexed with integers from 1 to _n_, and number _y_, _GukiZiana_(_a_,u2009_y_) represents maximum value of _j_u2009-u2009_i_, such that _a__j_u2009=u2009_a__i_u2009=u2009_y_. If there is no _y_ as an element in _a_, then _GukiZiana_(_a_,u2009_y_) is equal to u2009-u20091. GukiZ also prepared a problem for you. This time, you have two types of queries: 1. First type has form 1 _l_ _r_ _x_ and asks you to increase values of all _a__i_ such that _l_u2009≤u2009_i_u2009≤u2009_r_ by the non-negative integer _x_. 2. Second type has form 2 _y_ and asks you to find value of _GukiZiana_(_a_,u2009_y_). For each query of type 2, print the answer and make GukiZ happy! Input The first line contains two integers _n_, _q_ (1u2009≤u2009_n_u2009≤u20095u2009*u2009105,u20091u2009≤u2009_q_u2009≤u20095u2009*u2009104), size of array _a_, and the number of queries. The second line contains _n_ integers _a_1,u2009_a_2,u2009... _a__n_ (1u2009≤u2009_a__i_u2009≤u2009109), forming an array _a_. Each of next _q_ lines contain either four or two numbers, as described in statement: If line starts with 1, then the query looks like 1 _l_ _r_ _x_ (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_, 0u2009≤u2009_x_u2009≤u2009109), first type query. If line starts with 2, then th query looks like 2 _y_ (1u2009≤u2009_y_u2009≤u2009109), second type query. Output For each query of type 2, print the value of _GukiZiana_(_a_,u2009_y_), for _y_ value for that query. Examples Input 4 3 1 2 3 4 1 1 2 1 1 1 1 1 2 3 | 2,500 | false | false | true | false | true | false | false | true | false | false | 7,628 |
1063A | A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not. A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not. Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is $$$6$$$ because all its substrings are palindromes, and the palindromic count of the string "abc" is $$$3$$$ because only its substrings of length $$$1$$$ are palindromes. You are given a string $$$s$$$. You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count. Input The first line contains an integer $$$n$$$ ($$$1 le n le 100,000$$$)xa0— the length of string $$$s$$$. The second line contains string $$$s$$$ that consists of exactly $$$n$$$ lowercase characters of Latin alphabet. Output Print string $$$t$$$, which consists of the same set of characters (and each characters appears exactly the same number of times) as string $$$s$$$. Moreover, $$$t$$$ should have the maximum possible value of palindromic count among all such strings strings. If there are multiple such strings, print any of them. Note In the first example, string "ololo" has $$$9$$$ palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string. In the second example, the palindromic count of string "abccbaghghghgdfd" is $$$29$$$. | 1,300 | false | false | false | false | false | true | false | false | false | false | 5,396 |
1615F | After getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height $$$1$$$ and length $$$n$$$, some positions of which are occupied by $$$1$$$ by $$$1$$$ Lego pieces. In one second, you can either remove two adjacent Lego pieces from the strip (if both are present), or add two Lego pieces to adjacent positions (if both are absent). You can only add or remove Lego's at two adjacent positions at the same time, as otherwise your chubby fingers run into precision issues. You want to know exactly how much time you'll spend playing with Legos. You value efficiency, so given some starting state and some ending state, you'll always spend the least number of seconds to transform the starting state into the ending state. If it's impossible to transform the starting state into the ending state, you just skip it (so you spend $$$0$$$ seconds). The issue is that, for some positions, you don't remember whether there were Legos there or not (in either the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that are consistent with your memory, find the total amount of time it will take to transform the starting state to the ending state. Print this value modulo $$$1,000,000,007$$$ ($$$10^9 + 7$$$). Input The first line contains one integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0— the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 leq n leq 2000$$$)xa0— the size of the Lego strip. The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of the characters 0, 1, and ?xa0— your memory of the starting state: 1 represents a position that definitely has a Lego piece, 0 represents a position that definitely does not have a Lego piece, and ? represents a position that you don't remember. The third line of each test case contains a string $$$t$$$ of length $$$n$$$, consisting of the characters 0, 1, and ?xa0— your memory of the ending state. It follows a similar format to the starting state. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2000$$$. Output For each test case, output a single integerxa0— the answer to the problem modulo $$$1,000,000,007$$$ ($$$10^9 + 7$$$). Note For the first test case, $$$00$$$ is the only possible starting state, and $$$11$$$ is the only possible ending state. It takes exactly one operation to change $$$00$$$ to $$$11$$$. For the second test case, some of the possible starting and ending state pairs are: $$$(000, 011)$$$xa0— takes $$$1$$$ operation. $$$(001, 100)$$$xa0— takes $$$2$$$ operations. $$$(010, 000)$$$xa0— takes $$$0$$$ operations, as it's impossible to achieve the ending state. | 2,800 | true | false | false | true | false | false | false | false | false | false | 2,559 |
1585A | Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $$$n$$$ days from Petya's live and you have to determine what happened with his flower in the end. The flower grows as follows: If the flower isn't watered for two days in a row, it dies. If the flower is watered in the $$$i$$$-th day, it grows by $$$1$$$ centimeter. If the flower is watered in the $$$i$$$-th and in the $$$(i-1)$$$-th day ($$$i > 1$$$), then it grows by $$$5$$$ centimeters instead of $$$1$$$. If the flower is not watered in the $$$i$$$-th day, it does not grow. At the beginning of the $$$1$$$-st day the flower is $$$1$$$ centimeter tall. What is its height after $$$n$$$ days? Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 100$$$). Description of the test cases follows. The first line of each test case contains the only integer $$$n$$$ ($$$1 leq n leq 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$). If $$$a_i = 1$$$, the flower is watered in the $$$i$$$-th day, otherwise it is not watered. Output For each test case print a single integer $$$k$$$ — the flower's height after $$$n$$$ days, or $$$-1$$$, if the flower dies. Example Input 4 3 1 0 1 3 0 1 1 4 1 0 0 1 1 0 | 800 | false | false | true | false | false | false | false | false | false | false | 2,702 |
425B | Sereja has an _n_u2009×u2009_m_ rectangular table _a_, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size _h_u2009×u2009_w_, then the component must contain exactly _hw_ cells. A connected component of the same values is a set of cells of the table that meet the following conditions: every two cells of the set have the same value; the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table); it is impossible to add any cell to the set unless we violate the two previous conditions. Can Sereja change the values of at most _k_ cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case? Input The first line contains integers _n_, _m_ and _k_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100;xa01u2009≤u2009_k_u2009≤u200910). Next _n_ lines describe the table _a_: the _i_-th of them contains _m_ integers _a__i_1,u2009_a__i_2,u2009...,u2009_a__im_ (0u2009≤u2009_a__i_,u2009_j_u2009≤u20091) — the values in the cells of the _i_-th row. Output Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed. Examples Input 5 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Input 3 4 1 1 0 0 0 0 1 1 1 1 1 1 0 Input 3 4 1 1 0 0 1 0 1 1 0 1 0 0 1 | 2,200 | false | true | false | false | false | false | false | false | false | false | 8,137 |
1618E | $$$n$$$ towns are arranged in a circle sequentially. The towns are numbered from $$$1$$$ to $$$n$$$ in clockwise order. In the $$$i$$$-th town, there lives a singer with a repertoire of $$$a_i$$$ minutes for each $$$i in [1, n]$$$. Each singer visited all $$$n$$$ towns in clockwise order, starting with the town he lives in, and gave exactly one concert in each town. In addition, in each town, the $$$i$$$-th singer got inspired and came up with a song that lasts $$$a_i$$$ minutes. The song was added to his repertoire so that he could perform it in the rest of the cities. Hence, for the $$$i$$$-th singer, the concert in the $$$i$$$-th town will last $$$a_i$$$ minutes, in the $$$(i + 1)$$$-th town the concert will last $$$2 cdot a_i$$$ minutes, ..., in the $$$((i + k) bmod n + 1)$$$-th town the duration of the concert will be $$$(k + 2) cdot a_i$$$, ..., in the town $$$((i + n - 2) bmod n + 1)$$$ — $$$n cdot a_i$$$ minutes. You are given an array of $$$b$$$ integer numbers, where $$$b_i$$$ is the total duration of concerts in the $$$i$$$-th town. Reconstruct any correct sequence of positive integers $$$a$$$ or say that it is impossible. Input The first line contains one integer $$$t$$$ $$$(1 le t le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 le n le 4 cdot 10^4$$$) — the number of cities. The second line contains $$$n$$$ integers $$$b_1, b_2, dots, b_n$$$ ($$$1 le b_i le 10^{9}$$$) — the total duration of concerts in $$$i$$$-th city. The sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, print the answer as follows: If there is no suitable sequence $$$a$$$, print NO. Otherwise, on the first line print YES, on the next line print the sequence $$$a_1, a_2, dots, a_n$$$ of $$$n$$$ integers, where $$$a_i$$$ ($$$1 le a_i le 10^{9}$$$) is the initial duration of repertoire of the $$$i$$$-th singer. If there are multiple answers, print any of them. | 1,700 | true | false | false | false | false | true | false | false | false | false | 2,538 |
269B | Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated _n_ plants in his greenhouse, of _m_ different plant species numbered from 1 to _m_. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line. Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange _m_u2009-u20091 borders that would divide the greenhouse into _m_ sections numbered from 1 to _m_ from left to right with each section housing a single species. He is free to place the borders, but in the end all of the _i_-th species plants must reside in _i_-th section from the left. Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. Input The first line of input contains two space-separated integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u20095000, _n_u2009≥u2009_m_), the number of plants and the number of different species. Each of the following _n_ lines contain two space-separated numbers: one integer number _s__i_ (1u2009≤u2009_s__i_u2009≤u2009_m_), and one real number _x__i_ (0u2009≤u2009_x__i_u2009≤u2009109), the species and position of the _i_-th plant. Each _x__i_ will contain no more than 6 digits after the decimal point. It is guaranteed that all _x__i_ are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their _x__i_ coordinates (_x__i_u2009<u2009_x__i_u2009+u20091,u20091u2009≤u2009_i_u2009<u2009_n_). Output Output a single integer — the minimum number of plants to be replanted. Examples Input 6 3 1 14.284235 2 17.921382 1 20.328172 3 20.842331 1 25.790145 1 27.204125 Note In the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1. In the second test case, the species are already in the correct order, so no replanting is needed. | 1,700 | false | false | false | true | false | false | false | false | false | false | 8,757 |
2036G | This is an interactive problem. The Department of Supernatural Phenomena at the Oxenfurt Academy has opened the Library of Magic, which contains the works of the greatest sorcerers of Redania — $$$n$$$ ($$$3 leq n leq 10^{18}$$$) types of books, numbered from $$$1$$$ to $$$n$$$. Each book's type number is indicated on its spine. Moreover, each type of book is stored in the library in exactly two copies! And you have been appointed as the librarian. One night, you wake up to a strange noise and see a creature leaving the building through a window. Three thick tomes of different colors were sticking out of the mysterious thief's backpack. Before you start searching for them, you decide to compute the numbers $$$a$$$, $$$b$$$, and $$$c$$$ written on the spines of these books. All three numbers are distinct. So, you have an unordered set of tomes, which includes one tome with each of the pairwise distinct numbers $$$a$$$, $$$b$$$, and $$$c$$$, and two tomes for all numbers from $$$1$$$ to $$$n$$$, except for $$$a$$$, $$$b$$$, and $$$c$$$. You want to find these values $$$a$$$, $$$b$$$, and $$$c$$$. Since you are not working in a simple library, but in the Library of Magic, you can only use one spell in the form of a query to check the presence of books in their place: "xor l r" — Bitwise XOR query with parameters $$$l$$$ and $$$r$$$. Let $$$k$$$ be the number of such tomes in the library whose numbers are greater than or equal to $$$l$$$ and less than or equal to $$$r$$$. You will receive the result of the computation $$$v_1 oplus v_2 oplus ... oplus v_k$$$, where $$$v_1 ... v_k$$$ are the numbers on the spines of these tomes, and $$$oplus$$$ denotes the operation of — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$3 leq n leq 10^{18}$$$) — the number of types of tomes. Interaction The interaction for each test case begins with reading the integer $$$n$$$. Then you can make up to $$$150$$$ queries. To make a query, output a string in the format "xor l r" (without quotes) ($$$1 leq l leq r leq n$$$). After each query, read an integer — the answer to your query. To report the answer, output a string in the format "ans a b c" (without quotes), where $$$a$$$, $$$b$$$, and $$$c$$$ are the numbers you found as the answer to the problem. You can output them in any order. The interactor is not adaptive, which means that the answer is known before the participant makes queries and does not depend on the queries made by the participant. After making $$$150$$$ queries, the answer to any other query will be $$$-1$$$. Upon receiving such an answer, terminate the program to receive a verdict of "WA" (Wrong answer). After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of "IL" (Idleness limit exceeded). To flush the buffer, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; refer to the documentation for other languages. Hacks To make a hack, use the following format. The first line should contain a single integer $$$t$$$ ($$$1 leq t leq 300$$$) — the number of test cases. The only line of each test case should contain four integers $$$n$$$, $$$a$$$, $$$b$$$, and $$$c$$$ ($$$3 leq n leq 10^{18}$$$, $$$1 le a, b, c le n$$$) — the number of books in the library and the numbers of the stolen tomes. The numbers $$$a$$$, $$$b$$$, and $$$c$$$ must be distinct. Example Output xor 1 1 xor 2 2 xor 3 3 xor 4 6 ans 2 3 5 ans 1 2 3 Note In the first test case, the books in the library after the theft look like this: Now consider the answers to the queries: For the query "xor 1 1", you receive the result $$$1 oplus 1 = 0$$$. Two tomes satisfy the condition specified in the query — both with the number $$$1$$$. For the query "xor 2 2", you receive the result $$$2$$$, as only one tome satisfies the specified condition. For the query "xor 3 3", you receive the result $$$3$$$. For the query "xor 4 6", you receive the result $$$4 oplus 6 oplus 4 oplus 5 oplus 6 = 5$$$. In the second test case, there are only $$$3$$$ types of books, and it is easy to guess that the missing ones have the numbers $$$1$$$, $$$2$$$, and $$$3$$$. | 2,200 | true | false | false | false | false | true | false | true | false | false | 46 |
1528C | Soroush and Keshi each have a labeled and rooted tree on $$$n$$$ vertices. Both of their trees are rooted from vertex $$$1$$$. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph on $$$n$$$ vertices. They add an edge between vertices $$$u$$$ and $$$v$$$ in the memorial graph if both of the following conditions hold: One of $$$u$$$ or $$$v$$$ is the ancestor of the other in Soroush's tree. Neither of $$$u$$$ or $$$v$$$ is the ancestor of the other in Keshi's tree. Here vertex $$$u$$$ is considered ancestor of vertex $$$v$$$, if $$$u$$$ lies on the path from $$$1$$$ (the root) to the $$$v$$$. Popping out of nowhere, Mashtali tried to find the maximum clique in the memorial graph for no reason. He failed because the graph was too big. Help Mashtali by finding the size of the maximum clique in the memorial graph. As a reminder, clique is a subset of vertices of the graph, each two of which are connected by an edge. Input The first line contains an integer $$$t$$$ $$$(1le tle 3 cdot 10^5)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(2le nle 3 cdot 10^5)$$$. The second line of each test case contains $$$n-1$$$ integers $$$a_2, ldots, a_n$$$ $$$(1 le a_i < i)$$$, $$$a_i$$$ being the parent of the vertex $$$i$$$ in Soroush's tree. The third line of each test case contains $$$n-1$$$ integers $$$b_2, ldots, b_n$$$ $$$(1 le b_i < i)$$$, $$$b_i$$$ being the parent of the vertex $$$i$$$ in Keshi's tree. It is guaranteed that the given graphs are trees. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 cdot 10^5$$$. Output For each test case print a single integer — the size of the maximum clique in the memorial graph. Example Input 4 4 1 2 3 1 2 3 5 1 2 3 4 1 1 1 1 6 1 1 1 1 2 1 2 1 2 2 7 1 1 3 4 4 5 1 2 1 4 2 5 Note In the first and third test cases, you can pick any vertex. In the second test case, one of the maximum cliques is $$${2, 3, 4, 5}$$$. In the fourth test case, one of the maximum cliques is $$${3, 4, 6}$$$. | 2,300 | false | true | false | false | true | false | false | false | false | false | 3,021 |
846C | Problem - 846C - Codeforces =============== xa0 be the sum of all numbers on positions from _l_ to _r_ non-inclusive (_l_-th element is counted, _r_-th element is not counted). For indices _l_ and _r_ holds 0u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_. Indices in array are numbered from 0. For example, if _a_u2009=u2009 | 1,800 | false | false | false | true | true | false | true | false | false | false | 6,375 |
1418F | Problem - 1418F - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags data structures math number theory two pointers *3000 No tag edit access → Contest materials ") $$$ as good if: 1. $$$1 le x_1 < x_2 le n$$$; 2. $$$1 le y_2 < y_1 le m$$$; 3. $$$x_1 cdot y_1 = x_2 cdot y_2$$$; 4. $$$l le x_1 cdot y_1 le r$$$. Find any good tuple for each $$$x_1$$$ from $$$1$$$ to $$$n$$$ inclusive. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 2 cdot 10^5$$$). The second line contains two integers $$$l$$$ and $$$r$$$ ($$$1 le l le r le nm$$$). Output For each $$$x_1$$$ from $$$1$$$ to $$$n$$$ inclusive: if there are no such four integers, print $$$-1$$$; otherwise, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$. If there are multiple answers, print any of them. Examples Input 8 20 91 100 Output -1 -1 -1 -1 -1 6 16 8 12 -1 -1 Input 4 5 1 10 Output 1 2 2 1 2 3 3 2 -1 -1 Input 5 12 16 60 Output -1 2 9 3 6 3 8 4 6 4 5 5 4 -1 | 3,000 | true | false | false | false | true | false | false | false | false | false | 3,589 |
1491A | You are given an array $$$a$$$ consisting of $$$n$$$ integers. Initially all elements of $$$a$$$ are either $$$0$$$ or $$$1$$$. You need to process $$$q$$$ queries of two kinds: 1 x : Assign to $$$a_x$$$ the value $$$1 - a_x$$$. 2 k : Print the $$$k$$$-th largest value of the array. As a reminder, $$$k$$$-th largest value of the array $$$b$$$ is defined as following: Sort the array in the non-increasing order, return $$$k$$$-th element from it. For example, the second largest element in array $$$[0, 1, 0, 1]$$$ is $$$1$$$, as after sorting in non-increasing order it becomes $$$[1, 1, 0, 0]$$$, and the second element in this array is equal to $$$1$$$. Input The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 le n, q le 10^5$$$) — the length of the given array and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, a_3, dots, a_n$$$ ($$$0 le a_i le 1$$$) — elements of the initial array. Each of the following $$$q$$$ lines contains two integers. The first integer is $$$t$$$ ($$$1 le t le 2$$$) — the type of query. If $$$t = 1$$$ the second integer is $$$x$$$ ($$$1 le x le n$$$) — the position of the modified number. You have to assign to $$$a_x$$$ the value $$$1 - a_x$$$. If $$$t = 2$$$ the second integer is $$$k$$$ ($$$1 le k le n$$$) — you need to print the $$$k$$$-th largest value of the array. It's guaranteed that there will be at least one query of the second type (satisfying $$$t = 2$$$). Output For each query of the second type, print a single integer — the answer to the query. Example Input 5 5 1 1 0 1 0 2 3 1 2 2 3 2 1 2 5 Note Initially $$$a = [1, 1, 0, 1, 0]$$$. The first operation is printing the third largest value, which is $$$1$$$. The second operation is assigning $$$a_2$$$ the value $$$0$$$, $$$a$$$ becomes $$$[1, 0, 0, 1, 0]$$$. The third operation is printing the third largest value, it is $$$0$$$. The fourth operation is printing the first largest value, it is $$$1$$$. The last operation is printing the fifth largest value, it is $$$0$$$. | 800 | false | true | true | false | false | false | true | false | false | false | 3,222 |
1419E | An agent called Cypher is decrypting a message, that contains a $$$xa0— the number of test cases. Next $$$t$$$ lines describe each test case. In a single line of each test case description, there is a single composite number $$$n$$$ $$$(4 le n le 10^9)$$$xa0— the number from the message. It's guaranteed that the total number of divisors of $$$n$$$ for all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case in the first line output the initial order of divisors, which are greater than $$$1$$$, in the circle. In the second line output, the minimal number of moves needed to decrypt the message. If there are different possible orders with a correct answer, print any of them. Example Output 2 3 6 1 2 4 0 2 30 6 3 15 5 10 0 Note In the first test case $$$6$$$ has three divisors, which are greater than $$$1$$$: $$$2, 3, 6$$$. Regardless of the initial order, numbers $$$2$$$ and $$$3$$$ are adjacent, so it's needed to place their least common multiple between them. After that the circle becomes $$$2, 6, 3, 6$$$, and every two adjacent numbers are not coprime. In the second test case $$$4$$$ has two divisors greater than $$$1$$$: $$$2, 4$$$, and they are not coprime, so any initial order is correct, and it's not needed to place any least common multiples. In the third test case all divisors of $$$30$$$ greater than $$$1$$$ can be placed in some order so that there are no two adjacent numbers that are coprime. | 2,100 | true | false | true | false | false | true | false | false | false | false | 3,582 |
1194G | Problem - 1194G - 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 dp *2700 No tag edit access → Contest materials . Output Print the number of good fractions $$$frac{x}{y}$$$ such that $$$1 le x le n$$$ and $$$1 le y le n$$$. The answer may be really large, so print it modulo $$$998244353$$$. Examples Input 42 Output 150 Input 3141592653589793238462643383279 Output 459925407 | 2,700 | false | false | false | true | false | false | false | false | false | false | 4,730 |
999C | You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Polycarp wants to remove exactly $$$k$$$ characters ($$$k le n$$$) from the string $$$s$$$. Polycarp uses the following algorithm $$$k$$$ times: if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; ... remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $$$k$$$ times, thus removing exactly $$$k$$$ characters. Help Polycarp find the resulting string. Input The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k le n le 4 cdot 10^5$$$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Output Print the string that will be obtained from $$$s$$$ after Polycarp removes exactly $$$k$$$ letters using the above algorithm $$$k$$$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | 1,200 | false | false | true | false | false | false | false | false | false | false | 5,709 |
2039H2 | This is the hard version of the problem. The only difference is the maximum number of operations you can perform. You can only make hacks if both versions are solved. You are given an array $$$a$$$ of size $$$n$$$. A cool swap walk is the following process: In an $$$n imes n$$$ grid, we note the cells in row $$$i$$$ and column $$$j$$$ as $$$(i, j)$$$. You need to walk from $$$(1,1)$$$ to $$$(n,n)$$$, taking only steps to the right or down. Formally, if you are in $$$(x,y)$$$ currently, you can step to either $$$(x+1,y)$$$ or $$$(x,y+1)$$$, but you can not step beyond the boundaries of the grid. When you step in $$$(i,j)$$$, you must swap $$$a_i$$$ and $$$a_j$$$ when $$$i eq j$$$. You can perform at most $$$n+4$$$ cool swap walks. Sort the array $$$a_1, a_2, ldots, a_n$$$ in non-decreasing order. We can show that it's always possible to do so. 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 an integer $$$n$$$ ($$$2 leq n leq 500$$$)xa0— the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,ldots ,a_n$$$ ($$$1 le a_i le n$$$)xa0— the elements of the array. It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$2.5 cdot 10^5$$$. Output For each test case, your output should consist of several lines: The first line contains an integer $$$k$$$ ($$$0 leq k leq n+4$$$), representing the number of cool swap walks you perform. Each of the next $$$k$$$ lines contains a string $$$s$$$ of length $$$2n-2$$$ consisting only of R and D, representing the path (letters are case sensitive). For all $$$1 le i le 2n-2$$$, if $$$s_i=$$$ R, you walk right in the $$$i$$$-th step, otherwise you walk down in the $$$i$$$-th step. Example Output 0 2 RRDD DRDR 3 RRDRDD DRDDRR DDRRRD Note In the first test case, the array $$$a$$$ is already non-decreasing, so you don't need to perform any walk. In the second test case, $$$a=[2,1,3]$$$ initially. In the first walk: In the $$$1$$$-st step, you step right to $$$(1,2)$$$. Then, $$$a=[1,2,3]$$$. Note that although the array $$$a$$$ is already non-decreasing, you can not stop until you reach $$$(n,n)$$$. In the $$$2$$$-nd step, you step right to $$$(1,3)$$$. Then, $$$a=[3,2,1]$$$. In the $$$3$$$-rd step, you step down to $$$(2,3)$$$. Then, $$$a=[3,1,2]$$$. In the $$$4$$$-th step, you step down to $$$(3,3)$$$. Then, $$$a=[3,1,2]$$$. In the second walk: In the $$$1$$$-st step, you step down to $$$(2,1)$$$. Then, $$$a=[1,3,2]$$$. In the $$$2$$$-nd step, you step right to $$$(2,2)$$$. Then, $$$a=[1,3,2]$$$. In the $$$3$$$-rd step, you step down to $$$(3,2)$$$. Then, $$$a=[1,2,3]$$$. In the $$$4$$$-th step, you step down to $$$(3,3)$$$. Then, $$$a=[1,2,3]$$$. After the two cool swap walks above, we get $$$a=[1,2,3]$$$, which is non-decreasing. | 3,500 | false | false | true | false | false | true | false | false | true | false | 14 |
1110B | You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, ldots, s+t-1$$$. You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap. Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces? Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 le n le 10^5$$$, $$$n le m le 10^9$$$, $$$1 le k le n$$$)xa0— the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, ldots, b_n$$$ ($$$1 le b_i le m$$$)xa0— the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 < b_2 < ldots < b_n$$$. Output Print the minimum total length of the pieces. Note In the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$. In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$. | 1,400 | false | true | false | false | false | false | false | false | true | false | 5,148 |
1839E | This is an interactive problem. Consider the following game for two players: Initially, an array of integers $$$a_1, a_2, ldots, a_n$$$ of length $$$n$$$ is written on blackboard. Game consists of rounds. On each round, the following happens: The first player selects any $$$i$$$ such that $$$a_i gt 0$$$. If there is no such $$$i$$$, the first player loses the game (the second player wins) and game ends. The second player selects any $$$j eq i$$$ such that $$$a_j gt 0$$$. If there is no such $$$j$$$, the second player loses the game (the first player wins) and game ends. Let $$$d = min(a_i, a_j)$$$. The values of $$$a_i$$$ and $$$a_j$$$ are simultaneously decreased by $$$d$$$ and the next round starts. It can be shown that game always ends after the finite number of rounds. You have to select which player you will play for (first or second) and win the game. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 300$$$)xa0— the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 300$$$)xa0— array $$$a$$$. Interaction Interaction begins after reading $$$n$$$ and array $$$a$$$. You should start interaction by printing a single line, containing either "First" or "Second", representing the player you select. On each round, the following happens: If you are playing as the first player, you should print a single integer $$$i$$$ ($$$1 le i le n$$$) on a separate line. After that, you should read a single integer $$$j$$$ ($$$-1 le j le n$$$) written on a separate line.If $$$j = -1$$$, then you made an incorrect move. In this case your program should terminate immediately. If $$$j = 0$$$, then the second player can't make a correct move and you win the game. In this case your program should also terminate immediately. Otherwise $$$j$$$ is equal to the index chosen by the second player, and you should proceed to the next round. If you are playing as the second player, you should read a single integer $$$i$$$ ($$$-1 le i le n$$$) written on a separate line.If $$$i = -1$$$, then you made an incorrect move on the previous round (this cannot happen on the first round). In that case your program should terminate immediately. If $$$i = 0$$$, then the first player can't make a correct move and you win the game. In this case your program should also terminate immediately. Otherwise $$$i$$$ is equal to the index chosen by first player. In this case you should write single integer $$$j$$$ ($$$1 le j le n$$$) on a separate line and proceed to the next round. After printing $$$i$$$ or $$$j$$$, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see the documentation for other languages. Hacks Hacks are disabled in this problem. Examples Input 6 4 5 5 11 3 2 2 5 4 6 1 0 Note In the first example $$$n = 4$$$ and array $$$a$$$ is $$$[, 10, 4, 6, 3 ,]$$$. The game goes as follows: After reading array $$$a$$$ contestant's program chooses to play as the first player and prints "First". First round: the first player chooses $$$i = 1$$$, the second player chooses $$$j = 3$$$. $$$d = min(a_1, a_3) = min(10, 6) = 6$$$ is calculated. Elements $$$a_1$$$ and $$$a_3$$$ are decreased by $$$6$$$. Array $$$a$$$ becomes equal to $$$[, 4, 4, 0, 3 ,]$$$. Second round: the first player chooses $$$i = 2$$$, the second player chooses $$$j = 1$$$. $$$d = min(a_2, a_1) = min(4, 4) = 4$$$ is calculated. Elements $$$a_2$$$ and $$$a_1$$$ are decreased by $$$4$$$. Array $$$a$$$ becomes equal to $$$[, 0, 0, 0, 3 ,]$$$. Third round: the first player chooses $$$i = 4$$$. There is no $$$j eq 4$$$ such that $$$a_j > 0$$$, so the second player can't make a correct move and the first player wins. Jury's program prints $$$j = 0$$$. After reading it, contestant's program terminates. In the second example $$$n = 6$$$ and array $$$a$$$ is $$$[, 4, 5, 5, 11, 3, 2 ,]$$$. The game goes as follows: Contestant's program chooses to play as the second player and prints "Second". First round: $$$i = 2$$$, $$$j = 4$$$, $$$a = [, 4, 0, 5, 6, 3, 2 ,]$$$. Second round: $$$i = 5$$$, $$$j = 4$$$, $$$a = [, 4, 0, 5, 3, 0, 2 ,]$$$. Third round: $$$i = 4$$$, $$$j = 3$$$, $$$a = [, 4, 0, 2, 0, 0, 2 ,]$$$. Fourth round: $$$i = 6$$$, $$$j = 1$$$, $$$a = [, 2, 0, 2, 0, 0, 0 ,]$$$. Fifth round: $$$i = 1$$$, $$$j = 3$$$, $$$a = [, 0, 0, 0, 0, 0, 0 ,]$$$. Sixth round: the first player can't make a correct move and the second player wins. Jury's program prints $$$i = 0$$$. After reading it, contestant's program terminates. Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well. | 2,400 | false | true | false | true | false | true | false | false | false | false | 1,254 |
616B | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of _n_ streets and _m_ avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to _n_ and the avenues are numbered with integers from 1 to _m_. The cost of dinner in the restaurant at the intersection of the _i_-th street and the _j_-th avenue is _c__ij_. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. Input The first line contains two integers _n_,u2009_m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100) — the number of streets and avenues in Munhattan. Each of the next _n_ lines contains _m_ integers _c__ij_ (1u2009≤u2009_c__ij_u2009≤u2009109) — the cost of the dinner in the restaurant on the intersection of the _i_-th street and the _j_-th avenue. Output Print the only integer _a_ — the cost of the dinner for Jack and Emma. Examples Input 3 4 4 1 3 5 2 2 2 2 5 4 5 1 Note In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | 1,000 | false | true | false | false | false | false | false | false | false | false | 7,374 |
1704D | Eric has an array $$$b$$$ of length $$$m$$$, then he generates $$$n$$$ additional arrays $$$c_1, c_2, dots, c_n$$$, each of length $$$m$$$, from the array $$$b$$$, by the following way: Initially, $$$c_i = b$$$ for every $$$1 le i le n$$$. Eric secretly chooses an integer $$$k$$$ $$$(1 le k le n)$$$ and chooses $$$c_k$$$ to be the special array. There are two operations that Eric can perform on an array $$$c_t$$$: Operation 1: Choose two integers $$$i$$$ and $$$j$$$ ($$$2 leq i < j leq m-1$$$), subtract $$$1$$$ from both $$$c_t[i]$$$ and $$$c_t[j]$$$, and add $$$1$$$ to both $$$c_t[i-1]$$$ and $$$c_t[j+1]$$$. That operation can only be used on a non-special array, that is when $$$t eq k$$$.; Operation 2: Choose two integers $$$i$$$ and $$$j$$$ ($$$2 leq i < j leq m-2$$$), subtract $$$1$$$ from both $$$c_t[i]$$$ and $$$c_t[j]$$$, and add $$$1$$$ to both $$$c_t[i-1]$$$ and $$$c_t[j+2]$$$. That operation can only be used on a special array, that is when $$$t = k$$$.Note that Eric can't perform an operation if any element of the array will become less than $$$0$$$ after that operation. Now, Eric does the following: For every non-special array $$$c_i$$$ ($$$i eq k$$$), Eric uses only operation 1 on it at least once. For the special array $$$c_k$$$, Eric uses only operation 2 on it at least once. Lastly, Eric discards the array $$$b$$$. For given arrays $$$c_1, c_2, dots, c_n$$$, your task is to find out the special array, i.e. the value $$$k$$$. Also, you need to find the number of times of operation $$$2$$$ was used on it. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. Description of test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$3 leq n leq 10^5$$$, $$$7 leq m leq 3 cdot 10^5$$$) — the number of arrays given to you, and the length of each array. The next $$$n$$$ lines contains $$$m$$$ integers each, $$$c_{i,1}, c_{i,2}, dots , c_{i,m}$$$. It is guaranteed that each element of the discarded array $$$b$$$ is in the range $$$[0,10^6]$$$, and therefore $$$0 leq c_{i,j} leq 3 cdot 10^{11}$$$ for all possible pairs of $$$(i,j)$$$. It is guaranteed that the sum of $$$n cdot m$$$ over all test cases does not exceed $$$10^6$$$. It is guaranteed that the input is generated according to the procedure above. Output For each test case, output one line containing two integers — the index of the special array, and the number of times that Operation 2 was performed on it. It can be shown that under the constraints given in the problem, this value is unique and won't exceed $$$10^{18}$$$, so you can represent it as a $$$64$$$-bit integer. It can also be shown that the index of the special array is uniquely determined. In this problem, hacks are disabled. Example Input 7 3 9 0 1 2 0 0 2 1 1 0 0 1 1 1 2 0 0 2 0 0 1 2 0 0 1 2 1 0 3 7 25 15 20 15 25 20 20 26 14 20 14 26 20 20 25 15 20 15 20 20 25 3 9 25 15 20 15 25 20 20 20 20 26 14 20 14 26 20 20 20 20 25 15 20 15 25 15 20 20 25 3 11 25 15 20 15 25 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 25 15 20 15 25 20 15 20 20 20 25 3 13 25 15 20 15 25 20 20 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 20 20 25 15 20 15 25 20 20 15 20 20 20 20 25 3 15 25 15 20 15 25 20 20 20 20 20 20 20 20 20 20 26 14 20 14 26 20 20 20 20 20 20 20 20 20 20 25 15 20 15 25 20 20 20 15 20 20 20 20 20 25 3 9 909459 479492 676924 224197 162866 164495 193268 742456 728277 948845 455424 731850 327890 304150 237351 251763 225845 798316 975446 401170 792914 272263 300770 242037 236619 334316 725899 Output 3 1 3 10 3 15 3 20 3 25 3 30 1 1378716 Note In the first test case, the secret array $$$b$$$ is $$$[0, 1, 1, 1, 1, 1, 1, 1, 0]$$$. Array $$$c_1$$$ and array $$$c_2$$$ are generated by using operation 1. Array $$$c_3$$$ is generated by using operation 2. For Array $$$c_1$$$,you can choose $$$i=4$$$ and $$$j=5$$$ perform Operation 1 one time to generate it. For Array $$$c_2$$$, you can choose $$$i=6$$$ and $$$j=7$$$ perform Operation 1 one time to generate it. For Array $$$c_3$$$,you can choose $$$i=4$$$ and $$$j=5$$$ perform Operation 2 one time to generate it. In the second test case, the secret array $$$b$$$ is $$$[20, 20, 20, 20, 20, 20, 20]$$$. You can also find that array $$$c_1$$$ and array $$$c_2$$$ are generated by using Operation 1. Array $$$c_3$$$ is generated by using Operation 2. In the third test case, the secret array $$$b$$$ is $$$[20, 20, 20, 20, 20, 20, 20, 20, 20]$$$. You can also find that array $$$c_1$$$ and array $$$c_2$$$ are generated by using Operation 1. Array $$$c_3$$$ is generated by using Operation 2. | 1,900 | true | false | true | false | false | true | false | false | false | false | 2,052 |
1599J | Bob really likes playing with arrays of numbers. That's why for his birthday, his friends bought him a really interesting machine – an array beautifier. The array beautifier takes an array $$$A$$$ consisting of $$$N$$$ integers, and it outputs a new array $$$B$$$ of length N that it constructed based on the array given to it. The array beautifier constructs the new array in the following way: it takes two numbers at different indices from the original array and writes their sum to the end of the new array. It does this step $$$N$$$ times - resulting in an output array of length $$$N$$$. During this process, the machine can take the same index multiple times in different steps. Bob was very excited about the gift that his friends gave him, so he put his favorite array in the machine. However, when the machine finished, Bob was not happy with the resulting array. He misses his favorite array very much, and hopes to get it back. Given the array that the machine outputted, help Bob find an array that could be the original array that he put in the machine. Sometimes the machine makes mistakes, so it is possible that no appropriate input array exists for the array it has outputted. In such case, let Bob know that his array is forever lost. Input The first line contains one positive integer $$$N$$$ ($$$2 leq N leq 10^3$$$) – the length of Bob's array. The second line contains $$$N$$$ integers $$$B_1$$$, $$$B_2$$$, ..., $$$B_N$$$ ($$$1 leq B_i leq 10^6$$$) – the elements of the array the machine outputted. Output If an appropriate input array exists, print "YES", followed by the input array $$$A_1$$$, $$$A_2$$$, ..., $$$A_N$$$ ($$$-10^9 leq A_i leq 10^9$$$) in the next line. Otherwise, print "NO". | 2,600 | false | true | false | false | false | false | true | false | false | false | 2,655 |
136B | Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the _xor_ operation is performed on this computer (and whether there is anything like it). It turned out that the operation does exist (however, it is called _tor_) and it works like this. Suppose that we need to calculate the value of the expression _a_ _tor_ _b_. Both numbers _a_ and _b_ are written in the ternary notation one under the other one (_b_ under _a_). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 _tor_ 5010u2009=u200901123 _tor_ 12123u2009=u200910213u2009=u20093410. Petya wrote numbers _a_ and _c_ on a piece of paper. Help him find such number _b_, that _a_ _tor_ _b_u2009=u2009_c_. If there are several such numbers, print the smallest one. Input The first line contains two integers _a_ and _c_ (0u2009≤u2009_a_,u2009_c_u2009≤u2009109). Both numbers are written in decimal notation. Output Print the single integer _b_, such that _a_ _tor_ _b_u2009=u2009_c_. If there are several possible numbers _b_, print the smallest one. You should print the number in decimal notation. | 1,100 | true | false | true | false | false | false | false | false | false | false | 9,331 |
1521A | Nastia has $$$2$$$ positive integers $$$A$$$ and $$$B$$$. She defines that: The integer is good if it is divisible by $$$A cdot B$$$; Otherwise, the integer is nearly good, if it is divisible by $$$A$$$. For example, if $$$A = 6$$$ and $$$B = 4$$$, the integers $$$24$$$ and $$$72$$$ are good, the integers $$$6$$$, $$$660$$$ and $$$12$$$ are nearly good, the integers $$$16$$$, $$$7$$$ are neither good nor nearly good. Find $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10,000$$$)xa0— the number of test cases. The first line of each test case contains two integers $$$A$$$ and $$$B$$$ ($$$1 le A le 10^6$$$, $$$1 le B le 10^6$$$)xa0— numbers that Nastia has. Output For each test case print: "YES" and $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 le x, y, z le 10^{18}$$$) such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$. "NO" if no answer exists. You can print each character of "YES" or "NO" in any case. If there are multiple answers, print any. Example Output YES 10 50 60 YES 169 39 208 YES 28 154 182 Note In the first test case: $$$60$$$xa0— good number; $$$10$$$ and $$$50$$$xa0— nearly good numbers. In the second test case: $$$208$$$xa0— good number; $$$169$$$ and $$$39$$$xa0— nearly good numbers. In the third test case: $$$154$$$xa0— good number; $$$28$$$ and $$$182$$$xa0— nearly good numbers. | 1,000 | true | false | false | false | false | true | false | false | false | false | 3,055 |
37C | Problem - 37C - Codeforces =============== xa0 ") — the number of words in Old Berland language. The second line contains _N_ space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next _N_ lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Examples Input 3 1 2 3 Output YES 0 10 110 Input 3 1 1 1 Output NO | 1,900 | false | true | false | false | true | false | false | false | false | false | 9,811 |
1313C2 | This is a harder version of the problem. In this version $$$n le 500,000$$$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought $$$n$$$ plots along the highway and is preparing to build $$$n$$$ skyscrapers, one skyscraper per plot. Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it. Formally, let's number the plots from $$$1$$$ to $$$n$$$. Then if the skyscraper on the $$$i$$$-th plot has $$$a_i$$$ floors, it must hold that $$$a_i$$$ is at most $$$m_i$$$ ($$$1 le a_i le m_i$$$). Also there mustn't be integers $$$j$$$ and $$$k$$$ such that $$$j < i < k$$$ and $$$a_j > a_i < a_k$$$. Plots $$$j$$$ and $$$k$$$ are not required to be adjacent to $$$i$$$. The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors. Input The first line contains a single integer $$$n$$$ ($$$1 leq n leq 500,000$$$)xa0— the number of plots. The second line contains the integers $$$m_1, m_2, ldots, m_n$$$ ($$$1 leq m_i leq 10^9$$$)xa0— the limit on the number of floors for every possible number of floors for a skyscraper on each plot. Output Print $$$n$$$ integers $$$a_i$$$xa0— the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible. If there are multiple answers possible, print any of them. Note In the first example, you can build all skyscrapers with the highest possible height. In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer $$$[10, 6, 6]$$$ is optimal. Note that the answer of $$$[6, 6, 8]$$$ also satisfies all restrictions, but is not optimal. | 1,900 | false | true | false | true | true | false | false | false | false | false | 4,127 |
757B | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of _k_u2009>u20091 Pokemon with strengths {_s_1,u2009_s_2,u2009_s_3,u2009...,u2009_s__k_} tend to fight among each other if _gcd_(_s_1,u2009_s_2,u2009_s_3,u2009...,u2009_s__k_)u2009=u20091 (see notes for _gcd_ definition). Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take? Note: A Pokemon cannot fight with itself. Input The input consists of two lines. The first line contains an integer _n_ (1u2009≤u2009_n_u2009≤u2009105), the number of Pokemon in the lab. The next line contains _n_ space separated integers, where the _i_-th of them denotes _s__i_ (1u2009≤u2009_s__i_u2009≤u2009105), the strength of the _i_-th Pokemon. Output Print single integerxa0— the maximum number of Pokemons Bash can take. Note _gcd_ (greatest common divisor) of positive integers set {_a_1,u2009_a_2,u2009...,u2009_a__n_} is the maximum positive integer that divides all the integers {_a_1,u2009_a_2,u2009...,u2009_a__n_}. In the first sample, we can take Pokemons with strengths {2,u20094} since _gcd_(2,u20094)u2009=u20092. In the second sample, we can take Pokemons with strengths {2,u20094,u20096}, and there is no larger group with _gcd_u2009≠u20091. | 1,400 | true | true | false | false | false | false | false | false | false | false | 6,763 |
1863F | You are given an array of $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$. In one operation you split the array into two parts: a non-empty prefix and a non-empty suffix. The value of each part is the , determine whether it is possible to achieve the state when only the $$$i$$$-th element (with respect to the original numbering) remains. Formally, you have two numbers $$$l$$$ and $$$r$$$, initially $$$l = 1$$$ and $$$r = n$$$. The current state of the array is $$$[a_l, a_{l+1}, ldots, a_r]$$$. As long as $$$l < r$$$, you apply the following operation: Choose an arbitrary $$$k$$$ from the set $$${l, l + 1, ldots, r - 1}$$$. Denote $$$x = a_l oplus a_{l + 1} oplus ldots oplus a_k$$$ and $$$y = a_{k + 1} oplus a_{k + 2} oplus ldots oplus a_{r}$$$, where $$$oplus$$$ denotes the bitwise XOR operation. If $$$x < y$$$, set $$$l = k + 1$$$. If $$$x > y$$$, set $$$r = k$$$. If $$$x = y$$$, either set $$$l = k + 1$$$, or set $$$r = k$$$. For each $$$i$$$ ($$$1 le i le n$$$), determine whether it is possible to achieve $$$l = r = i$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10,000$$$). The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 le n le 10,000$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i < 2^{60}$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10,000$$$. Note In the first test case, it is possible to achieve $$$l = r = i$$$ for any $$$i$$$ from $$$1$$$ to $$$n$$$: for $$$i=1$$$: $$$[1; 6] ightarrow [1; 4] ightarrow [1; 1]$$$; for $$$i=2$$$: $$$[1; 6] ightarrow [1; 3] ightarrow [2; 3] ightarrow [2; 2]$$$; for $$$i=3$$$: $$$[1; 6] ightarrow [1; 3] ightarrow [3; 3]$$$; for $$$i=4$$$: $$$[1; 6] ightarrow [1; 4] ightarrow [4; 4]$$$; for $$$i=5$$$: $$$[1; 6] ightarrow [5; 6] ightarrow [5; 5]$$$; for $$$i=6$$$: $$$[1; 6] ightarrow [6; 6]$$$. Let's take a closer look at $$$i = 2$$$. Initially $$$l = 1$$$, $$$r = 6$$$. 1. We can choose $$$k = 3$$$ and set $$$r = k = 3$$$ since $$$(3 oplus 2 oplus 1) = 0 ge 0 = (3 oplus 7 oplus 4)$$$; 2. Next, we can choose $$$k = 1$$$ and set $$$l = k + 1 = 2$$$ since $$$3 le 3 = (2 oplus 1)$$$; 3. Finally, we can choose $$$k = 2$$$ and set $$$r = k = 2$$$ since $$$2 ge 1$$$. | 2,600 | true | false | false | true | false | false | false | false | false | false | 1,101 |
1320F | Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks — axis-aligned cubes of size $$$1 imes 1 imes 1$$$. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size $$$1 imes 1 imes 1$$$; each cell either contains exactly one block or is empty. Each cell is represented by its coordinates $$$(x, y, z)$$$ (the cell with these coordinates is a cube with opposite corners in $$$(x, y, z)$$$ and $$$(x + 1, y + 1, z + 1)$$$) and its contents $$$a_{x, y, z}$$$; if the cell is empty, then $$$a_{x, y, z} = 0$$$, otherwise $$$a_{x, y, z}$$$ is equal to the type of the block placed in it (the types are integers from $$$1$$$ to $$$2 cdot 10^5$$$). Polycarp has built a large structure consisting of blocks. This structure can be enclosed in an axis-aligned rectangular parallelepiped of size $$$n imes m imes k$$$, containing all cells $$$(x, y, z)$$$ such that $$$x in [1, n]$$$, $$$y in [1, m]$$$, and $$$z in [1, k]$$$. After that, Polycarp has installed $$$2nm + 2nk + 2mk$$$ sensors around this parallelepiped. A sensor is a special block that sends a ray in some direction and shows the type of the first block that was hit by this ray (except for other sensors). The sensors installed by Polycarp are adjacent to the borders of the parallelepiped, and the rays sent by them are parallel to one of the coordinate axes and directed inside the parallelepiped. More formally, the sensors can be divided into $$$6$$$ types: there are $$$mk$$$ sensors of the first type; each such sensor is installed in $$$(0, y, z)$$$, where $$$y in [1, m]$$$ and $$$z in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the same direction; there are $$$mk$$$ sensors of the second type; each such sensor is installed in $$$(n + 1, y, z)$$$, where $$$y in [1, m]$$$ and $$$z in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the opposite direction; there are $$$nk$$$ sensors of the third type; each such sensor is installed in $$$(x, 0, z)$$$, where $$$x in [1, n]$$$ and $$$z in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the same direction; there are $$$nk$$$ sensors of the fourth type; each such sensor is installed in $$$(x, m + 1, z)$$$, where $$$x in [1, n]$$$ and $$$z in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the opposite direction; there are $$$nm$$$ sensors of the fifth type; each such sensor is installed in $$$(x, y, 0)$$$, where $$$x in [1, n]$$$ and $$$y in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the same direction; finally, there are $$$nm$$$ sensors of the sixth type; each such sensor is installed in $$$(x, y, k + 1)$$$, where $$$x in [1, n]$$$ and $$$y in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the opposite direction. Polycarp has invited his friend Monocarp to play with him. Of course, as soon as Monocarp saw a large parallelepiped bounded by sensor blocks, he began to wonder what was inside of it. Polycarp didn't want to tell Monocarp the exact shape of the figure, so he provided Monocarp with the data from all sensors and told him to try guessing the contents of the parallelepiped by himself. After some hours of thinking, Monocarp has no clue about what's inside the sensor-bounded space. But he does not want to give up, so he decided to ask for help. Can you write a program that will analyze the sensor data and construct any figure that is consistent with it? Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 le n, m, k le 2 cdot 10^5$$$, $$$nmk le 2 cdot 10^5$$$) — the dimensions of the parallelepiped. Then the sensor data follows. For each sensor, its data is either $$$0$$$, if the ray emitted from it reaches the opposite sensor (there are no blocks in between), or an integer from $$$1$$$ to $$$2 cdot 10^5$$$ denoting the type of the first block hit by the ray. The data is divided into $$$6$$$ sections (one for each type of sensors), each consecutive pair of sections is separated by a blank line, and the first section is separated by a blank line from the first line of the input. The first section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(0, i, j)$$$. The second section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(n + 1, i, j)$$$. The third section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, 0, j)$$$. The fourth section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, m + 1, j)$$$. The fifth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, 0)$$$. Finally, the sixth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, k + 1)$$$. Output If the information from the input is inconsistent, print one integer $$$-1$$$. Otherwise, print the figure inside the parallelepiped as follows. The output should consist of $$$nmk$$$ integers: $$$a_{1, 1, 1}$$$, $$$a_{1, 1, 2}$$$, ..., $$$a_{1, 1, k}$$$, $$$a_{1, 2, 1}$$$, ..., $$$a_{1, 2, k}$$$, ..., $$$a_{1, m, k}$$$, $$$a_{2, 1, 1}$$$, ..., $$$a_{n, m, k}$$$, where $$$a_{i, j, k}$$$ is the type of the block in $$$(i, j, k)$$$, or $$$0$$$ if there is no block there. If there are multiple figures consistent with sensor data, describe any of them. For your convenience, the sample output is formatted as follows: there are $$$n$$$ separate sections for blocks having $$$x = 1$$$, $$$x = 2$$$, ..., $$$x = n$$$; each section consists of $$$m$$$ lines containing $$$k$$$ integers each. Note that this type of output is acceptable, but you may print the integers with any other formatting instead (even all integers on the same line), only their order matters. Examples Input 4 3 2 1 4 3 2 6 5 1 4 3 2 6 7 1 4 1 4 0 0 0 7 6 5 6 5 0 0 0 7 1 3 6 1 3 6 0 0 0 0 0 7 4 3 5 4 2 5 0 0 0 0 0 7 Output 1 4 3 0 6 5 1 4 3 2 6 5 0 0 0 0 0 0 0 0 0 0 0 7 Input 1 1 1 0 0 1337 0 0 0 Input 1 1 1 1337 1337 1337 1337 1337 1337 | 3,500 | false | false | false | false | false | false | true | false | false | false | 4,110 |
1497A | You are given an integer $$$n$$$ and an array $$$a_1, a_2, ldots, a_n$$$. You should reorder the elements of the array $$$a$$$ in such way that the sum of $$$ extbf{MEX}$$$ on prefixes ($$$i$$$-th prefix is $$$a_1, a_2, ldots, a_i$$$) is maximized. Formally, you should find an array $$$b_1, b_2, ldots, b_n$$$, such that the sets of elements of arrays $$$a$$$ and $$$b$$$ are equal (it is equivalent to array $$$b$$$ can be found as an array $$$a$$$ with some reordering of its elements) and $$$sumlimits_{i=1}^{n} extbf{MEX}(b_1, b_2, ldots, b_i)$$$ is maximized. $$$ extbf{MEX}$$$ of a set of nonnegative integers is the minimal nonnegative integer such that it is not in the set. For example, $$$ extbf{MEX}({1, 2, 3}) = 0$$$, $$$ extbf{MEX}({0, 1, 2, 4, 5}) = 3$$$. Input The first line contains a single integer $$$t$$$ $$$(1 le t le 100)$$$ xa0— the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 le n le 100)$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ $$$(0 le a_i le 100)$$$. Output For each test case print an array $$$b_1, b_2, ldots, b_n$$$ xa0— the optimal reordering of $$$a_1, a_2, ldots, a_n$$$, so the sum of $$$ extbf{MEX}$$$ on its prefixes is maximized. If there exist multiple optimal answers you can find any. Note In the first test case in the answer $$$ extbf{MEX}$$$ for prefixes will be: 1. $$$ extbf{MEX}({0}) = 1$$$ 2. $$$ extbf{MEX}({0, 1}) = 2$$$ 3. $$$ extbf{MEX}({0, 1, 2}) = 3$$$ 4. $$$ extbf{MEX}({0, 1, 2, 3}) = 4$$$ 5. $$$ extbf{MEX}({0, 1, 2, 3, 4}) = 5$$$ 6. $$$ extbf{MEX}({0, 1, 2, 3, 4, 7}) = 5$$$ 7. $$$ extbf{MEX}({0, 1, 2, 3, 4, 7, 3}) = 5$$$ The sum of $$$ extbf{MEX} = 1 + 2 + 3 + 4 + 5 + 5 + 5 = 25$$$. It can be proven, that it is a maximum possible sum of $$$ extbf{MEX}$$$ on prefixes. | 800 | false | true | false | false | true | false | true | false | true | false | 3,188 |
1874B | Jellyfish is given the non-negative integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ and $$$m$$$. Initially $$$(x,y)=(a,b)$$$. Jellyfish wants to do several operations so that $$$(x,y)=(c,d)$$$. For each operation, she can do one of the following: $$$x := x,&,y$$$, $$$x := x,,y$$$, $$$y := x oplus y$$$, $$$y := y oplus m$$$. Here $$$&$$$ denotes the =(c,d)$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 leq t leq 10^5$$$). The description of the test cases follows. The only line of each test case contains five integers, $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ and $$$m$$$ ($$$0 leq a, b, c, d, m < 2^{30}$$$). Output For each test case, output a single integerxa0— the minimum number of operations. If this cannot be achieved, output $$$-1$$$ instead. Example Input 10 1 0 1 1 1 3 3 1 2 1 1 6 0 7 1 2 4 4 9 8 21 4 0 17 28 50 50 0 0 39 95 33 1 33 110 138 202 174 64 108 78 340 68 340 461 457 291 491 566 766 Output 1 -1 2 -1 -1 2 1 4 1 3 Note In the first test case, we can do the operation $$$y = x oplus y$$$. In the second test case, it is not possible to change $$$(x,y)=(1,2)$$$ using any sequence of operations. In the third test case, we can do the operation $$$x = x,&,y$$$ followed by the operation $$$y = y oplus m$$$. | 2,400 | false | false | false | true | false | false | true | false | false | true | 1,035 |
1516B | Baby Ehab is known for his love for a certain operation. He has an array $$$a$$$ of length $$$n$$$, and he decided to keep doing the following operation on it: he picks $$$2$$$ adjacent elements; he then removes them and places a single integer in their place: their xa0— the number of test cases you need to solve. The first line of each test case contains an integers $$$n$$$ ($$$2 le n le 2000$$$)xa0— the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$ldots$$$, $$$a_{n}$$$ ($$$0 le a_i < 2^{30}$$$)xa0— the elements of the array $$$a$$$. Output If Baby Ehab can make all elements equal while leaving at least $$$2$$$ elements standing, print "YES". Otherwise, print "NO". Example Input 2 3 0 2 2 4 2 3 1 10 Note In the first sample, he can remove the first $$$2$$$ elements, $$$0$$$ and $$$2$$$, and replace them by $$$0 oplus 2=2$$$. The array will be $$$[2,2]$$$, so all the elements are equal. In the second sample, there's no way to make all the elements equal. | 1,500 | false | true | false | true | false | false | true | false | false | false | 3,081 |
1491H | Yuezheng Ling gives Luo Tianyi a tree which has $$$n$$$ nodes, rooted at $$$1$$$. Luo Tianyi will tell you that the parent of the $$$i$$$-th node is $$$a_i$$$ ($$$1 leq a_i<i$$$ for $$$2 le i le n$$$), and she will ask you to perform $$$q$$$ queries of $$$2$$$ types: 1. She'll give you three integers $$$l$$$, $$$r$$$ and $$$x$$$ ($$$2 le l le r le n$$$, $$$1 le x le 10^5$$$). You need to replace $$$a_i$$$ with $$$max(a_i-x,1)$$$ for all $$$i$$$ with $$$l leq i leq r$$$. 2. She'll give you two integers $$$u$$$, $$$v$$$ ($$$1 le u, v le n$$$). You need to find the . Input The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2leq n,q leq 10^5$$$) — the number of nodes and the number of queries, respectively. The second line contains $$$n-1$$$ integers $$$a_2, a_3,dots, a_n$$$ ($$$1 le a_i < i$$$), where $$$a_i$$$ is the parent of the node $$$i$$$. Next $$$q$$$ lines contain queries. For each query, the first integer of each line is $$$t$$$ ($$$t = 1$$$ or $$$2$$$) — the type of the query. If $$$t = 1$$$, this represents the query of the first type. Then, three integers will follow: $$$l$$$, $$$r$$$, $$$x$$$ ($$$2 le l le r le n$$$, $$$1 le x le 10^5$$$), meaning that you have to replace $$$a_i$$$ with $$$max(a_i-x,1)$$$ for all $$$i$$$ with $$$l leq i leq r$$$. If $$$t = 2$$$, this represents the query of the second type. Then, two integers will follow: $$$u$$$ and $$$v$$$ ($$$1 le u, v le n$$$), and you have to find the LCA of $$$u$$$ and $$$v$$$. It's guaranteed that there is at least one query of the second type. Note The tree in example is shown below. After the query of the first type, the tree changes and is looking as shown below. | 3,400 | false | false | false | false | true | false | false | false | false | false | 3,215 |
1424G | During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range $$$(1, 10^9)$$$! Therefore, the planet was named Longlifer. In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem! Input The first line contains an integer $$$n$$$ ($$$1 le n le 10^5$$$)xa0— the number of people. Each of the following $$$n$$$ lines contain two integers $$$b$$$ and $$$d$$$ ($$$1 le b lt d le 10^9$$$) representing birth and death year (respectively) of each individual. Output Print two integer numbers separated by blank character, $$$y$$$ xa0— the year with a maximum number of people alive and $$$k$$$ xa0— the number of people alive in year $$$y$$$. In the case of multiple possible solutions, print the solution with minimum year. Note You can assume that an individual living from $$$b$$$ to $$$d$$$ has been born at the beginning of $$$b$$$ and died at the beginning of $$$d$$$, and therefore living for $$$d$$$ - $$$b$$$ years. | 1,300 | false | false | false | false | true | false | false | false | true | false | 3,549 |
785B | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has _n_ variants when he will attend chess classes, _i_-th variant is given by a period of time (_l_1,u2009_i_,u2009_r_1,u2009_i_). Also he has _m_ variants when he will attend programming classes, _i_-th variant is given by a period of time (_l_2,u2009_i_,u2009_r_2,u2009_i_). Anton needs to choose exactly one of _n_ possible periods of time when he will attend chess classes and exactly one of _m_ possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal. The distance between periods (_l_1,u2009_r_1) and (_l_2,u2009_r_2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible _i_u2009-u2009_j_, where _l_1u2009≤u2009_i_u2009≤u2009_r_1 and _l_2u2009≤u2009_j_u2009≤u2009_r_2. In particular, when the periods intersect, the distance between them is 0. Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number! Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u2009200u2009000)xa0— the number of time periods when Anton can attend chess classes. Each of the following _n_ lines of the input contains two integers _l_1,u2009_i_ and _r_1,u2009_i_ (1u2009≤u2009_l_1,u2009_i_u2009≤u2009_r_1,u2009_i_u2009≤u2009109)xa0— the _i_-th variant of a period of time when Anton can attend chess classes. The following line of the input contains a single integer _m_ (1u2009≤u2009_m_u2009≤u2009200u2009000)xa0— the number of time periods when Anton can attend programming classes. Each of the following _m_ lines of the input contains two integers _l_2,u2009_i_ and _r_2,u2009_i_ (1u2009≤u2009_l_2,u2009_i_u2009≤u2009_r_2,u2009_i_u2009≤u2009109)xa0— the _i_-th variant of a period of time when Anton can attend programming classes. Note In the first sample Anton can attend chess classes in the period (2,u20093) and attend programming classes in the period (6,u20098). It's not hard to see that in this case the distance between the periods will be equal to 3. In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0. | 1,100 | false | true | false | false | false | false | false | false | true | false | 6,632 |
754C | Recently Vladik discovered a new entertainmentxa0— coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them. At first, he need to download _t_ chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. In particular, some of the messages have no information of their sender. It is known that if a person sends several messages in a row, they all are merged into a single message. It means that there could not be two or more messages in a row with the same sender. Moreover, a sender never mention himself in his messages. Vladik wants to recover senders of all the messages so that each two neighboring messages will have different senders and no sender will mention himself in his messages. He has no idea of how to do this, and asks you for help. Help Vladik to recover senders in each of the chats! Input The first line contains single integer _t_ (1u2009≤u2009_t_u2009≤u200910) — the number of chats. The _t_ chats follow. Each chat is given in the following format. The first line of each chat description contains single integer _n_ (1u2009≤u2009_n_u2009≤u2009100)xa0— the number of users in the chat. The next line contains _n_ space-separated distinct usernames. Each username consists of lowercase and uppercase English letters and digits. The usernames can't start with a digit. Two usernames are different even if they differ only with letters' case. The length of username is positive and doesn't exceed 10 characters. The next line contains single integer _m_ (1u2009≤u2009_m_u2009≤u2009100)xa0— the number of messages in the chat. The next _m_ line contain the messages in the following formats, one per line: <username>:<text>xa0— the format of a message with known sender. The username should appear in the list of usernames of the chat. <?>:<text>xa0— the format of a message with unknown sender. The text of a message can consist of lowercase and uppercase English letter, digits, characters '.' (dot), ',' (comma), '!' (exclamation mark), '?' (question mark) and ' ' (space). The text doesn't contain trailing spaces. The length of the text is positive and doesn't exceed 100 characters. We say that a text mention a user if his username appears in the text as a word. In other words, the username appears in a such a position that the two characters before and after its appearance either do not exist or are not English letters or digits. For example, the text "Vasya, masha13 and Kate!" can mention users "Vasya", "masha13", "and" and "Kate", but not "masha". It is guaranteed that in each chat no known sender mention himself in his messages and there are no two neighboring messages with the same known sender. Output Print the information about the _t_ chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print _m_ messages in the following format: <username>:<text> If there are multiple answers, print any of them. | 2,200 | false | false | true | true | false | true | true | false | false | false | 6,780 |
460A | Problem - 460A - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags brute force implementation math *900 No tag edit access → Contest materials mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input The single line contains two integers _n_ and _m_ (1u2009≤u2009_n_u2009≤u2009100;xa02u2009≤u2009_m_u2009≤u2009100), separated by a space. Output Print a single integer — the answer to the problem. Examples Input 2 2 Output 3 Input 9 3 Output 13 Note In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day. | 900 | true | false | true | false | false | false | true | false | false | false | 8,001 |
710B | Problem - 710B - Codeforces =============== xa0 — the number of points on the line. The second line contains _n_ integers _x__i_ (u2009-u2009109u2009≤u2009_x__i_u2009≤u2009109) — the coordinates of the given _n_ points. Output Print the only integer _x_ — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. Example Input 4 1 2 3 4 Output 2 | 1,400 | false | false | false | false | false | false | true | false | true | false | 6,981 |
542B | A duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0,u20090). As he doesn't like walking for his prey, he prefers to shoot only vertically up (because in this case, the ducks fall straight into his hands). The hunter doesn't reload the gun immediately — _r_ or more seconds must pass between the shots. When the hunter shoots up, the bullet immediately hits all the ducks who are directly above the hunter. In a two dimensional world each duck is a horizontal segment that moves horizontally in the negative direction of the _Ox_ axis at the speed 1 length unit per second. For each duck we know the values _h__i_ and _t__i_ — the _x_-coordinates of its head (the left end of the segment) and its tail (the right end of the segment) at time 0. The height where the duck is flying isn't important as the gun shoots vertically up to the infinite height and hits all the ducks on its way. The figure to the first sample. What maximum number of ducks can the hunter shoot? The duck is considered shot by the hunter if at the moment of the shot at least one of its point intersects the _Oy_ axis. After the hunter shoots the duck, it falls and it can't be shot anymore. The hunter cannot make shots before the moment of time 0. Input The first line of the input contains integers _n_, _r_ (1u2009≤u2009_n_u2009≤u2009200u2009000, 1u2009≤u2009_r_u2009≤u2009109) — the number of ducks and the minimum time in seconds between the shots. Then _n_ lines follow, each of them contains two integers _h__i_,u2009_t__i_ (u2009-u2009109u2009≤u2009_h__i_u2009<u2009_t__i_u2009≤u2009109)xa0— the _x_-coordinate of the head and tail of the _i_-th duck at the moment 0. Output Print a single integer — the maximum number of ducks that can be shot by the hunter. Note In the first sample the hunter must shoot at time 0, this shot kills ducks 1 and 3. Then the hunter needs to reload the gun and shoot again at time 3. His second shot hits the tail of duck 2. In the second sample the hunter can make shots at times 0 and 6 to hit three ducks. | 3,100 | false | false | false | false | true | false | false | false | false | false | 7,674 |
1916G | You are given a tree with $$$n$$$ vertices, whose vertices are numbered from $$$1$$$ to $$$n$$$. Each edge is labeled with some integer $$$w_i$$$. Define $$$len(u, v)$$$ as the number of edges in the simple path between vertices $$$u$$$ and $$$v$$$, and $$$gcd(u, v)$$$ as the Greatest Common Divisor of all numbers written on the edges of the simple path between vertices $$$u$$$ and $$$v$$$. For example, $$$len(u, u) = 0$$$ and $$$gcd(u, u) = 0$$$ for any $$$1 leq u leq n$$$. You need to find the maximum value of $$$len(u, v) cdot gcd(u, v)$$$ over all pairs of vertices in the tree. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0— the number of test cases. This is followed by their description. The first line of each test case contains the number $$$n$$$ ($$$2 leq n leq 10^5$$$)xa0— the number of vertices in the tree. The next $$$n-1$$$ lines specify the edges in the format $$$u$$$, $$$v$$$, $$$w$$$ ($$$1 leq u, v leq n$$$, $$$1 leq w leq 10^{12}$$$). 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 number equal to the maximum value of $$$len(u, v) cdot gcd(u, v)$$$ over all pairs of vertices in the tree. Example Input 4 2 1 2 1000000000000 4 3 2 6 2 1 10 2 4 6 8 1 2 12 2 3 9 3 4 9 4 5 6 5 6 12 6 7 4 7 8 9 12 1 2 12 2 3 12 2 4 6 2 5 9 5 6 6 1 7 4 4 8 12 8 9 4 8 10 12 2 11 9 7 12 9 Output 1000000000000 12 18 24 | 3,500 | false | false | false | true | false | false | false | false | false | false | 797 |
1194F | Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $$$T$$$ seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains $$$n$$$ Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number $$$t_i$$$ is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds). Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either $$$t_i$$$ seconds or $$$t_i + 1$$$ seconds to solve the $$$i$$$-th crossword, equiprobably (with probability $$$frac{1}{2}$$$ he solves the crossword in exactly $$$t_i$$$ seconds, and with probability $$$frac{1}{2}$$$ he has to spend an additional second to finish the crossword). All these events are independent. After $$$T$$$ seconds pass (or after solving the last crossword, if he manages to do it in less than $$$T$$$ seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate $$$E$$$ — the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values — in this problem it means that the expected value of the number of solved crosswords can be calculated as $$$E = sum limits_{i = 0}^{n} i p_i$$$, where $$$p_i$$$ is the probability that Adilbek will solve exactly $$$i$$$ crosswords. We can represent $$$E$$$ as rational fraction $$$frac{P}{Q}$$$ with $$$Q > 0$$$. To give the answer, you should print $$$P cdot Q^{-1} bmod (10^9 + 7)$$$. Input The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 le n le 2 cdot 10^5$$$, $$$1 le T le 2 cdot 10^{14}$$$) — the number of crosswords and the time Adilbek has to spend, respectively. The second line contains $$$n$$$ integers $$$t_1, t_2, dots, t_n$$$ ($$$1 le t_i le 10^9$$$), where $$$t_i$$$ is the time it takes a crossword expert to solve the $$$i$$$-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them. | 2,400 | false | false | false | true | false | false | false | false | false | false | 4,731 |
1791D | Let's denote the $$$f(x)$$$ function for a string $$$x$$$ as the number of distinct characters that the string contains. For example $$$f( exttt{abc}) = 3$$$, $$$f( exttt{bbbbb}) = 1$$$, and $$$f( exttt{babacaba}) = 3$$$. Given a string $$$s$$$, split it into two non-empty strings $$$a$$$ and $$$b$$$ such that $$$f(a) + f(b)$$$ is the maximum possible. In other words, find the maximum possible value of $$$f(a) + f(b)$$$ such that $$$a + b = s$$$ (the concatenation of string $$$a$$$ and string $$$b$$$ is equal to string $$$s$$$). Input The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 leq n leq 2cdot10^5$$$)xa0— the length of the string $$$s$$$. The second line contains the string $$$s$$$, consisting of lowercase English letters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2cdot10^5$$$. Output For each test case, output a single integer xa0— the maximum possible value of $$$f(a) + f(b)$$$ such that $$$a + b = s$$$. Example Input 5 2 aa 7 abcabcd 5 aaaaa 10 paiumoment 4 aazz Note For the first test case, there is only one valid way to split $$$ exttt{aa}$$$ into two non-empty strings $$$ exttt{a}$$$ and $$$ exttt{a}$$$, and $$$f( exttt{a}) + f( exttt{a}) = 1 + 1 = 2$$$. For the second test case, by splitting $$$ exttt{abcabcd}$$$ into $$$ exttt{abc}$$$ and $$$ exttt{abcd}$$$ we can get the answer of $$$f( exttt{abc}) + f( exttt{abcd}) = 3 + 4 = 7$$$ which is maximum possible. For the third test case, it doesn't matter how we split the string, the answer will always be $$$2$$$. | 1,000 | false | true | false | false | false | false | true | false | false | false | 1,532 |
48H | According to the legends the king of Berland Berl I was noted for his love of beauty and order. One day he ordered to tile the palace hall's floor where balls and receptions used to take place with black and white tiles according to a regular geometrical pattern invented by him. However, as is after the case, due to low financing there were only _a_ black and _b_ white tiles delivered to the palace. The other _c_ tiles were black and white (see the picture). The initial plan failed! Having learned of that, the king gave a new command: tile the floor with the available tiles so that no black side of a tile touched a white one. The tiles are squares of one size 1u2009×u20091, every black and white tile can be rotated in one of the four ways. The court programmer was given the task to work out the plan of tiling and he coped with the task and didn't suffer the consequences of disobedience. And can you cope with it? Input The first line contains given integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100) which represent the sizes of the rectangle that needs to be tiled. The next line contains non-negative numbers _a_, _b_ and _c_, _a_u2009+u2009_b_u2009+u2009_c_u2009=u2009_nm_, _c_u2009≥u2009_m_. Output Print 2_n_ lines containing 2_m_ characters each — the tiling scheme. Every tile is represented by a square 2u2009×u20092 in the following manner (the order corresponds to the order of the picture above): If multiple solutions exist, output any. Examples Output ###/# ##/.. #/.... /..... | 2,800 | false | false | false | false | false | true | false | false | false | false | 9,730 |
91E | Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building! There are _n_ walruses taking part in the contest. Each walrus is given a unique number from 1 to _n_. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper _i_-th walrus is equal to _a__i_. Each minute the _i_-th walrus finishes building _b__i_ floors. The journalists that are reporting from the spot where the Olympiad is taking place, make _q_ queries to the organizers. Each query is characterized by a group of three numbers _l__i_, _r__i_, _t__i_. The organizers respond to each query with a number _x_, such that: 1. Number _x_ lies on the interval from _l__i_ to _r__i_ inclusive (_l__i_u2009≤u2009_x_u2009≤u2009_r__i_). 2. The skyscraper of the walrus number _x_ possesses the maximum height among the skyscrapers of all walruses from the interval [_l__i_,u2009_r__i_] at the moment of time _t__i_. For each journalists' query print the number of the walrus _x_ that meets the above-given criteria. If there are several possible answers, print any of them. Input The first line contains numbers _n_ and _q_ (1u2009≤u2009_n_,u2009_q_u2009≤u2009105). Next _n_ lines contain pairs of numbers _a__i_, _b__i_ (1u2009≤u2009_a__i_,u2009_b__i_u2009≤u2009109). Then follow _q_ queries i the following format _l__i_, _r__i_, _t__i_, one per each line (1u2009≤u2009_l__i_u2009≤u2009_r__i_u2009≤u2009_n_, 0u2009≤u2009_t__i_u2009≤u2009106). All input numbers are integers. Output For each journalists' query print the number of the walrus _x_ that meets the criteria, given in the statement. Print one number per line. Examples Input 5 4 4 1 3 5 6 2 3 5 6 5 1 5 2 1 3 5 1 1 0 1 5 0 Input 5 4 6 1 5 1 2 5 4 3 6 1 2 4 1 3 4 5 1 4 5 1 2 0 | 2,500 | false | false | false | false | true | false | false | false | false | false | 9,518 |
1519C | Polycarp is an organizer of a Berland ICPC regional event. There are $$$n$$$ universities in Berland numbered from $$$1$$$ to $$$n$$$. Polycarp knows all competitive programmers in the region. There are $$$n$$$ students: the $$$i$$$-th student is enrolled at a university $$$u_i$$$ and has a programming skill $$$s_i$$$. Polycarp has to decide on the rules now. In particular, the number of members in the team. Polycarp knows that if he chooses the size of the team to be some integer $$$k$$$, each university will send their $$$k$$$ strongest (with the highest programming skill $$$s$$$) students in the first team, the next $$$k$$$ strongest students in the second team and so on. If there are fewer than $$$k$$$ students left, then the team can't be formed. Note that there might be universities that send zero teams. The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $$$0$$$. Help Polycarp to find the strength of the region for each choice of $$$k$$$ from $$$1$$$ to $$$n$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$)xa0— the number of universities and the number of students. The second line of each testcase contains $$$n$$$ integers $$$u_1, u_2, dots, u_n$$$ ($$$1 le u_i le n$$$)xa0— the university the $$$i$$$-th student is enrolled at. The third line of each testcase contains $$$n$$$ integers $$$s_1, s_2, dots, s_n$$$ ($$$1 le s_i le 10^9$$$)xa0— the programming skill of the $$$i$$$-th student. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 cdot 10^5$$$. Output For each testcase print $$$n$$$ integers: the strength of the regionxa0— the total skill of the members of the present teamsxa0— for each choice of team size $$$k$$$. Example Input 4 7 1 2 1 2 1 2 1 6 8 3 1 5 1 5 10 1 1 1 2 2 2 2 3 3 3 3435 3014 2241 2233 2893 2102 2286 2175 1961 2567 6 3 3 3 3 3 3 5 9 6 7 9 7 1 1 3083 Output 29 28 26 19 0 0 0 24907 20705 22805 9514 0 0 0 0 0 0 43 43 43 32 38 43 3083 Note In the first testcase the teams from each university for each $$$k$$$ are: $$$k=1$$$: university $$$1$$$: $$$[6], [5], [5], [3]$$$; university $$$2$$$: $$$[8], [1], [1]$$$; $$$k=2$$$: university $$$1$$$: $$$[6, 5], [5, 3]$$$; university $$$2$$$: $$$[8, 1]$$$; $$$k=3$$$: university $$$1$$$: $$$[6, 5, 5]$$$; university $$$2$$$: $$$[8, 1, 1]$$$; $$$k=4$$$: university $$$1$$$: $$$[6, 5, 5, 3]$$$; | 1,400 | false | true | false | false | true | false | true | false | true | false | 3,067 |
1284E | Kiwon's favorite video game is now holding a new year event to motivate the users! The game is about building and defending a castle, which led Kiwon to think about the following puzzle. In a 2-dimension plane, you have a set $$$s = {(x_1, y_1), (x_2, y_2), ldots, (x_n, y_n)}$$$ consisting of $$$n$$$ distinct points. In the set $$$s$$$, no three distinct points lie on a single line. For a point $$$p in s$$$, we can protect this point by building a castle. A castle is a simple quadrilateral (polygon with $$$4$$$ vertices) that strictly encloses the point $$$p$$$ (i.e. the point $$$p$$$ is strictly inside a quadrilateral). Kiwon is interested in the number of $$$4$$$-point subsets of $$$s$$$ that can be used to build a castle protecting $$$p$$$. Note that, if a single subset can be connected in more than one way to enclose a point, it is counted only once. Let $$$f(p)$$$ be the number of $$$4$$$-point subsets that can enclose the point $$$p$$$. Please compute the sum of $$$f(p)$$$ for all points $$$p in s$$$. Input The first line contains a single integer $$$n$$$ ($$$5 le n le 2,500$$$). In the next $$$n$$$ lines, two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 le x_i, y_i le 10^9$$$) denoting the position of points are given. It is guaranteed that all points are distinct, and there are no three collinear points. Output Print the sum of $$$f(p)$$$ for all points $$$p in s$$$. Examples Input 5 -1 0 1 0 -10 -1 10 -1 0 3 Input 8 0 1 1 2 2 2 1 3 0 -1 -1 -2 -2 -2 -1 -3 Input 10 588634631 265299215 -257682751 342279997 527377039 82412729 145077145 702473706 276067232 912883502 822614418 -514698233 280281434 -41461635 65985059 -827653144 188538640 592896147 -857422304 -529223472 | 2,500 | true | false | false | false | false | false | false | false | true | false | 4,270 |
1883D | Initially, you have an empty multiset of segments. You need to process $$$q$$$ operations of two types: $$$+$$$ $$$l$$$ $$$r$$$ — Add the segment $$$(l, r)$$$ to the multiset, $$$-$$$ $$$l$$$ $$$r$$$ — Remove exactly one segment $$$(l, r)$$$ from the multiset. It is guaranteed that this segment exists in the multiset. After each operation, you need to determine if there exists a pair of segments in the multiset that do not intersect. A pair of segments $$$(l, r)$$$ and $$$(a, b)$$$ do not intersect if there does not exist a point $$$x$$$ such that $$$l leq x leq r$$$ and $$$a leq x leq b$$$. Input The first line of each test case contains an integer $$$q$$$ ($$$1 leq q leq 10^5$$$) — the number of operations. The next $$$q$$$ lines describe two types of operations. If it is an addition operation, it is given in the format $$$+$$$ $$$l$$$ $$$r$$$. If it is a deletion operation, it is given in the format $$$-$$$ $$$l$$$ $$$r$$$ ($$$1 leq l leq r leq 10^9$$$). Output After each operation, print "YES" if there exists a pair of segments in the multiset that do not intersect, and "NO" otherwise. You can print the answer in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers. Example Input 12 + 1 2 + 3 4 + 2 3 + 2 2 + 3 4 - 3 4 - 3 4 - 1 2 + 3 4 - 2 2 - 2 3 - 3 4 Output NO YES YES YES YES YES NO NO YES NO NO NO Note In the example, after the second, third, fourth, and fifth operations, there exists a pair of segments $$$(1, 2)$$$ and $$$(3, 4)$$$ that do not intersect. Then we remove exactly one segment $$$(3, 4)$$$, and by that time we had two segments. Therefore, the answer after this operation also exists. | 1,500 | false | true | false | false | true | false | false | false | false | false | 988 |
203B | One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered white square piece of paper, consisting of _n_u2009×u2009_n_ cells. After that, he started to paint the white cells black one after the other. In total he painted _m_ different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him. Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist. Input The first line contains two integers _n_ and _m_ (1u2009≤u2009_n_u2009≤u20091000, 1u2009≤u2009_m_u2009≤u2009_min_(_n_·_n_,u2009105)) — the size of the squared piece of paper and the number of moves, correspondingly. Then, _m_ lines contain the description of the moves. The _i_-th line contains two integers _x__i_, _y__i_ (1u2009≤u2009_x__i_,u2009_y__i_u2009≤u2009_n_) — the number of row and column of the square that gets painted on the _i_-th move. All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom. Output On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1. Examples Input 4 11 1 1 1 2 1 3 2 2 2 3 1 4 2 4 3 4 3 2 3 3 4 1 Input 4 12 1 1 1 2 1 3 2 2 2 3 1 4 2 4 3 4 3 2 4 2 4 1 3 1 | 1,300 | false | false | true | false | false | false | true | false | false | false | 9,031 |
332A | Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice! Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All _n_ people who came to the barbecue sat in a circle (thus each person received a unique index _b__i_ from 0 to _n_u2009-u20091). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the _j_-th turn was made by the person with index _b__i_, then this person acted like that: 1. he pointed at the person with index (_b__i_u2009+u20091)xa0_mod_xa0_n_ either with an elbow or with a nod (_x_xa0_mod_xa0_y_ is the remainder after dividing _x_ by _y_); 2. if _j_u2009≥u20094 and the players who had turns number _j_u2009-u20091, _j_u2009-u20092, _j_u2009-u20093, made during their turns the same moves as player _b__i_ on the current turn, then he had drunk a glass of juice; 3. the turn went to person number (_b__i_u2009+u20091)xa0_mod_xa0_n_. The person who was pointed on the last turn did not make any actions. The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him. You can assume that in any scenario, there is enough juice for everybody. Input The first line contains a single integer _n_ (4u2009≤u2009_n_u2009≤u20092000) — the number of participants in the game. The second line describes the actual game: the _i_-th character of this line equals 'a', if the participant who moved _i_-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns. Output Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. Note In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different. | 1,300 | false | false | true | false | false | false | false | false | false | false | 8,510 |
1263B | A PIN code is a string that consists of exactly $$$4$$$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has $$$n$$$ ($$$2 le n le 10$$$) bank cards, the PIN code of the $$$i$$$-th card is $$$p_i$$$. Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $$$n$$$ codes would become different. Formally, in one step, Polycarp picks $$$i$$$-th card ($$$1 le i le n$$$), then in its PIN code $$$p_i$$$ selects one position (from $$$1$$$ to $$$4$$$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different. Polycarp quickly solved this problem. Can you solve it? Input The first line contains integer $$$t$$$ ($$$1 le t le 100$$$) — the number of test cases in the input. Then test cases follow. The first line of each of $$$t$$$ test sets contains a single integer $$$n$$$ ($$$2 le n le 10$$$) — the number of Polycarp's bank cards. The next $$$n$$$ lines contain the PIN codes $$$p_1, p_2, dots, p_n$$$ — one per line. The length of each of them is $$$4$$$. All PIN codes consist of digits only. Output Print the answers to $$$t$$$ test sets. The answer to each set should consist of a $$$n + 1$$$ lines In the first line print $$$k$$$ — the least number of changes to make all PIN codes different. In the next $$$n$$$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them. Example Input 3 2 1234 0600 2 1337 1337 4 3139 3139 3139 3139 Output 0 1234 0600 1 1337 1237 3 3139 3138 3939 6139 | 1,400 | false | true | true | false | false | false | false | false | false | false | 4,386 |
80B | Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock. Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll. Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00. You can only rotate the hands forward, that is, as is shown in the picture: As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction. Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still. Input The only line of input contains current time according to the digital clock, formatted as HH:MM (00u2009≤u2009HHu2009≤u200923, 00u2009≤u2009MMu2009≤u200959). The mantel clock initially shows 12:00. Pretests contain times of the beginning of some morning TV programs of the Channel One Russia. Output Print two numbers _x_ and _y_ — the angles of turning the hour and minute hands, respectively (0u2009≤u2009_x_,u2009_y_u2009<u2009360). The absolute or relative error in the answer should not exceed 10u2009-u20099. | 1,200 | true | false | false | false | false | false | false | false | false | false | 9,564 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.