You are given $n$ segments on a coordinate axis $OX$. The $i$-th segment has borders $[l_i; r_i]$. All points $x$, for which $l_i \le x \le r_i$ holds, belong to the $i$-th segment.

Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.

Two segments $[l_i; r_i]$ and $[l_j; r_j]$ are non-intersecting if they have no common points. For example, segments $[1; 2]$ and $[3; 4]$, $[1; 3]$ and $[5; 5]$ are non-intersecting, while segments $[1; 2]$ and $[2; 3]$, $[1; 2]$ and $[2; 2]$ are intersecting.

The segment $[l_i; r_i]$ lies inside the segment $[l_j; r_j]$ if $l_j \le l_i$ and $r_i \le r_j$. For example, segments $[2; 2]$, $[2, 3]$, $[3; 4]$ and $[2; 4]$ lie inside the segment $[2; 4]$, while $[2; 5]$ and $[1; 4]$ are not.

You have to answer $t$ independent test cases.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 3000$) — the number of segments. The next $n$ lines describe segments. The $i$-th segment is given as two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 2 \cdot 10^5$), where $l_i$ is the left border of the $i$-th segment and $r_i$ is the right border of the $i$-th segment.

Additional constraint on the input: there are no duplicates in the list of segments.

It is guaranteed that the sum of $n$ does not exceed $3000$ ($\sum n \le 3000$).

-----Output-----

For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.

-----Example-----
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7

Output
3
4
2
7


New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $h$ hours and $m$ minutes, where $0 \le hh < 24$ and $0 \le mm < 60$. We use 24-hour time format!

Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $0$ hours and $0$ minutes.

You have to answer $t$ independent test cases.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 1439$) — the number of test cases.

The following $t$ lines describe test cases. The $i$-th line contains the time as two integers $h$ and $m$ ($0 \le h < 24$, $0 \le m < 60$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $h=0$ and $m=0$. It is guaranteed that both $h$ and $m$ are given without leading zeros.

-----Output-----

For each test case, print the answer on it — the number of minutes before the New Year.

-----Example-----
Input
5
23 55
23 0
0 1
4 20
23 59

Output
5
60
1439
1180
1


There is a robot on a coordinate plane. Initially, the robot is located at the point $(0, 0)$. Its path is described as a string $s$ of length $n$ consisting of characters 'L', 'R', 'U', 'D'.

Each of these characters corresponds to some move:   'L' (left): means that the robot moves from the point $(x, y)$ to the point $(x - 1, y)$;  'R' (right): means that the robot moves from the point $(x, y)$ to the point $(x + 1, y)$;  'U' (up): means that the robot moves from the point $(x, y)$ to the point $(x, y + 1)$;  'D' (down): means that the robot moves from the point $(x, y)$ to the point $(x, y - 1)$.

The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $(x_e, y_e)$, then after optimization (i.e. removing some single substring from $s$) the robot also ends its path at the point $(x_e, y_e)$.

This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $s$).

Recall that the substring of $s$ is such string that can be obtained from $s$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".

You have to answer $t$ independent test cases.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The next $2t$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the robot's path. The second line of the test case contains one string $s$ consisting of $n$ characters 'L', 'R', 'U', 'D' — the robot's path.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).

-----Output-----

For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $l$ and $r$ such that $1 \le l \le r \le n$ — endpoints of the substring you remove. The value $r-l+1$ should be minimum possible. If there are several answers, print any of them.

-----Example-----
Input
4
4
LRUD
4
LURD
5
RRUDU
5
LLDDR

Output
1 2
1 4
3 4
-1


You have $n$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $i$-th student skill is denoted by an integer $a_i$ (different students can have the same skills).

So, about the teams. Firstly, these two teams should have the same size. Two more constraints:  The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).  The second team should consist of students with the same skills (i.e. all skills in the second team are equal).

Note that it is permissible that some student of the first team has the same skill as a student of the second team.

Consider some examples (skills are given):  $[1, 2, 3]$, $[4, 4]$ is not a good pair of teams because sizes should be the same;  $[1, 1, 2]$, $[3, 3, 3]$ is not a good pair of teams because the first team should not contain students with the same skills;  $[1, 2, 3]$, $[3, 4, 4]$ is not a good pair of teams because the second team should contain students with the same skills;  $[1, 2, 3]$, $[3, 3, 3]$ is a good pair of teams;  $[5]$, $[6]$ is a good pair of teams.

Your task is to find the maximum possible size $x$ for which it is possible to compose a valid pair of teams, where each team size is $x$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.

You have to answer $t$ independent test cases.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of students. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the skill of the $i$-th student. Different students can have the same skills.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).

-----Output-----

For each test case, print the answer — the maximum possible size $x$ for which it is possible to compose a valid pair of teams, where each team size is $x$.

-----Example-----
Input
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3

Output
3
1
0
2

-----Note-----

In the first test case of the example, it is possible to construct two teams of size $3$: the first team is $[1, 2, 4]$ and the second team is $[4, 4, 4]$. Note, that there are some other ways to construct two valid teams of size $3$.


You are given a tree consisting exactly of $n$ vertices. Tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a value $a_v$ assigned to it.

Let $dist(x, y)$ be the distance between the vertices $x$ and $y$. The distance between the vertices is the number of edges on the simple path between them.

Let's define the cost of the tree as the following value: firstly, let's fix some vertex of the tree. Let it be $v$. Then the cost of the tree is $\sum\limits_{i = 1}^{n} dist(i, v) \cdot a_i$.

Your task is to calculate the maximum possible cost of the tree if you can choose $v$ arbitrarily.

