Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.
The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.
When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.
What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N

-----Output-----
Print the maximum total comfort the N players can get.

-----Sample Input-----
4
2 2 1 3

-----Sample Output-----
7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.


How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"?
The answer can be enormous, so print it modulo (10^9+7).

-----Constraints-----
 - K is an integer between 1 and 10^6 (inclusive).
 - S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
K
S

-----Output-----
Print the number of strings satisfying the condition, modulo (10^9+7).

-----Sample Input-----
5
oof

-----Sample Output-----
575111451

For example, we can obtain proofend, moonwolf, and onionpuf, while we cannot obtain oofsix, oofelevennn, voxafolt, or fooooooo.


Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

-----Constraints-----
 - 2 \leq n \leq 10^5
 - 0 \leq a_i \leq 10^9
 - a_1,a_2,...,a_n are pairwise distinct.
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n

-----Output-----
Print a_i and a_j that you selected, with a space in between.

-----Sample Input-----
5
6 9 4 2 11

-----Sample Output-----
11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:
 - \rm{comb}(4,2)=6
 - \rm{comb}(6,2)=15
 - \rm{comb}(6,4)=15
 - \rm{comb}(9,2)=36
 - \rm{comb}(9,4)=126
 - \rm{comb}(9,6)=84
 - \rm{comb}(11,2)=55
 - \rm{comb}(11,4)=330
 - \rm{comb}(11,6)=462
 - \rm{comb}(11,9)=55
Thus, we should print 11 and 6.


The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.
Help the king by writing a program that answers this question.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq N
 - 1 \leq K \leq 10^{18}

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N

-----Output-----
Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

-----Sample Input-----
4 5
3 2 4 1

-----Sample Output-----
4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.


Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an integer K, list the K smallest Snuke numbers.

-----Constraints-----
 - 1 \leq K
 - The K-th smallest Snuke number is not greater than 10^{15}.

-----Input-----
Input is given from Standard Input in the following format:
K

-----Output-----
Print K lines. The i-th line should contain the i-th smallest Snuke number.

-----Sample Input-----
10

-----Sample Output-----
1
2
3
4
5
6
7
8
9
19


There is a function f(x), which is initially a constant function f(x) = 0.
We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:
 - An update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).
 - An evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.
We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq Q \leq 2 \times 10^5
 - -10^9 \leq a, b \leq 10^9
 - The first query is an update query.

-----Input-----
Input is given from Standard Input in the following format:
Q
Query_1
:
Query_Q

See Sample Input 1 for an example.

-----Output-----
For each evaluation query, print a line containing the response, in the order in which the queries are given.
The response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.

-----Sample Input-----
4
1 4 2
2
1 1 -8
2

-----Sample Output-----
4 2
1 -3

In the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.
In the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \leq x \leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.


Given are an integer N and arrays S, T, U, and V, each of length N.
Construct an N×N matrix a that satisfy the following conditions:
 - a_{i,j} is an integer.
 - 0 \leq a_{i,j}  \lt 2^{64}.
 - If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
 - If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
 - If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
 - If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.
However, there may be cases where no matrix satisfies the conditions.

-----Constraints-----
 - All values in input are integers.
 -  1 \leq N \leq 500
 -  0 \leq S_{i} \leq 1
 -  0 \leq T_{i} \leq 1
 -  0 \leq U_{i} \lt 2^{64}
 -  0 \leq V_{i} \lt 2^{64}

-----Input-----
Input is given from Standard Input in the following format:
N
S_{1} S_{2} ...  S_{N}
T_{1} T_{2} ...  T_{N}
U_{1} U_{2} ...  U_{N}
V_{1} V_{2} ...  V_{N}

-----Output-----
If there exists a matrix that satisfies the conditions, print one such matrix in the following format:
a_{1,1} ...  a_{1,N}
:
a_{N,1} ...  a_{N,N}

Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print -1.

-----Sample Input-----
2
0 1
1 0
1 1
1 0

-----Sample Output-----
1 1
1 0

In Sample Input 1, we need to find a matrix such that:
 - the bitwise AND of the elements in the 1-st row is 1;
 - the bitwise OR of the elements in the 2-nd row is 1;
 - the bitwise OR of the elements in the 1-st column is 1;
 - the bitwise AND of the elements in the 2-nd column is 0.


You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}.
For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:
 - If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 0 \leq A_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
A_1
:
A_N

-----Output-----
Print the minimum number of colors required to satisfy the condition.

-----Sample Input-----
5
2
1
4
5
3

-----Sample Output-----
2

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.


Chef likes arrays a lot. Today, he found an array A consisting of N positive integers.
Let L denote the sorted (in non-increasing order) list of size N*(N+1)/2 containing the sums of all possible contiguous subarrays of A. Chef is interested in finding the first K elements from the list L. Can you help him in accomplishing this task?

-----Input-----
There is only a single test case per input file.
The first line of input contains two space separated integer numbers N and K denoting the size of the array and the number of the maximal sums you need to find.
The following line contains N space separated integer numbers denoting the array A.

-----Output-----
Output K space separated integers where the ith integer denotes the ith element of L.

-----Constraints-----
- 1 ≤ N ≤ 105
- 1 ≤ K ≤ min(N*(N+1)/2, 105)
- 1 ≤ Ai ≤ 109

-----Subtasks-----
- Subtask 1 (47 pts) : 1 ≤ N ≤ 1000, 1 ≤ K ≤ min{N*(N+1)/2, 105}
- Subtask 2 (53 pts) : 1 ≤ N ≤ 105, 1 ≤ K ≤ min{N*(N+1)/2, 105}

-----Example-----
Input 13 4
1 3 4

Output 18 7 4 4

Input 23 3
10 2 7

Output 219 12 10

-----Explanation-----
Test 1:

The first 4 elements of it are [8, 7, 4, 4].


Chef has bought ten balls of five colours. There are two balls of each colour. Balls of same colour have same weight. Let us enumerate colours by numbers from 1 to 5. Chef knows that all balls, except two (of same colour), weigh exactly one kilogram. He also knows that each of these two balls is exactly 1 kg heavier than other balls.

You need to find the colour which balls are heavier than others.
To do that, you can use mechanical scales with two weighing pans. As your scales are very accurate, you can know the exact difference of weights of objects from first and second pans. Formally, the scales will give you the difference (signed difference) of weights of the objects put into the first pan and the second pan. See the following examples for details.

- If you put two balls of the same colour on your scales, each ball to one pan, the scales will tell you that difference is "0".
- But if you put into the first pan some balls of total weight 3 kg, and into the second pan of 5 kg, then scales will tell you "-2" because the second pan is 2 kg heavier than first.
- Similarly, if you put 5 kg weight in first pan and 3 kg in the second pan, then scale will tell you "2" as first pan is 2 kg heavier than second.

-----Input & Output-----
- The interaction process have two phases. At first phase you perform sequence of weighings on the mechanical scales. At the second phase you should output the colour of the heavier balls.
- To use the mechanical scales, you should print "1"(without quotes) and then print two lines, the first line will describe the enumeration of colours of balls on the first pan and second line should that of second pan.
- To describe some pan, you need to print one integer n - the number of balls you put in this pan, followed by n space-separated integers - colours of the balls you put in this pan.
- Once you have printed required data, you can read from the standard input one integer - the difference of weights of the first and the second pans.
- To output the colour of the heavier balls, you should print "2"(without quotes) and one integer in next line - colour of the heavier balls.

-----Constraints-----
- Each colour you print should be between 1 and 5.
- In each weighings, you can use at most two balls of same colour.
- Note that you can use scales as much times as you want (even zero).
- Once your program printed the colour of the heavier balls, it should finish its work, i.e. you should exit the program.
- Do not forget to flush standard output after each line you print.

-----Subtasks-----
- If you output incorrect colour (i.e. colour you printed is not that of heavier balls), your score will be zero.
- Let K will be the number of times you used scales.
- Then your score will be 100/K points.
- Please note that if K equals to zero, your score also will also be 100 points.

-----Example 1-----

Please note that the content in left side denotes output of your program where content in the right side denotes the response of judge which you should read as input.

Input and Output
1
1 1
1 1
					0
1
1 1
1 5
					-1
2
5

-----Example 2-----
Input and Output
1
3 1 2 5
0
					4
1
0
1 2
					-1
1
0
1 5
					-2
2
5

-----Explanation-----
In the first example, you first printed :

1
1 1
1 1

This means that you want to use the scale. Each of the first and second pan has one ball of colour 1.
Don't forget to flush the standard output after printing this.

After that you should read the input, the difference of weights between the two pans, in this case, it will be 0.

Now you printed :

1
1 1
1 5

It means, that you decided to use scale again. Now first pan contains one ball of colour 1 and the second pan contains one ball of colour 5.

Now, you should read the input, the difference of weights between the two pans, in this case, it will be -1.

Now, you realize that ball of colour 5 is heavier than of colour 1. It means that 5th colour is the colour of heaviest ball. So your print 2 followed by 5 in separate lines and exit your program.

You have used scale total 2 times. Hence your score will be 100/2 = 50.

In the second example, your score will be 100 / 3 = 33.3333333

-----Notes-----

Please note that clearing the output buffer can be done by using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout). Failure to flush the output buffer will result in Time Limit Exceeded verdict.

There are 5 test files. For each of the test file, score you will get is described above. The total sum of scores of your program for all the test files will be displayed on the contest page. This will be considered your final score for the problem.

Total points awarded for this problem will be equal to (your score) / (best score achieved in the contest) * 100.


Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set. Note that the square created need not to be parallel to the axis.

-----Input-----
The first line contains singe integer N.
Each of next N lines contains two integers Xi and Yi denotine the coordinates of i-th point.

-----Output-----
In a single line print single integer - the minimal number of points Chef need to paint to receive at least one square.

-----Constraints-----
- 0 ≤ N ≤ 2000
- -10^6 ≤ Xi, Yi ≤ 10^6
- There are NO coincided points

-----Example-----
Input:
3
0 0
2 2
3 3

Output:
2

Input:
5
0 0
100 100
200 200
100 0
0 100

Output:
0

-----Explanation-----
For the first example Chef can add points (2, 0), (0, 2) or (2, 3), (3, 2)
For the second example Chef already has square (0, 0), (100, 0), (0, 100), (100, 100).


