Score : <var>200</var> points

Problem Statement

We have <var>A</var> cards, each of which has an integer <var>1</var> written on it. Similarly, we also have <var>B</var> cards with <var>0</var>s and <var>C</var> cards with <var>-1</var>s.

We will pick up <var>K</var> among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

<var>0 \leq A, B, C</var>

<var>1 \leq K \leq A + B + C \leq 2 \times 10^9</var>

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>C</var> <var>K</var>

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with <var>1</var>s and one card with a <var>0</var>.
In this case, the sum of the numbers written on the cards is <var>2</var>, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


Score: <var>300</var> points

Problem Statement

We have <var>N</var> voting papers. The <var>i</var>-th vote <var>(1 \leq i \leq N)</var> has the string <var>S_i</var> written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

<var>1 \leq N \leq 2 \times 10^5</var>

<var>S_i</var> <var>(1 \leq i \leq N)</var> are strings consisting of lowercase English letters.

The length of <var>S_i</var> <var>(1 \leq i \leq N)</var> is between <var>1</var> and <var>10</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S_1</var>
<var>:</var>
<var>S_N</var>

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


Score : <var>100</var> points

Problem Statement

Rng is going to a festival.

The name of the festival is given to you as a string <var>S</var>, which ends with FESTIVAL, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.

Here, assume that the name of "a festival of <var>s</var>" is a string obtained by appending FESTIVAL to the end of <var>s</var>.
For example, CODEFESTIVAL is a festival of CODE.

Constraints

<var>9 \leq |S| \leq 50</var>

<var>S</var> consists of uppercase English letters.

<var>S</var> ends with FESTIVAL.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the answer to the question: "Rng is going to a festival of what?"

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE

This is the same as the example in the statement.

Sample Input 2

CODEFESTIVALFESTIVAL

Sample Output 2

CODEFESTIVAL

This string is obtained by appending FESTIVAL to the end of CODEFESTIVAL, so it is a festival of CODEFESTIVAL.

Sample Input 3

YAKINIKUFESTIVAL

Sample Output 3

YAKINIKU


Score : <var>100</var> points

Problem Statement

In this problem, we use the <var>24</var>-hour clock.

Takahashi gets up exactly at the time <var>H_1</var> : <var>M_1</var> and goes to bed exactly at the time <var>H_2</var> : <var>M_2</var>. (See Sample Inputs below for clarity.)
He has decided to study for <var>K</var> consecutive minutes while he is up.
What is the length of the period in which he can start studying?

Constraints

<var>0 \le H_1, H_2 \le 23</var>

<var>0 \le M_1, M_2 \le 59</var>

The time <var>H_1</var> : <var>M_1</var> comes before the time <var>H_2</var> : <var>M_2</var>.

<var>K \ge 1</var>

Takahashi is up for at least <var>K</var> minutes.

All values in input are integers (without leading zeros).

Input

Input is given from Standard Input in the following format:

<var>H_1</var> <var>M_1</var> <var>H_2</var> <var>M_2</var> <var>K</var>

Output

Print the length of the period in which he can start studying, as an integer.

Sample Input 1

10 0 15 0 30

Sample Output 1

270

Takahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.
It takes <var>30</var> minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is <var>270</var> minutes, so we should print <var>270</var>.

Sample Input 2

10 0 12 0 120

Sample Output 2

0

Takahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes <var>120</var> minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print <var>0</var>.


Score : <var>200</var> points

Problem Statement

We have an integer sequence <var>A</var>, whose length is <var>N</var>.

Find the number of the non-empty contiguous subsequences of <var>A</var> whose sums are <var>0</var>.
Note that we are counting the ways to take out subsequences.
That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.

Constraints

<var>1 \leq N \leq 2 \times 10^5</var>

<var>-10^9 \leq A_i \leq 10^9</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>

Output

Find the number of the non-empty contiguous subsequences of <var>A</var> whose sum is <var>0</var>.

Sample Input 1

6
1 3 -4 2 2 -2

Sample Output 1

3

There are three contiguous subsequences whose sums are <var>0</var>: <var>(1,3,-4)</var>, <var>(-4,2,2)</var> and <var>(2,-2)</var>.

Sample Input 2

7
1 -1 1 -1 1 -1 1

Sample Output 2

12

In this case, some subsequences that have the same contents but are taken from different positions are counted individually.
For example, three occurrences of <var>(1, -1)</var> are counted.

Sample Input 3

5
1 -2 3 -4 5

Sample Output 3

0

There are no contiguous subsequences whose sums are <var>0</var>.


Score : <var>400</var> points

Problem Statement

A maze is composed of a grid of <var>H \times W</var> squares - <var>H</var> vertical, <var>W</var> horizontal.

The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left - <var>(i,j)</var> - is a wall if <var>S_{ij}</var> is # and a road if <var>S_{ij}</var> is ..

There is a magician in <var>(C_h,C_w)</var>. He can do the following two kinds of moves:

Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.

Move B: Use magic to warp himself to a road square in the <var>5\times 5</var> area centered at the square he is currently in.

In either case, he cannot go out of the maze.

At least how many times does he need to use the magic to reach <var>(D_h, D_w)</var>?

Constraints

<var>1 \leq H,W \leq 10^3</var>

<var>1 \leq C_h,D_h \leq H</var>

<var>1 \leq C_w,D_w \leq W</var>

<var>S_{ij}</var> is # or ..

<var>S_{C_h C_w}</var> and <var>S_{D_h D_w}</var> are ..

<var>(C_h,C_w) \neq (D_h,D_w)</var>

Input

Input is given from Standard Input in the following format:

<var>H</var> <var>W</var>
<var>C_h</var> <var>C_w</var>
<var>D_h</var> <var>D_w</var>
<var>S_{11}\ldots S_{1W}</var>
<var>\vdots</var>
<var>S_{H1}\ldots S_{HW}</var>

Output

Print the minimum number of times the magician needs to use the magic. If he cannot reach <var>(D_h,D_w)</var>, print -1 instead.

Sample Input 1

4 4
1 1
4 4
..#.
..#.
.#..
.#..

Sample Output 1

1

For example, by walking to <var>(2,2)</var> and then using the magic to travel to <var>(4,4)</var>, just one use of magic is enough.

Note that he cannot walk diagonally.

Sample Input 2

4 4
1 4
4 1
.##.
####
####
.##.

Sample Output 2

-1

He cannot move from there.

Sample Input 3

4 4
2 2
3 3
....
....
....
....

Sample Output 3

0

No use of magic is needed.

Sample Input 4

4 5
1 2
2 5
#.###
####.
#..##
#..##

Sample Output 4

2


Score : <var>500</var> points

Problem Statement

There are <var>N</var> integers <var>X_1, X_2, \cdots, X_N</var>, and we know that <var>A_i \leq X_i \leq B_i</var>.
Find the number of different values that the median of <var>X_1, X_2, \cdots, X_N</var> can take.

Notes

The median of <var>X_1, X_2, \cdots, X_N</var> is defined as follows. Let <var>x_1, x_2, \cdots, x_N</var> be the result of sorting <var>X_1, X_2, \cdots, X_N</var> in ascending order.

If <var>N</var> is odd, the median is <var>x_{(N+1)/2}</var>;

if <var>N</var> is even, the median is <var>(x_{N/2} + x_{N/2+1}) / 2</var>.

Constraints

<var>2 \leq N \leq 2 \times 10^5</var>

<var>1 \leq A_i \leq B_i \leq 10^9</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>

Output

Print the answer.

Sample Input 1

2
1 2
2 3

Sample Output 1

3

If <var>X_1 = 1</var> and <var>X_2 = 2</var>, the median is <var>\frac{3}{2}</var>;

if <var>X_1 = 1</var> and <var>X_2 = 3</var>, the median is <var>2</var>;