-----Input-----

The first line contains one integer $n$, the number of vertices in the tree ($1 \le n \le 2 \cdot 10^5$).

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the value of the vertex $i$.

Each of the next $n - 1$ lines describes an edge of the tree. Edge $i$ is denoted by two integers $u_i$ and $v_i$, the labels of vertices it connects ($1 \le u_i, v_i \le n$, $u_i \ne v_i$).

It is guaranteed that the given edges form a tree.

-----Output-----

Print one integer — the maximum possible cost of the tree if you can choose any vertex as $v$.

-----Examples-----
Input
8
9 4 1 7 10 1 6 5
1 2
2 3
1 4
1 5
5 6
5 7
5 8

Output
121

Input
1
1337

Output
0

-----Note-----

Picture corresponding to the first example: [Image]

You can choose the vertex $3$ as a root, then the answer will be $2 \cdot 9 + 1 \cdot 4 + 0 \cdot 1 + 3 \cdot 7 + 3 \cdot 10 + 4 \cdot 1 + 4 \cdot 6 + 4 \cdot 5 = 18 + 4 + 0 + 21 + 30 + 4 + 24 + 20 = 121$.

In the second example tree consists only of one vertex so the answer is always $0$.


You are given an array $a$ consisting of $n$ positive integers.

Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations:  Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$).  Just increase $x$ by $1$ ($x := x + 1$).

The first operation can be applied no more than once to each $i$ from $1$ to $n$.

Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by $k$ (the value $k$ is given).

You have to answer $t$ independent test cases.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) — the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).

-----Output-----

For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by $k$.

-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8

Output
6
18
0
227
8

-----Note-----

Consider the first test case of the example:  $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$;  $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$;  $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$;  $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$;  $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$;  $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$;  $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.

Note that you can't add $x$ to the same element more than once.


Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

Note:
You may assume the greed factor is always positive.
You cannot assign more than one cookie to one child.

Example 1:

Input: [1,2,3], [1,1]

Output: 1

Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3.
And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
You need to output 1.

Example 2:

Input: [1,2], [1,2,3]

Output: 2

Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2.
You have 3 cookies and their sizes are big enough to gratify all of the children,
You need to output 2.


Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

Note that the row index starts from 0.

In Pascal's triangle, each number is the sum of the two numbers directly above it.

Example:

Input: 3
Output: [1,3,3,1]

Follow up:

Could you optimize your algorithm to use only O(k) extra space?


Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

Note:

Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3, the input represents the signed integer -3.

Example 1:
Input: n = 00000000000000000000000000001011
Output: 3
Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.

Example 2:
Input: n = 00000000000000000000000010000000
Output: 1
Explanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.

Example 3:
Input: n = 11111111111111111111111111111101
Output: 31
Explanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.

Constraints:

The input must be a binary string of length 32.

Follow up: If this function is called many times, how would you optimize it?


Given a non-empty array of digits representing a non-negative integer, plus one to the integer.

The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.

You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1:

Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.

Example 2:

Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.


You are given two integers A and B.
Find the largest value among A+B, A-B and A \times B.

-----Constraints-----
 - -1000 \leq A,B \leq 1000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B

-----Output-----
Print the largest value among A+B, A-B and A \times B.

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

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

3+1=4, 3-1=2 and 3 \times 1=3. The largest among them is 4.


We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.

-----Constraints-----
 - 1 \leq N \leq 2\times 10^5
 - 0 \leq D \leq 2\times 10^5
 - |X_i|,|Y_i| \leq 2\times 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N D
X_1 Y_1
\vdots
X_N Y_N

-----Output-----
Print an integer representing the number of points such that the distance from the origin is at most D.

-----Sample Input-----
4 5
0 5
-2 4
3 4
4 -4

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

The distance between the origin and each of the given points is as follows:
 - \sqrt{0^2+5^2}=5
 - \sqrt{(-2)^2+4^2}=4.472\ldots
 - \sqrt{3^2+4^2}=5
 - \sqrt{4^2+(-4)^2}=5.656\ldots
Thus, we have three points such that the distance from the origin is at most 5.


An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.
Given an integer N, determine whether it is a Harshad number.

-----Constraints-----
 - 1?N?10^8
 - N is an integer.

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

-----Output-----
Print Yes if N is a Harshad number; print No otherwise.

-----Sample Input-----
12

-----Sample Output-----
Yes