Ramu was a lazy farmer. He had inherited a fairly large farm and a nice house from his father. Ramu leased out the farm land to others and earned a rather handsome income. His father used to keep a buffalo at home and sell its milk but the buffalo died a few days after his father did.
Ramu too wanted to make some money from buffaloes, but in a quite a different way. He decided that his future lay in speculating on buffaloes. In the market in his village, buffaloes were bought and sold everyday. The price fluctuated over the year, but on any single day the price was always the same.
He decided that he would buy buffaloes when the price was low and sell them when the price was high and, in the process, accummulate great wealth. Unfortunately his house had space for just one buffalo and so he could own at most one buffalo at any time.
Before he entered the buffalo market, he decided to examine to examine the variation in the price of buffaloes over the last few days and determine the maximum profit he could have made. Suppose, the price of a buffalo over the last $10$ days varied as
1012811111012151310101281111101215131010\quad  12\quad  8\quad  11\quad  11\quad  10\quad  12\quad  15\quad  13\quad  10
Ramu is a lazy fellow and he reckoned that he would have been willing to visit the market at most $5$ times (each time to either buy or sell a buffalo) over the last $10$ days. Given this, the maximum profit he could have made is $9$ rupees. To achieve this, he buys a buffalo on day $1$, sells it on day $2$, buys one more on day $3$ and sells it on day $8$. If he was a little less lazy and was willing to visit the market $6$ times, then he could have made more money. He could have bought on day $1$, sold on day $2$, bought on day $3$, sold on day $4$, bought on day $6$ and sold on day $8$ to make a profit of $10$ rupees.
Your task is help Ramu calculate the maximum amount he can earn by speculating on buffaloes, given a history of daily buffalo prices over a period and a limit on how many times Ramu is willing to go to the market during this period.

-----Input:-----
- The first line of the input contains two integers $N$ and $K$, where $N$ is the number of days for which the price data is available and $K$ is the maximum number of times that Ramu is willing to visit the cattle market.
- The next $N$ lines (line $2, 3,...,N+1$) contain a single positive integer each. The integer on line $i+1$, $1 \leq i \leq N$, indicates the price of a buffalo on day $i$.

-----Output:-----
A single nonnegative integer indicating that maximum amount of profit that Ramu can make if he were to make at most $K$ trips to the market.

-----Constraints:-----
- $1 \leq N \leq 400$.
- $1 \leq K \leq 400$.
- $0 \leq$ price of a buffalo on any day $\leq 1000$

-----Sample Input 1:-----
10 5
10
12
8
11
11
10
12
15
13
10

-----Sample Output 1:-----
9

-----Sample Input 2:-----
10 6
10
12
8
11
11
10
12
15
13
10

-----Sample Output 2:-----
10


Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Сommunity(SCC).

SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC. Mike told them that all stamps of the members could be divided in such a way that i'th member would get i postage stamps. Now Mike wants to know if he was right. The next SCC meeting is tomorrow. Mike still has no answer.

So, help Mike! There are N members in the SCC, i'th member has Ci stamps in his collection. Your task is to determine if it is possible to redistribute C1 + C2 + ... + Cn stamps among the members of SCC thus that i'th member would get i stamps.

-----Input-----
The first line contains one integer N, denoting the number of members of SCC.
The second line contains N integers Ci, denoting the numbers of the stamps in the collection of i'th member.

-----Output-----
The first line should contain YES, if we can obtain the required division, otherwise NO.

-----Constraints-----
1 ≤ N ≤ 100 000;
1 ≤  Ci ≤ 109.

-----Examples-----
Input:
5
7 4 1 1 2

Output:
YES

Input:
5
1 1 1 1 1

Output:
NO


Today, Chef woke up to find that he had no clean socks. Doing laundry is such a turn-off for Chef, that in such a situation, he always buys new socks instead of cleaning the old dirty ones. He arrived at the fashion store with money rupees in his pocket and started looking for socks. Everything looked good, but then Chef saw a new jacket which cost jacketCost rupees. The jacket was so nice that he could not stop himself from buying it.

Interestingly, the shop only stocks one kind of socks, enabling them to take the unsual route of selling single socks, instead of the more common way of selling in pairs. Each of the socks costs sockCost rupees.

Chef bought as many socks as he could with his remaining money. It's guaranteed that the shop has more socks than Chef can buy. But now, he is interested in the question: will there be a day when he will have only 1 clean sock, if he uses a pair of socks each day starting tommorow? If such an unlucky day exists, output "Unlucky Chef", otherwise output "Lucky Chef". Remember that Chef never cleans or reuses any socks used once.

-----Input-----
The first line of input contains three integers — jacketCost, sockCost, money — denoting the cost of a jacket, cost of a single sock, and the initial amount of money Chef has, respectively.

-----Output-----
In a single line, output "Unlucky Chef" if such a day exists. Otherwise, output "Lucky Chef".

-----Constraints-----
- 1 ≤ jacketCost ≤ money ≤ 109
- 1 ≤ sockCost ≤ 109

-----Example-----
Input:
1 2 3

Output:
Unlucky Chef

Input:
1 2 6

Output:
Lucky Chef

-----Subtasks-----
- Subtask 1:  jacketCost, money, sockCost ≤ 103. Points - 20
- Subtask 2: Original constraints. Points - 80

-----Explanation-----
Test #1:
When Chef arrived at the shop, he had 3 rupees. After buying the jacket, he has 2 rupees left, enough to buy only 1 sock.
Test #2:
Chef had 6 rupees in the beginning. After buying the jacket, he has 5 rupees left, enough to buy a pair of socks for 4 rupees.


The lockdown hasn’t been great for our chef as his restaurant business got sabotaged because of lockdown, nevertheless no worries our chef is a multi-talented guy. Chef has decided to be a freelancer and work remotely. According to chef’s maths, he should be able to work on maximum tasks assuming that he can only work on a single task at a time.
Assume that chef does N tasks. The start and finish time units of those tasks are given. Select the maximum number of tasks that can be performed by a chef, assuming that a he can only work on a single task at a time.

-----Input:-----
- The first input contains of size of array N representing the total number of tasks.
- The second and third lines contains N space-seperated integers representing the starting and finish time of the the tasks.

-----Output:-----
A single line containing indices of tasks that chef will be able to do.

-----Constraints-----
- $1 \leq N \leq 10^5$
- Note: The lists have been sorted based on the ending times of the tasks.

-----Sample Input 1:-----
3

10 12 20

20 25 30

-----Sample Output 1:-----
0  2

-----Sample Input 2:-----
6

1 2 0 6 3 7

2 4 5 7 9 10

-----Sample Output 2:-----
0  1  3  5


A pair of strings $(α, β)$ is called a subpair of a string $x$ if $x$ = $x_1+$$α+$$x_2+$$β+$$x_3$ (where a+b means concatenation of strings a and b) for some (possibly empty) strings $x1, x2$ and $x3$. We are given two strings and we need to find one subpair from each string such that :
Let $(a,b) , (c,d) $be subpair of $string1$ and $string2$ respectively and $X$ $=$ $a$ + $b$ + $c$ + $d$
- $X$ is a palindrome
- $|a| = |d|$
- $|b| = |c|$
- $|X|$ is maximum

-----Input Format:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, two strings str1, str2.

-----Output Format:-----
- For each testcase, output in a single line representing the length of palindrome |X|.

-----Constraints-----
- $1 \leq T \leq 5$
- $2 \leq |str1| \leq 10^3$
- $2 \leq |str2| \leq 10^3$

-----Sample Input 1:-----
1
abgcd dchbag

-----Sample Output 1:-----
8

-----Sample Input 2:-----
4

aaa aaa

zaaax yaaaw

zax yaw

zx yw

-----Sample Output 2:-----
6

6

2

0

-----EXPLANATION:-----
Sample Testcase 1: The subpairs are ("ab","cd") and ("dc","ba"). When the subpairs are concatenated string is "abcddcba" which is a pallindrome , |"ab"| = |"ba"|, |"cd"| = |"dc"| and has the maximum length equal to 8.


Andy got a box of candies for Christmas. In fact, he discovered that the box contained several identical smaller boxes, and they could contain even smaller boxes, and so on. Formally, we say that candies are boxes of level 0, and for 1 ≤ i ≤ n, a level i box contains ai boxes of level i - 1. The largest box has level n. Andy realized that it can take quite a long time to open all the boxes before he actually gets to eat some candies, so he put the box aside in frustration.

But today being his birthday, some friends came to visit Andy, and Andy decided to share some candies with them. In order to do that, he must open some of the boxes. Naturally, Andy can not open a box that is still inside an unopened box. If Andy wants to retrieve X candies, what is the least number of boxes he must open? You must help him answer many such queries. Each query is independent.

-----Input-----
- The first line contains two integers n and m, which refer to the level of the largest box, and the number of queries respectively.
- The second line contains n integers a1, ..., an.
- The third line contains m integers X1, ..., Xm.

-----Output-----
- Print m integers each in a new line, ith of them equal to the smallest number of boxes Andy must open in order to retrieve at least Xi candies.

-----Constraints-----
- 1 ≤ n,m ≤ 300000
- 1 ≤ ai ≤ 109
- 1 ≤ Xi ≤ 1012
- It is guaranteed that the total number of candies is at least Xi for all i

-----Example-----
Input 1:
5 1
1 1 1 1 1
1

Output 1:
5

Input 2:
3 3
3 3 3
2 8 13

Output 2:
3
5
8

-----Explanation-----
Testcase 1: The only candy is contained in five levels of boxes.
Testcase 2: In the third query, for 13 candies, Andy should open the largest box, two level-2 boxes, and finally five of six available level-1 boxes. Each of those boxes will contain 3 level-0 boxes (which are candies). So he'll have 15 candies in total, but he needs only 13 of them.


Guys don’t misinterpret this it is three only.

-----Input:-----
- First line will contain an integer $X$.

-----Output:-----
A single line containing the answer to the problem modulo 1000000007.

-----Constraints-----
- $1 \leq X < 10^5$

-----Sample Input 1:-----
1

-----Sample Output 1:-----
3

-----Sample Input 2:-----
2

-----Sample Output 2:-----
14


Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has a sequence of digits $S_{1}, S_{2}, \ldots , S_{N}$. He is staying in the first digit $S_{1}$ and wants to reach the last digit $S_{N}$ in the minimal number of jumps.
While staying in some index $i$ Chef can jump into $i - 1$ and $i + 1$, but he can't jump out from sequence. Or he can jump into any digit with the same value $S_i$.
Help Chef to find the minimal number of jumps he need to reach digit $S_{N}$ from digit $S_1$.

-----Input-----
Input contains a single line consist of string $S$ of length $N$ - the sequence of digits.

-----Output-----
In a single line print single integer - the minimal number of jumps he needs.

-----Constraints-----
- $1\leq N \leq 10^5$
- Each symbol of $S$ is a digit from $0$ to $9$.

-----Example Input 1-----
01234567890

-----Example Output 1-----
1

-----Example Input 2-----
012134444444443