if <var>X_1 = 2</var> and <var>X_2 = 2</var>, the median is <var>2</var>;

if <var>X_1 = 2</var> and <var>X_2 = 3</var>, the median is <var>\frac{5}{2}</var>.

Thus, the median can take three values: <var>\frac{3}{2}</var>, <var>2</var>, and <var>\frac{5}{2}</var>.

Sample Input 2

3
100 100
10 10000
1 1000000000

Sample Output 2

9991


Score : <var>100</var> points

Problem Statement

There is always an integer in Takahashi's mind.

Initially, the integer in Takahashi's mind is <var>0</var>. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by <var>1</var>; when he eats -, the integer in his mind decreases by <var>1</var>.

The symbols Takahashi is going to eat are given to you as a string <var>S</var>. The <var>i</var>-th character in <var>S</var> is the <var>i</var>-th symbol for him to eat.

Find the integer in Takahashi's mind after he eats all the symbols.

Constraints

The length of <var>S</var> is <var>4</var>.

Each character in <var>S</var> is + or -.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the integer in Takahashi's mind after he eats all the symbols.

Sample Input 1

+-++

Sample Output 1

2

Initially, the integer in Takahashi's mind is <var>0</var>.

The first integer for him to eat is +. After eating it, the integer in his mind becomes <var>1</var>.

The second integer to eat is -. After eating it, the integer in his mind becomes <var>0</var>.

The third integer to eat is +. After eating it, the integer in his mind becomes <var>1</var>.

The fourth integer to eat is +. After eating it, the integer in his mind becomes <var>2</var>.

Thus, the integer in Takahashi's mind after he eats all the symbols is <var>2</var>.

Sample Input 2

-+--

Sample Output 2

-2

Sample Input 3

----

Sample Output 3

-4


Score : <var>100</var> points

Problem Statement

You are parking at a parking lot. You can choose from the following two fee plans:

Plan <var>1</var>: The fee will be <var>A×T</var> yen (the currency of Japan) when you park for <var>T</var> hours.

Plan <var>2</var>: The fee will be <var>B</var> yen, regardless of the duration.

Find the minimum fee when you park for <var>N</var> hours.

Constraints

<var>1≤N≤20</var>

<var>1≤A≤100</var>

<var>1≤B≤2000</var>

All input values are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>A</var> <var>B</var>

Output

When the minimum fee is <var>x</var> yen, print the value of <var>x</var>.

Sample Input 1

7 17 120

Sample Output 1

119

If you choose Plan <var>1</var>, the fee will be <var>7×17=119</var> yen.

If you choose Plan <var>2</var>, the fee will be <var>120</var> yen.

Thus, the minimum fee is <var>119</var> yen.

Sample Input 2

5 20 100

Sample Output 2

100

The fee might be the same in the two plans.

Sample Input 3

6 18 100

Sample Output 3

100


Score : <var>100</var> points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has <var>N</var> test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed <var>M</var> cases out of the <var>N</var> test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

<var>1 \leq N \leq 100</var>

<var>0 \leq M \leq N</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


Score : <var>200</var> points

Problem Statement

You are given strings <var>s</var> and <var>t</var>, consisting of lowercase English letters.
You will create a string <var>s'</var> by freely rearranging the characters in <var>s</var>.
You will also create a string <var>t'</var> by freely rearranging the characters in <var>t</var>.
Determine whether it is possible to satisfy <var>s' < t'</var> for the lexicographic order.

Notes

For a string <var>a = a_1 a_2 ... a_N</var> of length <var>N</var> and a string <var>b = b_1 b_2 ... b_M</var> of length <var>M</var>, we say <var>a < b</var> for the lexicographic order if either one of the following two conditions holds true:

<var>N < M</var> and <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_N = b_N</var>.

There exists <var>i</var> (<var>1 \leq i \leq N, M</var>) such that <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_{i - 1} = b_{i - 1}</var> and <var>a_i < b_i</var>. Here, letters are compared using alphabetical order.

For example, xy <var><</var> xya and atcoder <var><</var> atlas.

Constraints

The lengths of <var>s</var> and <var>t</var> are between <var>1</var> and <var>100</var> (inclusive).

<var>s</var> and <var>t</var> consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

<var>s</var>
<var>t</var>

Output

If it is possible to satisfy <var>s' < t'</var>, print Yes; if it is not, print No.

Sample Input 1

yx
axy

Sample Output 1

Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy <var><</var> yxa.

Sample Input 2

ratcode
atlas

Sample Output 2

Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort <var><</var> tslaa.

Sample Input 3

cd
abc

Sample Output 3

No

No matter how we rearrange cd and abc, we cannot achieve our objective.

Sample Input 4

w
ww

Sample Output 4

Yes

Sample Input 5

zzz
zzz

Sample Output 5

No


Score : <var>400</var> points

Problem Statement

Snuke has <var>N</var> strings. The <var>i</var>-th string is <var>s_i</var>.

Let us concatenate these strings into one string after arranging them in some order.
Find the maximum possible number of occurrences of AB in the resulting string.

Constraints

<var>1 \leq N \leq 10^{4}</var>

<var>2 \leq |s_i| \leq 10</var>

<var>s_i</var> consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>s_1</var>
<var>\vdots</var>
<var>s_N</var>

Output

Print the answer.

Sample Input 1

3
ABCA
XBAZ
BAD

Sample Output 1

2

For example, if we concatenate ABCA, BAD and XBAZ in this order, the resulting string ABCABADXBAZ has two occurrences of AB.

Sample Input 2

9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA

Sample Output 2

4

Sample Input 3

7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBHZ
SZMEHMA

Sample Output 3

4


Score : <var>200</var> points

Problem Statement

A sequence <var>a=\{a_1,a_2,a_3,......\}</var> is determined as follows:

The first term <var>s</var> is given as input.

Let <var>f(n)</var> be the following function: <var>f(n) = n/2</var> if <var>n</var> is even, and <var>f(n) = 3n+1</var> if <var>n</var> is odd.

<var>a_i = s</var> when <var>i = 1</var>, and <var>a_i = f(a_{i-1})</var> when <var>i > 1</var>.

Find the minimum integer <var>m</var> that satisfies the following condition:

There exists an integer <var>n</var> such that <var>a_m = a_n (m > n)</var>.

Constraints

<var>1 \leq s \leq 100</var>

All values in input are integers.

It is guaranteed that all elements in <var>a</var> and the minimum <var>m</var> that satisfies the condition are at most <var>1000000</var>.

Input

Input is given from Standard Input in the following format:

<var>s</var>

Output

Print the minimum integer <var>m</var> that satisfies the condition.

Sample Input 1

8

Sample Output 1

5

<var>a=\{8,4,2,1,4,2,1,4,2,1,......\}</var>. As <var>a_5=a_2</var>, the answer is <var>5</var>.

Sample Input 2

7

Sample Output 2

18

<var>a=\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\}</var>.

Sample Input 3

54

Sample Output 3

114


Score : <var>200</var> points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer <var>1</var>.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by <var>K</var>.

Square1001 needs to perform these operations <var>N</var> times in total.
Find the minimum possible value displayed in the board after <var>N</var> operations.

Constraints

<var>1 \leq N, K \leq 10</var>

All input values are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>K</var>

Output

Print the minimum possible value displayed in the board after <var>N</var> operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: <var>1</var> → <var>2</var> → <var>4</var> → <var>7</var> → <var>10</var>.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: <var>1</var> → <var>2</var> → <var>4</var> → <var>8</var> → <var>16</var> → <var>26</var> → <var>36</var> → <var>46</var> → <var>56</var> → <var>66</var> → <var>76</var>.

By the way, this contest is AtCoder Beginner Contest 076.


Score: <var>100</var> points

Problem Statement