f(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.


There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.
You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.
However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i.
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.
For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - -5000 \leq A_i \leq 5000 (1 \leq i \leq N)
 - All input values are integers.

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

-----Output-----
Print N lines.
In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled.

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

-----Sample Output-----
12
8
10

Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively.
For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:
 - For i = 1, the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.
 - For i = 2, the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.
 - For i = 3, the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.


Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u.

-----Constraints-----
 - c is a lowercase English letter.

-----Input-----
The input is given from Standard Input in the following format:
c

-----Output-----
If c is a vowel, print vowel. Otherwise, print consonant.

-----Sample Input-----
a

-----Sample Output-----
vowel

Since a is a vowel, print vowel.


Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

-----Constraints-----
 - 1 ≦ |S| ≦ 10^5
 - Each character in S is B or W.

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

-----Output-----
Print the minimum number of new stones that Jiro needs to place for his purpose.

-----Sample Input-----
BBBWW

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

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.
In either way, Jiro's purpose can be achieved by placing one stone.


AtCoDeer the deer has found two positive integers, a and b.
Determine whether the concatenation of a and b in this order is a square number.

-----Constraints-----
 - 1 ≤ a,b ≤ 100
 - a and b are integers.

-----Input-----
Input is given from Standard Input in the following format:
a b

-----Output-----
If the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.

-----Sample Input-----
1 21

-----Sample Output-----
Yes

As 121 = 11 × 11, it is a square number.


You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that a_i=X.
Maximize this count by making optimal choices.

-----Constraints-----
 - 1≤N≤10^5
 - 0≤a_i<10^5 (1≤i≤N)
 - a_i is an integer.

-----Input-----
The input is given from Standard Input in the following format:
N
a_1 a_2 .. a_N

-----Output-----
Print the maximum possible number of i such that a_i=X.

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

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

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.


We have an N \times N square grid.
We will paint each square in the grid either black or white.
If we paint exactly A squares white, how many squares will be painted black?

-----Constraints-----
 - 1 \leq N \leq 100
 - 0 \leq A \leq N^2

-----Inputs-----
Input is given from Standard Input in the following format:
N
A

-----Outputs-----
Print the number of squares that will be painted black.

-----Sample Input-----
3
4

-----Sample Output-----
5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.


Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.
Determine whether the arrangement of the poles is beautiful.

-----Constraints-----
 - 1 \leq a,b,c \leq 100
 - a, b and c are integers.

-----Input-----
Input is given from Standard Input in the following format:
a b c

-----Output-----
Print YES if the arrangement of the poles is beautiful; print NO otherwise.

-----Sample Input-----
2 4 6

-----Sample Output-----
YES

Since 4-2 = 6-4, this arrangement of poles is beautiful.


It is September 9 in Japan now.
You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

-----Constraints-----
 - 10≤N≤99

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

-----Output-----
If 9 is contained in the decimal notation of N, print Yes; if not, print No.

-----Sample Input-----
29

-----Sample Output-----
Yes

The one's digit of 29 is 9.


There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.
Initially, you are in Square X.
You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N.
However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1.
It is guaranteed that there is no toll gate in Square 0, Square X and Square N.
Find the minimum cost incurred before reaching the goal.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq M \leq 100
 - 1 \leq X \leq N - 1
 - 1 \leq A_1 < A_2 < ... < A_M \leq N
 - A_i \neq X
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M X
A_1 A_2 ... A_M

-----Output-----
Print the minimum cost incurred before reaching the goal.

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

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

The optimal solution is as follows:
 - First, travel from Square 3 to Square 4. Here, there is a toll gate in Square 4, so the cost of 1 is incurred.
 - Then, travel from Square 4 to Square 5. This time, no cost is incurred.
 - Now, we are in Square 5 and we have reached the goal.
In this case, the total cost incurred is 1.


We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.

-----Constraints-----
 - H is an integer between 1 and 50 (inclusive).
 - W is an integer between 1 and 50 (inclusive).
 - For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

-----Input-----
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

-----Output-----
If square1001 can achieve his objective, print Yes; if he cannot, print No.

-----Sample Input-----
3 3
.#.
###
.#.

-----Sample Output-----
Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.


Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

-----Constraints-----
 - 1 ≦ a, b, c ≦ 100

-----Input-----
The input is given from Standard Input in the following format:
a b c

-----Output-----
If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

-----Sample Input-----
10 30 20

-----Sample Output-----
Yes

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.


A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

-----Constraints-----
 - 1\leq A,B,C,D \leq 10
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B C D

-----Output-----
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

-----Sample Input-----
3 8 7 1

-----Sample Output-----
Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.


Joisino is planning to open a shop in a shopping street.
Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.
There are already N stores in the street, numbered 1 through N.
You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.
Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.
Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

-----Constraints-----
 - 1≤N≤100
 - 0≤F_{i,j,k}≤1
 - For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.
 - -10^7≤P_{i,j}≤10^7
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

-----Output-----
Print the maximum possible profit of Joisino's shop.

-----Sample Input-----
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

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

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.


The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

-----Constraints-----
 - 1≤A,B≤5
 - |S|=A+B+1
 - S consists of - and digits from 0 through 9.

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

-----Output-----
Print Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.

-----Sample Input-----
3 4
269-6650

-----Sample Output-----
Yes

The (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.


AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.
Find the minimum distance it needs to be moved.

-----Constraints-----
 - All input values are integers.
 - 1≤W≤10^5
 - 1≤a,b≤10^5

-----Input-----
The input is given from Standard Input in the following format:
W a b

-----Output-----
Print the minimum distance the second rectangle needs to be moved.

-----Sample Input-----
3 2 6

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

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.


Print all the integers that satisfies the following in ascending order:
 - Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

-----Constraints-----
 - 1 \leq A \leq B \leq 10^9
 - 1 \leq K \leq 100
 - All values in input are integers.

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

-----Output-----
Print all the integers that satisfies the condition above in ascending order.

-----Sample Input-----
3 8 2

-----Sample Output-----
3
4
7
8

 - 3 is the first smallest integer among the integers between 3 and 8.
 - 4 is the second smallest integer among the integers between 3 and 8.
 - 7 is the second largest integer among the integers between 3 and 8.
 - 8 is the first largest integer among the integers between 3 and 8.


Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC".
Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.

-----Constraints-----
 - The length of s is between 1 and 100, inclusive.
 - The first character in s is an uppercase English letter.
 - The second and subsequent characters in s are lowercase English letters.

-----Input-----
The input is given from Standard Input in the following format:
AtCoder s Contest

-----Output-----
Print the abbreviation of the name of the contest.

-----Sample Input-----
AtCoder Beginner Contest

-----Sample Output-----
ABC

The contest in which you are participating now.


There are a total of A + B cats and dogs.
Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
Determine if it is possible that there are exactly X cats among these A + B animals.

-----Constraints-----
 - 1 \leq A \leq 100
 - 1 \leq B \leq 100
 - 1 \leq X \leq 200
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B X

-----Output-----
If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

-----Sample Input-----
3 5 4

-----Sample Output-----
YES

If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.


We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.
How many grams of sand will the upper bulb contains after t seconds?

-----Constraints-----
 - 1≤X≤10^9
 - 1≤t≤10^9
 - X and t are integers.

-----Input-----
The input is given from Standard Input in the following format:
X t

-----Output-----
Print the number of sand in the upper bulb after t second.

-----Sample Input-----
100 17

-----Sample Output-----
83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.


Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.
However, if the result exceeds 10^{18}, print -1 instead.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - 0 \leq A_i \leq 10^{18}
 - All values in input are integers.

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

-----Output-----
Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

-----Sample Input-----
2
1000000000 1000000000

-----Sample Output-----
1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.


E869120 has A 1-yen coins and infinitely many 500-yen coins.

Determine if he can pay exactly N yen using only these coins.

-----Constraints-----
 - N is an integer between 1 and 10000 (inclusive).
 - A is an integer between 0 and 1000 (inclusive).

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

-----Output-----
If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.

-----Sample Input-----
2018
218

-----Sample Output-----
Yes

We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.


Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.
Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.
Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.
Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

-----Constraints-----
 - 1 ≤ X,A,B ≤ 10^9

-----Input-----
Input is given from Standard Input in the following format:
X A B

-----Output-----
Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

-----Sample Input-----
4 3 6

-----Sample Output-----
safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.


Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

-----Constraints-----
 - 1 \leq N \leq 10^9
 - N is an integer.

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

-----Output-----
Print the largest square number not exceeding N.

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

-----Sample Output-----
9

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.


AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

-----Constraints-----
 - 1≦N≦1000
 - 1≦T_i,A_i≦1000 (1≦i≦N)
 - T_i and A_i (1≦i≦N) are coprime.
 - It is guaranteed that the correct answer is at most 10^{18}.

-----Input-----
The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N

-----Output-----
Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

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

-----Sample Output-----
10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.


You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

-----Constraints-----
 - 2 ≤ |S| ≤ 26, where |S| denotes the length of S.
 - S consists of lowercase English letters.

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

-----Output-----
If all the characters in S are different, print yes (case-sensitive); otherwise, print no.

-----Sample Input-----
uncopyrightable

-----Sample Output-----
yes


There are N people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.
Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.
Find the minimum number of people who have to change their directions.

-----Constraints-----
 - 2 \leq N \leq 3 \times 10^5
 - |S| = N
 - S_i is E or W.

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

-----Output-----
Print the minimum number of people who have to change their directions.

-----Sample Input-----
5
WEEWW

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

Assume that we appoint the third person from the west as the leader.
Then, the first person from the west needs to face east and has to turn around.
The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.
It is not possible to have 0 people who have to change their directions, so the answer is 1.


There are N cities and M roads.
The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally.
There may be more than one road that connects the same pair of two cities.
For each city, how many roads are connected to the city?

-----Constraints-----
 - 2≤N,M≤50
 - 1≤a_i,b_i≤N
 - a_i ≠ b_i
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M

-----Output-----
Print the answer in N lines.
In the i-th line (1≤i≤N), print the number of roads connected to city i.

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

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

 - City 1 is connected to the 1-st and 3-rd roads.
 - City 2 is connected to the 1-st and 2-nd roads.
 - City 3 is connected to the 2-nd road.
 - City 4 is connected to the 3-rd road.


You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.
However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

-----Constraints-----
 - All input values are integers.
 - 1 ≤ N ≤ 100
 - 1 ≤ s_i ≤ 100

-----Input-----
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N

-----Output-----
Print the maximum value that can be displayed as your grade.

-----Sample Input-----
3
5
10
15

-----Sample Output-----
25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.


You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

-----Constraints-----
 - 2 \leq N \leq 100
 - |S| = N
 - S consists of lowercase English letters.

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

-----Output-----
Print the largest possible number of different letters contained in both X and Y.

-----Sample Input-----
6
aabbca

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

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.


The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...
Given is a string S representing the weather in the town today. Predict the weather tomorrow.

-----Constraints-----
 - S is Sunny, Cloudy, or Rainy.

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

-----Output-----
Print a string representing the expected weather tomorrow, in the same format in which input is given.

-----Sample Input-----
Sunny

-----Sample Output-----
Cloudy

In Takahashi's town, a sunny day is followed by a cloudy day.


You are parking at a parking lot. You can choose from the following two fee plans:
 - Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.
 - Plan 2: The fee will be B yen, regardless of the duration.
Find the minimum fee when you park for N hours.

-----Constraints-----
 - 1≤N≤20
 - 1≤A≤100
 - 1≤B≤2000
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N A B

-----Output-----
When the minimum fee is x yen, print the value of x.

-----Sample Input-----
7 17 120

-----Sample Output-----
119

 - If you choose Plan 1, the fee will be 7×17=119 yen.
 - If you choose Plan 2, the fee will be 120 yen.
Thus, the minimum fee is 119 yen.


Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.
Now, he goes through the following process:
 - Submit the code.
 - Wait until the code finishes execution on all the cases.
 - If the code fails to correctly solve some of the M cases, submit it again.
 - Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).

-----Constraints-----
 - All input values are integers.
 - 1 \leq N \leq 100
 - 1 \leq M \leq {\rm min}(N, 5)

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

-----Output-----
Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.

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

-----Sample Output-----
3800

In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.
The code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.
Thus, the answer is 1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800.


You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

-----Constraints-----
 - 1 \leq |S| \leq 10^5 (|S| is the length of string S.)
 - S consists of lowercase English letters.

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

-----Output-----
Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

-----Sample Input-----
atcoderregularcontest

-----Sample Output-----
b

The string atcoderregularcontest contains a, but does not contain b.


When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.

-----Constraints-----
 - 2 \leq N \leq 200000
 - N is even.
 - 1 \leq X_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N

-----Output-----
Print N lines.
The i-th line should contain B_i.

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

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

 - Since the median of X_2, X_3, X_4 is 4, B_1 = 4.
 - Since the median of X_1, X_3, X_4 is 3, B_2 = 3.
 - Since the median of X_1, X_2, X_4 is 3, B_3 = 3.
 - Since the median of X_1, X_2, X_3 is 4, B_4 = 4.


We have N sticks with negligible thickness.
The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

-----Constraints-----
 - 4 \leq N \leq 10^5
 - 1 \leq A_i \leq 10^9
 - A_i is an integer.

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

-----Output-----
Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

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

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

1 \times 2 rectangle can be formed.


Some number of chocolate pieces were prepared for a training camp.
The camp had N participants and lasted for D days.
The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.
As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq D \leq 100
 - 1 \leq X \leq 100
 - 1 \leq A_i \leq 100 (1 \leq i \leq N)
 - All input values are integers.

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

-----Output-----
Find the number of chocolate pieces prepared at the beginning of the camp.

-----Sample Input-----
3
7 1
2
5
10

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

The camp has 3 participants and lasts for 7 days.
Each participant eats chocolate pieces as follows:
 - The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.
 - The second participant eats one chocolate piece on Day 1 and 6, for a total of two.
 - The third participant eats one chocolate piece only on Day 1, for a total of one.
Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.


You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

-----Constraints-----
 - 0 \leq A, B, C \leq 50
 - A + B + C \geq 1
 - 50 \leq X \leq 20 000
 - A, B and C are integers.
 - X is a multiple of 50.

-----Input-----
Input is given from Standard Input in the following format:
A
B
C
X

-----Output-----
Print the number of ways to select coins.

-----Sample Input-----
2
2
2
100

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

There are two ways to satisfy the condition:
 - Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.
 - Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.


You are given three integers A, B and C.
Determine whether C is not less than A and not greater than B.

-----Constraints-----
 - -100≤A,B,C≤100
 - A, B and C are all integers.

-----Input-----
Input is given from Standard Input in the following format:
A B C

-----Output-----
If the condition is satisfied, print Yes; otherwise, print No.

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

-----Sample Output-----
Yes

C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.


Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
 - For each of the N kinds of doughnuts, make at least one doughnut of that kind.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.

-----Constraints-----
 - 2 ≤ N ≤ 100
 - 1 ≤ m_i ≤ 1000
 - m_1 + m_2 + ... + m_N ≤ X ≤ 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N X
m_1
m_2
:
m_N

-----Output-----
Print the maximum number of doughnuts that can be made under the condition.

-----Sample Input-----
3 1000
120
100
140

-----Sample Output-----
9

She has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.


You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.
How many kinds of items did you get?

-----Constraints-----
 - 1 \leq N \leq 2\times 10^5
 - S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).