-----Example Output 2-----
4

-----Explanation-----
Test Case 1: Chef can directly jump from the first digit (it is $0$) to the last (as it is also $0$).
Test Case 2: Chef should follow the following path: $1 - 2 - 4 - 5 - 15$.


Is the MRP of my new shoes exclusive or inclusive of taxes?

-----Input:-----
- First line will contain an integer $P$

-----Output:-----
For each testcase, print either 'Inclusive' or 'Exclusive' without quotes.

-----Constraints-----
- $100 \leq P \leq 999$

-----Sample Input 1:-----
123

-----Sample Output 1:-----
Exclusive

-----Sample Input 2:-----
111

-----Sample Output 2:-----
Inclusive


There are $n$ red balls kept on the positive $X$ axis, and $m$ blue balls kept on the positive $Y$ axis. You are given the positions of the balls. For each $i$ from $1$ to $n$, the $i$-th red ball has the coordinates $(x_i, 0)$, where $x_i$ is a positive integer. For each $i$ from $1$ to $m$, the $i$-th blue ball has the coordinates $(0, y_i)$, where $ y_i$ is a positive integer.
It is given that all $x_i$ are distinct. Also, all $y_i$ are distinct.
At the time $t= 0$, for each $i$ from $1$ to $n$, the $i^{\text{th}}$ red ball is thrown towards positive $Y$ axis with a speed of $u_i$( that is, with velocity vector $(0, u_i)$). Simultaneously (at time $t = 0$), for each $i$ from $1$ to $m$, the $i^{\text{th}}$ blue ball is thrown towards positive $X$ axis with a speed of $v_i$ (that is, with velocity vector $(v_i, 0)$).
Two balls are said to collide if they are at the same position at the same time. When two balls collide, they disappear, and hence no longer collide with other balls. (See sample examples for clarification).
Find the total number of collisions the balls will have.

-----Input-----
- First line contains $n$ and $m$, the number of red balls, and the number of blue balls, respectively.
- $i^{\text{th}}$  of the next $n$ lines contains two space separated integers $x_i$ and $u_i$, the position and speed of the $i^{\text{th}}$  red ball respectively
- $i^{\text{th}}$  of the next $m$ lines contains two space separated integers $y_i$ and $v_i$, the position and speed of the $i^{\text{th}}$  blue ball respectively

-----Output-----
Print the number of collisions.

-----Constraints-----
- $1 \le n, m \le 10^5$
- $1 \le x_i, u_i, y_i, v_i \le 10^9$
- for all $1 \le i < j \le n, x_i \neq x_j$
- for all $1 \le i < j \le m, y_i \neq y_j$

-----Example Input 1-----
1 1
1 2
2 1

-----Example Output 1-----
1

-----Example Input 2-----
1 2
1 2
2 1
1 2

-----Example Output 2-----
1