We have two distinct integers <var>A</var> and <var>B</var>.

Print the integer <var>K</var> such that <var>|A - K| = |B - K|</var>.

If such an integer does not exist, print IMPOSSIBLE instead.

Constraints

All values in input are integers.

<var>0 \leq A,\ B \leq 10^9</var>

<var>A</var> and <var>B</var> are distinct.

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var>

Output

Print the integer <var>K</var> satisfying the condition.

If such an integer does not exist, print IMPOSSIBLE instead.

Sample Input 1

2 16

Sample Output 1

9

<var>|2 - 9| = 7</var> and <var>|16 - 9| = 7</var>, so <var>9</var> satisfies the condition.

Sample Input 2

0 3

Sample Output 2

IMPOSSIBLE

No integer satisfies the condition.

Sample Input 3

998244353 99824435

Sample Output 3

549034394


Score: <var>100</var> points

Problem Statement

There is a train going from Station <var>A</var> to Station <var>B</var> that costs <var>X</var> yen (the currency of Japan).

Also, there is a bus going from Station <var>B</var> to Station <var>C</var> that costs <var>Y</var> yen.

Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station <var>A</var> to Station <var>B</var> by train and then travels from Station <var>B</var> to Station <var>C</var> by bus.

How much does it cost to travel from Station <var>A</var> to Station <var>C</var> if she uses this ticket?

Constraints

<var>1 \leq X,Y \leq 100</var>

<var>Y</var> is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>X</var> <var>Y</var>

Output

If it costs <var>x</var> yen to travel from Station <var>A</var> to Station <var>C</var>, print <var>x</var>.

Sample Input 1

81 58

Sample Output 1

110

The train fare is <var>81</var> yen.

The train fare is <var>58</var> ⁄ <var>2=29</var> yen with the <var>50</var>% discount.

Thus, it costs <var>110</var> yen to travel from Station <var>A</var> to Station <var>C</var>.

Sample Input 2

4 54

Sample Output 2

31


Score : <var>500</var> points

Problem Statement

We have <var>N</var> integers. The <var>i</var>-th number is <var>A_i</var>.

<var>\{A_i\}</var> is said to be pairwise coprime when <var>GCD(A_i,A_j)=1</var> holds for every pair <var>(i, j)</var> such that <var>1\leq i < j \leq N</var>.

<var>\{A_i\}</var> is said to be setwise coprime when <var>\{A_i\}</var> is not pairwise coprime but <var>GCD(A_1,\ldots,A_N)=1</var>.

Determine if <var>\{A_i\}</var> is pairwise coprime, setwise coprime, or neither.

Here, <var>GCD(\ldots)</var> denotes greatest common divisor.

Constraints

<var>2 \leq N \leq 10^6</var>

<var>1 \leq A_i\leq 10^6</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>\ldots</var> <var>A_N</var>

Output

If <var>\{A_i\}</var> is pairwise coprime, print pairwise coprime; if <var>\{A_i\}</var> is setwise coprime, print setwise coprime; if neither, print not coprime.

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

<var>GCD(3,4)=GCD(3,5)=GCD(4,5)=1</var>, so they are pairwise coprime.

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

Since <var>GCD(6,10)=2</var>, they are not pairwise coprime. However, since <var>GCD(6,10,15)=1</var>, they are setwise coprime.

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

<var>GCD(6,10,16)=2</var>, so they are neither pairwise coprime nor setwise coprime.


Score : <var>100</var> points

Problem Statement

An uppercase or lowercase English letter <var>\alpha</var> will be given as input.
If <var>\alpha</var> is uppercase, print A; if it is lowercase, print a.

Constraints

<var>\alpha</var> is an uppercase (A - Z) or lowercase (a - z) English letter.

Input

Input is given from Standard Input in the following format:

<var>α</var>

Output

If <var>\alpha</var> is uppercase, print A; if it is lowercase, print a.

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


Score : <var>200</var> points

Problem Statement

Given are a positive integer <var>N</var> and a string <var>S</var> of length <var>N</var> consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string <var>T</var> such that <var>S = T + T</var>.

Constraints

<var>1 \leq N \leq 100</var>

<var>S</var> consists of lowercase English letters.

<var>|S| = N</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S</var>

Output

If <var>S</var> is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let <var>T = </var> abc, and <var>S = T + T</var>.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No


Score : <var>100</var> points

Problem Statement

There is a hotel with the following accommodation fee:

<var>X</var> yen (the currency of Japan) per night, for the first <var>K</var> nights

<var>Y</var> yen per night, for the <var>(K+1)</var>-th and subsequent nights

Tak is staying at this hotel for <var>N</var> consecutive nights.
Find his total accommodation fee.

Constraints

<var>1 \leq N, K \leq 10000</var>

<var>1 \leq Y < X \leq 10000</var>

<var>N,\,K,\,X,\,Y</var> are integers.

Input

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

<var>N</var>
<var>K</var>
<var>X</var>
<var>Y</var>

Output

Print Tak's total accommodation fee.

Sample Input 1

5
3
10000
9000

Sample Output 1

48000

The accommodation fee is as follows:

<var>10000</var> yen for the <var>1</var>-st night

<var>10000</var> yen for the <var>2</var>-nd night

<var>10000</var> yen for the <var>3</var>-rd night

<var>9000</var> yen for the <var>4</var>-th night

<var>9000</var> yen for the <var>5</var>-th night

Thus, the total is <var>48000</var> yen.

Sample Input 2

2
3
10000
9000

Sample Output 2

20000


Score: <var>200</var> points

Problem Statement

There are three positive integers <var>A</var>, <var>B</var> and <var>C</var> written on a blackboard. E869120 performs the following operation <var>K</var> times:

Choose one integer written on the blackboard and let the chosen integer be <var>n</var>. Replace the chosen integer with <var>2n</var>.

What is the largest possible sum of the integers written on the blackboard after <var>K</var> operations?

Constraints

<var>A, B</var> and <var>C</var> are integers between <var>1</var> and <var>50</var> (inclusive).

<var>K</var> is an integer between <var>1</var> and <var>10</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>C</var>
<var>K</var>

Output

Print the largest possible sum of the integers written on the blackboard after <var>K</var> operations by E869220.

Sample Input 1

5 3 11
1

Sample Output 1

30

In this sample, <var>5, 3, 11</var> are initially written on the blackboard, and E869120 can perform the operation once.

There are three choices:

Double <var>5</var>: The integers written on the board after the operation are <var>10, 3, 11</var>.

Double <var>3</var>: The integers written on the board after the operation are <var>5, 6, 11</var>.

Double <var>11</var>: The integers written on the board after the operation are <var>5, 3, 22</var>.

If he chooses 3., the sum of the integers written on the board afterwards is <var>5 + 3 + 22 = 30</var>, which is the largest among 1. through 3.

Sample Input 2

3 3 4
2

Sample Output 2

22

E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:

First, double <var>4</var>. The integers written on the board are now <var>3, 3, 8</var>.

Next, double <var>8</var>. The integers written on the board are now <var>3, 3, 16</var>.

Then, the sum of the integers eventually written on the blackboard is <var>3 + 3 + 16 = 22</var>.


Score: <var>200</var> points

Problem Statement

The number <var>105</var> is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between <var>1</var> and <var>N</var> (inclusive)?

Constraints

<var>N</var> is an integer between <var>1</var> and <var>200</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the count.

Sample Input 1

105

Sample Output 1

1

Among the numbers between <var>1</var> and <var>105</var>, the only number that is odd and has exactly eight divisors is <var>105</var>.

Sample Input 2

7

Sample Output 2

0

<var>1</var> has one divisor. <var>3</var>, <var>5</var> and <var>7</var> are all prime and have two divisors. Thus, there is no number that satisfies the condition.


Score : <var>200</var> points