-----Input-----
Input is given from Standard Input in the following format:
N
S_1
:
S_N

-----Output-----
Print the number of kinds of items you got.

-----Sample Input-----
3
apple
orange
apple

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

You got two kinds of items: apple and orange.


In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
 - Rating 1-399 : gray
 - Rating 400-799 : brown
 - Rating 800-1199 : green
 - Rating 1200-1599 : cyan
 - Rating 1600-1999 : blue
 - Rating 2000-2399 : yellow
 - Rating 2400-2799 : orange
 - Rating 2800-3199 : red
Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.

Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.

Find the minimum and maximum possible numbers of different colors of the users.

-----Constraints-----
 - 1 ≤ N ≤ 100
 - 1 ≤ a_i ≤ 4800
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

-----Sample Input-----
4
2100 2500 2700 2700

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

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.


In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).
A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.
Write a program that, when S is given, prints the price of the corresponding bowl of ramen.

-----Constraints-----
 - S is a string of length 3.
 - Each character in S is o or x.

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

-----Output-----
Print the price of the bowl of ramen corresponding to S.

-----Sample Input-----
oxo

-----Sample Output-----
900

The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \times 2 = 900 yen.


Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given two characters a and b as the input. Each of them is either H or D, and carries the following information:
If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.
If b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.
Given this information, determine whether TopCoDeer is honest.