-----Explanation-----
Example case 1: The balls collide at t = 1, at the coordinates (1, 2).
Example case 2: The red ball and the second blue ball collide at time 0.5 at coordinates (1, 1). Note that the first blue ball would have collided with the red ball at t = 1 (like in sample input # 1), if the second blue ball wasn't present. But since the red ball disappears at t = 0.5, its collision with first blue ball doesn't happen. The total number of collisions is 1.


Teddy and Freddy are two friends. Teddy has a pile of strings of size $N$. Each string $Si$ in the pile has length less or equal to $100$ ($len(Si) \leq 100$).
Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$.
Teddy and Freddy like playing with strings. Teddy gives Freddy a string $B$ of size $M$.
He asks Freddy to find the count of the unique substrings of $B$ present in pile of strings of size $N$.
Freddy is busy with the some task, so he asks for your help.Help Freddy by giving the unique substrings of $B$ present in pile of strings of size $N$.
Note: The substrings having same permutation of characters are considered same.

-----Input:-----
- First line will contain $N$, number of strings. Then the strings follow.
- Next $N$ lines will contain a string
- $N+2$ line contains the $M$ - length of string B
- Following line contains the string B

-----Output:-----
For each testcase, output in a single line number of unique strings of B.

-----Constraints-----
- $1 \leq N \leq 100$
- $2 \leq len(Si) \leq 100$
- $2 \leq M \leq 100$

-----Sample Input:-----
4
a
abc
abcd
abcde
5
aaaaa

-----Sample Output:-----
1

-----Sample Input:-----
4
a
aa
aaa
aaaa
5
aaaaa

-----Sample Output:-----
4

-----EXPLANATION:-----
TestCase 1: Only substring of $aaaaa$ that is present in the pile of strings is $a$. So the answer is 1


$Alien$ likes to give challenges to $Codezen$ team to check their implementation ability, this time he has given a string $S$ and asked to find out whether the given string is a $GOOD$ string or not.
According to the challenge $GOOD$ String is a string that has at least $3$ consecutive vowels and at least $5$ different consonants.
For example $ACQUAINTANCES$  is a $ GOOD $String ,as it contains $3$ consecutive vowels  $UAI$ and $5$ different consonants $ {C, Q, N, T, S} $
but  $ACQUAINT $ is  not ,as it contain $3$ vowels but have only $ 4$ different consonants
${C, Q, N, T}$.

-----Input:-----
A string input is given from Standard Input that consists of only capital letters.

-----Output:-----
Output  a single line  that  is either $GOOD$  (if string is a good string ) or $-1$(if string is not good).

-----Constraints-----
- $8 \leq S \leq 1000$

-----Sample Input 1:-----
AMBITIOUSNESS

-----Sample Output 2:-----
GOOD

-----Sample Input 2:-----
COOEY

-----Sample Output 2:-----
-1


Zonal Computing Olympiad 2015, 29 Nov 2014

An interval is a pair of positive integers [a, b] with a ≤ b. It is meant to denote the set of integers that lie between the values a and b. For example [3,5] denotes the set {3,4,5} while the interval [3, 3] denotes the set {3}.

We say that an interval [a, b] is covered by an integer i, if i belongs to the set defined by [a, b]. For example interval [3, 5] is covered by 3 and so is the interval [3, 3].

Given a set of intervals I, and a set of integers S we say that I is covered by S if for each interval [a, b] in I there is an integer i in S such that [a, b] is covered by i. For example, the set {[3, 5], [3, 3]} is covered by the set {3}. The set of intervals {[6, 9], [3, 5], [4, 8]} is covered by the set {4, 5, 8}. It is also covered by the set {4, 7}.

We would like to compute, for any set of intervals I, the size of the smallest set S that covers it. You can check that for the set of intervals {[6, 9], [3, 5], [4, 8]} the answer is 2 while for the set of intervals {[3, 5], [3, 3]} the answer is 1.

Your program should take the set of intervals as input and output the size of the smallest set that covers it as the answer.

-----Input format-----
The first line contains a single integer N, giving the number of intervals in the input.

This is followed by N lines, each containing two integers separated by a space describing an interval, with the first integer guaranteed to be less than or equal to the second integer.

-----Output format-----
Output a single integer giving the size of the smallest set of integers that covers the given set of intervals.

-----Test data-----
You may assume that all integers in the input are in the range 1 to 10^8 inclusive.

Subtask 1 (100 marks) : 1 ≤ N ≤ 5000.

-----Sample Input 1-----
2
3 5
3 3

-----Sample Output 1-----
1

-----Sample Input 2-----
3
6 9
3 5
4 8

-----Sample Output 2-----
2


It is the last day of covid and you are coming back to your home with two empty sacks. On
the way to your home, you found Ambani brothers donating all their wealth in form of coins
after getting fed up with all the money they have. The coins have both positive and negative
values and they are laid down in a line. Now as you don’t want to go with an empty sack so
you also decided to take some of the money being given by Ambani’s. But anyone who
wants the money has to follow a rule that he/she can choose an only contiguous segment of
coins which are lying in a line (you can also imagine it like an array of coins) whether its value
is positive or negative.
Formally according to the rule if you are given an array [-1,2,3,4,2,0] you can only choose
subarrays like [2,3], [4,2,0], [-1] , [-1,2,3,4,2,0] etc.
Now as you have two siblings you decided to fill both the sacks with some coins. Your task is
to choose the coins in such a way that the sum of values of all the coins(including sacks 1
and 2) is maximum and both sacks are non-empty.
For e.g.:
If the array of coins is:
-1 2 3 4 -3 -5 6 7 1
Following are some ways you can choose the coins:
2 3 4 and -5 6 7
-1 2 3 and 6 7 1
2 3 4 and 6 7 1
and so on….
You can see that among the given ways the 3rd way will yield maximum values (2+3+4) +
(6+7+1)=23
Note:
Both the sack should be non-empty.
A subarray is a contiguous part of an array. An array that is inside another array.
A coin can be inserted in one and only one sacks i.e you cannot choose a coin more than one time.

-----Input:-----
- The first line contains $n$, the number of coins in the array $c$.
- The next line will contain $n$ space integers denoting the value $coin$ $c[i]$.

-----Output:-----
One and the only line containing the maximum possible sum of values of all the coins in
both sacks.

-----Constraints-----
- $2 \leq n \leq 10^5$
- $-10^5 \leq c[i] \leq 10^5$

-----Sample Input 1:-----
9

-1 2 3 4 -3 -5 6 7 1

-----Sample Output 1:-----
23

-----Sample Input 2:-----
6

-10 -1 -30 -40 -3 -11

-----Sample Output 2:-----
-4

-----EXPLANATION:-----
In first test case you can easily observe that the sum will be maximum if you choose [2,3,4]
and [6,7,1] contiguous subarrays from the given array.


Little Rohu from Pluto is the best bomb defusor on the entire planet. She has saved the planet from getting destruced multiple times now. Of course, she's proud of her achievments. But, to prepare herself for more complicated situations, she keeps challenging herself to handle tricky tasks.
Her current challenge involves the following things:
- A square matrix of the form N*N.
- B bombs planted at various cells of the square matrix.
- There can be multiple bombs at a given cell.
- Only the four corners of the square matrix have a bomb defusor, so if a bomb is moved to any one of the four corners, it will be defused.

From a given cell, any bomb can be moved in all the four directions, North, South, East, West respectively.

Rohu is given the number of bombs and the dimensions of the square matrix she's going to be dealing with, you've to help her figure out the minimum number of moves required to defuse all the bombs.

Note-1: She's not going to enter the matrix, she's just going to move the bombs from outside.
Note-2: The matrix is 1-indexed.

-----Input-----
- The first line of each test case contains two integers N, denoting the dimension of the square matrix, and B denoting the number of bombs. This will be followed by two lines, where the first line will denote the x-coordinate of all the bombs, and the second line will denote the y-coordinate of all the bombs. x[0], y[0] will be the position of the first bomb, ... , x[B-1], y[B-1] will be the position of the Bth bomb.

-----Output-----
- Output a single line containing the minimum number of moves required.

-----Subtasks-----
- 1 ≤ N, B ≤ 100000: 50 points

- 1 ≤ N, B ≤ 1000: 30 points

- 1 ≤ N, B ≤ 10: 20 points

-----Constraints-----
- 1 ≤ N, B ≤ 100000

-----Example 1-----
Input:
3 3
1 2 3
3 2 1

Output:
2

-----Example 2-----
Input:
2 1
1
1

Output:
0

-----Explanation-----
Example case 1:Only the bomb at {2,2} needs to be moved in two steps.
Example case 2:No bomb needs to be moved anywhere.


Write a program to obtain 2 numbers $($ $A$ $and$ $B$ $)$ and an arithmetic operator $(C)$ and then design a $calculator$ depending upon the operator entered by the user.
So for example if C="+", you have to sum the two numbers.
If C="-", you have to subtract the two numbers.
If C=" * ", you have to print the product.
If C=" / ", you have to divide the two numbers.

-----Input:-----
- First line will contain the first number $A$.
- Second line will contain the second number $B$.
- Third line will contain the operator $C$, that is to be performed on A and B.

-----Output:-----
Output a single line containing the answer, obtained by, performing the operator on the numbers. Your output will be considered to be correct if the difference between your output and the actual answer is not more than $10^{-6}$.

-----Constraints-----
- $-1000 \leq A \leq 1000$
- $-1000 \leq B \leq 1000$ $and$ $B \neq 0$
- $C$ $can$ $only$ $be$ $one$ $of$ $these$ $4$ $operators$ {" + ", " - ", " * ", " / "}

-----Sample Input:-----
8
2
/

-----Sample Output:-----
4.0

-----Sample Input:-----
5
3
+

-----Sample Output:-----
8


Mathison has bought a new deck of cards that contains 2N cards, numbered and ordered from 0 to 2N-1.
Mathison is getting bored and decides to learn the Dynamo shuffle (or Sybil cut) - a flashy manner to shuffle cards. Unfortunately, the Dynamo shuffle is a little too complicated so Mathison decides to create his own shuffle.

This newly invented shuffle is done in N steps. At step k (0 ≤ k < N) the deck is divided into 2k equal-sized decks
where each one contains cards that lie on consecutive positions.
Each one of those decks is then reordered: all the cards that lie on even positions are placed first followed by all cards that lie on odd positions
(the order is preserved in each one of the two subsequences and all positions are 0-based). Then all the decks are put back together (preserving the order of decks).

Mathison has spent hours practising the shuffle and he now believes that he has perfected his technique. However, Chef doesn't believe him yet so he asks Mathison to answer Q questions that given a deck of size 2N where i-th card is labelled i, find the position of the card labelled K in the final, shuffled deck.

-----Input-----
The first line of the input file will contain one integer, Q, representing the number of Chef's questions.
Each of the next Q lines will contain a pair of integers, N and K.

-----Output-----
The output file will contain Q lines, each one representing the answer to one of Chef's questions.

-----Constraints-----
- 1 ≤ Q ≤ 1000
- 1 ≤ N ≤ 64
- 0 ≤ K < 2N

-----Subtaks-----
Subtask #1 (30 points):

- 1 ≤ N ≤ 10

Subtask #2 (30 points):

- 1 ≤ N ≤ 32

Subtask #3 (40 points):

- Original constraints

-----Example-----
Input:
3
3 4
3 3
3 2

Output:
1
6
2

Input:
1
64 11047805202224836936

Output:
1337369305470044825

-----Explanation-----
In all questions, we have N = 3. Therefore, we have a deck with 8 cards.
The shuffling is done in three steps:

Step 0: We divide {0, 1, 2, 3, 4, 5, 6, 7} in 20 decks. We get only one deck.
The deck is reordered into {0, 2, 4, 6, 1, 3, 5, 7}.

Step 1: We divide {0, 2, 4, 6, 1, 3, 5, 7} in 21 decks. We get two decks: {0, 2, 4, 6} and {1, 3, 5, 7}.
{0, 2, 4, 6} is reordered into {0, 4, 2, 6} while {1, 3, 5, 7} is reordered into {1, 5, 3, 7}.
We get {0, 4, 2, 6, 1, 5, 3, 7} when we put the decks back together.

Step 2: We divide {0, 4, 2, 6, 1, 5, 3, 7} in 22 decks. We get four decks: {0, 4}, {2, 6}, {1, 5} and {3, 7}.
Each one of the four decks stays the same after it is reordered (as there are only two elements to reorder).
We get the final, shuffled deck: {0, 4, 2, 6, 1, 5, 3, 7}.

The card labelled 4 is on position 1.
The card labelled 3 is on position 6.
The card labelled 2 is on position 2.


Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on an NxN board.

The game is played between two players taking turns. First player puts an 'X' in an empty cell of the board, then the second player puts an 'O' in some other free cell. If the first player has K continuous X's or the second player has K continuous O's in row, column or diagonal, then he wins.

Chef started playing this new "Tic-Tac-Toe" with his assistant, beginning as the first player himself (that is, Chef plays 'X's). Currently, the game is ongoign, and it's Chef's turn. However, he needs to leave soon to begin tonight's dinner preparations, and has time to play only one more move. If he can win in one move, output "YES", otherwise output "NO" (without quotes). It is guaranteed that no player has already completed the winning criterion before this turn, and that it's a valid "Tic-Tac-Toe" game.

-----Input-----
The first line of input contains one integer T denoting the number of testcases. First line of each testcase contains two integers N and K, next N lines contains N characters each. Each character is either an 'X' denoting that the first player used this cell, an 'O' meaning that the second player used this cell, or a '.' (a period) representing a free cell.

-----Output-----
For each testcase, output, in a single line, "YES" if Chef can win in one move, or "NO" otherwise.

-----Constraints-----
- 1 ≤ T ≤ 100
- 3 ≤ N ≤ 20
- 1 ≤ K ≤ N

-----Example-----
Input:
3
3 3
XOX
O.O
XOX
3 1
...
...
...
3 2
...
...
...

Output:
YES
YES
NO

Input:
1
4 4
XOXO
OX..
XO..
OXOX

Output:
YES

-----Subtasks-----
- Subtask 1:  K  = 1. Points - 10
- Subtask 2:  N  =  K  = 3. Points - 30
- Subtask 3: Original constraints. Points - 60

-----Explanation-----
Test #1:

In first testcase, put 'X' in (2, 2), in second we can put 'X' in any cell and win.
Test #2:

If you put an 'X' in (3, 3), there will be four 'X's on the main diagonal (1, 1) - (2, 2) - (3, 3) - (4, 4).


As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma.
We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are words for our purpose. And aaabbaaa, abbba and bbb are examples of palindromes.
By a subword of a word, we mean a contiguous subsequence of the word. For example the subwords of the word abbba are a, b, ab, bb, ba, abb, bbb, bba, abbb, bbba and abbba.
In this task you will given a word and you must find the longest subword of this word that is also a palindrome.
For example if the given word is abbba then the answer is abbba. If the given word is abcbcabbacba then the answer is bcabbacb.

-----Input:-----
The first line of the input contains a single integer $N$ indicating the length of the word. The following line contains a single word of length $N$, made up of the letters a,b,…, z.

-----Output:-----
The first line of the output must contain a single integer indicating the length of the longest subword of the given word that is a palindrome. The second line must contain a subword that is a palindrome and which of maximum length. If there is more than one subword palindrome of maximum length, it suffices to print out any one.

-----Constraints:-----
- $1 \leq N \leq 5000$.
- You may assume that in $30 \%$ of the inputs $1 \leq N \leq 300$.

-----Sample Input 1:-----
5
abbba

-----Sample Output 1:-----
5
abbba

-----Sample Input 2:-----
12
abcbcabbacba

-----Sample Output 2:-----
8
bcabbacb


You are given a string S  of numbers. Dr. Dragoon has eaten up some numbers of the string. You decide to fix the string by putting the numbers 0 and 1 in the empty spaces.
The base cost for putting the ‘0’  is x  and putting ‘1’  is y . The cost of putting a number is the base cost multiplied by the number of times you use the letter till  that position (including   the position ).  The local mayor is happy with your work and commissions you for every number you put.

More specifically ,  if you put , say 0  in 5th position, the mayor will count the number of occurrences of 0  till 5th   position and pay you the same amount. You wonder what the minimum cost for fixing the string is. Note  – The answer can also be negative, they denote that you got an overall profit.

Input Format:

The input consists of 2 lines. First-line consists of the string of numbers S. ‘?’  denotes an empty position.

The second line consists of 2 integers x,y, the base cost of 0 and 1.

Output Format:

Output 1 integer, the minimum cost of fixing the string.

Constraints :

1<=|S|<=100

1<=x,y<=100

Sample Input:

501?1?

6 5

Sample Output:

6

Sample Input:

1001?11?

5  23

Sample Output:

8

Explanation  :

Fill 0 in the first place, the net cost will be 6-2=4. In the second place fill, 1 the net cost will be 5-3=2 Hence total cost is 4+2=6.

In second test case we will fill both spaces with zero , filling first zero costs  1*5-3=2 and filling the other zero costs  2*5  - 4 =6  , so total being 8.


Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with their hands and teeth and so on. A perceptive follower of such movies would have noticed that there are limits to what even the superheroes can do. For example, if the hero could directly jump to his ultimate destination, that would reduce the action sequence to nothing and thus make the movie quite boring. So he typically labours through a series of superhuman steps to reach his ultimate destination.
In this problem, our hero has to save his wife/mother/child/dog/… held captive by the nasty villain on the top floor of a tall building in the centre of Bombay/Bangkok/Kuala Lumpur/…. Our hero is on top of a (different) building. In order to make the action "interesting" the director has decided that the hero can only jump between buildings that are "close" to each other. The director decides which pairs of buildings are close enough and which are not.
Given the list of buildings, the identity of the building where the hero begins his search, the identity of the building where the captive (wife/mother/child/dog…) is held, and the set of pairs of buildings that the hero can jump across, your aim is determine whether it is possible for the hero to reach the captive. And, if he can reach the captive he would like to do so with minimum number of jumps.
Here is an example. There are $5$ buildings, numbered $1,2,...,5$, the hero stands on building $1$ and the captive is on building $4$. The director has decided that buildings $1$ and $3$, $2$ and $3, 1$ and $2, 3$ and $5$ and $4$ and $5$ are close enough for the hero to jump across. The hero can save the captive by jumping from $1$ to $3$ and then from $3$ to $5$ and finally from $5$ to $4$. (Note that if $i$ and $j$ are close then the hero can jump from $i$ to $j$ as well as from $j$ to $i$.). In this example, the hero could have also reached $4$ by jumping from $1$ to $2, 2$ to $3, 3$ to $5$ and finally from $5$ to $4$. The first route uses $3$ jumps while the second one uses $4$ jumps. You can verify that $3$ jumps is the best possible.
If the director decides that the only pairs of buildings that are close enough are $1$ and $3$, $1$ and $2$ and $4$ and $5$, then the hero would not be able to reach building $4$ to save the captive.

-----Input:-----
The first line of the input contains two integers $N$ and $M$. $N$ is the number of buildings: we assume that our buildings are numbered $1,2,...,N$. $M$ is the number of pairs of buildings that the director lists as being close enough to jump from one to the other. Each of the next $M$ lines, lines $2,...,M+1$, contains a pair of integers representing a pair of buildings that are close. Line $i+1$ contains integers $A_i$ and $B_i$, $1 \leq A_i \leq N$ and $1 \leq B_i \leq N$, indicating that buildings $A_i$ and $B_i$ are close enough. The last line, line $M+2$ contains a pair of integers $S$ and $T$, where $S$ is the building from which the Hero starts his search and $T$ is the building where the captive is held.

-----Output:-----
If the hero cannot reach the captive print $0$. If the hero can reach the captive print out a single integer indicating the number of jumps in the shortest route (in terms of the number of jumps) to reach the captive.

-----Constraints:-----
- $1 \leq N \leq 3500$.
- $1 \leq M \leq 1000000$.
- In at least $50 \%$ of the inputs $1 \leq N \leq 1000$ and $1 \leq M \leq 200000$.

-----Sample Input 1:-----
5 5
1 3
2 3
1 2
3 5
4 5
1 4

-----Sample Output 1:-----
3

-----Sample Input 2:-----
5 3
1 3
1 2
4 5
1 4

-----Sample Output 2:-----
0


Knights' tournaments were quite popular in the Middle Ages. A lot of boys were dreaming of becoming a knight, while a lot of girls were dreaming of marrying a knight on a white horse.

In this problem we consider one of these tournaments.

Let's us call a tournament binary, if it runs according to the scheme described below:

- Exactly N knights take part in the tournament, N=2K for some integer K > 0.

- Each knight has a unique skill called strength, described as an integer from the interval [1, N].

- Initially, all the knights are standing in a line, waiting for a battle. Since all their strengths are unique, each initial configuration can be described as a permutation of numbers from 1 to N.

- There are exactly K rounds in the tournament, 2K - i + 1 knights take part in the i'th round. The K'th round is called the final.

- The i'th round runs in the following way: for each positive integer j ≤ 2K - i happens a battle between a knight on the 2∙j'th position and a knight on the 2∙j+1'th position. The strongest of two continues his tournament, taking the j'th position on the next round, while the weakest of two is forced to leave.

- The only knight, who has won K rounds, is the winner. The only knight, who has won K - 1 rounds, but lost the final, is the runner-up.

As you can see from the scheme, the winner is always the same, an initial configuration doesn't change anything. So, your task is to determine chances of each knight to appear in the final.

Formally, for each knight you need to count the number of initial configurations, which will lead him to the final. Since the number can be extremly huge, you are asked to do all the calculations under modulo 109 + 9.

-----Input-----

The first line contains the only integer K, denoting the number of rounds of the tournament.

-----Output-----
Output should consist of 2K lines. The i'th line should contain the number of initial configurations, which lead the participant with strength equals to i to the final.

-----Constraints-----
1 ≤ K < 20

-----Examples-----
Input:
1

Output:
2
2

Input:
2

Output:
0
8
16
24

-----Explanation-----

In the first example we have N=2 knights. Let's consider each initial configuration that could appear and simulate the tournament.

(1, 2) -> (2)

(2, 1) -> (2)

In the second example we have N=4 knights. Let's consider some initial configurations that could appear and simulate the tournament.

(1, 2, 3, 4) -> (2, 4) -> (4)

(3, 2, 4, 1) -> (3, 4) -> (4)

(4, 1, 3, 2) -> (4, 3) -> (4)


We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example
24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8
is a permutation of $1,2,...,8$. Of course,
12345678123456781 \quad 2 \quad 3 \quad 4 \quad 5 \quad 6 \quad 7 \quad 8
is also a permutation of $1,2,...,8$.
We can "walk around" a permutation in a interesting way and here is how it is done for the permutation above:
Start at position $1$. At position $1$ we have $2$ and so we go to position $2$. Here we find $4$ and so we go to position $4$. Here we find $1$, which is a position that we have already visited. This completes the first part of our walk and we denote this walk by  ($1$ $2$ $4$ $1$). Such a walk is called a cycle. An interesting property of such walks, that you may take for granted, is that the position we revisit will always be the one we started from!
We continue our walk by jumping to first unvisited position, in this case position $3$ and continue in the same manner. This time we find $5$ at position $3$ and so we go to position $5$ and find $7$ and we go to position $7$ and find $3$ and thus we get the cycle ($3$ $5$ $7$ $3$). Next we start at position $6$ and get ($6$ $6$), and finally we start at position $8$ and get the cycle ($8$ $8$). We have exhausted all the positions. Our walk through this permutation consists of $4$ cycles.
One can carry out this walk through any permutation and obtain a set of cycles as the result. Your task is to print out the cycles that result from walking through a given permutation.

-----Input:-----
The first line of the input is a positive integer $N$ indicating the length of the permutation. The next line contains $N$ integers and is a permutation of $1,2,...,N$.

-----Output:-----
The first line of the output must contain a single integer $k$ denoting the number of cycles in the permutation. Line $2$ should describe the first cycle, line $3$ the second cycle and so on and line $k+1$ should describe the $k^{th}$ cycle.

-----Constraints:-----
- $1 \leq N \leq 1000$.

-----Sample input 1:-----
8
2 4 5 1 7 6 3 8

-----Sample output 1:-----
4
1 2 4 1
3 5 7 3
6 6
8 8

-----Sample input 2:-----
8
1 2 3 4 5 6 7 8

-----Sample output 2:-----
8
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8


$Riggi$   is a spy of $KBI$ and he is on a secret mission, he is spying an Underworld Don  $Anit$.
$Riggi$  is spying him since 5 years and he is not able to find  any evidence against $Anit$.
$KBI$ told $Riggi$ they will send him a code string in a special format that will inform him whether he  has continue or return back from mission.
According to $KBI$  firstly  he  has to find what is the original string and then he has to check string is palindrome or not .
If its a palindrome then he has to leave the mission and return back else continue spying $Anit$.
Rules to find original string :
1:-If in Code string any integer(N) followed by a string of alphabets that starts with '+' and  ends with '-' then he has to repeat that string N times  , like 3+acg- = acgacgacg.
2:-If there is no integer present before string then print the string is repeated 1 time.
like bc=bc.
Example of conversion from  Code string  to original string  : 2+ac-3+kb-j=acackbkbkbj

-----Input:-----
- Code string $S$ is taken as input  .

-----Output:-----
- Print  string $Continue$ if code string $S$ is not a palindrome else print $Return$ .

-----Constraints-----
- $1 \leq S \leq 1000$
- $1 \leq N \leq 1000$

-----Sample Input 1:-----
3+xy-bb3+yx-

-----Sample Output 1:-----
Return

-----Sample Input 2:-----
3+xy-bb3+xy-

-----Sample Output 2:-----
Continue

-----EXPLANATION:-----
Sample 1:- original string will be xyxyxybbyxyxyx which is  a palindrome hence print $Return$.
Sample 2:- original string will be xyxyxybbxyxyxy which is not a palindrome hence print
$Continue$.


Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e abs(i-j) .
Since Alisha is busy with her Semester exams help her find the maximum distance where distance is the maximum value of absolute difference between i and j  i.e abs(i-j) .

-----Input:-----
- The first and the only line contains the string s with each character either 'a', 'b', or 'c'.

-----Output:-----
Print a single integer the maximum absolute difference between i and j.

-----Constraints-----
- $1 \leq n \leq 10^5$
- s[i] can either be 'a', 'b' or 'c'.

-----Subtasks-----
- 40 points : $1 \leq n \leq 100$
- 60 points : $1 \leq n \leq 10^5$

-----Sample Input1:-----
aabcaaa

-----Sample Output1:-----
4

-----Sample Input2:-----
aba

-----Sample Output2:-----
1


Tim buy a string of  length N from his friend which consist of  ‘d’ and ‘u’ letters only
,but now Tim wants to sell the string at maximum cost.
The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence) consisting of equal letters.
Tim can change at most P characters of string (‘d’ to ‘u’   and   ‘u’ to ‘d’) you have to find out the maximum cost of string?