Problem Statement

You are given two integers <var>K</var> and <var>S</var>.

Three variable <var>X, Y</var> and <var>Z</var> takes integer values satisfying <var>0≤X,Y,Z≤K</var>.

How many different assignments of values to <var>X, Y</var> and <var>Z</var> are there such that <var>X + Y + Z = S</var>?

Constraints

<var>2≤K≤2500</var>

<var>0≤S≤3K</var>

<var>K</var> and <var>S</var> are integers.

Input

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

<var>K</var> <var>S</var>

Output

Print the number of the triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition:

<var>X = 0, Y = 0, Z = 2</var>

<var>X = 0, Y = 2, Z = 0</var>

<var>X = 2, Y = 0, Z = 0</var>

<var>X = 0, Y = 1, Z = 1</var>

<var>X = 1, Y = 0, Z = 1</var>

<var>X = 1, Y = 1, Z = 0</var>

Sample Input 2

5 15

Sample Output 2

1

The maximum value of <var>X + Y + Z</var> is <var>15</var>, achieved by one triple of <var>X, Y</var> and <var>Z</var>.


Score : <var>200</var> points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

You are given an even string <var>S</var> consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of <var>S</var>.
It is guaranteed that such a non-empty string exists for a given input.

Constraints

<var>2 \leq |S| \leq 200</var>

<var>S</var> is an even string consisting of lowercase English letters.

There exists a non-empty even string that can be obtained by deleting one or more characters from the end of <var>S</var>.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the length of the longest even string that can be obtained.

Sample Input 1

abaababaab

Sample Output 1

6

abaababaab itself is even, but we need to delete at least one character.

abaababaa is not even.

abaababa is not even.

abaabab is not even.

abaaba is even. Thus, we should print its length, <var>6</var>.

Sample Input 2

xxxx

Sample Output 2

2

xxx is not even.

xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

The longest even string that can be obtained is abcabc, whose length is <var>6</var>.

Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

The longest even string that can be obtained is akasakaakasaka, whose length is <var>14</var>.


Score : <var>300</var> points

Problem Statement

We have <var>N</var> switches with "on" and "off" state, and <var>M</var> bulbs. The switches are numbered <var>1</var> to <var>N</var>, and the bulbs are numbered <var>1</var> to <var>M</var>.

Bulb <var>i</var> is connected to <var>k_i</var> switches: Switch <var>s_{i1}</var>, <var>s_{i2}</var>, <var>...</var>, and <var>s_{ik_i}</var>. It is lighted when the number of switches that are "on" among these switches is congruent to <var>p_i</var> modulo <var>2</var>.

How many combinations of "on" and "off" states of the switches light all the bulbs?

Constraints

<var>1 \leq N, M \leq 10</var>

<var>1 \leq k_i \leq N</var>

<var>1 \leq s_{ij} \leq N</var>

<var>s_{ia} \neq s_{ib} (a \neq b)</var>

<var>p_i</var> is <var>0</var> or <var>1</var>.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>
<var>k_1</var> <var>s_{11}</var> <var>s_{12}</var> <var>...</var> <var>s_{1k_1}</var>
<var>:</var>
<var>k_M</var> <var>s_{M1}</var> <var>s_{M2}</var> <var>...</var> <var>s_{Mk_M}</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_M</var>

Output

Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

Sample Input 1

2 2
2 1 2
1 2
0 1

Sample Output 1

1

Bulb <var>1</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var> and <var>2</var>.

Bulb <var>2</var> is lighted when there is an odd number of switches that are "on" among the following: Switch <var>2</var>.

There are four possible combinations of states of (Switch <var>1</var>, Switch <var>2</var>): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print <var>1</var>.

Sample Input 2

2 3
2 1 2
1 1
1 2
0 0 1

Sample Output 2

0

Bulb <var>1</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var> and <var>2</var>.

Bulb <var>2</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var>.

Bulb <var>3</var> is lighted when there is an odd number of switches that are "on" among the following: Switch <var>2</var>.

Switch <var>1</var> has to be "off" to light Bulb <var>2</var> and Switch <var>2</var> has to be "on" to light Bulb <var>3</var>, but then Bulb <var>1</var> will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print <var>0</var>.

Sample Input 3

5 2
3 1 2 5
2 2 3
1 0

Sample Output 3

8


Score : <var>100</var> points

Problem Statement

Given an integer <var>N</var> not less than <var>3</var>, find the sum of the interior angles of a regular polygon with <var>N</var> sides.

Print the answer in degrees, but do not print units.

Constraints

<var>3 \leq N \leq 100</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print an integer representing the sum of the interior angles of a regular polygon with <var>N</var> sides.

Sample Input 1

3

Sample Output 1

180

The sum of the interior angles of a regular triangle is <var>180</var> degrees.

Sample Input 2

100

Sample Output 2

17640


Score : <var>100</var> points

Problem Statement

In programming, hexadecimal notation is often used.

In hexadecimal notation, besides the ten digits <var>0, 1, ..., 9</var>, the six letters A, B, C, D, E and F are used to represent the values <var>10, 11, 12, 13, 14</var> and <var>15</var>, respectively.

In this problem, you are given two letters <var>X</var> and <var>Y</var>. Each <var>X</var> and <var>Y</var> is A, B, C, D, E or F.

When <var>X</var> and <var>Y</var> are seen as hexadecimal numbers, which is larger?

Constraints

Each <var>X</var> and <var>Y</var> is A, B, C, D, E or F.

Input

Input is given from Standard Input in the following format:

<var>X</var> <var>Y</var>

Output

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

Sample Input 1

A B

Sample Output 1

<

<var>10 < 11</var>.

Sample Input 2

E C

Sample Output 2

>

<var>14 > 12</var>.

Sample Input 3

F F

Sample Output 3

=

<var>15 = 15</var>.


Score : <var>400</var> points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is <var>H</var>.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is <var>1</var>, it drops to <var>0</var>.

If the monster's health, <var>X</var>, is greater than <var>1</var>, that monster disappears. Then, two new monsters appear, each with the health of <var>\lfloor X/2 \rfloor</var>.

(<var>\lfloor r \rfloor</var> denotes the greatest integer not exceeding <var>r</var>.)

Caracal wins when the healths of all existing monsters become <var>0</var> or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

<var>1 \leq H \leq 10^{12}</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>H</var>

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of <var>1</var>.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775


Score: <var>100</var> points

Problem Statement

We held two competitions: Coding Contest and Robot Maneuver.

In each competition, the contestants taking the <var>3</var>-rd, <var>2</var>-nd, and <var>1</var>-st places receive <var>100000</var>, <var>200000</var>, and <var>300000</var> yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional <var>400000</var> yen.

DISCO-Kun took the <var>X</var>-th place in Coding Contest and the <var>Y</var>-th place in Robot Maneuver.
Find the total amount of money he earned.

Constraints

<var>1 \leq X \leq 205</var>

<var>1 \leq Y \leq 205</var>

<var>X</var> and <var>Y</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>X</var> <var>Y</var>

Output

Print the amount of money DISCO-Kun earned, as an integer.

Sample Input 1

1 1

Sample Output 1

1000000

In this case, he earned <var>300000</var> yen in Coding Contest and another <var>300000</var> yen in Robot Maneuver. Furthermore, as he won both competitions, he got an additional <var>400000</var> yen.
In total, he made <var>300000 + 300000 + 400000 = 1000000</var> yen.

Sample Input 2

3 101

Sample Output 2

100000

In this case, he earned <var>100000</var> yen in Coding Contest.

Sample Input 3

4 4

Sample Output 3

0

In this case, unfortunately, he was the highest-ranked contestant without prize money in both competitions.


Score : <var>100</var> points

Problem Statement

Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.

In this country, 24-hour clock is used. For example, <var>9:00</var> p.m. is referred to as "<var>21</var> o'clock".