-----Constraints-----
 - a=H or a=D.
 - b=H or b=D.

-----Input-----
The input is given from Standard Input in the following format:
a b

-----Output-----
If TopCoDeer is honest, print H. If he is dishonest, print D.

-----Sample Input-----
H H

-----Sample Output-----
H

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.


Sitting in a station waiting room, Joisino is gazing at her train ticket.
The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).
In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.
The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

-----Constraints-----
 - 0≤A,B,C,D≤9
 - All input values are integers.
 - It is guaranteed that there is a solution.

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

-----Output-----
Print the formula you made, including the part =7.
Use the signs + and -.
Do not print a space between a digit and a sign.

-----Sample Input-----
1222

-----Sample Output-----
1+2+2+2=7

This is the only valid solution.


A company has N members, who are assigned ID numbers 1, ..., N.
Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.
You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i < i

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

-----Output-----
For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.

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

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

The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.
The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.
The members numbered 3, 4, and 5 do not have immediate subordinates.


There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.
During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.
That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.
The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.
Find the earliest possible time to reach coordinate X.

-----Constraints-----
 - X is an integer.
 - 1≤X≤10^9

-----Input-----
The input is given from Standard Input in the following format:
X

-----Output-----
Print the earliest possible time for the kangaroo to reach coordinate X.

