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
817C
Problem - 817C - Codeforces =============== xa0 is not less than _s_. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than _n_. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. Input The first (and the only) line contains two integers _n_ and _s_ (1u2009≤u2009_n_,u2009_s_u2009≤u20091018). Output Print one integer — the quantity of really big numbers that are not greater than _n_. Examples Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 Note In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30u2009-u20093u2009≥u200920). In the third example 10 is the only really big number (10u2009-u20091u2009≥u20099).
1,600
true
false
false
true
false
false
true
true
false
false
6,491
427B
The prison of your city has _n_ prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer _c_ of the prisoners to a prison located in another city. For this reason, he made the _n_ prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the _c_ prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, The chosen _c_ prisoners has to form a contiguous segment of prisoners. Any of the chosen prisoner's crime level should not be greater then _t_. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the _c_ prisoners. Input The first line of input will contain three space separated integers _n_xa0(1u2009≤u2009_n_u2009≤u20092·105), _t_xa0(0u2009≤u2009_t_u2009≤u2009109) and _c_xa0(1u2009≤u2009_c_u2009≤u2009_n_). The next line will contain _n_ space separated integers, the _i__th_ integer is the severity _i__th_ prisoner's crime. The value of crime severities will be non-negative and will not exceed 109. Output Print a single integer — the number of ways you can choose the _c_ prisoners. Examples Input 11 4 2 2 2 0 7 3 2 2 4 9 1 4
1,100
false
false
true
false
true
false
false
false
false
false
8,130
343B
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input The single line of the input contains a sequence of characters "+" and "-" of length _n_ (1u2009≤u2009_n_u2009≤u2009100000). The _i_-th (1u2009≤u2009_i_u2009≤u2009_n_) position of the sequence contains the character "+", if on the _i_-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Note The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,600
false
true
true
false
true
false
false
false
false
false
8,462
457B
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic. Suppose she wants to join two tables, _A_ and _B_. Each of them has certain number of rows which are distributed on different number of partitions. Table _A_ is distributed on the first cluster consisting of _m_ partitions. Partition with index _i_ has _a__i_ rows from _A_. Similarly, second cluster containing table _B_ has _n_ partitions, _i_-th one having _b__i_ rows from _B_. In one network operation she can copy one row from any partition to any other partition. At the end, for each row from _A_ and each row from _B_ there should be a partition that has both rows. Determine the minimal number of network operations to achieve this. Input First line contains two integer numbers, _m_ and _n_ (1u2009≤u2009_m_,u2009_n_u2009≤u2009105). Second line contains description of the first cluster with _m_ space separated integers, _a__i_ (1u2009≤u2009_a__i_u2009≤u2009109). Similarly, third line describes second cluster with _n_ space separated integers, _b__i_ (1u2009≤u2009_b__i_u2009≤u2009109). Output Print one integer — minimal number of copy operations. Note In the first example it makes sense to move all the rows to the second partition of the second cluster which is achieved in 2u2009+u20096u2009+u20093u2009=u200911 operations In the second example Piegirl can copy each row from _B_ to the both partitions of the first cluster which needs 2·3u2009=u20096 copy operations.
1,900
false
true
false
false
false
false
false
false
false
false
8,011
659D
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the _Ox_ axis from west to east, and the _Oy_ axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa). Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored. Help Maria get ready for the competitionxa0— determine the number of dangerous turns on the track. Input The first line of the input contains an integer _n_ (4u2009≤u2009_n_u2009≤u20091000)xa0— the number of straight sections of the track. The following (_n_u2009+u20091)-th line contains pairs of integers (_x__i_,u2009_y__i_) (u2009-u200910u2009000u2009≤u2009_x__i_,u2009_y__i_u2009≤u200910u2009000). The first of these points is the starting position. The _i_-th straight section of the track begins at the point (_x__i_,u2009_y__i_) and ends at the point (_x__i_u2009+u20091,u2009_y__i_u2009+u20091). It is guaranteed that: the first straight section is directed to the north; the southernmost (and if there are several, then the most western of among them) point of the track is the first point; the last point coincides with the first one (i.e., the start position); any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); no pair of points (except for the first and last one) is the same; no two adjacent straight sections are directed in the same direction or in opposite directions. Note The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1,u20091). Thus, the answer is 1.
1,500
true
false
true
false
false
false
false
false
false
false
7,186
1515E
There are $$$n$$$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $$$i-1$$$ and computer $$$i+1$$$ are both on, computer $$$i$$$ $$$(2 le i le n-1)$$$ will turn on automatically if it is not already on. Note that Phoenix cannot manually turn on a computer that already turned on automatically. If we only consider the sequence of computers that Phoenix turns on manually, how many ways can he turn on all the computers? Two sequences are distinct if either the set of computers turned on manually is distinct, or the order of computers turned on manually is distinct. Since this number may be large, please print it modulo $$$M$$$. Input The first line contains two integers $$$n$$$ and $$$M$$$ ($$$3 le n le 400$$$; $$$10^8 le M le 10^9$$$)xa0— the number of computers and the modulo. It is guaranteed that $$$M$$$ is prime. Output Print one integerxa0— the number of ways to turn on the computers modulo $$$M$$$. Note In the first example, these are the $$$6$$$ orders in which Phoenix can turn on all computers: $$$[1,3]$$$. Turn on computer $$$1$$$, then $$$3$$$. Note that computer $$$2$$$ turns on automatically after computer $$$3$$$ is turned on manually, but we only consider the sequence of computers that are turned on manually. $$$[3,1]$$$. Turn on computer $$$3$$$, then $$$1$$$. $$$[1,2,3]$$$. Turn on computer $$$1$$$, $$$2$$$, then $$$3$$$. $$$[2,1,3]$$$ $$$[2,3,1]$$$ $$$[3,2,1]$$$
2,200
true
false
false
true
false
false
false
false
false
false
3,087
354A
Vasya has _n_ items lying in a line. The items are consecutively numbered by numbers from 1 to _n_ in such a way that the leftmost item has number 1, the rightmost item has number _n_. Each item has a weight, the _i_-th item weights _w__i_ kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend _w__i_u2009·u2009_l_ energy units (_w__i_ is a weight of the leftmost item, _l_ is some parameter). If the previous action was the same (left-hand), then the robot spends extra _Q__l_ energy units; 2. Take the rightmost item with the right hand and spend _w__j_u2009·u2009_r_ energy units (_w__j_ is a weight of the rightmost item, _r_ is some parameter). If the previous action was the same (right-hand), then the robot spends extra _Q__r_ energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items. Input The first line contains five integers _n_,u2009_l_,u2009_r_,u2009_Q__l_,u2009_Q__r_ (1u2009≤u2009_n_u2009≤u2009105;u20091u2009≤u2009_l_,u2009_r_u2009≤u2009100;u20091u2009≤u2009_Q__l_,u2009_Q__r_u2009≤u2009104). The second line contains _n_ integers _w_1,u2009_w_2,u2009...,u2009_w__n_ (1u2009≤u2009_w__i_u2009≤u2009100). Output In the single line print a single number — the answer to the problem. Note Consider the first sample. As _l_u2009=u2009_r_, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42u2009+u20094·99u2009+u20094·3u2009=u2009576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4)u2009+u2009(7·1)u2009+u2009(2·3)u2009+u2009(2·2u2009+u20099)u2009=u200934 energy units.
1,500
true
true
false
false
false
false
true
false
false
false
8,418
1120E
Problem - 1120E - 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 *2600 No tag edit access → Contest materials = S(n)/a$$$, where $$$S(x)$$$ denotes the sum of digits of the number $$$x$$$. Find out if what Baron told can be true. Input The only line contains a single integer $$$a$$$ ($$$2 le a le 10^3$$$). Output If there is no such number $$$n$$$, print $$$-1$$$. Otherwise print any appropriate positive integer $$$n$$$. Your number must not consist of more than $$$5cdot10^5$$$ digits. We can show that under given constraints either there is no answer, or there is an answer no longer than $$$5cdot10^5$$$ digits. Examples Input 2 Output 6 Input 3 Output 6669 Input 10 Output -1
2,600
false
false
false
false
false
false
true
false
false
false
5,082
175F
Vasya plays a popular game the Gnomes of Might and Magic. In this game Vasya manages the kingdom of gnomes, consisting of several castles, connected by bidirectional roads. The kingdom road network has a special form. The kingdom has _m_ main castles _a_1,u2009_a_2,u2009...,u2009_a__m_, which form the Good Path. This path consists of roads between the castles _a__i_,u2009_a__i_u2009+u20091 (1u2009≤u2009_i_u2009<u2009_m_) as well as the road between _a__m_ and _a_1. There are no other roads between the castles of the Good Path. In addition, for each pair of neighboring Good Path castles _u_ and _v_ there is exactly one Evil Shortcut — a path that goes along the roads leading from the first castle (_u_) to the second one (_v_) and not having any common vertexes with the Good Path except for the vertexes _u_ and _v_. It is known that there are no other roads and castles in the kingdom there, that is, every road and every castle lies either on the Good Path or the Evil Shortcut (castles can lie in both of them). In addition, no two Evil Shortcuts have any common castles, different than the castles of the Good Path. At the beginning of each week in the kingdom appears one very bad gnome who stands on one of the roads of the kingdom, and begins to rob the corovans going through this road. One road may accumulate multiple very bad gnomes. Vasya cares about his corovans, so sometimes he sends the Mission of Death from one castle to another. Let's suggest that the Mission of Death should get from castle _s_ to castle _t_. Then it will move from castle _s_ to castle _t_, destroying all very bad gnomes, which are on the roads of the Mission's path. Vasya is so tough that his Mission of Death can destroy any number of gnomes on its way. However, Vasya is very kind, so he always chooses such path between castles _s_ and _t_, following which he will destroy the smallest number of gnomes. If there are multiple such paths, then Vasya chooses the path that contains the smallest number of roads among them. If there are multiple such paths still, Vasya chooses the lexicographically minimal one among them. Help Vasya to simulate the life of the kingdom in the Gnomes of Might and Magic game. A path is a sequence of castles, such that each pair of the neighboring castles on the path is connected by a road. Also, path _x_1,u2009_x_2,u2009... ,u2009_x__p_ is lexicographically less than path _y_1,u2009_y_2,u2009... ,u2009_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 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. Input The first line contains two integers _n_ and _m_ (3u2009≤u2009_m_u2009≤u2009_n_u2009≤u2009100000) — the number of castles in the kingdom, and the number of castles on the Good Path, respectively. The second line contains _m_ integers, which are numbers of Good Path castles (the castles are numbered from 1 to _n_) in the order of occurrence on the Path, starting with some castle. All Good Path castles are different. Each of the following _m_ lines describes an Evil Shortcut. First a line contains an integer _k__i_ (3u2009≤u2009_k__i_u2009≤u2009100000) — the number of castles on the corresponding Evil Shortcut (with the two castles which are on the Good Path), followed by a _k__i_ integers — number of castles in the order of occurrence in the given Shortcut. All castles in one Evil Shortcut are different. It is guaranteed that the first and the last castles from the Shortcut are on the Good Path and the first castles in the Evil Shortcuts form the Good Path and are presented in the same order in which the Path was represented on the second line. The next line contains an integer _q_ (1u2009≤u2009_q_u2009≤u2009100000) — the number of events in the life of the kingdom. Each of the following _q_ lines describes a single event. An event is described by the symbol _c__j_ and two numbers or castles _s__j_ and _t__j_ (the character and numbers of castles are separated by a single space). If the character of _c__j_ is equal to "+" (a plus), it means that a very bad gnome (probably not the first one) has appeared on the road between castles _s__j_ and _t__j_. If _c__j_ equals "?" (a question), then Vasya sent a Mission of Death from castle _s__j_ to castle _t__j_. It is guaranteed that for each request "+", the road between castles _s__j_ and _t__j_ exists. The events are given in chronological order, starting with the earliest one. Initially there are no very bad gnomes on the roads. All numbers in all lines are separated by single spaces. It is guaranteed that all the given Evil Shortcuts and Good Path fit in the limitations given in the problem statement. Note In the example after the first four requests there is only one path from castle 1 to castle 2, which does not contain roads with very bad gnomes: 1 6 3 5 2. After a gnome stood on the road (2, 5), the next Mission of Death moves along path 1 2, and destroys the gnome, who was on the road (1, 2). The next Mission of Death follows the same path which is already free of gnomes. After yet another gnome stood on the road (1, 2), the next Mission of Death goes on the path 1 2, and kills the gnome.
3,000
false
false
true
false
true
false
false
false
false
true
9,160
1406C
Fishing Prince loves trees, and he especially loves trees with only one centroid. The tree is a connected graph without cycles. A vertex is a centroid of a tree only when you cut this vertex (remove it and remove all edges from this vertex), the size of the largest connected component of the remaining graph is the smallest possible. For example, the centroid of the following tree is $$$2$$$, because when you cut it, the size of the largest connected component of the remaining graph is $$$2$$$ and it can't be smaller. However, in some trees, there might be more than one centroid, for example: Both vertex $$$1$$$ and vertex $$$2$$$ are centroids because the size of the largest connected component is $$$3$$$ after cutting each of them. Now Fishing Prince has a tree. He should cut one edge of the tree (it means to remove the edge). After that, he should add one edge. The resulting graph after these two operations should be a tree. He can add the edge that he cut. He wants the centroid of the resulting tree to be unique. Help him and find any possible way to make the operations. It can be proved, that at least one such way always exists. Input The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1leq tleq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3leq nleq 10^5$$$) — the number of vertices. Each of the next $$$n-1$$$ lines contains two integers $$$x, y$$$ ($$$1leq x,yleq n$$$). It means, that there exists an edge connecting vertices $$$x$$$ and $$$y$$$. It's guaranteed that the given graph is a tree. It's guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$. Output For each test case, print two lines. In the first line print two integers $$$x_1, y_1$$$ ($$$1 leq x_1, y_1 leq n$$$), which means you cut the edge between vertices $$$x_1$$$ and $$$y_1$$$. There should exist edge connecting vertices $$$x_1$$$ and $$$y_1$$$. In the second line print two integers $$$x_2, y_2$$$ ($$$1 leq x_2, y_2 leq n$$$), which means you add the edge between vertices $$$x_2$$$ and $$$y_2$$$. The graph after these two operations should be a tree. If there are multiple solutions you can print any. Example Input 2 5 1 2 1 3 2 4 2 5 6 1 2 1 3 1 4 2 5 2 6 Note Note that you can add the same edge that you cut. In the first test case, after cutting and adding the same edge, the vertex $$$2$$$ is still the only centroid. In the second test case, the vertex $$$2$$$ becomes the only centroid after cutting the edge between vertices $$$1$$$ and $$$3$$$ and adding the edge between vertices $$$2$$$ and $$$3$$$.
1,700
false
false
false
false
false
true
false
false
false
true
3,644
895C
Problem - 895C - 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 bitmasks combinatorics dp math *2000 No tag edit access → Contest materials ") Editorial") xa0— the number of elements in the array. Second line contains _n_ integers _a__i_ (1u2009≤u2009_a__i_u2009≤u200970)xa0— the elements of the array. Output Print one integerxa0— the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109u2009+u20097. Examples Input 4 1 1 1 1 Output 15 Input 4 2 2 2 2 Output 7 Input 5 1 2 4 5 8 Output 7 Note In first sample product of elements chosen by any way is 1 and 1u2009=u200912. So the answer is 24u2009-u20091u2009=u200915. In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6u2009+u20091u2009=u20097.
2,000
true
false
false
true
false
false
false
false
false
false
6,168
858C
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. Input The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. Output Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
1,500
false
true
true
true
false
false
false
false
false
false
6,312
955F
Problem - 955F - 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 trees *2600 No tag edit access → Contest materials ") as maximum depth of _k_-ary heap in the subtree of _u_ (including _u_). Your goal is to compute . Input The first line contains an integer _n_ denoting the size of the tree (2u2009≤u2009_n_u2009≤u20093·105). The next _n_u2009-u20091 lines contain two integers _u_, _v_ each, describing vertices connected by _i_-th edge. It's guaranteed that the given configuration forms a tree. Output Output the answer to the task. Examples Input 4 1 3 2 3 4 3 Output 21 Input 4 1 2 2 3 3 4 Output 22 Note Consider sample case one. For _k_u2009≥u20093 all _dp__k_ will be equal to 1. For _k_u2009=u20092 _dp__k_ is 2 if and 1 otherwise. For _k_u2009=u20091 _dp__k_ values are (3,u20091,u20092,u20091) respectively. To sum up, 4·1u2009+u20094·1u2009+u20092·2u2009+u20092·1u2009+u20093u2009+u20091u2009+u20092u2009+u20091u2009=u200921.
2,600
false
false
false
true
false
false
false
false
false
false
5,895
1045F
Ani and Borna are playing a short game on a two-variable polynomial. It's a special kind of a polynomial: the monomials are fixed, but all of its coefficients are fill-in-the-blanks dashes, e.g. $$$$$$ _ xy + _ x^4 y^7 + _ x^8 y^3 + ldots $$$$$$ Borna will fill in the blanks with positive integers. He wants the polynomial to be bounded from below, i.e. his goal is to make sure there exists a real number $$$M$$$ such that the value of the polynomial at any point is greater than $$$M$$$. Ani is mischievous, and wants the polynomial to be unbounded. Along with stealing Borna's heart, she can also steal parts of polynomials. Ani is only a petty kind of thief, though: she can only steal at most one monomial from the polynomial before Borna fills in the blanks. If Ani and Borna play their only moves optimally, who wins? Input The first line contains a positive integer $$$N$$$ $$$(2 leq N leq 200, 000)$$$, denoting the number of the terms in the starting special polynomial. Each of the following $$$N$$$ lines contains a description of a monomial: the $$$k$$$-th line contains two **space**-separated integers $$$a_k$$$ and $$$b_k$$$ $$$(0 leq a_k, b_k leq 10^9$$$) which mean the starting polynomial has the term $$$_ x^{a_k} y^{b_k}$$$. It is guaranteed that for $$$k eq l$$$, either $$$a_k eq a_l$$$ or $$$b_k eq b_l$$$. Output If Borna can always choose the coefficients such that the resulting polynomial is bounded from below, regardless of what monomial Ani steals, output "Borna". Else, output "Ani". You shouldn't output the quotation marks. Note In the first sample, the initial polynomial is $$$_xy+ _x^2 + _y^2$$$. If Ani steals the $$$_y^2$$$ term, Borna is left with $$$_xy+_x^2$$$. Whatever positive integers are written on the blanks, $$$y ightarrow -infty$$$ and $$$x := 1$$$ makes the whole expression go to negative infinity. In the second sample, the initial polynomial is $$$_1 + _x + _x^2 + _x^8$$$. One can check that no matter what term Ani steals, Borna can always win.
3,400
true
false
false
false
false
false
false
false
false
false
5,465
830D
Problem - 830D - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags combinatorics dp graphs trees *2800 No tag edit access → Contest materials . Output Print single integerxa0— the answer for the task modulo 109u2009+u20097. Examples Input 2 Output 9 Input 3 Output 245 Input 20 Output 550384565 Note There are 9 paths in the first example (the vertices are numbered on the picture below): 1, 2, 3, 1-2, 2-1, 1-3, 3-1, 2-1-3, 3-1-2. Singer 2-house
2,800
false
false
false
true
false
false
false
false
false
true
6,444
1696B
For a collection of integers $$$S$$$, define $$$operatorname{mex}(S)$$$ as the smallest non-negative integer that does not appear in $$$S$$$. NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by snapping his fingers several times. The universe can be represented as a 1-indexed array $$$a$$$ of length $$$n$$$. When NIT snaps his fingers, he does the following operation on the array: He selects positive integers $$$l$$$ and $$$r$$$ such that $$$1le lle rle n$$$. Let $$$w=operatorname{mex}({a_l,a_{l+1},dots,a_r})$$$. Then, for all $$$lle ile r$$$, set $$$a_i$$$ to $$$w$$$. We say the universe is destroyed if and only if for all $$$1le ile n$$$, $$$a_i=0$$$ holds. Find the minimum number of times NIT needs to snap his fingers to destroy the universe. That is, find the minimum number of operations NIT needs to perform to make all elements in the array equal to $$$0$$$. 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 one integer $$$n$$$ ($$$1le nle 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$ldots$$$, $$$a_n$$$ ($$$0le a_ile 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2cdot 10^5$$$. Output For each test case, print one integer — the answer to the problem. Example Input 4 4 0 0 0 0 5 0 1 2 3 4 7 0 2 3 0 1 2 0 1 1000000000 Note In the first test case, we do $$$0$$$ operations and all elements in the array are already equal to $$$0$$$. In the second test case, one optimal way is doing the operation with $$$l=2$$$, $$$r=5$$$. In the third test case, one optimal way is doing the operation twice, respectively with $$$l=4$$$, $$$r=4$$$ and $$$l=2$$$, $$$r=6$$$. In the fourth test case, one optimal way is doing the operation with $$$l=1$$$, $$$r=1$$$.
900
false
true
false
false
false
false
false
false
false
false
2,107
433A
Problem - 433A - 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 *1100 No tag edit access → Contest materials — the number of apples. The second line contains _n_ integers _w_1,u2009_w_2,u2009...,u2009_w__n_ (_w__i_u2009=u2009100 or _w__i_u2009=u2009200), where _w__i_ is the weight of the _i_-th apple. Output In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). Examples Input 3 100 200 100 Output YES Input 4 100 100 100 200 Output NO Note In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
1,100
false
false
true
false
false
false
true
false
false
false
8,109
1895E
Monocarp and Bicarp are playing a card game. Each card has two parameters: an attack value and a defence value. A card $$$s$$$ beats another card $$$t$$$ if the attack of $$$s$$$ is strictly greater than the defence of $$$t$$$. Monocarp has $$$n$$$ cards, the $$$i$$$-th of them has an attack value of $$$mathit{ax}_i$$$ and a defence value of $$$mathit{ay}_i$$$. Bicarp has $$$m$$$ cards, the $$$j$$$-th of them has an attack value of $$$mathit{bx}_j$$$ and a defence value of $$$mathit{by}_j$$$. On the first move, Monocarp chooses one of his cards and plays it. Bicarp has to respond with his own card that beats that card. After that, Monocarp has to respond with a card that beats Bicarp's card. After that, it's Bicarp's turn, and so forth. After a card is beaten, it returns to the hand of the player who played it. It implies that each player always has the same set of cards to play as at the start of the game. The game ends when the current player has no cards that beat the card which their opponent just played, and the current player loses. If the game lasts for $$$100^{500}$$$ moves, it's declared a draw. Both Monocarp and Bicarp play optimally. That is, if a player has a winning strategy regardless of his opponent's moves, he plays for a win. Otherwise, if he has a drawing strategy, he plays for a draw. You are asked to calculate three values: the number of Monocarp's starting moves that result in a win for Monocarp; the number of Monocarp's starting moves that result in a draw; the number of Monocarp's starting moves that result in a win for Bicarp. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 le n le 3 cdot 10^5$$$)xa0— the number of cards Monocarp has. The second line contains $$$n$$$ integers $$$mathit{ax}_1, mathit{ax}_2, dots, mathit{ax}_n$$$ ($$$1 le mathit{ax}_i le 10^6$$$)xa0— the attack values of Monocarp's cards. The third line contains $$$n$$$ integers $$$mathit{ay}_1, mathit{ay}_2, dots, mathit{ay}_n$$$ ($$$1 le mathit{ay}_i le 10^6$$$)xa0— the defence values of Monocarp's cards. The fourth line contains a single integer $$$m$$$ ($$$1 le m le 3 cdot 10^5$$$)xa0— the number of cards Bicarp has. The fifth line contains $$$m$$$ integers $$$mathit{bx}_1, mathit{bx}_2, dots, mathit{bx}_m$$$ ($$$1 le mathit{bx}_j le 10^6$$$)xa0— the attack values of Bicarp's cards. The sixth line contains $$$m$$$ integers $$$mathit{by}_1, mathit{by}_2, dots, mathit{by}_m$$$ ($$$1 le mathit{by}_j le 10^6$$$)xa0— the defence values of Bicarp's cards. Additional constraints on the input: the sum of $$$n$$$ over all test cases doesn't exceed $$$3 cdot 10^5$$$, the sum of $$$m$$$ over all test cases doesn't exceed $$$3 cdot 10^5$$$. Output For each test case, print three integers: the number of Monocarp's starting moves that result in a win for Monocarp; the number of Monocarp's starting moves that result in a draw; the number of Monocarp's starting moves that result in a win for Bicarp. Example Input 3 3 8 7 4 7 1 10 2 8 4 5 10 9 8 8 5 5 5 4 4 1 4 2 7 5 2 8 9 7 1 9 10 9 8 7 6 5 5 4 3 2 1 7 1 6 7 5 8 8 4 9 6 1 10 5 1 10 5
2,300
false
true
false
true
true
false
true
true
true
true
940
1985C
Alex thinks some array is good if there exists some element that can be represented as the sum of all other elements (the sum of all other elements is $$$0$$$ if there are no other elements). For example, the array $$$[1,6,3,2]$$$ is good since $$$1+3+2=6$$$. Furthermore, the array $$$[0]$$$ is also good. However, the arrays $$$[1,2,3,4]$$$ and $$$[1]$$$ are not good. Alex has an array $$$a_1,a_2,ldots,a_n$$$. Help him count the number of good non-empty prefixes of the array $$$a$$$. In other words, count the number of integers $$$i$$$ ($$$1 le i le n$$$) such that the length $$$i$$$ prefix (i.e. $$$a_1,a_2,ldots,a_i$$$) is good. Input The first line of the input contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 2 cdot 10^5$$$) — the number of elements in the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,ldots,a_n$$$ ($$$0 le a_i le 10^9$$$) — the elements of the array. 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 number of good non-empty prefixes of the array $$$a$$$. Example Input 7 1 0 1 1 4 1 1 2 0 5 0 1 2 1 4 7 1 1 0 3 5 2 12 7 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296 10 0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592 Note In the fourth test case, the array has five prefixes: prefix $$$[0]$$$ is a good array, as mentioned in the statement; prefix $$$[0, 1]$$$ is not a good array, since $$$0 e 1$$$; prefix $$$[0, 1, 2]$$$ is not a good array, since $$$0 e 1 + 2$$$, $$$1 e 0 + 2$$$ and $$$2 e 0 + 1$$$; prefix $$$[0, 1, 2, 1]$$$ is a good array, since $$$2 = 0 + 1 + 1$$$; prefix $$$[0, 1, 2, 1, 4]$$$ is a good array, since $$$4 = 0 + 1 + 2 + 1$$$. As you can see, three of them are good, so the answer is $$$3$$$.
1,000
false
true
false
false
false
false
false
false
false
false
372
413D
The programmers from the R2 company love playing 2048. One day, they decided to invent their own simplified version of this game — 2_k_ on a stripe. Imagine an infinite in one direction stripe, consisting of unit squares (the side of each square is equal to the height of the stripe). Each square can either be empty or contain some number. Initially, all squares are empty. Then at infinity one of the unit squares number 2 or 4 appears. Then the player presses a button once, and the appeared number begins to move towards the beginning of the stripe. Let's assume that some number _x_ moves to the beginning of the stripe, then it will stop if: 1. it either gets in the first square of the stripe; 2. or it is in the square that is preceded by a square with number _y_ (_y_u2009≠u2009_x_). But if number _x_ at some point of time gets to the square with the same number then both numbers add to each other and result in 2_x_. The new number 2_x_ continues moving to the beginning of the stripe by the same rules. After the final stop of the number moving process, the infinity gets a new number 2 or 4 and the process repeats. Read the notes to the test samples to better understand the moving strategy. I guess you've understood that the game progress fully depends on the order in which numbers 2 and 4 appear. Let's look at some sequence of numbers 2 and 4 in the game. We assume that the sequence is winning if it results in at least one square getting the number greater or equal than 2_k_. The goal of the game is to make up a winning sequence of _n_ numbers. But not everything is so simple, some numbers in the sequence are identified beforehand. You are given a sequence consisting of numbers 0, 2, 4. Count how many ways there are to replace each 0 of the sequence with 2 or 4 to get a winning sequence. Input The first line contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u20092000;xa03u2009≤u2009_k_u2009≤u200911). The next line contains sequence of _n_ integers, each of them is either 0, or 2, or 4. Note Consider the first example. The beginning of the strip will look as follows: 2 u2009→u2009 4 u2009→u2009 8 u2009→u2009 8 2 u2009→u2009 8 4 u2009→u2009 8 4 2 u2009→u2009 16. To better understand the game, you can see the original game on Please note that the game that is described on the strip is slightly different from the original game (when the two numbers add up in the original game, they do not keep moving). Be careful, the game is addictive, there isn't much time for the contest!
2,000
false
false
false
true
false
false
false
false
false
false
8,171
743B
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (_n_u2009-u20091) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1,u20092,u20091] after the first step, the sequence [1,u20092,u20091,u20093,u20091,u20092,u20091] after the second step. The task is to find the value of the element with index _k_ (the elements are numbered from 1) in the obtained sequence, i.xa0e. after (_n_u2009-u20091) steps. Please help Chloe to solve the problem! Input The only line contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u200950, 1u2009≤u2009_k_u2009≤u20092_n_u2009-u20091). Output Print single integerxa0— the integer at the _k_-th position in the obtained sequence. Note In the first sample the obtained sequence is [1,u20092,u20091,u20093,u20091,u20092,u20091]. The number on the second position is 2. In the second sample the obtained sequence is [1,u20092,u20091,u20093,u20091,u20092,u20091,u20094,u20091,u20092,u20091,u20093,u20091,u20092,u20091]. The number on the eighth position is 4.
1,200
false
false
true
false
false
true
false
true
false
false
6,828
1821D
You are playing with a really long strip consisting of $$$10^{18}$$$ white cells, numbered from left to right as $$$0$$$, $$$1$$$, $$$2$$$ and so on. You are controlling a special pointer that is initially in cell $$$0$$$. Also, you have a "Shift" button you can press and hold. In one move, you can do one of three actions: move the pointer to the right (from cell $$$x$$$ to cell $$$x + 1$$$); press and hold the "Shift" button; release the "Shift" button: the moment you release "Shift", all cells that were visited while "Shift" was pressed are colored in black. (Of course, you can't press Shift if you already hold it. Similarly, you can't release Shift if you haven't pressed it.) Your goal is to color at least $$$k$$$ cells, but there is a restriction: you are given $$$n$$$ segments $$$[l_i, r_i]$$$xa0— you can color cells only inside these segments, i.xa0e. you can color the cell $$$x$$$ if and only if $$$l_i le x le r_i$$$ for some $$$i$$$. What is the minimum number of moves you need to make in order to color at least $$$k$$$ cells black? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n le 2 cdot 10^5$$$; $$$1 le k le 10^9$$$)xa0— the number of segments and the desired number of black cells, respectively. The second line contains $$$n$$$ integers $$$l_1, l_2, dots, l_n$$$ ($$$1 le l_1 < l_2 < dots < l_n le 10^9$$$), where $$$l_i$$$ is the left border of the $$$i$$$-th segment. The third line contains $$$n$$$ integers $$$r_1, r_2, dots, r_n$$$ ($$$1 le r_i le 10^9$$$; $$$l_i le r_i < l_{i + 1} - 1$$$), where $$$r_i$$$ is the right border of the $$$i$$$-th segment. Additional constraints on the input: every cell belongs to at most one segment; the sum of $$$n$$$ doesn't exceed $$$2 cdot 10^5$$$. Output For each test case, print the minimum number of moves to color at least $$$k$$$ cells black, or $$$-1$$$ if it's impossible. Example Input 4 2 3 1 3 1 4 4 20 10 13 16 19 11 14 17 20 2 3 1 3 1 10 2 4 99 999999999 100 1000000000 Note In the first test case, one of the optimal sequences of operations is the following: 1. Move right: pointer is moving into cell $$$1$$$; 2. Press Shift; 3. Release Shift: cell $$$1$$$ is colored black; 4. Move right: pointer is moving into cell $$$2$$$; 5. Move right: pointer is moving into cell $$$3$$$; 6. Press Shift; 7. Move right: pointer is moving into cell $$$4$$$; 8. Release Shift: cells $$$3$$$ and $$$4$$$ are colored in black. We've colored $$$3$$$ cells in $$$8$$$ moves. In the second test case, we can color at most $$$8$$$ cells, while we need $$$20$$$ cell to color. In the third test case, one of the optimal sequences of operations is the following: 1. Move right: pointer is moving into cell $$$1$$$; 2. Move right: pointer is moving into cell $$$2$$$; 3. Move right: pointer is moving into cell $$$3$$$; 4. Press Shift; 5. Move right: pointer is moving into cell $$$4$$$; 6. Move right: pointer is moving into cell $$$5$$$; 7. Release Shift: cells $$$3$$$, $$$4$$$ and $$$5$$$ are colored in black. We've colored $$$3$$$ cells in $$$7$$$ moves.
1,900
true
true
false
false
false
false
true
true
false
false
1,354
1714F
A tree is a connected undirected graph without cycles. Note that in this problem, we are talking about not rooted trees. You are given four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$. Construct a tree such that: it contains $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$, the distance (length of the shortest path) from vertex $$$1$$$ to vertex $$$2$$$ is $$$d_{12}$$$, distance from vertex $$$2$$$ to vertex $$$3$$$ is $$$d_{23}$$$, the distance from vertex $$$3$$$ to vertex $$$1$$$ is $$$d_{31}$$$. Output any tree that satisfies all the requirements above, or determine that no such tree exists. Input The first line of the input contains an integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0—the number of test cases in the test. This is followed by $$$t$$$ test cases, each written on a separate line. Each test case consists of four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$ ($$$3 le n le 2cdot10^5; 1 le d_{12}, d_{23}, d_{31} le n-1$$$). It is guaranteed that the sum of $$$n$$$ values for all test cases does not exceed $$$2cdot10^5$$$. Output For each test case, print YES if the suitable tree exists, and NO otherwise. If the answer is positive, print another $$$n-1$$$ line each containing a description of an edge of the tree — a pair of positive integers $$$x_i, y_i$$$, which means that the $$$i$$$th edge connects vertices $$$x_i$$$ and $$$y_i$$$. The edges and vertices of the edges can be printed in any order. If there are several suitable trees, output any of them. Example Input 9 5 1 2 1 5 2 2 2 5 2 2 3 5 2 2 4 5 3 2 3 4 2 1 1 4 3 1 1 4 1 2 3 7 1 4 1 Output YES 1 2 4 1 3 1 2 5 YES 4 3 2 5 1 5 5 3 NO YES 2 4 4 1 2 5 5 3 YES 5 4 4 1 2 5 3 5 YES 2 3 3 4 1 3 NO YES 4 3 1 2 2 4 NO
1,900
false
false
true
false
false
true
false
false
false
false
1,995
379F
You are a programmer and you have a New Year Tree (not the traditional fur tree, though) — a tree of four vertices: one vertex of degree three (has number 1), connected with three leaves (their numbers are from 2 to 4). On the New Year, programmers usually have fun. You decided to have fun as well by adding vertices to the tree. One adding operation looks as follows: First we choose some leaf of the tree with number _v_. Let's mark the number of vertices on the tree at this moment by variable _n_, then two vertexes are added to the tree, their numbers are _n_u2009+u20091 and _n_u2009+u20092, also you get new edges, one between vertices _v_ and _n_u2009+u20091 and one between vertices _v_ and _n_u2009+u20092. Your task is not just to model the process of adding vertices to the tree, but after each adding operation print the diameter of the current tree. Come on, let's solve the New Year problem! Input The first line contains integer _q_ (1u2009≤u2009_q_u2009≤u20095·105) — the number of operations. Each of the next _q_ lines contains integer _v__i_ (1u2009≤u2009_v__i_u2009≤u2009_n_) — the operation of adding leaves to vertex _v__i_. Variable _n_ represents the number of vertices in the current tree. It is guaranteed that all given operations are correct. Output Print _q_ integers — the diameter of the current tree after each operation.
2,400
false
false
false
false
true
false
false
false
false
false
8,312
639C
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is _n_ and its coefficients are integers not exceeding _k_ by the absolute value. More formally: Let _a_0,u2009_a_1,u2009...,u2009_a__n_ denote the coefficients, so . Then, a polynomial _P_(_x_) is valid if all the following conditions are satisfied: _a__i_ is integer for every _i_; _a__i_u2009≤u2009_k_ for every _i_; _a__n_u2009≠u20090. Limak has recently got a valid polynomial _P_ with coefficients _a_0,u2009_a_1,u2009_a_2,u2009...,u2009_a__n_. He noticed that _P_(2)u2009≠u20090 and he wants to change it. He is going to change one coefficient to get a valid polynomial _Q_ of degree _n_ that _Q_(2)u2009=u20090. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ. Input The first line contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u2009200u2009000,u20091u2009≤u2009_k_u2009≤u2009109)xa0— the degree of the polynomial and the limit for absolute values of coefficients. The second line contains _n_u2009+u20091 integers _a_0,u2009_a_1,u2009...,u2009_a__n_ (_a__i_u2009≤u2009_k_,u2009_a__n_u2009≠u20090)xa0— describing a valid polynomial . It's guaranteed that _P_(2)u2009≠u20090. Output Print the number of ways to change one coefficient to get a valid polynomial _Q_ that _Q_(2)u2009=u20090. Examples Input 3 1000000000 10 -9 -3 5 Note In the first sample, we are given a polynomial _P_(_x_)u2009=u200910u2009-u20099_x_u2009-u20093_x_2u2009+u20095_x_3. Limak can change one coefficient in three ways: 1. He can set _a_0u2009=u2009u2009-u200910. Then he would get _Q_(_x_)u2009=u2009u2009-u200910u2009-u20099_x_u2009-u20093_x_2u2009+u20095_x_3 and indeed _Q_(2)u2009=u2009u2009-u200910u2009-u200918u2009-u200912u2009+u200940u2009=u20090. 2. Or he can set _a_2u2009=u2009u2009-u20098. Then _Q_(_x_)u2009=u200910u2009-u20099_x_u2009-u20098_x_2u2009+u20095_x_3 and indeed _Q_(2)u2009=u200910u2009-u200918u2009-u200932u2009+u200940u2009=u20090. 3. Or he can set _a_1u2009=u2009u2009-u200919. Then _Q_(_x_)u2009=u200910u2009-u200919_x_u2009-u20093_x_2u2009+u20095_x_3 and indeed _Q_(2)u2009=u200910u2009-u200938u2009-u200912u2009+u200940u2009=u20090. In the second sample, we are given the same polynomial. This time though, _k_ is equal to 12 instead of 109. Two first of ways listed above are still valid but in the third way we would get _a_1u2009>u2009_k_ what is not allowed. Thus, the answer is 2 this time.
2,200
true
false
true
false
false
false
false
false
false
false
7,255
4A
Problem - 4A - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags brute force math *800 No tag edit access input line contains integer number _w_ (1u2009≤u2009_w_u2009≤u2009100) — the weight of the watermelon bought by the boys. Output Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Examples Input 8 Output YES Note For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
800
true
false
false
false
false
false
true
false
false
false
9,974
1375D
1,900
false
false
false
false
false
true
true
false
true
false
3,784
1070C
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for $$$n$$$ consecutive days, which are numbered from $$$1$$$ to $$$n$$$. Buber requires $$$k$$$ CPU cores each day. The cloud provider offers $$$m$$$ tariff plans, the $$$i$$$-th tariff plan is characterized by the following parameters: $$$l_i$$$ and $$$r_i$$$ — the $$$i$$$-th tariff plan is available only on days from $$$l_i$$$ to $$$r_i$$$, inclusive, $$$c_i$$$ — the number of cores per day available for rent on the $$$i$$$-th tariff plan, $$$p_i$$$ — the price of renting one core per day on the $$$i$$$-th tariff plan. Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to $$$c_i$$$) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day. Find the minimum amount of money that Buber will pay for its work for $$$n$$$ days from $$$1$$$ to $$$n$$$. If on a day the total number of cores for all available tariff plans is strictly less than $$$k$$$, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly $$$k$$$ cores this day. Input The first line of the input contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 le n,k le 10^6, 1 le m le 2cdot10^5$$$) — the number of days to analyze, the desired daily number of cores, the number of tariff plans. The following $$$m$$$ lines contain descriptions of tariff plans, one description per line. Each line contains four integers $$$l_i$$$, $$$r_i$$$, $$$c_i$$$, $$$p_i$$$ ($$$1 le l_i le r_i le n$$$, $$$1 le c_i, p_i le 10^6$$$), where $$$l_i$$$ and $$$r_i$$$ are starting and finishing days of the $$$i$$$-th tariff plan, $$$c_i$$$ — number of cores, $$$p_i$$$ — price of a single core for daily rent on the $$$i$$$-th tariff plan. Output Print a single integer number — the minimal amount of money that Buber will pay. Examples Input 5 7 3 1 4 5 3 1 3 5 2 2 5 10 1 Input 7 13 5 2 3 10 7 3 5 10 10 1 2 10 6 4 5 10 9 3 4 10 8 Input 4 100 3 3 3 2 5 1 1 3 2 2 4 4 4
2,000
false
true
false
false
true
false
false
false
false
false
5,365
618F
You are given two multisets _A_ and _B_. Each multiset has exactly _n_ integers each between 1 and _n_ inclusive. Multisets may contain multiple copies of the same number. You would like to find a nonempty subset of _A_ and a nonempty subset of _B_ such that the sum of elements in these subsets are equal. Subsets are also multisets, i.e. they can contain elements with equal values. If no solution exists, print u2009-u20091. Otherwise, print the indices of elements in any such subsets of _A_ and _B_ that have the same sum. Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u20091u2009000u2009000)xa0— the size of both multisets. The second line contains _n_ integers, denoting the elements of _A_. Each element will be between 1 and _n_ inclusive. The third line contains _n_ integers, denoting the elements of _B_. Each element will be between 1 and _n_ inclusive. Output If there is no solution, print a single integer u2009-u20091. Otherwise, your solution should be printed on four lines. The first line should contain a single integer _k__a_, the size of the corresponding subset of _A_. The second line should contain _k__a_ distinct integers, the indices of the subset of _A_. The third line should contain a single integer _k__b_, the size of the corresponding subset of _B_. The fourth line should contain _k__b_ distinct integers, the indices of the subset of _B_. Elements in both sets are numbered from 1 to _n_. If there are multiple possible solutions, print any of them. Examples Input 10 10 10 10 10 10 10 10 10 10 10 10 9 8 7 6 5 4 3 2 1
3,000
false
false
false
false
false
true
false
false
false
false
7,359
1619H
You are given a permutation $$$p$$$ of $$$n$$$ elements. A permutation of $$$n$$$ elements is an array of length $$$n$$$ containing each integer from $$$1$$$ to $$$n$$$ exactly once. For example, $$$[1, 2, 3]$$$ and $$$[4, 3, 5, 1, 2]$$$ are permutations, but $$$[1, 2, 4]$$$ and $$$[4, 3, 2, 1, 2]$$$ are not permutations. You should perform $$$q$$$ queries. There are two types of queries: $$$1$$$ $$$x$$$ $$$y$$$ — swap $$$p_x$$$ and $$$p_y$$$. $$$2$$$ $$$i$$$ $$$k$$$ — print the number that $$$i$$$ will become if we assign $$$i = p_i$$$ $$$k$$$ times. Input The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 le n, q le 10^5$$$). The second line contains $$$n$$$ integers $$$p_1, p_2, dots, p_n$$$. Each of the next $$$q$$$ lines contains three integers. The first integer is $$$t$$$ ($$$1 le t le 2$$$) — type of query. If $$$t = 1$$$, then the next two integers are $$$x$$$ and $$$y$$$ ($$$1 le x, y le n$$$; $$$x e y$$$) — first-type query. If $$$t = 2$$$, then the next two integers are $$$i$$$ and $$$k$$$ ($$$1 le i, k le n$$$) — second-type query. It is guaranteed that there is at least one second-type query. Output For every second-type query, print one integer in a new line — answer to this query. Examples Input 5 4 5 3 4 2 1 2 3 1 2 1 2 1 1 3 2 1 2 Input 5 9 2 3 5 1 4 2 3 5 2 5 5 2 5 1 2 5 3 2 5 4 1 5 4 2 5 3 2 2 5 2 5 1 Note In the first example $$$p = {5, 3, 4, 2, 1}$$$. The first query is to print $$$p_3$$$. The answer is $$$4$$$. The second query is to print $$$p_{p_1}$$$. The answer is $$$1$$$. The third query is to swap $$$p_1$$$ and $$$p_3$$$. Now $$$p = {4, 3, 5, 2, 1}$$$. The fourth query is to print $$$p_{p_1}$$$. The answer is $$$2$$$.
2,400
false
false
false
false
true
false
true
false
false
false
2,528
1326C
You are given a permutation $$$p_1, p_2, ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$ and an integer $$$k$$$, such that $$$1 leq k leq n$$$. A permutation means that every number from $$$1$$$ to $$$n$$$ is contained in $$$p$$$ exactly once. Let's consider all partitions of this permutation into $$$k$$$ disjoint segments. Formally, a partition is a set of segments $$${[l_1, r_1], [l_2, r_2], ldots, [l_k, r_k]}$$$, such that: $$$1 leq l_i leq r_i leq n$$$ for all $$$1 leq i leq k$$$; For all $$$1 leq j leq n$$$ there exists exactly one segment $$$[l_i, r_i]$$$, such that $$$l_i leq j leq r_i$$$. Two partitions are different if there exists a segment that lies in one partition but not the other. Let's calculate the partition value, defined as $$$sumlimits_{i=1}^{k} {maxlimits_{l_i leq j leq r_i} {p_j}}$$$, for all possible partitions of the permutation into $$$k$$$ disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by $$$998,244,353$$$. Input The first line contains two integers, $$$n$$$ and $$$k$$$ ($$$1 leq k leq n leq 200,000$$$)xa0— the size of the given permutation and the number of segments in a partition. The second line contains $$$n$$$ different integers $$$p_1, p_2, ldots, p_n$$$ ($$$1 leq p_i leq n$$$)xa0— the given permutation. Output Print two integersxa0— the maximum possible partition value over all partitions of the permutation into $$$k$$$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $$$998,244,353$$$. Please note that you should only find the second value modulo $$$998,244,353$$$. Note In the first test, for $$$k = 2$$$, there exists only two valid partitions: $$${[1, 1], [2, 3]}$$$ and $$${[1, 2], [3, 3]}$$$. For each partition, the partition value is equal to $$$2 + 3 = 5$$$. So, the maximum possible value is $$$5$$$ and the number of partitions is $$$2$$$. In the third test, for $$$k = 3$$$, the partitions with the maximum possible partition value are $$${[1, 2], [3, 5], [6, 7]}$$$, $$${[1, 3], [4, 5], [6, 7]}$$$, $$${[1, 4], [5, 5], [6, 7]}$$$, $$${[1, 2], [3, 6], [7, 7]}$$$, $$${[1, 3], [4, 6], [7, 7]}$$$, $$${[1, 4], [5, 6], [7, 7]}$$$. For all of them, the partition value is equal to $$$7 + 5 + 6 = 18$$$. The partition $$${[1, 2], [3, 4], [5, 7]}$$$, however, has the partition value $$$7 + 3 + 6 = 16$$$. This is not the maximum possible value, so we don't count it.
1,300
true
true
false
false
false
false
false
false
false
false
4,085
362B
Problem - 362B - 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 sortings *1100 No tag edit access → Contest materials ") . Tutorial. Part 1.") — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains _m_ different space-separated integers _d_1,u2009_d_2,u2009...,u2009_d__m_ (1u2009≤u2009_d__i_u2009≤u2009_n_) — the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number _n_, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
1,100
false
false
true
false
false
false
false
false
true
false
8,386
543D
The country has _n_ cities and _n_u2009-u20091 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to _n_ inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city _x_ to any other city contains at most one bad road. Your task is — for every possible _x_ determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1u2009000u2009000u2009007 (109u2009+u20097). Input The first line of the input contains a single integer _n_ (2u2009≤u2009_n_u2009≤u20092·105) — the number of cities in the country. Next line contains _n_u2009-u20091 positive integers _p_2,u2009_p_3,u2009_p_4,u2009...,u2009_p__n_ (1u2009≤u2009_p__i_u2009≤u2009_i_u2009-u20091) — the description of the roads in the country. Number _p__i_ means that the country has a road connecting city _p__i_ and city _i_. Output Print _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_, where _a__i_ is the sought number of ways to improve the quality of the roads modulo 1u2009000u2009000u2009007 (109u2009+u20097), if the capital of the country is at city number _i_.
2,300
false
false
false
true
false
false
false
false
false
false
7,666
1430B
You have $$$n$$$ barrels lined up in a row, numbered from left to right from one. Initially, the $$$i$$$-th barrel contains $$$a_i$$$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $$$x$$$ and $$$y$$$ (the $$$x$$$-th barrel shouldn't be empty) and pour any possible amount of water from barrel $$$x$$$ to barrel $$$y$$$ (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them. Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $$$k$$$ times. Some examples: if you have four barrels, each containing $$$5$$$ liters of water, and $$$k = 1$$$, you may pour $$$5$$$ liters from the second barrel into the fourth, so the amounts of water in the barrels are $$$[5, 0, 5, 10]$$$, and the difference between the maximum and the minimum is $$$10$$$; if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still $$$0$$$. Input The first line contains one integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le k < n le 2 cdot 10^5$$$)xa0— the number of barrels and the number of pourings you can make. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$0 le a_i le 10^{9}$$$), where $$$a_i$$$ is the initial amount of water the $$$i$$$-th barrel has. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 cdot 10^5$$$. Output For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $$$k$$$ times. Example Input 2 4 1 5 5 5 5 3 2 0 0 0
800
false
true
true
false
false
false
false
false
true
false
3,515
346E
In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia. It is a very popular game and xiaodao likes it very much. One day when playing the game she wondered whether there exists a platform that the doodler couldn't reach due to the limits of its jumping ability. Consider the following problem. There are _n_ platforms. The height of the _x_-th (1u2009≤u2009_x_u2009≤u2009_n_) platform is _a_·_x_ mod _p_, where _a_ and _p_ are positive co-prime integers. The maximum possible height of a Doodler's jump is _h_. That is, it can jump from height _h_1 to height _h_2 (_h_1u2009<u2009_h_2) if _h_2u2009-u2009_h_1u2009≤u2009_h_. Initially, the Doodler is on the ground, the height of which is 0. The question is whether it can reach the highest platform or not. For example, when _a_u2009=u20097, _n_u2009=u20094, _p_u2009=u200912, _h_u2009=u20092, the heights of the platforms are 7, 2, 9, 4 as in the picture below. With the first jump the Doodler can jump to the platform at height 2, with the second one the Doodler can jump to the platform at height 4, but then it can't jump to any of the higher platforms. So, it can't reach the highest platform. User xiaodao thought about the problem for a long time but didn't solve it, so she asks you for help. Also, she has a lot of instances of the problem. Your task is solve all of these instances. Input The first line contains an integer _t_ (1u2009≤u2009_t_u2009≤u2009104) — the number of problem instances. Each of the next _t_ lines contains four integers _a_, _n_, _p_ and _h_ (1u2009≤u2009_a_u2009≤u2009109, 1u2009≤u2009_n_u2009<u2009_p_u2009≤u2009109, 0u2009≤u2009_h_u2009≤u2009109). It's guaranteed that _a_ and _p_ are co-prime. Output For each problem instance, if the Doodler can reach the highest platform, output "YES", otherwise output "NO".
3,000
true
false
false
false
false
false
false
false
false
false
8,445
1391C
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array). Consider a permutation $$$p$$$ of length $$$n$$$, we build a graph of size $$$n$$$ using it as follows: For every $$$1 leq i leq n$$$, find the largest $$$j$$$ such that $$$1 leq j < i$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ For every $$$1 leq i leq n$$$, find the smallest $$$j$$$ such that $$$i < j leq n$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ In cases where no such $$$j$$$ exists, we make no edges. Also, note that we make edges between the corresponding indices, not the values at those indices. For clarity, consider as an example $$$n = 4$$$, and $$$p = [3,1,4,2]$$$; here, the edges of the graph are $$$(1,3),(2,1),(2,3),(4,3)$$$. A permutation $$$p$$$ is cyclic if the graph built using $$$p$$$ has at least one simple cycle. Given $$$n$$$, find the number of cyclic permutations of length $$$n$$$. Since the number may be very large, output it modulo $$$10^9+7$$$. Please refer to the Notes section for the formal definition of a simple cycle Note There are $$$16$$$ cyclic permutations for $$$n = 4$$$. $$$[4,2,1,3]$$$ is one such permutation, having a cycle of length four: $$$4 ightarrow 3 ightarrow 2 ightarrow 1 ightarrow 4$$$. Nodes $$$v_1$$$, $$$v_2$$$, $$$ldots$$$, $$$v_k$$$ form a simple cycle if the following conditions hold: $$$k geq 3$$$. $$$v_i eq v_j$$$ for any pair of indices $$$i$$$ and $$$j$$$. ($$$1 leq i < j leq k$$$) $$$v_i$$$ and $$$v_{i+1}$$$ share an edge for all $$$i$$$ ($$$1 leq i < k$$$), and $$$v_1$$$ and $$$v_k$$$ share an edge.
1,500
true
false
false
true
false
false
false
false
false
true
3,719
679C
You have a grid with _n_ rows and _n_ columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X'). Two empty cells are directly connected if they share a side. Two cells (_r_1,u2009_c_1) (located in the row _r_1 and column _c_1) and (_r_2,u2009_c_2) are connected if there exists a sequence of empty cells that starts with (_r_1,u2009_c_1), finishes with (_r_2,u2009_c_2), and any two consecutive cells in this sequence are directly connected. A connected component is a set of empty cells such that any two cells in the component are connected, and there is no cell in this set that is connected to some cell not in this set. Your friend Limak is a big grizzly bear. He is able to destroy any obstacles in some range. More precisely, you can choose a square of size _k_u2009×u2009_k_ in the grid and Limak will transform all blocked cells there to empty ones. However, you can ask Limak to help only once. The chosen square must be completely inside the grid. It's possible that Limak won't change anything because all cells are empty anyway. You like big connected components. After Limak helps you, what is the maximum possible size of the biggest connected component in the grid? Input The first line of the input contains two integers _n_ and _k_ (1u2009≤u2009_k_u2009≤u2009_n_u2009≤u2009500)xa0— the size of the grid and Limak's range, respectively. Each of the next _n_ lines contains a string with _n_ characters, denoting the _i_-th row of the grid. Each character is '.' or 'X', denoting an empty cell or a blocked one, respectively. Output Print the maximum possible size (the number of cells) of the biggest connected component, after using Limak's help. Examples Input 5 2 ..XXX XX.XX X.XXX X...X XXXX. Input 5 3 ..... .XXX. .XXX. .XXX. ..... Note In the first sample, you can choose a square of size 2u2009×u20092. It's optimal to choose a square in the red frame on the left drawing below. Then, you will get a connected component with 10 cells, marked blue in the right drawing.
2,400
false
false
true
false
false
false
false
false
false
false
7,108
1848C
Vika came to her favorite cosmetics store "Golden Pear". She noticed that the prices of $$$n$$$ items have changed since her last visit. She decided to analyze how much the prices have changed and calculated the difference between the old and new prices for each of the $$$n$$$ items. Vika enjoyed calculating the price differences and decided to continue this process. Let the old prices be represented as an array of non-negative integers $$$a$$$, and the new prices as an array of non-negative integers $$$b$$$. Both arrays have the same length $$$n$$$. In one operation, Vika constructs a new array $$$c$$$ according to the following principle: $$$c_i = a_i - b_i$$$. Then, array $$$c$$$ renamed into array $$$b$$$, and array $$$b$$$ renamed into array $$$a$$$ at the same time, after which Vika repeats the operation with them. For example, if $$$a = [1, 2, 3, 4, 5, 6, 7]$$$; $$$b = [7, 6, 5, 4, 3, 2, 1]$$$, then $$$c = [6, 4, 2, 0, 2, 4, 6]$$$. Then, $$$a = [7, 6, 5, 4, 3, 2, 1]$$$; $$$b = [6, 4, 2, 0, 2, 4, 6]$$$. Vika decided to call a pair of arrays $$$a$$$, $$$b$$$ dull if after some number of such operations all elements of array $$$a$$$ become zeros. Output "YES" if the original pair of arrays is dull, and "NO" otherwise. Input Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^5$$$)xa0— the number of items whose prices have changed. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^9$$$)xa0— the old prices of the items. The third line contains $$$n$$$ integers $$$b_1, b_2, ldots, b_n$$$ ($$$0 le b_i le 10^9$$$)xa0— the new prices of the items. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output "YES" if the pair of price arrays is dull, and "NO" otherwise. You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer. Note In the first test case, the array $$$a$$$ is initially zero. In the second test case, after the first operation $$$a = [1, 2, 3], b = [0, 0, 0]$$$. After the second operation $$$a = [0, 0, 0], b = [1, 2, 3]$$$. In the third test case, it can be shown that the array $$$a$$$ will never become zero.
1,800
true
false
false
false
false
false
false
false
false
false
1,192
29B
Problem - 29B - 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 *1500 No tag edit access → Contest materials ") — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light. Output Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10u2009-u20096. Examples Input 2 1 3 4 5 Output 0.66666667 Input 5 4 3 1 1 Output 2.33333333
1,500
false
false
true
false
false
false
false
false
false
false
9,852
336D
Vasily the Bear loves beautiful strings. String _s_ is beautiful if it meets the following criteria: 1. String _s_ only consists of characters 0 and 1, at that character 0 must occur in string _s_ exactly _n_ times, and character 1 must occur exactly _m_ times. 2. We can obtain character _g_ from string _s_ with some (possibly, zero) number of modifications. The character _g_ equals either zero or one. A modification of string with length at least two is the following operation: we replace two last characters from the string by exactly one other character. This character equals one if it replaces two zeros, otherwise it equals zero. For example, one modification transforms string "01010" into string "0100", two modifications transform it to "011". It is forbidden to modify a string with length less than two. Help the Bear, count the number of beautiful strings. As the number of beautiful strings can be rather large, print the remainder after dividing the number by 1000000007 (109u2009+u20097). Input The first line of the input contains three space-separated integers _n_,u2009_m_,u2009_g_ (0u2009≤u2009_n_,u2009_m_u2009≤u2009105,u2009_n_u2009+u2009_m_u2009≥u20091,u20090u2009≤u2009_g_u2009≤u20091). Output Print a single integer — the answer to the problem modulo 1000000007 (109u2009+u20097). Note In the first sample the beautiful strings are: "01", "10". In the second sample the beautiful strings are: "0011", "1001", "1010", "1100". In the third sample there are no beautiful strings.
2,100
true
false
false
false
false
false
false
false
false
false
8,489
837D
Problem - 837D - Codeforces =============== xa0 . The second line contains _n_ space-separated integer numbers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u20091018). Output Print maximal roundness of product of the chosen subset of length _k_. Examples Input 3 2 50 4 20 Output 3 Input 5 3 15 16 3 25 9 Output 3 Input 3 3 9 77 13 Output 0 Note In the first example there are 3 subsets of 2 numbers.
2,100
true
false
false
true
false
false
false
false
false
false
6,418
623B
You are given array _a__i_ of length _n_. You may consecutively apply two operations to this array: remove some subsegment (continuous subsequence) of length _m_u2009<u2009_n_ and pay for it _m_·_a_ coins; change some elements of the array by at most 1, and pay _b_ coins for each change. Please note that each of operations may be applied at most once (and may be not applied at all) so you can remove only one segment and each number may be changed (increased or decreased) by at most 1. Also note, that you are not allowed to delete the whole array. Your goal is to calculate the minimum number of coins that you need to spend in order to make the greatest common divisor of the elements of the resulting array be greater than 1. Input The first line of the input contains integers _n_, _a_ and _b_ (1u2009≤u2009_n_u2009≤u20091u2009000u2009000,u20090u2009≤u2009_a_,u2009_b_u2009≤u2009109)xa0— the length of the array, the cost of removing a single element in the first operation and the cost of changing an element, respectively. The second line contains _n_ integers _a__i_ (2u2009≤u2009_a__i_u2009≤u2009109)xa0— elements of the array. Output Print a single numberxa0— the minimum cost of changes needed to obtain an array, such that the greatest common divisor of all its elements is greater than 1. Examples Input 8 3 4 3 7 5 4 3 12 9 4 Note In the first sample the optimal way is to remove number 3 and pay 1 coin for it. In the second sample you need to remove a segment [17,u200913] and then decrease number 6. The cost of these changes is equal to 2·3u2009+u20092u2009=u20098 coins.
2,300
false
true
false
true
false
false
false
false
false
false
7,339
689B
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of _n_ intersections numbered from 1 to _n_. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number _i_ to intersection _j_ requires _i_u2009-u2009_j_ units of energy. The total energy spent by Mike to visit a sequence of intersections _p_1u2009=u20091,u2009_p_2,u2009...,u2009_p__k_ is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly _n_ shortcuts in Mike's city, the _i__th_ of them allows walking from intersection _i_ to intersection _a__i_ (_i_u2009≤u2009_a__i_u2009≤u2009_a__i_u2009+u20091) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence _p_1u2009=u20091,u2009_p_2,u2009...,u2009_p__k_ then for each 1u2009≤u2009_i_u2009<u2009_k_ satisfying _p__i_u2009+u20091u2009=u2009_a__p__i_ and _a__p__i_u2009≠u2009_p__i_ Mike will spend only 1 unit of energy instead of _p__i_u2009-u2009_p__i_u2009+u20091 walking from the intersection _p__i_ to intersection _p__i_u2009+u20091. For example, if Mike chooses a sequence _p_1u2009=u20091,u2009_p_2u2009=u2009_a__p_1,u2009_p_3u2009=u2009_a__p_2,u2009...,u2009_p__k_u2009=u2009_a__p__k_u2009-u20091, he spends exactly _k_u2009-u20091 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1u2009≤u2009_i_u2009≤u2009_n_ Mike is interested in finding minimum possible total energy of some sequence _p_1u2009=u20091,u2009_p_2,u2009...,u2009_p__k_u2009=u2009_i_. Input The first line contains an integer _n_ (1u2009≤u2009_n_u2009≤u2009200u2009000)xa0— the number of Mike's city intersection. The second line contains _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (_i_u2009≤u2009_a__i_u2009≤u2009_n_ , , describing shortcuts of Mike's city, allowing to walk from intersection _i_ to intersection _a__i_ using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from _a__i_ to _i_). Output In the only line print _n_ integers _m_1,u2009_m_2,u2009...,u2009_m__n_, where _m__i_ denotes the least amount of total energy required to walk from intersection 1 to intersection _i_. Note In the first sample case desired sequences are: 1:u20091; _m_1u2009=u20090; 2:u20091,u20092; _m_2u2009=u20091; 3:u20091,u20093; _m_3u2009=u20093u2009-u20091u2009=u20092. In the second sample case the sequence for any intersection 1u2009<u2009_i_ is always 1,u2009_i_ and _m__i_u2009=u20091u2009-u2009_i_. In the third sample casexa0— consider the following intersection sequences: 1:u20091; _m_1u2009=u20090; 2:u20091,u20092; _m_2u2009=u20092u2009-u20091u2009=u20091; 3:u20091,u20094,u20093; _m_3u2009=u20091u2009+u20094u2009-u20093u2009=u20092; 4:u20091,u20094; _m_4u2009=u20091; 5:u20091,u20094,u20095; _m_5u2009=u20091u2009+u20094u2009-u20095u2009=u20092; 6:u20091,u20094,u20096; _m_6u2009=u20091u2009+u20094u2009-u20096u2009=u20093; 7:u20091,u20094,u20095,u20097; _m_7u2009=u20091u2009+u20094u2009-u20095u2009+u20091u2009=u20093.
1,600
false
true
false
false
false
false
false
false
false
true
7,068
1362C
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of $$$5 = 101_2$$$ and $$$14 = 1110_2$$$ equals to $$$3$$$, since $$$0101$$$ and $$$1110$$$ differ in $$$3$$$ positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants. Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from $$$0$$$ to $$$n$$$. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers. Input The input consists of multiple test cases. The first line contains one integer $$$t$$$ ($$$1 leq t leq 10,000$$$)xa0— the number of test cases. The following $$$t$$$ lines contain a description of test cases. The first and only line in each test case contains a single integer $$$n$$$ ($$$1 leq n leq 10^{18})$$$. Output Output $$$t$$$ lines. For each test case, you should output a single line with one integerxa0— the unfairness of the contest if the rating sequence equals to $$$0$$$, $$$1$$$, ..., $$$n - 1$$$, $$$n$$$. Example Input 5 5 7 11 1 2000000000000 Output 8 11 19 1 3999999999987 Note For $$$n = 5$$$ we calculate unfairness of the following sequence (numbers from $$$0$$$ to $$$5$$$ written in binary with extra leading zeroes, so they all have the same length): $$$000$$$ $$$001$$$ $$$010$$$ $$$011$$$ $$$100$$$ $$$101$$$ The differences are equal to $$$1$$$, $$$2$$$, $$$1$$$, $$$3$$$, $$$1$$$ respectively, so unfairness is equal to $$$1 + 2 + 1 + 3 + 1 = 8$$$.
1,400
true
true
false
false
false
false
false
false
false
false
3,869
1600E
Problem - 1600E - 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 games greedy two pointers *1900 No tag edit access → Contest materials - the length of the array $$$A$$$. The second line contains $$$N$$$ integers $$$A_1$$$, $$$A_2$$$,...,$$$A_N$$$ ($$$0 leq A_i leq 10^9$$$) Output The first and only line of output consists of one string, the name of the winner. If Alice won, print "Alice", otherwise, print "Bob". Examples Input 1 5 Output Alice Input 3 5 4 5 Output Alice Input 6 5 8 2 1 10 9 Output Bob
1,900
false
true
false
false
false
false
false
false
false
false
2,654
131B
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the _i_-th client number _t__i_ (u2009-u200910u2009≤u2009_t__i_u2009≤u200910). Of course, one number can be assigned to any number of customers. "Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of _t_. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence _t_1,u2009_t_2,u2009...,u2009_t__n_. For example, if _t_u2009=u2009(1,u2009u2009-u20091,u20091,u2009u2009-u20091), then any two elements _t__i_ and _t__j_ form a couple if _i_ and _j_ have different parity. Consequently, in this case the sought number equals 4. Of course, a client can't form a couple with him/herself. Input The first line of the input data contains an integer _n_ (1u2009≤u2009_n_u2009≤u2009105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers _t_1,u2009_t_2,u2009...,u2009_t__n_ (u2009-u200910u2009≤u2009_t__i_u2009≤u200910), _t__i_ — is the parameter of the _i_-th customer that has been assigned to the customer by the result of the analysis of his interests. Output Print the number of couples of customs with opposite _t_. The opposite number for _x_ is number u2009-u2009_x_ (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Note In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4). In the second sample any couple of clients is opposite.
1,200
true
false
true
false
false
false
false
false
false
false
9,352
1538F
Problem - 1538F - 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 dp math number theory *1500 No tag edit access → Contest materials ") Editorial") . Then $$$t$$$ test cases follow. Each test case is characterized by two integers $$$l$$$ and $$$r$$$ ($$$1 le l < r le 10^9$$$). Output For each test case, calculate the total number of changed digits if you want to get $$$r$$$ from $$$l$$$, adding one each time. Example Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110
1,500
true
false
false
true
false
false
false
true
false
false
2,950
1328B
For the given integer $$$n$$$ ($$$n > 2$$$) let's write down all the strings of length $$$n$$$ which contain $$$n-2$$$ letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string $$$s$$$ of length $$$n$$$ is lexicographically less than string $$$t$$$ of length $$$n$$$, if there exists such $$$i$$$ ($$$1 le i le n$$$), that $$$s_i < t_i$$$, and for any $$$j$$$ ($$$1 le j < i$$$) $$$s_j = t_j$$$. The lexicographic comparison of strings is implemented by the operator < in modern programming languages. For example, if $$$n=5$$$ the strings are (the order does matter): 1. aaabb 2. aabab 3. aabba 4. abaab 5. ababa 6. abbaa 7. baaab 8. baaba 9. babaa 10. bbaaa It is easy to show that such a list of strings will contain exactly $$$frac{n cdot (n-1)}{2}$$$ strings. You are given $$$n$$$ ($$$n > 2$$$) and $$$k$$$ ($$$1 le k le frac{n cdot (n-1)}{2}$$$). Print the $$$k$$$-th string from the list. Input The input contains one or more test cases. The first line contains one integer $$$t$$$ ($$$1 le t le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case is written on the the separate line containing two integers $$$n$$$ and $$$k$$$ ($$$3 le n le 10^5, 1 le k le min(2cdot10^9, frac{n cdot (n-1)}{2})$$$. The sum of values $$$n$$$ over all test cases in the test doesn't exceed $$$10^5$$$. Output For each test case print the $$$k$$$-th string from the list of all described above strings of length $$$n$$$. Strings in the list are sorted lexicographically (alphabetically). Example Input 7 5 1 5 2 5 8 5 10 3 1 3 2 20 100 Output aaabb aabab baaba bbaaa abb bab aaaaabaaaaabaaaaaaaa
1,300
true
false
true
false
false
false
true
true
false
false
4,070
959A
Problem - 959A - 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 games math *800 No tag edit access → Contest materials ") , the number at the beginning of the game. Output Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. Examples Input 1 Output Ehab Input 2 Output Mahmoud Note In the first sample, Mahmoud can't choose any integer _a_ initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose _a_u2009=u20092 and subtract it from _n_. It's Ehab's turn and _n_u2009=u20090. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
800
true
false
false
false
false
false
false
false
false
false
5,877
411C
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack). Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the _i_-th player is _a__i_, the attack skill is _b__i_. Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents. We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence. The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team. Input The input contain the players' description in four lines. The _i_-th line contains two space-separated integers _a__i_ and _b__i_ (1u2009≤u2009_a__i_,u2009_b__i_u2009≤u2009100) — the defence and the attack skill of the _i_-th player, correspondingly. Output If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes). Note Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence. Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team).
1,700
false
false
true
false
false
false
false
false
false
false
8,180
722E
Unfortunately, the formal description of the task turned out to be too long, so here is the legend. Research rover finally reached the surface of Mars and is ready to complete its mission. Unfortunately, due to the mistake in the navigation system design, the rover is located in the wrong place. The rover will operate on the grid consisting of _n_ rows and _m_ columns. We will define as (_r_,u2009_c_) the cell located in the row _r_ and column _c_. From each cell the rover is able to move to any cell that share a side with the current one. The rover is currently located at cell (1,u20091) and has to move to the cell (_n_,u2009_m_). It will randomly follow some shortest path between these two cells. Each possible way is chosen equiprobably. The cargo section of the rover contains the battery required to conduct the research. Initially, the battery charge is equal to _s_ units of energy. Some of the cells contain anomaly. Each time the rover gets to the cell with anomaly, the battery looses half of its charge rounded down. Formally, if the charge was equal to _x_ before the rover gets to the cell with anomaly, the charge will change to . While the rover picks a random shortest path to proceed, compute the expected value of the battery charge after it reaches cell (_n_,u2009_m_). If the cells (1,u20091) and (_n_,u2009_m_) contain anomaly, they also affect the charge of the battery. Input The first line of the input contains four integers _n_, _m_, _k_ and _s_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100u2009000, 0u2009≤u2009_k_u2009≤u20092000, 1u2009≤u2009_s_u2009≤u20091u2009000u2009000)xa0— the number of rows and columns of the field, the number of cells with anomaly and the initial charge of the battery respectively. The follow _k_ lines containing two integers _r__i_ and _c__i_ (1u2009≤u2009_r__i_u2009≤u2009_n_, 1u2009≤u2009_c__i_u2009≤u2009_m_)xa0— coordinates of the cells, containing anomaly. It's guaranteed that each cell appears in this list no more than once. Note In the first sample, the rover picks one of the following six routes: 1. , after passing cell (2,u20093) charge is equal to 6. 2. , after passing cell (2,u20093) charge is equal to 6. 3. , charge remains unchanged and equals 11. 4. , after passing cells (2,u20091) and (2,u20093) charge equals 6 and then 3. 5. , after passing cell (2,u20091) charge is equal to 6. 6. , after passing cell (2,u20091) charge is equal to 6. Expected value of the battery charge is calculated by the following formula: . Thus _P_u2009=u200919, and _Q_u2009=u20093. 3u2009-u20091 modulo 109u2009+u20097 equals 333333336. 19·333333336u2009=u2009333333342xa0(_mod_xa0109u2009+u20097)
2,900
false
false
false
true
false
false
false
false
false
false
6,922
1747E
For given integers $$$n$$$ and $$$m$$$, let's call a pair of arrays $$$a$$$ and $$$b$$$ of integers good, if they satisfy the following conditions: $$$a$$$ and $$$b$$$ have the same length, let their length be $$$k$$$. $$$k ge 2$$$ and $$$a_1 = 0, a_k = n, b_1 = 0, b_k = m$$$. For each $$$1 < i le k$$$ the following holds: $$$a_i geq a_{i - 1}$$$, $$$b_i geq b_{i - 1}$$$, and $$$a_i + b_i eq a_{i - 1} + b_{i - 1}$$$. Find the sum of $$$a$$$ over all good pairs of arrays $$$(a,b)$$$. Since the answer can be very large, output it modulo $$$10^9 + 7$$$. Input The input consists of multiple test cases. The first line contains a single integer $$$t (1 leq t leq 10^4)$$$ xa0— the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$n$$$ and $$$m$$$ $$$(1 leq n, m leq 5 cdot 10^6)$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 cdot 10^6$$$ and the sum of $$$m$$$ over all test cases does not exceed $$$5 cdot 10^6$$$. Output For each test case, output a single integer xa0— the sum of $$$a$$$ over all good pairs of arrays $$$(a,b)$$$ modulo $$$10^9 + 7$$$. Note In the first testcase, the good pairs of arrays are $$$([0, 1], [0, 1])$$$, length = $$$2$$$. $$$([0, 1, 1], [0, 0, 1])$$$, length = $$$3$$$. $$$([0, 0, 1], [0, 1, 1])$$$, length = $$$3$$$. Hence the sum of the lengths would be $$${2 + 3 + 3} = 8$$$.
2,900
true
false
false
true
false
false
false
false
false
false
1,798
846A
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced _n_ games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array _s_1,u2009_s_2,u2009...,u2009_s__n_ of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. Input The first line contains one integer number _n_ (1u2009≤u2009_n_u2009≤u2009100). The second line contains _n_ space-separated integer numbers _s_1,u2009_s_2,u2009...,u2009_s__n_ (0u2009≤u2009_s__i_u2009≤u20091). 0 corresponds to an unsuccessful game, 1 — to a successful one. Output Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
1,500
false
false
true
false
false
false
true
false
false
false
6,377
1686A
You are given an array of $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation. In one operation, you choose $$$n-1$$$ elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array $$$[1, 2, 3, 1]$$$ we can get the array $$$[2, 2, 2, 1]$$$, if we choose the first three elements, or we can get the array $$$[frac{4}{3}, frac{4}{3}, 3, frac{4}{3}]$$$, if we choose all elements except the third. Is it possible to make all elements of the array equal by performing a finite number of such operations? Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 200$$$) xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 le n le 50$$$) xa0— the number of integers. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 100$$$). Output For each test case, if it is possible to make all elements equal after some number of operations, output $$$ exttt{YES}$$$. Otherwise, output $$$ exttt{NO}$$$. You can output $$$ exttt{YES}$$$ and $$$ exttt{NO}$$$ in any case (for example, strings $$$ exttt{yEs}$$$, $$$ exttt{yes}$$$, $$$ exttt{Yes}$$$ will be recognized as a positive response). Example Input 4 3 42 42 42 5 1 2 3 4 5 4 4 3 2 1 3 24 2 22 Note In the first test case, all elements are already equal. In the second test case, you can choose all elements except the third, their average is $$$frac{1 + 2 + 4 + 5}{4} = 3$$$, so the array will become $$$[3, 3, 3, 3, 3]$$$. It's possible to show that it's impossible to make all elements equal in the third and fourth test cases.
800
false
true
false
false
false
false
false
false
false
false
2,159
1735B
There are $$$n$$$ pieces of tangerine peel, the $$$i$$$-th of them has size $$$a_i$$$. In one step it is possible to divide one piece of size $$$x$$$ into two pieces of positive integer sizes $$$y$$$ and $$$z$$$ so that $$$y + z = x$$$. You want that for each pair of pieces, their sizes differ strictly less than twice. In other words, there should not be two pieces of size $$$x$$$ and $$$y$$$, such that $$$2x le y$$$. What is the minimum possible number of steps needed to satisfy the condition? Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integer $$$n$$$ ($$$1 le n le 100$$$). Then one line follows, containing $$$n$$$ integers $$$a_1 le a_2 le ldots le a_n$$$ ($$$1 le a_i le 10^7$$$). Output For each test case, output a single line containing the minimum number of steps. Example Input 3 5 1 2 3 4 5 1 1033 5 600 900 1300 2000 2550 Note In the first test case, we initially have a piece of size $$$1$$$, so all final pieces must have size $$$1$$$. The total number of steps is: $$$0 + 1 + 2 + 3 + 4 = 10$$$. In the second test case, we have just one piece, so we don't need to do anything, and the answer is $$$0$$$ steps. In the third test case, one of the possible cut options is: $$$600, 900, (600 700), (1000 1000), (1000 1000 550)$$$. You can see this option in the picture below. The maximum piece has size $$$1000$$$, and it is less than $$$2$$$ times bigger than the minimum piece of size $$$550$$$. $$$4$$$ steps are done. We can show that it is the minimum possible number of steps.
900
true
true
false
false
false
false
false
false
false
false
1,879
977A
Problem - 977A - 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 Editorial") . You are given an integer number $$$n$$$. Tanya will subtract one from it $$$k$$$ times. Your task is to print the result after all $$$k$$$ subtractions. It is guaranteed that the result will be positive integer number. Input The first line of the input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2 le n le 10^9$$$, $$$1 le k le 50$$$) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Print one integer number — the result of the decreasing $$$n$$$ by one $$$k$$$ times. It is guaranteed that the result will be positive integer number. Examples Input 512 4 Output 50 Input 1000000000 9 Output 1 Note The first example corresponds to the following sequence: $$$512 ightarrow 511 ightarrow 510 ightarrow 51 ightarrow 50$$$.
800
false
false
true
false
false
false
false
false
false
false
5,824
1428D
To improve the boomerang throwing skills of the animals, Zookeeper has set up an $$$n imes n$$$ grid with some targets, where each row and each column has at most $$$2$$$ targets each. The rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. For each column, Zookeeper will throw a boomerang from the bottom of the column (below the grid) upwards. When the boomerang hits any target, it will bounce off, make a $$$90$$$ degree turn to the right and fly off in a straight line in its new direction. The boomerang can hit multiple targets and does not stop until it leaves the grid. In the above example, $$$n=6$$$ and the black crosses are the targets. The boomerang in column $$$1$$$ (blue arrows) bounces $$$2$$$ times while the boomerang in column $$$3$$$ (red arrows) bounces $$$3$$$ times. The boomerang in column $$$i$$$ hits exactly $$$a_i$$$ targets before flying out of the grid. It is known that $$$a_i leq 3$$$. However, Zookeeper has lost the original positions of the targets. Thus, he asks you to construct a valid configuration of targets that matches the number of hits for each column, or tell him that no such configuration exists. If multiple valid configurations exist, you may print any of them. Input The first line contains a single integer $$$n$$$ $$$(1 leq n leq 10^5)$$$. The next line contains $$$n$$$ integers $$$a_1,a_2,ldots,a_n$$$ $$$(0 leq a_i leq 3)$$$. Output If no configuration of targets exist, print $$$-1$$$. Otherwise, on the first line print a single integer $$$t$$$ $$$(0 leq t leq 2n)$$$: the number of targets in your configuration. Then print $$$t$$$ lines with two spaced integers each per line. Each line should contain two integers $$$r$$$ and $$$c$$$ $$$(1 leq r,c leq n)$$$, where $$$r$$$ is the target's row and $$$c$$$ is the target's column. All targets should be different. Every row and every column in your configuration should have at most two targets each. Examples Output 5 2 1 2 5 3 3 3 6 5 6 Note For the first test, the answer configuration is the same as in the picture from the statement. For the second test, the boomerang is not supposed to hit anything, so we can place $$$0$$$ targets. For the third test, the following configuration of targets matches the number of hits, but is not allowed as row $$$3$$$ has $$$4$$$ targets. It can be shown for this test case that no valid configuration of targets will result in the given number of target hits.
1,900
false
true
true
false
false
true
false
false
false
false
3,522
1107A
You are given a sequence $$$s$$$ consisting of $$$n$$$ digits from $$$1$$$ to $$$9$$$. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one. More formally: if the resulting division of the sequence is $$$t_1, t_2, dots, t_k$$$, where $$$k$$$ is the number of element in a division, then for each $$$i$$$ from $$$1$$$ to $$$k-1$$$ the condition $$$t_{i} < t_{i + 1}$$$ (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied. For example, if $$$s=654$$$ then you can divide it into parts $$$[6, 54]$$$ and it will be suitable division. But if you will divide it into parts $$$[65, 4]$$$ then it will be bad division because $$$65 > 4$$$. If $$$s=123$$$ then you can divide it into parts $$$[1, 23]$$$, $$$[1, 2, 3]$$$ but not into parts $$$[12, 3]$$$. Your task is to find any suitable division for each of the $$$q$$$ independent queries. Input The first line of the input contains one integer $$$q$$$ ($$$1 le q le 300$$$) — the number of queries. The first line of the $$$i$$$-th query contains one integer number $$$n_i$$$ ($$$2 le n_i le 300$$$) — the number of digits in the $$$i$$$-th query. The second line of the $$$i$$$-th query contains one string $$$s_i$$$ of length $$$n_i$$$ consisting only of digits from $$$1$$$ to $$$9$$$. Output If the sequence of digits in the $$$i$$$-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print $$$k_i$$$ — the number of parts in your division of the $$$i$$$-th query sequence and in the third line print $$$k_i$$$ strings $$$t_{i, 1}, t_{i, 2}, dots, t_{i, k_i}$$$ — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string $$$s_i$$$. See examples for better understanding.
900
false
true
false
false
false
false
false
false
false
false
5,169
95D
Petya likes horse racing very much. Horses numbered from _l_ to _r_ take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A nearly lucky number is an integer number that has at least two lucky digits the distance between which does not exceed _k_. Petya learned from some of his mates from Lviv that lucky digits are digits 4 and 7. The distance between the digits is the absolute difference between their positions in the number of a horse. For example, if _k_u2009=u20092, then numbers 412395497, 404, 4070400000070004007 are nearly lucky and numbers 4, 4123954997, 4007000040070004007 are not. Petya prepared _t_ intervals [_l__i_,u2009_r__i_] and invented number _k_, common for all of them. Your task is to find how many nearly happy numbers there are in each of these segments. Since the answers can be quite large, output them modulo 1000000007 (109u2009+u20097). Input The first line contains two integers _t_ and _k_ (1u2009≤u2009_t_,u2009_k_u2009≤u20091000) — the number of segments and the distance between the numbers correspondingly. Next _t_ lines contain pairs of integers _l__i_ and _r__i_ (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009101000). All numbers are given without the leading zeroes. Numbers in each line are separated by exactly one space character. Output Output _t_ lines. In each line print one integer — the answer for the corresponding segment modulo 1000000007 (109u2009+u20097). Note In the first sample, the four nearly lucky numbers are 44, 47, 74, 77. In the second sample, only 74 and 77 are in the given segment.
2,500
true
false
false
true
false
false
false
false
false
false
9,505
922B
Problem - 922B - 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 *1300 No tag edit access → Contest materials ") A xorangle of order _n_ is such a non-degenerate triangle, that lengths of its sides are integers not exceeding _n_, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order _n_ to get out of the forest. Formally, for a given integer _n_ you have to find the number of such triples (_a_,u2009_b_,u2009_c_), that: 1u2009≤u2009_a_u2009≤u2009_b_u2009≤u2009_c_u2009≤u2009_n_; , where denotes the form a non-degenerate (with strictly positive area) triangle. Input The only line contains a single integer _n_ (1u2009≤u2009_n_u2009≤u20092500). Output Print the number of xorangles of order _n_. Examples Input 6 Output 1 Input 10 Output 2 Note The only xorangle in the first sample is (3,u20095,u20096).
1,300
false
false
false
false
false
false
true
false
false
false
6,028
1768A
You are given an integer $$$k$$$. Find the largest integer $$$x$$$, where $$$1 le x < k$$$, such that $$$x! + (x - 1)!^dagger$$$ is a multiple of $$$^ddagger$$$ $$$k$$$, or determine that no such $$$x$$$ exists. $$$^dagger$$$ $$$y!$$$ denotes the factorial of $$$y$$$, which is defined recursively as $$$y! = y cdot (y-1)!$$$ for $$$y geq 1$$$ with the base case of $$$0! = 1$$$. For example, $$$5! = 5 cdot 4 cdot 3 cdot 2 cdot 1 cdot 0! = 120$$$. $$$^ddagger$$$ If $$$a$$$ and $$$b$$$ are integers, then $$$a$$$ is a multiple of $$$b$$$ if there exists an integer $$$c$$$ such that $$$a = b cdot c$$$. For example, $$$10$$$ is a multiple of $$$5$$$ but $$$9$$$ is not a multiple of $$$6$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The description of test cases follows. The only line of each test case contains a single integer $$$k$$$ ($$$2 le k le 10^9$$$). Output For each test case output a single integerxa0— the largest possible integer $$$x$$$ that satisfies the conditions above. If no such $$$x$$$ exists, output $$$-1$$$. Note In the first test case, $$$2! + 1! = 2 + 1 = 3$$$, which is a multiple of $$$3$$$. In the third test case, $$$7! + 6! = 5040 + 720 = 5760$$$, which is a multiple of $$$8$$$.
800
true
true
false
false
false
false
false
false
false
false
1,691
1742F
Alperen has two strings, $$$s$$$ and $$$t$$$ which are both initially equal to "a". He will perform $$$q$$$ operations of two types on the given strings: $$$1 ;; k ;; x$$$ — Append the string $$$x$$$ exactly $$$k$$$ times at the end of string $$$s$$$. In other words, $$$s := s + underbrace{x + dots + x}_{k ext{ times}}$$$. $$$2 ;; k ;; x$$$ — Append the string $$$x$$$ exactly $$$k$$$ times at the end of string $$$t$$$. In other words, $$$t := t + underbrace{x + dots + x}_{k ext{ times}}$$$. After each operation, determine if it is possible to rearrange the characters of $$$s$$$ and $$$t$$$ such that $$$s$$$ is lexicographically smaller$$$^{dagger}$$$ than $$$t$$$. Note that the strings change after performing each operation and don't go back to their initial states. $$$^{dagger}$$$ Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. A formal definition is as follows: string $$$p$$$ is lexicographically smaller than string $$$q$$$ if there exists a position $$$i$$$ such that $$$p_i < q_i$$$, and for all $$$j < i$$$, $$$p_j = q_j$$$. If no such $$$i$$$ exists, then $$$p$$$ is lexicographically smaller than $$$q$$$ if the length of $$$p$$$ is less than the length of $$$q$$$. For example, $$$ exttt{abdc} < exttt{abe}$$$ and $$$ exttt{abc} < exttt{abcd}$$$, where we write $$$p < q$$$ if $$$p$$$ is lexicographically smaller than $$$q$$$. Input The first line of the input contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0— the number of test cases. The first line of each test case contains an integer $$$q$$$ $$$(1 leq q leq 10^5)$$$xa0— the number of operations Alperen will perform. Then $$$q$$$ lines follow, each containing two positive integers $$$d$$$ and $$$k$$$ ($$$1 leq d leq 2$$$; $$$1 leq k leq 10^5$$$) and a non-empty string $$$x$$$ consisting of lowercase English letters — the type of the operation, the number of times we will append string $$$x$$$ and the string we need to append respectively. It is guaranteed that the sum of $$$q$$$ over all test cases doesn't exceed $$$10^5$$$ and that the sum of lengths of all strings $$$x$$$ in the input doesn't exceed $$$5 cdot 10^5$$$. Output For each operation, output "YES", if it is possible to arrange the elements in both strings in such a way that $$$s$$$ is lexicographically smaller than $$$t$$$ and "NO" otherwise. Example Input 3 5 2 1 aa 1 2 a 2 3 a 1 2 b 2 3 abca 2 1 5 mihai 2 2 buiucani 3 1 5 b 2 3 a 2 4 paiu Output YES NO YES NO YES NO YES NO NO YES Note In the first test case, the strings are initially $$$s = $$$ "a" and $$$t = $$$ "a". After the first operation the string $$$t$$$ becomes "aaa". Since "a" is already lexicographically smaller than "aaa", the answer for this operation should be "YES". After the second operation string $$$s$$$ becomes "aaa", and since $$$t$$$ is also equal to "aaa", we can't arrange $$$s$$$ in any way such that it is lexicographically smaller than $$$t$$$, so the answer is "NO". After the third operation string $$$t$$$ becomes "aaaaaa" and $$$s$$$ is already lexicographically smaller than it so the answer is "YES". After the fourth operation $$$s$$$ becomes "aaabb" and there is no way to make it lexicographically smaller than "aaaaaa" so the answer is "NO". After the fifth operation the string $$$t$$$ becomes "aaaaaaabcaabcaabca", and we can rearrange the strings to: "bbaaa" and "caaaaaabcaabcaabaa" so that $$$s$$$ is lexicographically smaller than $$$t$$$, so we should answer "YES".
1,500
false
true
false
false
false
true
false
false
false
false
1,826
327A
Problem - 327A - 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 implementation *1200 No tag edit access → Contest materials and flips all values _a__k_ for which their positions are in range
1,200
false
false
true
true
false
false
true
false
false
false
8,536
1017D
Childan is making up a legendary story and trying to sell his forgeryxa0— a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace. This "personal treasure" is a multiset $$$S$$$ of $$$m$$$ "01-strings". A "01-string" is a string that contains $$$n$$$ characters "0" and "1". For example, if $$$n=4$$$, strings "0110", "0000", and "1110" are "01-strings", but "00110" (there are $$$5$$$ characters, not $$$4$$$) and "zero" (unallowed characters) are not. Note that the multiset $$$S$$$ can contain equal elements. Frequently, Mr. Kasoura will provide a "01-string" $$$t$$$ and ask Childan how many strings $$$s$$$ are in the multiset $$$S$$$ such that the "Wu" value of the pair $$$(s, t)$$$ is not greater than $$$k$$$. Mrs. Kasoura and Mr. Kasoura think that if $$$s_i = t_i$$$ ($$$1leq ileq n$$$) then the "Wu" value of the character pair equals to $$$w_i$$$, otherwise $$$0$$$. The "Wu" value of the "01-string" pair is the sum of the "Wu" values of every character pair. Note that the length of every "01-string" is equal to $$$n$$$. For example, if $$$w=[4, 5, 3, 6]$$$, "Wu" of ("1001", "1100") is $$$7$$$ because these strings have equal characters only on the first and third positions, so $$$w_1+w_3=4+3=7$$$. You need to help Childan to answer Mr. Kasoura's queries. That is to find the number of strings in the multiset $$$S$$$ such that the "Wu" value of the pair is not greater than $$$k$$$. Input The first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$1leq nleq 12$$$, $$$1leq q, mleq 5cdot 10^5$$$)xa0— the length of the "01-strings", the size of the multiset $$$S$$$, and the number of queries. The second line contains $$$n$$$ integers $$$w_1, w_2, ldots, w_n$$$ ($$$0 le w_i le 100$$$)xa0— the value of the $$$i$$$-th caracter. Each of the next $$$m$$$ lines contains the "01-string" $$$s$$$ of length $$$n$$$xa0— the string in the multiset $$$S$$$. Each of the next $$$q$$$ lines contains the "01-string" $$$t$$$ of length $$$n$$$ and integer $$$k$$$ ($$$0leq kleq 100$$$)xa0— the query. Output For each query, print the answer for this query. Examples Input 2 4 5 40 20 01 01 10 11 00 20 00 40 11 20 11 40 11 60 Input 1 2 4 100 0 1 0 0 0 100 1 0 1 100 Note In the first example, we can get: "Wu" of ("01", "00") is $$$40$$$. "Wu" of ("10", "00") is $$$20$$$. "Wu" of ("11", "00") is $$$0$$$. "Wu" of ("01", "11") is $$$20$$$. "Wu" of ("10", "11") is $$$40$$$. "Wu" of ("11", "11") is $$$60$$$. In the first query, pairs ("11", "00") and ("10", "00") satisfy the condition since their "Wu" is not greater than $$$20$$$. In the second query, all strings satisfy the condition. In the third query, pairs ("01", "11") and ("01", "11") satisfy the condition. Note that since there are two "01" strings in the multiset, the answer is $$$2$$$, not $$$1$$$. In the fourth query, since $$$k$$$ was increased, pair ("10", "11") satisfies the condition too. In the fifth query, since $$$k$$$ was increased, pair ("11", "11") satisfies the condition too.
1,900
false
false
false
false
true
false
true
false
false
false
5,602
613A
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path. Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine. Peter decided to tie his car to point _P_ and now he is wondering what is the area of u200bu200bthe region that will be cleared from snow. Help him. Input The first line of the input contains three integersxa0— the number of vertices of the polygon _n_ (), and coordinates of point _P_. Each of the next _n_ lines contains two integersxa0— coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1u2009000u2009000 in their absolute value. Output Print a single real value numberxa0— the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10u2009-u20096. Namely: let's assume that your answer is _a_, and the answer of the jury is _b_. The checker program will consider your answer correct, if . Examples Output 12.566370614359172464 Output 21.991148575128551812 Note In the first sample snow will be removed from that area:
1,900
false
false
false
false
false
false
false
true
false
false
7,387
1966A
You have a hand of $$$n$$$ cards, where each card has a number written on it, and a fixed integer $$$k$$$. You can perform the following operation any number of times: Choose any $$$k$$$ cards from your hand that all have the same number. Exchange these cards for $$$k-1$$$ cards, each of which can have any number you choose (including the number written on the cards you just exchanged). Here is one possible sequence of operations for the first example case, which has $$$k=3$$$: What is the minimum number of cards you can have in your hand at the end of this process? Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 500$$$)xa0— the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n le 100$$$, $$$2 le k le 100$$$)xa0— the number of cards you have, and the number of cards you exchange during each operation, respectively. The next line of each test case contains $$$n$$$ integers $$$c_1, c_2, ldots c_n$$$ ($$$1 le c_i le 100$$$)xa0— the numbers written on your cards. Output For each test case, output a single integerxa0— the minimum number of cards you can have left in your hand after any number of operations. Example Input 7 5 3 4 1 1 4 4 1 10 7 7 2 4 2 1 100 5 2 3 10 4 1 1 1 1 1 1 1 1 1 1 5 2 3 8 1 48 7 6 2 10 20 30 10 20 40 6 3 10 20 30 10 20 40 Note The first example case corresponds to the picture above. The sequence of operations displayed there is optimal, so the answer is $$$2$$$. In the second example case, no operations can be performed, so the answer is $$$1$$$. In the fourth example case, you can repeatedly select $$$4$$$ cards numbered with $$$1$$$ and replace them with $$$3$$$ cards numbered with $$$1$$$, until there are $$$3$$$ cards left.
800
false
true
false
false
false
true
false
false
false
false
510
193E
Problem - 193E - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags brute force math matrices *2900 No tag edit access → Contest materials and now wants to find its first occurrence in the list given above. Help John and find the number of the first occurence of number _f_ in the list or otherwise state that number _f_ does not occur in the list. The numeration in John's list starts from zero. There, the 0-th position is the number 0, the 1-st position is the number 1, the 2-nd position is the number 1, the 3-rd position is the number 2, the 4-th position is the number 3 and so on. Thus, the beginning of the list looks like this: 0,u20091,u20091,u20092,u20093,u20095,u20098,u200913,u200921,u2009... Input The first line contains the single integer _f_ (0u2009≤u2009_f_u2009<u20091013) — the number, which position in the list we should find. 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 number — the number of the first occurrence of the given number in John's list. If this number doesn't occur in John's list, print -1. Examples Input 13 Output 7 Input 377 Output 14
2,900
true
false
false
false
false
false
true
false
false
false
9,066
1393E1
This is an easier version of the problem E with smaller constraints. Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin. To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them. Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll. Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo $$$10^9+7$$$. It may occur that princess Celestia has sent a wrong scroll so the answer may not exist. A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a e b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 1000$$$): the number of words in the scroll. The $$$i$$$-th of the next $$$n$$$ lines contains a string consisting of lowercase English letters: the $$$i$$$-th word in the scroll. The length of each word is more or equal than $$$1$$$. The sum of lengths of words does not exceed $$$20000$$$. Output Print one integer: the number of ways to get a version of the original from the scroll modulo $$$10^9+7$$$. Examples Input 6 lapochka kartyshka bigbabytape morgenshtern ssshhhiiittt queen Note Notice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length $$$1$$$ now).
2,800
false
false
true
true
false
false
false
false
false
false
3,703
1404D
This is an interactive problem. Consider a fixed positive integer $$$n$$$. Two players, First and Second play a game as follows: 1. First considers the $$$2n$$$ numbers $$$1, 2, dots, 2n$$$, and partitions them as he wants into $$$n$$$ disjoint pairs. 2. Then, Second chooses exactly one element from each of the pairs that First created (he chooses elements he wants). To determine the winner of the game, we compute the sum of the numbers chosen by Second. If the sum of all these numbers is a multiple of $$$2n$$$, then Second wins. Otherwise, First wins. You are given the integer $$$n$$$. Your task is to decide which player you wish to play as and win the game. Interaction The interaction begins by reading the integer $$$n$$$ ($$$1 le n le 5 cdot 10^5$$$). After reading, print a single line containing either First or Second, denoting who you want to play as. The interaction then varies depending on who you chose to play as. If you chose to play as First, print a single line containing $$$2n$$$ integers $$$p_1, p_2, dots, p_{2n}$$$, denoting that the number $$$i$$$ belongs to the $$$p_i$$$-th pair for $$$1le i le 2n$$$. Thus, $$$1 le p_i le n$$$, and every number between $$$1$$$ and $$$n$$$ inclusive should appear exactly twice. If you chose to play as Second, the interactor will print $$$2n$$$ integers $$$p_1, p_2, dots, p_{2n}$$$, denoting that the number $$$i$$$ belongs to the $$$p_i$$$-th pair. As a response, print $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ in a single line. These should contain exactly one number from each pair. Regardless of who you chose to play as the interactor will finish by printing a single integer: $$$0$$$ if your answer for the test case is correct (that is, you are playing as First and it cannot choose adequate numbers from your pairs, or you are playing as Second and your chosen numbers add up to a multiple of $$$2n$$$), or $$$-1$$$ if it is incorrect. In particular, the interactor will not print the chosen numbers if you choose to play First and lose. In either case, your program should terminate immediately after reading this number. If at any point you make an invalid interaction, the interactor will print $$$-1$$$ and finish the interaction. You will receive a Wrong Answer verdict. Make sure to terminate immediately to avoid getting other verdicts. After printing something do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see documentation for other languages. Hack Format To hack, use the following format: The first line contains an integer $$$n$$$ ($$$1 le n le 5 cdot 10^5$$$). The second line contains $$$2n$$$ integers $$$p_1, p_2, dots, p_{2n}$$$, denoting that the number $$$i$$$ belongs to the $$$p_i$$$-th pair if the solution being hacked chooses to play as Second. If the solution being hacked chooses to play as First, those pairs don't matter but the $$$p_1, p_2, dots, p_{2n}$$$ must still form a valid partition of $$$1, 2, dots, 2n$$$ into $$$n$$$ disjoint pairs. Note In the first sample, $$$n = 2$$$, and you decide to play as Second. The judge chooses the pairs $$$(1, 2)$$$ and $$$(3, 4)$$$, and you reply with the numbers $$$1$$$ and $$$3$$$. This is a valid choice since it contains exactly one number from each pair, and the sum $$$1 + 3 = 4$$$ is divisible by $$$4$$$. In the second sample, $$$n = 2$$$ again, and you play as First. You choose the pairs $$$(2, 4)$$$ and $$$(1, 3)$$$. The judge fails to choose a number from each pair such that their sum is divisible by $$$4$$$, so the answer is correct. Note that the sample tests are just for illustration of the interaction protocol, and don't necessarily correspond to the behavior of the real interactor.
2,800
true
false
false
false
false
true
false
false
false
false
3,650
1027G
The campus has $$$m$$$ rooms numbered from $$$0$$$ to $$$m - 1$$$. Also the $$$x$$$-mouse lives in the campus. The $$$x$$$-mouse is not just a mouse: each second $$$x$$$-mouse moves from room $$$i$$$ to the room $$$i cdot x mod{m}$$$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the $$$x$$$-mouse is unknown. You are responsible to catch the $$$x$$$-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the $$$x$$$-mouse enters a trapped room, it immediately gets caught. And the only observation you made is $$$ ext{GCD} (x, m) = 1$$$. Input The only line contains two integers $$$m$$$ and $$$x$$$ ($$$2 le m le 10^{14}$$$, $$$1 le x < m$$$, $$$ ext{GCD} (x, m) = 1$$$) — the number of rooms and the parameter of $$$x$$$-mouse. Output Print the only integer — minimum number of traps you need to install to catch the $$$x$$$-mouse. Note In the first example you can, for example, put traps in rooms $$$0$$$, $$$2$$$, $$$3$$$. If the $$$x$$$-mouse starts in one of this rooms it will be caught immediately. If $$$x$$$-mouse starts in the $$$1$$$-st rooms then it will move to the room $$$3$$$, where it will be caught. In the second example you can put one trap in room $$$0$$$ and one trap in any other room since $$$x$$$-mouse will visit all rooms $$$1..m-1$$$ if it will start in any of these rooms.
2,600
true
false
false
false
false
false
false
false
false
false
5,570
741C
Note that girls in Arpa’s land are really attractive. Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw _n_ pairs of friends sitting around a table. _i_-th pair consisted of a boy, sitting on the _a__i_-th chair, and his girlfriend, sitting on the _b__i_-th chair. The chairs were numbered 1 through 2_n_ in clockwise direction. There was exactly one person sitting on each chair. There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that: Each person had exactly one type of food, No boy had the same type of food as his girlfriend, Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2_n_ and 1 are considered consecutive. Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions. Input The first line contains an integer _n_ (1u2009u2009≤u2009u2009_n_u2009u2009≤u2009u2009105)xa0— the number of pairs of guests. The _i_-th of the next _n_ lines contains a pair of integers _a__i_ and _b__i_ (1u2009u2009≤u2009_a__i_,u2009_b__i_u2009≤u2009u20092_n_)xa0— the number of chair on which the boy in the _i_-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair. Output If there is no solution, print -1. Otherwise print _n_ lines, the _i_-th of them should contain two integers which represent the type of food for the _i_-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2. If there are multiple solutions, print any of them.
2,600
false
false
false
false
false
true
false
false
false
true
6,834
2038K
Problem - 2038K - 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 math number theory *2100 No tag edit access → Contest materials $$$. You are standing in the cell $$$(1, 1)$$$ and want to move into the cell $$$(n, n)$$$. Suppose you are in the cell $$$(i, j)$$$; in one step, you can move either into the cell $$$(i, j + 1)$$$ or into the cell $$$(i + 1, j)$$$ if the corresponding cells exist. Let's define the cost of the cell $$$(i, j)$$$ as $$$c(i, j) = gcd(i, a) + gcd(j, b)$$$ (here, $$$gcd(x,y)$$$ denotes the greatest common divisor of $$$x$$$ and $$$y$$$). The cost of the route from $$$(1, 1)$$$ to $$$(n, n)$$$ is the sum of costs of the visited cells (including the starting cell and the finishing cell). Find the route with minimum possible cost and print its cost. Input The only line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$2 le n le 10^6$$$; $$$1 le a, b le 10^6$$$). Output Print one integerxa0— the cost of the cheapest route from $$$(1, 1)$$$ to $$$(n, n)$$$. Examples Input 4 2 4 Output 21 Input 10 210 420 Output 125 Note The first example is described in the picture above.
2,100
true
true
false
true
false
false
true
false
false
false
28
1388B
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it. In the beginning, uncle Bogdan wrote on a board a positive integer $$$x$$$ consisting of $$$n$$$ digits. After that, he wiped out $$$x$$$ and wrote integer $$$k$$$ instead, which was the concatenation of binary representations of digits $$$x$$$ consists of (without leading zeroes). For example, let $$$x = 729$$$, then $$$k = 111101001$$$ (since $$$7 = 111$$$, $$$2 = 10$$$, $$$9 = 1001$$$). After some time, uncle Bogdan understood that he doesn't know what to do with $$$k$$$ and asked Denis to help. Denis decided to wipe last $$$n$$$ digits of $$$k$$$ and named the new number as $$$r$$$. As a result, Denis proposed to find such integer $$$x$$$ of length $$$n$$$ that $$$r$$$ (as number) is maximum possible. If there are multiple valid $$$x$$$ then Denis is interested in the minimum one. All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you? Note: in this task, we compare integers ($$$x$$$ or $$$k$$$) as numbers (despite what representations they are written in), so $$$729 < 1999$$$ or $$$111 < 1000$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of test cases. Next $$$t$$$ lines contain test casesxa0— one per test case. The one and only line of each test case contains the single integer $$$n$$$ ($$$1 le n le 10^5$$$)xa0— the length of the integer $$$x$$$ you need to find. It's guaranteed that the sum of $$$n$$$ from all test cases doesn't exceed $$$2 cdot 10^5$$$. Note In the second test case (with $$$n = 3$$$), if uncle Bogdan had $$$x = 998$$$ then $$$k = 100110011000$$$. Denis (by wiping last $$$n = 3$$$ digits) will obtain $$$r = 100110011$$$. It can be proved that the $$$100110011$$$ is the maximum possible $$$r$$$ Denis can obtain and $$$998$$$ is the minimum $$$x$$$ to obtain it.
1,000
true
true
false
false
false
false
false
false
false
false
3,732
1615H
There are $$$n$$$ reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingly, the "Top Reindeer" title is just a measure of upvotes and has nothing to do with their skill level in the reindeer games, but they still give it the utmost importance. Currently, the $$$i$$$-th reindeer has a score of $$$a_i$$$. You would like to influence the leaderboard with some operations. In an operation, you can choose a reindeer, and either increase or decrease his score by $$$1$$$ unit. Negative scores are allowed. You have $$$m$$$ requirements for the resulting scores. Each requirement is given by an ordered pair $$$(u, v)$$$, meaning that after all operations, the score of reindeer $$$u$$$ must be less than or equal to the score of reindeer $$$v$$$. Your task is to perform the minimum number of operations so that all requirements will be satisfied. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2le nle 1000$$$; $$$1le mle 1000$$$)xa0— the number of reindeer and requirements, respectively. The second line contains $$$n$$$ integers $$$a_1,ldots, a_n$$$ ($$$1le a_ile 10^9$$$), where $$$a_i$$$ is the current score of reindeer $$$i$$$. The next $$$m$$$ lines describe the requirements. The $$$i$$$-th of these lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1le u_i, v_ile n$$$; $$$u_i e v_i$$$)xa0— the two reindeer of the $$$i$$$-th requirement. Output Print $$$n$$$ integers $$$b_1,ldots, b_n$$$ ($$$-10^{15}le b_ile 10^{15}$$$), where $$$b_i$$$ is the score of the $$$i$$$-th reindeer after all operations. If there are multiple solutions achieving the minimum number of operations, you may output any. We can prove that there is always an optimal solution such that $$$b_ile 10^{15}$$$ for all $$$i$$$. Examples Input 7 6 3 1 4 9 2 5 6 1 2 2 3 3 4 4 5 5 6 6 7 Input 4 6 6 5 8 2 3 1 4 1 3 2 1 2 2 3 3 1 Input 10 18 214 204 195 182 180 176 176 172 169 167 1 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 6 1 6 2 6 3 6 4 6 5 6 7 6 8 6 9 6 10 Output 204 204 195 182 180 167 176 172 169 167
3,000
false
false
false
false
true
true
false
true
false
true
2,557
1438D
Ksenia has an array $$$a$$$ consisting of $$$n$$$ positive integers $$$a_1, a_2, ldots, a_n$$$. In one operation she can do the following: choose three distinct indices $$$i$$$, $$$j$$$, $$$k$$$, and then change all of $$$a_i, a_j, a_k$$$ to $$$a_i oplus a_j oplus a_k$$$ simultaneously, where $$$oplus$$$ denotes the xa0— the length of $$$a$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, ldots, a_n$$$ ($$$1 leq a_i leq 10^9$$$)xa0— elements of $$$a$$$. Output Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $$$n$$$ operations. If it is possible, print an integer $$$m$$$ ($$$0 leq m leq n$$$), which denotes the number of operations you do. In each of the next $$$m$$$ lines, print three distinct integers $$$i, j, k$$$, representing one operation. If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations. Note In the first example, the array becomes $$$[4 oplus 1 oplus 7, 2, 4 oplus 1 oplus 7, 4 oplus 1 oplus 7, 2] = [2, 2, 2, 2, 2]$$$.
2,200
true
false
false
false
false
true
false
false
false
false
3,475
1773I
Oh no, this wicked jury hides something from you again, and you need to guess it interactively. This time, you need to find an integer $$$n$$$. To do that, you can make at most 10 queries of the form "Whatxa0is the $$$k$$$-th decimal digit of the product of all integers from 1 to $$$n$$$ (also known as factorial and denoted asxa0$$$n!$$$)?". Interaction In the first line, there is an integer $$$t$$$ ($$$1 le t le 100$$$)xa0— the number of tests you shall process. For each test, the integer $$$n$$$ is chosen in advance. The length of $$$n!$$$ is at most $$$20,000$$$, so $$$1 le n le 5982$$$. You can make at most 10 queries of the form "? $$$k$$$" ($$$0 le k < 20,000$$$). In response to the query, you will get a single digitxa0— the $$$k$$$-th decimal digit of $$$n!$$$ (the response is between 0 and 9 inclusive). Digits are numbered from 0, starting with the least significant digit. If $$$n!$$$ is too short, and there is no $$$k$$$-th digit, then 0 is returned. After your program finds the value of $$$n$$$ it shall answer with "! $$$n$$$". If the answer is correct, then you will receive "YES" and should proceed to the next test or terminate if it was the last one. If the answer is not correct, or you are trying to guess, and there are several possible answers consistent with the information you have received, you will get "NO". In that case, your submission will receive "Wrong answer" verdict and your code shall terminate immediately.
2,500
false
false
true
false
false
false
true
false
false
false
1,648
177D1
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_. Encryption uses a key which is a sequence of _m_ integers _b_1,u2009_b_2,u2009...,u2009_b__m_ (_m_u2009≤u2009_n_). All numbers from the message and from the key belong to the interval from 0 to _c_u2009-u20091, inclusive, and all the calculations are performed modulo _c_. Encryption is performed in _n_u2009-u2009_m_u2009+u20091 steps. On the first step we add to each number _a_1,u2009_a_2,u2009...,u2009_a__m_ a corresponding number _b_1,u2009_b_2,u2009...,u2009_b__m_. On the second step we add to each number _a_2,u2009_a_3,u2009...,u2009_a__m_u2009+u20091 (changed on the previous step) a corresponding number _b_1,u2009_b_2,u2009...,u2009_b__m_. And so on: on step number _i_ we add to each number _a__i_,u2009_a__i_u2009+u20091,u2009...,u2009_a__i_u2009+u2009_m_u2009-u20091 a corresponding number _b_1,u2009_b_2,u2009...,u2009_b__m_. The result of the encryption is the sequence _a_1,u2009_a_2,u2009...,u2009_a__n_ after _n_u2009-u2009_m_u2009+u20091 steps. Help the Beaver to write a program that will encrypt messages in the described manner. Input The first input line contains three integers _n_, _m_ and _c_, separated by single spaces. The second input line contains _n_ integers _a__i_ (0u2009≤u2009_a__i_u2009<u2009_c_), separated by single spaces — the original message. The third input line contains _m_ integers _b__i_ (0u2009≤u2009_b__i_u2009<u2009_c_), separated by single spaces — the encryption key. The input limitations for getting 30 points are: 1u2009≤u2009_m_u2009≤u2009_n_u2009≤u2009103 1u2009≤u2009_c_u2009≤u2009103 The input limitations for getting 100 points are: 1u2009≤u2009_m_u2009≤u2009_n_u2009≤u2009105 1u2009≤u2009_c_u2009≤u2009103 Note In the first sample the encryption is performed in two steps: after the first step _a_u2009=u2009(0,u20090,u20090,u20091) (remember that the calculations are performed modulo 2), after the second step _a_u2009=u2009(0,u20091,u20091,u20090), and that is the answer.
1,200
false
false
false
false
false
false
true
false
false
false
9,148
137A
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? Input The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the _i_-th character in the string is the letter "С", that means that the _i_-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the _i_-th character is the letter "P", than the _i_-th object on the wall is a photo. Output Print the only number — the minimum number of times Polycarpus has to visit the closet. Note In the first sample Polycarpus needs to take one item to the closet 7 times. In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice. In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice. In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
900
false
false
true
false
false
false
false
false
false
false
9,330
1312D
Problem - 1312D - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags combinatorics math *1700 No tag edit access → Contest materials . Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 le n le m le 2 cdot 10^5$$$). Output Print one integer — the number of arrays that meet all of the aforementioned conditions, taken modulo $$$998244353$$$. Examples Input 3 4 Output 6 Input 3 5 Output 10 Input 42 1337 Output 806066790 Input 100000 200000 Output 707899035 Note The arrays in the first example are: $$$
1,700
true
false
false
false
false
false
false
false
false
false
4,134
1411A
Problem - 1411A - Codeforces =============== xa0 and Technocup 2021 — Elimination Round 3") Editorial") '. The message is bad if the number of characters ')' at the end of the string strictly greater than the number of remaining characters. For example, the string ")bc)))" has three parentheses at the end, three remaining characters, and is not considered bad. Input The first line contains the number of test cases $$$t$$$ ($$$1 leq t leq 100$$$). Description of the $$$t$$$ test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 leq n leq 100$$$). The second line of each test case contains a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters and characters ')'. Output For each of $$$t$$$ test cases, print "Yes" if the string is bad. Otherwise, print "No". You can print each letter in any case (upper or lower). Example Input 5 2 )) 12 gl))hf)))))) 9 gege))))) 14 )aa))b)))))))) 1 ) Output Yes No Yes Yes Yes
800
false
false
true
false
false
false
false
false
false
false
3,621
1167A
A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string $$$s$$$ of length $$$n$$$, consisting of digits. In one operation you can delete any character from string $$$s$$$. For example, it is possible to obtain strings 112, 111 or 121 from string 1121. You need to determine whether there is such a sequence of operations (possibly empty), after which the string $$$s$$$ becomes a telephone number. Input The first line contains one integer $$$t$$$ ($$$1 le t le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 le n le 100$$$) — the length of string $$$s$$$. The second line of each test case contains the string $$$s$$$ ($$$s = n$$$) consisting of digits. Output For each test print one line. If there is a sequence of operations, after which $$$s$$$ becomes a telephone number, print YES. Otherwise, print NO. Example Input 2 13 7818005553535 11 31415926535 Note In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535.
800
false
true
false
false
false
false
true
false
false
false
4,883
1870G
Let's define $$$f(S)$$$. Let $$$S$$$ be a multiset (i.e., it can contain repeated elements) of non-negative integers. In one operation, you can choose any non-empty subset of $$$S$$$ (which can also contain repeated elements), remove this subset (all elements in it) from $$$S$$$, and add the MEX of the removed subset to $$$S$$$. You can perform any number of such operations. After all the operations, $$$S$$$ should contain exactly $$$1$$$ number. $$$f(S)$$$ is the largest number that could remain in $$$S$$$ after any sequence of operations. You are given an array of non-negative integers $$$a$$$ of length $$$n$$$. For each of its $$$n$$$ prefixes, calculate $$$f(S)$$$ if $$$S$$$ is the corresponding prefix (for the $$$i$$$-th prefix, $$$S$$$ consists of the first $$$i$$$ elements of array $$$a$$$). The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of $$$[2,2,1]$$$ is $$$0$$$, because $$$0$$$ does not belong to the array. The MEX of $$$[3,1,0,1]$$$ is $$$2$$$, because $$$0$$$ and $$$1$$$ belong to the array, but $$$2$$$ does not. The MEX of $$$[0,3,1,2]$$$ is $$$4$$$, because $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$ belong to the array, but $$$4$$$ does not. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. Then follows the description of the test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 leq n leq 2 cdot 10^5$$$) — the size of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 leq a_i leq 2 cdot 10^5$$$) — the array $$$a$$$. It is guaranteed that the sum of all $$$n$$$ values across all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, output $$$n$$$ numbers: $$$f(S)$$$ for each of the $$$n$$$ prefixes of array $$$a$$$. Example Input 4 8 179 57 2 0 2 3 2 3 1 0 3 1 0 3 8 1 0 1 2 4 3 0 2 Output 179 2 3 3 3 4 4 5 1 1 2 2 1 2 2 3 3 5 5 5 Note Consider the first test case. For a prefix of length $$$1$$$, the initial multiset is $$${179}$$$. If we do nothing, we get $$$179$$$. For a prefix of length $$$2$$$, the initial multiset is $$${57, 179}$$$. Using the following sequence of operations, we can obtain $$$2$$$. 1. Apply the operation to $$${57}$$$, the multiset becomes $$${0, 179}$$$. 2. Apply the operation to $$${179}$$$, the multiset becomes $$${0, 0}$$$. 3. Apply the operation to $$${0}$$$, the multiset becomes $$${0, 1}$$$. 4. Apply the operation to $$${0, 1}$$$, the multiset becomes $$${2}$$$. This is our answer. Consider the second test case. For a prefix of length $$$1$$$, the initial multiset is $$${0}$$$. If we apply the operation to $$${0}$$$, the multiset becomes $$${1}$$$. This is the answer.
3,300
false
false
false
false
true
false
false
false
false
false
1,053
1561D1
This version of the problem differs from the next one only in the constraint on $$$n$$$. Note that the memory limit in this problem is lower than in others. You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom. You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$. Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$. Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$lfloor frac{x}{z} floor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding). Input The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 le n le 2 cdot 10^5$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number)xa0— the length of the strip and the modulo. Output Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$. Note In the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$. There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$. Therefore, there are five ways in total.
1,700
true
false
false
true
true
false
true
false
false
false
2,821
1722B
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue. Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same. Input The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 leq t leq 100$$$)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 leq n leq 100$$$)xa0— the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectivelyxa0— the description of the grid. Output For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer). Example Input 6 2 RG RB 4 GRBG GBGB 5 GGGGG BBBBB 7 BBBBBBB RRRRRRR 8 RGBRRGBR RGGRRBGR 1 G G Output YES NO YES NO YES YES Note In the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't. In the second test case, Vasya can see that the two rows are different. In the third test case, every cell is green or blue, so Vasya will think they are the same.
800
false
false
true
false
false
false
false
false
false
false
1,952
689C
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly _k_ times more than the previous one. The value of _k_ (_k_u2009>u20091) is a secret integer known only to them. It is also known that each thief's bag can carry at most _n_ chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved. Sadly, only the thieves know the value of _n_, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed _n_, but not fixed _k_) is _m_. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them. Mike want to track the thieves down, so he wants to know what their bags are and value of _n_ will help him in that. Please find the smallest possible value of _n_ or tell him that the rumors are false and there is no such _n_. Output Print the only integer _n_xa0— the maximum amount of chocolates that thieves' bags can carry. If there are more than one _n_ satisfying the rumors, print the smallest one. If there is no such _n_ for a false-rumoured _m_, print u2009-u20091. Note In the first sample case the smallest _n_ that leads to exactly one way of stealing chocolates is _n_u2009=u20098, whereas the amounts of stealed chocolates are (1,u20092,u20094,u20098) (the number of chocolates stolen by each of the thieves). In the second sample case the smallest _n_ that leads to exactly 8 ways is _n_u2009=u200954 with the possibilities: (1,u20092,u20094,u20098),u2009u2002(1,u20093,u20099,u200927),u2009u2002(2,u20094,u20098,u200916),u2009u2002(2,u20096,u200918,u200954),u2009u2002(3,u20096,u200912,u200924),u2009u2002(4,u20098,u200916,u200932),u2009u2002(5,u200910,u200920,u200940),u2009u2002(6,u200912,u200924,u200948). There is no _n_ leading to exactly 10 ways of stealing chocolates in the third sample case.
1,700
true
false
false
false
false
false
false
true
false
false
7,067
617E
Bob has a favorite number _k_ and _a__i_ of length _n_. Now he asks you to answer _m_ queries. Each query is given by a pair _l__i_ and _r__i_ and asks you to count the number of pairs of integers _i_ and _j_, such that _l_u2009≤u2009_i_u2009≤u2009_j_u2009≤u2009_r_ and the xor of the numbers _a__i_,u2009_a__i_u2009+u20091,u2009...,u2009_a__j_ is equal to _k_. Input The first line of the input contains integers _n_, _m_ and _k_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100u2009000, 0u2009≤u2009_k_u2009≤u20091u2009000u2009000)xa0— the length of the array, the number of queries and Bob's favorite number respectively. The second line contains _n_ integers _a__i_ (0u2009≤u2009_a__i_u2009≤u20091u2009000u2009000)xa0— Bob's array. Then _m_ lines follow. The _i_-th line contains integers _l__i_ and _r__i_ (1u2009≤u2009_l__i_u2009≤u2009_r__i_u2009≤u2009_n_)xa0— the parameters of the _i_-th query. Output Print _m_ lines, answer the queries in the order they appear in the input. Examples Input 6 2 3 1 2 1 1 0 3 1 6 3 5 Input 5 3 1 1 1 1 1 1 1 5 2 4 1 3 Note In the first sample the suitable pairs of _i_ and _j_ for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query. In the second sample xor equals 1 for all subarrays of an odd length.
2,200
false
false
false
false
true
false
false
false
false
false
7,365
848C
I won't feel lonely, nor will I be sorrowful... not before everything is buried. A string of _n_ beads is left as the message of leaving. The beads are numbered from 1 to _n_ from left to right, each having a shape numbered by integers between 1 and _n_ inclusive. Some beads may have the same shapes. The memory of a shape _x_ in a certain subsegment of beads, is defined to be the difference between the last position and the first position that shape _x_ appears in the segment. The memory of a subsegment is the sum of memories over all shapes that occur in it. From time to time, shapes of beads change as well as the memories. Sometimes, the past secreted in subsegments are being recalled, and you are to find the memory for each of them. Input The first line of input contains two space-separated integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100u2009000) — the number of beads in the string, and the total number of changes and queries, respectively. The second line contains _n_ integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u2009_n_)xa0— the initial shapes of beads 1,u20092,u2009...,u2009_n_, respectively. The following _m_ lines each describes either a change in the beads or a query of subsegment. A line has one of the following formats: 1 p x (1u2009≤u2009_p_u2009≤u2009_n_, 1u2009≤u2009_x_u2009≤u2009_n_), meaning that the shape of the _p_-th bead is changed into _x_; 2 l r (1u2009≤u2009_l_u2009≤u2009_r_u2009≤u2009_n_), denoting a query of memory of the subsegment from _l_ to _r_, inclusive. Output For each query, print one line with an integer — the memory of the recalled subsegment. Examples Input 7 6 1 2 3 1 3 2 1 2 3 7 2 1 3 1 7 2 1 3 2 2 1 6 2 5 7 Input 7 5 1 3 2 1 4 2 3 1 1 4 2 2 3 1 1 7 2 4 5 1 1 7 Note The initial string of beads has shapes (1,u20092,u20093,u20091,u20093,u20092,u20091). Consider the changes and queries in their order: 1. 2 3 7: the memory of the subsegment [3,u20097] is (7u2009-u20094)u2009+u2009(6u2009-u20096)u2009+u2009(5u2009-u20093)u2009=u20095; 2. 2 1 3: the memory of the subsegment [1,u20093] is (1u2009-u20091)u2009+u2009(2u2009-u20092)u2009+u2009(3u2009-u20093)u2009=u20090; 3. 1 7 2: the shape of the 7-th bead changes into 2. Beads now have shapes (1,u20092,u20093,u20091,u20093,u20092,u20092) respectively; 4. 1 3 2: the shape of the 3-rd bead changes into 2. Beads now have shapes (1,u20092,u20092,u20091,u20093,u20092,u20092) respectively; 5. 2 1 6: the memory of the subsegment [1,u20096] is (4u2009-u20091)u2009+u2009(6u2009-u20092)u2009+u2009(5u2009-u20095)u2009=u20097; 6. 2 5 7: the memory of the subsegment [5,u20097] is (7u2009-u20096)u2009+u2009(5u2009-u20095)u2009=u20091.
2,600
false
false
false
false
true
false
false
false
false
false
6,356
79A
Problem - 79A - Codeforces =============== xa0 ") and _y_ (0u2009≤u2009_y_u2009≤u2009106), separated by a single space. Output If Ciel wins, print "Ciel". Otherwise, print "Hanako". Examples Input 2 2 Output Ciel Input 3 22 Output Hanako Note In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose.
1,200
false
true
false
false
false
false
false
false
false
false
9,570
840A
Problem - 840A - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags combinatorics greedy math number theory sortings *1300 No tag edit access → Contest materials . Consider all possible _k_-element subsets of the set
1,300
true
true
false
false
false
false
false
false
true
false
6,403
1850E
Mircea has $$$n$$$ pictures. The $$$i$$$-th picture is a square with a side length of $$$s_i$$$ centimeters. He mounted each picture on a square piece of cardboard so that each picture has a border of $$$w$$$ centimeters of cardboard on all sides. In total, he used $$$c$$$ square centimeters of cardboard. Given the picture sizes and the value $$$c$$$, can you find the value of $$$w$$$? A picture of the first test case. Here $$$c = 50 = 5^2 + 4^2 + 3^2$$$, so $$$w=1$$$ is the answer. Please note that the piece of cardboard goes behind each picture, not just the border. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 1000$$$)xa0— the number of test cases. The first line of each test case contains two positive integers $$$n$$$ ($$$1 leq n leq 2 cdot 10^5$$$) and $$$c$$$ ($$$1 leq c leq 10^{18}$$$)xa0— the number of paintings, and the amount of used square centimeters of cardboard. The second line of each test case contains $$$n$$$ space-separated integers $$$s_i$$$ ($$$1 leq s_i leq 10^4$$$)xa0— the sizes of the paintings. The sum of $$$n$$$ over all test cases doesn't exceed $$$2 cdot 10^5$$$. Additional constraint on the input: Such an integer $$$w$$$ exists for each test case. Please note, that some of the input for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++). Output For each test case, output a single integerxa0— the value of $$$w$$$ ($$$w geq 1$$$) which was used to use exactly $$$c$$$ squared centimeters of cardboard. Example Input 10 3 50 3 2 1 1 100 6 5 500 2 2 2 2 2 2 365 3 4 2 469077255466389 10000 2023 10 635472106413848880 9181 4243 7777 1859 2017 4397 14 9390 2245 7225 7 176345687772781240 9202 9407 9229 6257 7743 5738 7966 14 865563946464579627 3654 5483 1657 7571 1639 9815 122 9468 3079 2666 5498 4540 7861 5384 19 977162053008871403 9169 9520 9209 9013 9300 9843 9933 9454 9960 9167 9964 9701 9251 9404 9462 9277 9661 9164 9161 18 886531871815571953 2609 10 5098 9591 949 8485 6385 4586 1064 5412 6564 8460 2245 6552 5089 8353 3803 3764 Output 1 2 4 5 7654321 126040443 79356352 124321725 113385729 110961227 Note The first test case is explained in the statement. For the second test case, the chosen $$$w$$$ was $$$2$$$, thus the only cardboard covers an area of $$$c = (2 cdot 2 + 6)^2 = 10^2 = 100$$$ squared centimeters. For the third test case, the chosen $$$w$$$ was $$$4$$$, which obtains the covered area $$$c = (2 cdot 4 + 2)^2 imes 5 = 10^2 imes 5 = 100 imes 5 = 500$$$ squared centimeters.
1,100
true
false
true
false
false
false
false
true
false
false
1,178
1437E
You are given an array of $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$, and a set $$$b$$$ of $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$. In one operation, you may choose two integers $$$i$$$ and $$$x$$$ ($$$1 le i le n$$$, $$$x$$$ can be any integer) and assign $$$a_i := x$$$. This operation can be done only if $$$i$$$ does not belong to the set $$$b$$$. Calculate the minimum number of operations you should perform so the array $$$a$$$ is increasing (that is, $$$a_1 < a_2 < a_3 < dots < a_n$$$), or report that it is impossible. Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 le n le 5 cdot 10^5$$$, $$$0 le k le n$$$) — the size of the array $$$a$$$ and the set $$$b$$$, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 le a_i le 10^9$$$). Then, if $$$k e 0$$$, the third line follows, containing $$$k$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_k$$$ ($$$1 le b_1 < b_2 < dots < b_k le n$$$). If $$$k = 0$$$, this line is skipped. Output If it is impossible to make the array $$$a$$$ increasing using the given operations, print $$$-1$$$. Otherwise, print one integer — the minimum number of operations you have to perform. Examples Input 7 2 1 2 1 1 3 5 1 3 5 Input 10 3 1 3 5 6 12 9 8 10 13 15 2 4 9
2,200
false
false
true
true
true
true
false
true
false
false
3,481
213B
Problem - 213B - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags combinatorics dp *1900 No tag edit access → Contest materials occurs in the number at least _a_
1,900
false
false
false
true
false
false
false
false
false
false
8,987
443B
Problem - 443B - 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 strings *1500 No tag edit access → Contest materials . This string contains only small English letters. The second line contains number _k_ (1u2009≤u2009_k_u2009≤u2009200) — the number of the added characters. Output Print a single number — the maximum length of the tandem repeat that could have occurred in the new string. Examples Input aaba 2 Output 6 Input aaabbbb 2 Output 6 Input abracadabra 10 Output 20 Note A tandem repeat of length 2_n_ is string _s_, where for any position _i_ (1u2009≤u2009_i_u2009≤u2009_n_) the following condition fulfills: _s__i_u2009=u2009_s__i_u2009+u2009_n_. In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.
1,500
false
false
true
false
false
false
true
false
false
false
8,064
573C
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree. Recall that tree is a connected graph consisting of _n_ vertices and _n_u2009-u20091 edges. Limak chose a tree with _n_ vertices. He has infinite strip of paper with two parallel rows of dots. Little bear wants to assign vertices of a tree to some _n_ distinct dots on a paper so that edges would intersect only at their endpoints — drawn tree must be planar. Below you can see one of correct drawings for the first sample test. Is it possible for Limak to draw chosen tree? Input The first line contains single integer _n_ (1u2009≤u2009_n_u2009≤u2009105). Next _n_u2009-u20091 lines contain description of a tree. _i_-th of them contains two space-separated integers _a__i_ and _b__i_ (1u2009≤u2009_a__i_,u2009_b__i_u2009≤u2009_n_,u2009_a__i_u2009≠u2009_b__i_) denoting an edge between vertices _a__i_ and _b__i_. It's guaranteed that given description forms a tree. Output Print "Yes" (without the quotes) if Limak can draw chosen tree. Otherwise, print "No" (without the quotes). Examples Input 8 1 2 1 3 1 6 6 4 6 7 6 5 7 8 Input 13 1 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 3 10 4 11 4 12 4 13
2,300
false
false
false
false
false
true
false
false
false
false
7,557
1283A
Problem - 1283A - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags math *800 No tag edit access → Contest materials ") Editorial") — the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 le h < 24$$$, $$$0 le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros. Output For each test case, print the answer on it — the number of minutes before the New Year. Example Input 5 23 55 23 0 0 1 4 20 23 59 Output 5 60 1439 1180 1
800
true
false
false
false
false
false
false
false
false
false
4,280
2008A
Today, Sakurako has a math exam. The teacher gave the array, consisting of $$$a$$$ ones and $$$b$$$ twos. In an array, Sakurako must place either a '+' or a '-' in front of each element so that the sum of all elements in the array equals $$$0$$$. Sakurako is not sure if it is possible to solve this problem, so determine whether there is a way to assign signs such that the sum of all elements in the array equals $$$0$$$. Input The first line contains a single integer $$$t$$$ ($$$1le tle 100$$$) xa0— the number of test cases. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0le a,b<10$$$) xa0— the number of '1's and the number of '2's in the array. Output For each test case, output "Yes" if you can make the sum of the entire array equal to $$$0$$$, and "No" otherwise. You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer. Note 1. $$$a=0$$$, $$$b=1$$$: This means the array is $$$[2]$$$ — it is impossible to add the signs '+' or '-' to get $$$0$$$ as a result; 2. $$$a=0$$$, $$$b=3$$$: This means the array is $$$[2, 2, 2]$$$ — it is impossible to add the signs '+' or '-' to get $$$0$$$ as a result; 3. $$$a=2$$$, $$$b=0$$$: This means the array is $$$[1, 1]$$$ — it is possible to add the signs '+' or '-' to get $$$0$$$ as a result ($$$+1-1=0$$$); 4. $$$a=2$$$, $$$b=3$$$: This means the array is $$$[1, 1, 2, 2, 2]$$$ — it is possible to add the signs '+' or '-' to get $$$0$$$ as a result ($$$+1+1-2-2+2=0$$$);
800
true
true
false
false
false
true
true
false
false
false
208
1121B
Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has $$$n$$$ sweets with sizes $$$a_1, a_2, ldots, a_n$$$. All his sweets have different sizes. That is, there is no such pair $$$(i, j)$$$ ($$$1 leq i, j leq n$$$) such that $$$i e j$$$ and $$$a_i = a_j$$$. Since Mike has taught for many years, he knows that if he gives two sweets with sizes $$$a_i$$$ and $$$a_j$$$ to one child and $$$a_k$$$ and $$$a_p$$$ to another, where $$$(a_i + a_j) eq (a_k + a_p)$$$, then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer $$$n$$$ ($$$2 leq n leq 1,000$$$)xa0— the number of sweets Mike has. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 leq a_i leq 10^5$$$)xa0— the sizes of the sweets. It is guaranteed that all integers are distinct. Note In the first example, Mike can give $$$9+2=11$$$ to one child, $$$8+3=11$$$ to another one, and $$$7+4=11$$$ to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give $$$3+9=12$$$ to one child and $$$1+11$$$ to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
1,200
false
false
true
false
false
false
true
false
false
false
5,079
1930H
This is an interactive problem. Alice has a tree $$$T$$$ consisting of $$$n$$$ nodes, numbered from $$$1$$$ to $$$n$$$. Alice will show $$$T$$$ to Bob. After observing $$$T$$$, Bob needs to tell Alice two permutations $$$p_1$$$ and $$$p_2$$$ of $$$[1, 2, ldots, n]$$$. Then, Alice will play $$$q$$$ rounds of the following game. Alice will create an array $$$a$$$ that is a permutation of $$$[0,1,ldots,n-1]$$$. The value of node $$$v$$$ will be $$$a_v$$$. Alice will choose two nodes $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n$$$, $$$u eq v$$$) of $$$T$$$ and tell them to Bob. Bob will need to find the $$$operatorname{MEX}^dagger$$$ of the values on the unique simple path between nodes $$$u$$$ and $$$v$$$. To find this value, Bob can ask Alice at most $$$5$$$ queries. In each query, Bob should give three integers $$$t$$$, $$$l$$$ and $$$r$$$ to Alice such that $$$t$$$ is either $$$1$$$ or $$$2$$$, and $$$1 leq l leq r leq n$$$. Alice will then tell Bob the value equal to $$$$$$min_{i=l}^{r} a[p_{t,i}].$$$$$$ Note that all rounds are independent of each other. In particular, the values of $$$a$$$, $$$u$$$ and $$$v$$$ can be different in different rounds. Bob is puzzled as he only knows the HLD solution, which requires $$$O(log(n))$$$ queries per round. So he needs your help to win the game. $$$^dagger$$$ The $$$operatorname{MEX}$$$ (minimum excludant) of a collection of integers $$$c_1, c_2, ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$. Interaction Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^4$$$)xa0— the number of test cases. Read it. The description of the test cases follows. The first line of each test case contains two positive integers $$$n$$$ and $$$q$$$ ($$$2 leq n leq 10^5$$$, $$$1 leq q leq 10^4$$$)xa0— the number of nodes in $$$T$$$ and the number of rounds respectively. The following next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n$$$, $$$u eq v$$$)xa0— denoting an edge between nodes $$$u$$$ and $$$v$$$. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of $$$n$$$ and $$$q$$$ over all test cases does not exceed $$$10^5$$$ and $$$10^4$$$ respectively. It is also guaranteed that the sum of $$$n cdot q$$$ does not exceed $$$3 cdot 10^6$$$. The interaction for each test case begins by outputting two permutations $$$p_1$$$ and $$$p_2$$$ of $$$[1, 2, ldots, n]$$$. On a new line, output $$$n$$$ space-separated distinct integers denoting $$$p_1$$$. In the next line, output $$$n$$$ space-separated distinct integers denoting $$$p_2$$$. Alice will start playing the game. For each round, you must read two integers, $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n$$$, $$$u eq v$$$). You need to find the $$$operatorname{MEX}$$$ of the values on the unique simple path between nodes $$$u$$$ and $$$v$$$. To make a query, output "? $$$t$$$ $$$l$$$ $$$r$$$" without quotes, such that $$$t$$$ is either $$$1$$$ or $$$2$$$, and $$$1 leq l leq r leq n$$$. Afterwards, you should read a single integer — the answer to your query $$$min_{i=l}^{r} a_{p_{t,i}}$$$. You can make at most $$$5$$$ such queries in each round. If you want to print the answer, output "! $$$x$$$" ($$$1 leq x, y leq n$$$) without quotes. After doing that, read a single integer, which is normally equal to $$$1$$$. If you receive the integer $$$-1$$$ instead of a valid reply, it means your program has made an invalid query, exceeded the query limit, or gave an incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream. After printing a query or the answer, do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: fflush(stdout) or cout.flush() in C++; System.out.flush() in Java; flush(output) in Pascal; stdout.flush() in Python; see documentation for other languages. Hacks To hack, follow the test format below. The first line should contain a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The first line of each test case should contain two positive integers $$$n$$$ and $$$q$$$ ($$$2 leq n leq 10^5$$$; $$$1 leq q leq 10^4$$$)xa0— the number of nodes in $$$T$$$ and the number of rounds respectively. The following next $$$n-1$$$ lines should contain two integers $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq n$$$, $$$u eq v$$$)xa0— denoting an edge between nodes $$$u$$$ and $$$v$$$. The given edges must form a tree. For each of the $$$q$$$ rounds, first print a permutation of $$$[0, 1, 2, ldots, n-1]$$$ on a new line, denoting the array $$$a$$$ chosen by Alice during the start of the round. In the following line, print two distinct nodes $$$u$$$ and $$$v$$$ ($$$1 leq u, v leq v$$$, $$$u eq v$$$), representing the endpoints of the path asked by Alice. The sum of $$$n$$$ and $$$q$$$ over all test cases should not exceed $$$10^5$$$ and $$$10^4$$$ respectively. The sum of $$$n cdot q$$$ should not exceed $$$3 cdot 10^6$$$.
3,300
false
false
false
false
false
true
false
false
false
false
703
1436B
Problem - 1436B - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags constructive algorithms math *900 No tag edit access → Contest materials based on Final Andersen Programming Contest 2020") . Editorial") xa0— the number of test cases. Each of the next $$$t$$$ lines contains a single integer $$$n$$$ ($$$2 le n le 100$$$)xa0— the required size of a square. Output For each test case print $$$n$$$ lines, each containing $$$n$$$ integersxa0— the prime square you built. If there are multiple answers, print any. Example Input 2 4 2 Output 4 6 8 1 4 9 9 9 4 10 10 65 1 4 4 4 1 1 1 1
900
true
false
false
false
false
true
false
false
false
false
3,490
1473A
You have an array $$$a_1, a_2, dots, a_n$$$. All $$$a_i$$$ are positive integers. In one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i eq j$$$; $$$i eq k$$$; $$$j eq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i.xa0e. make $$$a_i = a_j + a_k$$$. Can you make all $$$a_i$$$ lower or equal to $$$d$$$ using the operation above any number of times (possibly, zero)? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 2000$$$)xa0— the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$3 le n le 100$$$; $$$1 le d le 100$$$)xa0— the number of elements in the array $$$a$$$ and the value $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 100$$$)xa0— the array $$$a$$$. Output For each test case, print YES, if it's possible to make all elements $$$a_i$$$ less or equal than $$$d$$$ using the operation above. Otherwise, print NO. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer). Example Input 3 5 3 2 3 2 5 4 3 4 2 4 4 5 4 2 1 5 3 6 Note In the first test case, we can prove that we can't make all $$$a_i le 3$$$. In the second test case, all $$$a_i$$$ are already less or equal than $$$d = 4$$$. In the third test case, we can, for example, choose $$$i = 5$$$, $$$j = 1$$$, $$$k = 2$$$ and make $$$a_5 = a_1 + a_2 = 2 + 1 = 3$$$. Array $$$a$$$ will become $$$[2, 1, 5, 3, 3]$$$. After that we can make $$$a_3 = a_5 + a_2 = 3 + 1 = 4$$$. Array will become $$$[2, 1, 4, 3, 3]$$$ and all elements are less or equal than $$$d = 4$$$.
800
true
true
true
false
false
false
false
false
true
false
3,317