The current time is <var>A</var> o'clock, and a contest will begin in exactly <var>B</var> hours.
When will the contest begin? Answer in 24-hour time.

Constraints

<var>0 \leq A,B \leq 23</var>

<var>A</var> and <var>B</var> are integers.

Input

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

<var>A</var> <var>B</var>

Output

Print the hour of the starting time of the contest in 24-hour time.

Sample Input 1

9 12

Sample Output 1

21

In this input, the current time is <var>9</var> o'clock, and <var>12</var> hours later it will be <var>21</var> o'clock in 24-hour time.

Sample Input 2

19 0

Sample Output 2

19

The contest has just started.

Sample Input 3

23 2

Sample Output 3

1

The contest will begin at <var>1</var> o'clock the next day.


Score : <var>100</var> points

Problem Statement

Snuke has a grid consisting of three squares numbered <var>1</var>, <var>2</var> and <var>3</var>.
In each square, either 0 or 1 is written. The number written in Square <var>i</var> is <var>s_i</var>.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of <var>s_1</var>, <var>s_2</var> and <var>s_3</var> is either 1 or 0.

Input

Input is given from Standard Input in the following format:

<var>s_{1}s_{2}s_{3}</var>

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square <var>1</var> and <var>3</var>.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


Score : <var>200</var> points

Problem Statement

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

Constraints

<var>1</var> <var>≤</var> <var>a,b</var> <var>≤</var> <var>100</var>

<var>a</var> and <var>b</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>a</var> <var>b</var>

Output

If the concatenation of <var>a</var> and <var>b</var> in this order is a square number, print Yes; otherwise, print No.

Sample Input 1

1 21

Sample Output 1

Yes

As <var>121</var> <var>=</var> <var>11</var> × <var>11</var>, it is a square number.

Sample Input 2

100 100

Sample Output 2

No

<var>100100</var> is not a square number.

Sample Input 3

12 10

Sample Output 3

No


Score : <var>600</var> points

Problem Statement

Given are a sequence of <var>N</var> positive integers <var>A_1</var>, <var>A_2</var>, <var>\ldots</var>, <var>A_N</var> and another positive integer <var>S</var>.

For a non-empty subset <var>T</var> of the set <var>\{1, 2, \ldots , N \}</var>, let us define <var>f(T)</var> as follows:

<var>f(T)</var> is the number of different non-empty subsets <var>\{x_1, x_2, \ldots , x_k \}</var> of <var>T</var> such that <var>A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S</var>.

Find the sum of <var>f(T)</var> over all <var>2^N-1</var> subsets <var>T</var> of <var>\{1, 2, \ldots , N \}</var>. Since the sum can be enormous, print it modulo <var>998244353</var>.

Constraints

All values in input are integers.

<var>1 \leq N \leq 3000</var>

<var>1 \leq S \leq 3000</var>

<var>1 \leq A_i \leq 3000</var>

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>S</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>

Output

Print the sum of <var>f(T)</var> modulo <var>998244353</var>.

Sample Input 1

3 4
2 2 4

Sample Output 1

6

For each <var>T</var>, the value of <var>f(T)</var> is shown below. The sum of these values is <var>6</var>.

<var>f(\{1\}) = 0</var>

<var>f(\{2\}) = 0</var>

<var>f(\{3\}) = 1</var> (One subset <var>\{3\}</var> satisfies the condition.)

<var>f(\{1, 2\}) = 1</var> (<var>\{1, 2\}</var>)

<var>f(\{2, 3\}) = 1</var> (<var>\{3\}</var>)

<var>f(\{1, 3\}) = 1</var> (<var>\{3\}</var>)

<var>f(\{1, 2, 3\}) = 2</var> (<var>\{1, 2\}, \{3\}</var>)

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

10 10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

3296


Score : <var>100</var> points

Problem Statement

It is September <var>9</var> in Japan now.

You are given a two-digit integer <var>N</var>. Answer the question: Is <var>9</var> contained in the decimal notation of <var>N</var>?

Constraints

<var>10≤N≤99</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

If <var>9</var> is contained in the decimal notation of <var>N</var>, print Yes; if not, print No.

Sample Input 1

29

Sample Output 1

Yes

The one's digit of <var>29</var> is <var>9</var>.

Sample Input 2

72

Sample Output 2

No

<var>72</var> does not contain <var>9</var>.

Sample Input 3

91

Sample Output 3

Yes


Score : <var>100</var> points

Problem Statement

You are given positive integers <var>X</var> and <var>Y</var>.
If there exists a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, choose one such integer and print it.
If it does not exist, print <var>-1</var>.

Constraints

<var>1 ≤ X,Y ≤ 10^9</var>

<var>X</var> and <var>Y</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>X</var> <var>Y</var>

Output

Print a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, or print <var>-1</var> if it does not exist.

Sample Input 1

8 6

Sample Output 1

16

For example, <var>16</var> is a multiple of <var>8</var> but not a multiple of <var>6</var>.

Sample Input 2

3 3

Sample Output 2

-1

A multiple of <var>3</var> is a multiple of <var>3</var>.


Score : <var>200</var> points

Problem Statement

Print all the integers that satisfies the following in ascending order:

Among the integers between <var>A</var> and <var>B</var> (inclusive), it is either within the <var>K</var> smallest integers or within the <var>K</var> largest integers.

Constraints

<var>1 \leq A \leq B \leq 10^9</var>

<var>1 \leq K \leq 100</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>K</var>

Output

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

Sample Input 1

3 8 2

Sample Output 1

3
4
7
8

<var>3</var> is the first smallest integer among the integers between <var>3</var> and <var>8</var>.

<var>4</var> is the second smallest integer among the integers between <var>3</var> and <var>8</var>.

<var>7</var> is the second largest integer among the integers between <var>3</var> and <var>8</var>.

<var>8</var> is the first largest integer among the integers between <var>3</var> and <var>8</var>.

Sample Input 2

4 8 3

Sample Output 2

4
5
6
7
8

Sample Input 3

2 9 100

Sample Output 3

2
3
4
5
6
7
8
9


Score : <var>100</var> points

Problem Statement

The door of Snuke's laboratory is locked with a security code.

The security code is a <var>4</var>-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.

You are given the current security code <var>S</var>. If <var>S</var> is hard to enter, print Bad; otherwise, print Good.

Constraints

<var>S</var> is a <var>4</var>-character string consisting of digits.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

If <var>S</var> is hard to enter, print Bad; otherwise, print Good.

Sample Input 1

3776

Sample Output 1

Bad

The second and third digits are the same, so <var>3776</var> is hard to enter.

Sample Input 2

8080

Sample Output 2

Good

There are no two consecutive digits that are the same, so <var>8080</var> is not hard to enter.

Sample Input 3

1333

Sample Output 3

Bad

Sample Input 4

0024

Sample Output 4

Bad


Score : <var>400</var> points

Problem Statement

An altar enshrines <var>N</var> stones arranged in a row from left to right. The color of the <var>i</var>-th stone from the left <var>(1 \leq i \leq N)</var> is given to you as a character <var>c_i</var>; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

<var>2 \leq N \leq 200000</var>

<var>c_i</var> is R or W.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>c_{1}c_{2}...c_{N}</var>

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the <var>1</var>-st and <var>3</var>-rd stones from the left, resulting in RWWR.

Change the color of the <var>4</var>-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3


Score: <var>400</var> points

Problem Statement

The Kingdom of Takahashi has <var>N</var> towns, numbered <var>1</var> through <var>N</var>.

There is one teleporter in each town. The teleporter in Town <var>i</var> <var>(1 \leq i \leq N)</var> sends you to Town <var>A_i</var>.