-----Sample Input-----
6

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

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.


We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?

-----Constraints-----
 - 1000 ≤ N ≤ 9999
 - N is an integer.

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

-----Output-----
If N is good, print Yes; otherwise, print No.

-----Sample Input-----
1118

-----Sample Output-----
Yes

N is good, since it contains three consecutive 1.


The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 1 \leq A_i \leq 10^9(1\leq i\leq N)
 - 1 \leq B_i \leq 10^9(1\leq i\leq N)
 - 1 \leq C_i \leq 10^9(1\leq i\leq N)
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

-----Output-----
Print the number of different altars that Ringo can build.

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

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

The following three altars can be built:
 - Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
 - Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
 - Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part


In programming, hexadecimal notation is often used.
In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.
In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.
When X and Y are seen as hexadecimal numbers, which is larger?

-----Constraints-----
 - Each X and Y is A, B, C, D, E or F.

-----Input-----
Input is given from Standard Input in the following format:
X Y

-----Output-----
If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.

-----Sample Input-----
A B

-----Sample Output-----
<

10 < 11.


You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
. stands for an empty square, and # stands for a square containing a bomb.
Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.
Print the strings after the process.

-----Constraints-----
 - 1 \leq H,W \leq 50
 - S_i is a string of length W consisting of # and ..

-----Input-----
Input is given from Standard Input in the following format:
H W
S_1
:
S_H

-----Output-----
Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

-----Sample Input-----
3 5
.....
.#.#.
.....

-----Sample Output-----
11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.


We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.
It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).
Consider the following action:
 - Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.
How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

-----Constraints-----
 - 1 \leq N, M \leq 200000
 - 1 \leq K \leq 10^9
 - 1 \leq A_i, B_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

-----Output-----
Print an integer representing the maximum number of books that can be read.

-----Sample Input-----
3 4 240
60 90 120
80 150 80 150

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

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.
We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.
 - Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.
 - Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.
 - Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.


"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.
Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

-----Constraints-----
 - 1 ≤ A, B, C ≤ 5000
 - 1 ≤ X, Y ≤ 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B C X Y

-----Output-----
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.

-----Sample Input-----
1500 2000 1600 3 2

-----Sample Output-----
7900

It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.


You are given an integer N.
Find the number of the positive divisors of N!, modulo 10^9+7.

-----Constraints-----
 - 1≤N≤10^3

-----Input-----
The input is given from Standard Input in the following format:
N

-----Output-----
Print the number of the positive divisors of N!, modulo 10^9+7.

-----Sample Input-----
3

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

There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.


You are given a positive integer X.
Find the largest perfect power that is at most X.
Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

-----Constraints-----
 - 1 ≤ X ≤ 1000
 - X is an integer.

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

-----Output-----
Print the largest perfect power that is at most X.

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

-----Sample Output-----
9

There are four perfect powers that are at most 10: 1, 4, 8 and 9.
We should print the largest among them, 9.


An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.
Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

-----Constraints-----
 - 1 ≤ N ≤ 100
 - 1 ≤ d_i ≤ 100
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
d_1
:
d_N

-----Output-----
Print the maximum number of layers in a kagami mochi that can be made.

-----Sample Input-----
4
10
8
8
6

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

If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.


Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).
Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

-----Constraints-----
 - 1 ≦ |s| ≦ 200{,}000
 - s consists of uppercase English letters.
 - There exists a substring of s that starts with A and ends with Z.

-----Input-----
The input is given from Standard Input in the following format:
s

-----Output-----
Print the answer.

-----Sample Input-----
QWERTYASDFZXCV

-----Sample Output-----
5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.


There are N positive integers written on a blackboard: A_1, ..., A_N.
Snuke can perform the following operation when all integers on the blackboard are even:
 - Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number of operations that Snuke can perform.

-----Constraints-----
 - 1 \leq N \leq 200
 - 1 \leq A_i \leq 10^9

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

-----Output-----
Print the maximum possible number of operations that Snuke can perform.

-----Sample Input-----
3
8 12 40

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

Initially, [8, 12, 40] are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.
After the operation is performed once, [4, 6, 20] are written on the blackboard.
Since all those integers are again even, he can perform the operation.
After the operation is performed twice, [2, 3, 10] are written on the blackboard.
Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.
Thus, Snuke can perform the operation at most twice.


Snuke loves working out. He is now exercising N times.
Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.
Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

-----Constraints-----
 - 1 ≤ N ≤ 10^{5}

-----Input-----
The input is given from Standard Input in the following format:
N

-----Output-----
Print the answer modulo 10^{9}+7.

-----Sample Input-----
3

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

 - After Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.
 - After Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.
 - After Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.


There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

-----Constraints-----
 - 1≦N≦100

-----Input-----
The input is given from Standard Input in the following format:
N

-----Output-----
Print the necessary number of candies in total.

-----Sample Input-----
3

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

The answer is 1+2+3=6.


We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

-----Constraints-----
 - N is an integer between 1 and 100 (inclusive).
 - a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N

-----Output-----
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

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

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

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.


Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).
The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.
The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties.

