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
1950G
Vladislav has a playlist consisting of $$$n$$$ songs, numbered from $$$1$$$ to $$$n$$$. Song $$$i$$$ has genre $$$g_i$$$ and writer $$$w_i$$$. He wants to make a playlist in such a way that every pair of adjacent songs either have the same writer or are from the same genre (or both). He calls such a playlist exciting. Both $$$g_i$$$ and $$$w_i$$$ are strings of length no more than $$$10^4$$$. It might not always be possible to make an exciting playlist using all the songs, so the shuffling process occurs in two steps. First, some amount (possibly zero) of the songs are removed, and then the remaining songs in the playlist are rearranged to make it exciting. Since Vladislav doesn't like when songs get removed from his playlist, he wants the making playlist to perform as few removals as possible. Help him find the minimum number of removals that need to be performed in order to be able to rearrange the rest of the songs to make the playlist exciting. Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 16$$$)xa0— the number of songs in the original playlist. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains two strings of lowercase letters $$$g_i$$$ and $$$w_i$$$ ($$$1 leq g_i, w_i leq 10^4$$$)xa0— the genre and the writer of the $$$i$$$-th song. Where $$$g_i$$$ and $$$w_i$$$ are lengths of the strings. The sum of $$$2^n$$$ over all test cases does not exceed $$$2^{16}$$$. The sum of $$$g_i + w_i$$$ over all test cases does not exceed $$$4 cdot 10^5$$$. Output For each test case, output a single integerxa0— the minimum number of removals necessary so that the resulting playlist can be made exciting. Example Input 4 1 pop taylorswift 4 electronic themotans electronic carlasdreams pop themotans pop irinarimes 7 rap eminem rap drdre rap kanyewest pop taylorswift indierock arcticmonkeys indierock arcticmonkeys punkrock theoffspring 4 a b c d e f g h Note In the first test case, the playlist is already exciting. In the second test case, if you have the songs in the order $$$4, 3, 1, 2$$$, it is exciting, so you don't need to remove any songs. In the third test case, you can remove songs $$$4, 5, 6, 7$$$. Then the playlist with songs in the order $$$1, 2, 3$$$ is exciting.
1,900
false
false
true
true
false
false
false
false
false
true
575
417A
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of _c_ problems, the winners of the round are the first _n_ people in the rating list. Each of the additional elimination rounds consists of _d_ problems. The winner of the additional round is one person. Besides, _k_ winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least _n_·_m_ people should go to the finals. You need to organize elimination rounds in such a way, that at least _n_·_m_ people go to the finals, and the total amount of used problems in all rounds is as small as possible. Input The first line contains two integers _c_ and _d_ (1u2009≤u2009_c_,u2009_d_u2009≤u2009100)xa0— the number of problems in the main and additional rounds, correspondingly. The second line contains two integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u2009100). Finally, the third line contains an integer _k_ (1u2009≤u2009_k_u2009≤u2009100)xa0— the number of the pre-chosen winners. Output In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
1,500
true
false
true
true
false
false
false
false
false
false
8,157
1547B
A string $$$s$$$ of length $$$n$$$ ($$$1 le n le 26$$$) is called alphabetical if it can be obtained using the following algorithm: first, write an empty string to $$$s$$$ (i.e. perform the assignment $$$s$$$xa0:= ""); then perform the next step $$$n$$$ times; at the $$$i$$$-th step take $$$i$$$-th lowercase letter of the Latin alphabet and write it either to the left of the string $$$s$$$ or to the right of the string $$$s$$$ (i.e. perform the assignment $$$s$$$xa0:=xa0$$$c+s$$$ or $$$s$$$xa0:=xa0$$$s+c$$$, where $$$c$$$ is the $$$i$$$-th letter of the Latin alphabet). In other words, iterate over the $$$n$$$ first letters of the Latin alphabet starting from 'a' and etc. Each time we prepend a letter to the left of the string $$$s$$$ or append a letter to the right of the string $$$s$$$. Strings that can be obtained in that way are alphabetical. For example, the following strings are alphabetical: "a", "ba", "ab", "bac" and "ihfcbadeg". The following strings are not alphabetical: "z", "aa", "ca", "acb", "xyz" and "ddcba". From the given string, determine if it is alphabetical. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. Then $$$t$$$ test cases follow. Each test case is written on a separate line that contains one string $$$s$$$. String $$$s$$$ consists of lowercase letters of the Latin alphabet and has a length between $$$1$$$ and $$$26$$$, inclusive. Output Output $$$t$$$ lines, each of them must contain the answer to the corresponding test case. Output YES if the given string $$$s$$$ is alphabetical and NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive answer). Example Input 11 a ba ab bac ihfcbadeg z aa ca acb xyz ddcba Output YES YES YES YES YES NO NO NO NO NO NO Note The example contains test cases from the main part of the condition.
800
false
true
true
false
false
false
false
false
false
false
2,912
1346I
Polycarp is developing a new version of an old video game "Pac-Man". Though he really enjoyed playing the original game, he didn't like some aspects of it, so he decided to alter the rules a bit. In Polycarp's version, you play as Pac-Man and you have to collect pellets scattered over the game world while avoiding dangerous ghosts (no difference from the original yet). Polycarp didn't like the fact that there was no escape from the ghosts in the original, so, in his version, the game world is divided into $$$n$$$ safe zones with $$$m$$$ one-directional pathways between them — and it is guaranteed that Pac-Man can reach any safe zone from any other. Since safe zones are safe, the ghosts cannot attack Pac-Man while it is there, it is in danger only while traversing the pathways. Pac-Man starts the game in the safe zone $$$s$$$. All pellets are scattered over the safe zones; initially, the $$$i$$$-th safe zone contains $$$a_i$$$ pellets (and if Pac-Man is in a safe zone, it may freely collect all the pellets in it). The pellets disappear after being collected, but after the last pellet in the game world is collected, new pellets spawn in the safe zones in the same quantity as before ($$$a_i$$$ new pellets spawn in the $$$i$$$-th zone). The pellets can be respawned any number of times, so the game is essentially infinite. Polycarp has already determined the structure of the game world and the number of pellets in each safe zone. Now he is trying to find out if the game is difficult enough. There are $$$q$$$ goals in the game, the $$$i$$$-th goal is to collect at least $$$C_i$$$ pellets from the beginning of the game. Polycarp denotes the difficulty of the $$$i$$$-th goal as the minimum number of times the player has to traverse a one-directional pathway in order to collect $$$C_i$$$ pellets (since only traversing a pathway puts Pac-Man in danger). If some pathway is traversed multiple times while Pac-Man is collecting the pellets, it is included in the answer the same number of times. Help Polycarp to calculate the difficulty of each goal! Input The first line contains four integers $$$n$$$, $$$m$$$, $$$q$$$ and $$$s$$$ ($$$2 le n le 15$$$; $$$n le m le n(n-1)$$$; $$$1 le q le 5000$$$; $$$1 le s le n$$$) — the number of safe zones, the number of pathways, the number of goals and the index of the starting safe zone, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 le a_i le 10^9$$$), where $$$a_i$$$ is the initial number of pellets in the $$$i$$$-th safe zone (and the number of pellets that spawn in the $$$i$$$-th safe zone when the last pellet in the world is collected). Then $$$m$$$ lines follow, each line contains two integers $$$v_i$$$ and $$$u_i$$$ ($$$1 le v_i, u_i le n$$$; $$$v_i e u_i$$$) denoting a one-directional pathway from the safe zone $$$v_i$$$ to the safe zone $$$u_i$$$. Each ordered pair $$$(v_i, u_i)$$$ appears in this section at most once (there are no multiple pathways from $$$v_i$$$ to $$$u_i$$$), and it is possible to reach every safe zone from every other safe zone using these pathways. The last line contains $$$q$$$ integers $$$C_1$$$, $$$C_2$$$, ..., $$$C_q$$$ ($$$1 le C_i le 10^{15}$$$), where $$$C_i$$$ is the minimum number of pellets the player has to collect in order to fulfil the $$$i$$$-th goal. Output For each goal $$$i$$$, print one integer — its difficulty (the minimum number of times the player has to traverse along some pathway in order to collect at least $$$C_i$$$ pellets). Examples Input 3 4 2 1 3 1 2 1 2 2 1 1 3 3 1 5 8 Input 5 7 4 2 1 3 2 2 1 2 3 4 2 3 4 3 1 1 4 5 4 4 5 7 14 23 27 Input 4 4 3 3 2 3 1 4 3 4 4 1 1 2 2 3 13 42 1337 Note Consider the first test. In order to collect $$$5$$$ pellets, the player should collect $$$3$$$ pellets in the safe zone $$$1$$$ (which is starting), move to zone $$$3$$$, collect $$$2$$$ pellets there. In order to collect $$$8$$$ pellets, the player should collect $$$3$$$ pellets in the safe zone $$$1$$$, go to $$$2$$$, collect $$$1$$$ pellet, go to $$$1$$$ without getting pellets, go to $$$3$$$, collect $$$2$$$ pellets. Now the last pellet in the world is collected, so they are respawned. The player can collect $$$2$$$ pellets in the safe zone $$$3$$$ and now the number of collected pellets is $$$8$$$. Consider the second test. In order to collect $$$7$$$ pellets let's do the following: $$$2(+3) ightarrow 3(+2) ightarrow 4(+2)$$$. In such a way $$$7$$$ pellets were collected. In order to collect $$$14$$$ pellets let's do the following: $$$2(+3) ightarrow 3(+2) ightarrow 1(+1) ightarrow 4(+2) ightarrow 5(+1)$$$ respawn of pellets $$$5(+1) ightarrow 4 (+2) ightarrow 2(+3)$$$. In such a way $$$15$$$ pellets were collected. In order to collect $$$23$$$ pellets let's do the following: $$$2(+3) ightarrow 3(+2) ightarrow 1(+1) ightarrow 4(+2) ightarrow 5(+1)$$$ respawn of pellets $$$5(+1) ightarrow 4(+2) ightarrow 2(+3) ightarrow 3(+2) ightarrow 1(+1)$$$ respawn of pellets $$$1(+1) ightarrow 4(+2) ightarrow 2(+3)$$$. In such a way $$$24$$$ pellets were collected.
2,900
false
false
false
true
false
false
false
false
false
false
3,971
605A
Problem - 605A - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags constructive algorithms greedy *1600 No tag edit access → Contest materials and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? Input The first line of the input contains integer _n_ (1u2009≤u2009_n_u2009≤u2009100u2009000)xa0— the number of cars in the train. The second line contains _n_ integers _p__i_ (1u2009≤u2009_p__i_u2009≤u2009_n_, _p__i_u2009≠u2009_p__j_ if _i_u2009≠u2009_j_)xa0— the sequence of the numbers of the cars in the train. Output Print a single integerxa0— the minimum number of actions needed to sort the railway cars. Examples Input 5 4 1 2 5 3 Output 2 Input 4 4 1 3 2 Output 2 Note In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
1,600
false
true
false
false
false
true
false
false
false
false
7,426
1181C
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $$$n cdot m$$$ colored pieces that form a rectangle with $$$n$$$ rows and $$$m$$$ columns. The colored pieces attracted Innokenty's attention so he immediately came up with the following business plan. If he cuts out a subrectangle consisting of three colored stripes, he can sell it as a flag of some country. Innokenty decided that a subrectangle is similar enough to a flag of some country if it consists of three stripes of equal heights placed one above another, where each stripe consists of cells of equal color. Of course, the color of the top stripe must be different from the color of the middle stripe; and the color of the middle stripe must be different from the color of the bottom stripe. Innokenty has not yet decided what part he will cut out, but he is sure that the flag's boundaries should go along grid lines. Also, Innokenty won't rotate the blanket. Please help Innokenty and count the number of different subrectangles Innokenty can cut out and sell as a flag. Two subrectangles located in different places but forming the same flag are still considered different. xa0xa0These subrectangles are flags. xa0xa0xa0xa0xa0These subrectangles are not flags. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 1,000$$$)xa0— the number of rows and the number of columns on the blanket. Each of the next $$$n$$$ lines contains $$$m$$$ lowercase English letters from 'a' to 'z' and describes a row of the blanket. Equal letters correspond to equal colors, different letters correspond to different colors. Output In the only line print the number of subrectangles which form valid flags. Note xa0The selected subrectangles are flags in the first example.
1,900
false
false
true
true
false
false
true
false
false
false
4,812
1927D
You are given an array $$$a$$$ of $$$n$$$ integers, and $$$q$$$ queries. Each query is represented by two integers $$$l$$$ and $$$r$$$ ($$$1 le l le r le n$$$). Your task is to find, for each query, two indices $$$i$$$ and $$$j$$$ (or determine that they do not exist) such that: $$$l le i le r$$$; $$$l le j le r$$$; $$$a_i e a_j$$$. In other words, for each query, you need to find a pair of different elements among $$$a_l, a_{l+1}, dots, a_r$$$, or report that such a pair does not exist. Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$)xa0— the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^6$$$)xa0— the elements of the array $$$a$$$. The third line of each test case contains a single integer $$$q$$$ ($$$1 le q le 2 cdot 10^5$$$)xa0— the number of queries. The next $$$q$$$ lines contain two integers each, $$$l$$$ and $$$r$$$ ($$$1 le l < r le n$$$)xa0— the boundaries of the query. It is guaranteed that the sum of the values of $$$n$$$ across all test cases does not exceed $$$2 cdot 10^5$$$. Similarly, it is guaranteed that the sum of the values of $$$q$$$ across all test cases does not exceed $$$2 cdot 10^5$$$. Output For each query, output two integers separated by space: $$$i$$$ and $$$j$$$ ($$$l le i, j le r$$$), for which $$$a_i e a_j$$$. If such a pair does not exist, output $$$i=-1$$$ and $$$j=-1$$$. You may separate the outputs for the test cases with empty lines. This is not a mandatory requirement. Example Input 5 5 1 1 2 1 1 3 1 5 1 2 1 3 6 30 20 20 10 10 20 5 1 2 2 3 2 4 2 6 3 5 4 5 2 3 4 4 1 2 1 4 2 3 2 4 5 1 4 3 2 4 5 1 5 2 4 3 4 3 5 4 5 5 2 3 1 4 2 7 1 2 1 4 1 5 2 4 2 5 3 5 4 5 Output 2 3 -1 -1 1 3 2 1 -1 -1 4 2 4 6 5 3 1 2 1 2 2 3 3 2 1 3 2 4 3 4 5 3 5 4 1 2 4 2 1 3 2 3 3 2 5 4 5 4
1,300
false
true
false
true
true
false
true
true
false
false
727
380E
Problem - 380E - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags data structures *2600 No tag edit access → Contest materials ; 2. consecutively perform assignments: . Let's use function _g_(_a_,u2009_x_) to represent the largest value that can be obtained from variable _x_, using the described operation any number of times and sequence _a_. Sereja has sequence _b_1,u2009_b_2,u2009...,u2009_b__b_. Help Sereja calculate sum: . Record
2,600
false
false
false
false
true
false
false
false
false
false
8,306
1043B
Bajtek, known for his unusual gifts, recently got an integer array $$$x_0, x_1, ldots, x_{k-1}$$$. Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array $$$a$$$ of length $$$n + 1$$$. As a formal description of $$$a$$$ says, $$$a_0 = 0$$$ and for all other $$$i$$$xa0($$$1 le i le n$$$) $$$a_i = x_{(i-1)bmod k} + a_{i-1}$$$, where $$$p bmod q$$$ denotes the remainder of division $$$p$$$ by $$$q$$$. For example, if the $$$x = [1, 2, 3]$$$ and $$$n = 5$$$, then: $$$a_0 = 0$$$, $$$a_1 = x_{0bmod 3}+a_0=x_0+0=1$$$, $$$a_2 = x_{1bmod 3}+a_1=x_1+1=3$$$, $$$a_3 = x_{2bmod 3}+a_2=x_2+3=6$$$, $$$a_4 = x_{3bmod 3}+a_3=x_0+6=7$$$, $$$a_5 = x_{4bmod 3}+a_4=x_1+7=9$$$. So, if the $$$x = [1, 2, 3]$$$ and $$$n = 5$$$, then $$$a = [0, 1, 3, 6, 7, 9]$$$. Now the boy hopes that he will be able to restore $$$x$$$ from $$$a$$$! Knowing that $$$1 le k le n$$$, help him and find all possible values of $$$k$$$xa0— possible lengths of the lost array. Input The first line contains exactly one integer $$$n$$$ ($$$1 le n le 1000$$$)xa0— the length of the array $$$a$$$, excluding the element $$$a_0$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^6$$$). Note that $$$a_0$$$ is always $$$0$$$ and is not given in the input. Output The first line of the output should contain one integer $$$l$$$ denoting the number of correct lengths of the lost array. The second line of the output should contain $$$l$$$ integersxa0— possible lengths of the lost array in increasing order. Note In the first example, any $$$k$$$ is suitable, since $$$a$$$ is an arithmetic progression. Possible arrays $$$x$$$: $$$[1]$$$ $$$[1, 1]$$$ $$$[1, 1, 1]$$$ $$$[1, 1, 1, 1]$$$ $$$[1, 1, 1, 1, 1]$$$ In the second example, Bajtek's array can have three or five elements. Possible arrays $$$x$$$: $$$[1, 2, 2]$$$ $$$[1, 2, 2, 1, 2]$$$ For example, $$$k = 4$$$ is bad, since it leads to $$$6 + x_0 = 8$$$ and $$$0 + x_0 = 1$$$, which is an obvious contradiction. In the third example, only $$$k = n$$$ is good. Array $$$[1, 4, -2]$$$ satisfies the requirements. Note that $$$x_i$$$ may be negative.
1,200
false
false
true
false
false
false
false
false
false
false
5,482
1805F2
This is the hard version of the problem. It differs from the easy one only in constraints on $$$n$$$. You can make hacks only if you lock both versions. Let $$$a_1, a_2, ldots, a_n$$$ be an array of non-negative integers. Let $$$F(a_1, a_2, ldots, a_n)$$$ be the sorted in the non-decreasing order array of $$$n - 1$$$ smallest numbers of the form $$$a_i + a_j$$$, where $$$1 le i < j le n$$$. In other words, $$$F(a_1, a_2, ldots, a_n)$$$ is the sorted in the non-decreasing order array of $$$n - 1$$$ smallest sums of all possible pairs of elements of the array $$$a_1, a_2, ldots, a_n$$$. For example, $$$F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7]$$$. You are given an array of non-negative integers $$$a_1, a_2, ldots, a_n$$$. Determine the single element of the array $$$underbrace{F(F(Fldots F}_{n-1}(a_1, a_2, ldots, a_n)ldots))$$$. Since the answer can be quite large, output it modulo $$$10^9+7$$$. Input The first line contains one integer $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$)xa0— the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^9$$$)xa0— the array elements. Output Output a single numberxa0— the answer modulo $$$10^9 + 7$$$. Examples Input 3 1000000000 1000000000 777 Note In the first test, the array is transformed as follows: $$$[1, 2, 4, 5, 6] o [3, 5, 6, 6] o [8, 9, 9] o [17, 17] o [34]$$$. The only element of the final array is $$$34$$$. In the second test, $$$F(a_1, a_2, ldots, a_n)$$$ is $$$[2, 2, 2, 8, 8, 8, 8, 8]$$$. This array is made up of $$$3$$$ numbers of the form $$$1 + 1$$$ and $$$5$$$ numbers of the form $$$1 + 7$$$. In the fourth test, the array is transformed as follows: $$$[10^9, 10^9, 777] o [10^9+777, 10^9+777] o [2 cdot 10^9 + 1554]$$$. $$$2 cdot 10^9 + 1554$$$ modulo $$$10^9+7$$$ equals $$$1540$$$.
3,100
true
true
false
false
false
false
false
false
true
false
1,443
521D
Vasya plays one very well-known and extremely popular MMORPG game. His game character has _k_ skill; currently the _i_-th of them equals to _a__i_. Also this game has a common rating table in which the participants are ranked according to the product of all the skills of a hero in the descending order. Vasya decided to 'upgrade' his character via the game store. This store offers _n_ possible ways to improve the hero's skills; Each of these ways belongs to one of three types: 1. assign the _i_-th skill to _b_; 2. add _b_ to the _i_-th skill; 3. multiply the _i_-th skill by _b_. Unfortunately, a) every improvement can only be used once; b) the money on Vasya's card is enough only to purchase not more than _m_ of the _n_ improvements. Help Vasya to reach the highest ranking in the game. To do this tell Vasya which of improvements he has to purchase and in what order he should use them to make his rating become as high as possible. If there are several ways to achieve it, print any of them. Input The first line contains three numbers — _k_,u2009_n_,u2009_m_ (1u2009≤u2009_k_u2009≤u2009105, 0u2009≤u2009_m_u2009≤u2009_n_u2009≤u2009105) — the number of skills, the number of improvements on sale and the number of them Vasya can afford. The second line contains _k_ space-separated numbers _a__i_ (1u2009≤u2009_a__i_u2009≤u2009106), the initial values of skills. Next _n_ lines contain 3 space-separated numbers _t__j_,u2009_i__j_,u2009_b__j_ (1u2009≤u2009_t__j_u2009≤u20093,u20091u2009≤u2009_i__j_u2009≤u2009_k_,u20091u2009≤u2009_b__j_u2009≤u2009106) — the type of the _j_-th improvement (1 for assigning, 2 for adding, 3 for multiplying), the skill to which it can be applied and the value of _b_ for this improvement. Output The first line should contain a number _l_ (0u2009≤u2009_l_u2009≤u2009_m_) — the number of improvements you should use. The second line should contain _l_ distinct space-separated numbers _v__i_ (1u2009≤u2009_v__i_u2009≤u2009_n_) — the indices of improvements in the order in which they should be applied. The improvements are numbered starting from 1, in the order in which they appear in the input. Examples Input 2 4 3 13 20 1 1 14 1 2 30 2 1 6 3 2 2
2,800
false
true
false
false
false
false
false
false
false
false
7,752
45C
There are _n_ people taking dancing lessons. Every person is characterized by his/her dancing skill _a__i_. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, having the minimal difference in dancing skills start to dance. If there are several such couples, the one first from the left starts to dance. After a couple leaves to dance, the line closes again, i.e. as a result the line is always continuous. The difference in dancing skills is understood as the absolute value of difference of _a__i_ variable. Your task is to find out what pairs and in what order will start dancing. Input The first line contains an integer _n_ (1u2009≤u2009_n_u2009≤u20092·105) — the number of people. The next line contains _n_ symbols B or G without spaces. B stands for a boy, G stands for a girl. The third line contains _n_ space-separated integers _a__i_ (1u2009≤u2009_a__i_u2009≤u2009107) — the dancing skill. People are specified from left to right in the order in which they lined up. Output Print the resulting number of couples _k_. Then print _k_ lines containing two numerals each — the numbers of people forming the couple. The people are numbered with integers from 1 to _n_ from left to right. When a couple leaves to dance you shouldn't renumber the people. The numbers in one couple should be sorted in the increasing order. Print the couples in the order in which they leave to dance.
1,900
false
false
false
false
true
false
false
false
false
false
9,757
1553F
Problem - 1553F - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags data structures math *2300 No tag edit access → Contest materials ") Editorial") . The second line contains $$$n$$$ space-separated distinct integers $$$a_1, ldots, a_n$$$ ($$$1 le a_i le 3 cdot 10^5$$$, $$$a_i eq a_j$$$ if $$$i eq j$$$). Output Print $$$n$$$ integers $$$p_1, p_2, ldots, p_n$$$. Examples Input 4 6 2 7 3 Output 0 2 12 22 Input 3 3 2 1 Output 0 3 5
2,300
true
false
false
false
true
false
false
false
false
false
2,870
1426A
Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is $$$n$$$. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains $$$2$$$ apartments, every other floor contains $$$x$$$ apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers $$$1$$$ and $$$2$$$, apartments on the second floor have numbers from $$$3$$$ to $$$(x + 2)$$$, apartments on the third floor have numbers from $$$(x + 3)$$$ to $$$(2 cdot x + 2)$$$, and so on. Your task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least $$$n$$$ apartments. You have to answer $$$t$$$ independent test cases. Input The first line of the input contains one integer $$$t$$$ ($$$1 le t le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 le n, x le 1000$$$) — the number of Petya's apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor). Output For each test case, print the answer: the number of floor on which Petya lives. Example Input 4 7 3 1 5 22 5 987 13 Note Consider the first test case of the example: the first floor contains apartments with numbers $$$1$$$ and $$$2$$$, the second one contains apartments with numbers $$$3$$$, $$$4$$$ and $$$5$$$, the third one contains apartments with numbers $$$6$$$, $$$7$$$ and $$$8$$$. Therefore, Petya lives on the third floor. In the second test case of the example, Petya lives in the apartment $$$1$$$ which is on the first floor.
800
true
false
true
false
false
false
false
false
false
false
3,539
254C
String _x_ is an anagram of string _y_, if we can rearrange the letters in string _x_ and get exact string _y_. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA" are not. You are given two strings _s_ and _t_ of the same length, consisting of uppercase English letters. You need to get the anagram of string _t_ from string _s_. You are permitted to perform the replacing operation: every operation is replacing some character from the string _s_ by any other character. Get the anagram of string _t_ in the least number of replacing operations. If you can get multiple anagrams of string _t_ in the least number of operations, get the lexicographically minimal one. The lexicographic order of strings is the familiar to us "dictionary" order. Formally, the string _p_ of length _n_ is lexicographically smaller than string _q_ of the same length, if _p_1u2009=u2009_q_1, _p_2u2009=u2009_q_2, ..., _p__k_u2009-u20091u2009=u2009_q__k_u2009-u20091, _p__k_u2009<u2009_q__k_ for some _k_ (1u2009≤u2009_k_u2009≤u2009_n_). Here characters in the strings are numbered from 1. The characters of the strings are compared in the alphabetic order. Input The input consists of two lines. The first line contains string _s_, the second line contains string _t_. The strings have the same length (from 1 to 105 characters) and consist of uppercase English letters. Output In the first line print _z_ — the minimum number of replacement operations, needed to get an anagram of string _t_ from string _s_. In the second line print the lexicographically minimum anagram that could be obtained in _z_ operations. Note The second sample has eight anagrams of string _t_, that can be obtained from string _s_ by replacing exactly two letters: "ADBADC", "ADDABC", "CDAABD", "CDBAAD", "CDBADA", "CDDABA", "DDAABC", "DDBAAC". These anagrams are listed in the lexicographical order. The lexicographically minimum anagram is "ADBADC".
1,800
false
true
false
false
false
false
false
false
false
false
8,817
1372B
In Omkar's last class of math, he learned about the least common multiple, or $$$LCM$$$. $$$LCM(a, b)$$$ is the smallest positive integer $$$x$$$ which is divisible by both $$$a$$$ and $$$b$$$. Omkar, having a laudably curious mind, immediately thought of a problem involving the $$$LCM$$$ operation: given an integer $$$n$$$, find positive integers $$$a$$$ and $$$b$$$ such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum value possible. Can you help Omkar solve his ludicrously challenging math problem? Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 leq t leq 10$$$). Description of the test cases follows. Each test case consists of a single integer $$$n$$$ ($$$2 leq n leq 10^{9}$$$). Output For each test case, output two positive integers $$$a$$$ and $$$b$$$, such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum possible. Note For the first test case, the numbers we can choose are $$$1, 3$$$ or $$$2, 2$$$. $$$LCM(1, 3) = 3$$$ and $$$LCM(2, 2) = 2$$$, so we output $$$2 2$$$. For the second test case, the numbers we can choose are $$$1, 5$$$, $$$2, 4$$$, or $$$3, 3$$$. $$$LCM(1, 5) = 5$$$, $$$LCM(2, 4) = 4$$$, and $$$LCM(3, 3) = 3$$$, so we output $$$3 3$$$. For the third test case, $$$LCM(3, 6) = 6$$$. It can be shown that there are no other pairs of numbers which sum to $$$9$$$ that have a lower $$$LCM$$$.
1,300
true
true
false
false
false
false
false
false
false
false
3,806
116B
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size _n_u2009×u2009_m_. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs. They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf. What is the maximum number of little pigs that may be eaten by the wolves? Input The first line contains integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u200910) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow _n_ lines containing _m_ characters each — that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf. It is guaranteed that there will be at most one wolf adjacent to any little pig. Output Print a single number — the maximal number of little pigs that may be eaten by the wolves. Note In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows.
1,100
false
true
true
false
false
false
false
false
false
false
9,422
899C
Problem - 899C - 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 graphs math *1300 No tag edit access → Contest materials ") Editorial") — the number of integers Petya has. Output Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. Examples Input 4 Output 0 2 1 4 Input 2 Output 1 1 1 Note In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
1,300
true
false
false
false
false
true
false
false
false
true
6,150
1418A
You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $$$k$$$ torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: exchange $$$1$$$ stick for $$$x$$$ sticks (you lose $$$1$$$ stick and gain $$$x$$$ sticks). exchange $$$y$$$ sticks for $$$1$$$ coal (you lose $$$y$$$ sticks and gain $$$1$$$ coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order. Your task is to find the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints. You have to answer $$$t$$$ independent test cases. Input The first line of the input contains one integer $$$t$$$ ($$$1 le t le 2 cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$ and $$$k$$$ ($$$2 le x le 10^9$$$; $$$1 le y, k le 10^9$$$) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively. Output For each test case, print the answer: the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints. Example Input 5 2 1 5 42 13 24 12 11 12 1000000000 1000000000 1000000000 2 1000000000 1000000000 Output 14 33 25 2000000003 1000000001999999999
1,000
true
false
false
false
false
false
false
false
false
false
3,594
1824B2
This is the hard version of the problem. The only difference is that in this version $$$kle n$$$. You can make hacks only if both versions of the problem are solved. Chtholly and the floating islands. LuoTianyi now lives in a world with $$$n$$$ floating islands. The floating islands are connected by $$$n-1$$$ undirected air routes, and any two of them can reach each other by passing the routes. That means, the $$$n$$$ floating islands form a tree. One day, LuoTianyi wants to meet her friends: Chtholly, Nephren, William, .... Totally, she wants to meet $$$k$$$ people. She doesn't know the exact positions of them, but she knows that they are in pairwise distinct islands. She define an island is good if and only if the sum of the distances$$$^{dagger}$$$ from it to the islands with $$$k$$$ people is the minimal among all the $$$n$$$ islands. Now, LuoTianyi wants to know that, if the $$$k$$$ people are randomly set in $$$k$$$ distinct of the $$$n$$$ islands, then what is the expect number of the good islands? You just need to tell her the expect number modulo $$$10^9+7$$$. $$$^{dagger}$$$The distance between two islands is the minimum number of air routes you need to take to get from one island to the other. Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1le k le n le 2cdot 10^5$$$) — the number of the islands and people respectively. Next $$$n−1$$$ lines describe the air routes. The $$$i$$$-th of them contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 le u_i,v_i le n, u_i eq v_i$$$) — the islands connected by the $$$i$$$-th air route. Output Print a single integer — the expect number of the good islands modulo $$$10^9 + 7$$$. Formally, let $$$M = 10^9 + 7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q ot equiv 0$$$ ($$$operatorname{mod} M$$$). Output the integer equal to $$$p cdot q^{-1}$$$ $$$operatorname{mod} M$$$. In other words, output such an integer $$$x$$$ that $$$0 le x < M$$$ and $$$x cdot q equiv p$$$ ($$$operatorname{mod} M$$$). Note In the first example the air routes form the following tree: If the people are in the islands $$$1$$$ and $$$2$$$, then islands $$$1$$$ and $$$2$$$ will be good. The sum of the distances from island $$$1$$$ or $$$2$$$ to all the people is $$$1+0=1$$$, which is the minimal. While the sum of the distances from island $$$3$$$ to all the people is $$$2+1=3$$$, which is greater than $$$1$$$. Like this, when the people are in island $$$1$$$ and $$$3$$$, then islands $$$1,2$$$ and $$$3$$$ will be good. When the people are in islands $$$1$$$ and $$$4$$$, then islands $$$1,2,3$$$ and $$$4$$$ will be good. When the people are in islands $$$2$$$ and $$$3$$$, then islands $$$2$$$ and $$$3$$$ will be good. When the people are in islands $$$2$$$ and $$$4$$$, then islands $$$2,3$$$ and $$$4$$$ will be good. When the people are in islands $$$3$$$ and $$$4$$$, then islands $$$3$$$ and $$$4$$$ will be good. So the expect of the number of the good islands is $$$frac{16}{6}$$$, which equals to $$$666666674$$$ modulo $$$10^9+7$$$. In the second example the air routes form the following tree: We can see that there is one person in each island, and only the island $$$3$$$ is good. So the expect number is $$$1$$$.
2,300
true
false
false
false
false
false
false
false
false
false
1,335
765F
Artsem is on vacation and wants to buy souvenirs for his two teammates. There are _n_ souvenir shops along the street. In _i_-th shop Artsem can buy one souvenir for _a__i_ dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price. Artsem has visited the shopping street _m_ times. For some strange reason on the _i_-th day only shops with numbers from _l__i_ to _r__i_ were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops. In other words, for each Artsem's visit you should find the minimum possible value of _a__s_u2009-u2009_a__t_ where _l__i_u2009≤u2009_s_,u2009_t_u2009≤u2009_r__i_, _s_u2009≠u2009_t_. Input The first line contains an integer _n_ (2u2009≤u2009_n_u2009≤u2009105). The second line contains _n_ space-separated integers _a_1, ..., _a__n_ (0u2009≤u2009_a__i_u2009≤u2009109). The third line contains the number of queries _m_ (1u2009≤u2009_m_u2009≤u20093·105). Next _m_ lines describe the queries. _i_-th of these lines contains two space-separated integers _l__i_ and _r__i_ denoting the range of shops working on _i_-th day (1u2009≤u2009_l__i_u2009<u2009_r__i_u2009≤u2009_n_). Output Print the answer to each query in a separate line. Example Input 8 3 1 4 1 5 9 2 6 4 1 8 1 3 4 8 5 7
3,100
false
false
false
false
true
false
false
false
false
false
6,725
978G
Petya studies at university. The current academic year finishes with $$$n$$$ special days. Petya needs to pass $$$m$$$ exams in those special days. The special days in this problem are numbered from $$$1$$$ to $$$n$$$. There are three values about each exam: $$$s_i$$$ — the day, when questions for the $$$i$$$-th exam will be published, $$$d_i$$$ — the day of the $$$i$$$-th exam ($$$s_i < d_i$$$), $$$c_i$$$ — number of days Petya needs to prepare for the $$$i$$$-th exam. For the $$$i$$$-th exam Petya should prepare in days between $$$s_i$$$ and $$$d_i-1$$$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $$$i$$$-th exam in day $$$j$$$, then $$$s_i le j < d_i$$$. It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days. Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible. Input The first line contains two integers $$$n$$$ and $$$m$$$ $$$(2 le n le 100, 1 le m le n)$$$ — the number of days and the number of exams. Each of the following $$$m$$$ lines contains three integers $$$s_i$$$, $$$d_i$$$, $$$c_i$$$ $$$(1 le s_i < d_i le n, 1 le c_i le n)$$$ — the day, when questions for the $$$i$$$-th exam will be given, the day of the $$$i$$$-th exam, number of days Petya needs to prepare for the $$$i$$$-th exam. Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given. Output If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $$$n$$$ integers, where the $$$j$$$-th number is: $$$(m + 1)$$$, if the $$$j$$$-th day is a day of some exam (recall that in each day no more than one exam is conducted), zero, if in the $$$j$$$-th day Petya will have a rest, $$$i$$$ ($$$1 le i le m$$$), if Petya will prepare for the $$$i$$$-th exam in the day $$$j$$$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $$$1$$$. If there are multiple schedules, print any of them. Examples Input 10 3 4 7 2 1 10 3 8 9 1 Output 2 2 2 1 1 0 4 3 4 4 Note In the first example Petya can, for example, prepare for exam $$$1$$$ in the first day, prepare for exam $$$2$$$ in the second day, pass exam $$$1$$$ in the third day, relax in the fourth day, and pass exam $$$2$$$ in the fifth day. So, he can prepare and pass all exams. In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.
1,700
false
true
true
false
false
false
false
false
true
false
5,812
1239A
Problem - 1239A - 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 math *1700 No tag edit access → Contest materials ") pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$. Input The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n, m le 100,000$$$), the number of rows and the number of columns of the field. Output Print one integer, the number of random pictures modulo $$$10^9 + 7$$$. Example Input 2 3 Output 8 Note The picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$.
1,700
true
false
false
true
false
false
false
false
false
false
4,496
1082A
Vasya is reading a e-book. The file of the book consists of $$$n$$$ pages, numbered from $$$1$$$ to $$$n$$$. The screen is currently displaying the contents of page $$$x$$$, and Vasya wants to read the page $$$y$$$. There are two buttons on the book which allow Vasya to scroll $$$d$$$ pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of $$$10$$$ pages, and $$$d = 3$$$, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth. Help Vasya to calculate the minimum number of times he needs to press a button to move to page $$$y$$$. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10^3$$$) — the number of testcases. Each testcase is denoted by a line containing four integers $$$n$$$, $$$x$$$, $$$y$$$, $$$d$$$ ($$$1le n, d le 10^9$$$, $$$1 le x, y le n$$$) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively. Output Print one line for each test. If Vasya can move from page $$$x$$$ to page $$$y$$$, print the minimum number of times he needs to press a button to do it. Otherwise print $$$-1$$$. Example Input 3 10 4 5 2 5 1 3 4 20 4 19 3 Note In the first test case the optimal sequence is: $$$4 ightarrow 2 ightarrow 1 ightarrow 3 ightarrow 5$$$. In the second test case it is possible to get to pages $$$1$$$ and $$$5$$$. In the third test case the optimal sequence is: $$$4 ightarrow 7 ightarrow 10 ightarrow 13 ightarrow 16 ightarrow 19$$$.
1,200
true
false
true
false
false
false
false
false
false
false
5,315
1721C
You are given an array $$$a_1, a_2, dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, dots, b_n$$$: 1. Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-negative integers. 2. Set $$$b_i = a_i + d_i$$$ for each $$$b_i$$$. 3. Sort the array $$$b$$$ in non-descending order. You are given the resulting array $$$b$$$. For each index $$$i$$$, calculate what is the minimum and maximum possible value of $$$d_i$$$ you can choose in order to get the given array $$$b$$$. Note that the minimum (maximum) $$$d_i$$$-s are independent of each other, i.xa0e. they can be obtained from different possible arrays $$$d$$$. Input The first line contains the single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— 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$$$)xa0— the length of arrays $$$a$$$, $$$b$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^9$$$; $$$a_i le a_{i+1}$$$)xa0— the array $$$a$$$ in non-descending order. The third line contains $$$n$$$ integers $$$b_1, b_2, dots, b_n$$$ ($$$1 le b_i le 10^9$$$; $$$b_i le b_{i+1}$$$)xa0— the array $$$b$$$ in non-descending order. Additional constraints on the input: there is at least one way to obtain the array $$$b$$$ from the $$$a$$$ by choosing an array $$$d$$$ consisting of non-negative integers; the sum of $$$n$$$ doesn't exceed $$$2 cdot 10^5$$$. Output For each test case, print two lines. In the first line, print $$$n$$$ integers $$$d_1^{min}, d_2^{min}, dots, d_n^{min}$$$, where $$$d_i^{min}$$$ is the minimum possible value you can add to $$$a_i$$$. Secondly, print $$$n$$$ integers $$$d_1^{max}, d_2^{max}, dots, d_n^{max}$$$, where $$$d_i^{max}$$$ is the maximum possible value you can add to $$$a_i$$$. All $$$d_i^{min}$$$ and $$$d_i^{max}$$$ values are independent of each other. In other words, for each $$$i$$$, $$$d_i^{min}$$$ is just the minimum value among all possible values of $$$d_i$$$. Example Input 4 3 2 3 5 7 11 13 1 1000 5000 4 1 2 3 4 1 2 3 4 4 10 20 30 40 22 33 33 55 Output 5 4 2 11 10 8 4000 4000 0 0 0 0 0 0 0 0 12 2 3 15 23 13 3 15 Note In the first test case, in order to get $$$d_1^{min} = 5$$$, we can choose, for example, $$$d = [5, 10, 6]$$$. Then $$$b$$$ $$$=$$$ $$$[2+5,3+10,5+6]$$$ $$$=$$$ $$$[7,13,11]$$$ $$$=$$$ $$$[7,11,13]$$$. For $$$d_2^{min} = 4$$$, we can choose $$$d$$$ $$$=$$$ $$$[9, 4, 8]$$$. Then $$$b$$$ $$$=$$$ $$$[2+9,3+4,5+8]$$$ $$$=$$$ $$$[11,7,13]$$$ $$$=$$$ $$$[7,11,13]$$$.
1,400
false
true
false
false
false
false
false
true
false
false
1,957
734D
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help. Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move. Help Anton and write the program that for the given position determines whether the white king is in check. Remainder, on how do chess pieces move: Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells. Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells. Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap". Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u2009500u2009000)xa0— the number of black pieces. The second line contains two integers _x_0 and _y_0 (u2009-u2009109u2009≤u2009_x_0,u2009_y_0u2009≤u2009109)xa0— coordinates of the white king. Then follow _n_ lines, each of them contains a character and two integers _x__i_ and _y__i_ (u2009-u2009109u2009≤u2009_x__i_,u2009_y__i_u2009≤u2009109)xa0— type of the _i_-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position. Output The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise. Note Picture for the first sample: White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES". Picture for the second sample: Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".
1,700
false
false
true
false
false
false
false
false
false
false
6,855
31D
Bob has a rectangular chocolate bar of the size _W_u2009×u2009_H_. He introduced a cartesian coordinate system so that the point (0,u20090) corresponds to the lower-left corner of the bar, and the point (_W_,u2009_H_) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line _x_u2009=u2009_x__c_ or _y_u2009=u2009_y__c_, where _x__c_ and _y__c_ are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made _n_ breaks and wrote them down in his notebook in arbitrary order. At the end he got _n_u2009+u20091 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. Input The first line contains 3 integers _W_, _H_ and _n_ (1u2009≤u2009_W_,u2009_H_,u2009_n_u2009≤u2009100) — width of the bar, height of the bar and amount of breaks. Each of the following _n_ lines contains four integers _x__i_,u20091,u2009_y__i_,u20091,u2009_x__i_,u20092,u2009_y__i_,u20092 — coordinates of the endpoints of the _i_-th break (0u2009≤u2009_x__i_,u20091u2009≤u2009_x__i_,u20092u2009≤u2009_W_,u20090u2009≤u2009_y__i_,u20091u2009≤u2009_y__i_,u20092u2009≤u2009_H_, or _x__i_,u20091u2009=u2009_x__i_,u20092, or _y__i_,u20091u2009=u2009_y__i_,u20092). Breaks are given in arbitrary order. It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts.
2,000
false
false
true
false
false
false
false
false
false
false
9,840
1676D
Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bishop on the board such that the sum of all cells attacked by the bishop is maximal. The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked. Help him find the maximal sum he can get. Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$m$$$ ($$$1 le n le 200$$$, $$$1 leq m leq 200$$$). The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element of the $$$i$$$-th line $$$a_{ij}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row $$$(0leq a_{ij} leq 10^6)$$$ It is guaranteed that the sum of $$$ncdot m$$$ over all test cases does not exceed $$$4cdot10^4$$$. Output For each test case output a single integer, the maximum sum over all possible placements of the bishop. Example Input 4 4 4 1 2 2 1 2 4 2 4 2 2 3 1 2 4 2 4 2 1 1 0 3 3 1 1 1 1 1 1 1 1 1 3 3 0 1 1 1 0 1 1 1 0 Note For the first test case here the best sum is achieved by the bishop being in this position:
1,000
false
true
true
false
false
false
true
false
false
false
2,212
2022B
Karel is a salesman in a car dealership. The dealership has $$$n$$$ different models of cars. There are $$$a_i$$$ cars of the $$$i$$$-th model. Karel is an excellent salesperson and can convince customers to buy up to $$$x$$$ cars (of Karel's choice), as long as the cars are from different models. Determine the minimum number of customers Karel has to bring in to sell all the cars. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 le t le 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 le n le 5 cdot 10^5$$$; $$$1 le x le 10$$$)xa0— the number of different models of cars and the maximum number of cars Karel can convince a customer to buy. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^9$$$)xa0— the number of cars of each model. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 cdot 10^5$$$. Output For each test case, output the minimum possible number of customers needed to sell all the cars. Example Input 4 3 2 3 1 2 3 3 2 1 3 5 3 2 2 1 9 2 7 4 2 5 3 3 5 2 5 Note For the first case, Karel only needs to lure in $$$3$$$ customers. He will convince the customers to buy the following models of cars: Customer $$$1$$$ buys $$$2$$$ cars with model $$$1$$$ and $$$3$$$. Customer $$$2$$$ buys $$$2$$$ cars with model $$$1$$$ and $$$2$$$. Customer $$$3$$$ buys $$$2$$$ cars with model $$$1$$$ and $$$3$$$. For the second case, Karel only needs to lure in $$$3$$$ customers. He will convince the customers to buy the following models of cars: Customer $$$1$$$ buys $$$2$$$ cars with model $$$1$$$ and $$$3$$$. Customer $$$2$$$ buys $$$3$$$ cars with model $$$1$$$, $$$2$$$ and $$$3$$$. Customer $$$3$$$ buys $$$1$$$ car with model $$$3$$$.
1,300
true
true
false
false
false
false
false
true
false
false
137
1054D
At a break Vanya came to the class and saw an array of $$$n$$$ $$$k$$$-bit integers $$$a_1, a_2, ldots, a_n$$$ on the board. An integer $$$x$$$ is called a $$$k$$$-bit integer if $$$0 leq x leq 2^k - 1$$$. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array $$$i$$$ ($$$1 leq i leq n$$$) and replace the number $$$a_i$$$ with the number $$$overline{a_i}$$$. We define $$$overline{x}$$$ for a $$$k$$$-bit integer $$$x$$$ as the $$$k$$$-bit integer such that all its $$$k$$$ bits differ from the corresponding bits of $$$x$$$. Vanya does not like the number $$$0$$$. Therefore, he likes such segments $$$. The next line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 leq a_i leq 2^k - 1$$$), separated by spacesxa0— the array of $$$k$$$-bit integers. Output Print one integerxa0— the maximum possible number of segments with XOR not equal to $$$0$$$ that can be obtained by making several (possibly $$$0$$$) operations described in the statement. Note In the first example if Vasya does not perform any operations, he gets an array that has $$$5$$$ segments that Vanya likes. If he performs the operation with $$$i = 2$$$, he gets an array $$$[1, 0, 0]$$$, because $$$overline{3} = 0$$$ when $$$k = 2$$$. This array has $$$3$$$ segments that Vanya likes. Also, to get an array with $$$5$$$ segments that Vanya likes, he can perform two operations with $$$i = 3$$$ and with $$$i = 2$$$. He then gets an array $$$[1, 0, 3]$$$. It can be proven that he can't obtain $$$6$$$ or more segments that he likes. In the second example, to get $$$19$$$ segments that Vanya likes, he can perform $$$4$$$ operations with $$$i = 3$$$, $$$i = 4$$$, $$$i = 5$$$, $$$i = 6$$$ and get an array $$$[1, 4, 3, 0, 4, 3]$$$.
1,900
false
true
true
false
false
false
false
false
false
false
5,444
1881D
You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. You can perform the following operation on it: 1. Choose a pair of elements $$$a_i$$$ and $$$a_j$$$ ($$$1 le i, j le n$$$ and $$$i eq j$$$); 2. Choose one of the divisors of the integer $$$a_i$$$, i.e., an integer $$$x$$$ such that $$$a_i bmod x = 0$$$; 3. Replace $$$a_i$$$ with $$$frac{a_i}{x}$$$ and $$$a_j$$$ with $$$a_j cdot x$$$. Determine whether it is possible to make all elements in the array the same by applying the operation a certain number of times (possibly zero). For example, let's consider the array $$$a$$$ = [$$$100, 2, 50, 10, 1$$$] with $$$5$$$ elements. Perform two operations on it: 1. Choose $$$a_3 = 50$$$ and $$$a_2 = 2$$$, $$$x = 5$$$. Replace $$$a_3$$$ with $$$frac{a_3}{x} = frac{50}{5} = 10$$$, and $$$a_2$$$ with $$$a_2 cdot x = 2 cdot 5 = 10$$$. The resulting array is $$$a$$$ = [$$$100, 10, 10, 10, 1$$$]; 2. Choose $$$a_1 = 100$$$ and $$$a_5 = 1$$$, $$$x = 10$$$. Replace $$$a_1$$$ with $$$frac{a_1}{x} = frac{100}{10} = 10$$$, and $$$a_5$$$ with $$$a_5 cdot x = 1 cdot 10 = 10$$$. The resulting array is $$$a$$$ = [$$$10, 10, 10, 10, 10$$$]. After performing these operations, all elements in the array $$$a$$$ become equal to $$$10$$$. Input The first line of the input contains a single integer $$$t$$$ ($$$1 le t le 2000$$$)xa0— the number of test cases. Then follows the description of each test case. The first line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^4$$$) — the number of elements in the array $$$a$$$. The second line of each test case contains exactly $$$n$$$ integers $$$a_i$$$ ($$$1 le a_i le 10^6$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$. Output For each test case, output a single line: "YES" if it is possible to make all elements in the array equal by applying the operation a certain (possibly zero) number of times; "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer). Example Input 7 5 100 2 50 10 1 3 1 1 1 4 8 2 4 2 4 30 50 27 20 2 75 40 2 4 4 3 2 3 1 Output YES YES NO YES NO YES NO Note The first test case is explained in the problem statement.
1,300
true
false
false
false
false
false
false
false
false
false
1,001
1903D1
This is the easy version of the problem. The only difference between the two versions is the constraint on $$$n$$$ and $$$q$$$, the memory and time limits. You can make hacks only if all versions of the problem are solved. Theofanis really likes to play with the bits of numbers. He has an array $$$a$$$ of size $$$n$$$ and an integer $$$k$$$. He can make at most $$$k$$$ operations in the array. In each operation, he picks a single element and increases it by $$$1$$$. He found the maximum xa0— the size of the array and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$0 le a_i le 10^6$$$)xa0— the elements of the array. Next $$$q$$$ lines describe the queries. The $$$i$$$-th line contains one integer $$$k_i$$$ ($$$0 le k_i le 10^{18}$$$)xa0— the number of operations that can be done in the $$$i$$$-th query. Output For each query, print one integerxa0— the maximum bitwise AND that array $$$a$$$ can have after at most $$$k_i$$$ operations. Examples Input 3 5 4 0 2 9 8 17 1 3 Input 1 2 10 5 2318381298321 Note In the first test case, in the first query, we add $$$1$$$ in the first and last elements of the array. Thus, the array becomes $$$[2,3,7,6]$$$ with bitwise AND equal to $$$2$$$. In the second test case, in the first query, we add $$$1$$$ in the first element, $$$5$$$ in the second, and $$$3$$$ in the third and now all the elements are equal to $$$5$$$.
1,700
false
true
false
false
false
false
true
true
false
false
894
380D
The cinema theater hall in Sereja's city is _n_ seats lined up in front of one large screen. There are slots for personal possessions to the left and to the right of each seat. Any two adjacent seats have exactly one shared slot. The figure below shows the arrangement of seats and slots for _n_u2009=u20094. Today it's the premiere of a movie called "Dry Hard". The tickets for all the seats have been sold. There is a very strict controller at the entrance to the theater, so all _n_ people will come into the hall one by one. As soon as a person enters a cinema hall, he immediately (momentarily) takes his seat and occupies all empty slots to the left and to the right from him. If there are no empty slots, the man gets really upset and leaves. People are not very constant, so it's hard to predict the order in which the viewers will enter the hall. For some seats, Sereja knows the number of the viewer (his number in the entering queue of the viewers) that will come and take this seat. For others, it can be any order. Being a programmer and a mathematician, Sereja wonders: how many ways are there for the people to enter the hall, such that nobody gets upset? As the number can be quite large, print it modulo 1000000007 (109u2009+u20097). Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u2009105). The second line contains _n_ integers, the _i_-th integer shows either the index of the person (index in the entering queue) with the ticket for the _i_-th seat or a 0, if his index is not known. It is guaranteed that all positive numbers in the second line are distinct. You can assume that the index of the person who enters the cinema hall is a unique integer from 1 to _n_. The person who has index 1 comes first to the hall, the person who has index 2 comes second and so on. Output In a single line print the remainder after dividing the answer by number 1000000007 (109u2009+u20097). Examples Input 11 0 0 0 0 0 0 0 0 0 0 0
2,500
true
false
false
false
false
false
false
false
false
false
8,307
1776B
Vittorio is playing with his new LEGO Duplo bricks. All the bricks have the shape of a square cuboid with a $$$2 imes 2$$$ square base and a height of $$$1$$$. They can be arranged in the 3D space to build structures, provided that the following rules are met: 1. No two bricks can intersect, but they can touch on their faces. 2. The corners of every brick must have integer coordinates (so bricks are axis-aligned) and the $$$z$$$ coordinates of all corners must be non-negative. 3. The square bases of every brick must be parallel to the ground (i.e. the plane $$$z=0$$$). 4. The lower base of any brick that is not touching the ground must touch the upper base of some other brick in a region of positive area (when this happens, the two bricks stay attached to each other thanks to small studs). For example, this is a valid structure: Vittorio wants to build a structure that includes purple bricks in the following $$$n$$$ positions: $$$(x_1, 0, h)$$$, $$$(x_2, 0, h)$$$, $$$dots$$$, $$$(x_n, 0, h)$$$ — these are the coordinates of the centers of their lower bases; note that all of these bricks have $$$y$$$ coordinate equal to $$$0$$$ and $$$z$$$ coordinate equal to $$$h$$$. Vittorio will use additional bricks of other colors to support the purple bricks. He is willing to place bricks only in positions where the center of the lower base has $$$y$$$ coordinate equal to $$$0$$$. What is the minimum number of additional bricks needed? It can be shown that a valid construction always exists. Input The first line contains two integers $$$n$$$ and $$$h$$$ ($$$1 le n le 300$$$, $$$0 le h le 10^9$$$) — the number of purple bricks and their common $$$z$$$ coordinate. The second line contains $$$n$$$ integers $$$x_1, , x_2, , dots, , x_n$$$ ($$$1 le x_i le 10^9$$$, $$$x_i + 1 < x_{i+1}$$$) — the $$$x$$$ coordinates of the purple bricks (centers of the bases), given in increasing order. Output Print the minimum number of additional bricks needed. Note In the first sample, all the purple bricks lie on the ground, so no additional bricks are needed. In the second sample, Vittorio will have to place supporting bricks under the purple bricks, and he can use a single brick to support both the third and the fourth purple bricks. For example, he can place additional bricks at positions $$$(3, 0, 0)$$$, $$$(7, 0, 0)$$$ and $$$(12, 0, 0)$$$. It can be shown that it is impossible to build a valid construction using less than $$$3$$$ additional bricks. In the fourth sample, a possible structure that minimizes the number of additional bricks is shown in the problem description.
2,200
false
false
false
true
false
false
false
false
false
false
1,627
1832F
Polycarp plays a computer game in a post-apocalyptic setting. The zombies have taken over the world, and Polycarp with a small team of survivors is defending against hordes trying to invade their base. The zombies are invading for $$$x$$$ minutes starting from minute $$$0$$$. There are $$$n$$$ entrances to the base, and every minute one zombie attempts to enter through every entrance. The survivors can defend the entrances against the zombies. There are two options: manuallyxa0— shoot the zombies coming through a certain entrance; automaticallyxa0— set up an electric fence on a certain entrance to fry the zombies. If an entrance is defended either or both ways during some minute, no zombie goes through. Every entrance is defended by a single dedicated survivor. The $$$i$$$-th entrance is defended manually from minute $$$l_i$$$ until minute $$$r_i$$$, non-inclusivexa0— $$$[l_i, r_i)$$$. There are $$$k$$$ generators that can be used to defend the entrances automatically. Every entrance should be connected to exactly one generator, but a generator can be connected to multiple entrances (or even none of them). Each generator will work for exactly $$$m$$$ consecutive minutes. Polycarp can choose when to power on each generator independently of each other, the $$$m$$$ minute long interval should be fully inside the $$$[0, x)$$$ time interval. Polycarp is a weird gamer. He wants the game to be as difficult as possible for him. So he wants to connect each entrance to a generator and choose the time for each generator in such a way that as many zombies as possible enter the base. Please, help him to achieve that! Input The first line contains four integers $$$n, k, x$$$ and $$$m$$$ ($$$1 le k le n le 2000$$$; $$$1 le m le x le 10^9$$$)xa0— the number of entrances, the number of generators, the duration of the zombie invasion and the duration of all generators. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 le l_i < r_i le x$$$)xa0— the time interval the $$$i$$$-th entrance is defended manually.
3,200
false
false
false
true
false
false
false
true
false
false
1,292
1957E
You are given an integer $$$n$$$. The function $$$C(i,k)$$$ represents the number of distinct ways you can select $$$k$$$ distinct numbers from the set {$$$1, 2, ldots, i$$$} and arrange them in a circle$$$^dagger$$$. Find the value of $$$$$$ sumlimits_{i=1}^n sumlimits_{j=1}^i left( C(i,j) bmod j ight). $$$$$$ Here, the operation $$$x bmod y$$$ denotes the remainder from dividing $$$x$$$ by $$$y$$$. Since this value can be very large, find it modulo $$$10^9+7$$$. $$$^dagger$$$ In a circular arrangement, sequences are considered identical if one can be rotated to match the other. For instance, $$$[1, 2, 3]$$$ and $$$[2, 3, 1]$$$ are equivalent in a circle. Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 10^5$$$)xa0— the number of test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 le n le 10^6$$$). Output For each test case, output a single integer on a new linexa0— the value of the expression to be calculated modulo $$$10^9+7$$$. Note In the first test case, $$$C(1,1) bmod 1 = 0$$$. In the second test case: $$$C(1,1)=1$$$ (the arrangements are: $$$[1]$$$); $$$C(2,1)=2$$$ (the arrangements are: $$$[1]$$$, $$$[2]$$$); $$$C(2,2)=1$$$ (the arrangements are: $$$[1, 2]$$$); $$$C(3,1)=3$$$ (the arrangements are: $$$[1]$$$, $$$[2]$$$, $$$[3]$$$); $$$C(3,2)=3$$$ (the arrangements are: $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[3, 1]$$$); $$$C(3,3)=2$$$ (the arrangements are: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$). In total, $$$left(C(1,1) bmod 1 ight) + left(C(2,1) bmod 1 ight) + left(C(2,2) bmod 2 ight) + left(C(3,1) bmod 1 ight) + left(C(3,2) bmod 2 ight) + left(C(3,3) bmod 3 ight) = 4$$$.
2,400
true
false
false
true
false
false
true
false
false
false
529
680B
There are _n_ cities in Bearland, numbered 1 through _n_. Cities are arranged in one long row. The distance between cities _i_ and _j_ is equal to _i_u2009-u2009_j_. Limak is a police officer. He lives in a city _a_. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city _a_. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. Input The first line of the input contains two integers _n_ and _a_ (1u2009≤u2009_a_u2009≤u2009_n_u2009≤u2009100)xa0— the number of cities and the index of city where Limak lives. The second line contains _n_ integers _t_1,u2009_t_2,u2009...,u2009_t__n_ (0u2009≤u2009_t__i_u2009≤u20091). There are _t__i_ criminals in the _i_-th city. Output Print the number of criminals Limak will catch. Note In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: There is one criminal at distance 0 from the third cityxa0— Limak is sure that this criminal is exactly in the third city. There is one criminal at distance 1 from the third cityxa0— Limak doesn't know if a criminal is in the second or fourth city. There are two criminals at distance 2 from the third cityxa0— Limak is sure that there is one criminal in the first city and one in the fifth city. There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
1,000
false
false
true
false
false
true
false
false
false
false
7,104
1481A
You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$. The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = ext{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = ext{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = ext{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = ext{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions. Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? Input The first line contains a single integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 le p_x, p_y le 10^5$$$; $$$(p_x, p_y) eq (0, 0)$$$)xa0— the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 le s le 10^5$$$: $$$s$$$ is the length of string $$$s$$$)xa0— the list of orders. It is guaranteed that the sum of $$$s$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). Example Input 6 10 5 RRRRRRRRRRUUUUU 1 1 UDDDRLLL -3 -5 LDLDLDDDR 1 2 LLLLUU 3 -2 RDULRLLDR -1 6 RUDURUUUUR Output YES YES YES NO YES NO Note In the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces. In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR". In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces.
800
false
true
false
false
false
false
false
false
false
false
3,273
652A
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height _h_1 cm from the ground. On the height _h_2 cm (_h_2u2009>u2009_h_1) on the same tree hung an apple and the caterpillar was crawling to the apple. Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by _a_ cm per hour by day and slips down by _b_ cm per hour by night. In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm. Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple. Input The first line contains two integers _h_1,u2009_h_2 (1u2009≤u2009_h_1u2009<u2009_h_2u2009≤u2009105) — the heights of the position of the caterpillar and the apple in centimeters. The second line contains two integers _a_,u2009_b_ (1u2009≤u2009_a_,u2009_b_u2009≤u2009105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour. Output Print the only integer _k_ — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple. If the caterpillar can't get the apple print the only integer u2009-u20091. Note In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple. Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
1,400
true
false
true
false
false
false
false
false
false
false
7,210
1349D
Slime and his $$$n$$$ friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the $$$i$$$-th player has $$$a_i$$$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $$$a_1 + a_2 + ldots + a_n$$$ biscuits, and the owner of this biscuit will give it to a random uniform player among $$$n-1$$$ players except himself. The game stops when one person will have all the biscuits. As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time. For convenience, as the answer can be represented as a rational number $$$frac{p}{q}$$$ for coprime $$$p$$$ and $$$q$$$, you need to find the value of $$$(p cdot q^{-1})mod 998,244,353$$$. You can prove that $$$qmod 998,244,353 eq 0$$$. Input The first line contains one integer $$$n (2le nle 100,000)$$$: the number of people playing the game. The second line contains $$$n$$$ non-negative integers $$$a_1,a_2,dots,a_n (1le a_1+a_2+dots+a_nle 300,000)$$$, where $$$a_i$$$ represents the number of biscuits the $$$i$$$-th person own at the beginning. Output Print one integer: the expected value of the time that the game will last, modulo $$$998,244,353$$$. Note For the first example, in the first second, the probability that player $$$1$$$ will give the player $$$2$$$ a biscuit is $$$frac{1}{2}$$$, and the probability that player $$$2$$$ will give the player $$$1$$$ a biscuit is $$$frac{1}{2}$$$. But anyway, the game will stop after exactly $$$1$$$ second because only one player will occupy all biscuits after $$$1$$$ second, so the answer is $$$1$$$.
3,200
true
false
false
false
false
false
false
false
false
false
3,961
1093D
You are given an undirected unweighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges. You have to write a number on each vertex of the graph. Each number should be $$$1$$$, $$$2$$$ or $$$3$$$. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd. Calculate the number of possible ways to write numbers $$$1$$$, $$$2$$$ and $$$3$$$ on vertices so the graph becomes beautiful. Since this number may be large, print it modulo $$$998244353$$$. Note that you have to write exactly one number on each vertex. The graph does not have any self-loops or multiple edges. Input The first line contains one integer $$$t$$$ ($$$1 le t le 3 cdot 10^5$$$) — the number of tests in the input. The first line of each test contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 3 cdot 10^5, 0 le m le 3 cdot 10^5$$$) — the number of vertices and the number of edges, respectively. Next $$$m$$$ lines describe edges: $$$i$$$-th line contains two integers $$$u_i$$$, $$$ v_i$$$ ($$$1 le u_i, v_i le n; u_i eq v_i$$$) — indices of vertices connected by $$$i$$$-th edge. It is guaranteed that $$$sumlimits_{i=1}^{t} n le 3 cdot 10^5$$$ and $$$sumlimits_{i=1}^{t} m le 3 cdot 10^5$$$. Output For each test print one line, containing one integer — the number of possible ways to write numbers $$$1$$$, $$$2$$$, $$$3$$$ on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo $$$998244353$$$. Example Input 2 2 1 1 2 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Note Possible ways to distribute numbers in the first test: 1. the vertex $$$1$$$ should contain $$$1$$$, and $$$2$$$ should contain $$$2$$$; 2. the vertex $$$1$$$ should contain $$$3$$$, and $$$2$$$ should contain $$$2$$$; 3. the vertex $$$1$$$ should contain $$$2$$$, and $$$2$$$ should contain $$$1$$$; 4. the vertex $$$1$$$ should contain $$$2$$$, and $$$2$$$ should contain $$$3$$$. In the second test there is no way to distribute numbers.
1,700
false
false
false
false
false
false
false
false
false
true
5,241
1113A
Sasha is a very happy guy, that's why he is always on the move. There are $$$n$$$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $$$1$$$ to $$$n$$$ in increasing order. The distance between any two adjacent cities is equal to $$$1$$$ kilometer. Since all roads in the country are directed, it's possible to reach the city $$$y$$$ from the city $$$x$$$ only if $$$x < y$$$. Once Sasha decided to go on a trip around the country and to visit all $$$n$$$ cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is $$$v$$$ liters, and it spends exactly $$$1$$$ liter of fuel for $$$1$$$ kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number $$$1$$$ and wants to get to the city with the number $$$n$$$. There is a gas station in each city. In the $$$i$$$-th city, the price of $$$1$$$ liter of fuel is $$$i$$$ dollars. It is obvious that at any moment of time, the tank can contain at most $$$v$$$ liters of fuel. Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out! Input The first line contains two integers $$$n$$$ and $$$v$$$ ($$$2 le n le 100$$$, $$$1 le v le 100$$$) xa0— the number of cities in the country and the capacity of the tank. Output Print one integerxa0— the minimum amount of money that is needed to finish the trip. Note In the first example, Sasha can buy $$$2$$$ liters for $$$2$$$ dollars ($$$1$$$ dollar per liter) in the first city, drive to the second city, spend $$$1$$$ liter of fuel on it, then buy $$$1$$$ liter for $$$2$$$ dollars in the second city and then drive to the $$$4$$$-th city. Therefore, the answer is $$$1+1+2=4$$$. In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities.
900
true
true
false
true
false
false
false
false
false
false
5,136
1216C
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $$$(0, 0)$$$, and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates $$$(x_1, y_1)$$$, and the top right — $$$(x_2, y_2)$$$. After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are $$$(x_3, y_3)$$$, and the top right — $$$(x_4, y_4)$$$. Coordinates of the bottom left corner of the second black sheet are $$$(x_5, y_5)$$$, and the top right — $$$(x_6, y_6)$$$. Example of three rectangles. Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets. Input The first line of the input contains four integers $$$x_1, y_1, x_2, y_2$$$ $$$(0 le x_1 < x_2 le 10^{6}, 0 le y_1 < y_2 le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the white sheet. The second line of the input contains four integers $$$x_3, y_3, x_4, y_4$$$ $$$(0 le x_3 < x_4 le 10^{6}, 0 le y_3 < y_4 le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the first black sheet. The third line of the input contains four integers $$$x_5, y_5, x_6, y_6$$$ $$$(0 le x_5 < x_6 le 10^{6}, 0 le y_5 < y_6 le 10^{6})$$$ — coordinates of the bottom left and the top right corners of the second black sheet. The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes. Output If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO". Examples Input 2 2 4 4 1 1 3 5 3 1 5 5 Input 3 3 7 5 0 0 4 6 0 0 7 4 Input 5 2 10 5 3 1 7 6 8 1 11 7 Input 0 0 1000000 1000000 0 0 499999 1000000 500000 0 1000000 1000000 Note In the first example the white sheet is fully covered by black sheets. In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point $$$(6.5, 4.5)$$$ lies not strictly inside the white sheet and lies strictly outside of both black sheets.
1,700
true
false
false
false
false
false
false
false
false
false
4,595
27A
Problem - 27A - 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 *1200 No tag edit access → Contest materials ") — the amount of previously added tests. The second line contains _n_ distinct integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (1u2009≤u2009_a__i_u2009≤u20093000) — indexes of these tests. Output Output the required default value for the next test index. Examples Input 3 1 7 2 Output 3
1,200
false
false
true
false
false
false
false
false
true
false
9,863
1237E
Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree. The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $$$0$$$. Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices. Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $$$v$$$: If $$$v$$$ has a left subtree whose root is $$$u$$$, then the parity of the key of $$$v$$$ is different from the parity of the key of $$$u$$$. If $$$v$$$ has a right subtree whose root is $$$w$$$, then the parity of the key of $$$v$$$ is the same as the parity of the key of $$$w$$$. You are given a single integer $$$n$$$. Find the number of perfectly balanced striped binary search trees with $$$n$$$ vertices that have distinct integer keys between $$$1$$$ and $$$n$$$, inclusive. Output this number modulo $$$998,244,353$$$. Input The only line contains a single integer $$$n$$$ ($$$1 le n le 10^6$$$), denoting the required number of vertices. Output Output the number of perfectly balanced striped binary search trees with $$$n$$$ vertices and distinct integer keys between $$$1$$$ and $$$n$$$, inclusive, modulo $$$998,244,353$$$. Note In the first example, this is the only tree that satisfies the conditions: In the second example, here are various trees that don't satisfy some condition:
2,400
true
false
false
true
false
false
false
false
false
false
4,507
988C
You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$. You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i e j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$). Note that it's required to remove exactly one element in each of the two chosen sequences. Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$. Input The first line contains an integer $$$k$$$ ($$$2 le k le 2 cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 le n_i < 2 cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 cdot 10^5$$$, i.e. $$$n_1 + n_2 + dots + n_k le 2 cdot 10^5$$$. Output If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 le i le k, 1 le x le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 le j le k, 1 le y le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i e j$$$. You can print them in any order. If there are multiple possible answers, print any of them. Examples Input 2 5 2 3 1 3 2 6 1 1 2 2 2 1 Input 4 6 2 2 2 2 2 2 5 2 2 2 2 2 3 2 2 2 5 2 2 2 2 2 Note In the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.
1,400
false
false
true
false
false
false
false
false
true
false
5,761
1511B
You are given three integers $$$a$$$, $$$b$$$ and $$$c$$$. Find two positive integers $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that: the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits; the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$$ digits; the decimal representation of $$$gcd(x, y)$$$ without leading zeroes consists of $$$c$$$ digits. $$$gcd(x, y)$$$ denotes the xa0— the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 le a, b le 9$$$, $$$1 le c le min(a, b)$$$)xa0— the required lengths of the numbers. It can be shown that the answer exists for all testcases under the given constraints. Additional constraint on the input: all testcases are different. Output For each testcase print two positive integersxa0— $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits; the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$$ digits; the decimal representation of $$$gcd(x, y)$$$ without leading zeroes consists of $$$c$$$ digits. Example Input 4 2 3 1 2 2 2 6 6 2 1 1 1 Output 11 492 13 26 140133 160776 1 1 Note In the example: 1. $$$gcd(11, 492) = 1$$$ 2. $$$gcd(13, 26) = 13$$$ 3. $$$gcd(140133, 160776) = 21$$$ 4. $$$gcd(1, 1) = 1$$$
1,100
true
false
false
false
false
true
false
false
false
false
3,115
662E
Consider a regular Codeforces round consisting of three problems that uses dynamic scoring. You are given an almost final scoreboard. For each participant (including yourself), the time of the accepted submission for each of the problems is given. Also, for each solution you already know whether you are able to hack it or not. The only changes in the scoreboard that will happen before the end of the round are your challenges. What is the best place you may take at the end? More formally, _n_ people are participating (including yourself). For any problem, if it was solved by exactly _k_ people at the end of the round, the maximum score for this problem is defined as: 1. If _n_u2009<u20092_k_u2009≤u20092_n_, then the maximum possible score is 500; 2. If _n_u2009<u20094_k_u2009≤u20092_n_, then the maximum possible score is 1000; 3. If _n_u2009<u20098_k_u2009≤u20092_n_, then the maximum possible score is 1500; 4. If _n_u2009<u200916_k_u2009≤u20092_n_, then the maximum possible score is 2000; 5. If _n_u2009<u200932_k_u2009≤u20092_n_, then the maximum possible score is 2500; 6. If 32_k_u2009≤u2009_n_, then the maximum possible score is 3000. Let the maximum possible score for some problem be equal to _s_. Then a contestant who didn't manage to get it accepted (or his solution was hacked) earns 0 points for this problem. If he got the the solution accepted _t_ minutes after the beginning of the round (and his solution wasn't hacked), he earns points for this problem. The overall score of a participant is equal to the sum of points he earns for each problem plus 100 points for each successful hack (only you make hacks). The resulting place you get is equal to one plus the number of participants who's overall score is strictly greater than yours. Input The first line of the input contains a single integer _n_ (1u2009≤u2009_n_u2009≤u20095000)xa0— the number of participants. You are the participant number 1. Each of the following _n_ lines contains three integers _a__i_, _b__i_ and _c__i_. Here _a__i_u2009=u20090 means that the participant number _i_ didn't manage to accept first problem. If 1u2009≤u2009_a__i_u2009≤u2009120, then the participant number _i_ got the first problem accepted _a__i_ minutes after the start of the contest and you cannot hack this solution. Finally, u2009-u2009120u2009≤u2009_a__i_u2009≤u2009u2009-u20091 means that the participant number _i_ got the first problem accepted u2009-u2009_a__i_ minutes after the start of the contest and you can hack this solution. Similarly, _b__i_ and _c__i_ provide the information regarding second and third problems in the same format. It's guaranteed that integers _a_1, _b_1 and _c_1 are non-negative. Output Print the only integerxa0— the best place you can take at the end of the round. Examples Input 4 120 120 1 61 61 120 -61 61 120 0 0 0 Input 4 0 0 119 -3 -17 -42 0 7 0 51 0 0 Note Consider the first sample. If you do not hack any solutions, you will win the contest (scoreboard to the left). However, if you hack the solution of the first problem of the third participant (the only one you can hack), the maximum score for the first problem will change and you will finish second (scoreboard to the right).
3,100
false
true
false
true
false
false
true
false
false
false
7,164
1729F
Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$. A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of indexes ($$$l, r$$$), where $$$1 le l le r le n$$$, corresponds to a substring of the string $$$s$$$. We will define as $$$v(l,r)$$$ the numeric value of the corresponding substring (leading zeros are allowed in it). For example, if $$$n=7$$$, $$$s=$$$"1003004", then $$$v(1,3)=100$$$, $$$v(2,3)=0$$$ and $$$v(2,7)=3004$$$. You are given $$$n$$$, $$$s$$$ and an integer $$$w$$$ ($$$1 le w < n$$$). You need to process $$$m$$$ queries, each of which is characterized by $$$3$$$ numbers $$$l_i, r_i, k_i$$$ ($$$1 le l_i le r_i le n; 0 le k_i le 8$$$). The answer to the $$$i$$$th query is such a pair of substrings of length $$$w$$$ that if we denote them as $$$(L_1, L_1+w-1)$$$ and $$$(L_2, L_2+w-1)$$$, then: $$$L_1 e L_2$$$, that is, the substrings are different; the remainder of dividing a number $$$v(L_1, L_1+w-1) cdot v(l_i, r_i) + v(L_2, L_2 + w - 1)$$$ by $$$9$$$ is equal to $$$k_i$$$. If there are many matching substring pairs, then find a pair where $$$L_1$$$ is as small as possible. If there are many matching pairs in this case, then minimize $$$L_2$$$. Note that the answer may not exist. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— number of input test cases. The first line of each test case contains a string $$$s$$$, which contains only the characters 0-9 and has a length $$$n$$$ ($$$2 le n le 2 cdot 10^5$$$). The second line contains two integers $$$w, m$$$ ($$$1 le w < n, 1 le m le 2 cdot 10^5$$$), where $$$n$$$ — is the length of the given string $$$s$$$. The number $$$w$$$ denotes the lengths of the substrings being searched for, and $$$m$$$ is the number of queries to be processed. The following $$$m$$$ lines contain integers $$$l_i, r_i, k_i$$$ ($$$1 le l_i le r_i le n$$$, $$$0 le k_i le 8$$$)xa0— $$$i$$$th query parameters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. It is also guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each request, print in a separate line: left borders of the required substrings: $$$L_1$$$ and $$$L_2$$$; -1 -1 otherwise, if there is no solution. If there are several solutions, minimize $$$L_1$$$ first, and minimize $$$L_2$$$ second. Example Input 5 1003004 4 1 1 2 1 179572007 4 2 2 7 3 2 7 4 111 2 1 2 2 6 0000 1 2 1 4 0 1 4 1 484 1 5 2 2 0 2 3 7 1 2 5 3 3 8 2 2 6 Output 2 4 1 5 1 2 -1 -1 1 2 -1 -1 1 3 1 3 -1 -1 -1 -1 -1 -1 Note Consider the first test case of example inputs. In this test case $$$n=7$$$, $$$s=$$$"1003004", $$$w=4$$$ and one query $$$l_1=1$$$, $$$r_1=2$$$, $$$k_1=1$$$. Note that $$$v(1,2)=10$$$. We need to find a pair of substrings of length $$$4$$$ such that $$$v(L_1, L_1+3)cdot10+v(L_2,L_2+3)$$$ has a remainder of $$$k_1=1$$$ when divided by $$$9$$$. The values $$$L_1=2, L_2=4$$$ actually satisfy all the requirements: $$$v(L_1, L_1+w-1)=v(2,5)=30$$$, $$$v(L_2, L_2+w-1)=v(4,7)=3004$$$. Indeed, $$$30cdot10+3004=3304$$$, which has a remainder of $$$1$$$ when divided by $$$9$$$. It can be shown that $$$L_1=2$$$ is the minimum possible value, and $$$L_2=4$$$ is the minimum possible with $$$L_1=2$$$.
1,900
true
false
false
false
false
false
false
false
false
false
1,913
1393B
This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well). Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend's company. Initially, the company storehouse has $$$n$$$ planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack's friend can provide her with information about each operation. For convenience, he will give her information according to the following format: $$$+$$$ $$$x$$$: the storehouse received a plank with length $$$x$$$ $$$-$$$ $$$x$$$: one plank with length $$$x$$$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $$$x$$$). Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help! We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 10^5$$$): the initial amount of planks at the company's storehouse, the second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le 10^5$$$): the lengths of the planks. The third line contains a single integer $$$q$$$ ($$$1 le q le 10^5$$$): the number of events in the company. Each of the next $$$q$$$ lines contains a description of the events in a given format: the type of the event (a symbol $$$+$$$ or $$$-$$$) is given first, then goes the integer $$$x$$$ ($$$1 le x le 10^5$$$). Output After every event in the company, print "YES" if two storages of the required shape can be built from the planks of that company's set, and print "NO" otherwise. You can print each letter in any case (upper or lower). Example Input 6 1 1 1 2 1 1 6 + 2 + 1 - 1 + 2 - 1 + 2 Output NO YES NO NO NO YES Note After the second event Applejack can build a rectangular storage using planks with lengths $$$1$$$, $$$2$$$, $$$1$$$, $$$2$$$ and a square storage using planks with lengths $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$. After the sixth event Applejack can build a rectangular storage using planks with lengths $$$2$$$, $$$2$$$, $$$2$$$, $$$2$$$ and a square storage using planks with lengths $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$.
1,400
false
true
true
false
true
true
false
false
false
false
3,706
437C
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of _n_ parts and _m_ ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part _i_ as _v__i_. The child spend _v__f_1u2009+u2009_v__f_2u2009+u2009...u2009+u2009_v__f__k_ energy for removing part _i_ where _f_1,u2009_f_2,u2009...,u2009_f__k_ are the parts that are directly connected to the _i_-th and haven't been removed. Help the child to find out, what is the minimum total energy he should spend to remove all _n_ parts. Input The first line contains two integers _n_ and _m_ (1u2009≤u2009_n_u2009≤u20091000; 0u2009≤u2009_m_u2009≤u20092000). The second line contains _n_ integers: _v_1,u2009_v_2,u2009...,u2009_v__n_ (0u2009≤u2009_v__i_u2009≤u2009105). Then followed _m_ lines, each line contains two integers _x__i_ and _y__i_, representing a rope from part _x__i_ to part _y__i_ (1u2009≤u2009_x__i_,u2009_y__i_u2009≤u2009_n_;xa0_x__i_u2009≠u2009_y__i_). Consider all the parts are numbered from 1 to _n_. Output Output the minimum total energy the child should spend to remove all _n_ parts of the toy. Examples Input 4 3 10 20 30 40 1 4 1 2 2 3 Input 4 4 100 100 100 100 1 2 2 3 2 4 3 4 Input 7 10 40 10 20 10 20 80 40 1 5 4 7 4 5 5 2 5 7 6 4 1 6 1 3 4 3 1 4 Note One of the optimal sequence of actions in the first sample is: First, remove part 3, cost of the action is 20. Then, remove part 2, cost of the action is 10. Next, remove part 4, cost of the action is 10. At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20u2009+u200910u2009+u200910u2009+u20090u2009=u200940, which is the minimum. In the second sample, the child will spend 400 no matter in what order he will remove the parts.
1,400
false
true
false
false
false
false
false
false
true
true
8,089
1468J
There are $$$n$$$ cities and $$$m$$$ bidirectional roads in Berland. The $$$i$$$-th road connects the cities $$$x_i$$$ and $$$y_i$$$, and has the speed limit $$$s_i$$$. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all $$$m$$$ roads is too costly, so $$$m - (n - 1)$$$ roads will be demolished in such a way that the remaining $$$(n - 1)$$$ roads still allow to get to any city from any other city. Formally, the remaining roads should represent an undirected tree. Secondly, the speed limits on the remaining roads might be changed. The changes will be done sequentially, each change is either increasing the speed limit on some road by $$$1$$$, or decreasing it by $$$1$$$. Since changing the speed limit requires a lot of work, the Ministry wants to minimize the number of changes. The goal of the Ministry is to have a road network of $$$(n - 1)$$$ roads with the maximum speed limit over all roads equal to exactly $$$k$$$. They assigned you the task of calculating the minimum number of speed limit changes they have to perform so the road network meets their requirements. For example, suppose the initial map of Berland looks like that, and $$$k = 7$$$: Then one of the optimal courses of action is to demolish the roads $$$1$$$–$$$4$$$ and $$$3$$$–$$$4$$$, and then decrease the speed limit on the road $$$2$$$–$$$3$$$ by $$$1$$$, so the resulting road network looks like that: Input The first line contains one integer $$$t$$$ ($$$1 le t le 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 le n le 2 cdot 10^5$$$; $$$n - 1 le m le min(2 cdot 10^5, frac{n(n-1)}{2})$$$; $$$1 le k le 10^9$$$) — the number of cities, the number of roads and the required maximum speed limit, respectively. Then $$$m$$$ lines follow. The $$$i$$$-th line contains three integers $$$x_i$$$, $$$y_i$$$ and $$$s_i$$$ ($$$1 le x_i, y_i le n$$$; $$$x_i e y_i$$$; $$$1 le s_i le 10^9$$$) — the cities connected by the $$$i$$$-th road and the speed limit on it, respectively. All roads are bidirectional. The road network in each test case is connected (that is, it is possible to reach any city from any other city by traveling along the road), and each pair of cities is connected by at most one road. The sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Similarly, the sum of $$$m$$$ over all test cases does not exceed $$$2 cdot 10^5$$$. Output For each test case, print one integer — the minimum number of changes the Ministry has to perform so that the maximum speed limit among the remaining $$$(n - 1)$$$ roads is exactly $$$k$$$. Example Input 4 4 5 7 4 1 3 1 2 5 2 3 8 2 4 1 3 4 4 4 6 5 1 2 1 1 3 1 1 4 2 2 4 1 4 3 1 3 2 1 3 2 10 1 2 8 1 3 10 5 5 15 1 2 17 3 1 15 2 3 10 1 4 14 2 5 8 Note The explanation for the example test: The first test case is described in the problem statement. In the second test case, the road network initially looks like that: The Ministry can demolish the roads $$$1$$$–$$$2$$$, $$$3$$$–$$$2$$$ and $$$3$$$–$$$4$$$, and then increase the speed limit on the road $$$1$$$–$$$4$$$ three times. In the third test case, the road network already meets all the requirements. In the fourth test case, it is enough to demolish the road $$$1$$$–$$$2$$$ so the resulting road network meets the requirements.
1,800
false
true
false
false
false
false
false
false
false
true
3,343
1809G
Consider a tournament with $$$n$$$ participants. The rating of the $$$i$$$-th participant is $$$a_i$$$. The tournament will be organized as follows. First of all, organizers will assign each participant an index from $$$1$$$ to $$$n$$$. All indices will be unique. Let $$$p_i$$$ be the participant who gets the index $$$i$$$. Then, $$$n-1$$$ games will be held. In the first game, participants $$$p_1$$$ and $$$p_2$$$ will play. In the second game, the winner of the first game will play against $$$p_3$$$. In the third game, the winner of the second game will play against $$$p_4$$$, and so on — in the last game, the winner of the $$$(n-2)$$$-th game will play against $$$p_n$$$. Monocarp wants to predict the results of all $$$n-1$$$ games (of course, he will do the prediction only after the indices of the participants are assigned). He knows for sure that, when two participants with ratings $$$x$$$ and $$$y$$$ play, and $$$x - y > k$$$, the participant with the higher rating wins. But if $$$x - y le k$$$, any of the two participants may win. Among all $$$n!$$$ ways to assign the indices to participants, calculate the number of ways to do this so that Monocarp can predict the results of all $$$n-1$$$ games. Since the answer can be large, print it modulo $$$998244353$$$. Input The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 le n le 10^6$$$; $$$0 le k le 10^9$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$0 le a_1 le a_2 le dots le a_n le 10^9$$$). Note In the first example, a match with any pair of players can be predicted by Monocarp, so all $$$24$$$ ways to assign indices should be counted. In the second example, suitable ways are $$$[1, 3, 2]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2$$$] and $$$[3, 2, 1]$$$.
2,800
true
false
false
true
false
false
false
false
false
false
1,414
1209E2
This is a harder version of the problem. The difference is only in constraints. You are given a rectangular $$$n imes m$$$ matrix $$$a$$$. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times. After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for $$$i$$$-th row it is equal $$$r_i$$$. What is the maximal possible value of $$$r_1+r_2+ldots+r_n$$$? Input The first line contains an integer $$$t$$$ ($$$1 le t le 40$$$), the number of test cases in the input. The first line of each test case contains integers $$$n$$$ and $$$m$$$ ($$$1 le n le 12$$$, $$$1 le m le 2000$$$) — the number of rows and the number of columns in the given matrix $$$a$$$. Each of the following $$$n$$$ lines contains $$$m$$$ integers, the elements of $$$a$$$ ($$$1 le a_{i, j} le 10^5$$$). Output Print $$$t$$$ integers: answers for all test cases in the order they are given in the input. Example Input 3 2 3 2 5 7 4 2 4 3 6 4 1 5 2 10 4 8 6 6 4 9 10 5 4 9 5 8 7 3 3 9 9 9 1 1 1 1 1 1 Note In the first test case you can shift the third column down by one, this way there will be $$$r_1 = 5$$$ and $$$r_2 = 7$$$. In the second case you can don't rotate anything at all, this way there will be $$$r_1 = r_2 = 10$$$ and $$$r_3 = 9$$$.
2,500
false
true
false
true
false
false
false
false
true
false
4,641
414A
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of _n_ distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers _x_ and _y_ from the board, he gets _gcd_(_x_,u2009_y_) points. At the beginning of the game Bimokh has zero points. Mashmokh wants to win in the game. For this reason he wants his boss to get exactly _k_ points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find _n_ distinct integers _a_1,u2009_a_2,u2009...,u2009_a__n_ such that his boss will score exactly _k_ points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109. Input The first line of input contains two space-separated integers _n_,u2009_k_xa0(1u2009≤u2009_n_u2009≤u2009105;xa00u2009≤u2009_k_u2009≤u2009108). Output If such sequence doesn't exist output -1 otherwise output _n_ distinct space-separated integers _a_1,u2009_a_2,u2009...,u2009_a__n_xa0(1u2009≤u2009_a__i_u2009≤u2009109). Note _gcd_(_x_,u2009_y_) is greatest common divisor of _x_ and _y_.
1,500
false
false
false
false
false
true
false
false
false
false
8,169
100H
Do you know the game Battleship? If no, look into Wikipedia article You are given the positions of ships on a 10u2009×u200910 board for playing Battleship. According to the rules, the board should contain the following ships: one of size 4 (4u2009×u20091 or 1u2009×u20094 rectangle), two of size 3 (3u2009×u20091 or 1u2009×u20093 rectangles), three of size 2 (2u2009×u20091 or 1u2009×u20092 rectangles), four of size 1 (1u2009×u20091 rectangles). The ships should not 'bend', touch each other or overlap in any way. Each ship can be oriented horizontaly or verticaly. Your task is to check whether the given set of boards meets the given conditions. Input The first line contains number _n_ (1u2009≤u2009_n_u2009≤u200910) — the number of boards. Each board is described by 10 lines containing 10 characters each. The symbol "0" stands for an empty square and the symbol "*" stands for a square occupied by a ship. The descriptions of boards are separated with empty lines. Output Print _n_ lines YES or NO. Print the first word if the board meets the given conditions; otherwise print the second word. Examples Input 2 ****000000 0000000000 ***00***00 0000000000 00000000* 000**00000 00000000* 000*000000 00000*00*0 0*00000000****000000 0000000000 ***00***00 0000000000 00000000* 000**00000 00000000* 0000*00000 00000*00*0 0*00000000
2,100
false
false
true
false
false
false
false
false
false
false
9,482
920F
Problem - 920F - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags brute force data structures dsu number theory *2000 No tag edit access → Contest materials be the number of positive divisors of a positive integer _x_. For example, _D_(2)u2009=u20092 (2 is divisible by 1 and 2), _D_(6)u2009=u20094 (6 is divisible by 1, 2, 3 and 6). You are given an array _a_ of _n_ integers. You have to process two types of queries: 1. REPLACE _l_ _r_ — for every replace _a__i_ with _D_(_a__i_); 2. SUM _l_ _r_ — calculate . Print the answer for each SUM query. Input The first line contains two integers _n_ and _m_ (1u2009≤u2009_n_,u2009_m_u2009≤u20093·105) — the number of elements in the array and the number of queries to process, respectively. The second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (1u2009≤u2009_a__i_u2009≤u2009106) — the elements of the array. Then _m_ lines follow, each containing 3 integers _t__i_, _l__i_, _r__i_ denoting _i_-th query. If _t__i_u2009=u20091, then _i_-th query is REPLACE _l__i_ _r__i_, otherwise it's SUM _l__i_ _r__i_ (1u2009≤u2009_t__i_u2009≤u20092, 1u2009≤u2009_l__i_u2009≤u2009_r__i_u2009≤u2009_n_). There is at least one SUM query. Output For each SUM query print the answer to it. Example Input 7 6 6 4 1 10 3 2 4 2 1 7 2 4 5 1 3 5 2 4 4 1 5 7 2 1 7 Output 30 13 4 22
2,000
false
false
false
false
true
false
true
false
false
false
6,045
768G
Given a rooted tree with _n_ nodes. The Night King removes exactly one node from the tree and all the edges associated with it. Doing this splits the tree and forms a forest. The node which is removed is not a part of the forest. The root of a tree in the forest is the node in that tree which does not have a parent. We define the strength of the forest as the size of largest tree in forest. Jon Snow wants to minimize the strength of the forest. To do this he can perform the following operation at most once. He removes the edge between a node and its parent and inserts a new edge between this node and any other node in forest such that the total number of trees in forest remain same. For each node _v_ you need to find the minimum value of strength of the forest formed when node _v_ is removed. Input The first line of the input contains an integer _n_ (1u2009u2009≤u2009u2009_n_u2009u2009≤u2009u2009105) — the number of vertices in the tree. Each of the next _n_ lines contains a pair of vertex indices _u__i_ and _v__i_ (1u2009u2009≤u2009u2009_u__i_,u2009u2009_v__i_u2009u2009≤u2009u2009_n_) where _u__i_ is the parent of _v__i_. If _u__i_u2009=u20090 then _v__i_ is the root. Output Print _n_ line each containing a single integer. The _i_-th of them should be equal to minimum value of strength of forest formed when _i_-th node is removed and Jon Snow performs the operation described above at most once. Examples Input 10 0 1 1 2 1 3 1 4 2 5 2 6 3 7 4 8 4 9 5 10 Note The tree for first test case is depicted below. When you remove the first node, the tree splits to form the following forest. The strength of this forest is 4. Jon Snow now changes the parent of vertex 10 from 5 to 3. The strength of forest now becomes 3.
3,300
false
false
false
false
true
false
false
true
false
false
6,707
1774H
Ecrade bought a deck of cards numbered from $$$1$$$ to $$$n$$$. Let the value of a permutation $$$a$$$ of length $$$n$$$ be $$$minlimits_{i = 1}^{n - k + 1} sumlimits_{j = i}^{i + k - 1}a_j$$$. Ecrade wants to find the most valuable one among all permutations of the cards. However, it seems a little difficult, so please help him! Input The first line contains a single integer $$$t$$$ ($$$1 leq t leq 2 cdot 10^4$$$) xa0— the number of test cases. The description of test cases follows. The only line of each test case contains two integers $$$n,k$$$ ($$$4 leq k < n leq 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 cdot 10^6$$$. Output For each test case, output the largest possible value in the first line. Then in the second line, print $$$n$$$ integers $$$a_1,a_2,dots,a_n$$$ ($$$1 le a_i le n$$$, all $$$a_i$$$ are distinct) xa0— the elements of the permutation that has the largest value. If there are multiple such permutations, output any of them. Example Output 13 1 4 5 3 2 18 4 2 5 7 8 3 1 6 Note In the first test case, $$$[1,4,5,3,2]$$$ has a value of $$$13$$$. It can be shown that no permutations of length $$$5$$$ have a value greater than $$$13$$$ when $$$k = 4$$$. In the second test case, $$$[4,2,5,7,8,3,1,6]$$$ has a value of $$$18$$$. It can be shown that no permutations of length $$$8$$$ have a value greater than $$$18$$$ when $$$k = 4$$$.
3,500
false
false
false
false
false
true
false
false
false
false
1,636
1557A
Ezzat has an array of $$$n$$$ integers (maybe negative). He wants to split it into two non-empty subsequences $$$a$$$ and $$$b$$$, such that every element from the array belongs to exactly one subsequence, and the value of $$$f(a) + f(b)$$$ is the maximum possible value, where $$$f(x)$$$ is the average of the subsequence $$$x$$$. A sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by deletion of several (possibly, zero or all) elements. The average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence. For example, the average of $$$[1,5,6]$$$ is $$$(1+5+6)/3 = 12/3 = 4$$$, so $$$f([1,5,6]) = 4$$$. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^3$$$)— the number of test cases. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$2 le n le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$-10^9 le a_i le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3cdot10^5$$$. Output For each test case, print a single value — the maximum value that Ezzat can achieve. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$frac{a - b}{max{(1, b)}} le 10^{-6}$$$. Example Input 4 3 3 1 2 3 -7 -6 -6 3 2 2 2 4 17 3 5 -3 Output 4.500000000 -12.500000000 4.000000000 18.666666667 Note In the first test case, the array is $$$[3, 1, 2]$$$. These are all the possible ways to split this array: $$$a = [3]$$$, $$$b = [1,2]$$$, so the value of $$$f(a) + f(b) = 3 + 1.5 = 4.5$$$. $$$a = [3,1]$$$, $$$b = [2]$$$, so the value of $$$f(a) + f(b) = 2 + 2 = 4$$$. $$$a = [3,2]$$$, $$$b = [1]$$$, so the value of $$$f(a) + f(b) = 2.5 + 1 = 3.5$$$. Therefore, the maximum possible value $$$4.5$$$. In the second test case, the array is $$$[-7, -6, -6]$$$. These are all the possible ways to split this array: $$$a = [-7]$$$, $$$b = [-6,-6]$$$, so the value of $$$f(a) + f(b) = (-7) + (-6) = -13$$$. $$$a = [-7,-6]$$$, $$$b = [-6]$$$, so the value of $$$f(a) + f(b) = (-6.5) + (-6) = -12.5$$$. Therefore, the maximum possible value $$$-12.5$$$.
800
true
false
false
false
false
false
true
false
true
false
2,847
26B
Problem - 26B - 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 greedy *1400 No tag edit access → Contest materials ") ") )()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained? Input Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. Output Output the maximum possible length of a regular bracket sequence. Examples Input (()))( Output 4 Input ((()()) Output 6
1,400
false
true
false
false
false
false
false
false
false
false
9,867
735A
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length _n_ such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly _k_ cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if _k_u2009=u20091 the grasshopper can jump to a neighboring cell only, and if _k_u2009=u20092 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. Input The first line of the input contains two integers _n_ and _k_ (2u2009≤u2009_n_u2009≤u2009100, 1u2009≤u2009_k_u2009≤u2009_n_u2009-u20091)xa0— the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length _n_ consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. Output If there exists a sequence of jumps (each jump of length _k_), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Note In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is freexa0— he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
800
false
false
true
false
false
false
false
false
false
false
6,852
1837B
Problem - 1837B - 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 greedy *900 No tag edit access → Contest materials — the number of test cases. Each test case consists of two lines: the first line contains one integer $$$n$$$ ($$$1 le n le 100$$$); the second line contains the string $$$s$$$, consisting of $$$n$$$ characters. Each character of $$$s$$$ is either < or >. Output For each test case, print one integer — the minimum cost among all arrays which are compatible with the given string $$$s$$$. Example Input 4 4 <<>> 4 >><< 5 >>>>> 7 <><><>< Output 3 3 6 2 Note In the first test case of the example, the array can be $$$
900
false
true
false
false
false
false
false
false
false
false
1,269
989E
The cool breeze blows gently, the flowing water ripples steadily."Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually." "Everything is transient in a way and perennial in another." Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night skyxa0— the inexhaustible gifts from nature. Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams. There is a set $$$S$$$ of $$$n$$$ points on a coordinate plane. Kanno starts from a point $$$P$$$ that can be chosen on the plane. $$$P$$$ is not added to $$$S$$$ if it doesn't belong to $$$S$$$. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order: 1. Choose a line $$$l$$$ such that it passes through at least two elements in $$$S$$$ and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably. 2. Move to one of the points that belong to $$$S$$$ and lie on $$$l$$$. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to $$$S$$$). There are $$$q$$$ queries each consisting of two integers $$$(t_i, m_i)$$$. For each query, you're to help Kanno maximize the probability of the stopping position being the $$$t_i$$$-th element in $$$S$$$ after $$$m_i$$$ moves with a proper selection of $$$P$$$, and output this maximum probability. Note that according to rule 1, $$$P$$$ should belong to at least one line that passes through at least two points from $$$S$$$. Input The first line contains a positive integer $$$n$$$ ($$$2 leq n leq 200$$$)xa0— the number of points in $$$S$$$. The $$$i$$$-th of the following $$$n$$$ lines contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^4 leq x_i, y_i leq 10^4$$$)xa0— the coordinates of the $$$i$$$-th point in $$$S$$$. The input guarantees that for all $$$1 leq i lt j leq n$$$, $$$(x_i, y_i) eq (x_j, y_j)$$$ holds. The next line contains a positive integer $$$q$$$ ($$$1 leq q leq 200$$$)xa0— the number of queries. Each of the following $$$q$$$ lines contains two space-separated integers $$$t$$$ and $$$m$$$ ($$$1 leq t_i leq n$$$, $$$1 leq m_i leq 10^4$$$)xa0— the index of the target point and the number of moves, respectively. Output Output $$$q$$$ lines each containing a decimal numberxa0— the $$$i$$$-th among them denotes the maximum probability of staying on the $$$t_i$$$-th point after $$$m_i$$$ steps, with a proper choice of starting position $$$P$$$. Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is considered correct if $$$a - b le 10^{-6}$$$. Example Input 5 0 0 1 3 2 2 3 1 4 4 10 1 1 2 1 3 1 4 1 5 1 3 2 3 3 3 4 3 5 3 6 Output 0.50000000000000000000 0.50000000000000000000 0.33333333333333331483 0.50000000000000000000 0.50000000000000000000 0.18518518518518517491 0.15226337448559670862 0.14494741655235482414 0.14332164812274550414 0.14296036624949901017 Note The points in $$$S$$$ and possible candidates for line $$$l$$$ are depicted in the following figure. For the first query, when $$$P = (-1, -3)$$$, $$$l$$$ is uniquely determined to be $$$3x = y$$$, and thus Kanno will move to $$$(0, 0)$$$ with a probability of $$$frac 1 2$$$. For the third query, when $$$P = (2, 2)$$$, $$$l$$$ is chosen equiprobably between $$$x + y = 4$$$ and $$$x = y$$$. Kanno will then move to the other four points with a probability of $$$frac 1 2 cdot frac 1 3 = frac 1 6$$$ each, or stay at $$$(2, 2)$$$ with a probability of $$$frac 1 3$$$.
2,700
false
false
false
true
false
false
false
false
false
false
5,753
1774F2
This is the hard version of the problem. The only difference between the two versions is the constraint on $$$n$$$ and $$$x$$$. You can make hacks only if both versions of the problem are solved. Little09 has been interested in magic for a long time, and it's so lucky that he meets a magician! The magician will perform $$$n$$$ operations, each of them is one of the following three: $$$1 x$$$: Create a pig with $$$x$$$ Health Points. $$$2 x$$$: Reduce the Health Point of all living pigs by $$$x$$$. $$$3$$$: Repeat all previous operations. Formally, assuming that this is the $$$i$$$-th operation in the operation sequence, perform the first $$$i-1$$$ operations (including "Repeat" operations involved) in turn. A pig will die when its Health Point is less than or equal to $$$0$$$. Little09 wants to know how many living pigs there are after all the operations. Please, print the answer modulo $$$998,244,353$$$. Input The first line contains a single integer $$$n$$$ ($$$1leq nleq 8cdot 10^5$$$) xa0— the number of operations. Each of the following $$$n$$$ lines contains an operation given in the form described in the problem statement. It's guaranteed that $$$1leq xleq 10^9$$$ in operations of the first two types. Output Print a single integer xa0— the number of living pigs after all the operations, modulo $$$998,244,353$$$. Examples Input 6 1 5 1 6 2 2 3 1 4 3 Input 12 2 1 1 15 1 9 3 1 12 2 2 1 13 3 2 1 1 9 1 8 3 Note In the first example, the operations are equivalent to repeating four times: create a pig with $$$8$$$ Health Points and then reduce the Health Points of all living pigs by $$$3$$$. It is easy to find that there are two living pigs in the end with $$$2$$$ and $$$5$$$ Health Points.
2,700
false
false
true
false
true
false
true
true
false
false
1,638
538F
Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment. The teacher gave Andrew an array of _n_ numbers _a_1, ..., _a__n_. After that he asked Andrew for each _k_ from 1 to _n_u2009-u20091 to build a _k_-ary heap on the array and count the number of elements for which the property of the minimum-rooted heap is violated, i.e. the value of an element is less than the value of its parent. Andrew looked up on the Wikipedia that a _k_-ary heap is a rooted tree with vertices in elements of the array. If the elements of the array are indexed from 1 to _n_, then the children of element _v_ are elements with indices _k_(_v_u2009-u20091)u2009+u20092, ..., _kv_u2009+u20091 (if some of these elements lie outside the borders of the array, the corresponding children are absent). In any _k_-ary heap every element except for the first one has exactly one parent; for the element 1 the parent is absent (this element is the root of the heap). Denote _p_(_v_) as the number of the parent of the element with the number _v_. Let's say that for a non-root element _v_ the property of the heap is violated if _a__v_u2009<u2009_a__p_(_v_). Help Andrew cope with the task! Input The first line contains a single integer _n_ (2u2009≤u2009_n_u2009≤u20092·105). The second line contains _n_ space-separated integers _a_1, ..., _a__n_ (u2009-u2009109u2009≤u2009_a__i_u2009≤u2009109). Output in a single line print _n_u2009-u20091 integers, separate the consecutive numbers with a single space — the number of elements for which the property of the _k_-ary heap is violated, for _k_u2009=u20091, 2, ..., _n_u2009-u20091. Note Pictures with the heaps for the first sample are given below; elements for which the property of the heap is violated are marked with red. In the second sample all elements are equal, so the property holds for all pairs.
2,200
true
false
false
false
true
false
true
false
true
false
7,683
1585G
Alice and Bob are two poachers who cut trees in a forest. A forest is a set of zero or more trees. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a node $$$v$$$ is the next vertex on the shortest path from $$$v$$$ to the root. Children of vertex $$$v$$$ are all nodes for which $$$v$$$ is the parent. A vertex is a leaf if it has no children. In this problem we define the depth of vertex as number of vertices on the simple path from this vertex to the root. The rank of a tree is the minimum depth among its leaves. Initially there is a forest of rooted trees. Alice and Bob play a game on this forest. They play alternating turns with Alice going first. At the beginning of their turn, the player chooses a tree from the forest. Then the player chooses a positive cutting depth, which should not exceed the rank of the chosen tree. Then the player removes all vertices of that tree whose depth is less that or equal to the cutting depth. All other vertices of the tree form a set of rooted trees with root being the vertex with the smallest depth before the cut. All these trees are included in the game forest and the game continues. A player loses if the forest is empty at the beginning of his move. You are to determine whether Alice wins the game if both players play optimally. Input Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 leq t leq 5 cdot 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 leq n leq 5 cdot 10^5$$$) — total number of vertices in the initial forest. The second line contains $$$n$$$ integers $$$p_1, p_2, ldots, p_n$$$ ($$$0 leq p_i leq n$$$) — description of the forest. If $$$p_i = 0$$$, then the $$$i$$$-th vertex is the root of a tree, otherwise $$$p_i$$$ is the parent of the vertex $$$i$$$. It's guaranteed that $$$p$$$ defines a correct forest of rooted trees. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 cdot 10^5$$$. Output For each test case, print "YES" (without quotes) if Alice wins, otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). Example Input 4 4 0 1 0 3 7 0 1 2 0 4 5 6 4 0 1 1 2 7 0 1 1 2 2 3 3 Note In the first test case Bob has a symmetric strategy, so Alice cannot win. In the second test case Alice can choose the second tree and cutting depth $$$1$$$ to get a forest on which she has a symmetric strategy. In third test case the rank of the only tree is $$$2$$$ and both possible moves for Alice result in a loss. Bob either can make the forest with a symmetric strategy for himself, or clear the forest. In the fourth test case all leafs have the same depth, so Alice can clear the forest in one move.
2,500
false
false
false
true
false
false
false
false
false
true
2,696
1876A
Pak Chanek is the chief of a village named Khuntien. On one night filled with lights, Pak Chanek has a sudden and important announcement that needs to be notified to all of the $$$n$$$ residents in Khuntien. First, Pak Chanek shares the announcement directly to one or more residents with a cost of $$$p$$$ for each person. After that, the residents can share the announcement to other residents using a magical helmet-shaped device. However, there is a cost for using the helmet-shaped device. For each $$$i$$$, if the $$$i$$$-th resident has got the announcement at least once (either directly from Pak Chanek or from another resident), he/she can share the announcement to at most $$$a_i$$$ other residents with a cost of $$$b_i$$$ for each share. If Pak Chanek can also control how the residents share the announcement to other residents, what is the minimum cost for Pak Chanek to notify all $$$n$$$ residents of Khuntien about the announcement? Input Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 leq t leq 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 leq n leq 10^5$$$; $$$1 leq p leq 10^5$$$) — the number of residents and the cost for Pak Chanek to share the announcement directly to one resident. The second line contains $$$n$$$ integers $$$a_1,a_2,a_3,ldots,a_n$$$ ($$$1leq a_ileq10^5$$$) — the maximum number of residents that each resident can share the announcement to. The third line contains $$$n$$$ integers $$$b_1,b_2,b_3,ldots,b_n$$$ ($$$1leq b_ileq10^5$$$) — the cost for each resident to share the announcement to one other resident. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Output For each test case, output a line containing an integer representing the minimum cost to notify all $$$n$$$ residents of Khuntien about the announcement. Example Input 3 6 3 2 3 2 1 1 3 4 3 2 6 3 6 1 100000 100000 1 4 94 1 4 2 3 103 96 86 57 Note In the first test case, the following is a possible optimal strategy: 1. Pak Chanek shares the announcement directly to the $$$3$$$-rd, $$$5$$$-th, and $$$6$$$-th resident. This requires a cost of $$$p+p+p=3+3+3=9$$$. 2. The $$$3$$$-rd resident shares the announcement to the $$$1$$$-st and $$$2$$$-nd resident. This requires a cost of $$$b_3+b_3=2+2=4$$$. 3. The $$$2$$$-nd resident shares the announcement to the $$$4$$$-th resident. This requires a cost of $$$b_2=3$$$. The total cost is $$$9+4+3=16$$$. It can be shown that there is no other strategy with a smaller cost.
1,000
false
true
false
false
false
false
false
false
true
false
1,026
486D
As you know, an undirected connected graph with _n_ nodes and _n_u2009-u20091 edges is called a tree. You are given an integer _d_ and a tree consisting of _n_ nodes. Each node _i_ has a value _a__i_ associated with it. We call a set _S_ of tree nodes valid if following conditions are satisfied: 1. _S_ is non-empty. 2. _S_ is connected. In other words, if nodes _u_ and _v_ are in _S_, then all nodes lying on the simple path between _u_ and _v_ should also be presented in _S_. 3. . Your task is to count the number of valid sets. Since the result can be very large, you must print its remainder modulo 1000000007 (109u2009+u20097). Input The first line contains two space-separated integers _d_ (0u2009≤u2009_d_u2009≤u20092000) and _n_ (1u2009≤u2009_n_u2009≤u20092000). The second line contains _n_ space-separated positive integers _a_1,u2009_a_2,u2009...,u2009_a__n_(1u2009≤u2009_a__i_u2009≤u20092000). Then the next _n_u2009-u20091 line each contain pair of integers _u_ and _v_ (1u2009≤u2009_u_,u2009_v_u2009≤u2009_n_) denoting that there is an edge between _u_ and _v_. It is guaranteed that these edges form a tree. Output Print the number of valid sets modulo 1000000007. Examples Input 4 8 7 8 7 5 4 6 4 10 1 6 1 2 5 8 1 3 3 5 6 7 3 4 Note In the first sample, there are exactly 8 valid sets: {1},u2009{2},u2009{3},u2009{4},u2009{1,u20092},u2009{1,u20093},u2009{3,u20094} and {1,u20093,u20094}. Set {1,u20092,u20093,u20094} is not valid, because the third condition isn't satisfied. Set {1,u20094} satisfies the third condition, but conflicts with the second condition.
2,100
true
false
false
true
false
false
false
false
false
false
7,892
625C
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of _k_-special tables. In case you forget, the table _n_u2009×u2009_n_ is called _k_-special if the following three conditions are satisfied: every integer from 1 to _n_2 appears in the table exactly once; in each row numbers are situated in increasing order; the sum of numbers in the _k_-th column is maximum possible. Your goal is to help Alice and find at least one _k_-special table of size _n_u2009×u2009_n_. Both rows and columns are numbered from 1 to _n_, with rows numbered from top to bottom and columns numbered from left to right. Input The first line of the input contains two integers _n_ and _k_ (1u2009≤u2009_n_u2009≤u2009500,u20091u2009≤u2009_k_u2009≤u2009_n_)xa0— the size of the table Alice is looking for and the column that should have maximum possible sum. Output First print the sum of the integers in the _k_-th column of the required table. Next _n_ lines should contain the description of the table itself: first line should contains _n_ elements of the first row, second line should contain _n_ elements of the second row and so on. If there are multiple suitable table, you are allowed to print any. Examples Output 28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output 85 5 6 17 18 19 9 10 23 24 25 7 8 20 21 22 3 4 14 15 16 1 2 11 12 13
1,300
false
false
true
false
false
true
false
false
false
false
7,331
1093G
You are given an array $$$a$$$ of $$$n$$$ points in $$$k$$$-dimensional space. Let the distance between two points $$$a_x$$$ and $$$a_y$$$ be $$$sum limits_{i = 1}^{k} a_{x, i} - a_{y, i}$$$ (it is also known as Manhattan distance). You have to process $$$q$$$ queries of the following two types: $$$1$$$ $$$i$$$ $$$b_1$$$ $$$b_2$$$ ... $$$b_k$$$ — set $$$i$$$-th element of $$$a$$$ to the point $$$(b_1, b_2, dots, b_k)$$$; $$$2$$$ $$$l$$$ $$$r$$$ — find the maximum distance between two points $$$a_i$$$ and $$$a_j$$$, where $$$l le i, j le r$$$. Input The first line contains two numbers $$$n$$$ and $$$k$$$ ($$$1 le n le 2 cdot 10^5$$$, $$$1 le k le 5$$$) — the number of elements in $$$a$$$ and the number of dimensions of the space, respectively. Then $$$n$$$ lines follow, each containing $$$k$$$ integers $$$a_{i, 1}$$$, $$$a_{i, 2}$$$, ..., $$$a_{i, k}$$$ ($$$-10^6 le a_{i, j} le 10^6$$$) — the coordinates of $$$i$$$-th point. The next line contains one integer $$$q$$$ ($$$1 le q le 2 cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow, each denoting a query. There are two types of queries: $$$1$$$ $$$i$$$ $$$b_1$$$ $$$b_2$$$ ... $$$b_k$$$ ($$$1 le i le n$$$, $$$-10^6 le b_j le 10^6$$$) — set $$$i$$$-th element of $$$a$$$ to the point $$$(b_1, b_2, dots, b_k)$$$; $$$2$$$ $$$l$$$ $$$r$$$ ($$$1 le l le r le n$$$) — find the maximum distance between two points $$$a_i$$$ and $$$a_j$$$, where $$$l le i, j le r$$$. There is at least one query of the second type. Output Print the answer for each query of the second type. Example Input 5 2 1 2 2 3 3 4 4 5 5 6 7 2 1 5 2 1 3 2 3 5 1 5 -1 -2 2 1 5 1 4 -1 -2 2 1 5
2,300
false
false
false
false
true
false
false
false
false
false
5,238
610C
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or u2009-u20091 and any two vectors are orthogonal. Just as a reminder, two vectors in _n_-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is: . Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2_k_ vectors in 2_k_-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it? Input The only line of the input contains a single integer _k_ (0u2009≤u2009_k_u2009≤u20099). Output Print 2_k_ lines consisting of 2_k_ characters each. The _j_-th character of the _i_-th line must be equal to 'u2009*u2009' if the _j_-th coordinate of the _i_-th vector is equal to u2009-u20091, and must be equal to 'u2009+u2009' if it's equal to u2009+u20091. It's guaranteed that the answer always exists. If there are many correct answers, print any. Note Consider all scalar products in example: Vectors 1 and 2: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009+u20091)·(u2009-u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009-u20091)u2009=u20090 Vectors 1 and 3: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009+u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009=u20090 Vectors 1 and 4: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009+u20091)·(u2009-u20091)u2009+u2009(u2009-u20091)·(u2009-u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009=u20090 Vectors 2 and 3: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009+u2009(u2009+u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009=u20090 Vectors 2 and 4: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009-u20091)·(u2009-u20091)u2009+u2009(u2009+u20091)·(u2009-u20091)u2009+u2009(u2009-u20091)·(u2009+u20091)u2009=u20090 Vectors 3 and 4: (u2009+u20091)·(u2009+u20091)u2009+u2009(u2009+u20091)·(u2009-u20091)u2009+u2009(u2009+u20091)·(u2009-u20091)u2009+u2009(u2009+u20091)·(u2009+u20091)u2009=u20090
1,800
false
false
false
false
false
true
false
false
false
false
7,404
264E
Squirrel Liss loves nuts. Liss asks you to plant some nut trees. There are _n_ positions (numbered 1 to _n_ from west to east) to plant a tree along a street. Trees grow one meter per month. At the beginning of each month you should process one query. The query is one of the following types: 1. Plant a tree of height _h_ at position _p_. 2. Cut down the _x_-th existent (not cut) tree from the west (where _x_ is 1-indexed). When we cut the tree it drops down and takes all the available place at the position where it has stood. So no tree can be planted at this position anymore. After processing each query, you should print the length of the longest increasing subsequence. A subset of existent trees is called an increasing subsequence if the height of the trees in the set is strictly increasing from west to east (for example, the westmost tree in the set must be the shortest in the set). The length of the increasing subsequence is the number of trees in it. Note that Liss don't like the trees with the same heights, so it is guaranteed that at any time no two trees have the exactly same heights. Input The first line contains two integers: _n_ and _m_ (1u2009u2009≤u2009_n_u2009≤u2009105;xa01u2009≤u2009_m_u2009≤u20092·105) — the number of positions and the number of queries. Next _m_ lines contains the information of queries by following formats: If the _i_-th query is type 1, the _i_-th line contains three integers: 1, _p__i_, and _h__i_ (1u2009≤u2009_p__i_u2009≤u2009_n_,u20091u2009≤u2009_h__i_u2009≤u200910), where _p__i_ is the position of the new tree and _h__i_ is the initial height of the new tree. If the _i_-th query is type 2, the _i_-th line contains two integers: 2 and _x__i_ (1u2009≤u2009_x__i_u2009≤u200910), where the _x__i_ is the index of the tree we want to cut. The input is guaranteed to be correct, i.e., For type 1 queries, _p__i_ will be pairwise distinct. For type 2 queries, _x__i_ will be less than or equal to the current number of trees. At any time no two trees have the exactly same heights. In each line integers are separated by single spaces. Output Print _m_ integers — the length of the longest increasing subsequence after each query. Separate the numbers by whitespaces. Examples Input 4 6 1 1 1 1 4 4 1 3 4 2 2 1 2 8 2 3 Note States of street after each query you can see on the following animation: If your browser doesn't support animation png, please see the gif version here:
3,000
false
false
false
true
true
false
false
false
false
false
8,774
1207B
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$. You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 imes 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 le x < n$$$ and $$$1 le y < m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$. Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$. Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations. Input The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 le n, m le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$. Output If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ — the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 le k le 2500$$$ should hold. Examples Input 3 3 1 1 1 1 1 1 0 1 1 Input 3 3 1 0 1 1 0 1 0 0 0 Note The sequence of operations in the first example: $$$begin{matrix} 0 & 0 & 0 & & 1 & 1 & 0 & & 1 & 1 & 1 & & 1 & 1 & 1 0 & 0 & 0 & ightarrow & 1 & 1 & 0 & ightarrow & 1 & 1 & 1 & ightarrow & 1 & 1 & 1 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 0 & 0 & & 0 & 1 & 1 end{matrix}$$$
1,200
false
true
true
false
false
true
false
false
false
false
4,660
981D
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $$$k$$$ bookshelves. He decided that the beauty of the $$$k$$$ shelves is the xa0— the number of books and the number of shelves in the new office. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots a_n$$$, ($$$0 < a_i < 2^{50}$$$)xa0— the prices of the books in the order they stand on the old shelf. Output Print the maximum possible beauty of $$$k$$$ shelves in the new office. Examples Input 10 4 9 14 28 1 7 13 15 29 2 31 Input 7 3 3 14 15 92 65 35 89 Note In the first example you can split the books as follows: $$$$$$(9 + 14 + 28 + 1 + 7) & (13 + 15) & (29 + 2) & (31) = 24.$$$$$$ In the second example you can split the books as follows: $$$$$$(3 + 14 + 15 + 92) & (65) & (35 + 89) = 64.$$$$$$
1,900
false
true
false
true
false
false
false
false
false
false
5,797
461C
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1u2009×u2009_n_. Your task is help Appleman with folding of such a sheet. Actually, you need to perform _q_ queries. Each query will have one of the following types: 1. Fold the sheet of paper at position _p__i_. After this query the leftmost part of the paper with dimensions 1u2009×u2009_p__i_ must be above the rightmost part of the paper with dimensions 1u2009×u2009([_current_xa0_width_xa0_of_xa0_sheet_]u2009-u2009_p__i_). 2. Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance _l__i_ from the left border of the current sheet of paper and the other at distance _r__i_ from the left border of the current sheet of paper. Please look at the explanation of the first test example for better understanding of the problem. Input The first line contains two integers: _n_ and _q_ (1u2009u2009≤u2009_n_u2009≤u2009105;xa01u2009≤u2009_q_u2009≤u2009105) — the width of the paper and the number of queries. Each of the following _q_ lines contains one of the described queries in the following format: "1 _p__i_" (1u2009≤u2009_p__i_u2009<u2009[_current_xa0_width_xa0_of_xa0_sheet_]) — the first type query. "2 _l__i_ _r__i_" (0u2009≤u2009_l__i_u2009<u2009_r__i_u2009≤u2009[_current_xa0_width_xa0_of_xa0_sheet_]) — the second type query. Output For each query of the second type, output the answer. Examples Input 10 9 2 2 9 1 1 2 0 1 1 8 2 0 8 1 2 2 1 3 1 4 2 2 4 Note The pictures below show the shapes of the paper during the queries of the first example: After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.
2,200
false
false
true
false
true
false
false
false
false
false
7,994
1118D2
The only difference between easy and hard versions is the constraints. Polycarp has to write a coursework. The coursework consists of $$$m$$$ pages. Polycarp also has $$$n$$$ cups of coffee. The coffee in the $$$i$$$-th cup Polycarp has $$$a_i$$$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days). Surely, courseworks are not being written in a single day (in a perfect world of Berland, at least). Let's consider some day of Polycarp's work. Consider Polycarp drinks $$$k$$$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $$$a_{i_1}, a_{i_2}, dots, a_{i_k}$$$. Then the first cup he drinks gives him energy to write $$$a_{i_1}$$$ pages of coursework, the second cup gives him energy to write $$$max(0, a_{i_2} - 1)$$$ pages, the third cup gives him energy to write $$$max(0, a_{i_3} - 2)$$$ pages, ..., the $$$k$$$-th cup gives him energy to write $$$max(0, a_{i_k} - k + 1)$$$ pages. If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day. Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible. Input The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 le n le 2 cdot 10^5$$$, $$$1 le m le 10^9$$$) — the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 le a_i le 10^9$$$), where $$$a_i$$$ is the caffeine dosage of coffee in the $$$i$$$-th cup. Output If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it. Note In the first example Polycarp can drink fourth cup during first day (and write $$$1$$$ page), first and second cups during second day (and write $$$2 + (3 - 1) = 4$$$ pages), fifth cup during the third day (and write $$$2$$$ pages) and third cup during the fourth day (and write $$$1$$$ page) so the answer is $$$4$$$. It is obvious that there is no way to write the coursework in three or less days. In the second example Polycarp can drink third, fourth and second cups during first day (and write $$$4 + (2 - 1) + (3 - 2) = 6$$$ pages) and sixth cup during second day (and write $$$4$$$ pages) so the answer is $$$2$$$. It is obvious that Polycarp cannot write the whole coursework in one day in this test. In the third example Polycarp can drink all cups of coffee during first day and write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$$$ pages of coursework. In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$$$ pages of coursework and during second day he will write $$$5$$$ pages of coursework. This is enough to complete it. In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
1,700
false
true
false
false
false
false
false
true
false
false
5,098
678B
Problem - 678B - Codeforces =============== xa0 ]( "Educational Codeforces Round 13") — the year of the calendar. Output Print the only integer _y_' — the next year after _y_ when the calendar will be the same. Note that you should find the first year after _y_ with the same calendar. Examples Input 2016 Output 2044 Input 2000 Output 2028 Input 50501 Output 50507 Note Today is Monday, the 13th of June, 2016.
1,600
false
false
true
false
false
false
false
false
false
false
7,115
987B
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids. One of the popular pranks on Vasya is to force him to compare $$$x^y$$$ with $$$y^x$$$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers. Please help Vasya! Write a fast program to compare $$$x^y$$$ with $$$y^x$$$ for Vasya, maybe then other androids will respect him. Input On the only line of input there are two integers $$$x$$$ and $$$y$$$ ($$$1 le x, y le 10^{9}$$$). Output If $$$x^y < y^x$$$, then print '<' (without quotes). If $$$x^y > y^x$$$, then print '>' (without quotes). If $$$x^y = y^x$$$, then print '=' (without quotes). Note In the first example $$$5^8 = 5 cdot 5 cdot 5 cdot 5 cdot 5 cdot 5 cdot 5 cdot 5 = 390625$$$, and $$$8^5 = 8 cdot 8 cdot 8 cdot 8 cdot 8 = 32768$$$. So you should print '>'. In the second example $$$10^3 = 1000 < 3^{10} = 59049$$$. In the third example $$$6^6 = 46656 = 6^6$$$.
1,100
true
false
false
false
false
false
false
false
false
false
5,765
1020A
You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room. The building consists of _n_ towers, _h_ floors each, where the towers are labeled from 1 to _n_, the floors are labeled from 1 to _h_. There is a passage between any two adjacent towers (two towers _i_ and _i_u2009+u20091 for all _i_: 1u2009≤u2009_i_u2009≤u2009_n_u2009-u20091) on every floor _x_, where _a_u2009≤u2009_x_u2009≤u2009_b_. It takes exactly one minute to walk between any two adjacent floors of a tower, as well as between any two adjacent towers, provided that there is a passage on that floor. It is not permitted to leave the building. The picture illustrates the first example. You have given _k_ pairs of locations (_t__a_,u2009_f__a_), (_t__b_,u2009_f__b_): floor _f__a_ of tower _t__a_ and floor _f__b_ of tower _t__b_. For each pair you need to determine the minimum walking time between these locations. Input The first line of the input contains following integers: _n_: the number of towers in the building (1u2009≤u2009_n_u2009≤u2009108), _h_: the number of floors in each tower (1u2009≤u2009_h_u2009≤u2009108), _a_ and _b_: the lowest and highest floor where it's possible to move between adjacent towers (1u2009≤u2009_a_u2009≤u2009_b_u2009≤u2009_h_), _k_: total number of queries (1u2009≤u2009_k_u2009≤u2009104). Next _k_ lines contain description of the queries. Each description consists of four integers _t__a_, _f__a_, _t__b_, _f__b_ (1u2009≤u2009_t__a_,u2009_t__b_u2009≤u2009_n_, 1u2009≤u2009_f__a_,u2009_f__b_u2009≤u2009_h_). This corresponds to a query to find the minimum travel time between _f__a_-th floor of the _t__a_-th tower and _f__b_-th floor of the _t__b_-th tower. Output For each query print a single integer: the minimum walking time between the locations in minutes. Example Input 3 6 2 3 3 1 2 1 3 1 4 3 4 1 2 2 3
1,000
true
false
false
false
false
false
false
false
false
false
5,592
304B
Problem - 304B - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags brute force implementation *1300 No tag edit access → Contest materials . Output Print a single integer — the answer to the problem. Examples Input 1900:01:01 2038:12:31 Output 50768 Input 1996:03:09 1991:11:12 Output 1579
1,300
false
false
true
false
false
false
true
false
false
false
8,617
1669C
Given an array $$$a=[a_1,a_2,dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it: 1. Add $$$1$$$ to every element with an odd index. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, dots$$$. 2. Add $$$1$$$ to every element with an even index. In other words change the array as follows: $$$a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, dots$$$. Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations. Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times. Input The first line contains an integer $$$t$$$ ($$$1 leq t leq 100$$$)xa0— the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 leq n leq 50$$$)xa0— the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ ($$$1 leq a_i leq 10^3$$$)xa0— the elements of the array. Note that after the performed operations the elements in the array can become greater than $$$10^3$$$. Output Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, 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 4 3 1 2 1 4 2 2 2 3 4 2 2 2 2 5 1000 1 1000 1 1000 Note For the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is "YES". For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO". For the third test case, all elements already have the same parity so the answer is "YES". For the fourth test case, we can perform one operation and increase all elements at odd positions by $$$1$$$, thus obtaining the array $$$[1001, 1, 1001, 1, 1001]$$$, and all elements become odd so the answer is "YES".
800
true
true
true
false
false
false
false
false
false
false
2,263
1858A
Anna and Katie ended up in a secret laboratory. There are $$$a+b+c$$$ buttons in the laboratory. It turned out that $$$a$$$ buttons can only be pressed by Anna, $$$b$$$ buttons can only be pressed by Katie, and $$$c$$$ buttons can be pressed by either of them. Anna and Katie decided to play a game, taking turns pressing these buttons. Anna makes the first turn. Each button can be pressed at most once, so at some point, one of the girls will not be able to make her turn. The girl who cannot press a button loses. Determine who will win if both girls play optimally. Input The first line contains a single integer $$$t$$$ ($$$1 le t le 10^4$$$)xa0— the number of test cases. Each test case consists of three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 le a, b, c le 10^9$$$)xa0— the number of buttons that can only be pressed by Anna, the number of buttons that can only be pressed by Katie, and the number of buttons that can be pressed by either of them, respectively. Output For each test case, output First if Anna wins, or Second if Katie wins. Example Input 5 1 1 1 9 3 3 1 2 3 6 6 9 2 2 8 Output First First Second First Second Note For the simplicity of the explanation, we will numerate the buttons by the numbers from $$$1$$$ to $$$a+b+c$$$: the first $$$a$$$ buttons can only be pressed by Anna, the next $$$b$$$ buttons can only be pressed by Katie, and the last $$$c$$$ buttons can be pressed by either of them. In the first test case, Anna can press the $$$3$$$-rd button on the first turn. Then Katie will press the $$$2$$$-nd button (since it is the only possible turn for her). Then Anna will press the $$$1$$$-st button. Katie won't have a button to press, so Anna will win. In the second test case, Anna can press the first nine buttons in some order on her turns. No matter what buttons Katie will press, all the buttons from the $$$10$$$-th to the $$$15$$$-th will be pressed after $$$12$$$ turns. On the $$$13$$$-th turn, Anna will press one of the first nine buttons and Katie will not have a button to press on her turn. Thus, Anna will win. In the third test case, the game can proceed as follows: On the $$$1$$$-st turn Anna presses the $$$5$$$-th button. On the $$$2$$$-st turn Katie presses the $$$4$$$-th button. On the $$$3$$$-st turn Anna presses the $$$6$$$-th button. On the $$$4$$$-st turn Katie presses the $$$3$$$-th button. On the $$$5$$$-st turn Anna presses the $$$1$$$-th button. On the $$$6$$$-st turn Katie presses the $$$2$$$-th button. Anna cannot make the turn, so Katie wins. It can be shown that Katie can win no matter what moves Anna takes.
800
true
true
false
false
false
false
false
false
false
false
1,137
1841B
The array $$$[a_1, a_2, dots, a_k]$$$ is called beautiful if it is possible to remove several (maybe zero) elements from the beginning of the array and insert all these elements to the back of the array in the same order in such a way that the resulting array is sorted in non-descending order. In other words, the array $$$[a_1, a_2, dots, a_k]$$$ is beautiful if there exists an integer $$$i in [0, k-1]$$$ such that the array $$$[a_{i+1}, a_{i+2}, dots, a_{k-1}, a_k, a_1, a_2, dots, a_i]$$$ is sorted in non-descending order. For example: $$$[3, 7, 7, 9, 2, 3]$$$ is beautiful: we can remove four first elements and insert them to the back in the same order, and we get the array $$$[2, 3, 3, 7, 7, 9]$$$, which is sorted in non-descending order; $$$[1, 2, 3, 4, 5]$$$ is beautiful: we can remove zero first elements and insert them to the back, and we get the array $$$[1, 2, 3, 4, 5]$$$, which is sorted in non-descending order; $$$[5, 2, 2, 1]$$$ is not beautiful. Note that any array consisting of zero elements or one element is beautiful. You are given an array $$$a$$$, which is initially empty. You have to process $$$q$$$ queries to it. During the $$$i$$$-th query, you will be given one integer $$$x_i$$$, and you have to do the following: if you can append the integer $$$x_i$$$ to the back of the array $$$a$$$ so that the array $$$a$$$ stays beautiful, you have to append it; otherwise, do nothing. After each query, report whether you appended the given integer $$$x_i$$$, or not. Input The first line contains one integer $$$t$$$ ($$$1 le t le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line contains one integer $$$q$$$ ($$$1 le q le 2 cdot 10^5$$$) — the number of queries. The second line contains $$$q$$$ integers $$$x_1, x_2, dots, x_q$$$ ($$$0 le x_i le 10^9$$$). Additional constraint on the input: the sum of $$$q$$$ over all test cases does not exceed $$$2 cdot 10^5$$$). Output For each test case, print one string consisting of exactly $$$q$$$ characters. The $$$i$$$-th character of the string should be 1 if you appended the integer during the $$$i$$$-th query; otherwise, it should be 0.
1,000
false
false
true
false
false
false
false
false
false
false
1,244
1364D
# Ehab’s Last Corollary Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes Given a connected undirected graph with n vertices and an integer k, you have to either: • either find an independent set that has exactly d k > 2 e vertices. • or find a simple cycle of length at most k.An independent set is a set of vertices such that no two of them are connected by an edge. A simple cycle is a cycle that doesn’t contain any vertex twice. I have a proof that for any input you can always solve at least one of these problems, but it’s left as an exercise for the reader. # Input The first line contains three integers n, m, and k (3 ≤ k ≤ n ≤ 10 5, n − 1 ≤ m ≤ 2 · 10 5) x16 the number of vertices and edges in the graph, and the parameter k from the statement. Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) that mean there’s an edge between vertices u and v. It’s guaranteed that the graph is connected and doesn’t contain any self-loops or multiple edges. # Output If you choose to solve the first problem, then on the first line print 1, followed by a line containing d k > 2 e distinct integers not exceeding n, the vertices in the desired independent set. If you, however, choose to solve the second problem, then on the first line print 2, followed by a line containing one integer, c, representing the length of the found cycle, followed by a line containing c distinct integers not exceeding n, the vertices in the desired cycle, in the order they appear in the cycle . Page 1 of 6 Examples standard input standard output 4 4 3 1 2 2 3 3 4 4 1 11 3 4 5 3 1 2 2 3 3 4 4 1 2 4 232 3 4 4 6 3 1 2 2 3 3 4 4 1 1 3 2 4 231 2 3 5 4 5 1 2 1 3 2 4 2 5 11 4 5 # Note In the first sample: Page 2 of 6 Notice that printing the independent set {2, 4} is also OK, but printing the cycle 1 − 2 − 3 − 4 isn’t, because its length must be at most 3.In the second sample: Page 3 of 6 Notice that printing the independent set {1, 3} or printing the cycle 2 − 1 − 4 is also OK. In the third sample: Page 4 of 6 In the fourth sample: Page 5 of 6 Page 6 of 6
2,100
false
true
true
false
false
true
false
false
false
true
3,859
362A
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard. Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count. Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board. Please see the test case analysis. Input The first line contains number _t_ (1u2009≤u2009_t_u2009≤u200950) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line. Output For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise. Examples Input 2 ........ ........ ......#. K..##..# .......# ...##..# ......#. K............... ........ ..#..... ..#..#.. ..####.. ...##... ........ ....K#K# Note Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7). On the second board the semiknights will never meet.
1,500
true
true
false
false
false
false
false
false
false
false
8,387
912E
Problem - 912E - 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 dfs and similar math meet-in-the-middle number theory two pointers *2400 No tag edit access → Contest materials Editorial") . The next line lists _n_ distinct prime numbers _p_1,u2009_p_2,u2009...,u2009_p__n_ (2u2009≤u2009_p__i_u2009≤u2009100) in ascending order. The last line gives a single integer _k_ (1u2009≤u2009_k_). It is guaranteed that the _k_-th smallest integer such that all its prime divisors are in this set does not exceed 1018. Output Print a single line featuring the _k_-th smallest integer. It's guaranteed that the answer doesn't exceed 1018. Examples Input 3 2 3 5 7 Output 8 Input 5 3 7 11 13 31 17 Output 93 Note The list of numbers with all prime divisors inside {2,u20093,u20095} begins as follows: (1,u20092,u20093,u20094,u20095,u20096,u20098,u2009...) The seventh number in this list (1-indexed) is eight.
2,400
true
false
false
false
false
false
false
true
false
false
6,092
498E
Problem - 498E - 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 matrices *2700 No tag edit access → Contest materials : And if _w_u2009=u2009{5,u20091,u20090,u20093,u20090,u20090,u20091}, then it looks like that: Find the number of ways to color some borders of the figure's inner squares so that no square had all four borders colored. The borders of the squares lying on the border of the figure should be considered painted. The ways that differ with the figure's rotation should be considered distinct. Input The single line of the input contains 7 numbers _w_1,u2009_w_2,u2009...,u2009_w_7 (0u2009≤u2009_w__i_u2009≤u2009105). It is guaranteed that at least one of the _w__i_'s isn't equal to zero. Output In the single line of the output display a single number — the answer to the problem modulo 109u2009+u20097. Examples Input 0 1 0 0 0 0 0 Output 1 Input 0 2 0 0 0 0 0 Output 7 Input 1 1 1 0 0 0 0 Output 9 Input 5 1 0 3 0 0 1 Output 411199181 Note All the possible ways of painting the third sample are given below:
2,700
false
false
false
true
false
false
false
false
false
false
7,840
1176C
You are given an array $$$a$$$ consisting of $$$n$$$ integers. Each $$$a_i$$$ is one of the six following numbers: $$$4, 8, 15, 16, 23, 42$$$. Your task is to remove the minimum number of elements to make this array good. An array of length $$$k$$$ is called good if $$$k$$$ is divisible by $$$6$$$ and it is possible to split it into $$$frac{k}{6}$$$ subsequences $$$4, 8, 15, 16, 23, 42$$$. Examples of good arrays: $$$[4, 8, 15, 16, 23, 42]$$$ (the whole array is a required sequence); $$$[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$$$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements); $$$[]$$$ (the empty array is good). Examples of bad arrays: $$$[4, 8, 15, 16, 42, 23]$$$ (the order of elements should be exactly $$$4, 8, 15, 16, 23, 42$$$); $$$[4, 8, 15, 16, 23, 42, 4]$$$ (the length of the array is not divisible by $$$6$$$); $$$[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$$$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). Input The first line of the input contains one integer $$$n$$$ ($$$1 le n le 5 cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, dots, a_n$$$ (each $$$a_i$$$ is one of the following numbers: $$$4, 8, 15, 16, 23, 42$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. Output Print one integer — the minimum number of elements you have to remove to obtain a good array. Examples Input 12 4 8 4 15 16 8 23 15 16 42 23 42 Input 15 4 8 4 8 15 16 8 16 23 15 16 4 42 23 42
1,300
false
true
true
true
false
false
false
false
false
false
4,836
478E
Problem - 478E - 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 dfs and similar meet-in-the-middle sortings *2900 No tag edit access → Contest materials ") :: разбор задач") . Output Your task is to output the only integer _r_ — the answer to the given problem. If such number does not exist or it is larger than 1014, then print "-1" (minus one without the quotes) instead. Examples Input 123 4 Output 1845 Input 100 1 Output -1 Input 97461 457 Output 1805270103 Note The values of the first four wavy numbers that are divisible by _n_ for the first sample are: 492, 615, 738 and 1845.
2,900
false
false
false
false
false
false
true
false
true
false
7,917
1064B
Colossal!xa0— exclaimed Hawk-nose.xa0— A programmer! That's exactly what we are looking for. Arkadi and Boris Strugatsky. Monday starts on Saturday Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $$$a - (a oplus x) - x = 0$$$ for some given $$$a$$$, where $$$oplus$$$ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some $$$x$$$, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help. Input Each test contains several possible values of $$$a$$$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $$$t$$$ ($$$1 le t le 1000$$$)xa0— the number of these values. The following $$$t$$$ lines contain the values of parameter $$$a$$$, each value is an integer from $$$0$$$ to $$$2^{30} - 1$$$ inclusive. Output For each value of $$$a$$$ print exactly one integerxa0— the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of $$$a$$$ appear in the input. One can show that the number of solutions is always finite. Note Let's define the bitwise exclusive OR (XOR) operation. Given two integers $$$x$$$ and $$$y$$$, consider their binary representations (possibly with leading zeroes): $$$x_k dots x_2 x_1 x_0$$$ and $$$y_k dots y_2 y_1 y_0$$$. Here, $$$x_i$$$ is the $$$i$$$-th bit of the number $$$x$$$ and $$$y_i$$$ is the $$$i$$$-th bit of the number $$$y$$$. Let $$$r = x oplus y$$$ be the result of the XOR operation of $$$x$$$ and $$$y$$$. Then $$$r$$$ is defined as $$$r_k dots r_2 r_1 r_0$$$ where: $$$$$$ r_i = left{ begin{aligned} 1, ~ ext{if} ~ x_i e y_i 0, ~ ext{if} ~ x_i = y_i end{aligned} ight. $$$$$$ For the first value of the parameter, only $$$x = 0$$$ is a solution of the equation. For the second value of the parameter, solutions are $$$x = 0$$$ and $$$x = 2$$$.
1,200
true
false
false
false
false
false
false
false
false
false
5,389
177D2
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,500
false
false
false
false
true
false
false
false
false
false
9,147
12A
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base. Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3u2009×u20093 with digits from 1 to 9. Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. Input Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». Output Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. Note If you are not familiar with the term «central symmetry», you may look into
800
false
false
true
false
false
false
false
false
false
false
9,935
1073A
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it. Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not. Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. Input The first line contains a single integer $$$n$$$ ($$$1 le n le 1000$$$) — the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. Output Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. Note The first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.
1,000
false
false
true
false
false
false
false
false
false
false
5,353
1538G
Polycarp has $$$x$$$ of red and $$$y$$$ of blue candies. Using them, he wants to make gift sets. Each gift set contains either $$$a$$$ red candies and $$$b$$$ blue candies, or $$$a$$$ blue candies and $$$b$$$ red candies. Any candy can belong to at most one gift set. Help Polycarp to find the largest number of gift sets he can create. For example, if $$$x = 10$$$, $$$y = 12$$$, $$$a = 5$$$, and $$$b = 2$$$, then Polycarp can make three gift sets: In the first set there will be $$$5$$$ red candies and $$$2$$$ blue candies; In the second set there will be $$$5$$$ blue candies and $$$2$$$ red candies; In the third set will be $$$5$$$ blue candies and $$$2$$$ red candies. Note that in this example there is one red candy that Polycarp does not use in any gift set. Input The first line contains an integer $$$t$$$ ($$$1 le t le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single string containing four integers $$$x$$$, $$$y$$$, $$$a$$$, and $$$b$$$ ($$$1 le x, y, a, b le 10^9$$$). Output For each test case, output one numberxa0— the maximum number of gift sets that Polycarp can make. Example Input 9 10 12 2 5 1 1 2 2 52 311 13 27 1000000000 1000000000 1 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1 2 1 1 7 8 1 2 4 1 2 3 Output 3 0 4 1000000000 1 1 1 5 0
2,100
true
true
false
false
false
false
false
true
false
false
2,949
1919C
You are given an array $$$a$$$ of size $$$n$$$. You will do the following process to calculate your penalty: 1. Split array $$$a$$$ into two (possibly empty) subsequences$$$^dagger$$$ $$$s$$$ and $$$t$$$ such that every element of $$$a$$$ is either in $$$s$$$ or $$$t^ddagger$$$. 2. For an array $$$b$$$ of size $$$m$$$, define the penalty $$$p(b)$$$ of an array $$$b$$$ as the number of indices $$$i$$$ between $$$1$$$ and $$$m - 1$$$ where $$$b_i < b_{i + 1}$$$. 3. The total penalty you will receive is $$$p(s) + p(t)$$$. If you perform the above process optimally, find the minimum possible penalty you will receive. $$$^dagger$$$ A sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by the deletion of several (possibly, zero or all) elements. $$$^ddagger$$$ Some valid ways to split array $$$a=[3,1,4,1,5]$$$ into $$$(s,t)$$$ are $$$([3,4,1,5],[1])$$$, $$$([1,1],[3,4,5])$$$ and $$$([,],[3,1,4,1,5])$$$ while some invalid ways to split $$$a$$$ are $$$([3,4,5],[1])$$$, $$$([3,1,4,1],[1,5])$$$ and $$$([1,3,4],[5,1])$$$. Input 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. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1le nle 2cdot 10^5$$$)xa0— the size of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, ldots, a_n$$$ ($$$1 le a_i le n$$$)xa0— the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2cdot 10^5$$$. Note In the first test case, a possible way to split $$$a$$$ is $$$s=[2,4,5]$$$ and $$$t=[1,3]$$$. The penalty is $$$p(s)+p(t)=2 + 1 =3$$$. In the second test case, a possible way to split $$$a$$$ is $$$s=[8,3,1]$$$ and $$$t=[2,1,7,4,3]$$$. The penalty is $$$p(s)+p(t)=0 + 1 =1$$$. In the third test case, a possible way to split $$$a$$$ is $$$s=[,]$$$ and $$$t=[3,3,3,3,3]$$$. The penalty is $$$p(s)+p(t)=0 + 0 =0$$$.
1,400
false
true
false
true
true
false
false
false
false
false
779
1599I
Problem - 1599I - Codeforces =============== xa0 ]( --- Finished → Virtual participation Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest. → Problem tags data structures graphs *2700 No tag edit access → Contest materials $$$, ($$$1 leq L leq R leq M$$$) such that, if we delete all the edges except for $$$E_L, E_{L+1}, dots E_R$$$, the graph is a desert. Input The first line contains two integers $$$N$$$ and $$$M$$$ ($$$2 leq N leq 2.5 imes 10^5$$$, $$$1 leq M leq 5 imes 10^5$$$). Each of the next $$$M$$$ lines contains two integers. The $$$i$$$-th line describes the $$$i$$$-th edge. It contains integers $$$U_i$$$ and $$$V_i$$$, the nodes connected by the $$$i$$$-th edge ($$$E_i=(U_i, V_i)$$$). It is guaranteed that $$$1 leq U_i, V_i leq N$$$ and $$$U_i eq V_i$$$. Output The output contains one integer number – the answer. Examples Input 5 6 1 2 2 3 3 4 4 5 5 1 2 4 Output 20 Input 2 3 1 2 1 2 1 2 Output 5 Note In the second example: Graphs for pairs $$$(1, 1)$$$, $$$(2, 2)$$$ and $$$(3, 3)$$$ are deserts because they don't have any cycles. Graphs for pairs $$$(1, 2)$$$ and $$$(2, 3)$$$ have one cycle of length 2 so they are deserts.
2,700
false
false
false
false
true
false
false
false
false
true
2,656
1201E1
This problem only differs from the next problem in constraints. This is an interactive problem. Alice and Bob are playing a game on the chessboard of size $$$n imes m$$$ where $$$n$$$ and $$$m$$$ are even. The rows are numbered from $$$1$$$ to $$$n$$$ and the columns are numbered from $$$1$$$ to $$$m$$$. There are two knights on the chessboard. A white one initially is on the position $$$(x_1, y_1)$$$, while the black one is on the position $$$(x_2, y_2)$$$. Alice will choose one of the knights to play with, and Bob will use the other one. The Alice and Bob will play in turns and whoever controls the white knight starts the game. During a turn, the player must move their knight adhering the chess rules. That is, if the knight is currently on the position $$$(x, y)$$$, it can be moved to any of those positions (as long as they are inside the chessboard): $$$(x+1, y+2)$$$, $$$(x+1, y-2)$$$, $$$(x-1, y+2)$$$, $$$(x-1, y-2)$$$,$$$(x+2, y+1)$$$, $$$(x+2, y-1)$$$, $$$(x-2, y+1)$$$, $$$(x-2, y-1)$$$. We all know that knights are strongest in the middle of the board. Both knight have a single position they want to reach: the owner of the white knight wins if it captures the black knight or if the white knight is at $$$(n/2, m/2)$$$ and this position is not under attack of the black knight at this moment; The owner of the black knight wins if it captures the white knight or if the black knight is at $$$(n/2+1, m/2)$$$ and this position is not under attack of the white knight at this moment. Formally, the player who captures the other knight wins. The player who is at its target square ($$$(n/2, m/2)$$$ for white, $$$(n/2+1, m/2)$$$ for black) and this position is not under opponent's attack, also wins. A position is under attack of a knight if it can move into this position. Capturing a knight means that a player moves their knight to the cell where the opponent's knight is. If Alice made $$$350$$$ moves and nobody won, the game is a draw. Alice is unsure in her chess skills, so she asks you for a help. Choose a knight and win the game for her. It can be shown, that Alice always has a winning strategy. Interaction The interaction starts with two integers $$$n$$$ and $$$m$$$ ($$$6 le n,m le 40$$$, $$$n$$$ and $$$m$$$ are even) — the dimensions of the chessboard. The second line contains four integers $$$x_1, y_1, x_2, y_2$$$ ($$$1 le x_1, x_2 le n$$$, $$$1 le y_1, y_2 le m$$$)xa0— the positions of the white and the black knight. It is guaranteed that the two knights have different starting positions. It is also guaranteed that none of the knights are in their own target square in the beginning of the game (however, they can be on the opponent's target position). Your program should reply with either "WHITE" or "BLACK", depending on the knight you want to play with. In case you select the white knight, you start the game. During every your turn, you need to print two integers: $$$x$$$ and $$$y$$$, the position to move the knight. If you won the game by this turn, you must terminate your program immediately. After every turn of the opponent, you will receive two integers: $$$x$$$ and $$$y$$$, the position where Bob moved his knight. If your last move was illegal or you lost the game after jury's turn, or you made $$$350$$$ moves, and haven't won, you will receive "-1 -1". In such cases, you should terminate your program and then you will get a Wrong Answer verdict. After printing anything, do not forget to output the end of line and flush the output. Otherwise, you might 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 are disabled for this problem. Jury's program is adaptive: the moves of jury may depend on the moves made by your program. Note In the first example, the white knight can reach it's target square in one move. In the second example black knight wins, no matter what white knight moves.
2,900
false
false
false
false
false
false
false
false
false
true
4,691
1239E
Kolya has a turtle and a field of size $$$2 imes n$$$. The field rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom, while the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. Suppose in each cell of the field there is a lettuce leaf. The energy value of lettuce leaf in row $$$i$$$ and column $$$j$$$ is equal to $$$a_{i,j}$$$. The turtle is initially in the top left cell and wants to reach the bottom right cell. The turtle can only move right and down and among all possible ways it will choose a way, maximizing the total energy value of lettuce leaves (in case there are several such paths, it will choose any of them). Kolya is afraid, that if turtle will eat too much lettuce, it can be bad for its health. So he wants to reorder lettuce leaves in the field, so that the energetic cost of leaves eaten by turtle will be minimized. Input The first line contains an integer $$$n$$$ ($$$2 le n le 25$$$)xa0— the length of the field. The second line contains $$$n$$$ integers $$$a_{1, i}$$$ ($$$0 le a_{1, i} le 50,000$$$), the energetic cost of lettuce leaves in the first row of the field. The third line contains $$$n$$$ integers $$$a_{2, i}$$$ ($$$0 le a_{2, i} le 50,000$$$), the energetic cost of lettuce leaves in the second row of the field. Output Print two lines with $$$n$$$ integers in eachxa0— the optimal reordering of lettuce from the input data. In case there are several optimal ways to reorder lettuce, print any of them. Note In the first example, after reordering, the turtle will eat lettuce with total energetic cost $$$1+4+2 = 7$$$. In the second example, the turtle will eat lettuce with energetic cost equal $$$0$$$. In the third example, after reordering, the turtle will eat lettuce with total energetic cost equal $$$1$$$.
3,100
false
false
true
true
false
false
false
false
false
false
4,492
246B
Problem - 246B - 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 greedy math *1300 No tag edit access → Contest materials ") Tutorial") ; he simultaneously increases number _a__i_ by 1 and decreases number _a__j_ by 1, that is, executes _a__i_u2009=u2009_a__i_u2009+u20091 and _a__j_u2009=u2009_a__j_u2009-u20091. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input The first line contains integer _n_ (1u2009≤u2009_n_u2009≤u2009105) — the array size. The second line contains space-separated integers _a_1,u2009_a_2,u2009...,u2009_a__n_ (_a__i_u2009≤u2009104) — the original array. Output Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Examples Input 2 2 1 Output 1 Input 3 1 4 1 Output 3
1,300
true
true
false
false
false
false
false
false
false
false
8,847