Takahashi, the king, loves the positive integer <var>K</var>. The selfish king wonders what town he will be in if he starts at Town <var>1</var> and uses a teleporter exactly <var>K</var> times from there.

Help the king by writing a program that answers this question.

Constraints

<var>2 \leq N \leq 2 \times 10^5</var>

<var>1 \leq A_i \leq N</var>

<var>1 \leq K \leq 10^{18}</var>

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>K</var>
<var>A_1</var> <var>A_2</var> <var>\dots</var> <var>A_N</var>

Output

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

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

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

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)

Beginner's Guide

Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Problem Statement

You will be given a contest schedule for <var>D</var> days.
For each <var>d=1,2,\ldots,D</var>, calculate the satisfaction at the end of day <var>d</var>.

Input

Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.

<var>D</var>
<var>c_1</var> <var>c_2</var> <var>\cdots</var> <var>c_{26}</var>
<var>s_{1,1}</var> <var>s_{1,2}</var> <var>\cdots</var> <var>s_{1,26}</var>
<var>\vdots</var>
<var>s_{D,1}</var> <var>s_{D,2}</var> <var>\cdots</var> <var>s_{D,26}</var>
<var>t_1</var>
<var>t_2</var>
<var>\vdots</var>
<var>t_D</var>

The constraints and generation methods for the input part are the same as those for Problem A.

For each <var>d</var>, <var>t_d</var> is an integer satisfying <var>1\leq t_d \leq 26</var>, and your program is expected to work correctly for any value that meets the constraints.

Output

Let <var>v_d</var> be the satisfaction at the end of day <var>d</var>.
Print <var>D</var> integers <var>v_d</var> to Standard Output in the following format:

<var>v_1</var>
<var>v_2</var>
<var>\vdots</var>
<var>v_D</var>

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13

Sample Output 1

18398
35037
51140
65837
79325

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint <var>D=365</var> and is never actually given as a test case.

Next Step

We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each <var>d=1,2,\ldots,D</var>, we select the contest type that maximizes the satisfaction at the end of day <var>d</var>. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!

Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.


Score : <var>300</var> points

Problem Statement

Snuke has <var>N</var> dogs and <var>M</var> monkeys. He wants them to line up in a row.

As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.

How many such arrangements there are? Find the count modulo <var>10^9+7</var> (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Constraints

<var>1 ≤ N,M ≤ 10^5</var>

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>

Output

Print the number of possible arrangements, modulo <var>10^9+7</var>.

Sample Input 1

2 2

Sample Output 1

8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

Sample Input 2

3 2

Sample Output 2

12

Sample Input 3

1 8

Sample Output 3

0

Sample Input 4

100000 100000

Sample Output 4

530123477


Score: <var>100</var> points

Problem Statement

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

Given is a string <var>S</var> representing the weather in the town today. Predict the weather tomorrow.

Constraints

<var>S</var> is Sunny, Cloudy, or Rainy.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

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

Sample Input 1

Sunny

Sample Output 1

Cloudy

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

Sample Input 2

Rainy

Sample Output 2

Sunny


Score : <var>200</var> points

Problem Statement

It's now the season of TAKOYAKI FESTIVAL!

This year, <var>N</var> takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the <var>i</var>-th takoyaki is <var>d_i</var>.

As is commonly known, when you eat two takoyaki of deliciousness <var>x</var> and <var>y</var> together, you restore <var>x \times y</var> health points.

There are <var>\frac{N \times (N - 1)}{2}</var> ways to choose two from the <var>N</var> takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these <var>\frac{N \times (N - 1)}{2}</var> values.

Constraints

All values in input are integers.

<var>2 \leq N \leq 50</var>

<var>0 \leq d_i \leq 100</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>d_1</var> <var>d_2</var> <var>...</var> <var>d_N</var>

Output

Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the <var>N</var> takoyaki served.

Sample Input 1

3
3 1 2

Sample Output 1

11

There are three possible choices:

Eat the first and second takoyaki. You will restore <var>3</var> health points.

Eat the second and third takoyaki. You will restore <var>2</var> health points.

Eat the first and third takoyaki. You will restore <var>6</var> health points.

The sum of these values is <var>11</var>.

Sample Input 2

7
5 0 7 8 3 3 2

Sample Output 2

312


Score : <var>300</var> points

Problem Statement

"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 <var>A</var> yen, <var>B</var> yen and <var>C</var> yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare <var>X</var> A-pizzas and <var>Y</var> 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

<var>1 ≤ A, B, C ≤ 5000</var>

<var>1 ≤ X, Y ≤ 10^5</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>C</var> <var>X</var> <var>Y</var>

Output

Print the minimum amount of money required to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas.

Sample Input 1

1500 2000 1600 3 2

Sample Output 1

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.

Sample Input 2

1500 2000 1900 3 2

Sample Output 2

8500

It is optimal to directly buy three A-pizzas and two B-pizzas.

Sample Input 3

1500 2000 500 90000 100000

Sample Output 3

100000000

It is optimal to buy <var>200000</var> AB-pizzas and rearrange them into <var>100000</var> A-pizzas and <var>100000</var> B-pizzas. We will have <var>10000</var> more A-pizzas than necessary, but that is fine.


Score : <var>100</var> points

Problem Statement

You are given two integers <var>a</var> and <var>b</var>.
Determine if <var>a+b=15</var> or <var>a\times b=15</var> or neither holds.

Note that <var>a+b=15</var> and <var>a\times b=15</var> do not hold at the same time.

Constraints

<var>1 \leq a,b \leq 15</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>a</var> <var>b</var>

Output

If <var>a+b=15</var>, print +;
if <var>a\times b=15</var>, print *;
if neither holds, print x.

Sample Input 1

4 11

Sample Output 1

+

<var>4+11=15</var>.

Sample Input 2

3 5

Sample Output 2

*

<var>3\times 5=15</var>.

Sample Input 3

1 1

Sample Output 3

x

<var>1+1=2</var> and <var>1\times 1=1</var>, neither of which is <var>15</var>.


Score: <var>100</var> points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers <var>A</var>, <var>B</var>, and <var>C</var>. If this triple is poor, print Yes; otherwise, print No.

Constraints

<var>A</var>, <var>B</var>, and <var>C</var> are all integers between <var>1</var> and <var>9</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>C</var>

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

<var>A</var> and <var>C</var> are equal, but <var>B</var> is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

<var>A</var>, <var>B</var>, and <var>C</var> are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


Score: <var>300</var> points

Problem Statement

AtCoder Mart sells <var>1000000</var> of each of the six items below:

Riceballs, priced at <var>100</var> yen (the currency of Japan) each

Sandwiches, priced at <var>101</var> yen each

Cookies, priced at <var>102</var> yen each

Cakes, priced at <var>103</var> yen each

Candies, priced at <var>104</var> yen each

Computers, priced at <var>105</var> yen each

Takahashi wants to buy some of them that cost exactly <var>X</var> yen in total.
Determine whether this is possible.

(Ignore consumption tax.)

Constraints

<var>1 \leq X \leq 100000</var>

<var>X</var> is an integer.

Input

Input is given from Standard Input in the following format:

<var>X</var>

Output

If it is possible to buy some set of items that cost exactly <var>X</var> yen in total, print 1; otherwise, print 0.

Sample Input 1

615

Sample Output 1

1

For example, we can buy one of each kind of item, which will cost <var>100+101+102+103+104+105=615</var> yen in total.

Sample Input 2

217

Sample Output 2

0

No set of items costs <var>217</var> yen in total.


Score : <var>100</var> points

Problem Statement

Find the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive). The order does not matter.

Constraints

<var>2\leq K\leq 100</var>

<var>K</var> is an integer.

Input

Input is given from Standard Input in the following format:

<var>K</var>

Output

Print the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive).

Sample Input 1

3

Sample Output 1

2