-----Constraints-----
 - N, M, and p_i are integers.
 - 1 \leq N \leq 10^5
 - 0 \leq M \leq 10^5
 - 1 \leq p_i \leq N
 - S_i is AC or WA.

-----Input-----
Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M

-----Output-----
Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

-----Sample Input-----
2 5
1 WA
1 AC
2 WA
2 AC
2 WA

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

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.
In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.
Thus, he has two correct answers and two penalties.


Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
 - Attack: Fennec chooses one monster. That monster's health will decrease by 1.
 - Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

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

-----Input-----
Input is given from Standard Input in the following format:
N K
H_1 ... H_N

-----Output-----
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

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

-----Sample Output-----
5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.


There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.
When activated, each type of robot will operate as follows.
 - When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
 - When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq K \leq 100
 - 0 < x_i < K
 - All input values are integers.

-----Inputs-----
Input is given from Standard Input in the following format:
N
K
x_1 x_2 ... x_N

-----Outputs-----
Print the minimum possible total distance covered by robots.

-----Sample Input-----
1
10
2

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

There are just one ball, one type-A robot and one type-B robot.
If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.
Similarly, if the type-B robot is used, the total distance covered will be 16.
Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.


You planned a trip using trains and buses.
The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket.
Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket.
Find the minimum total fare when the optimal choices are made for trains and buses.

-----Constraints-----
 - 1 \leq A \leq 1 000
 - 1 \leq B \leq 1 000
 - 1 \leq C \leq 1 000
 - 1 \leq D \leq 1 000
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
A
B
C
D

-----Output-----
Print the minimum total fare.

-----Sample Input-----
600
300
220
420

-----Sample Output-----
520

The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket.
Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen.
On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.
Therefore, the minimum total fare is 300 + 220 = 520 yen.


There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.
Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

-----Constraints-----
 - 1≦N≦10^5
 - 0≦A_i≦N-1

-----Input-----
The input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N

-----Output-----
Print the number of the possible orders in which they were standing, modulo 10^9+7.

-----Sample Input-----
5
2 4 4 0 2

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

There are four possible orders, as follows:
 - 2,1,4,5,3
 - 2,5,4,1,3
 - 3,1,4,5,2
 - 3,5,4,1,2


Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

-----Constraints-----
 - 1 \leq N \leq 10^4
 - 1 \leq A \leq B \leq 36
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N A B

-----Output-----
Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

-----Sample Input-----
20 2 5

-----Sample Output-----
84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.


This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

-----Constraints-----
 - 100 ≤ N ≤ 999

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

-----Output-----
Print the abbreviation for the N-th round of ABC.

-----Sample Input-----
100

-----Sample Output-----
ABC100

The 100th round of ABC is ABC100.


In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.

For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.

How many days from 2018-1-1 through 2018-a-b are Takahashi?

-----Constraints-----
 - a is an integer between 1 and 12 (inclusive).
 - b is an integer between 1 and 31 (inclusive).
 - 2018-a-b is a valid date in Gregorian calendar.

-----Input-----
Input is given from Standard Input in the following format:
a b

-----Output-----
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.

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

-----Sample Output-----
5

There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.


Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.
These buttons are numbered 1 through N.
When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.
When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

-----Constraints-----
 - 2 ≤ N ≤ 10^5
 - 1 ≤ a_i ≤ N

-----Input-----
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N

-----Output-----
Print -1 if it is impossible to lighten up Button 2.
Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.

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

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

Press Button 1, then Button 3.


You are playing the following game with Joisino.
 - Initially, you have a blank sheet of paper.
 - Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
 - Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

-----Constraints-----
 - 1≤N≤100000
 - 1≤A_i≤1000000000(=10^9)
 - All input values are integers.

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

-----Output-----
Print how many numbers will be written on the sheet at the end of the game.

-----Sample Input-----
3
6
2
6

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

The game proceeds as follows:
 - 6 is not written on the sheet, so write 6.
 - 2 is not written on the sheet, so write 2.
 - 6 is written on the sheet, so erase 6.
Thus, the sheet contains only 2 in the end. The answer is 1.


Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

-----Constraints-----
 - 1 \leq K \leq N \leq 200000
 - 1 \leq A_i \leq N
 - All input values are integers.

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

-----Output-----
Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

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

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

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.


AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 0 ≤ x_i ≤ 10^5
 - 0 ≤ y_i ≤ 10^5
 - 1 ≤ t_i ≤ 10^5
 - t_i < t_{i+1} (1 ≤ i ≤ N-1)
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N

-----Output-----
If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

-----Sample Input-----
2
3 1 2
6 1 1

-----Sample Output-----
Yes

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).


You are given two positive integers a and b.
Let x be the average of a and b.
Print x rounded up to the nearest integer.

-----Constraints-----
 - a and b are integers.
 - 1 \leq a, b \leq 100

-----Input-----
Input is given from Standard Input in the following format:
a b

-----Output-----
Print x rounded up to the nearest integer.

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

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

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.


You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.

The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.
An edge whose removal disconnects the graph is called a bridge.

Find the number of the edges that are bridges among the M edges.

-----Notes-----
 - A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M).
 - Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M).
 - An undirected graph is said to be connected when there exists a path between every pair of vertices.

-----Constraints-----
 - 2 \leq N \leq 50
 - N-1 \leq M \leq min(N(N−1)⁄2,50)
 - 1 \leq a_i<b_i \leq N
 - The given graph does not contain self-loops and double edges.
 - The given graph is connected.

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M

-----Output-----
Print the number of the edges that are bridges among the M edges.

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

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

The figure below shows the given graph:
The edges shown in red are bridges. There are four of them.