-----Input:-----
- First line will contain $N$ and $P$ .
- Second line will contain the String $S$.

-----Output:-----
Maximum cost of string S.

-----Constraints-----
- $1 \leq N\leq 10^5$
- $0 \leq P \leq N$

-----Sample Input 1:-----
4  2
$duud$

-----Sample Output 1:-----
4

-----Sample Input 2 :-----
10 1
$dduddudddu$

-----Sample Output 2:-----
6

-----EXPLANATION:-----
In the first sample input , We can obtain both strings $dddd$ and $uuuu$ .
In the second sample, the optimal answer is obtained with the string $dddddudd$ or with the string $dduddddd$


Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies.
Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie!
Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A$, to satisfy his hunger.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- Each testcase contains of  two space separated integers $N, B$.

-----Output:-----
For each test case, print a single integer $A$, the minimum number of cookies Chef must bake initially.

-----Constraints-----
- $1 \leq T \leq 1000$
- $1 \leq N \leq 1000000000$
- $2 \leq B \leq 1000000000$

-----Sample Input 1:-----
1
3 2

-----Sample Output 1:-----
2

-----Sample Input 2:-----
1
11 2

-----Sample Output 2:-----
6

-----Explanation 2:-----
Chef initially make 6 cookies. From the crumbs, Chef makes 3 new cookies with no crumbs left over. From the crumbs of the new cookies, Chef makes 1 new cookie and have crumbs left from one cookie. From the new cookie, Chef gets more crumbs. He adds the crumbs and gets one last cookie. After eating that, there are not enough crumbs left to make a new cookie. So a total of 11 cookies are consumed!