Two pairs can be chosen: <var>(2,1)</var> and <var>(2,3)</var>.

Sample Input 2

6

Sample Output 2

9

Sample Input 3

11

Sample Output 3

30

Sample Input 4

50

Sample Output 4

625


Score : <var>200</var> points

Problem Statement

Given is a sequence of <var>N</var> integers <var>A_1, \ldots, A_N</var>.

Find the (multiplicative) inverse of the sum of the inverses of these numbers, <var>\frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}</var>.

Constraints

<var>1 \leq N \leq 100</var>

<var>1 \leq A_i \leq 1000</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>A_2</var> <var>\ldots</var> <var>A_N</var>

Output

Print a decimal number (or an integer) representing the value of <var>\frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}</var>.

Your output will be judged correct when its absolute or relative error from the judge's output is at most <var>10^{-5}</var>.

Sample Input 1

2
10 30

Sample Output 1

7.5

<var>\frac{1}{\frac{1}{10} + \frac{1}{30}} = \frac{1}{\frac{4}{30}} = \frac{30}{4} = 7.5</var>.

Printing 7.50001, 7.49999, and so on will also be accepted.

Sample Input 2

3
200 200 200

Sample Output 2

66.66666666666667

<var>\frac{1}{\frac{1}{200} + \frac{1}{200} + \frac{1}{200}} = \frac{1}{\frac{3}{200}} = \frac{200}{3} = 66.6666...</var>.

Printing 6.66666e+1 and so on will also be accepted.

Sample Input 3

1
1000

Sample Output 3

1000

<var>\frac{1}{\frac{1}{1000}} = 1000</var>.

Printing +1000.0 and so on will also be accepted.


Score: <var>100</var> points

Problem Statement

E869120 has <var>A</var> <var>1</var>-yen coins and infinitely many <var>500</var>-yen coins.

Determine if he can pay exactly <var>N</var> yen using only these coins.

Constraints

<var>N</var> is an integer between <var>1</var> and <var>10000</var> (inclusive).

<var>A</var> is an integer between <var>0</var> and <var>1000</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A</var>

Output

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

Sample Input 1

2018
218

Sample Output 1

Yes

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

Sample Input 2

2763
0

Sample Output 2

No

When we have no <var>1</var>-yen coins, we can only pay a multiple of <var>500</var> yen using only <var>500</var>-yen coins. Since <var>2763</var> is not a multiple of <var>500</var>, we cannot pay this amount.

Sample Input 3

37
514

Sample Output 3

Yes


Score : <var>500</var> points

Problem Statement

There are <var>K</var> items placed on a grid of squares with <var>R</var> rows and <var>C</var> columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row (<var>1 \leq i \leq R</var>) and the <var>j</var>-th column (<var>1 \leq j \leq C</var>). The <var>i</var>-th item is at <var>(r_i, c_i)</var> and has the value <var>v_i</var>.

Takahashi will begin at <var>(1, 1)</var>, the start, and get to <var>(R, C)</var>, the goal. When he is at <var>(i, j)</var>, he can move to <var>(i + 1, j)</var> or <var>(i, j + 1)</var> (but cannot move to a non-existent square).

He can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.

Find the maximum possible sum of the values of items he picks up.

Constraints

<var>1 \leq R, C \leq 3000</var>

<var>1 \leq K \leq \min(2 \times 10^5, R \times C)</var>

<var>1 \leq r_i \leq R</var>

<var>1 \leq c_i \leq C</var>

<var>(r_i, c_i) \neq (r_j, c_j) (i \neq j)</var>

<var>1 \leq v_i \leq 10^9</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>R</var> <var>C</var> <var>K</var>
<var>r_1</var> <var>c_1</var> <var>v_1</var>
<var>r_2</var> <var>c_2</var> <var>v_2</var>
<var>:</var>
<var>r_K</var> <var>c_K</var> <var>v_K</var>

Output

Print the maximum possible sum of the values of items Takahashi picks up.

Sample Input 1

2 2 3
1 1 3
2 1 4
1 2 5

Sample Output 1

8

He has two ways to get to the goal:

Visit <var>(1, 1)</var>, <var>(1, 2)</var>, and <var>(2, 2)</var>, in this order. In this case, the total value of the items he can pick up is <var>3 + 5 = 8</var>.

Visit <var>(1, 1)</var>, <var>(2, 1)</var>, and <var>(2, 2)</var>, in this order. In this case, the total value of the items he can pick up is <var>3 + 4 = 7</var>.

Thus, the maximum possible sum of the values of items he picks up is <var>8</var>.

Sample Input 2

2 5 5
1 1 3
2 4 20
1 2 1
1 3 4
1 4 2

Sample Output 2

29

We have four items in the <var>1</var>-st row. The optimal choices are as follows:

Visit <var>(1, 1)</var> <var>(1, 2)</var>, <var>(1, 3)</var>, <var>(1, 4)</var>, <var>(2, 4)</var>, and <var>(2, 5)</var>, in this order, and pick up all items except the one on <var>(1, 2)</var>. Then, the total value of the items he picks up will be <var>3 + 4 + 2 + 20 = 29</var>.

Sample Input 3

4 5 10
2 5 12
1 5 12
2 3 15
1 2 20
1 1 28
2 4 26
3 2 27
4 5 21
3 5 10
1 3 10

Sample Output 3

142


Score : <var>400</var> points

Problem Statement

There are <var>N</var> empty boxes arranged in a row from left to right.
The integer <var>i</var> is written on the <var>i</var>-th box from the left <var>(1 \leq i \leq N)</var>.

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive), the total number of balls contained in the boxes with multiples of <var>i</var> written on them is congruent to <var>a_i</var> modulo <var>2</var>.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

<var>1 \leq N \leq 2 \times 10^5</var>

<var>a_i</var> is <var>0</var> or <var>1</var>.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

<var>M</var>
<var>b_1</var> <var>b_2</var> <var>...</var> <var>b_M</var>

where <var>M</var> denotes the number of boxes that will contain a ball, and <var>b_1,\ b_2,\ ...,\ b_M</var> are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with <var>1</var> written on it.

There are three boxes with multiples of <var>1</var> written on them: the boxes with <var>1</var>, <var>2</var>, and <var>3</var>. The total number of balls contained in these boxes is <var>1</var>.

There is only one box with a multiple of <var>2</var> written on it: the box with <var>2</var>. The total number of balls contained in these boxes is <var>0</var>.

There is only one box with a multiple of <var>3</var> written on it: the box with <var>3</var>. The total number of balls contained in these boxes is <var>0</var>.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.


Score : <var>100</var> points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are <var>a</var>, <var>b</var> and <var>c</var> 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, <var>b-a = c-b</var>.

Determine whether the arrangement of the poles is beautiful.

Constraints

<var>1 \leq a,b,c \leq 100</var>

<var>a</var>, <var>b</var> and <var>c</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>a</var> <var>b</var> <var>c</var>

Output

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

Sample Input 1

2 4 6

Sample Output 1

YES

Since <var>4-2 = 6-4</var>, this arrangement of poles is beautiful.

Sample Input 2

2 5 6

Sample Output 2

NO

Since <var>5-2 \neq 6-5</var>, this arrangement of poles is not beautiful.

Sample Input 3

3 2 1

Sample Output 3

YES

Since <var>1-2 = 2-3</var>, this arrangement of poles is beautiful.


Score : <var>300</var> points

Problem Statement

Snuke can change a string <var>t</var> of length <var>N</var> into a string <var>t'</var> of length <var>N - 1</var> under the following rule:

For each <var>i</var> (<var>1 ≤ i ≤ N - 1</var>), the <var>i</var>-th character of <var>t'</var> must be either the <var>i</var>-th or <var>(i + 1)</var>-th character of <var>t</var>.