You are given three integers, A, B and C.

Among them, two are the same, but the remaining one is different from the rest.

For example, when A=5,B=7,C=5, A and C are the same, but B is different.

Find the one that is different from the rest among the given three integers.

-----Constraints-----
 - -100 \leq A,B,C \leq 100
 - A, B and C are integers.
 - The input satisfies the condition in the statement.

-----Input-----
Input is given from Standard Input in the following format:
A B C

-----Output-----
Among A, B and C, print the integer that is different from the rest.

-----Sample Input-----
5 7 5

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

This is the same case as the one in the statement.


Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.
 - Operation 1: Pour 100A grams of water into the beaker.
 - Operation 2: Pour 100B grams of water into the beaker.
 - Operation 3: Put C grams of sugar into the beaker.
 - Operation 4: Put D grams of sugar into the beaker.
In our experimental environment, E grams of sugar can dissolve into 100 grams of water.
Snuke will make sugar water with the highest possible density.
The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.
We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

-----Constraints-----
 - 1 \leq A < B \leq 30
 - 1 \leq C < D \leq 30
 - 1 \leq E \leq 100
 - 100A \leq F \leq 3 000
 - A, B, C, D, E and F are all integers.

-----Inputs-----
Input is given from Standard Input in the following format:
A B C D E F

-----Outputs-----
Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

-----Sample Input-----
1 2 10 20 15 200

-----Sample Output-----
110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.
We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:
 - If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.
 - If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.


The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.
You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

-----Constraints-----
 - 3 ≤ |s| ≤ 100 (|s| denotes the length of s.)
 - s consists of lowercase English letters.

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

-----Output-----
Print the abbreviation of s.

-----Sample Input-----
internationalization

-----Sample Output-----
i18n


You are given a grid with 2 rows and 3 columns of squares.
The color of the square at the i-th row and j-th column is represented by the character C_{ij}.
Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

-----Constraints-----
 - C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3) is a lowercase English letter.

-----Input-----
Input is given from Standard Input in the following format:
C_{11}C_{12}C_{13}
C_{21}C_{22}C_{23}

-----Output-----
Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.

-----Sample Input-----
pot
top

-----Sample Output-----
YES

This grid remains the same when rotated 180 degrees.


You are given a string s.
Among the different substrings of s, print the K-th lexicographically smallest one.
A substring of s is a string obtained by taking out a non-empty contiguous part in s.
For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.
Also, we say that substrings are different when they are different as strings.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

-----Constraints-----
 - 1 ≤ |s| ≤ 5000
 - s consists of lowercase English letters.
 - 1 ≤ K ≤ 5
 - s has at least K different substrings.

-----Partial Score-----
 - 200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

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

-----Output-----
Print the K-th lexicographically smallest substring of K.

-----Sample Input-----
aba
4

-----Sample Output-----
b

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.


There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).
Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:
 - If a_i = 1, he painted the region satisfying x < x_i within the rectangle.
 - If a_i = 2, he painted the region satisfying x > x_i within the rectangle.
 - If a_i = 3, he painted the region satisfying y < y_i within the rectangle.
 - If a_i = 4, he painted the region satisfying y > y_i within the rectangle.
Find the area of the white region within the rectangle after he finished painting.

-----Constraints-----
 - 1 ≦ W, H ≦ 100
 - 1 ≦ N ≦ 100
 - 0 ≦ x_i ≦ W (1 ≦ i ≦ N)
 - 0 ≦ y_i ≦ H (1 ≦ i ≦ N)
 - W, H (21:32, added), x_i and y_i are integers.
 - a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

-----Input-----
The input is given from Standard Input in the following format:
W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

-----Output-----
Print the area of the white region within the rectangle after Snuke finished painting.

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

-----Sample Output-----
9

The figure below shows the rectangle before Snuke starts painting.
First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:
Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:
Now, the area of the white region within the rectangle is 9.


A railroad running from west to east in Atcoder Kingdom is now complete.
There are N stations on the railroad, numbered 1 through N from west to east.
Tomorrow, the opening ceremony of the railroad will take place.
On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.
The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.
Here, it is guaranteed that F_i divides S_i.
That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.
For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

-----Constraints-----
 - 1≤N≤500
 - 1≤C_i≤100
 - 1≤S_i≤10^5
 - 1≤F_i≤10
 - S_i％F_i=0
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

-----Output-----
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

-----Sample Input-----
3
6 5 1
1 10 1

-----Sample Output-----
12
11
0

We will travel from Station 1 as follows:
 - 5 seconds after the beginning: take the train to Station 2.
 - 11 seconds: arrive at Station 2.
 - 11 seconds: take the train to Station 3.
 - 12 seconds: arrive at Station 3.
We will travel from Station 2 as follows:
 - 10 seconds: take the train to Station 3.
 - 11 seconds: arrive at Station 3.
Note that we should print 0 for Station 3.


There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or *. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).

-----Constraints-----
 - 1≦H, W≦100
 - C_{i,j} is either . or *.

-----Input-----
The input is given from Standard Input in the following format:
H W
C_{1,1}...C_{1,W}
:
C_{H,1}...C_{H,W}

-----Output-----
Print the extended image.

-----Sample Input-----
2 2
*.
.*

-----Sample Output-----
*.
*.
.*
.*


Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

-----Constraints-----
 - 2 ≤ N ≤ 200000
 - 1 ≤ A_i ≤ 10^9
 - All values in input are integers.

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

-----Output-----
If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

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

-----Sample Output-----
YES

The elements are pairwise distinct.