This is a rather simple problem to describe. You will be given three numbers $S, P$ and $k$. Your task is to find if there are integers $n_1, n_2,...,n_k$ such that $n_1 + n_2 +...+ n_k = S$, $n_1 \cdot n_2 \cdot ... \cdot n_k = P$. If such integers exist, print them out. If no such sequence of integers exist, then print "NO".
For example if $S=11, P=48$ and $k=3$ then $3, 4$ and $4$ is a solution. On the other hand, if $S=11, P=100$ and $k=3$, there is no solution and you should print "NO".

-----Input:-----
A single line with three integers $S, P$ and $k$.

-----Output:-----
A single word "NO" or a seqence of $k$ integers $n_1, n_2,..., n_k$ on a single line. (The $n_i$'s must add up to $S$ and their product must be $P$).

-----Constraints:-----
- $1 \leq k \leq 4$.
- $1 \leq S \leq 1000$.
- $1 \leq P \leq 1000$.

-----Sample input 1:-----
11 48 3

-----Sample output 1:-----
3 4 4

-----Sample input 2:-----
11 100 3

-----Sample output 2:-----
NO


Zonal Computing Olympiad 2013, 10 Nov 2012

Spaceman Spiff has crash landed on Planet Quorg. He has to reach his ship quickly. But the evil Yukbarfs have stolen many Death Ray Blasters and have placed them along the way. You'll have to help him out!

Spaceman Spiff is initially at the top left corner (1,1) of a rectangular N × M grid . He needs to reach the bottom right corner (N,M). He can only move down or right. He moves at the speed of 1 cell per second. He has to move every second—that is, he cannot stop and wait at any cell.

There are K special cells that contain the Death Ray Blasters planted by the Yukbarfs. Each Blaster has a starting time t and a frequency f.  It first fires at time t seconds, followed by another round at time t+f seconds, then at time t+2f seconds ….  When a Blaster fires, it simultaneously emits four pulses, one in each of the four directions: up, down, left and right.  The pulses travel at 1 cell per second.

Suppose a blaster is located at (x,y) with starting time t and frequency f.  At time t seconds, it shoots its first set of pulses. The pulse travelling upwards will be at the cell (x,y-s) at time t+s seconds.  At this time, the pulse travelling left will be at cell (x-s,y), the pulse travelling right will be at cell (x+s,y) and the pulse travelling down will be at cell (x,y+s).  It will fire next at time t+f seconds.  If a pulse crosses an edge of the grid, it disappears. Pulses do not affect each other if they meet. They continue along their original path. At any time, if Spaceman Spiff and a pulse are in the same cell, he dies. That is the only way pulses interact with Spaceman Spiff. Spaceman Spiff can also never be on a cell which has a blaster. Given these, you should find the least time (in seconds) in which Spaceman Spiff can reach his ship safely.

As an example consider a 4×4 grid that has only one Blaster, at (3,2), with starting time 1 and frequency 3.  In the grids below, S denotes Spaceman Spiff, B denotes the blaster and P denotes a pulse.  The sequence of grids describes a successful attempt to reach his ship that takes 6 seconds.
t=0                t=1                t=2                t=3
S  .  .  .         .  S  .  .         .  .  S  .         .  P  .  S
.  .  .  .         .  .  .  .         .  P  .  .         .  .  .  .
.  B  .  .         .  P  .  .         P  B  P  .         .  B  .  P
.  .  .  .         .  .  .  .         .  P  .  .         .  .  .  .

t=4                t=5                t=6
.  .  .  .         .  .  .  .         .  P  .  .
.  .  .  S         .  P  .  .         .  .  .  .
.  P  .  .         P  B  P  S         .  B  .  P
.  .  .  .         .  P  .  .         .  .  .  S

-----Input format-----
Line 1: Three space separated integers N, M and K, describing the number of rows and columns in the grid and the number of Blasters, respectively.

Lines 2 to K+1: These lines describe the K blasters.  Each line has four space separated integers. The first two integers on the line denote the row and column where the Blaster is located, the third integer is its starting time, and the fourth integer is its frequency.

-----Output format-----
The first line of output must either consist of the word YES, if Spaceman Spiff can reach his ship safely, or the word NO, if he cannot do so. If the output on the first line is YES then the second line should contain a single integer giving the least time, in seconds, that it takes him to reach his ship safely.

-----Sample Input 1-----
4 4 1
3 2 1 3

-----Sample Output 1-----
YES
6

-----Sample Input 2-----
5 5 2
5 1 1 2
4 4 1 2

-----Sample Output 2-----
YES
8

-----Test data-----
In all subtasks, you may assume that:
-
2 ≤ N,M ≤ 2500.
-
All the frequencies are guaranteed to be integers between 1 and 3000, inclusive.
-
All the starting times are guaranteed to be integers between 0 and 3000, inclusive.
-
All the coordinates of the Blasters are guaranteed to be valid cells in the N×M grid. No two Blasters will be on the same cell.

- Subtask 1 (30 marks) : K = 1.
- Subtask 2 (70 marks) : 1 ≤ K ≤ 2500.

-----Live evaluation data-----
- Subtask 1: Testcases 0,1.
- Subtask 2: Testcases 2,3,4,5.


Gotham City is again under attack. This time Joker has given an open challenge to solve the following problem in order to save Gotham. Help Batman in protecting Gotham by solving the problem.
You are given two strings A and B composed of lowercase letters of Latin alphabet. B can be obtained by removing some characters from A(including 0). You are given an array containing any random permutation of numbers $1$ to $N$, where $N$ is the length of the string A. You have to remove the letters of A in the given order of indices. Note that after removing one letter, the indices of other letters do not change. Return the maximum number of indices you can remove in the given order such that B is still obtainable from A.

-----Input:-----
- First two lines contains the strings A and B respectively.
- The third line contains a random permutation of numbers from $1$ to $N$ representing some order of indices of string A.

-----Output:-----
Print a single number denoting the maximum number of indices you can remove in the given order such that B is still obtainable from A.

-----Constraints-----
- $1 \leq |B| \leq |A| \leq 200000$

-----Sample Input #1:-----
xxyxxy
xyy
1 5 4 6 3 2

-----Sample Output #1:-----
3

-----Sample Input #2:-----
jphokenixr
joker
2 9 3 7 8 1 6 5 4 10

-----Sample Output #2:-----
5

-----EXPLANATION:-----
For the first example removing characters in order,
xxyxxy => _xyxxy => _xyx_y => _xy__y.
If we remove any other element now then we can not obtain 'xxy'. So the ans is 3.


Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected.
The professor took them to a place where there was a never-ending queue of solid metal cubes. The professor could see $n$ cubes at a time. On the day before, he had painted the first $n$ cubes from the left with various colours.
Ali was allowed to choose any painted cube to initially stand on (say $X$). Zafar was asked to stand on the last painted cube (the $n^{th}$ cube) with the professor.
The two students were given an activity each:
- Ali had to shout out the colour of the cube he is standing on.
- Zafar had to paint the adjacent cube on the right of him with that colour.
Both Ali and Zafar had to take one step to the right each time they performed their activity.
The Professor jumped along with Zafar, and never left his side. Throughout the activity he was looking leftwards keeping an eye on Ali. They were given a gold star and were allowed to go home when all the cubes that the professor could see at the time were painted with the same color.
Ali wanted to choose a position furthest from the professor and also wanted the gold star.
Can you help Ali to choose this position $X$?
The cubes are numbered from 1 starting from the first painted cube.
The colours are represented as integers.

-----Input:-----
- The first line contains one integer n, the number of cubes initially painted.
- The second line contains n space-separated integers: $a_1$, $a_2$, $\dots$, $a_n$, the colours the professor chose for the first $n$ cubes.

-----Output:-----
Print a single line containing one integer $X$, the position Ali should initially stand on.

-----Constraints-----
- $1 \leq n \leq 10^{6}$
- $0 \leq a_i \leq 999$

-----Sample Input 1:-----
4

3 3 8 8

-----Sample Output 1:-----
3

-----Sample Input 2:-----
4

2 8 7 3

-----Sample Output 2:-----
4


A greek once sifted some numbers. And it did something wonderful!

-----Input:-----
- First line will contain an integer $N$

-----Output:-----
Output in a single line answer to the problem.

-----Constraints-----
- $1 \leq N \leq 10^5$

-----Sample Input 1:-----
10

-----Sample Output 1:-----
4

-----Sample Input 2:-----
20

-----Sample Output 2:-----
8


Chef loves cooking. Also, he is very hygienic. Hence, Chef grows his own vegetables in his mini kitchen garden. He has $M$ lanes in which he grows vegetables. The $ith$  lane has $Ai$ vegetables growing in it.

Vegetables in $ith$ lane become edible on day $Di$ and day $Di+1$(that is, the vegetables are edible only on days $Di$ and $Di+1$,where $Di+1$ is the next day of $Di$).   For Example, if $Di$ is 2, then vegetable is edible on day 2 and day 3 only.   If not collected in these days, they cannot be cooked.

Also, Chef is a lone worker. Hence, with respect to his capacity, he can collect only $V$ vegetables per day.
But, Chef is a hard worker, and is willing to work every day, starting from day 1.

Chef is busy sowing the seeds. So, he assigns you the task to find out the maximum number of vegetables he can collect, provided that he collects optimally.

-----Input:-----
- First line contains of 2 space separated integers $M$ and $V$, number of lanes and capacity of Chef.
- Next $M$ lines follow
- Each $ith$ line contains 2 space separated integers, $Di$ and $Ai$, the day when the vegetable of the $ith$ lane become edible and the number of vegetables in that lane.

-----Output:-----
For each testcase, output in a single integer, that is the maximum number of vegetables that can be cooked

-----Constraints-----
- $1 \leq M,V \leq 3000$
- $1 \leq Di,Ai \leq 3000$

-----Subtasks-----
- 20 points : $1 \leq M \leq 100$
- 30 points : $1 \leq M \leq 1000$
- 50 points : $Original  Constraints$

-----Sample Input 1:-----
2 4
1 6
2 5

-----Sample Output 1:-----
11

-----Sample Input 2:-----
3 3
1 4
6 2
5 3

-----Sample Output 2:-----
9

-----EXPLANATION:-----
In the first sample, in order to obtain the optimal answer, you should do the following:-
- On day 1, collect 4 vegetables from lane 1
- On day 2, collect 2 vegetables from lane 1 and 2 vegetables from lane 2
- On day 3, collect 3 vegetables from lane 2
In the first sample, in order to obtain the optimal answer, you should do the following:-
- On day 1, collect 3 vegetables from lane 1
- On day 2, collect 1 vegetable from lane 1
- On day 5, collect 3 vegetables from lane 3
- On day 6, collect 2 vegetables from lane 2


Rashmi loves the festival of Diwali as she gets to spend time with family and enjoy the festival. Before she can fully enjoy the festival she needs to complete the homework assigned by her teacher. Since Rashmi is smart , she has solved all the problems but is struck at one tricky pattern question.
Your Task is to help Rashmi solve the problem so that she can enjoy the festival with her family.
The Problem she is struck on is defined like this:
Given an integer N you need to generate the pattern according to following example:
Example:

Input:

3
Output:

1 4 10

2 5 11

4 10 22

3 6 12

-----Input:-----
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The next line of each contains T space separated integers N.

-----Output:-----
For each N print the required pattern.

-----Constraints:-----
$1 \leq T \leq 10^5$
$1 \leq N \leq 30$

-----Sample Input:-----
2
3 5

-----Sample Output:-----
1 4 10

2 5 11

4 10 22

3 6 12

1 4 10 22 46

2 5 11 23 47

4 10 22 46 94

3 6 12 24 48

-----Sample Input:-----
1

4

-----Sample Output:-----
1 4 10 22

2 5 11 23

4 10 22 46

3 6 12 24


Chef likes inequalities. Please help him to solve next one.
Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers.

-----Input-----
The first line contains an integer T denoting number of tests.
First line of each test case contains four positive integer numbers a, b, c and d.

-----Output-----
For each test case, output a single number each in separate line denoting number of integer solutions as asked in the problem.

-----Constraints-----
- 1 ≤ T ≤ 20
- 1 ≤ a, b, c, d ≤ 106

-----Subtasks-----
- Subtask #1: (30 points)  1 ≤ a, b, c, d ≤ 103.
- Subtask #2: (70 points)  Original constraints.

-----Example-----
Input:1
2 3 3 4

Output:3

Input:1
2 999999 1 1000000

Output:499998500001


In Chef's house there are N apples lying in a row on the floor. These apples are numbered from 1 (left most one) to N (right most one). The types of apples are also numbered by positive integers, and the type of apple i is Ti.
Chef has recently brought two trained dogs. Both of the dogs are too intelligent to know the smell of each type of apple. If Chef gives a dog an integer x, and releases it at one end of the row of apples, then the dog smells each apple one by one. Once the dog find an apple of type x, the dog picks the apple and back to Chef's room immidiately. If there is no apple of type x, then the dog will back without any apples.
Now Chef wants to eat two apples as soon as possible. Here the apples must have distinct types, and the sum of the types must be equal to K. Chef can release the dogs from either of the ends, namely, he can leave (both at left end) or (both at right end) or (one at left end and one at right end) and he can release them at the same time. The dogs take one second to smell each apple. However the dogs can run rapidly, so the time for moving can be ignored. What is the minimum time (in seconds) to get the desired apples from his dogs?

-----Input-----
The first line of input contains two space-separated integers N and K, denoting the number of apples and the required sum respectively. Then the next line contains N space-separated integers T1, T2, ..., TN, denoting the types of the apples.

-----Output-----
Print one integer describing the minimum number of seconds that Chef needs to wait till he gets the desired apples. If Chef cannot get the desired apples, then output "-1" without quotes.

-----Constraints-----
- 2 ≤ N ≤ 500000 (5 × 105)
- 1 ≤ K ≤ 1000000 (106)
- 1 ≤ Ti ≤ 1000000 (106)

-----Example-----
Sample Input 1:
5 5
2 4 3 2 1

Sample Output 1:
2

Sample Input 2:
5 5
2 4 9 2 5

Sample Output 2:
-1

-----Explanation-----
In the first example, if Chef leaves the first dog from left and gives it integer 4, and the second dog from right and gives it integer 1, then the first dog takes 2 seconds and the second dog takes 1 second to get the apples. Thus Chef needs to wait 2 seconds. In any other way, Chef can't get the desired apples in less than 2 seconds.
In the second example, Chef cannot get two apples such that the sum of their types is 5 so the answer is "-1".


There has been yet another murder in the Shady city of Riverdale. This murder is being investigated by none other than the Riverdale's Finest- Jughead Jones & Betty Cooper. This murder has been done exactly in the same manner as all the murders happening since the return of the deadly game Gargoyle &Griffins. Betty has decided to put an end to these murders, so they decide to interrogate each and every person in the neighbourhood.
As they don't know these people personally they want to first get to know about their character i.e whether a particular person is a Truth−speaking−person$Truth-speaking-person$ or a False−speaking−person$False-speaking-person$. Jughead devises a strategy of interrogating the civilians.
Jughead decides that they will collect statements from all the people in the neighbourhood about every other person living in the neighbourhood. Each person speaks a statement in form of an array consisting of T$T$ and F$ F$, which tells us what he thinks about the ith$ith$ person. Let there be N$N$ people living in the neighbourhood. So if a person i$i$ is giving his/her statement, he/her will always call himself/herself a True person i.e Statement[i]=T$Statement[i]=T$.
So Jughead says that they will select the maximum$maximum$ number$number$ of people that maybe speaking the truth such that their statements don't contradict and then interrogate them further about the murder.
Help them pick the max no. of Truth speaking people.
Note$Note$- A person speaking falsely$falsely$ doesn't mean that the complement of his statement would be the truth$truth$. If a person is declared false$false$(i.e not included in the set) after Betty and Jughead pick their set of truth speaking people with non-contradicting statements, the person declared false might not be speaking falsely$falsely$ about anyone(except saying he himself is a true$true$ speaking person which contradicts with the selected statements) but since the selected Set of statements feels him to be a false$false$ speaking person he won't be included in the set.
But if a person is tagged as truth$truth$ speaking person then their Statement must be entirely correct and should not contradict with the chosen set of truth$truth$ speaking people. All truth$truth$ speaking people mentioned in the selected statements should be part of the set and all the people declared false$false$ in the statements shouldn't be part of the set.
See example for clarity.

-----Input:-----
- First line will contain N$N$, the number of people in the neighbourhood. Then the Statements of ith$ith$ person follow.
- Each Statement contains a single line of input, an array of length N$N$ consisting of T$T$ and F$F$.

-----Output:-----
Print a single line denoting the maximum no. of people that might be speaking the truth.

-----Constraints-----
- 1≤N≤1000$1 \leq N \leq 1000$
- Statement$Statement$i$i$[i]=T$[i]=T$

-----Sample Input1:-----
5
T T F F F
T T F F F
T T T F F
F F F T T
F F F T T

-----Sample Output1:-----
2

-----Sample Input2:-----
3
T T T
T T T
F F T

-----Sample Output2:-----
1

-----EXPLANATION:-----
In Sample 1
We can consider the 1st$1st$ and 2nd$2nd$ person to be speaking the truth. We can also consider the 4th$4th$ and the 5th$5th$ person to be speaking the truth.
Note$Note$: we cannot select 1st$1st$ 2nd$2nd$ and 3rd$3rd$ person because the 1st$1st$ and the second person have labelled the 3rd person as a false speaking person, therefore if we select all 3 contradiction will arise.
In sample 2
Set contains only the 3rd person


Binod and his family live in Codingland. They have a festival called N-Halloween.
The festival is celebrated for N  consecutive days. On each day Binod gets some candies from his mother. He may or may not take them. On a given day ,  Binod will be sad if he collected candies on that day and he does not have at least X   candies remaining  from the candies he collected that day at the end of that day . His friend Pelu who is very fond of candies asks for X  candies from Binod on a day if Binod collects any candy on that day. He does so immediately after Binod collects them. Binod being a good friend never denies him.

Given a list a   where ai   denotes the number of candies Binod may take on the ith   day and  Q  queries having a number X , find the maximum number of candies Binod can collect so that he won't be sad after the festival ends.
Input format:

First-line contains two integers N and Q denoting the number of festival days and number of queries respectively.

The second line is the array whose ith   element is the maximum number of candies Binod may
collect on that day.

Each of the next Q lines contains the number X i.e the minimum number of candies Binod wants to have at the end of every day on which he collects any candy.
Output format:

For every query output, a single integer denoting the max number of candies Binod may
collect (for the given X ) to be happy after the festival ends.
Constraints:

1<=N,Q<=105

1<=Q<=105

0<=ai<=109

0<=X<=109

Sample Input :

5 2

4 6 5 8 7

1

2

Sample Output :

30

30

Sample Input:

6 3

20 10 12 3 30 5

2

6

13

Sample Output

77

62

30

Explanation:

In the first query of sample input 1, Binod can collect the maximum number of given chocolates for a given day each day as after the end of every day Binod will have a number of collected
chocolates on that day greater than equal to 1 even after giving 1 chocolate to Pelu. So the
the answer is 4+6+5+8+7=30.


Devu has an array A consisting of N positive integers. He would like to perform following operation on array.

- Pick some two elements a, b in the array (a could be same as b, but their corresponding indices in the array should not be same).
Remove both the elements a and b and instead add a number x such that x lies between min(a, b) and max(a, b), both inclusive, (i.e. min(a, b) ≤ x ≤ max(a, b)).

Now, as you know after applying the above operation N - 1 times, Devu will end up with a single number in the array. He is wondering whether it is possible to do the operations in such a way that he ends up a number t.

He asks your help in answering Q such queries, each of them will contain an integer t and you have to tell whether it is possible to end up t.

-----Input-----
There is only one test case per test file.
First line of the input contains two space separated integers N, Q denoting number of elements in A and number of queries for which Devu asks your help, respectively
Second line contains N space separated integers denoting the content of array A.

Each of the next Q lines, will contain a single integer t corresponding to the query.

-----Output-----
Output Q lines, each containing "Yes" or "No" (both without quotes) corresponding to the answer of corresponding query.

-----Constraints-----
- 1 ≤ N, Q ≤ 105
- 0 ≤ t ≤ 109

-----Subtasks-----
Subtask #1 : 30 points
- 1 ≤ Ai ≤ 2

Subtask #2 : 70 points
- 1 ≤ Ai ≤ 109

-----Example-----
Input 1:
1 2
1
1
2

Output:
Yes
No

Input 2:
2 4
1 3
1
2
3
4

Output:
Yes
Yes
Yes
No

-----Explanation-----
In the first example, Devu can't apply any operation. So the final element in the array will be 1 itself.

In the second example,
Devu can replace 1 and 3 with any of the numbers among 1, 2, 3. Hence final element of the array could be 1, 2 or 3.


Uppal-balu is busy in extraction of gold from ores. He got an assignment from his favorite professor MH sir, but he got stuck in a problem. Can you help Uppal-balu to solve the problem.
You are given an array $a_1$, $a_2$, $\dots$, $a_n$ of length $n$. You can perform the following operations on it:
- Choose an index $i$ ($1 \leq i \leq n$), and replace $a_i$ by $a_{i} + 1$ or $a_{i} - 1$, which means add or subtract one to the element at index $i$.
Beauty of the array is defined as maximum length of a subarray containing numbers which give same remainder upon dividing it by $k$ (that is, ($a_l$ mod $k$) = ($a_{l+1}$ mod $k$) = $\dots$ = ($a_r$ mod $k$) for some $1 \leq l \leq r \leq n$).
You need to calculate the beauty of the array $a_1$, $a_2$, $\dots$, $a_n$ after applying at most $m$ operations.
NOTE:
- The subarray of a is a contiguous part of the array $a$, i. e. the array $a_l$, $a_{l+1}$, $\dots$, $a_r$ for some $1 \leq l \leq r \leq n$.
- $x$ mod $y$ means the remainder of $x$ after dividing it by $y$.

-----Input:-----
- First line of input contains 3 integers $n$, $m$ and $k$.
- The second line contains $n$ integers $a_1$, $a_2$, $\dots$, $a_n$.

-----Output:-----
Output in a single line the beauty of the array after applying at most m operations.

-----Constraints-----
- $1 \leq n,m \leq 2\cdot10^{5}$
- $1 \leq k \leq 7$
- $1 \leq a_i \leq 10^9$

-----Sample Input 1:-----
7 3 4

8 2 3 7 8 1 1

-----Sample Output 1:-----
5

-----Sample Input 2:-----
8 3 5

7 2 1 3 6 5 6 2

-----Sample Output 2:-----
5


Jack and Jill got into a serious fight. Jack didn't not belive Jill when she said that her memory was far better than the others. He asked her to prove it as follows :-

-  Jack would dictate a long list of numbers to her. At any point after he has dictated  at least "k" numbers, he can ask her what is the k-th minimum number (the k-th number if the numbers are arranged in increasing order) in the list so far.
-  She succeeds in proving herself if she can tell the k-th minimum number every time he asks.
-  The number of queries (dictate a new number or ask her the k-th minimum of the numbers given till then) has to be pre-decided before he starts asking.

Jill succeeded in proving herself by convincing Jack quite a few times. Now, Jill remembered that Jack had claimed that he was good at programming. It's her turn to ask him to prove his skill. Jack doesn't want to lose to her and comes to you for help. He asks you to make the program for him.

-----Input-----
Jill has agreed to let Jack decide the format of the input and here's what he has decided. First line of the input contains n, the number of queries. Next line contains k. Next n lines contain a query each, say q. If  q >= 0  then the number is being 'dictated' to the system and needs to be remembered. If q = -1, then your program should return the k-th minimum number presented so far . It is given that 'q' can be -1 only if at least k numbers have already been given.

-----Output-----
For every q = -1, you have to output the k-th minimum number given as input so far (not counting -1 as an input)

-----Example-----
Input1:
6
2
3
2
-1
-1
1
-1

Output1:
3
3
2

Input2:
10
5
3
6
1
4
2
9
3
1
0
-1

Output2:
3


Given an array A of n non-negative integers. Find the number of ways to partition/divide the array into subarrays, such that  mex in each subarray is not more than k. For example, mex of the arrays [1, 2] will be 0, and that of [0, 2] will be 1, and that of [0, 1, 2] will be 3. Due to the fact that the answer can turn out to be quite large, calculate it modulo 109 + 7.

-----Input-----
- The first line of the input contains two integers n, k denoting the number of elements and limit of mex.
- The second line contains n space-separated integers A1, A2, ... , An .

-----Output-----
- Output a single integer corresponding to the answer of the problem.

-----Constraints-----
- 1 ≤ n ≤ 5 * 105
- 0 ≤ k, A[i] ≤ 109

-----Example-----
Input:
3 1
0 1 2

Output:
2

Input:
10 3
0 1 2 3 4 0 1 2 5 3

Output:
379

-----Explanation-----
Example 1. The valid ways of partitioning will be [[0], [1, 2]] (mex of first subarray is 1, while that of the second is zero), and [[0], [1], [2]] (mex of first subarray is 1, and that of others is 0). There is no other way to partition the array such that mex is less than or equal to 1. For example, [[0, 1], [2]] is not a valid partitioning as mex of first subarray is 2 which is more than 1.


Ayush is learning how to decrease a number by one, but he does it wrong with a number consisting of two or more digits. Ayush subtracts one from a number by the following algorithm:
if the last digit of the number is non-zero, he decreases the number by one.
if the last digit of the number is zero, he divides the number by 10.
You are given an integer number n
Ayush will subtract one from it k times. Your task is to print the result after all k subtractions.
It is guaranteed that the result will be a positive integer number.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 10^9, 1 ≤ k ≤ 50) -- the number from which Ayush will subtract and the number of subtractions respectively.
Output
Print one integer number — the result of the decreasing n by one k times.
It is guaranteed that the result will be a positive integer number.
EXAMPLE
Sample Input 1
512 4
Sample Output 1
50
Sample Input 2
1000000000 9
Sample Output 2
1