There is a string <var>s</var> consisting of lowercase English letters.
Snuke's objective is to apply the above operation to <var>s</var> repeatedly so that all the characters in <var>s</var> are the same.
Find the minimum necessary number of operations.

Constraints

<var>1 ≤ |s| ≤ 100</var>

<var>s</var> consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

<var>s</var>

Output

Print the minimum necessary number of operations to achieve the objective.

Sample Input 1

serval

Sample Output 1

3

One solution is: serval → srvvl → svvv → vvv.

Sample Input 2

jackal

Sample Output 2

2

One solution is: jackal → aacaa → aaaa.

Sample Input 3

zzz

Sample Output 3

0

All the characters in <var>s</var> are the same from the beginning.

Sample Input 4

whbrjpjyhsrywlqjxdbrbaomnw

Sample Output 4

8

In <var>8</var> operations, he can change <var>s</var> to rrrrrrrrrrrrrrrrrr.


Score : <var>100</var> points

Problem Statement

You are given three integers <var>A, B</var> and <var>C</var>.

Determine if there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</var>.

Constraints

All values in input are integers.

<var>1 \leq A,B,C \leq 100</var>

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>C</var>

Output

If there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</var>, print Yes; otherwise, print No.

Sample Input 1

2 2 2

Sample Output 1

Yes

There exists an equilateral triangle whose sides have lengths <var>2, 2</var> and <var>2</var>.

Sample Input 2

3 4 5

Sample Output 2

No

There is no equilateral triangle whose sides have lengths <var>3, 4</var> and <var>5</var>.


Score : <var>300</var> points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had <var>N</var> problems.

Takahashi made <var>M</var> submissions during the contest.

The <var>i</var>-th submission was made for the <var>p_i</var>-th problem and received the verdict <var>S_i</var> (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

<var>N</var>, <var>M</var>, and <var>p_i</var> are integers.

<var>1 \leq N \leq 10^5</var>

<var>0 \leq M \leq 10^5</var>

<var>1 \leq p_i \leq N</var>

<var>S_i</var> is AC or WA.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>
<var>p_1</var> <var>S_1</var>
<var>:</var>
<var>p_M</var> <var>S_M</var>

Output

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

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

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.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


Score : <var>100</var> points

Problem Statement

You are given positive integers <var>A</var> and <var>B</var>.

If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.

Constraints

All values in input are integers.

<var>1 \leq A \leq B \leq 20</var>

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var>

Output

If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.

Sample Input 1

4 12

Sample Output 1

16

As <var>4</var> is a divisor of <var>12</var>, <var>4 + 12 = 16</var> should be printed.

Sample Input 2

8 20

Sample Output 2

12

Sample Input 3

1 1

Sample Output 3

2

<var>1</var> is a divisor of <var>1</var>.


Score : <var>400</var> points

Problem Statement

There are <var>N</var> mountains in a circle, called Mountain <var>1</var>, Mountain <var>2</var>, <var>...</var>, Mountain <var>N</var> in clockwise order. <var>N</var> is an odd number.

Between these mountains, there are <var>N</var> dams, called Dam <var>1</var>, Dam <var>2</var>, <var>...</var>, Dam <var>N</var>. Dam <var>i</var> (<var>1 \leq i \leq N</var>) is located between Mountain <var>i</var> and <var>i+1</var> (Mountain <var>N+1</var> is Mountain <var>1</var>).

When Mountain <var>i</var> (<var>1 \leq i \leq N</var>) receives <var>2x</var> liters of rain, Dam <var>i-1</var> and Dam <var>i</var> each accumulates <var>x</var> liters of water (Dam <var>0</var> is Dam <var>N</var>).

One day, each of the mountains received a non-negative even number of liters of rain.

As a result, Dam <var>i</var> (<var>1 \leq i \leq N</var>) accumulated a total of <var>A_i</var> liters of water.

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Constraints

All values in input are integers.

<var>3 \leq N \leq 10^5-1</var>

<var>N</var> is an odd number.

<var>0 \leq A_i \leq 10^9</var>

The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>

Output

Print <var>N</var> integers representing the number of liters of rain Mountain <var>1</var>, Mountain <var>2</var>, <var>...</var>, Mountain <var>N</var> received, in this order.

Sample Input 1

3
2 2 4

Sample Output 1

4 0 4

If we assume Mountain <var>1</var>, <var>2</var>, and <var>3</var> received <var>4</var>, <var>0</var>, and <var>4</var> liters of rain, respectively, it is consistent with this input, as follows:

Dam <var>1</var> should have accumulated <var>\frac{4}{2} + \frac{0}{2} = 2</var> liters of water.

Dam <var>2</var> should have accumulated <var>\frac{0}{2} + \frac{4}{2} = 2</var> liters of water.

Dam <var>3</var> should have accumulated <var>\frac{4}{2} + \frac{4}{2} = 4</var> liters of water.

Sample Input 2

5
3 8 7 5 5

Sample Output 2

2 4 12 2 8

Sample Input 3

3
1000000000 1000000000 0

Sample Output 3

0 2000000000 0


Score : <var>200</var> points

Problem Statement

You are given a string <var>S</var> of length <var>N</var>.
Among its subsequences, count the ones such that all characters are different, modulo <var>10^9+7</var>. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.

Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.

Constraints

<var>1 \leq N \leq 100000</var>

<var>S</var> consists of lowercase English letters.

<var>|S|=N</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S</var>

Output

Print the number of the subsequences such that all characters are different, modulo <var>10^9+7</var>.

Sample Input 1

4
abcd

Sample Output 1

15

Since all characters in <var>S</var> itself are different, all its subsequences satisfy the condition.

Sample Input 2

3
baa

Sample Output 2

5

The answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.

Sample Input 3

5
abcab

Sample Output 3

17


Score : <var>100</var> points

Problem Statement

Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are <var>a</var>, <var>b</var> and <var>c</var> (in meters), respectively.
Two people can directly communicate when the distance between them is at most <var>d</var> meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

Constraints

<var>1</var> <var>≤</var> <var>a,b,c</var> <var>≤</var> <var>100</var>

<var>1</var> <var>≤</var> <var>d</var> <var>≤</var> <var>100</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>a</var> <var>b</var> <var>c</var> <var>d</var>

Output

If A and C can communicate, print Yes; if they cannot, print No.

Sample Input 1

4 7 9 3

Sample Output 1

Yes

A and B can directly communicate, and also B and C can directly communicate, so we should print Yes.

Sample Input 2

100 10 1 2

Sample Output 2

No

They cannot communicate in this case.

Sample Input 3

10 10 10 1

Sample Output 3

Yes

There can be multiple people at the same position.

Sample Input 4

1 100 2 10

Sample Output 4

Yes


Score : <var>300</var> points

Problem Statement

Snuke has a fair <var>N</var>-sided die that shows the integers from <var>1</var> to <var>N</var> with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between <var>1</var> and <var>K-1</var> (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes <var>0</var> if the coin lands tails up.

The game ends when the score becomes <var>0</var> or becomes <var>K</var> or above. Snuke wins if the score is <var>K</var> or above, and loses if the score is <var>0</var>.

You are given <var>N</var> and <var>K</var>. Find the probability that Snuke wins the game.

Constraints

<var>1 ≤ N ≤ 10^5</var>

<var>1 ≤ K ≤ 10^5</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>K</var>

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most <var>10^{-9}</var>.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows <var>1</var>, Snuke needs to get four consecutive heads from four coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}</var>.

If the die shows <var>2</var>, Snuke needs to get three consecutive heads from three coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}</var>.

If the die shows <var>3</var>, Snuke needs to get two consecutive heads from two coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}</var>.

Thus, the probability that Snuke wins is <var>\frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333</var>.

Sample Input 2

100000 5

Sample Output 2

0.999973749998