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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1473G | Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: the first row consists of $$$1$$$ tile; then $$$a_1$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row; then $$$b_1$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row; then $$$a_2$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row; then $$$b_2$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row; ... then $$$a_n$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row; then $$$b_n$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row. An example of the road with $$$n = 2$$$, $$$a_1 = 4$$$, $$$b_1 = 2$$$, $$$a_2 = 2$$$, $$$b_2 = 3$$$. Rows are arranged from left to right. You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile. Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo $$$998244353$$$. Input The first line contains one integer $$$n$$$ ($$$1 le n le 1000$$$). Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 le a_i, b_i le 10^5$$$; $$$a_i - b_i le 5$$$). Additional constraint on the input: the sequence of $$$a_i$$$ and $$$b_i$$$ never results in a row with non-positive number of tiles. Output Print one integer β the number of paths from the first row to the last row, taken modulo $$$998244353$$$. Examples Input 8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796 | 2,800 | true | false | false | true | false | false | false | false | false | false | 3,311 |
1909C | You have $$$n$$$ intervals $$$[l_1, r_1], [l_2, r_2], dots, [l_n, r_n]$$$, such that $$$l_i < r_i$$$ for each $$$i$$$, and all the endpoints of the intervals are distinct. The $$$i$$$-th interval has weight $$$c_i$$$ per unit length. Therefore, the weight of the $$$i$$$-th interval is $$$c_i cdot (r_i - l_i)$$$. You don't like large weights, so you want to make the sum of weights of the intervals as small as possible. It turns out you can perform all the following three operations: rearrange the elements in the array $$$l$$$ in any order; rearrange the elements in the array $$$r$$$ in any order; rearrange the elements in the array $$$c$$$ in any order. However, after performing all of the operations, the intervals must still be valid (i.e., for each $$$i$$$, $$$l_i < r_i$$$ must hold). What's the minimum possible sum of weights of the intervals after performing the operations? 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 a single integer $$$n$$$ ($$$1 le n le 10^5$$$)xa0β the number of intervals. The second line of each test case contains $$$n$$$ integers $$$l_1, l_2, ldots, l_n$$$ ($$$1 le l_i le 2 cdot 10^5$$$)xa0β the left endpoints of the initial intervals. The third line of each test case contains $$$n$$$ integers $$$r_1, r_2, ldots, r_n$$$ ($$$l_i < r_i le 2 cdot 10^5$$$)xa0β the right endpoints of the initial intervals. It is guaranteed that $$${l_1, l_2, dots, l_n, r_1, r_2, dots, r_n}$$$ are all distinct. The fourth line of each test case contains $$$n$$$ integers $$$c_1, c_2, ldots, c_n$$$ ($$$1 le c_i le 10^7$$$)xa0β the initial weights of the intervals per unit length. 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 integer: the minimum possible sum of weights of the intervals after your operations. Example Input 2 2 8 3 12 23 100 100 4 20 1 2 5 30 4 3 10 2 3 2 3 Note In the first test case, you can make $$$l = [8, 3]$$$; $$$r = [23, 12]$$$; $$$c = [100, 100]$$$. In that case, there are two intervals: interval $$$[8, 23]$$$ with weight $$$100$$$ per unit length, and $$$100 cdot (23-8) = 1500$$$ in total; interval $$$[3, 12]$$$ with weight $$$100$$$ per unit length, and $$$100 cdot (12-3) = 900$$$ in total. The sum of the weights is $$$2400$$$. It can be shown that there is no configuration of final intervals whose sum of weights is less than $$$2400$$$. In the second test case, you can make $$$l = [1, 2, 5, 20]$$$; $$$r = [3, 4, 10, 30]$$$; $$$c = [3, 3, 2, 2]$$$. In that case, there are four intervals: interval $$$[1, 3]$$$ with weight $$$3$$$ per unit length, and $$$3 cdot (3-1) = 6$$$ in total; interval $$$[2, 4]$$$ with weight $$$3$$$ per unit length, and $$$3 cdot (4-2) = 6$$$ in total; interval $$$[5, 10]$$$ with weight $$$2$$$ per unit length, and $$$2 cdot (10-5) = 10$$$ in total; interval $$$[20, 30]$$$ with weight $$$2$$$ per unit length, and $$$2 cdot (30-20) = 20$$$ in total. The sum of the weights is $$$42$$$. It can be shown that there is no configuration of final intervals whose sum of weights is less than $$$42$$$. | 1,400 | true | true | false | false | true | true | false | false | true | false | 855 |
281A | Problem - 281A - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags implementation strings *800 No tag edit access β Contest materials | 800 | false | false | true | false | false | false | false | false | false | false | 8,710 |
1203E | There are $$$n$$$ boxers, the weight of the $$$i$$$-th boxer is $$$a_i$$$. Each of them can change the weight by no more than $$$1$$$ before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values u200b$$$a_i$$$ will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is $$$150001$$$ (but no more). Input The first line contains an integer $$$n$$$ ($$$1 le n le 150000$$$) β the number of boxers. The next line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$, where $$$a_i$$$ ($$$1 le a_i le 150000$$$) is the weight of the $$$i$$$-th boxer. Output Print a single integer β the maximum possible number of people in a team. Note In the first example, boxers should not change their weights β you can just make a team out of all of them. In the second example, one boxer with a weight of $$$1$$$ can be increased by one (get the weight of $$$2$$$), one boxer with a weight of $$$4$$$ can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of $$$3$$$ and $$$5$$$, respectively). Thus, you can get a team consisting of boxers with weights of $$$5, 4, 3, 2, 1$$$. | 1,500 | false | true | false | false | false | false | false | false | true | false | 4,678 |
1431H | Marina plays a new rogue-like game. In this game, there are $$$n$$$ different character species and $$$m$$$ different classes. The game is played in runs; for each run, Marina has to select a species and a class for her character. If she selects the $$$i$$$-th species and the $$$j$$$-th class, she will get $$$c_{i, j}$$$ points for this run. Initially, some species and classes are unlocked, all others are locked. To unlock the $$$i$$$-th species, Marina has to get at least $$$a_i$$$ points in total for previous runs β that is, as soon as her total score for played runs is at least $$$a_i$$$, this species is unlocked. Similarly, to unlock the $$$j$$$-th class, she has to get at least $$$b_j$$$ points in total for previous runs. If $$$a_i = 0$$$ for some $$$i$$$, then this species is unlocked initially (the same applies to classes with $$$b_j = 0$$$). Marina wants to unlock all species and classes in the minimum number of runs. Before playing the game, she can read exactly one guide on some combination of species and class, and reading a guide will increase the score she gets for all runs with that combination by $$$k$$$ (formally, before playing the game, she can increase exactly one value of $$$c_{i, j}$$$ by $$$k$$$). What is the minimum number of runs she has to play to unlock all species and classes if she chooses the combination to read a guide on optimally? Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 le n, m le 1500$$$; $$$0 le k le 10^9$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 = a_1 le a_2 le dots le a_n le 10^{12}$$$), where $$$a_i$$$ is the number of points required to unlock the $$$i$$$-th species (or $$$0$$$, if it is unlocked initially). Note that $$$a_1 = 0$$$, and these values are non-descending. The third line contains $$$m$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_m$$$ ($$$0 = b_1 le b_2 le dots le b_m le 10^{12}$$$), where $$$b_i$$$ is the number of points required to unlock the $$$i$$$-th class (or $$$0$$$, if it is unlocked initially). Note that $$$b_1 = 0$$$, and these values are non-descending. Then $$$n$$$ lines follow, each of them contains $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$c_{i, j}$$$ ($$$1 le c_{i, j} le 10^9$$$) β the score Marina gets for a run with the $$$i$$$-th species and the $$$j$$$-th class. Output Print one integer β the minimum number of runs Marina has to play to unlock all species and all classes if she can read exactly one guide before playing the game. Examples Input 3 4 2 0 5 7 0 2 6 10 2 5 5 2 5 3 4 4 3 4 2 4 Input 4 2 1 0 3 9 9 0 2 3 3 5 1 1 3 2 3 Input 3 3 5 0 8 11 0 0 3 3 1 3 1 2 1 1 1 3 Note The explanation for the first test: 1. Marina reads a guide on the combination of the $$$1$$$-st species and the $$$2$$$-nd class. Thus, $$$c_{1, 2}$$$ becomes $$$7$$$. Initially, only the $$$1$$$-st species and the $$$1$$$-st class are unlocked. 2. Marina plays a run with the $$$1$$$-st species and the $$$1$$$-st class. Her score becomes $$$2$$$, and she unlocks the $$$2$$$-nd class. 3. Marina plays a run with the $$$1$$$-st species and the $$$2$$$-nd class. Her score becomes $$$9$$$, and she unlocks everything except the $$$4$$$-th class. 4. Marina plays a run with the $$$3$$$-rd species and the $$$3$$$-rd class. Her score becomes $$$11$$$, and she unlocks the $$$4$$$-th class. She has unlocked everything in $$$3$$$ runs. Note that this way to unlock everything is not the only one. The explanation for the second test: 1. Marina reads a guide on the combination of the $$$2$$$-nd species and the $$$1$$$-st class. Thus, $$$c_{2, 1}$$$ becomes $$$6$$$. Initially, only the $$$1$$$-st species and the $$$1$$$-st class are unlocked. 2. Marina plays a run with the $$$1$$$-st species and the $$$1$$$-st class. Her score becomes $$$3$$$, and she unlocks the $$$2$$$-nd species and the $$$2$$$-nd class. 3. Marina plays a run with the $$$2$$$-nd species and the $$$1$$$-st class. Her score becomes $$$9$$$, and she unlocks the $$$3$$$-rd species and the $$$4$$$-th species. She has unlocked everything in $$$2$$$ runs. As in the $$$1$$$-st example, this is not the only way to unlock everything in $$$2$$$ runs. | 2,600 | false | true | false | false | false | false | true | false | false | false | 3,502 |
434E | One day, Okazaki Tomoya has bought a tree for Furukawa Nagisa's birthday. The tree is so strange that every node of the tree has a value. The value of the _i_-th node is _v__i_. Now Furukawa Nagisa and Okazaki Tomoya want to play a game on the tree. Let (_s_,u2009_e_) be the path from node _s_ to node _e_, we can write down the sequence of the values of nodes on path (_s_,u2009_e_), and denote this sequence as _S_(_s_,u2009_e_). We define the value of the sequence _G_(_S_(_s_,u2009_e_)) as follows. Suppose that the sequence is _z_0,u2009_z_1..._z__l_u2009-u20091, where _l_ is the length of the sequence. We define _G_(_S_(_s_,u2009_e_))u2009=u2009_z_0u2009Γu2009_k_0u2009+u2009_z_1u2009Γu2009_k_1u2009+u2009...u2009+u2009_z__l_u2009-u20091u2009Γu2009_k__l_u2009-u20091. If the path (_s_,u2009_e_) satisfies , then the path (_s_,u2009_e_) belongs to Furukawa Nagisa, otherwise it belongs to Okazaki Tomoya. Calculating who has more paths is too easy, so they want to play something more difficult. Furukawa Nagisa thinks that if paths (_p_1,u2009_p_2) and (_p_2,u2009_p_3) belong to her, then path (_p_1,u2009_p_3) belongs to her as well. Also, she thinks that if paths (_p_1,u2009_p_2) and (_p_2,u2009_p_3) belong to Okazaki Tomoya, then path (_p_1,u2009_p_3) belongs to Okazaki Tomoya as well. But in fact, this conclusion isn't always right. So now Furukawa Nagisa wants to know how many triplets (_p_1,u2009_p_2,u2009_p_3) are correct for the conclusion, and this is your task. Input The first line contains four integers _n_, _y_, _k_ and _x_xa0(1u2009β€u2009_n_u2009β€u2009105;xa02u2009β€u2009_y_u2009β€u2009109;xa01u2009β€u2009_k_u2009<u2009_y_;xa00u2009β€u2009_x_u2009<u2009_y_) β _n_ being the number of nodes on the tree. It is guaranteed that _y_ is a prime number. The second line contains _n_ integers, the _i_-th integer is _v__i_xa0(0u2009β€u2009_v__i_u2009<u2009_y_). Then follow _n_u2009-u20091 lines, each line contains two integers, denoting an edge of the tree. The nodes of the tree are numbered from 1 to _n_. | 3,000 | false | false | false | false | false | false | false | true | true | false | 8,103 |
748B | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. Input The input consists of only two strings _s_ and _t_ denoting the favorite Santa's patter and the resulting string. _s_ and _t_ are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. Output If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print Β«-1Β» (without quotes). Otherwise, the first line of output should contain the only integer _k_ (_k_u2009β₯u20090)xa0β the number of pairs of keys that should be swapped. The following _k_ lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. Examples Input helloworld ehoolwlroz Input hastalavistababy hastalavistababy Input merrychristmas christmasmerry | 1,500 | false | false | true | false | false | false | false | false | false | false | 6,803 |
588A | Duff is addicted to meat! Malek wants to keep her happy for _n_ days. In order to be happy in _i_-th day, she needs to eat exactly _a__i_ kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In _i_-th day, they sell meat for _p__i_ dollars per kilogram. Malek knows all numbers _a_1,u2009...,u2009_a__n_ and _p_1,u2009...,u2009_p__n_. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future. Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for _n_ days. Input The first line of input contains integer _n_ (1u2009β€u2009_n_u2009β€u2009105), the number of days. In the next _n_ lines, _i_-th line contains two integers _a__i_ and _p__i_ (1u2009β€u2009_a__i_,u2009_p__i_u2009β€u2009100), the amount of meat Duff needs and the cost of meat in that day. Output Print the minimum money needed to keep Duff happy for _n_ days, in one line. Note In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 900 | false | true | false | false | false | false | false | false | false | false | 7,491 |
22B | Problem - 22B - 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 dp *1500 No tag edit access β Contest materials ") β the office room dimensions. Then there follow _n_ lines with _m_ characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free. Output Output one number β the maximum possible perimeter of a bargaining table for Bob's office room. Examples Input 3 3 000 010 000 Output 8 Input 5 4 1100 0000 0000 0000 0000 Output 16 | 1,500 | false | false | false | true | false | false | true | false | false | false | 9,887 |
45B | There are _n_ students studying in the 6th grade, in group "B" of a berland secondary school. Every one of them has exactly one friend whom he calls when he has some news. Let us denote the friend of the person number _i_ by _g_(_i_). Note that the friendships are not mutual, i.e. _g_(_g_(_i_)) is not necessarily equal to _i_. On day _i_ the person numbered as _a__i_ learns the news with the rating of _b__i_ (_b__i_u2009β₯u20091). He phones the friend immediately and tells it. While he is doing it, the news becomes old and its rating falls a little and becomes equal to _b__i_u2009-u20091. The friend does the same thing β he also calls his friend and also tells the news. The friend of the friend gets the news already rated as _b__i_u2009-u20092. It all continues until the rating of the news reaches zero as nobody wants to tell the news with zero rating. More formally, everybody acts like this: if a person _x_ learns the news with a non-zero rating _y_, he calls his friend _g_(_i_) and his friend learns the news with the rating of _y_u2009-u20091 and, if it is possible, continues the process. Let us note that during a day one and the same person may call his friend and tell him one and the same news with different ratings. Thus, the news with the rating of _b__i_ will lead to as much as _b__i_ calls. Your task is to count the values of _res__i_ β how many students learned their first news on day _i_. The values of _b__i_ are known initially, whereas _a__i_ is determined from the following formula: where mod stands for the operation of taking the excess from the cleavage, _res_0 is considered equal to zero and _v__i_ β some given integers. Input The first line contains two space-separated integers _n_ and _m_ (2u2009β€u2009_n_,u2009_m_u2009β€u2009105) β the number of students and the number of days. The second line contains _n_ space-separated integers _g_(_i_) (1u2009β€u2009_g_(_i_)u2009β€u2009_n_,u2009_g_(_i_)u2009β u2009_i_) β the number of a friend of the _i_-th student. The third line contains _m_ space-separated integers _v__i_ (1u2009β€u2009_v__i_u2009β€u2009107). The fourth line contains _m_ space-separated integers _b__i_ (1u2009β€u2009_b__i_u2009β€u2009107). Output Print _m_ lines containing one number each. The _i_-th line should contain _res__i_ β for what number of students the first news they've learned over the _m_ days in question, was the news number _i_. The number of the news is the number of the day on which it can be learned. The days are numbered starting from one in the order in which they are given in the input file. Don't output _res_0. | 2,200 | false | false | false | true | false | false | false | false | false | false | 9,758 |
1271D | You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $$$n$$$ castles of your opponent. Let's describe the game process in detail. Initially you control an army of $$$k$$$ warriors. Your enemy controls $$$n$$$ castles; to conquer the $$$i$$$-th castle, you need at least $$$a_i$$$ warriors (you are so good at this game that you don't lose any warriors while taking over a castle, so your army stays the same after the fight). After you take control over a castle, you recruit new warriors into your army β formally, after you capture the $$$i$$$-th castle, $$$b_i$$$ warriors join your army. Furthermore, after capturing a castle (or later) you can defend it: if you leave at least one warrior in a castle, this castle is considered defended. Each castle has an importance parameter $$$c_i$$$, and your total score is the sum of importance values over all defended castles. There are two ways to defend a castle: if you are currently in the castle $$$i$$$, you may leave one warrior to defend castle $$$i$$$; there are $$$m$$$ one-way portals connecting the castles. Each portal is characterised by two numbers of castles $$$u$$$ and $$$v$$$ (for each portal holds $$$u > v$$$). A portal can be used as follows: if you are currently in the castle $$$u$$$, you may send one warrior to defend castle $$$v$$$. Obviously, when you order your warrior to defend some castle, he leaves your army. You capture the castles in fixed order: you have to capture the first one, then the second one, and so on. After you capture the castle $$$i$$$ (but only before capturing castle $$$i + 1$$$) you may recruit new warriors from castle $$$i$$$, leave a warrior to defend castle $$$i$$$, and use any number of portals leading from castle $$$i$$$ to other castles having smaller numbers. As soon as you capture the next castle, these actions for castle $$$i$$$ won't be available to you. If, during some moment in the game, you don't have enough warriors to capture the next castle, you lose. Your goal is to maximize the sum of importance values over all defended castles (note that you may hire new warriors in the last castle, defend it and use portals leading from it even after you capture it β your score will be calculated afterwards). Can you determine an optimal strategy of capturing and defending the castles? Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 le n le 5000$$$, $$$0 le m le min(frac{n(n - 1)}{2}, 3 cdot 10^5)$$$, $$$0 le k le 5000$$$) β the number of castles, the number of portals and initial size of your army, respectively. Then $$$n$$$ lines follow. The $$$i$$$-th line describes the $$$i$$$-th castle with three integers $$$a_i$$$, $$$b_i$$$ and $$$c_i$$$ ($$$0 le a_i, b_i, c_i le 5000$$$) β the number of warriors required to capture the $$$i$$$-th castle, the number of warriors available for hire in this castle and its importance value. Then $$$m$$$ lines follow. The $$$i$$$-th line describes the $$$i$$$-th portal with two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 le v_i < u_i le n$$$), meaning that the portal leads from the castle $$$u_i$$$ to the castle $$$v_i$$$. There are no two same portals listed. It is guaranteed that the size of your army won't exceed $$$5000$$$ under any circumstances (i.u2009e. $$$k + sumlimits_{i = 1}^{n} b_i le 5000$$$). Output If it's impossible to capture all the castles, print one integer $$$-1$$$. Otherwise, print one integer equal to the maximum sum of importance values of defended castles. Examples Input 4 3 7 7 4 17 3 0 8 11 2 0 13 3 5 3 1 2 1 4 3 Input 4 3 7 7 4 17 3 0 8 11 2 0 13 3 5 3 1 2 1 4 1 Input 4 3 7 7 4 17 3 0 8 11 2 0 14 3 5 3 1 2 1 4 3 Note The best course of action in the first example is as follows: 1. capture the first castle; 2. hire warriors from the first castle, your army has $$$11$$$ warriors now; 3. capture the second castle; 4. capture the third castle; 5. hire warriors from the third castle, your army has $$$13$$$ warriors now; 6. capture the fourth castle; 7. leave one warrior to protect the fourth castle, your army has $$$12$$$ warriors now. This course of action (and several other ones) gives $$$5$$$ as your total score. The best course of action in the second example is as follows: 1. capture the first castle; 2. hire warriors from the first castle, your army has $$$11$$$ warriors now; 3. capture the second castle; 4. capture the third castle; 5. hire warriors from the third castle, your army has $$$13$$$ warriors now; 6. capture the fourth castle; 7. leave one warrior to protect the fourth castle, your army has $$$12$$$ warriors now; 8. send one warrior to protect the first castle through the third portal, your army has $$$11$$$ warriors now. This course of action (and several other ones) gives $$$22$$$ as your total score. In the third example it's impossible to capture the last castle: you need $$$14$$$ warriors to do so, but you can accumulate no more than $$$13$$$ without capturing it. | 2,100 | false | true | true | true | true | false | false | false | true | false | 4,332 |
1408F | You are given an integer $$$n$$$. You should find a list of pairs $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$, ..., $$$(x_q, y_q)$$$ ($$$1 leq x_i, y_i leq n$$$) satisfying the following condition. Let's consider some function $$$f: mathbb{N} imes mathbb{N} o mathbb{N}$$$ (we define $$$mathbb{N}$$$ as the set of positive integers). In other words, $$$f$$$ is a function that returns a positive integer for a pair of positive integers. Let's make an array $$$a_1, a_2, ldots, a_n$$$, where $$$a_i = i$$$ initially. You will perform $$$q$$$ operations, in $$$i$$$-th of them you will: 1. assign $$$t = f(a_{x_i}, a_{y_i})$$$ ($$$t$$$ is a temporary variable, it is used only for the next two assignments); 2. assign $$$a_{x_i} = t$$$; 3. assign $$$a_{y_i} = t$$$. In other words, you need to simultaneously change $$$a_{x_i}$$$ and $$$a_{y_i}$$$ to $$$f(a_{x_i}, a_{y_i})$$$. Note that during this process $$$f(p, q)$$$ is always the same for a fixed pair of $$$p$$$ and $$$q$$$. In the end, there should be at most two different numbers in the array $$$a$$$. It should be true for any function $$$f$$$. Find any possible list of pairs. The number of pairs should not exceed $$$5 cdot 10^5$$$. Output In the first line print $$$q$$$ ($$$0 leq q leq 5 cdot 10^5$$$)xa0β the number of pairs. In each of the next $$$q$$$ lines print two integers. In the $$$i$$$-th line print $$$x_i$$$, $$$y_i$$$ ($$$1 leq x_i, y_i leq n$$$). The condition described in the statement should be satisfied. If there exists multiple answers you can print any of them. Note In the first example, after performing the only operation the array $$$a$$$ will be $$$[f(a_1, a_2), f(a_1, a_2), a_3]$$$. It will always have at most two different numbers. In the second example, after performing two operations the array $$$a$$$ will be $$$[f(a_1, a_2), f(a_1, a_2), f(a_3, a_4), f(a_3, a_4)]$$$. It will always have at most two different numbers. | 2,300 | false | false | false | false | false | true | false | false | false | false | 3,631 |
299B | Problem - 299B - 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 *900 No tag edit access β Contest materials ? Input The first line contains two integers _n_ and _k_ (2u2009β€u2009_n_u2009β€u20093Β·105,u20091u2009β€u2009_k_u2009β€u20093Β·105). The next line contains _n_ characters β the description of the road: the _i_-th character equals ".", if the _i_-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". Output Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). Examples Input 2 1 .. Output YES Input 5 2 .#.#. Output YES Input 7 3 .#.###. Output NO | 900 | false | false | true | false | false | false | true | false | false | false | 8,636 |
278B | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of _n_ last problems β the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string. A substring _s_[_l_... _r_] (1u2009β€u2009_l_u2009β€u2009_r_u2009β€u2009_s_) of string _s_u2009=u2009_s_1_s_2... _s__s_ (where _s_ is the length of string _s_) is string _s__l__s__l_u2009+u20091... _s__r_. String _x_u2009=u2009_x_1_x_2... _x__p_ is lexicographically smaller than string _y_u2009=u2009_y_1_y_2... _y__q_, if either _p_u2009<u2009_q_ and _x_1u2009=u2009_y_1,u2009_x_2u2009=u2009_y_2,u2009... ,u2009_x__p_u2009=u2009_y__p_, or there exists such number _r_ (_r_u2009<u2009_p_,u2009_r_u2009<u2009_q_), that _x_1u2009=u2009_y_1,u2009_x_2u2009=u2009_y_2,u2009... ,u2009_x__r_u2009=u2009_y__r_ and _x__r_u2009+u20091u2009<u2009_y__r_u2009+u20091. The string characters are compared by their ASCII codes. Input The first line contains integer _n_ (1u2009β€u2009_n_u2009β€u200930) β the number of titles you've got to consider. Then follow _n_ problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. Output Print a string, consisting of lowercase English letters β the lexicographically minimum shortest original title. Examples Input 5 threehorses goodsubstrings secret primematrix beautifulyear Input 4 aa bdefghijklmn opqrstuvwxyz c Note In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j. In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,500 | false | false | false | false | false | false | true | false | false | false | 8,721 |
1987F2 | This is the hard version of the problem. The only difference between the two versions is the constraint on $$$n$$$. You can make hacks only if both versions of the problem are solved. You are given an array of integers $$$a$$$ of length $$$n$$$. In one operation, you will perform the following two-step process: 1. Choose an index $$$i$$$ such that $$$1 le i < a$$$ and $$$a_i = i$$$. 2. Remove $$$a_i$$$ and $$$a_{i+1}$$$ from the array and concatenate the remaining parts. Find the maximum number of times that you can perform the operation above. Input Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 le t le 100$$$)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 800$$$)xa0β the length of the array $$$a$$$. 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 $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$800$$$. Output For each test case, output a single integerxa0β the maximum number of times that you can perform the operation. Example Input 6 5 1 5 3 2 4 8 2 1 3 4 5 6 7 8 3 1 2 3 4 1 2 4 4 5 4 4 1 3 5 1 1 Note In the first test case, one possible optimal sequence of operations is $$$[ 1, 5, color{red}{3}, color{red}{2}, 4 ] ightarrow [color{red}{1}, color{red}{5}, 4] ightarrow [4]$$$. In the third test case, one possible optimal sequence of operations is $$$[1, color{red}{2}, color{red}{3}] ightarrow [1]$$$. | 2,600 | false | false | false | true | false | false | false | false | false | false | 351 |
475A | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. The event coordinator has a list of _k_ participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one. In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by _k_ participants. Your task is to draw the figure representing occupied seats. Input The only line of input contains integer _k_, (0u2009β€u2009_k_u2009β€u200934), denoting the number of participants. Output Print the figure of a bus with _k_ passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters. Examples Output +------------------------+ O.O.O.#.#.#.#.#.#.#.#.D) O.O.O.#.#.#.#.#.#.#.#.. O....................... O.O.#.#.#.#.#.#.#.#.#..) +------------------------+ Output +------------------------+ O.O.O.O.O.O.O.#.#.#.#.D) O.O.O.O.O.O.#.#.#.#.#.. O....................... O.O.O.O.O.O.#.#.#.#.#..) +------------------------+ | 1,100 | false | false | true | false | false | false | false | false | false | false | 7,934 |
1131E | Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings $$$s$$$ of length $$$m$$$ and $$$t$$$ is a string $$$t + s_1 + t + s_2 + ldots + t + s_m + t$$$, where $$$s_i$$$ denotes the $$$i$$$-th symbol of the string $$$s$$$, and "+" denotes string concatenation. For example, the product of strings "abc" and "de" is a string "deadebdecde", while the product of the strings "ab" and "z" is a string "zazbz". Note, that unlike the numbers multiplication, the product of strings $$$s$$$ and $$$t$$$ is not necessarily equal to product of $$$t$$$ and $$$s$$$. Roman was jealous of Denis, since he invented such a cool operation, and hence decided to invent something string-related too. Since Roman is beauty-lover, he decided to define the beauty of the string as the length of the longest substring, consisting of only one letter. For example, the beauty of the string "xayyaaabca" is equal to $$$3$$$, since there is a substring "aaa", while the beauty of the string "qwerqwer" is equal to $$$1$$$, since all neighboring symbols in it are different. In order to entertain Roman, Denis wrote down $$$n$$$ strings $$$p_1, p_2, p_3, ldots, p_n$$$ on the paper and asked him to calculate the beauty of the string $$$( ldots (((p_1 cdot p_2) cdot p_3) cdot ldots ) cdot p_n$$$, where $$$s cdot t$$$ denotes a multiplication of strings $$$s$$$ and $$$t$$$. Roman hasn't fully realized how Denis's multiplication works, so he asked you for a help. Denis knows, that Roman is very impressionable, he guarantees, that the beauty of the resulting string is at most $$$10^9$$$. Input The first line contains a single integer $$$n$$$ ($$$2 leq n leq 100,000$$$)xa0β the number of strings, wroted by Denis. Next $$$n$$$ lines contain non-empty strings $$$p_1, p_2, ldots, p_n$$$, consisting of lowercase english letters. It's guaranteed, that the total length of the strings $$$p_i$$$ is at most $$$100,000$$$, and that's the beauty of the resulting product is at most $$$10^9$$$. Note In the first example, the product of strings is equal to "abaaaba". In the second example, the product of strings is equal to "abanana". | 2,300 | false | true | false | true | false | false | false | false | false | false | 5,064 |
852E | John has just bought a new car and is planning a journey around the country. Country has _N_ cities, some of which are connected by bidirectional roads. There are _N_u2009-u20091 roads and every city is reachable from any other city. Cities are labeled from 1 to _N_. John first has to select from which city he will start his journey. After that, he spends one day in a city and then travels to a randomly choosen city which is directly connected to his current one and which he has not yet visited. He does this until he can't continue obeying these rules. To select the starting city, he calls his friend Jack for advice. Jack is also starting a big casino business and wants to open casinos in some of the cities (max 1 per city, maybe nowhere). Jack knows John well and he knows that if he visits a city with a casino, he will gamble exactly once before continuing his journey. He also knows that if John enters a casino in a good mood, he will leave it in a bad mood and vice versa. Since he is John's friend, he wants him to be in a good mood at the moment when he finishes his journey. John is in a good mood before starting the journey. In how many ways can Jack select a starting city for John and cities where he will build casinos such that no matter how John travels, he will be in a good mood at the end? Print answer modulo 109u2009+u20097. Input In the first line, a positive integer _N_ (1u2009β€u2009_N_u2009β€u2009100000), the number of cities. In the next _N_u2009-u20091 lines, two numbers _a_,u2009 _b_ (1u2009β€u2009_a_,u2009_b_u2009β€u2009_N_) separated by a single space meaning that cities _a_ and _b_ are connected by a bidirectional road. Output Output one number, the answer to the problem modulo 109u2009+u20097. Note Example 1: If Jack selects city 1 as John's starting city, he can either build 0 casinos, so John will be happy all the time, or build a casino in both cities, so John would visit a casino in city 1, become unhappy, then go to city 2, visit a casino there and become happy and his journey ends there because he can't go back to city 1. If Jack selects city 2 for start, everything is symmetrical, so the answer is 4. Example 2: If Jack tells John to start from city 1, he can either build casinos in 0 or 2 cities (total 4 possibilities). If he tells him to start from city 2, then John's journey will either contain cities 2 and 1 or 2 and 3. Therefore, Jack will either have to build no casinos, or build them in all three cities. With other options, he risks John ending his journey unhappy. Starting from 3 is symmetric to starting from 1, so in total we have 4u2009+u20092u2009+u20094u2009=u200910 options. | 2,100 | false | false | false | true | false | false | false | false | false | false | 6,339 |
1005E2 | You are given an integer sequence $$$a_1, a_2, dots, a_n$$$. Find the number of pairs of indices $$$(l, r)$$$ ($$$1 le l le r le n$$$) such that the value of median of $$$a_l, a_{l+1}, dots, a_r$$$ is exactly the given number $$$m$$$. The median of a sequence is the value of an element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $$$a=[4, 2, 7, 5]$$$ then its median is $$$4$$$ since after sorting the sequence, it will look like $$$[2, 4, 5, 7]$$$ and the left of two middle elements is equal to $$$4$$$. The median of $$$[7, 1, 2, 9, 6]$$$ equals $$$6$$$ since after sorting, the value $$$6$$$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $$$(l, r)$$$ ($$$1 le l le r le n$$$) such that the value of median of $$$a_l, a_{l+1}, dots, a_r$$$ is exactly the given number $$$m$$$. Input The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 le n,m le 2cdot10^5$$$) β the length of the given sequence and the required value of the median. The second line contains an integer sequence $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 2cdot10^5$$$). Note In the first example, the suitable pairs of indices are: $$$(1, 3)$$$, $$$(1, 4)$$$, $$$(1, 5)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$, $$$(2, 5)$$$, $$$(4, 5)$$$ and $$$(5, 5)$$$. | 2,400 | false | false | false | false | false | false | false | false | true | false | 5,657 |
1969F | Problem - 1969F - 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 greedy hashing implementation *3000 No tag edit access β Contest materials . The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le k$$$). Output Print one integer β the maximum number of coins you can earn. Examples Input 4 2 1 2 1 2 Output 0 Input 8 2 2 1 2 2 1 2 1 2 Output 1 Input 4 4 1 2 1 2 Output 2 Input 6 4 3 2 3 1 2 1 Output 3 Input 6 4 3 2 3 3 2 1 Output 2 Input 18 6 5 6 1 1 6 5 4 1 5 1 1 6 2 6 2 2 6 3 Output 6 Input 8 4 1 2 3 4 4 3 1 2 Output 2 Input 8 4 1 2 3 4 4 3 3 2 Output 3 | 3,000 | false | true | true | true | false | false | false | false | false | false | 487 |
2009C | Freya the Frog is traveling on the 2D coordinate plane. She is currently at point $$$(0,0)$$$ and wants to go to point $$$(x,y)$$$. In one move, she chooses an integer $$$d$$$ such that $$$0 leq d leq k$$$ and jumps $$$d$$$ spots forward in the direction she is facing. Initially, she is facing the positive $$$x$$$ direction. After every move, she will alternate between facing the positive $$$x$$$ direction and the positive $$$y$$$ direction (i.e., she will face the positive $$$y$$$ direction on her second move, the positive $$$x$$$ direction on her third move, and so on). What is the minimum amount of moves she must perform to land on point $$$(x,y)$$$? Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$) β the number of test cases. Each test case contains three integers $$$x$$$, $$$y$$$, and $$$k$$$ ($$$0 leq x, y leq 10^9, 1 leq k leq 10^9$$$). Output For each test case, output the number of jumps Freya needs to make on a new line. Example Input 3 9 11 3 0 10 8 1000000 100000 10 Note In the first sample, one optimal set of moves is if Freya jumps in the following way: ($$$0,0$$$) $$$ ightarrow$$$ ($$$2,0$$$) $$$ ightarrow$$$ ($$$2,2$$$) $$$ ightarrow$$$ ($$$3,2$$$) $$$ ightarrow$$$ ($$$3,5$$$) $$$ ightarrow$$$ ($$$6,5$$$) $$$ ightarrow$$$ ($$$6,8$$$) $$$ ightarrow$$$ ($$$9,8$$$) $$$ ightarrow$$$ ($$$9,11$$$). This takes 8 jumps. | 1,100 | true | false | true | false | false | false | false | false | false | false | 198 |
608A | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special β it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to _s_ and elevator initially starts on floor _s_ at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. Input The first line of input contains two integers _n_ and _s_ (1u2009β€u2009_n_u2009β€u2009100, 1u2009β€u2009_s_u2009β€u20091000)xa0β the number of passengers and the number of the top floor respectively. The next _n_ lines each contain two space-separated integers _f__i_ and _t__i_ (1u2009β€u2009_f__i_u2009β€u2009_s_, 1u2009β€u2009_t__i_u2009β€u20091000)xa0β the floor and the time of arrival in seconds for the passenger number _i_. Output Print a single integerxa0β the minimum amount of time in seconds needed to bring all the passengers to floor 0. Examples Input 5 10 2 77 3 33 8 21 9 12 10 64 Note In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: takes 1 second. 7. Pick up passenger 1. 8. Go to floor 0: takes 2 seconds. This gives a total of 2u2009+u20092u2009+u20094u2009+u20091u2009+u20092u2009=u200911 seconds. | 1,000 | true | false | true | false | false | false | false | false | false | false | 7,414 |
158B | Problem - 158B - Codeforces =============== xa0 , and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer _n_ (1u2009β€u2009_n_u2009β€u2009105) β the number of groups of schoolchildren. The second line contains a sequence of integers _s_1,u2009_s_2,u2009...,u2009_s__n_ (1u2009β€u2009_s__i_u2009β€u20094). The integers are separated by a space, _s__i_ is the number of children in the _i_-th group. Output Print the single number β the minimum number of taxis necessary to drive all children to Polycarpus. Examples Input 5 1 2 4 3 3 Output 4 Input 8 2 3 4 4 2 1 3 1 Output 5 Note In the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars. | 1,100 | false | true | true | false | false | false | false | false | false | false | 9,244 |
1975G | One day, Zimpha casually came up with a problem. As a member of "Zimpha fan club", you decided to solve that problem. You are given two strings $$$s$$$ and $$$t$$$ of length $$$n$$$ and $$$m$$$, respectively. Both strings only consist of lowercase English letters, - and *. You need to replace all occurrences of and -, observing the following rules: For each -, you must replace it with any lowercase English letter. For each *, you must replace it with a string of any (possibly, zero) length which only consists of lowercase English letters. Note that you can replace two different instances of - with different characters. You can also replace each two different instances of with different strings. Suppose $$$s$$$ and $$$t$$$ have been transformed into $$$s'$$$ and $$$t'$$$. Now you're wondering if there's a replacement that makes $$$s'=t'$$$. Input The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 leq n, m leq 2 cdot 10^6$$$)xa0β the length of the strings $$$s$$$ and $$$t$$$, respectively. The second line contains the string $$$s$$$ of length $$$n$$$. It is guaranteed that $$$s$$$ only consists of lowercase English letters, - and *. The third line contains the string $$$t$$$ of length $$$m$$$. It is guaranteed that $$$t$$$ only consists of lowercase English letters, - and *. Output For each test case, output "Yes" if there is a replacement that makes $$$s'=t'$$$, and output "No" otherwise. You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response). Examples Input 10 10 justmonika j-stsayori Input 13 11 asoulwangziji -soulg*z-y- Input 20 18 bulijiojio-dibuliduo *li*ji-*ox*i*-du*- Note In the second test case, we can transform both strings into ttklwxx. In $$$s$$$, - will be replaced with l. In $$$t$$$, will be replaced by the empty string with the first and second - will be replaced with k and w respectively. In the fifth test case, we can transform both strings into bulijiojioxdibuliduo. | 3,000 | true | true | false | false | false | false | false | false | false | false | 436 |
1624C | You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You can perform operations on it. In one operation you can replace any element of the array $$$a_i$$$ with $$$lfloor frac{a_i}{2} floor$$$, that is, by an integer part of dividing $$$a_i$$$ by $$$2$$$ (rounding down). See if you can apply the operation some number of times (possible $$$0$$$) to make the array $$$a$$$ become a permutation of numbers from $$$1$$$ to $$$n$$$xa0βthat is, so that it contains all numbers from $$$1$$$ to $$$n$$$, each exactly once. For example, if $$$a = [1, 8, 25, 2]$$$, $$$n = 4$$$, then the answer is yes. You could do the following: 1. Replace $$$8$$$ with $$$lfloor frac{8}{2} floor = 4$$$, then $$$a = [1, 4, 25, 2]$$$. 2. Replace $$$25$$$ with $$$lfloor frac{25}{2} floor = 12$$$, then $$$a = [1, 4, 12, 2]$$$. 3. Replace $$$12$$$ with $$$lfloor frac{12}{2} floor = 6$$$, then $$$a = [1, 4, 6, 2]$$$. 4. Replace $$$6$$$ with $$$lfloor frac{6}{2} floor = 3$$$, then $$$a = [1, 4, 3, 2]$$$. Input The first line of input data contains an integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0βthe number of test cases. Each test case contains exactly two lines. The first one contains an integer $$$n$$$ ($$$1 le n le 50$$$), the second one contains integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^9$$$). Output For each test case, output on a separate line: YES if you can make the array $$$a$$$ become a permutation of numbers from $$$1$$$ to $$$n$$$, NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response). Example Input 6 4 1 8 25 2 2 1 1 9 9 8 3 4 2 7 1 5 6 3 8 2 1 4 24 7 16 7 5 22 6 22 4 22 Output YES NO YES NO NO YES Note The first test case is explained in the text of the problem statement. In the second test case, it is not possible to get a permutation. | 1,100 | true | true | false | false | false | true | false | false | false | false | 2,498 |
1949D | You are designing a new video game. It has $$$n$$$ scenarios, which the player may play in any order, but each scenario must be played exactly once. When a player switches from a scenario to another scenario, the game shows a specially crafted transition video to make it all feel part of one big story. This video is specific to a pair of scenarios, but not to their order, in other words, the video playing when switching from scenario $$$a$$$ to scenario $$$b$$$ is the same as the video playing when switching from scenario $$$b$$$ to scenario $$$a$$$. Therefore, you need to create $$$frac{n(n-1)}{2}$$$ different transition videos, one for each possible pair of different scenarios. Each transition video can be either funny or scary. It is boring to see too many funny videos or too many scary videos in a row. Therefore, your goal is to create the videos in such a way that no matter in which order does the player approach the scenarios, they will never see more than $$$lceil frac{3n}{4} ceil$$$ transition videos of the same type in a row. You have already come up with ideas for at most $$$lfloor frac{n}{2} floor$$$ of the transition videos, and therefore already know if those will be funny or scary. Now you need to choose funny or scary for all other transition videos in such a way that the above requirement is satisfied. Input The first line contains a single integer $$$n$$$ ($$$2 le n le 24$$$)xa0β the number of scenarios in the game. The next $$$n$$$ lines describe the partial transition video plan. Each of those lines contains $$$n$$$ characters. The $$$j$$$-th character of the $$$i$$$-th line corresponds to the transition video between the $$$i$$$-th and the $$$j$$$-th scenarios. It will be F if the corresponding transition video will be funny, S if the corresponding transition video will be scary, ? if the corresponding transition video is still undecided, orxa0.xa0if $$$i=j$$$. It is guaranteed that the $$$i$$$-th character of the $$$j$$$-th line and the $$$j$$$-th character of the $$$i$$$-th line will be the same for all $$$i$$$ and $$$j$$$. It is guaranteed that at most $$$lfloor frac{n}{2} floor$$$ ($$$n$$$ divided by 2, rounded down) transition videos will already be decided, in other words, that at most $$$2lfloor frac{n}{2} floor$$$ characters in the input will be F or S. Output Print $$$n$$$ lines describing the full transition video plan in the same format as the input. Each of those lines must contain $$$n$$$ characters. The $$$j$$$-th character of the $$$i$$$-th line must be F if the corresponding transition video is funny, S if the corresponding transition video is scary, orxa0.xa0if $$$i=j$$$. Each ? character from the input must be replaced with either F or S, and all other characters from the input must remain unchanged. It must still hold that the $$$i$$$-th character of the $$$j$$$-th line and the $$$j$$$-th character of the $$$i$$$-th line are the same for all $$$i$$$ and $$$j$$$. For each permutation of the $$$n$$$ scenarios, it must hold that the transition videos corresponding to playing the scenarios in this order do not have more than $$$lceil frac{3n}{4} ceil$$$ ($$$3n$$$ divided by 4, rounded up) videos of the same type consecutively. If there are multiple solutions, print any of them. It can be proven that for all inputs satisfying the constraints of this problem a solution always exists. Examples Input 5 .?F?? ?.??? F?.S? ??S.? ????. Output .FFFF F.FFF FF.SF FFS.F FFFF. Input 12 .??????????? ?.?????????? ??.????????? ???.???????? ????.??????? ?????.?????? ??????.????? ???????.???? ????????.??? ?????????.?? ??????????.? ???????????. Output .SSSFFSSSSFS S.SFFSFSFFFS SS.SFFFSSSFS SFS.FFSSSSFS FFFF.FFFFFSF FSFFF.SFFSFF SFFSFS.SSSFS SSSSFFS.SSFS SFSSFFSS.SFS SFSSFSSSS.FS FFFFSFFFFF.F SSSSFFSSSSF. Note In the first sample: We are allowed $$$lceil frac{3cdot 5}{4} ceil=4$$$ transition videos of the same type in a row, but for any permutation of the 5 scenarios the player will see only 4 transition videos in total, therefore we can choose funny or scary freely. We must still respect the already chosen types. In the second sample: One of the 479001600 possible permutations of scenarios is 1, 7, 4, 12, 9, 8, 2, 6, 10, 3, 11, 5. The player will get the following sequence of transition videos for this permutation: SSSSSSSSSFS. Even though this sequence has 10 scary transition videos in total, it has only 9 scary transition videos in a row, which is the maximum allowed amount ($$$lceil frac{3cdot 12}{4} ceil=9$$$). | 2,600 | false | false | false | false | false | true | false | false | false | false | 589 |
1798C | The store sells $$$n$$$ types of candies with numbers from $$$1$$$ to $$$n$$$. One candy of type $$$i$$$ costs $$$b_i$$$ coins. In total, there are $$$a_i$$$ candies of type $$$i$$$ in the store. You need to pack all available candies in packs, each pack should contain only one type of candies. Formally, for each type of candy $$$i$$$ you need to choose the integer $$$d_i$$$, denoting the number of type $$$i$$$ candies in one pack, so that $$$a_i$$$ is divided without remainder by $$$d_i$$$. Then the cost of one pack of candies of type $$$i$$$ will be equal to $$$b_i cdot d_i$$$. Let's denote this cost by $$$c_i$$$, that is, $$$c_i = b_i cdot d_i$$$. After packaging, packs will be placed on the shelf. Consider the cost of the packs placed on the shelf, in order $$$c_1, c_2, ldots, c_n$$$. Price tags will be used to describe costs of the packs. One price tag can describe the cost of all packs from $$$l$$$ to $$$r$$$ inclusive if $$$c_l = c_{l+1} = ldots = c_r$$$. Each of the packs from $$$1$$$ to $$$n$$$ must be described by at least one price tag. For example, if $$$c_1, ldots, c_n = [4, 4, 2, 4, 4]$$$, to describe all the packs, a $$$3$$$ price tags will be enough, the first price tag describes the packs $$$1, 2$$$, the second: $$$3$$$, the third: $$$4, 5$$$. You are given the integers $$$a_1, b_1, a_2, b_2, ldots, a_n, b_n$$$. Your task is to choose integers $$$d_i$$$ so that $$$a_i$$$ is divisible by $$$d_i$$$ for all $$$i$$$, and the required number of price tags to describe the values of $$$c_1, c_2, ldots, c_n$$$ is the minimum possible. For a better understanding of the statement, look at the illustration of the first test case of the first test: Let's repeat the meaning of the notation used in the problem: $$$a_i$$$xa0β the number of candies of type $$$i$$$ available in the store. $$$b_i$$$xa0β the cost of one candy of type $$$i$$$. $$$d_i$$$xa0β the number of candies of type $$$i$$$ in one pack. $$$c_i$$$xa0β the cost of one pack of candies of type $$$i$$$ is expressed by the formula $$$c_i = b_i cdot d_i$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 100,000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 le n le 200,000$$$)xa0β the number of types of candies. Each of the next $$$n$$$ lines of each test case contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 le a_i le 10^9$$$, $$$1 le b_i le 10,000$$$)xa0β the number of candies and the cost of one candy of type $$$i$$$, respectively. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200,000$$$. Note In the first test case, you can choose $$$d_1 = 4$$$, $$$d_2 = 6$$$, $$$d_3 = 7$$$, $$$d_4 = 5$$$. Then the cost of packs will be equal to $$$[12, 12, 35, 35]$$$. $$$2$$$ price tags are enough to describe them, the first price tag for $$$c_1, c_2$$$ and the second price tag for $$$c_3, c_4$$$. It can be shown that with any correct choice of $$$d_i$$$, at least $$$2$$$ of the price tag will be needed to describe all the packs. Also note that this example is illustrated by a picture in the statement. In the second test case, with $$$d_1 = 4$$$, $$$d_2 = 2$$$, $$$d_3 = 10$$$, the costs of all packs will be equal to $$$20$$$. Thus, $$$1$$$ price tag is enough to describe all the packs. Note that $$$a_i$$$ is divisible by $$$d_i$$$ for all $$$i$$$, which is necessary condition. In the third test case, it is not difficult to understand that one price tag can be used to describe $$$2$$$nd, $$$3$$$rd and $$$4$$$th packs. And additionally a price tag for pack $$$1$$$ and pack $$$5$$$. Total: $$$3$$$ price tags. | 1,700 | true | true | false | false | false | false | false | false | false | false | 1,488 |
1800A | You were walking down the street and heard a sound. The sound was described by the string $$$s$$$ consisting of lowercase and uppercase Latin characters. Now you want to find out if the sound was a cat meowing. For the sound to be a meowing, the string can only contain the letters 'm', 'e', 'o' and 'w', in either uppercase or lowercase. Also: string must start with non-empty sequence consisting only of characters 'm' or 'M' it must be immediately followed by non-empty sequence consisting only of characters 'e' or 'E' it must be immediately followed by non-empty sequence consisting only of characters 'o' or 'O' it must be immediately followed by non-empty sequence consisting only of characters 'w' or 'W', this sequence ends the string, after it immediately comes the string end For example, strings "meow", "mmmEeOWww", "MeOooOw" describe a meowing, but strings "Mweo", "MeO", "moew", "MmEW", "meowmeow" do not. Determine whether the sound you heard was a cat meowing or something else. Input The first line of input data contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 le n le 50$$$) β the length of the string describing the sound. The second line of each test case contains a string $$$s$$$ of $$$n$$$ characters. The string describes the sound you heard and consists only of lowercase and uppercase Latin letters. Output For each test case, output on a separate line: YES if the sound was a cat meowing; NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response). Example Input 7 4 meOw 14 mMmeoOoWWWwwwW 3 mew 7 MmeEeUw 4 MEOW 6 MmyaVW 5 meowA Output YES YES NO NO YES NO NO Note In the first test case, the string consists of a sequence of characters 'm', 'e', 'O', 'w', which satisfies the definition of meowing. In the second test case, the string consists of a sequence of $$$3$$$ characters 'm' and 'M', one 'e', a sequence of $$$3$$$ characters 'o' and 'O' and a sequence of $$$7$$$ characters 'w' and 'W', which satisfies the definition of meowing. In the third test case, the string does not describe a meowing because it lacks a sequence of 'o' or 'O' characters between 'e' and 'w'. In the fourth test case, the string contains the character 'U', so it does not describe a meowing. | 800 | false | false | true | false | false | false | false | false | false | false | 1,475 |
234C | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last _n_ days. Thus, he got a sequence of numbers _t_1,u2009_t_2,u2009...,u2009_t__n_, where the _i_-th number is the temperature on the _i_-th day. Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer _k_ (1u2009β€u2009_k_u2009β€u2009_n_u2009-u20091) such that _t_1u2009<u20090,u2009_t_2u2009<u20090,u2009...,u2009_t__k_u2009<u20090 and _t__k_u2009+u20091u2009>u20090,u2009_t__k_u2009+u20092u2009>u20090,u2009...,u2009_t__n_u2009>u20090. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset. You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that. Input The first line contains a single integer _n_ (2u2009β€u2009_n_u2009β€u2009105) β the number of days for which Vasya has been measuring the temperature. The second line contains a sequence of _n_ integers _t_1,u2009_t_2,u2009...,u2009_t__n_ (_t__i_u2009β€u2009109) β the sequence of temperature values. Numbers _t__i_ are separated by single spaces. | 1,300 | false | false | true | true | false | false | false | false | false | false | 8,902 |
1251E1 | The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $$$n$$$ voters, and two ways to convince each of them to vote for you. The first way to convince the $$$i$$$-th voter is to pay him $$$p_i$$$ coins. The second way is to make $$$m_i$$$ other voters vote for you, and the $$$i$$$-th voter will vote for free. Moreover, the process of such voting takes place in several steps. For example, if there are five voters with $$$m_1 = 1$$$, $$$m_2 = 2$$$, $$$m_3 = 2$$$, $$$m_4 = 4$$$, $$$m_5 = 5$$$, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: $$${5} ightarrow {1, 5} ightarrow {1, 2, 3, 5} ightarrow {1, 2, 3, 4, 5}$$$. Calculate the minimum number of coins you have to spend so that everyone votes for you. Input The first line contains one integer $$$t$$$ ($$$1 le t le 5000$$$) β the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 le n le 5000$$$) β the number of voters. The next $$$n$$$ lines contains the description of voters. $$$i$$$-th line contains two integers $$$m_i$$$ and $$$p_i$$$ ($$$1 le p_i le 10^9, 0 le m_i < n$$$). It is guaranteed that the sum of all $$$n$$$ over all test cases does not exceed $$$5000$$$. Output For each test case print one integer β the minimum number of coins you have to spend so that everyone votes for you. Example Input 3 3 1 5 2 10 2 8 7 0 1 3 1 1 1 6 1 1 1 4 1 4 1 6 2 6 2 3 2 8 2 7 4 4 5 5 Note In the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: $$${3} ightarrow {1, 3} ightarrow {1, 2, 3}$$$. In the second example you don't need to buy votes. The set of people voting for you will change as follows: $$${1} ightarrow {1, 3, 5} ightarrow {1, 2, 3, 5} ightarrow {1, 2, 3, 5, 6, 7} ightarrow {1, 2, 3, 4, 5, 6, 7}$$$. In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: $$${2, 5} ightarrow {1, 2, 3, 4, 5} ightarrow {1, 2, 3, 4, 5, 6}$$$. | 2,300 | false | true | false | true | true | false | false | false | false | false | 4,437 |
1737F | Enter Register HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN Dytechlab Cup 2022 Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags constructive algorithms math number theory *3300 No tag edit access β Contest materials Announcement (en) Tutorial (en) PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST F. Ela and Prime GCD time limit per test2 seconds memory limit per test256 megabytes After a long, tough, but fruitful day at DTL, Ela goes home happily. She entertains herself by solving Competitive Programming problems. She prefers short statements, because she already read too many long papers and documentation at work. The problem of the day reads: You are given an integer $$$c$$$. Suppose that $$$c$$$ has $$$n$$$ divisors. You have to find a sequence with $$$n - 1$$$ integers $$$[a_1, a_2, ... a_{n - 1}]$$$, which satisfies the following conditions: Each element is strictly greater than $$$1$$$. Each element is a divisor of $$$c$$$. All elements are distinct. For all $$$1 le i < n - 1$$$, $$$gcd(a_i, a_{i + 1})$$$ is a prime number. In this problem, because $$$c$$$ can be too big, the result of prime factorization of $$$c$$$ is given instead. Note that $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$ and a prime number is a positive integer which has exactly $$$2$$$ divisors. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10^4$$$) - the number of test cases. The first line of each test case contains one integer $$$m$$$ ($$$1 le m le 16$$$) - the number of prime factor of $$$c$$$. The second line of each test case contains $$$m$$$ integers $$$b_1, b_2, ldots, b_m$$$ ($$$1 le b_i < 2^{20}$$$) β exponents of corresponding prime factors of $$$c$$$, so that $$$c = p_1^{b_1} cdot p_2^{b_2} cdot ldots cdot p_m^{b_m}$$$ and $$$n = (b_1 + 1)(b_2 + 1) ldots (b_m + 1)$$$ hold. $$$p_i$$$ is the $$$i$$$-th smallest prime number. It is guaranteed that the sum of $$$n cdot m$$$ over all test cases does not exceed $$$2^{20}$$$. Output Print the answer for each test case, one per line. If there is no sequence for the given $$$c$$$, print $$$-1$$$. Otherwise, print $$$n - 1$$$ lines. In $$$i$$$-th line, print $$$m$$$ space-separated integers. The $$$j$$$-th integer of $$$i$$$-th line is equal to the exponent of $$$j$$$-th prime number from $$$a_i$$$. If there are multiple answers, print any of them. Example input 5 2 1 1 1 1 3 1 1 1 1 4 2 2 1 output 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 1 1 0 0 1 0 1 1 1 1 0 0 -1 2 0 1 1 0 1 2 1 1 0 Note In each test case, the values of $$$c$$$ are $$$6$$$, $$$2$$$, $$$30$$$, $$$16$$$, and $$$12$$$ in that order. In the first test case, $$$1$$$, $$$2$$$, $$$3$$$, $$$6$$$ are divisors of $$$6$$$. Here, sequences $$$[2, 6, 3]$$$ and $$$[3, 6, 2]$$$ can be answer. Permutation $$$[3, 2, 6]$$$ is invalid because $$$gcd(a_1, a_2) = 1$$$ is not a prime number. In the forth test case, $$$1$$$, $$$2$$$, $$$4$$$, $$$8$$$, $$$16$$$ are divisors of $$$16$$$. Among the permutation of sequence $$$[2, 4, 8, 16]$$$, no valid answer exist. Codeforces (c) | 3,300 | true | false | false | false | false | true | false | false | false | false | 1,863 |
691F | Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a rectangle. A bag with _n_ balls, each with an integer written on it, is placed on the table. The first player reaches in and grabs a ball randomly (all balls have equal probability of being chosen) β the number written on this ball is the rectangle's width in meters. This ball is not returned to the bag, and the second player reaches into the bag and grabs another ball β the number written on this ball is the rectangle's height in meters. If the area of the rectangle is greater than or equal some threshold _p_ square meters, the players win. Otherwise, they lose. The organizers of the game are trying to select an appropriate value for _p_ so that the probability of a couple winning is not too high and not too low, but they are slow at counting, so they have hired you to answer some questions for them. You are given a list of the numbers written on the balls, the organizers would like to know how many winning pairs of balls exist for different values of _p_. Note that two pairs are different if either the first or the second ball is different between the two in pair, and two different balls with the same number are considered different. Input The input begins with a single positive integer _n_ in its own line (1u2009β€u2009_n_u2009β€u2009106). The second line contains _n_ positive integers β the _i_-th number in this line is equal to _a__i_ (1u2009β€u2009_a__i_u2009β€u20093Β·106), the number written on the _i_-th ball. The next line contains an integer _m_ (1u2009β€u2009_m_u2009β€u2009106), the number of questions you are being asked. Then, the following line contains _m_ positive integers β the _j_-th number in this line is equal to the value of _p_ (1u2009β€u2009_p_u2009β€u20093Β·106) in the _j_-th question you are being asked. Output For each question, print the number of winning pairs of balls that exist for the given value of _p_ in the separate line. | 2,200 | false | false | false | true | false | false | true | false | false | false | 7,042 |
1993A | Tim is doing a test consisting of $$$4n$$$ questions; each question has $$$4$$$ options: 'A', 'B', 'C', and 'D'. For each option, there are exactly $$$n$$$ correct answers corresponding to that option β meaning there are $$$n$$$ questions with the answer 'A', $$$n$$$ questions with the answer 'B', $$$n$$$ questions with the answer 'C', and $$$n$$$ questions with the answer 'D'. For each question, Tim wrote his answer on the answer sheet. If he could not figure out the answer, he would leave a question mark '?' for that question. You are given his answer sheet of $$$4n$$$ characters. What is the maximum number of correct answers Tim can get? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0β the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 le n le 100$$$). The second line of each test case contains a string $$$s$$$ of $$$4n$$$ characters ($$$s_i in { exttt{A}, exttt{B}, exttt{C}, exttt{D}, exttt{?}}$$$)xa0β Tim's answers for the questions. Output For each test case, print a single integerxa0β the maximum score that Tim can achieve. Example Input 6 1 ABCD 2 AAAAAAAA 2 AAAABBBB 2 ???????? 3 ABCABCABCABC 5 ACADC??ACAC?DCAABC?C Note In the first test case, there is exactly one question with each answer 'A', 'B', 'C', and 'D'; so it's possible that Tim gets all his answers correct. In the second test case, there are only two correct answers 'A' which makes him get exactly $$$2$$$ points in any case. In the third test case, Tim can get at most $$$2$$$ correct answers with option 'A' and $$$2$$$ correct answers with option 'B'. For example, he would get $$$4$$$ points if the answers were 'AACCBBDD'. In the fourth test case, he refuses to answer any question at all, which makes him get $$$0$$$ points. | 800 | false | true | true | false | false | false | false | false | false | false | 312 |
1971F | Problem - 1971F - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags binary search brute force dfs and similar geometry implementation math *1600 No tag edit access β Contest materials ") Editorial") $$$ greater than or equal to $$$r$$$ but strictly less than $$$r+1$$$. A lattice point is a point with integer coordinates. The Euclidean distance from $$$(0, 0)$$$ to the point $$$(x,y)$$$ is $$$sqrt{x^2 + y^2}$$$. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0β the number of test cases. The only line of each test case contains a single integer $$$r$$$ ($$$1 leq r leq 10^5$$$). The sum of $$$r$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output a single integerxa0β the number of lattice points that have an Euclidean distance $$$d$$$ from $$$(0, 0)$$$ such that $$$r leq d < r+1$$$. Example Input 6 1 2 3 4 5 1984 Output 8 16 20 24 40 12504 Note The points for the first three test cases are shown below. | 1,600 | true | false | true | false | false | false | true | true | false | false | 460 |
1910D | You are given an array $$$a_1, a_2, dots, a_n$$$, consisting of $$$n$$$ integers. You goal is to make is strictly increasing. To achieve that, you perform each of the following operations exactly once: first, remove any element; second, select any number of elements (possibly, none or all $$$n-1$$$) and add $$$1$$$ to them. Note that you are not allowed to rearrange the elements of the array. For the resulting array $$$a'$$$, $$$a'_1 < a'_2 < dots < a'_{n-1}$$$ should hold. Determine if it's possible to achieve that. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$)xa0β the number of elements of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^6$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 cdot 10^5$$$. Output For each testcase, print YES if it's possible to remove one element and add $$$1$$$ to some elements (possibly, none or all), so that the array becomes strictly increasing. Otherwise, print NO. Example Input 8 4 4 4 1 5 5 4 4 1 5 5 2 10 5 3 1 2 3 3 2 1 1 4 1 1 1 1 4 1 3 1 2 5 1 1 3 3 1 Output YES NO YES YES YES NO YES YES Note In the first testcase, you can remove the third element and add $$$1$$$ to the second and the last element. $$$a'$$$ will become $$$[4, 5, 6]$$$, which is strictly increasing. In the second testcase, there is no way to perform the operations, so that the result is strictly increasing. In the third testcase, you can remove either of the elements. In the fourth testcase, you are already given a strictly increasing array, but you still have to remove an element. The result $$$a'$$$ can be $$$[1, 3]$$$, for example. | 1,800 | false | true | false | false | false | false | false | false | false | false | 844 |
1847F | While tracking Diavolo's origins, Giorno receives a secret code from Polnareff. The code can be represented as an infinite sequence of positive integers: $$$a_1, a_2, dots $$$. Giorno immediately sees the pattern behind the code. The first $$$n$$$ numbers $$$a_1, a_2, dots, a_n$$$ are given. For $$$i > n$$$ the value of $$$a_i$$$ is $$$(a_{i-n} a_{i-n+1})$$$, where $$$$$$ denotes the . The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 leq n leq 2 cdot 10^5$$$ , $$$1 leq q leq 2 cdot 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,ldots,a_n$$$ ($$$0 leq a_i leq 10^9$$$)xa0β the parts of the code which define the pattern. The $$$i$$$-th line of the next $$$q$$$ lines contain a single integer $$$v_i$$$ ($$$0 leq v_i leq 10^9$$$)xa0β the question Giorno asks you. The sum of $$$n$$$ and $$$q$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output Print $$$q$$$ numbers. The $$$i$$$-th number is the answer to the $$$i$$$-th question asked by Giorno. Example Input 3 2 3 2 1 1 2 3 4 5 0 2 1 3 0 1 2 3 4 5 5 1 2 3 4 5 7 2 6 0 4 Output 1 3 -1 2 2 4 -1 -1 -1 3 8 1 5 Note In the first test case, $$$a = [2,1,3,3,ldots]$$$. For the first question, $$$a_1=2$$$ is the element with the smallest index greater than $$$1$$$. For the second question, $$$a_3=3$$$ is the element with the smallest index greater than $$$2$$$. For the third question, there is no index $$$i$$$ such that $$$a_i > 3$$$. | 2,500 | true | true | false | false | true | false | false | true | true | false | 1,195 |
1007C | This is an interactive problem. Vasya and Vitya play a game. Vasya thought of two integers $$$a$$$ and $$$b$$$ from $$$1$$$ to $$$n$$$ and Vitya tries to guess them. Each round he tells Vasya two numbers $$$x$$$ and $$$y$$$ from $$$1$$$ to $$$n$$$. If both $$$x=a$$$ and $$$y=b$$$ then Vitya wins. Else Vasya must say one of the three phrases: 1. $$$x$$$ is less than $$$a$$$; 2. $$$y$$$ is less than $$$b$$$; 3. $$$x$$$ is greater than $$$a$$$ or $$$y$$$ is greater than $$$b$$$. Vasya can't lie, but if multiple phrases are true, he may choose any of them. For example, if Vasya thought of numbers $$$2$$$ and $$$4$$$, then he answers with the phrase $$$3$$$ to a query $$$(3, 4)$$$, and he can answer with the phrase $$$1$$$ or phrase $$$3$$$ to a query $$$(1, 5)$$$. Help Vitya win in no more than $$$600$$$ rounds. Interaction First, you need to read the number $$$n$$$, after that you can make queries. To make a query, print two integers: $$$x$$$ and $$$y$$$ ($$$1 leq x, y leq n$$$), then flush the output. After each query, read a single integer $$$ans$$$ ($$$0 leq ans leq 3$$$). If $$$ans > 0$$$, then it is the number of the phrase said by Vasya. If $$$ans = 0$$$, it means that you win and your program should terminate. If you make more than $$$600$$$ queries or make an incorrect query, you will get Wrong Answer. Your solution will get Idleness Limit Exceeded, if you don't print anything or forget to flush the output. To flush you need to do the following right after printing a query and a line end: fflush(stdout) in C++; System.out.flush() in Java; stdout.flush() in Python; flush(output) in Pascal; For other languages see documentation. Hacks format For hacks, use the following format: In the first line, print a single integer $$$n$$$ ($$$1 leq n leq 10^{18}$$$)xa0β the upper limit of the numbers. In the second line, print two integers $$$a$$$ and $$$b$$$ ($$$1 leq a, b leq n$$$)xa0β the numbers which Vasya thought of. In the third line, print a single integer $$$m$$$ ($$$1 leq m leq 10^5$$$)xa0β the number of instructions for the interactor. In each of the next $$$m$$$ lines, print five integers: $$$x_i$$$, $$$y_i$$$, $$$r^{12}_i$$$, $$$r^{13}_i$$$, and $$$r^{23}_i$$$ ($$$1 leq x_i, y_i leq n$$$), where $$$r^{ST}_i$$$ equals to either number $$$S$$$ or number $$$T$$$. While answering the query $$$x,, y$$$, the interactor finds a number $$$i$$$ from $$$1$$$ to $$$n$$$ with the minimal value $$$x-x_i + y-y_i$$$. If multiple numbers can be chosen, the least $$$i$$$ is preferred. Then the interactor answers to the query, but if there are two phrases $$$S$$$ and $$$T$$$ that can be given, then $$$r^{ST}_i$$$ is chosen. For example, the sample test data file contains the following: 5 2 4 2 2 5 1 1 2 4 1 2 3 3 Note Let's analyze the sample test. The chosen numbers are $$$2$$$ and $$$4$$$. The interactor was given two instructions. For the query $$$(4, 3)$$$, it can return $$$2$$$ or $$$3$$$. Out of the two instructions the second one is chosen, so the interactor returns $$$a^{23}_2=3$$$. For the query $$$(3, 4)$$$, it can return only $$$3$$$. For the query $$$(3, 3)$$$, it can return $$$2$$$ or $$$3$$$. Out of the two instructions the first one is chosen (since in case of equal values, the least number is preferred), so the interactor returns $$$a^{23}_1=2$$$. For the query $$$(1, 5)$$$, it can return $$$1$$$ or $$$3$$$. Out of the two instructions the first one is chosen, so the interactor returns $$$a^{13}_1=1$$$. In the fifth query $$$(2, 4)$$$, the numbers are guessed correctly, the player wins. | 3,000 | false | false | false | false | false | false | false | true | false | false | 5,647 |
1065B | Vasya has got an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges $$$(1, 2)$$$ and $$$(2, 1)$$$ is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex. Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Input The only line contains two integers $$$n$$$ and $$$m~(1 le n le 10^5, 0 le m le frac{n (n - 1)}{2})$$$. It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges. Output In the only line print two numbers $$$min$$$ and $$$max$$$ β the minimum and maximum number of isolated vertices, respectively. Note In the first example it is possible to construct a graph with $$$0$$$ isolated vertices: for example, it should contain edges $$$(1, 2)$$$ and $$$(3, 4)$$$. To get one isolated vertex, we may construct a graph with edges $$$(1, 2)$$$ and $$$(1, 3)$$$. In the second example the graph will always contain exactly one isolated vertex. | 1,300 | false | false | false | false | false | true | false | false | false | true | 5,387 |
915F | Problem - 915F - 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 dsu graphs trees *2400 No tag edit access β Contest materials as the difference between maximum and minimum value of _a__i_ on a simple path connecting vertices _x_ and _y_. Your task is to calculate . Input The first line contains one integer number _n_ (1u2009β€u2009_n_u2009β€u2009106) β the number of vertices in the tree. The second line contains _n_ integer numbers _a_1, _a_2, ..., _a__n_ (1u2009β€u2009_a__i_u2009β€u2009106) β the numbers written on the vertices. Then _n_u2009-u20091 lines follow. Each line contains two integers _x_ and _y_ denoting an edge connecting vertex _x_ and vertex _y_ (1u2009β€u2009_x_,u2009_y_u2009β€u2009_n_, _x_u2009β u2009_y_). It is guaranteed that these edges denote a tree. Output Print one number equal to . Example Input 4 2 2 3 1 1 2 1 3 1 4 Output 6 | 2,400 | false | false | false | false | true | false | false | false | false | true | 6,070 |
1709A | There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door. There are three keysxa0β one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands. Can you open all the doors? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 18$$$)xa0β the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 le x le 3$$$)xa0β the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 le a, b, c le 3$$$)xa0β the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$. Output For each testcase, print "YES" if you can open all the doors. Otherwise, print "NO". Example Input 4 3 0 1 2 1 0 3 2 2 3 1 0 2 1 3 0 | 800 | true | true | true | false | false | false | true | false | false | false | 2,026 |
1929C | Sasha decided to give his girlfriend the best handbag, but unfortunately for Sasha, it is very expensive. Therefore, Sasha wants to earn it. After looking at earning tips on the internet, he decided to go to the casino. Sasha knows that the casino operates under the following rules. If Sasha places a bet of $$$y$$$ coins (where $$$y$$$ is a positive integer), then in case of winning, he will receive $$$y cdot k$$$ coins (i.e., his number of coins will increase by $$$y cdot (k - 1)$$$). And in case of losing, he will lose the entire bet amount (i.e., his number of coins will decrease by $$$y$$$). Note that the bet amount must always be a positive ($$$> 0$$$) integer and cannot exceed Sasha's current number of coins. Sasha also knows that there is a promotion at the casino: he cannot lose more than $$$x$$$ times in a row. Initially, Sasha has $$$a$$$ coins. He wonders whether he can place bets such that he is guaranteed to win any number of coins. In other words, is it true that for any integer $$$n$$$, Sasha can make bets so that for any outcome that does not contradict the rules described above, at some moment of time he will have at least $$$n$$$ coins. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$) β the number of test cases. The description of the test cases follows. The single line of each test case contains three integers $$$k, x$$$ and $$$a$$$ ($$$2 leq k leq 30$$$, $$$1 leq x leq 100$$$, $$$1 leq a leq 10^9$$$) β the number of times the bet is increased in case of a win, the maximum number of consecutive losses, and the initial number of coins Sasha has. Output For each test case, output "YES" (without quotes) if Sasha can achieve it and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes" and "Yes" will be recognized as a positive answer). Example Input 9 2 1 7 2 1 1 2 3 15 3 3 6 4 4 5 5 4 7 4 88 1000000000 25 69 231 13 97 18806 Output YES NO YES NO NO YES NO NO NO Note In the first test case, Sasha can proceed as follows: If Sasha places a bet for the first time or if he won the previous bet, then he places $$$1$$$ coin. If Sasha lost the previous bet, then he places $$$2$$$ coins. Note that Sasha cannot lose more than once in a row. It can be proven that with this strategy, Sasha can obtain as many coins as he wants. In the second test case, Sasha can only place $$$1$$$ coin for the first time. But in case of a loss, he will not be able to place any more bets, so he will not be able to guarantee having as many coins as he wants. | 1,400 | true | true | false | false | false | true | true | true | false | false | 715 |
722D | You are given a set _Y_ of _n_ distinct positive integers _y_1,u2009_y_2,u2009...,u2009_y__n_. Set _X_ of _n_ distinct positive integers _x_1,u2009_x_2,u2009...,u2009_x__n_ is said to generate set _Y_ if one can transform _X_ to _Y_ by applying some number of the following two operation to integers in _X_: 1. Take any integer _x__i_ and multiply it by two, i.e. replace _x__i_ with 2Β·_x__i_. 2. Take any integer _x__i_, multiply it by two and add one, i.e. replace _x__i_ with 2Β·_x__i_u2009+u20091. Note that integers in _X_ are not required to be distinct after each operation. Two sets of distinct integers _X_ and _Y_ are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal. Note, that any set of integers (or its permutation) generates itself. You are given a set _Y_ and have to find a set _X_ that generates _Y_ and the maximum element of _X_ is mininum possible. Input The first line of the input contains a single integer _n_ (1u2009β€u2009_n_u2009β€u200950u2009000)xa0β the number of elements in _Y_. The second line contains _n_ integers _y_1,u2009...,u2009_y__n_ (1u2009β€u2009_y__i_u2009β€u2009109), that are guaranteed to be distinct. Output Print _n_ integersxa0β set of distinct integers that generate _Y_ and the maximum element of which is minimum possible. If there are several such sets, print any of them. | 1,900 | false | true | false | false | true | false | false | true | false | false | 6,923 |
1651E | Let's denote the size of the maximum matching in a graph $$$G$$$ as $$$mathit{MM}(G)$$$. You are given a bipartite graph. The vertices of the first part are numbered from $$$1$$$ to $$$n$$$, the vertices of the second part are numbered from $$$n+1$$$ to $$$2n$$$. Each vertex's degree is $$$2$$$. For a tuple of four integers $$$(l, r, L, R)$$$, where $$$1 le l le r le n$$$ and $$$n+1 le L le R le 2n$$$, let's define $$$G'(l, r, L, R)$$$ as the graph which consists of all vertices of the given graph that are included in the segment $$$[l, r]$$$ or in the segment $$$[L, R]$$$, and all edges of the given graph such that each of their endpoints belongs to one of these segments. In other words, to obtain $$$G'(l, r, L, R)$$$ from the original graph, you have to remove all vertices $$$i$$$ such that $$$i otin [l, r]$$$ and $$$i otin [L, R]$$$, and all edges incident to these vertices. Calculate the sum of $$$mathit{MM}(G(l, r, L, R))$$$ over all tuples of integers $$$(l, r, L, R)$$$ having $$$1 le l le r le n$$$ and $$$n+1 le L le R le 2n$$$. Input The first line contains one integer $$$n$$$ ($$$2 le n le 1500$$$)xa0β the number of vertices in each part. Then $$$2n$$$ lines follow, each denoting an edge of the graph. The $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 le x_i le n$$$; $$$n + 1 le y_i le 2n$$$)xa0β the endpoints of the $$$i$$$-th edge. There are no multiple edges in the given graph, and each vertex has exactly two incident edges. Output Print one integerxa0β the sum of $$$mathit{MM}(G(l, r, L, R))$$$ over all tuples of integers $$$(l, r, L, R)$$$ having $$$1 le l le r le n$$$ and $$$n+1 le L le R le 2n$$$. | 2,600 | true | true | false | false | false | true | true | false | false | false | 2,364 |
913G | Problem - 913G - Codeforces =============== xa0 ) digits. Here _length_(_m_) is the length of the decimal notation of _m_. Note that you don't have to minimize _k__i_. The decimal notations in this problem do not contain leading zeros. Input The first line contains a single integer _n_ (1u2009β€u2009_n_u2009β€u20092u2009000)xa0β the number of integers _a__i_. Each of the next _n_ lines contains a positive integer _a__i_ (1u2009β€u2009_a__i_u2009<u20091011). Output Print _n_ lines. The _i_-th of them should contain a positive integer _k__i_ such that the last _min_(100,u2009_length_(2_k__i_)) digits of 2_k__i_ contain the decimal notation of _a__i_ as a substring. Integers _k__i_ must satisfy 1u2009β€u2009_k__i_u2009β€u20091050. It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them. Examples Input 2 8 2 Output 3 1 Input 2 3 4857 Output 5 20 | 3,200 | true | false | false | false | false | false | false | false | false | false | 6,085 |
1526C1 | This is the easy version of the problem. The only difference is that in this version $$$n leq 2000$$$. You can make hacks only if both versions of the problem are solved. There are $$$n$$$ potions in a line, with potion $$$1$$$ on the far left and potion $$$n$$$ on the far right. Each potion will increase your health by $$$a_i$$$ when drunk. $$$a_i$$$ can be negative, meaning that potion will decrease will health. You start with $$$0$$$ health and you will walk from left to right, from first potion to the last one. At each potion, you may choose to drink it or ignore it. You must ensure that your health is always non-negative. What is the largest number of potions you can drink? Input The first line contains a single integer $$$n$$$ ($$$1 leq n leq 2000$$$) β the number of potions. The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ... ,$$$a_n$$$ ($$$-10^9 leq a_i leq 10^9$$$) which represent the change in health after drinking that potion. Output Output a single integer, the maximum number of potions you can drink without your health becoming negative. Note For the sample, you can drink $$$5$$$ potions by taking potions $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$ and $$$6$$$. It is not possible to drink all $$$6$$$ potions because your health will go negative at some point | 1,500 | false | true | false | true | true | false | true | false | false | false | 3,034 |
1588F | You are given an array of integers $$$a$$$ of size $$$n$$$ and a permutation $$$p$$$ of size $$$n$$$. There are $$$q$$$ queries of three types coming to you: 1. For given numbers $$$l$$$ and $$$r$$$, calculate the sum in array $$$a$$$ on the segment from $$$l$$$ to $$$r$$$: $$$sumlimits_{i=l}^{r} a_i$$$. 2. You are given two numbers $$$v$$$ and $$$x$$$. Let's build a directed graph from the permutation $$$p$$$: it has $$$n$$$ vertices and $$$n$$$ edges $$$i o p_i$$$. Let $$$C$$$ be the set of vertices that are reachable from $$$v$$$ in this graph. You should add $$$x$$$ to all $$$a_u$$$ such that $$$u$$$ is in $$$C$$$. 3. You are given indices $$$i$$$ and $$$j$$$. You should swap $$$p_i$$$ and $$$p_j$$$. The graph corresponding to the permutation $$$[2, 3, 1, 5, 4]$$$. Please, process all queries and print answers to queries of type $$$1$$$. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$)xa0β the size of the array and permutation. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$-10^8 le a_i le 10^8$$$). The third line contains $$$n$$$ distinct integers $$$p_1, p_2, ldots, p_n$$$ ($$$1 le p_i le n$$$). The fourth line contains a single integer $$$q$$$xa0β the number of queries ($$$1 le q le 2 cdot 10^5$$$). Next $$$q$$$ lines contain description of queries. The $$$i$$$-th of them starts with an integer $$$t_i$$$ ($$$1 le t_i le 3$$$)xa0β the query type. If $$$t_i = 1$$$, then the $$$i$$$-th line also contains two integers $$$l$$$, $$$r$$$ ($$$1 le l le r le n$$$). If $$$t_i = 2$$$, then the $$$i$$$-th line also contains two integers $$$v$$$, $$$x$$$ ($$$1 le v le n$$$, $$$-10^8 le x le 10^8$$$). If $$$t_i = 3$$$, then the $$$i$$$-th line also contains also two integers $$$i$$$, $$$j$$$ ($$$1 le i, j le n$$$). Output For every first type query, print a single integerxa0β the answer to this query. Examples Input 5 6 9 -5 3 0 2 3 1 5 4 6 1 1 5 2 1 1 1 1 5 3 1 5 2 1 -1 1 1 5 Input 8 -15 52 -4 3 5 9 0 5 2 4 6 8 1 3 5 7 10 2 2 2 2 5 -1 1 1 8 1 1 5 1 5 8 3 1 6 2 1 50 1 1 8 2 6 -20 1 1 8 Note In the first example: The graph corresponding to the initial permutation. There are $$$6$$$ queries. 1. The sum on the segment from $$$1$$$ to $$$5$$$ is $$$a_1 + a_2 + a_3 + a_4 + a_5 = 6 + 9 + (-5) + 3 + 0 = 13$$$. 2. If we start from $$$1$$$, we can reach $$${1, 2, 3}$$$. After this query $$$a$$$ is: $$$[7, 10, -4, 3, 0]$$$. 3. The sum on the segment from $$$1$$$ to $$$5$$$ is $$$a_1 + a_2 + a_3 + a_4 + a_5 = 6 + 9 + (-5) + 3 + 0 = 16$$$. 4. After this query $$$p = [4, 3, 1, 5, 2]$$$. The graph corresponding to the new permutation. 5. If we start from $$$2$$$, we can reach $$${1, 2, 3, 4, 5}$$$. After this query $$$a$$$ is: $$$[6, 9, -5, 2, -1]$$$. 6. The sum on the segment from $$$1$$$ to $$$5$$$ is $$$a_1 + a_2 + a_3 + a_4 + a_5 = 6 + 9 + (-5) + 2 + (-1) = 11$$$. | 3,500 | false | false | false | false | true | false | false | true | false | true | 2,694 |
1416D | You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Initially there is a single integer written on every vertex: the vertex $$$i$$$ has $$$p_i$$$ written on it. All $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$. You have to process $$$q$$$ queries of two types: $$$1$$$ $$$v$$$ β among all vertices reachable from the vertex $$$v$$$ using the edges of the graph (including the vertex $$$v$$$ itself), find a vertex $$$u$$$ with the largest number $$$p_u$$$ written on it, print $$$p_u$$$ and replace $$$p_u$$$ with $$$0$$$; $$$2$$$ $$$i$$$ β delete the $$$i$$$-th edge from the graph. Note that, in a query of the first type, it is possible that all vertices reachable from $$$v$$$ have $$$0$$$ written on them. In this case, $$$u$$$ is not explicitly defined, but since the selection of $$$u$$$ does not affect anything, you can choose any vertex reachable from $$$v$$$ and print its value (which is $$$0$$$). Input The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 le n le 2 cdot 10^5$$$; $$$1 le m le 3 cdot 10^5$$$; $$$1 le q le 5 cdot 10^5$$$). The second line contains $$$n$$$ distinct integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$, where $$$p_i$$$ is the number initially written on vertex $$$i$$$ ($$$1 le p_i le n$$$). Then $$$m$$$ lines follow, the $$$i$$$-th of them contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 le a_i, b_i le n$$$, $$$a_i e b_i$$$) and means that the $$$i$$$-th edge connects vertices $$$a_i$$$ and $$$b_i$$$. It is guaranteed that the graph does not contain multi-edges. Then $$$q$$$ lines follow, which describe the queries. Each line is given by one of the following formats: $$$1$$$ $$$v$$$ β denotes a query of the first type with a vertex $$$v$$$ ($$$1 le v le n$$$). $$$2$$$ $$$i$$$ β denotes a query of the second type with an edge $$$i$$$ ($$$1 le i le m$$$). For each query of the second type, it is guaranteed that the corresponding edge is not deleted from the graph yet. Output For every query of the first type, print the value of $$$p_u$$$ written on the chosen vertex $$$u$$$. Example Input 5 4 6 1 2 5 4 3 1 2 2 3 1 3 4 5 1 1 2 1 2 3 1 1 1 2 1 2 | 2,600 | false | false | true | false | true | false | false | false | false | true | 3,599 |
382D | Ksenia has a chessboard of size _n_u2009Γu2009_m_. Each cell of the chessboard contains one of the characters: "<", ">", "^", "v", "#". The cells that contain character "#" are blocked. We know that all chessboard cells that touch the border are blocked. Ksenia is playing with two pawns on this chessboard. Initially, she puts the pawns on the chessboard. One cell of the chessboard can contain two pawns if and only if the cell is blocked. In other cases two pawns can not stand in one cell. The game begins when Ksenia put pawns on the board. In one move, Ksenia moves each pawn to a side adjacent cell in the direction of arrows painted on the cell on which the corresponding pawn sits (if the pawn sits on "#", it does not move). Assume that Ksenia moves pawns simultaneously (see the second test case). Of course, Ksenia plays for points. How can one calculate the points per game? Very simply! Let's count how many movements the first pawn made and how many movements the second pawn made, sum these two numbers β it will be the resulting score of the game. Ksenia wonders: what is the maximum number of points she can earn (for that, she should place the pawns optimally well early in the game). Help her and find that number. Input The first line contains two integers, _n_ and _m_ (1u2009β€u2009_n_,u2009_m_u2009β€u20092000) β the sizes of the board. Each of the following _n_ lines contains _m_ characters β the board's description. Each character is one of the characters: "<", ">", "^", "v", "#". It is guaranteed that the border cells of the table are blocked cells (with character "#"). Output If Ksenia can get infinitely many points, print -1. Otherwise, print the maximum number of points she can get. Examples Input 7 5 ##### ##v## ##v## ##### ##^## ##^## ##### Input 7 5 ##### ##v## ##v## ##<## ##^## ##^## ##### | 2,200 | false | false | true | false | false | false | false | false | false | true | 8,300 |
1585F | Problem - 1585F - Codeforces =============== xa0 ") Editorial") , and $$$b_i eq b_{i+1}$$$ for every $$$i$$$ ($$$1 le i le n - 1$$$). The number of such arrays can be very large, so print it modulo $$$998,244,353$$$. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$)xa0β the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^9$$$). Output Print the answer modulo $$$998,244,353$$$ in a single line. Examples Input 3 2 2 2 Output 2 Input 2 2 3 Output 4 Input 3 1 1 1 Output 0 Note In the first test case possible arrays are $$$ | 2,400 | true | false | false | true | false | false | false | false | false | false | 2,697 |
1279E | Yeah, we failed to make up a New Year legend for this problem. A permutation of length $$$n$$$ is an array of $$$n$$$ integers such that every integer from $$$1$$$ to $$$n$$$ appears in it exactly once. An element $$$y$$$ of permutation $$$p$$$ is reachable from element $$$x$$$ if $$$x = y$$$, or $$$p_x = y$$$, or $$$p_{p_x} = y$$$, and so on. The decomposition of a permutation $$$p$$$ is defined as follows: firstly, we have a permutation $$$p$$$, all elements of which are not marked, and an empty list $$$l$$$. Then we do the following: while there is at least one not marked element in $$$p$$$, we find the leftmost such element, list all elements that are reachable from it in the order they appear in $$$p$$$, mark all of these elements, then cyclically shift the list of those elements so that the maximum appears at the first position, and add this list as an element of $$$l$$$. After all elements are marked, $$$l$$$ is the result of this decomposition. For example, if we want to build a decomposition of $$$p = [5, 4, 2, 3, 1, 7, 8, 6]$$$, we do the following: 1. initially $$$p = [5, 4, 2, 3, 1, 7, 8, 6]$$$ (bold elements are marked), $$$l = []$$$; 2. the leftmost unmarked element is $$$5$$$; $$$5$$$ and $$$1$$$ are reachable from it, so the list we want to shift is $$$[5, 1]$$$; there is no need to shift it, since maximum is already the first element; 3. $$$p = [ extbf{5}, 4, 2, 3, extbf{1}, 7, 8, 6]$$$, $$$l = [[5, 1]]$$$; 4. the leftmost unmarked element is $$$4$$$, the list of reachable elements is $$$[4, 2, 3]$$$; the maximum is already the first element, so there's no need to shift it; 5. $$$p = [ extbf{5}, extbf{4}, extbf{2}, extbf{3}, extbf{1}, 7, 8, 6]$$$, $$$l = [[5, 1], [4, 2, 3]]$$$; 6. the leftmost unmarked element is $$$7$$$, the list of reachable elements is $$$[7, 8, 6]$$$; we have to shift it, so it becomes $$$[8, 6, 7]$$$; 7. $$$p = [ extbf{5}, extbf{4}, extbf{2}, extbf{3}, extbf{1}, extbf{7}, extbf{8}, extbf{6}]$$$, $$$l = [[5, 1], [4, 2, 3], [8, 6, 7]]$$$; 8. all elements are marked, so $$$[[5, 1], [4, 2, 3], [8, 6, 7]]$$$ is the result. The New Year transformation of a permutation is defined as follows: we build the decomposition of this permutation; then we sort all lists in decomposition in ascending order of the first elements (we don't swap the elements in these lists, only the lists themselves); then we concatenate the lists into one list which becomes a new permutation. For example, the New Year transformation of $$$p = [5, 4, 2, 3, 1, 7, 8, 6]$$$ is built as follows: 1. the decomposition is $$$[[5, 1], [4, 2, 3], [8, 6, 7]]$$$; 2. after sorting the decomposition, it becomes $$$[[4, 2, 3], [5, 1], [8, 6, 7]]$$$; 3. $$$[4, 2, 3, 5, 1, 8, 6, 7]$$$ is the result of the transformation. We call a permutation good if the result of its transformation is the same as the permutation itself. For example, $$$[4, 3, 1, 2, 8, 5, 6, 7]$$$ is a good permutation; and $$$[5, 4, 2, 3, 1, 7, 8, 6]$$$ is bad, since the result of transformation is $$$[4, 2, 3, 5, 1, 8, 6, 7]$$$. Your task is the following: given $$$n$$$ and $$$k$$$, find the $$$k$$$-th (lexicographically) good permutation of length $$$n$$$. | 2,700 | false | false | false | true | false | false | false | false | false | false | 4,296 |
996A | Problem - 996A - Codeforces =============== xa0 ]( "Codeforces Round #492 . The denominations for dollar bills are $$$1$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$100$$$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer $$$n$$$ ($$$1 le n le 10^9$$$). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a $$$100$$$ dollar bill, a $$$20$$$ dollar bill, and a $$$5$$$ dollar bill. There is no way for Allen to receive $$$125$$$ dollars in one or two bills. In the second sample case, Allen can withdraw two $$$20$$$ dollar bills and three $$$1$$$ dollar bills. In the third sample case, Allen can withdraw $$$100000000$$$ (ten million!) $$$100$$$ dollar bills. | 800 | false | true | false | true | false | false | false | false | false | false | 5,720 |
1609A | William has array of $$$n$$$ numbers $$$a_1, a_2, dots, a_n$$$. He can perform the following sequence of operations any number of times: 1. Pick any two items from array $$$a_i$$$ and $$$a_j$$$, where $$$a_i$$$ must be a multiple of $$$2$$$ 2. $$$a_i = frac{a_i}{2}$$$ 3. $$$a_j = a_j cdot 2$$$ Help William find the maximal sum of array elements, which he can get by performing the sequence of operations described above. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10^4$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(1 le n le 15)$$$, the number of elements in William's array. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ $$$(1 le a_i < 16)$$$, the contents of William's array. Output For each test case output the maximal sum of array elements after performing an optimal sequence of operations. Example Input 5 3 6 4 2 5 1 2 3 4 5 1 10 3 2 3 4 15 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 Output 50 46 10 26 35184372088846 Note In the first example test case the optimal sequence would be: 1. Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_2 = frac{4}{2} = 2$$$ and $$$a_1 = 6 cdot 2 = 12$$$, making the array look as: [12, 2, 2]. 2. Pick $$$i = 2$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_2 = frac{2}{2} = 1$$$ and $$$a_1 = 12 cdot 2 = 24$$$, making the array look as: [24, 1, 2]. 3. Pick $$$i = 3$$$ and $$$j = 1$$$. After performing a sequence of operations $$$a_3 = frac{2}{2} = 1$$$ and $$$a_1 = 24 cdot 2 = 48$$$, making the array look as: [48, 1, 1]. The final answer $$$48 + 1 + 1 = 50$$$. In the third example test case there is no way to change the sum of elements, so the answer is $$$10$$$. | 900 | true | true | true | false | false | false | false | false | false | false | 2,608 |
1579E2 | Enter Register HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN Codeforces Round 744 (Div. 3) 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 greedy *1700 No tag edit access β Contest materials Announcement (ru) Tutorial PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST E2. Array Optimization by Deque time limit per test2 seconds memory limit per test256 megabytes In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems. You are given an integer array $$$a[1 ldots n] = [a_1, a_2, ldots, a_n]$$$. Let us consider an empty deque (double-ended queue). A deque is a data structure that supports adding elements to both the beginning and the end. So, if there are elements $$$[3, 4, 4]$$$ currently in the deque, adding an element $$$1$$$ to the beginning will produce the sequence $$$[color{red}{1}, 3, 4, 4]$$$, and adding the same element to the end will produce $$$[3, 4, 4, color{red}{1}]$$$. The elements of the array are sequentially added to the initially empty deque, starting with $$$a_1$$$ and finishing with $$$a_n$$$. Before adding each element to the deque, you may choose whether to add it to the beginning or to the end. For example, if we consider an array $$$a = [3, 7, 5, 5]$$$, one of the possible sequences of actions looks like this: $$$quad$$$ 1. add $$$3$$$ to the beginning of the deque: deque has a sequence $$$[color{red}{3}]$$$ in it; $$$quad$$$ 2. add $$$7$$$ to the end of the deque: deque has a sequence $$$[3, color{red}{7}]$$$ in it; $$$quad$$$ 3. add $$$5$$$ to the end of the deque: deque has a sequence $$$[3, 7, color{red}{5}]$$$ in it; $$$quad$$$ 4. add $$$5$$$ to the beginning of the deque: deque has a sequence $$$[color{red}{5}, 3, 7, 5]$$$ in it; Find the minimal possible number of inversions in the deque after the whole array is processed. An inversion in sequence $$$d$$$ is a pair of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$d_i > d_j$$$. For example, the array $$$d = [5, 3, 7, 5]$$$ has exactly two inversionsxa0β $$$(1, 2)$$$ and $$$(3, 4)$$$, since $$$d_1 = 5 > 3 = d_2$$$ and $$$d_3 = 7 > 5 = d_4$$$. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0β the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains an integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$)xa0β array size. The second line of the description contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 le a_i le 10^9$$$)xa0β elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be a single integerxa0β the minimal possible number of inversions in the deque after executing the described algorithm. Example input 6 4 3 7 5 5 3 3 2 1 3 3 1 2 4 -1 2 2 -1 4 4 5 1 3 5 1 3 1 3 2 output 2 0 1 0 1 2 Note One of the ways to get the sequence $$$[5, 3, 7, 5]$$$ in the deque, containing only two inversions, from the initial array $$$[3, 7, 5, 5]$$$ (the first sample test case) is described in the problem statement. Also, in this example, you could get the answer of two inversions by simply putting each element of the original array at the end of the deque. In this case, the original sequence $$$[3, 7, 5, 5]$$$, also containing exactly two inversions, will be in the deque as-is. Codeforces (c) | 1,700 | false | true | false | false | true | false | false | false | false | false | 2,736 |
347B | Problem - 347B - 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 *1100 No tag edit access β Contest materials appears exactly once in it. For example, sequence | 1,100 | true | false | true | false | false | false | true | false | false | false | 8,443 |
835A | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of _s_ characters. The first participant types one character in _v_1 milliseconds and has ping _t_1 milliseconds. The second participant types one character in _v_2 milliseconds and has ping _t_2 milliseconds. If connection ping (delay) is _t_ milliseconds, the competition passes for a participant as follows: 1. Exactly after _t_ milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly _t_ milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers _s_, _v_1, _v_2, _t_1, _t_2 (1u2009β€u2009_s_,u2009_v_1,u2009_v_2,u2009_t_1,u2009_t_2u2009β€u20091000)xa0β the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participantxa0β in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participantxa0β in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participantxa0β in 22 milliseconds. So, it is be a draw. | 800 | true | false | false | false | false | false | false | false | false | false | 6,427 |
275B | Problem - 275B - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags constructive algorithms implementation *1700 No tag edit access β Contest materials black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input The first line of the input contains two integers _n_ and _m_ (1u2009β€u2009_n_,u2009_m_u2009β€u200950) β the size of the grid. Each of the next _n_ lines contains _m_ characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Examples Input 3 4 WWBW BWWW WWWB Output NO Input 3 1 B B W Output YES | 1,700 | false | false | true | false | false | true | false | false | false | false | 8,733 |
1543D1 | This is the easy version of the problem. The only difference is that here $$$k=2$$$. You can make hacks only if both the versions of the problem are solved. This is an interactive problem. Every decimal number has a base $$$k$$$ equivalent. The individual digits of a base $$$k$$$ number are called $$$k$$$-its. Let's define the $$$k$$$-itwise XOR of two $$$k$$$-its $$$a$$$ and $$$b$$$ as $$$(a + b)bmod k$$$. The $$$k$$$-itwise XOR of two base $$$k$$$ numbers is equal to the new number formed by taking the $$$k$$$-itwise XOR of their corresponding $$$k$$$-its. The $$$k$$$-itwise XOR of two decimal numbers $$$a$$$ and $$$b$$$ is denoted by $$$aoplus_{k} b$$$ and is equal to the decimal representation of the $$$k$$$-itwise XOR of the base $$$k$$$ representations of $$$a$$$ and $$$b$$$. All further numbers used in the statement below are in decimal unless specified. When $$$k = 2$$$ (it is always true in this version), the $$$k$$$-itwise XOR is the same as the , also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between $$$0$$$ and $$$n-1$$$ inclusive. So, you have decided to guess it. Luckily, you can try at most $$$n$$$ times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was $$$x$$$, and you guess a different number $$$y$$$, then the system changes the password to a number $$$z$$$ such that $$$xoplus_{k} z=y$$$. Guess the password and break into the system. Input The first line of input contains a single integer $$$t$$$ ($$$1leq tleq 10,000$$$) denoting the number of test cases. $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ ($$$1leq nleq 2cdot 10^5$$$) and $$$k$$$ ($$$k=2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2cdot 10^5$$$. Interaction For each test case, first read two integers $$$n$$$ and $$$k$$$. Then you may ask up to $$$n$$$ queries. For each query, print a single integer $$$y$$$ ($$$0leq yleq 2cdot 10^7$$$). Let the current password be $$$x$$$. After that, read an integer $$$r$$$. If $$$x=y$$$, you will read $$$r=1$$$ and the test case is solved. You must then continue solving the remaining test cases. Else, you will read $$$r=0$$$. At this moment the password is changed to a number $$$z$$$ such that $$$xoplus_{k} z=y$$$. After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get the Idleness limit exceeded verdict. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see documentation for other languages. If you ask an invalid query or exceed $$$n$$$ queries, you will read $$$r=-1$$$ and you will receive the Wrong Answer verdict. Make sure to exit immediately to avoid unexpected verdicts. Note that the interactor is adaptive. That is, the original password is not fixed in the beginning and may depend on your queries. But it is guaranteed that at any moment there is at least one initial password such that all the answers to the queries are consistent. Hacks: To use hacks, use the following format of tests: The first line should contain a single integer $$$t$$$ ($$$1leq tleq 10,000$$$) β the number of test cases. The first and only line of each test case should contain two integers $$$n$$$ ($$$1leq nleq 2cdot 10^5$$$) and $$$k$$$ ($$$k=2$$$) denoting the number of queries and the base respectively. The optimal original password is automatically decided by the adaptive interactor. You must ensure that the sum of $$$n$$$ over all test cases does not exceed $$$2cdot 10^5$$$. Note In the example test case, the hidden password is $$$2$$$. The first query is $$$3$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$1$$$ since $$$2oplus_2 1=3$$$. The second query is $$$4$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$5$$$ since $$$1oplus_2 5=4$$$. The third query is $$$5$$$. It is equal to the current password. So, $$$1$$$ is returned, and the job is done. Note that this initial password is taken just for the sake of explanation. When you submit, the interactor might behave differently because it is adaptive. | 1,700 | true | false | false | false | false | true | false | false | false | false | 2,925 |
633B | Problem - 633B - Codeforces =============== xa0 ]( "Announcement") xa0β the required number of trailing zeroes in factorial. Output First print _k_xa0β the number of values of _n_ such that the factorial of _n_ ends with _m_ zeroes. Then print these _k_ integers in increasing order. Examples Input 1 Output 5 5 6 7 8 9 Input 5 Output 0 Note The factorial of _n_ is equal to the product of all integers from 1 to _n_ inclusive, that is _n_!u2009=u20091Β·2Β·3Β·...Β·_n_. In the first sample, 5!u2009=u2009120, 6!u2009=u2009720, 7!u2009=u20095040, 8!u2009=u200940320 and 9!u2009=u2009362880. | 1,300 | true | false | false | false | false | true | true | false | false | false | 7,274 |
1391A | A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$. Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 le n le 100$$$). Output For every test, output any good permutation of length $$$n$$$ on a separate line. Example Output 1 3 1 2 4 3 5 2 7 1 6 Note For $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3 ext{ OR }1 = 3 geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3 ext{ OR }1 ext{ OR }2 = 3 geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1 ext{ OR }2 = 3 geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good. | 800 | true | false | false | false | false | true | false | false | false | false | 3,721 |
1948F | There are $$$n$$$ bags numbered from $$$1$$$ to $$$n$$$, the $$$i$$$-th bag contains $$$a_i$$$ golden coins and $$$b_i$$$ silver coins. The value of a gold coin is $$$1$$$. The value of a silver coin is either $$$0$$$ or $$$1$$$, determined for each silver coin independently ($$$0$$$ with probability $$$frac{1}{2}$$$, $$$1$$$ with probability $$$frac{1}{2}$$$). You have to answer $$$q$$$ independent queries. Each query is the following: $$$l$$$ $$$r$$$xa0β calculate the probability that the total value of coins in bags from $$$l$$$ to $$$r$$$ is strictly greater than the total value in all other bags. Input The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 le n, q le 3 cdot 10^5$$$)xa0β the number of bags and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$0 le a_i le 10^6$$$)xa0β the number of gold coins in the $$$i$$$-th bag. The third line contains $$$n$$$ integers $$$b_1, b_2, dots, b_n$$$ ($$$0 le b_i le 10^6$$$)xa0β the number of silver coins in the $$$i$$$-th bag. Next $$$q$$$ lines contain queries. The $$$j$$$-th of the next $$$q$$$ lines contains two integers $$$l_j$$$ and $$$r_j$$$ ($$$1 le l_j le r_j le n$$$)xa0β the description of the $$$j$$$-th query. Additional constraints on the input: the sum of the array $$$a$$$ doesn't exceed $$$10^6$$$; the sum of the array $$$b$$$ doesn't exceed $$$10^6$$$. Output For each query, print one integerxa0β the probability that the total value of coins in bags from $$$l$$$ to $$$r$$$ is strictly greater than the total value in all other bags, taken modulo $$$998244353$$$. Formally, the probability can be expressed as an irreducible fraction $$$frac{x}{y}$$$. You have to print the value of $$$x cdot y^{-1} bmod 998244353$$$, where $$$y^{-1}$$$ is an integer such that $$$y cdot y^{-1} bmod 998244353 = 1$$$. Examples Output 748683265 748683265 Input 4 3 2 3 4 5 1 0 7 3 3 3 2 3 1 4 Output 997756929 273932289 1 Note In both queries from the first example, the answer is $$$frac{1}{4}$$$. | 2,500 | true | false | false | false | false | false | false | false | false | false | 594 |
1990A | Alice and Bob are playing a game in an array $$$a$$$ of size $$$n$$$. They take turns to do operations, with Alice starting first. The player who can not operate will lose. At first, a variable $$$mx$$$ is set to $$$0$$$. In one operation, a player can do: Choose an index $$$i$$$ ($$$1 le i le n$$$) such that $$$a_{i} geq mx$$$ and set $$$mx$$$ to $$$a_{i}$$$. Then, set $$$a_{i}$$$ to $$$0$$$. Determine whether Alice has a winning strategy. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^3$$$)xa0β the number of test cases. For each test case: The first line contains an integer $$$n$$$ ($$$2 leq n leq 50$$$)xa0β the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 leq a_i leq n$$$)xa0β the elements of the array. Output For each test case, if Alice has a winning strategy, output "YES". Otherwise, output "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 5 2 2 1 2 1 1 3 3 3 3 4 3 3 4 4 4 1 2 2 2 Note In the first test case, Alice can choose $$$i=1$$$ since $$$a_1=2 ge mx=0$$$. After Alice's operation, $$$a=[0,1]$$$ and $$$mx=2$$$. Bob can not do any operation. Alice wins. In the second test case, Alice doesn't have a winning strategy. For example, if Alice chooses $$$i=1$$$, after Alice's operation: $$$a=[0,1]$$$ and $$$mx=1$$$. Then, Bob can choose $$$i=2$$$ since $$$a_2=1 ge mx=1$$$. After Bob's operation: $$$a=[0,0]$$$ and $$$mx=1$$$. Alice can not do any operation. Bob wins. | 900 | false | true | false | false | false | false | true | false | true | false | 335 |
1487G | You have $$$c_1$$$ letters 'a', $$$c_2$$$ letters 'b', ..., $$$c_{26}$$$ letters 'z'. You want to build a beautiful string of length $$$n$$$ from them (obviously, you cannot use the $$$i$$$-th letter more than $$$c_i$$$ times). Each $$$c_i$$$ is greater than $$$frac{n}{3}$$$. A string is called beautiful if there are no palindromic contiguous substrings of odd length greater than $$$1$$$ in it. For example, the string "abacaba" is not beautiful, it has several palindromic substrings of odd length greater than $$$1$$$ (for example, "aca"). Another example: the string "abcaa" is beautiful. Calculate the number of different strings you can build, and print the answer modulo $$$998244353$$$. Input The first line contains one integer $$$n$$$ ($$$3 le n le 400$$$). The second line contains $$$26$$$ integers $$$c_1$$$, $$$c_2$$$, ..., $$$c_{26}$$$ ($$$frac{n}{3} < c_i le n$$$). Output Print one integer β the number of strings you can build, taken modulo $$$998244353$$$. Examples Input 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Input 3 2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 3 3 3 2 2 3 2 2 3 2 2 Input 400 348 322 247 158 209 134 151 267 268 176 214 379 372 291 388 135 147 304 169 149 193 351 380 368 181 340 | 2,700 | true | false | false | true | false | false | false | false | false | false | 3,240 |
1801F | Mom bought the boy Vasya a $$$n$$$-dimensional chocolate bar, which is a $$$n$$$-dimensional cube with the length of each side equal to $$$1$$$. The chocolate is planned to be divided into slices. According to the $$$i$$$th dimension, it can be divided by hyperplanes into $$$a_i$$$ equal parts. Thus, the chocolate is divided in total into $$$a_1 cdot a_2 cdot a_3 cdot ldots cdot a_n$$$ slices, each slice has a length of $$$i$$$-th dimension equal to $$$frac{1}{a_i}$$$, respectively, the volume of each slice is $$$frac{1}{a_1 a_2 cdots a_n}$$$. Vasya and his friends want to cut a chocolate bar to get at least $$$k$$$ pieces, while Vasya wants to maximize the volume of the smallest of them. It is possible to cut the chocolate bar only at the junction of the lobules, and each incision must pass through the entire chocolate bar along some hyperplane involved in the formation of lobules. Only after making all the cuts, Vasya disassembles the chocolate into pieces. More formally, Vasya wants to choose the numbers $$$b_1, b_2, dots, b_n$$$ ($$$1 le b_i le a_i$$$)xa0β the number of parts into which Vasya will cut the chocolate bar along each dimension. The condition $$$b_1 cdot b_2 cdot ldots cdot b_n ge k$$$ must be met to get at least $$$k$$$ pieces after all cuts. It can be noted that with optimal cutting with such parameters, the minimum piece will contain $$$lfloor frac{a_1}{b_1} floor dotsm lfloor frac{a_n}{b_n} floor$$$ slices, and its volume will be equal to $$$lfloor frac{a_1}{b_1} floor dotsm lfloor frac{a_n}{b_n} floor cdot frac{1}{a_1 a_2 cdots a_n}$$$. Vasya wants to get the maximum possible value of the volume of the minimum piece multiplied by $$$k$$$, that is, he wants to maximize the number of $$$lfloor frac{a_1}{b_1} floor dotsm lfloor frac{a_n}{b_n} floor cdot frac{1}{a_1 a_2 cdots a_n} cdot k$$$. Help him with this. Input The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 le n le 100$$$, $$$1 le k le 10^7)$$$xa0β the dimension of the chocolate bar, and how many parts it needs to be divided into. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ $$$(1 le a_i le 10^7)$$$xa0β the number of pieces on which the chocolate is placed along each of the dimensions. Output Print one number xa0β the maximum possible volume of the smallest of the obtained pieces, multiplied by $$$k$$$, with an absolute or relative error of no more than $$$10^{-9}$$$. If it is impossible to cut a chocolate bar into at least $$$k$$$ pieces under the given restrictions, output $$$0$$$. Note In the first example, a one β dimensional chocolate bar can be divided as follows: Then the answer will be $$$frac{2}{5} cdot 2 = 0.8$$$ In the second example, the chocolate bar can be cut as follows: Then the answer will be $$$frac{2}{5} cdot frac{3}{10} cdot 6 = 0.72$$$ In the third example, the chocolate bar can be cut as follows: Then the answer will be $$$frac{2}{4} cdot frac{1}{4} cdot 7 = 0.875$$$ | 2,700 | true | false | false | true | false | false | false | false | false | false | 1,461 |
1234B2 | The only difference between easy and hard versions are constraints on $$$n$$$ and $$$k$$$. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $$$k$$$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $$$0$$$). Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend. You (suddenly!) have the ability to see the future. You know that during the day you will receive $$$n$$$ messages, the $$$i$$$-th message will be received from the friend with ID $$$id_i$$$ ($$$1 le id_i le 10^9$$$). If you receive a message from $$$id_i$$$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages. Otherwise (i.e. if there is no conversation with $$$id_i$$$ on the screen): Firstly, if the number of conversations displayed on the screen is $$$k$$$, the last conversation (which has the position $$$k$$$) is removed from the screen. Now the number of conversations on the screen is guaranteed to be less than $$$k$$$ and the conversation with the friend $$$id_i$$$ is not displayed on the screen. The conversation with the friend $$$id_i$$$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $$$n$$$ messages. Input The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n, k le 2 cdot 10^5)$$$ β the number of messages and the number of conversations your smartphone can show. The second line of the input contains $$$n$$$ integers $$$id_1, id_2, dots, id_n$$$ ($$$1 le id_i le 10^9$$$), where $$$id_i$$$ is the ID of the friend which sends you the $$$i$$$-th message. Output In the first line of the output print one integer $$$m$$$ ($$$1 le m le min(n, k)$$$) β the number of conversations shown after receiving all $$$n$$$ messages. In the second line print $$$m$$$ integers $$$ids_1, ids_2, dots, ids_m$$$, where $$$ids_i$$$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $$$i$$$ after receiving all $$$n$$$ messages. Examples Input 10 4 2 3 3 1 1 2 1 2 3 3 Note In the first example the list of conversations will change in the following way (in order from the first to last message): $$$[]$$$; $$$[1]$$$; $$$[2, 1]$$$; $$$[3, 2]$$$; $$$[3, 2]$$$; $$$[1, 3]$$$; $$$[1, 3]$$$; $$$[2, 1]$$$. In the second example the list of conversations will change in the following way: $$$[]$$$; $$$[2]$$$; $$$[3, 2]$$$; $$$[3, 2]$$$; $$$[1, 3, 2]$$$; and then the list will not change till the end. | 1,300 | false | false | true | false | true | false | false | false | false | false | 4,523 |
1884E | Consider an array of integers $$$b_0, b_1, ldots, b_{n-1}$$$. Your goal is to make all its elements equal. To do so, you can perform the following operation several (possibly, zero) times: Pick a pair of indices $$$0 le l le r le n-1$$$, then for each $$$l le i le r$$$ increase $$$b_i$$$ by $$$1$$$ (i.xa0e. replace $$$b_i$$$ with $$$b_i + 1$$$). After performing this operation you receive $$$(r - l + 1)^2$$$ coins. The value $$$f(b)$$$ is defined as a pair of integers $$$(cnt, cost)$$$, where $$$cnt$$$ is the smallest number of operations required to make all elements of the array equal, and $$$cost$$$ is the largest total number of coins you can receive among all possible ways to make all elements equal within $$$cnt$$$ operations. In other words, first, you need to minimize the number of operations, second, you need to maximize the total number of coins you receive. You are given an array of integers $$$a_0, a_1, ldots, a_{n-1}$$$. Please, find the value of $$$f$$$ for all cyclic shifts of $$$a$$$. Formally, for each $$$0 le i le n-1$$$ you need to do the following: Let $$$c_j = a_{(j + i) pmod{n}}$$$ for each $$$0 le j le n-1$$$. Find $$$f(c)$$$. Since $$$cost$$$ can be very large, output it modulo $$$(10^9 + 7)$$$. Please note that under a fixed $$$cnt$$$ you need to maximize the total number of coins $$$cost$$$, not its remainder modulo $$$(10^9 + 7)$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 2 cdot 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^6$$$). The second line of each test case contains $$$n$$$ integers $$$a_0, a_1, ldots, a_{n-1}$$$ ($$$1 le a_i le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. Output For each test case, for each $$$0 le i le n-1$$$ output the value of $$$f$$$ for the $$$i$$$-th cyclic shift of array $$$a$$$: first, output $$$cnt$$$ (the minimum number of operations), then output $$$cost$$$ (the maximum number of coins these operations can give) modulo $$$10^9 + 7$$$. Example Input 5 1 1 3 1 3 2 5 3 2 4 5 1 8 6 5 6 4 2 6 2 2 4 10 10 10 10 Output 0 0 3 3 2 5 2 5 7 18 7 16 6 22 5 28 5 28 9 27 9 27 9 27 9 27 11 23 9 27 9 27 13 19 0 0 0 0 0 0 0 0 Note In the first test case, there is only one cycle shift, which is equal to $$$[1]$$$, and all its elements are already equal. In the second test case, you need to find the answer for three arrays: 1. $$$f([1, 3, 2]) = (3, 3)$$$. 2. $$$f([3, 2, 1]) = (2, 5)$$$. 3. $$$f([2, 1, 3]) = (2, 5)$$$. Consider the case of $$$[2, 1, 3]$$$. To make all elements equal, we can pick $$$l = 1$$$ and $$$r = 1$$$ on the first operation, which results in $$$[2, 2, 3]$$$. On the second operation we can pick $$$l = 0$$$ and $$$r = 1$$$, which results in $$$[3, 3, 3]$$$. We have used $$$2$$$ operations, and the total number of coins received is $$$1^2 + 2^2 = 5$$$. | 2,800 | true | true | true | false | false | false | false | false | false | false | 979 |
1090K | , # Problem A. Right Expansion Of The Mind Time limit: 2 seconds Memory limit: 512 megabytes One day n people decided to expand their mind. Initially, the mind of the i-th person is two strings si and ti consisting of lowercase English letters. After the expansion, the mind of the person becomes an infinite to the right string wi = si + ti + ti + Β· Β· Β· . That is, wi is a concatenation of si and the infinite number of ti. For example, if si = mi and ti = nd , the corresponding wi = mindndndnd . . . .Two persons with expanded mind are interested in each other, if the mind of the first person forms a subsequence of the mind of the second person, and the mind of the second person forms a subsequence of the mind of the first person. The infinite string a is called a subsequence of the infinite string b if there is an infinite sequence of indices 1 β€ i1 < i 2 < i 3 < . . . , such that for each j it is aj = bij . For example, the infinite string β baaa . . . β is a subsequence of an infinite string β cabababab . . . β. After having the mind expanded, people decided to split into groups in such way, that any two persons in one group are interested in each other. Your task is to split them into the groups, so that the number of groups is minimal possible. # Input The first line contains one integer n β the number of people that have decided to get their mind expanded (1 β€ n β€ 100 000 ). Each of the following n lines contains two non-empty strings si and ti, consisting of lowercase English letters. They represent the minds of every person before the mind expansion. It is guaranteed that the total length of all strings doesnβt exceed 1 000 000 . # Output The first line must contain one integer β the minimum number of groups. Then print each group in the following way: first print the number of people in this group and then the indices of them. Each of the indices must be printed exactly once. The groups and indices of the people in the group can be printed in any order. If there are multiple ways to split the people, you can print any of them. # Examples standard input standard output 5ab ab ababab ab a abb x y z w 33 1 2 3 1 4 1 5 3kokoko tlin koko kotlin ko kokotlin 21 1 2 2 3 Page 1 of 2 , # Note In the first example the expanded minds of the people look as follows: β’ βabababab... β β’ βabababab... β β’ βaabbabbabb... β β’ βxyyyyyy... β β’ βzwwwwww... βNeither person 4 nor 5 are interested in anybody else. However, the first three people show pairwise interest in each other. Hence it is possible to have the groups {1, 2, 3}, {4}, {5}. Page 2 of 2 | 2,000 | true | false | false | false | false | false | false | false | false | false | 5,262 |
1792C | You are given a permutation $$$p$$$ of length $$$n$$$ (a permutation of length $$$n$$$ is an array of length $$$n$$$ in which each integer from $$$1$$$ to $$$n$$$ occurs exactly once). You can perform the following operation any number of times (possibly zero): 1. choose two different elements $$$x$$$ and $$$y$$$ and erase them from the permutation; 2. insert the minimum of $$$x$$$ and $$$y$$$ into the permutation in such a way that it becomes the first element; 3. insert the maximum of $$$x$$$ and $$$y$$$ into the permutation in such a way that it becomes the last element. For example, if $$$p = [1, 5, 4, 2, 3]$$$ and we want to apply the operation to the elements $$$3$$$ and $$$5$$$, then after the first step of the operation, the permutation becomes $$$p = [1, 4, 2]$$$; and after we insert the elements, it becomes $$$p = [3, 1, 4, 2, 5]$$$. Your task is to calculate the minimum number of operations described above to sort the permutation $$$p$$$ in ascending order (i.u2009e. transform $$$p$$$ so that $$$p_1 < p_2 < dots < p_n$$$). 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 the test case contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$)xa0β the number of elements in the permutation. The second line of the test case contains $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$xa0β the given permutation $$$p$$$. The sum of $$$n$$$ over all test cases doesn't exceed $$$2 cdot 10^5$$$. Output For each test case, output a single integerxa0β the minimum number of operations described above to sort the array $$$p$$$ in ascending order. Example Input 4 5 1 5 4 2 3 3 1 2 3 4 2 1 4 3 6 5 2 4 1 6 3 Note In the first example, you can proceed as follows: 1. in the permutation $$$p = [1, 5, 4, 2, 3]$$$, let's choose the elements $$$4$$$ and $$$2$$$, then, after applying the operation, the permutation becomes $$$p = [2, 1, 5, 3, 4]$$$; 2. in the permutation $$$p = [2, 1, 5, 3, 4]$$$, let's choose the elements $$$1$$$ and $$$5$$$, then, after applying operation, the permutation becomes $$$p = [1, 2, 3, 4, 5]$$$. | 1,500 | true | true | false | false | false | false | true | true | false | false | 1,525 |
287B | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly _n_ houses in Ultimate Thule, Vova wants the city to have exactly _n_ pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters. A splitter is a construction that consists of one input (it can be connected to a water pipe) and _x_ output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., _k_ outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible. Vova needs the pipeline to have exactly _n_ pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters. Input The first line contains two space-separated integers _n_ and _k_ (1u2009β€u2009_n_u2009β€u20091018, 2u2009β€u2009_k_u2009β€u2009109). Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Print a single integer β the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | 1,700 | true | false | false | false | false | false | false | true | false | false | 8,685 |
938A | Problem - 938A - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags implementation *800 No tag edit access β Contest materials β the number of letters in word _s_ before the correction. The second line contains a string _s_ consisting of exactly _n_ lowercase Latin letters β the word before the correction. Output Output the word _s_ after the correction. Examples Input 5 weird Output werd Input 4 word Output word Input 5 aaeaa Output a Note Explanations of the examples: 1. There is only one replace: weird werd; 2. No replace needed since there are no two consecutive vowels; 3. aaeaa aeaa aaa aa a. | 800 | false | false | true | false | false | false | false | false | false | false | 5,951 |
1276C | Problem - 1276C - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags brute force combinatorics constructive algorithms data structures greedy math *2300 No tag edit access β Contest materials ") . Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the $$$n$$$ numbers may not be chosen. A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different. What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself. Input The first line contains $$$n$$$ ($$$1 le n le 4cdot10^5$$$). The second line contains $$$n$$$ integers ($$$1 le a_i le 10^9$$$). Output In the first line print $$$x$$$ ($$$1 le x le n$$$) β the total number of cells of the required maximum beautiful rectangle. In the second line print $$$p$$$ and $$$q$$$ ($$$p cdot q=x$$$): its sizes. In the next $$$p$$$ lines print the required rectangle itself. If there are several answers, print any. Examples Input 12 3 1 4 1 5 9 2 6 5 3 5 8 Output 12 3 4 1 2 3 5 3 1 5 4 5 6 8 9 Input 5 1 1 1 1 1 Output 1 1 1 1 | 2,300 | true | true | false | false | true | true | true | false | false | false | 4,313 |
135B | Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case. Input You are given 8 pairs of integers, a pair per line β the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide. Output Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed. Examples Input 0 0 10 11 10 0 0 11 1 1 2 2 2 1 1 2 Input 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 Input 0 0 4 4 4 0 0 4 1 2 2 3 3 2 2 1 Note Pay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes. | 1,600 | true | false | false | false | false | false | true | false | false | false | 9,336 |
604B | Kevin Sun wants to move his precious collection of _n_ cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into _k_ boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his _i_-th (1u2009β€u2009_i_u2009β€u2009_n_) cowbell is an integer _s__i_. In fact, he keeps his cowbells sorted by size, so _s__i_u2009-u20091u2009β€u2009_s__i_ for any _i_u2009>u20091. Also an expert packer, Kevin can fit one or two cowbells into a box of size _s_ if and only if the sum of their sizes does not exceed _s_. Given this information, help Kevin determine the smallest _s_ for which it is possible to put all of his cowbells into _k_ boxes of size _s_. Input The first line of the input contains two space-separated integers _n_ and _k_ (1u2009β€u2009_n_u2009β€u20092Β·_k_u2009β€u2009100u2009000), denoting the number of cowbells and the number of boxes, respectively. The next line contains _n_ space-separated integers _s_1,u2009_s_2,u2009...,u2009_s__n_ (1u2009β€u2009_s_1u2009β€u2009_s_2u2009β€u2009...u2009β€u2009_s__n_u2009β€u20091u2009000u2009000), the sizes of Kevin's cowbells. It is guaranteed that the sizes _s__i_ are given in non-decreasing order. Output Print a single integer, the smallest _s_ for which it is possible for Kevin to put all of his cowbells into _k_ boxes of size _s_. Note In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2,u20093}, {5} and {9}. In the third sample, the optimal solution is {3,u20095} and {7}. | 1,400 | false | true | false | false | false | false | false | true | false | false | 7,427 |
1466E | Only a few know that Pan and Apollo weren't only battling for the title of the GOAT musician. A few millenniums later, they also challenged each other in math (or rather in fast calculations). The task they got to solve is the following: Let $$$x_1, x_2, ldots, x_n$$$ be the sequence of $$$n$$$ non-negative integers. Find this value: $$$$$$sum_{i=1}^n sum_{j=1}^n sum_{k=1}^n (x_i , & , x_j) cdot (x_j , , x_k)$$$$$$ Here $$$&$$$ denotes the denoting the number of test cases, then $$$t$$$ test cases follow. The first line of each test case consists of a single integer $$$n$$$ ($$$1 leq n leq 5 cdot 10^5$$$), the length of the sequence. The second one contains $$$n$$$ non-negative integers $$$x_1, x_2, ldots, x_n$$$ ($$$0 leq x_i < 2^{60}$$$), elements of the sequence. The sum of $$$n$$$ over all test cases will not exceed $$$5 cdot 10^5$$$. Output Print $$$t$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th text case. Example Input 8 2 1 7 3 1 2 4 4 5 5 5 5 5 6 2 2 1 0 1 0 1 1 6 1 12 123 1234 12345 123456 5 536870912 536870911 1152921504606846975 1152921504606846974 1152921504606846973 Output 128 91 1600 505 0 1 502811676 264880351 | 1,800 | true | false | false | false | false | false | true | false | false | false | 3,362 |
538H | _T_ students applied into the ZPP class of Summer Irrelevant School. The organizing committee of the school may enroll any number of them, but at least _t_ students must be enrolled. The enrolled students should be divided into two groups in any manner (it is possible that one of the groups will be empty!) During a shift the students from the ZPP grade are tutored by _n_ teachers. Due to the nature of the educational process, each of the teachers should be assigned to exactly one of two groups (it is possible that no teacher will be assigned to some of the groups!). The _i_-th teacher is willing to work in a group as long as the group will have at least _l__i_ and at most _r__i_ students (otherwise it would be either too boring or too hard). Besides, some pairs of the teachers don't like each other other and therefore can not work in the same group; in total there are _m_ pairs of conflicting teachers. You, as the head teacher of Summer Irrelevant School, have got a difficult task: to determine how many students to enroll in each of the groups and in which group each teacher will teach. Input The first line contains two space-separated integers, _t_ and _T_ (1u2009β€u2009_t_u2009β€u2009_T_u2009β€u2009109). The second line contains two space-separated integers _n_ and _m_ (1u2009β€u2009_n_u2009β€u2009105, 0u2009β€u2009_m_u2009β€u2009105). The _i_-th of the next _n_ lines contain integers _l__i_ and _r__i_ (0u2009β€u2009_l__i_u2009β€u2009_r__i_u2009β€u2009109). The next _m_ lines describe the pairs of conflicting teachers. Each of these lines contain two space-separated integers β the indices of teachers in the pair. The teachers are indexed starting from one. It is guaranteed that no teacher has a conflict with himself and no pair of conflicting teachers occurs in the list more than once. Output If the distribution is possible, print in the first line a single word 'POSSIBLE' (without the quotes). In the second line print two space-separated integers _n_1 and _n_2xa0β the number of students in the first and second group, correspondingly, the contstraint _t_u2009β€u2009_n_1u2009+u2009_n_2u2009β€u2009_T_ should be met. In the third line print _n_ characters, the _i_-th of which should be 1 or 2, if the _i_-th teacher should be assigned to the first or second group, correspondingly. If there are multiple possible distributions of students and teachers in groups, you can print any of them. If the sought distribution doesn't exist, print a single word 'IMPOSSIBLE' (without the quotes). Examples Input 1 10 3 3 0 10 0 10 0 10 1 2 1 3 2 3 | 3,200 | false | true | false | false | true | false | false | false | false | false | 7,681 |
1881F | You have a tree with $$$n$$$ vertices, some of which are marked. A tree is a connected undirected graph without cycles. Let $$$f_i$$$ denote the maximum distance from vertex $$$i$$$ to any of the marked vertices. Your task is to find the minimum value of $$$f_i$$$ among all vertices. For example, in the tree shown in the example, vertices $$$2$$$, $$$6$$$, and $$$7$$$ are marked. Then the array $$$f(i) = [2, 3, 2, 4, 4, 3, 3]$$$. The minimum $$$f_i$$$ is for vertices $$$1$$$ and $$$3$$$. Input The first line contains an integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k le n le 2 cdot 10^5$$$)xa0β the number of vertices in the tree and the number of marked vertices, respectively. The second line of each test case contains $$$k$$$ integers $$$a_i$$$ ($$$1 le a_i le n, a_{i-1} < a_i$$$)xa0β the indices of the marked vertices. The next $$$n - 1$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ β the indices of vertices connected by the $$$i$$$-th edge. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output a single integer β the minimum value of $$$f_i$$$ among all vertices. Examples Input 6 7 3 2 6 7 1 2 1 3 2 4 2 5 3 6 3 7 4 4 1 2 3 4 1 2 2 3 3 4 5 1 1 1 2 1 3 1 4 1 5 5 2 4 5 1 2 2 3 1 4 4 5 10 8 1 2 3 4 5 8 9 10 2 10 10 5 5 3 3 1 1 7 7 4 4 9 8 9 6 1 10 9 1 2 4 5 6 7 8 9 10 1 3 3 9 9 4 4 10 10 6 6 7 7 2 2 5 5 8 Input 3 6 1 3 1 2 1 3 3 4 3 5 2 6 5 3 1 2 5 1 2 1 3 2 4 3 5 7 1 2 3 2 2 6 6 1 5 6 7 6 4 5 | 1,700 | false | false | false | true | false | false | false | false | false | true | 999 |
1055D | Alice has written a program and now tries to improve its readability. One of the ways to improve readability is to give sensible names to the variables, so now Alice wants to rename some variables in her program. In her IDE there is a command called "massive refactoring", which can replace names of many variable in just one run. To use it, Alice needs to select two strings $$$s$$$ and $$$t$$$ and after that for each variable the following algorithm is performed: if the variable's name contains $$$s$$$ as a substring, then the first (and only first) occurrence of $$$s$$$ is replaced with $$$t$$$. If the name doesn't contain $$$s$$$, then this variable's name stays the same. The list of variables is known and for each variable both the initial name and the name Alice wants this variable change to are known. Moreover, for each variable the lengths of the initial name and the target name are equal (otherwise the alignment of the code could become broken). You need to perform renaming of all variables in exactly one run of the massive refactoring command or determine that it is impossible. Input The first line contains the only integer $$$n$$$ ($$$1 le n le 3000$$$)xa0β the number of variables in Alice's program. The following $$$n$$$ lines contain the initial names of variables $$$w_1, w_2, ldots, w_n$$$, one per line. After that, $$$n$$$ more lines go, the $$$i$$$-th of them contains the target name $$$w'_i$$$ for the $$$i$$$-th variable. It is guaranteed that $$$1 le w_i = w'_i le 3000$$$. It is guaranteed that there is at least one variable having its target name different from the initial name. Both initial and target names consist of lowercase English letters only. For each variable the length of its initial name is equal to the length of its target name. Output If it is impossible to rename all variables with one call of "massive refactoring", print "NO" (quotes for clarity). Otherwise, on the first line print "YES" (quotes for clarity) and on the following lines print $$$s$$$ and $$$t$$$ ($$$1 le s, t le 5000$$$), which should be used for replacement. Strings $$$s$$$ and $$$t$$$ should consist only of lowercase letters of English alphabet. If there are multiple ways to perform a "massive refactoring", you can use any of them. Examples Output YES topforces codecoder | 2,400 | false | true | true | false | false | false | false | false | false | false | 5,436 |
1607C | Yelisey has an array $$$a$$$ of $$$n$$$ integers. If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it: 1. First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them. 2. Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$. For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$. Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible. Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$. Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0β the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 leq n leq 2 cdot 10^5$$$)xa0β the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 leq a_i leq 10^9$$$)xa0β elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integerxa0β the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it. Example Input 8 1 10 2 0 0 3 -1 2 0 4 2 10 1 7 2 2 3 5 3 2 -4 -2 0 2 -1 1 1 -2 Note In the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$. In the second set of input data, the array will always consist only of zeros. In the third set, the array will be changing as follows: $$$[color{blue}{-1}, 2, 0] o [3, color{blue}{1}] o [color{blue}{2}]$$$. The minimum elements are highlighted with $$$color{blue}{ ext{blue}}$$$. The maximal one is $$$2$$$. In the fourth set, the array will be modified as $$$[2, 10, color{blue}{1}, 7] o [color{blue}{1}, 9, 6] o [8, color{blue}{5}] o [color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$. | 1,000 | false | false | false | false | false | false | true | false | true | false | 2,621 |
2039F1 | This is the easy version of the problem. The only differences between the two versions of this problem are the constraints on $$$t$$$, $$$m$$$, and the sum of $$$m$$$. You can only make hacks if both versions of the problem are solved. For an integer array $$$a$$$ of length $$$n$$$, define $$$f(k)$$$ as the = operatorname{gcd}(operatorname{max}([2, 1, 4]), operatorname{max}([1, 4, 6]), operatorname{max}([4, 6, 2])) = operatorname{gcd}(4, 6, 6) = 2$$$. An array is good if $$$f(i) eq f(j)$$$ is satisfied over all pairs $$$1 le i lt j le n$$$. Shohag has an integer $$$m$$$. Help him count the number, modulo $$$998,244,353$$$, of non-empty good arrays of arbitrary length such that each element of the array is an integer from $$$1$$$ to $$$m$$$. $$$^{ ext{β}}$$$An array $$$d$$$ is a subarray of an array $$$c$$$ if $$$d$$$ can be obtained from $$$c$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements 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 an integer $$$m$$$ ($$$1 le m le 10^5$$$). It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output an integerxa0β the number of valid arrays modulo $$$998,244,353$$$. Note In the first test case, the valid arrays are $$$[1]$$$, $$$[1, 2]$$$, $$$[2]$$$, and $$$[2, 1]$$$. In the second test case, there are a total of $$$29$$$ valid arrays. In particular, the array $$$[2, 1, 4]$$$ with length $$$n = 3$$$ is valid because all elements are from $$$1$$$ to $$$m = 5$$$ and $$$f(1)$$$, $$$f(2)$$$ and $$$f(n = 3)$$$ all are distinct: $$$f(1) = operatorname{gcd}(operatorname{max}([2]), operatorname{max}([1]), operatorname{max}([4])) = operatorname{gcd}(2, 1, 4) = 1.$$$ $$$f(2) = operatorname{gcd}(operatorname{max}([2, 1]), operatorname{max}([1, 4])) = operatorname{gcd}(2, 4) = 2.$$$ $$$f(3) = operatorname{gcd}(operatorname{max}([2, 1, 4])) = operatorname{gcd}(4) = 4.$$$ | 2,800 | true | false | false | true | false | false | true | false | false | false | 18 |
2020F | Let $$$n$$$ and $$$d$$$ be positive integers. We build the the divisor tree $$$T_{n,d}$$$ as follows: The root of the tree is a node marked with number $$$n$$$. This is the $$$0$$$-th layer of the tree. For each $$$i$$$ from $$$0$$$ to $$$d - 1$$$, for each vertex of the $$$i$$$-th layer, do the following. If the current vertex is marked with $$$x$$$, create its children and mark them with all possible distinct divisors$$$^dagger$$$ of $$$x$$$. These children will be in the $$$(i+1)$$$-st layer. The vertices on the $$$d$$$-th layer are the leaves of the tree. For example, $$$T_{6,2}$$$ (the divisor tree for $$$n = 6$$$ and $$$d = 2$$$) looks like this: Define $$$f(n,d)$$$ as the number of leaves in $$$T_{n,d}$$$. Given integers $$$n$$$, $$$k$$$, and $$$d$$$, please compute $$$sumlimits_{i=1}^{n} f(i^k,d)$$$, modulo $$$10^9+7$$$. $$$^dagger$$$ In this problem, we say that an integer $$$y$$$ is a divisor of $$$x$$$ if $$$y ge 1$$$ and there exists an integer $$$z$$$ such that $$$x = y cdot z$$$. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10^4$$$). The description of the test cases follows. The only line of each test case contains three integers $$$n$$$, $$$k$$$, and $$$d$$$ ($$$1 le n le 10^9$$$, $$$1 le k,d le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^9$$$. Output For each test case, output $$$sumlimits_{i=1}^{n} f(i^k,d)$$$, modulo $$$10^9+7$$$. Note In the first test case, $$$n = 6$$$, $$$k = 1$$$, and $$$d = 1$$$. Thus, we need to find the total number of leaves in the divisor trees $$$T_{1,1}$$$, $$$T_{2,1}$$$, $$$T_{3,1}$$$, $$$T_{4,1}$$$, $$$T_{5,1}$$$, $$$T_{6,1}$$$. $$$T_{1,1}$$$ has only one leaf, which is marked with $$$1$$$. $$$T_{2,1}$$$ has two leaves, marked with $$$1$$$ and $$$2$$$. $$$T_{3,1}$$$ has two leaves, marked with $$$1$$$ and $$$3$$$. $$$T_{4,1}$$$ has three leaves, marked with $$$1$$$, $$$2$$$, and $$$4$$$. $$$T_{5,1}$$$ has two leaves, marked with $$$1$$$ and $$$5$$$. $$$T_{6,1}$$$ has four leaves, marked with $$$1$$$, $$$2$$$, $$$3$$$, and $$$6$$$. The total number of leaves is $$$1 + 2 + 2 + 3 + 2 + 4 = 14$$$. In the second test case, $$$n = 1$$$, $$$k = 3$$$, $$$d = 3$$$. Thus, we need to find the number of leaves in $$$T_{1,3}$$$, because $$$1^3 = 1$$$. This tree has only one leaf, so the answer is $$$1$$$. | 2,900 | true | false | false | true | false | false | false | false | false | false | 147 |
431B | Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower. Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2_i_u2009-u20091)-th man in the line (for the current moment) talks with the (2_i_)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower. We know that if students _i_ and _j_ talk, then the _i_-th student's happiness increases by _g__ij_ and the _j_-th student's happiness increases by _g__ji_. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower. Input The input consists of five lines, each line contains five space-separated integers: the _j_-th number in the _i_-th line shows _g__ij_ (0u2009β€u2009_g__ij_u2009β€u2009105). It is guaranteed that _g__ii_u2009=u20090 for all _i_. Assume that the students are numbered from 1 to 5. Note In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals: (_g_23u2009+u2009_g_32u2009+u2009_g_15u2009+u2009_g_51)u2009+u2009(_g_13u2009+u2009_g_31u2009+u2009_g_54u2009+u2009_g_45)u2009+u2009(_g_15u2009+u2009_g_51)u2009+u2009(_g_54u2009+u2009_g_45)u2009=u200932 . | 1,200 | false | false | true | false | false | false | true | false | false | false | 8,118 |
1622A | There are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$. You are asked to break exactly one of them into two pieces in such a way that: both pieces have positive (strictly greater than $$$0$$$) integer length; the total length of the pieces is equal to the original length of the stick; it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides. A square is also considered a rectangle. Determine if it's possible to do that. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β the number of testcases. The only line of each testcase contains three integers $$$l_1, l_2, l_3$$$ ($$$1 le l_i le 10^8$$$)xa0β the lengths of the sticks. Output For each testcase, print "YES" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as a positive answer). Example Input 4 6 1 5 2 5 2 2 4 2 5 5 4 Note In the first testcase, the first stick can be broken into parts of length $$$1$$$ and $$$5$$$. We can construct a rectangle with opposite sides of length $$$1$$$ and $$$5$$$. In the second testcase, breaking the stick of length $$$2$$$ can only result in sticks of lengths $$$1, 1, 2, 5$$$, which can't be made into a rectangle. Breaking the stick of length $$$5$$$ can produce results $$$2, 3$$$ or $$$1, 4$$$ but neither of them can't be put into a rectangle. In the third testcase, the second stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$2$$$ (which is a square). In the fourth testcase, the third stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$5$$$. | 800 | true | false | false | false | false | false | false | false | false | false | 2,511 |
980F | You are given a special connected undirected graph where each vertex belongs to at most one simple cycle. Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles). For each node, independently, output the maximum distance between it and a leaf in the resulting tree, assuming you were to remove the edges in a way that minimizes this distance. Input The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 leq n leq 5cdot 10^5$$$), the number of nodes and the number of edges, respectively. Each of the following $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 leq u,v leq n$$$, $$$u e v$$$), and represents an edge connecting the two nodes $$$u$$$ and $$$v$$$. Each pair of nodes is connected by at most one edge. It is guaranteed that the given graph is connected and each vertex belongs to at most one simple cycle. Output Print $$$n$$$ space-separated integers, the $$$i$$$-th integer represents the maximum distance between node $$$i$$$ and a leaf if the removed edges were chosen in a way that minimizes this distance. Examples Input 9 10 7 2 9 2 1 6 3 1 4 3 4 7 7 6 9 8 5 8 5 9 Note In the first sample, a possible way to minimize the maximum distance from vertex $$$1$$$ is by removing the marked edges in the following image: Note that to minimize the answer for different nodes, you can remove different edges. | 2,900 | false | false | false | true | false | false | false | false | false | true | 5,801 |
525B | Problem - 525B - Codeforces =============== xa0 ]( --- Finished β Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. β Problem tags constructive algorithms greedy math strings *1400 No tag edit access β Contest materials ") Editorial") from position _a__i_ to position _s_u2009-u2009_a__i_u2009+u20091. It is guaranteed that 2Β·_a__i_u2009β€u2009_s_. You face the following task: determine what Pasha's string will look like after _m_ days. Input The first line of the input contains Pasha's string _s_ of length from 2 to 2Β·105 characters, consisting of lowercase Latin letters. The second line contains a single integer _m_ (1u2009β€u2009_m_u2009β€u2009105)xa0βxa0 the number of days when Pasha changed his string. The third line contains _m_ space-separated elements _a__i_ (1u2009β€u2009_a__i_; 2Β·_a__i_u2009β€u2009_s_)xa0βxa0the position from which Pasha started transforming the string on the _i_-th day. Output In the first line of the output print what Pasha's string _s_ will look like after _m_ days. Examples Input abcdef 1 2 Output aedcbf Input vwxyz 2 2 2 Output vwxyz Input abcdef 3 1 2 3 Output fbdcea | 1,400 | true | true | false | false | false | true | false | false | false | false | 7,735 |
1842C | Enjoy erasing Tenzing, identified as Accepted! Tenzing has $$$n$$$ balls arranged in a line. The color of the $$$i$$$-th ball from the left is $$$a_i$$$. Tenzing can do the following operation any number of times: select $$$i$$$ and $$$j$$$ such that $$$1leq i < j leq a$$$ and $$$a_i=a_j$$$, remove $$$a_i,a_{i+1},ldots,a_j$$$ from the array (and decrease the indices of all elements to the right of $$$a_j$$$ by $$$j-i+1$$$). Tenzing wants to know the maximum number of balls he can remove. Input Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1leq tleq 10^3$$$) β the number of test cases. The description of test cases follows. The first line contains a single integer $$$n$$$ ($$$1leq nleq 2cdot 10^5$$$)xa0β the number of balls. The second line contains $$$n$$$ integers $$$a_1,a_2,ldots,a_n$$$ ($$$1leq a_i leq n$$$)xa0β the color of the balls. It is guaranteed that sum of $$$n$$$ of all test cases will not exceed $$$2cdot 10^5$$$. Output For each test case, output the maximum number of balls Tenzing can remove. Note In the first example, Tenzing will choose $$$i=2$$$ and $$$j=3$$$ in the first operation so that $$$a=[1,3,3]$$$. Then Tenzing will choose $$$i=2$$$ and $$$j=3$$$ again in the second operation so that $$$a=[1]$$$. So Tenzing can remove $$$4$$$ balls in total. In the second example, Tenzing will choose $$$i=1$$$ and $$$j=3$$$ in the first and only operation so that $$$a=[2]$$$. So Tenzing can remove $$$3$$$ balls in total. | 1,500 | false | false | false | true | false | false | false | false | false | false | 1,237 |
185D | The Great Mushroom King descended to the dwarves, but not everyone managed to see him. Only the few chosen ones could see the King. We know that only _LCM_(_k_2_l_u2009+u20091,u2009_k_2_l_u2009+u20091u2009+u20091,u2009...,u2009_k_2_r_u2009+u20091) dwarves can see the Great Mushroom King. Numbers _k_, _l_, _r_ are chosen by the Great Mushroom King himself in some complicated manner which is unclear to common dwarves. The dwarven historians decided to document all visits of the Great Mushroom King. For each visit the dwarven historians know three integers _k__i_, _l__i_, _r__i_, chosen by the Great Mushroom King for this visit. They also know a prime number _p__i_. Help them to count the remainder of dividing the number of dwarves who can see the King, by number _p__i_, for each visit. Input The first line contains the single integer _t_ (1u2009β€u2009_t_u2009β€u2009105) β the number of the King's visits. Each of the following _t_ input lines contains four space-separated integers _k__i_, _l__i_, _r__i_ and _p__i_ (1u2009β€u2009_k__i_u2009β€u2009106;xa00u2009β€u2009_l__i_u2009β€u2009_r__i_u2009β€u20091018;xa02u2009β€u2009_p__i_u2009β€u2009109) β the numbers, chosen by the Great Mushroom King and the prime module, correspondingly. It is guaranteed that for all visits number _p__i_ is prime. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Output For each visit print the answer on a single line β the remainder of dividing the number of the dwarves who can see the King this time, by number _p__i_. Print the answers for the visits in the order, in which the visits are described in the input. Note We consider that _LCM_(_a_1,u2009_a_2,u2009...,u2009_a__n_) represents the least common multiple of numbers _a_1, _a_2, ..., _a__n_. We consider that _x_0u2009=u20091, for any _x_. | 2,600 | true | false | false | false | false | false | false | false | false | false | 9,101 |
99B | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. Input The first line contains integer _n_ β the number of cups on the royal table (1u2009β€u2009_n_u2009β€u20091000). Next _n_ lines contain volumes of juice in each cup β non-negative integers, not exceeding 104. Output If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "_v_ ml. from cup #_a_ to cup #_b_." (without the quotes), where _v_ represents the volume of poured juice, _a_ represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), _b_ represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). Examples Output 20 ml. from cup #4 to cup #1. Output Unrecoverable configuration. | 1,300 | false | false | true | false | false | false | false | false | true | false | 9,490 |
317E | Princess Vlada enjoys springing in the meadows and walking in the forest. One day β wonderful, sunny day β during her walk Princess found out with astonishment that her shadow was missing! "Blimey!", β she thought and started her search of the shadow in the forest. Normally the Shadow is too lazy and simply sleeps under the Princess. But at this terrifically hot summer day she got bored of such a dull life, so she decided to play with Vlada. The forest, where our characters entertain themselves, may be represented as a set of integer cells in the plane, where the Shadow and the Princess can move only up, down, left and right by 1. Some cells (as it happens in decent forests) are occupied by trees. The Shadow and the Princess are not allowed to enter a cell occupied by a tree. Unfortunately, these are the hard times for the forest, so there are very few trees growing here... At first the Princess was walking within the cell (_v__x_,xa0_v__y_), while the Shadow hid from the Princess in the cell (_s__x_,xa0_s__y_). The Princess, The Shadow and the trees are located in the different cells. The Shadow is playing with the Princess. As soon as the Princess moves by 1 in some direction, the Shadow simultaneously flies by 1 in the same direction, if it is possible (if the cell to fly to is not occupied by some tree); otherwise, the Shadow doesn't move. The Shadow is very shadowy, so our characters do not interfere with each other. We say that the Shadow is caught by the Princess if after some move both of them are located in the same cell. Vlada managed to catch her Shadow! Can you? Input First line of the input contains the coordinates of the characters _v__x_, _v__y_, _s__x_, _s__y_ and the number of trees _m_ (0u2009β€u2009_m_u2009β€u2009400). The following _m_ lines contain the coordinates of the trees. All the coordinates are integers between -100 and 100, inclusive. The Princess, The Shadow and the trees are located in the different cells. Output If it is impossible for the Princess to catch the Shadow, print "-1" (without quotes). Otherwise print a sequence of characters "L", "R", "D", "U", corresponding to the Princess's moves, following which she will be able to catch the Shadow at some turn (L β move to the left, R β to the right, U β up, D β down; axis _x_ is directed to the right, _y_ β up). The number of characters (that is, the number of moves) must not exceed 106. All the Princess's moves should be correct, that is must not lead to the cell where a tree grows. It is allowed for the Princess and the Shadow to occupy the same cell before the last turn. Examples Input 5 0 3 0 8 2 -1 2 0 2 1 3 -1 4 1 4 0 3 1 4 -1 Note Below the pictures for the samples are given (Princess, Shadow and the trees are colored in pink, gray and black correspondingly; the blue dot marks the lattice center). In the first case the Princess may make two left steps, one step upwards and one right step: In the following case the Princess cannot catch the Shadow: In the last sample the Princess may make two left steps and one down step (in any order): | 3,100 | false | false | false | false | false | true | false | false | false | false | 8,561 |
1380C | Problem - 1380C - 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 dp greedy implementation sortings *1400 No tag edit access β Contest materials xa0β the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 le n le 10^5; 1 le x le 10^9$$$)xa0β the number of programmers and the restriction of team skill respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots , a_n$$$ ($$$1 le a_i le 10^9$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th programmer. The sum of $$$n$$$ over all inputs does not exceed $$$10^5$$$. Output For each test case print one integer β the maximum number of teams that you can assemble. Example Input 3 5 10 7 11 2 9 5 4 8 2 4 2 3 4 11 1 3 3 7 Output 2 1 0 | 1,400 | false | true | true | true | false | false | true | false | true | false | 3,769 |
1834C | Alice and Bob are playing a game. They have two strings $$$S$$$ and $$$T$$$ of the same length $$$n$$$ consisting of lowercase latin letters. Players take turns alternately, with Alice going first. On her turn, Alice chooses an integer $$$i$$$ from $$$1$$$ to $$$n$$$, one of the strings $$$S$$$ or $$$T$$$, and any lowercase latin letter $$$c$$$, and replaces the $$$i$$$-th symbol in the chosen string with the character $$$c$$$. On his turn, Bob chooses one of the strings $$$S$$$ or $$$T$$$, and reverses it. More formally, Bob makes the replacement $$$S := operatorname{rev}(S)$$$ or $$$T := operatorname{rev}(T)$$$, where $$$operatorname{rev}(P) = P_n P_{n-1} ldots P_1$$$. The game lasts until the strings $$$S$$$ and $$$T$$$ are equal. As soon as the strings become equal, the game ends instantly. Define the duration of the game as the total number of moves made by both players during the game. For example, if Alice made $$$2$$$ moves in total, and Bob made $$$1$$$ move, then the duration of this game is $$$3$$$. Alice's goal is to minimize the duration of the game, and Bob's goal is to maximize the duration of the game. What will be the duration of the game, if both players play optimally? It can be shown that the game will end in a finite number of turns. 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 a single integer $$$n$$$ ($$$1 le n le 10^5$$$)xa0β the length of the strings $$$S$$$ and $$$T$$$. The second line of each test case contains a string $$$S$$$ of length $$$n$$$ consisting of lowercase latin letters. The third line of each test case contains a string $$$T$$$ of length $$$n$$$ consisting of lowercase latin letters. 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 on a separate linexa0β the duration of the described game, if both players play optimally. Example Input 7 5 abcde abxde 5 hello olleo 2 ab cd 7 aaaaaaa abbbbba 1 q q 6 yoyoyo oyoyoy 8 abcdefgh hguedfbh Note In the first test case, in her turn, Alice can replace the third symbol of the string $$$S$$$ with x. After that, both strings will become equal to "abxde" and the game will end after one move. Since Alice's goal is to finish the game in as few moves as possible, this move will be one of her optimal first moves, and the final answer will be $$$1$$$. In the second test case, in her turn, Alice can replace the fifth symbol of the string $$$T$$$ with h. After this move, $$$S =$$$ "hello", $$$T =$$$ "olleh". Then Bob makes his turn. In his turn, he must reverse one of the strings. If Bob chooses the string $$$S$$$, then after his turn both strings will be equal to "olleh", and if he chooses the string $$$T$$$, then after his turn both strings will be equal to "hello". Thus, after the presented first move of Alice, the game will definitely end in $$$2$$$ moves. It can be shown that there is no strategy for Alice to finish the game in less than $$$2$$$ moves, with both players playing optimally. The final answer is $$$2$$$. In the third test case, in her first move, Alice can replace the second symbol of the string $$$S$$$ with c. After this move, $$$S =$$$ "ac", $$$T =$$$ "cd". Then Bob makes his turn. If Bob reverses the string $$$S$$$, then after his turn $$$S =$$$ "ca", $$$T =$$$ "cd". Then it is easy to see that in this case Alice can definitely finish the game on the $$$3$$$-rd move, by replacing the second symbol of the string $$$T$$$ with a, after which both strings will become equal to "ca". If Bob reverses the string $$$T$$$, then after his turn $$$S =$$$ "ac", $$$T =$$$ "dc". In this case, Alice can also definitely finish the game on the $$$3$$$rd move, by replacing the first symbol of the string $$$S$$$ with d, after which both strings will become equal to "dc". Thus, Alice can definitely finish the game in $$$3$$$ moves regardless of Bob's moves. It can be shown that the game cannot end in less than $$$3$$$ moves, with both players playing optimally. In the fifth test case, the strings $$$S$$$ and $$$T$$$ are equal, so the game will end without starting, in $$$0$$$ moves. | 1,200 | true | true | false | false | false | false | false | false | false | false | 1,282 |
993C | There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$-100$$$, while the second group is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$100$$$. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with $$$x=0$$$ (with not necessarily integer $$$y$$$-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 60$$$), the number of enemy spaceships with $$$x = -100$$$ and the number of enemy spaceships with $$$x = 100$$$, respectively. The second line contains $$$n$$$ integers $$$y_{1,1}, y_{1,2}, ldots, y_{1,n}$$$ ($$$y_{1,i} le 10,000$$$) β the $$$y$$$-coordinates of the spaceships in the first group. The third line contains $$$m$$$ integers $$$y_{2,1}, y_{2,2}, ldots, y_{2,m}$$$ ($$$y_{2,i} le 10,000$$$) β the $$$y$$$-coordinates of the spaceships in the second group. The $$$y$$$ coordinates are not guaranteed to be unique, even within a group. Output Print a single integer β the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Input 5 5 1 2 3 4 5 1 2 3 4 5 Note In the first example the first spaceship can be positioned at $$$(0, 2)$$$, and the second β at $$$(0, 7)$$$. This way all the enemy spaceships in the first group and $$$6$$$ out of $$$9$$$ spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at $$$(0, 3)$$$, and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships. | 2,100 | false | false | false | false | false | false | true | false | false | false | 5,732 |
1804F | Jack has a graph of $$$n$$$ vertices and $$$m$$$ edges. All edges are bidirectional and of unit length. The graph is connected, i.xa0e. there exists a path between any two of its vertices. There can be more than one edge connecting the same pair of vertices. The graph can contain self-loops, i.xa0e. edges connecting a node to itself. The distance between vertices $$$u$$$ and $$$v$$$ is denoted as $$$ ho(u, v)$$$ and equals the minimum possible number of edges on a path between $$$u$$$ and $$$v$$$. The diameter of graph $$$G$$$ is defined as the maximum possible distance between some pair of its vertices. We denote it as $$$d(G)$$$. In other words, $$$$$$d(G) = max_{1 le u, v le n}{ ho(u, v)}.$$$$$$ Jack plans to consecutively apply $$$q$$$ updates to his graph. Each update adds exactly one edge to the graph. Denote as $$$G_i$$$ the graph after exactly $$$i$$$ updates are made. Jack wants to calculate $$$q + 1$$$ values $$$d(G_0), d(G_1), d(G_2), ldots, d(G_q)$$$. However, Jack suspects that finding the exact diameters of $$$q + 1$$$ graphs might be a difficult task, so he is fine with approximate answers that differ from the correct answers no more than twice. Formally, Jack wants to find a sequence of positive integers $$$a_0, a_1, a_2, ldots, a_q$$$ such that $$$$$$leftlceil frac{d(G_i)}{2} ight ceil le a_i le 2 cdot d(G_i)$$$$$$ for each $$$i$$$. Hacks You cannot make hacks in this problem. Input The first line of the input contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$2 leq n leq 10^5$$$, $$$n - 1 leq m leq 10^5$$$, $$$0 leq q leq 10^5$$$), the number of vertices in the given graph, the number of edges and the number of updates, respectively. Then follow $$$m$$$ lines describing the initial edges of the graph. The $$$i$$$-th of these lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 leq u_i, v_i leq n$$$), the indexes of the vertices connected by the $$$i$$$-th edge. Then follow $$$q$$$ lines describing the updates. The $$$i$$$-th of these lines contains two integers $$$u'_i$$$ and $$$v'_i$$$ ($$$1 leq u'_i, v'_i leq n$$$), the indexes of the vertices connected by the edge that is added to the graph in the $$$i$$$-th update. Important note. For testing purposes, the input data may contain some extra lines after the mentioned input format. These will be used by the checker to verify your answer. They are not a part of the test data, you should not use them in any way and you can even omit reading them. Output Print a sequence of $$$q + 1$$$ positive integers $$$a_0, a_1, a_2, ldots, a_q$$$. The $$$i$$$-th of these integers should differ from the diameter of graph $$$G_i$$$ no more than twice. Examples Input 9 10 8 1 2 2 3 2 4 3 5 4 5 5 6 5 7 6 8 7 8 8 9 3 4 6 7 2 8 1 9 1 6 4 9 3 9 7 1 Input 8 7 9 1 2 2 3 3 4 4 5 5 6 6 7 7 8 1 5 3 7 2 4 4 6 6 8 8 2 5 4 2 4 3 3 1 652997 124613 653029 653029 124613 124613 124613 648901 124613 653029 Output 7 5 4 4 4 3 3 3 3 3 Note In the first example, the correct sequence of $$$d(G_0), d(G_1), d(G_2), ldots, d(G_q)$$$ is $$$6, 6, 6, 3, 3, 3, 2, 2, 2$$$. In the second example, the input contains an extra line that you can omit reading. It is not a part of the test and will be used for verifying your answer. The output of the second example contains the correct values of $$$d(G_i)$$$. | 2,700 | false | false | false | false | false | false | false | true | false | true | 1,452 |
1059B | Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it? For simplicity, the signature is represented as an $$$n imes m$$$ grid, where every cell is either filled with ink or empty. Andrey's pen can fill a $$$3 imes3$$$ square without its central cell if it is completely contained inside the grid, as shown below. xxx x.x xxx Determine whether is it possible to forge the signature on an empty $$$n imes m$$$ grid. Input The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$3 le n, m le 1000$$$). Then $$$n$$$ lines follow, each contains $$$m$$$ characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell. Output If Andrey can forge the signature, output "YES". Otherwise output "NO". You can print each letter in any case (upper or lower). Examples Input 5 7 ....... .#####. .#.#.#. .#####. ....... Note In the first sample Andrey can paint the border of the square with the center in $$$(2, 2)$$$. In the second sample the signature is impossible to forge. In the third sample Andrey can paint the borders of the squares with the centers in $$$(2, 2)$$$ and $$$(3, 2)$$$: 1. we have a clear paper: ... ... ... ... 2. use the pen with center at $$$(2, 2)$$$. ### #.# ### ... 3. use the pen with center at $$$(3, 2)$$$. ### ### ### ### In the fourth sample Andrey can paint the borders of the squares with the centers in $$$(3, 3)$$$ and $$$(3, 5)$$$. | 1,300 | false | false | true | false | false | false | false | false | false | false | 5,420 |
1833B | You are given an array $$$a$$$ containing the weather forecast for Berlandia for the last $$$n$$$ days. That is, $$$a_i$$$xa0β is the estimated air temperature on day $$$i$$$ ($$$1 le i le n$$$). You are also given an array $$$b$$$xa0β the air temperature that was actually present on each of the days. However, all the values in array $$$b$$$ are mixed up. Determine which day was which temperature, if you know that the weather never differs from the forecast by more than $$$k$$$ degrees. In other words, if on day $$$i$$$ the real air temperature was $$$c$$$, then the equality $$$a_i - c le k$$$ is always true. For example, let an array $$$a$$$ = [$$$1, 3, 5, 3, 9$$$] of length $$$n = 5$$$ and $$$k = 2$$$ be given and an array $$$b$$$ = [$$$2, 5, 11, 2, 4$$$]. Then, so that the value of $$$b_i$$$ corresponds to the air temperature on day $$$i$$$, we can rearrange the elements of the array $$$b$$$ so: [$$$2, 2, 5, 4, 11$$$]. Indeed: On the $$$1$$$st day, $$$a_1 - b_1 = 1 - 2 = 1$$$, $$$1 le 2 = k$$$ is satisfied; On the $$$2$$$nd day $$$a_2 - b_2 = 3 - 2 = 1$$$, $$$1 le 2 = k$$$ is satisfied; On the $$$3$$$rd day, $$$a_3 - b_3 = 5 - 5 = 0$$$, $$$0 le 2 = k$$$ is satisfied; On the $$$4$$$th day, $$$a_4 - b_4 = 3 - 4 = 1$$$, $$$1 le 2 = k$$$ is satisfied; On the $$$5$$$th day, $$$a_5 - b_5 = 9 - 11 = 2$$$, $$$2 le 2 = k$$$ is satisfied. Input The first line of input data contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0β the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ ($$$1 le n le 10^5$$$) and $$$k$$$ ($$$0 le k le10^9$$$)xa0β the number of days and the maximum difference between the expected and actual air temperature on each day. The second line of each test case contains exactly $$$n$$$ integersxa0β elements of array $$$a$$$ ($$$-10^9 le a_i le 10^9$$$). The third line of each test case contains exactly $$$n$$$ integersxa0β elements of array $$$b$$$ ($$$-10^9 le b_i le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$, and that the elements of array $$$b$$$ can always be rearranged so that the equality $$$a_i - b_i le k$$$ is true for all $$$i$$$. Output On a separate line for each test case, output exactly $$$n$$$ numbersxa0β the values of air temperature on each of the days in the correct order. If there is more than one answerxa0β output any of them. | 900 | false | true | false | false | false | false | false | false | true | false | 1,290 |
1717A | Madoka is a very strange girl, and therefore she suddenly wondered how many pairs of integers $$$(a, b)$$$ exist, where $$$1 leq a, b leq n$$$, for which $$$frac{operatorname{lcm}(a, b)}{operatorname{gcd}(a, b)} leq 3$$$. In this problem, $$$operatorname{gcd}(a, b)$$$ denotes $$$ denotes xa0β the number of test cases. Description of the test cases follows. The first and the only line of each test case contains the integer $$$n$$$ ($$$1 le n le 10^8$$$). Output For each test case output a single integer β the number of pairs of integers satisfying the condition. Example Output 1 4 7 10 11 266666666 Note For $$$n = 1$$$ there is exactly one pair of numbersxa0β $$$(1, 1)$$$ and it fits. For $$$n = 2$$$, there are only $$$4$$$ pairsxa0β $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(2, 2)$$$ and they all fit. For $$$n = 3$$$, all $$$9$$$ pair are suitable, except $$$(2, 3)$$$ and $$$(3, 2)$$$, since their $$$operatorname{lcm}$$$ is $$$6$$$, and $$$operatorname{gcd}$$$ is $$$1$$$, which doesn't fit the condition. | 800 | true | false | false | false | false | false | false | false | false | false | 1,981 |
216C | A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least _k_ people must work in the store. Berland has a law that determines the order of working days and non-working days. Namely, each employee must work for exactly _n_ consecutive days, then rest for exactly _m_ days, then work for _n_ more days and rest for _m_ more, and so on. Vitaly doesn't want to break the law. Fortunately, there is a loophole: the law comes into force on the day when the employee is hired. For example, if an employee is hired on day _x_, then he should work on days [_x_,u2009_x_u2009+u20091,u2009...,u2009_x_u2009+u2009_n_u2009-u20091], [_x_u2009+u2009_m_u2009+u2009_n_,u2009_x_u2009+u2009_m_u2009+u2009_n_u2009+u20091,u2009...,u2009_x_u2009+u2009_m_u2009+u20092_n_u2009-u20091], and so on. Day _x_ can be chosen arbitrarily by Vitaly. There is one more thing: the key to the store. Berland law prohibits making copies of keys, so there is only one key. Vitaly is planning to entrust the key to the store employees. At the same time on each day the key must be with an employee who works that day β otherwise on this day no one can get inside the store. During the day the key holder can give the key to another employee, if he also works that day. The key will handed to the first hired employee at his first working day. Each employee has to be paid salary. Therefore, Vitaly wants to hire as few employees as possible provided that the store can operate normally on each day from 1 to infinity. In other words, on each day with index from 1 to infinity, the store must have at least _k_ working employees, and one of the working employees should have the key to the store. Help Vitaly and determine the minimum required number of employees, as well as days on which they should be hired. Output In the first line print a single integer _z_ β the minimum required number of employees. In the second line print _z_ positive integers, separated by spaces: the _i_-th integer _a__i_ (1u2009β€u2009_a__i_u2009β€u2009104) should represent the number of the day, on which Vitaly should hire the _i_-th employee. If there are multiple answers, print any of them. | 1,800 | false | true | false | false | false | false | false | false | false | false | 8,974 |
573E | Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record! For rolling a ball one gets a score β an integer (maybe negative) number of points. Score for _i_-th roll is multiplied by _i_ and scores are summed up. So, for _k_ rolls with scores _s_1,u2009_s_2,u2009...,u2009_s__k_, total score is . Total score is 0 if there were no rolls. Limak made _n_ rolls and got score _a__i_ for _i_-th of them. He wants to maximize his total score and he came up with an interesting idea. He will cancel some rolls, saying that something distracted him or there was a strong wind. Limak is able to cancel any number of rolls, maybe even all or none of them. Total score is calculated as if there were only non-canceled rolls. Look at the sample tests for clarification. What maximum total score can Limak get? Input The first line contains single integer _n_ (1u2009β€u2009_n_u2009β€u2009105). The second line contains _n_ space-separated integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (_a__i_u2009β€u2009107) - scores for Limak's rolls. Output Print the maximum possible total score after choosing rolls to cancel. Examples Input 6 -10 20 -30 40 -50 60 Note In first sample Limak should cancel rolls with scores u2009-u20098 and u2009-u20093. Then he is left with three rolls with scores u2009-u20092,u20090,u20095. Total score is 1Β·(u2009-u20092)u2009+u20092Β·0u2009+u20093Β·5u2009=u200913. In second sample Limak should cancel roll with score u2009-u200950. Total score is 1Β·(u2009-u200910)u2009+u20092Β·20u2009+u20093Β·(u2009-u200930)u2009+u20094Β·40u2009+u20095Β·60u2009=u2009400. | 3,200 | false | true | false | false | true | false | false | false | false | false | 7,555 |
1093F | Vasya has got an array consisting of $$$n$$$ integers, and two integers $$$k$$$ and $$$len$$$ in addition. All numbers in the array are either between $$$1$$$ and $$$k$$$ (inclusive), or equal to $$$-1$$$. The array is good if there is no segment of $$$len$$$ consecutive equal numbers. Vasya will replace each $$$-1$$$ with some number from $$$1$$$ to $$$k$$$ (inclusive) in such a way that the resulting array is good. Tell him the number of ways to do this replacement. Since the answer may be large, print it modulo $$$998244353$$$. Input The first line contains three integers $$$n, k$$$ and $$$len$$$ ($$$1 le n le 10^5, 1 le k le 100, 1 le len le n$$$). The second line contains $$$n$$$ numbers β the array. Each number is either $$$-1$$$ or between $$$1$$$ and $$$k$$$ (inclusive). Output Print one integer β the number of ways to replace each $$$-1$$$ with some number from $$$1$$$ to $$$k$$$ (inclusive) so the array is good. The answer may be large, so print it modulo $$$998244353$$$. Examples Input 6 3 2 1 1 -1 -1 -1 -1 Input 10 42 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 Note Possible answers in the first test: 1. $$$[1, 2, 1, 1, 2]$$$; 2. $$$[1, 2, 1, 2, 2]$$$. There is no way to make the array good in the second test, since first two elements are equal. There are too many answers in the third test, so we won't describe any of them. | 2,400 | false | false | false | true | false | false | false | false | false | false | 5,239 |
339C | Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes on the left scalepan, the fourth one goes on the right scalepan and so on. Xenia wants to put the total of _m_ weights on the scalepans. Simply putting weights on the scales is not interesting, so Xenia has set some rules. First, she does not put on the scales two consecutive weights of the same weight. That is, the weight that goes _i_-th should be different from the (_i_u2009+u20091)-th weight for any _i_ (1u2009β€u2009_i_u2009<u2009_m_). Second, every time Xenia puts a weight on some scalepan, she wants this scalepan to outweigh the other one. That is, the sum of the weights on the corresponding scalepan must be strictly greater than the sum on the other pan. You are given all types of weights available for Xenia. You can assume that the girl has an infinite number of weights of each specified type. Your task is to help Xenia lay _m_ weights on u200bu200bthe scales or to say that it can't be done. Input The first line contains a string consisting of exactly ten zeroes and ones: the _i_-th (_i_u2009β₯u20091) character in the line equals "1" if Xenia has _i_ kilo weights, otherwise the character equals "0". The second line contains integer _m_ (1u2009β€u2009_m_u2009β€u20091000). Output In the first line print "YES", if there is a way to put _m_ weights on the scales by all rules. Otherwise, print in the first line "NO". If you can put _m_ weights on the scales, then print in the next line _m_ integers β the weights' weights in the order you put them on the scales. If there are multiple solutions, you can print any of them. | 1,700 | false | true | false | true | false | true | false | false | false | true | 8,478 |
1056F | Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of $$$n$$$ problems and lasts for $$$T$$$ minutes. Each of the problems is defined by two positive integers $$$a_i$$$ and $$$p_i$$$xa0β its difficulty and the score awarded by its solution. Polycarp's experience suggests that his skill level is defined with positive real value $$$s$$$, and initially $$$s=1.0$$$. To solve the $$$i$$$-th problem Polycarp needs $$$a_i/s$$$ minutes. Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by $$$10%$$$, that is skill level $$$s$$$ decreases to $$$0.9s$$$. Each episode takes exactly $$$10$$$ minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for $$$a_i/s$$$ minutes, where $$$s$$$ is his current skill level. In calculation of $$$a_i/s$$$ no rounding is performed, only division of integer value $$$a_i$$$ by real value $$$s$$$ happens. Also, Polycarp can train for some time. If he trains for $$$t$$$ minutes, he increases his skill by $$$C cdot t$$$, where $$$C$$$ is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value. Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem. Input The first line contains one integer $$$tc$$$ ($$$1 le tc le 20$$$)xa0β the number of test cases. Then $$$tc$$$ test cases follow. The first line of each test contains one integer $$$n$$$ ($$$1 le n le 100$$$)xa0β the number of problems in the contest. The second line of the test contains two real values $$$C, T$$$ ($$$0 < C < 10$$$, $$$0 le T le 2 cdot 10^5$$$), where $$$C$$$ defines the efficiency of the training and $$$T$$$ is the duration of the contest in minutes. Value $$$C, T$$$ are given exactly with three digits after the decimal point. Each of the next $$$n$$$ lines of the test contain characteristics of the corresponding problem: two integers $$$a_i, p_i$$$ ($$$1 le a_i le 10^4$$$, $$$1 le p_i le 10$$$)xa0β the difficulty and the score of the problem. It is guaranteed that the value of $$$T$$$ is such that changing it by the $$$0.001$$$ in any direction will not change the test answer. Please note that in hacks you can only use $$$tc = 1$$$. Output Print $$$tc$$$ integersxa0β the maximum possible score in each test case. Examples Input 2 4 1.000 31.000 12 3 20 6 30 1 5 1 3 1.000 30.000 1 10 10 10 20 8 Note In the first example, Polycarp can get score of $$$7$$$ as follows: 1. Firstly he trains for $$$4$$$ minutes, increasing $$$s$$$ to the value of $$$5$$$; 2. Then he decides to solve $$$4$$$-th problem: he watches one episode in $$$10$$$ minutes, his skill level decreases to $$$s=5*0.9=4.5$$$ and then he solves the problem in $$$5/s=5/4.5$$$, which is roughly $$$1.111$$$ minutes; 3. Finally, he decides to solve $$$2$$$-nd problem: he watches one episode in $$$10$$$ minutes, his skill level decreases to $$$s=4.5*0.9=4.05$$$ and then he solves the problem in $$$20/s=20/4.05$$$, which is roughly $$$4.938$$$ minutes. This way, Polycarp uses roughly $$$4+10+1.111+10+4.938=30.049$$$ minutes, to get score of $$$7$$$ points. It is not possible to achieve larger score in $$$31$$$ minutes. In the second example, Polycarp can get $$$20$$$ points as follows: 1. Firstly he trains for $$$4$$$ minutes, increasing $$$s$$$ to the value of $$$5$$$; 2. Then he decides to solve $$$1$$$-st problem: he watches one episode in $$$10$$$ minutes, his skill decreases to $$$s=5*0.9=4.5$$$ and then he solves problem in $$$1/s=1/4.5$$$, which is roughly $$$0.222$$$ minutes. 3. Finally, he decides to solve $$$2$$$-nd problem: he watches one episode in $$$10$$$ minutes, his skill decreases to $$$s=4.5*0.9=4.05$$$ and then he solves the problem in $$$10/s=10/4.05$$$, which is roughly $$$2.469$$$ minutes. This way, Polycarp gets score of $$$20$$$ in $$$4+10+0.222+10+2.469=26.691$$$ minutes. It is not possible to achieve larger score in $$$30$$$ minutes. | 2,500 | true | false | false | true | false | false | false | true | false | false | 5,427 |
1198E | There is a square grid of size $$$n imes n$$$. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs $$$min(h, w)$$$ to color a rectangle of size $$$h imes w$$$. You are to make all cells white for minimum total cost. The square is large, so we give it to you in a compressed way. The set of black cells is the union of $$$m$$$ rectangles. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 10^{9}$$$, $$$0 le m le 50$$$)xa0β the size of the square grid and the number of black rectangles. Each of the next $$$m$$$ lines contains 4 integers $$$x_{i1}$$$ $$$y_{i1}$$$ $$$x_{i2}$$$ $$$y_{i2}$$$ ($$$1 le x_{i1} le x_{i2} le n$$$, $$$1 le y_{i1} le y_{i2} le n$$$)xa0β the coordinates of the bottom-left and the top-right corner cells of the $$$i$$$-th black rectangle. The rectangles may intersect. Output Print a single integerxa0β the minimum total cost of painting the whole square in white. Examples Input 10 2 4 1 5 10 1 4 10 5 Input 7 6 2 1 2 1 4 2 4 3 2 5 2 5 2 3 5 3 1 2 1 2 3 2 5 3 Note The examples and some of optimal solutions are shown on the pictures below. | 2,500 | false | false | false | false | false | false | false | false | false | true | 4,705 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.