In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of a_{i} soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighboring cities by at moving along at most one road.

Check if is it possible that after roaming there will be exactly b_{i} soldiers in the i-th city.

-----Input-----

First line of input consists of two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 200).

Next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 100).

Next line contains n integers b_1, b_2, ..., b_{n} (0 ≤ b_{i} ≤ 100).

Then m lines follow, each of them consists of two integers p and q (1 ≤ p, q ≤ n, p ≠ q) denoting that there is an undirected road between cities p and q.

It is guaranteed that there is at most one road between each pair of cities.

-----Output-----

If the conditions can not be met output single word "NO".

Otherwise output word "YES" and then n lines, each of them consisting of n integers. Number in the i-th line in the j-th column should denote how many soldiers should road from city i to city j (if i ≠ j) or how many soldiers should stay in city i (if i = j).

If there are several possible answers you may output any of them.

-----Examples-----
Input
4 4
1 2 6 3
3 5 3 1
1 2
2 3
3 4
4 2

Output
YES
1 0 0 0
2 0 0 0
0 5 1 0
0 0 2 1

Input
2 0
1 2
2 1

Output
NO


While exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. Therefore, the researchers can reconstruct the book.

After taking a deeper look into the contents of these pages, linguists think that this may be some kind of dictionary. What's interesting is that this ancient civilization used an alphabet which is a subset of the English alphabet, however, the order of these letters in the alphabet is not like the one in the English language.

Given the contents of pages that researchers have found, your task is to reconstruct the alphabet of this ancient civilization using the provided pages from the dictionary.

-----Input-----

First-line contains two integers: $n$ and $k$ ($1 \le n, k \le 10^3$) — the number of pages that scientists have found and the number of words present at each page. Following $n$ groups contain a line with a single integer $p_i$ ($0 \le n \lt 10^3$) — the number of $i$-th page, as well as $k$ lines, each line containing one of the strings (up to $100$ characters) written on the page numbered $p_i$.

-----Output-----

Output a string representing the reconstructed alphabet of this ancient civilization. If the book found is not a dictionary, output "IMPOSSIBLE" without quotes. In case there are multiple solutions, output any of them.

-----Example-----
Input
3 3
2
b
b
bbac
0
a
aca
acba
1
ab
c
ccb

Output
acb


Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $a$, $b$, and $c$. Now he needs to find out some possible integer length $d$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $a$, $b$, $c$, and $d$. Help Yura, find any possible length of the fourth side.

A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.

-----Input-----

The first line contains a single integer $t$ — the number of test cases ($1 \le t \le 1000$). The next $t$ lines describe the test cases.

Each line contains three integers $a$, $b$, and $c$ — the lengths of the three fence segments ($1 \le a, b, c \le 10^9$).

-----Output-----

For each test case print a single integer $d$ — the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.

-----Example-----
Input
2
1 2 3
12 34 56

Output
4
42

-----Note-----

We can build a quadrilateral with sides $1$, $2$, $3$, $4$.

We can build a quadrilateral with sides $12$, $34$, $56$, $42$.


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 \neq v_i$) — indices of vertices connected by $i$-th edge.

It is guaranteed that $\sum\limits_{i=1}^{t} n \le 3 \cdot 10^5$ and $\sum\limits_{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

Output
4
0

-----Note-----

Possible ways to distribute numbers in the first test:   the vertex $1$ should contain $1$, and $2$ should contain $2$;  the vertex $1$ should contain $3$, and $2$ should contain $2$;  the vertex $1$ should contain $2$, and $2$ should contain $1$;  the vertex $1$ should contain $2$, and $2$ should contain $3$.

In the second test there is no way to distribute numbers.


We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller.
 - Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

-----Constraints-----
 - 0 ≤ K ≤ 50 \times 10^{16}

-----Input-----
Input is given from Standard Input in the following format:
K

-----Output-----
Print a solution in the following format:
N
a_1 a_2 ... a_N

Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.

-----Sample Input-----
0

-----Sample Output-----
4
3 3 3 3


Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.

There are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th route can be used to go from city v_{i} to city u_{i} (and from u_{i} to v_{i}), and it costs w_{i} coins to use this route.

Each city will be visited by "Flayer", and the cost of the concert ticket in i-th city is a_{i} coins.

You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city i you have to compute the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

Formally, for every $i \in [ 1, n ]$ you have to calculate $\operatorname{min}_{j = 1} 2 d(i, j) + a_{j}$, where d(i, j) is the minimum number of coins you have to spend to travel from city i to city j. If there is no way to reach city j from city i, then we consider d(i, j) to be infinitely large.

-----Input-----

The first line contains two integers n and m (2 ≤ n ≤ 2·10^5, 1 ≤ m ≤ 2·10^5).

Then m lines follow, i-th contains three integers v_{i}, u_{i} and w_{i} (1 ≤ v_{i}, u_{i} ≤ n, v_{i} ≠ u_{i}, 1 ≤ w_{i} ≤ 10^12) denoting i-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (v, u) neither extra (v, u) nor (u, v) present in input.

The next line contains n integers a_1, a_2, ... a_{k} (1 ≤ a_{i} ≤ 10^12) — price to attend the concert in i-th city.

-----Output-----

Print n integers. i-th of them must be equal to the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

-----Examples-----
Input
4 2
1 2 4
2 3 7
6 20 1 25

Output
6 14 1 25

Input
3 3
1 2 1
2 3 1
1 3 1
30 10 20

Output
12 10 12


You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.

Example 1:

Input:
s = "barfoothefoobarman",
words = ["foo","bar"]
Output: [0,9]
Explanation: Substrings starting at index 0 and 9 are "barfoor" and "foobar" respectively.
The output order does not matter, returning [9,0] is fine too.

Example 2:

Input:
s = "wordgoodstudentgoodword",
words = ["word","student"]
Output: []