A - Five Integers

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。

制約

  • 0 \leq A, B, C, D, E \leq 100
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

A B C D E

出力

答えを出力せよ。


入力例 1

31 9 24 31 24

出力例 1

3

与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。


入力例 2

0 0 0 0 0

出力例 2

1

Score : 100 points

Problem Statement

Print how many distinct integers there are in given five integers A, B, C, D, and E.

Constraints

  • 0 \leq A, B, C, D, E \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D E

Output

Print the answer.


Sample Input 1

31 9 24 31 24

Sample Output 1

3

In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.


Sample Input 2

0 0 0 0 0

Sample Output 2

1
B - Spoiler

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

英小文字と | のみからなる文字列 S が与えられます。S| をちょうど 2 個含むことが保証されます。

2 つの | の間にある文字および |S から削除した文字列を出力してください。

制約

  • S は英小文字および | のみからなる長さ 2 以上 100 以下の文字列
  • S| をちょうど 2 個含む

入力

入力は以下の形式で標準入力から与えられる。

S

出力

答えを出力せよ。


入力例 1

atcoder|beginner|contest

出力例 1

atcodercontest

2 つの | に挟まれた文字を全て削除して出力してください。


入力例 2

|spoiler|

出力例 2



全ての文字が削除されることもあります。


入力例 3

||xyz

出力例 3

xyz

Score: 150 points

Problem Statement

You are given a string S consisting of lowercase English letters and |. S is guaranteed to contain exactly two |s.

Remove the characters between the two |s, including the |s themselves, and print the resulting string.

Constraints

  • S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and |.
  • S contains exactly two |s.

Input

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

S

Output

Print the answer.


Sample Input 1

atcoder|beginner|contest

Sample Output 1

atcodercontest

Remove all the characters between the two |s and print the result.


Sample Input 2

|spoiler|

Sample Output 2



It is possible that all characters are removed.


Sample Input 3

||xyz

Sample Output 3

xyz
C - Piano 3

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は、横一列に並んだ 100 個の鍵盤からなるピアノを持っています。 このピアノの左から i 個目の鍵盤のことを鍵盤 i と呼びます。

高橋君は今から N 回にわたってこのピアノの鍵盤を一つずつ押すことでとある曲を演奏します。 i 回目に押す鍵盤は鍵盤 A_i であり、それを押す手は S_i= L のとき左手、S_i= R のとき右手です。

演奏を始める前、高橋君は両手をそれぞれ好きな鍵盤の上に置くことができ、この時点での疲労度0 です。 演奏中、片方の手を鍵盤 x の上から鍵盤 y の上へと動かすと疲労度が |y-x| 増加します(逆に、手の移動以外で疲労度が増加することはありません)。 なお、ある手である鍵盤を押すためには、その手がその鍵盤の上に置かれている必要があります。

演奏が終了した時点での疲労度は最小でいくつになるか求めてください。

制約

  • 1\leq N \leq 100
  • 1\leq A_i \leq 100
  • N,A_i は整数
  • S_iL または R

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 S_1
A_2 S_2
\vdots
A_N S_N

出力

演奏が終了した時点での疲労度の最小値を出力せよ。


入力例 1

4
3 L
6 R
9 L
1 R

出力例 1

11

例えば以下のように演奏することができます。

  • 最初、左手を鍵盤 3 の上に、右手を鍵盤 6 の上に置いておく。
  • 左手で鍵盤 3 を押す。
  • 右手で鍵盤 6 を押す。
  • 左手を鍵盤 3 の上から鍵盤 9 の上へと動かす。疲労度が |9-3|=6 増加する。
  • 右手を鍵盤 6 の上から鍵盤 1 の上へと動かす。疲労度が |1-6|=5 増加する。
  • 左手で鍵盤 9 を押す。
  • 右手で鍵盤 1 を押す。

このとき、演奏が終了した時点での疲労度は 6+5=11 であり、これが最小です。


入力例 2

3
2 L
2 L
100 L

出力例 2

98

入力例 3

8
22 L
75 L
26 R
45 R
72 R
81 R
47 L
29 R

出力例 3

188

Score : 200 points

Problem Statement

Takahashi has a piano with 100 keys arranged in a row. The i-th key from the left is called key i.

He will play music by pressing N keys one by one. For the i-th press, he will press key A_i, using his left hand if S_i= L, and his right hand if S_i= R.

Before starting to play, he can place both of his hands on any keys he likes, and his fatigue level at this point is 0. During the performance, if he moves one hand from key x to key y, the fatigue level increases by |y-x| (conversely, the fatigue level does not increase for any reason other than moving hands). To press a certain key with a hand, that hand must be placed on that key.

Find the minimum possible fatigue level at the end of the performance.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • N and A_i are integers.
  • S_i is L or R.

Input

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

N
A_1 S_1
A_2 S_2
\vdots
A_N S_N

Output

Print the minimum fatigue level at the end of the performance.


Sample Input 1

4
3 L
6 R
9 L
1 R

Sample Output 1

11

For example, the performance can be done as follows:

  • Initially, place the left hand on key 3 and the right hand on key 6.
  • Press key 3 with the left hand.
  • Press key 6 with the right hand.
  • Move the left hand from key 3 to key 9. The fatigue level increases by |9-3| = 6.
  • Move the right hand from key 6 to key 1. The fatigue level increases by |1-6| = 5.
  • Press key 9 with the left hand.
  • Press key 1 with the right hand.

In this case, the fatigue level at the end of the performance is 6+5 = 11, which is the minimum possible.


Sample Input 2

3
2 L
2 L
100 L

Sample Output 2

98

Sample Input 3

8
22 L
75 L
26 R
45 R
72 R
81 R
47 L
29 R

Sample Output 3

188
D - Mex

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。

A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。

制約

  • 1 \leq N \leq 2000
  • 0 \leq A_i \leq 2000
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

8
0 3 2 6 2 1 0 0

出力例 1

4

非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3A に含まれ、4A に含まれないので、答えは 4 です。


入力例 2

3
2000 2000 2000

出力例 2

0

Score : 200 points

Problem Statement

You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).

Find the smallest non-negative integer not in (A_1,\ldots,A_N).

Constraints

  • 1 \leq N \leq 2000
  • 0 \leq A_i \leq 2000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

8
0 3 2 6 2 1 0 0

Sample Output 1

4

The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.


Sample Input 2

3
2000 2000 2000

Sample Output 2

0
E - Balls and Bag Query

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

空の袋があります。 クエリが Q 個与えられるので、順番に処理してください。

クエリは次の 3 種類です。

  • 1 x : 整数 x が書かれたボールを 1 つ袋に入れる。
  • 2 x : 整数 x が書かれたボールを 1 つ袋の中から取り出して外に捨てる。このクエリが与えられるとき、袋の中に整数 x が書かれたボールが存在することが保証される。
  • 3 : 袋の中にあるボールに書かれている整数の種類数を出力する。

制約

  • 1 \leq Q \leq 2 \times 10^{5}
  • 1 \leq x \leq 10^{6}
  • 2 種類目のクエリが与えられるとき、袋の中に整数 x が書かれたボールが存在する。
  • 3 種類目のクエリが 1 つ以上存在する。
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

i 番目のクエリ \text{query}_i は以下の 3 つの形式のいずれかで与えられる。

1 x
2 x
3

出力

3 種類目のクエリが K 個あるとき、K 行出力せよ。 i 行目(1 \leq i \leq K) では、i 番目の 3 種類目のクエリに対する答えを出力せよ。


入力例 1

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

出力例 1

3
2
3

はじめ、袋の中は空です。

1 番目のクエリ 1 3 で袋の中に 3 が書かれたボールが 1 つ入ります。

2 番目のクエリ 1 1 で袋の中に 1 が書かれたボールが 1 つ入ります。

3 番目のクエリ 1 4 で袋の中に 4 が書かれたボールが 1 つ入ります。

4 番目のクエリ 3 で袋の中に 1, 3, 43 種類のボールが入っているため、3 を出力します。

5 番目のクエリ 2 1 で袋の中から 1 が書かれたボールを 1 つ取り出します。

6 番目のクエリ 3 で袋の中に 3, 42 種類のボールが入っているため、2 を出力します。

7 番目のクエリ 1 5 で袋の中に 5 が書かれたボールが 1 つ入ります。

8 番目のクエリ 3 で袋の中に 3, 4, 53 種類のボールが入っているため、3 を出力します。


入力例 2

8
1 2
1 2
3
2 2
1 4
1 4
2 2
3

出力例 2

1
1

Score : 300 points

Problem Statement

You have an empty bag. You are given Q queries, which must be processed in order.

There are three types of queries.

  • 1 x : Put one ball with the integer x written on it into the bag.
  • 2 x : Remove one ball with the integer x written on it from the bag and discard it. It is guaranteed that the bag has a ball with the integer x written on it when this query is given.
  • 3 : Print the number of different integers written on the balls in the bag.

Constraints

  • 1 \leq Q \leq 2 \times 10^{5}
  • 1 \leq x \leq 10^{6}
  • When a query of the second type is given, the bag has a ball with the integer x written on it.
  • There is at least one query of the third type.
  • All input values are integers.

Input

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

Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

The i-th query \text{query}_i is given in one of the following three formats:

1 x
2 x
3

Output

If there are K queries of the third type, print K lines. The i-th line (1 \leq i \leq K) should contain the answer to the i-th query of the third type.


Sample Input 1

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

Sample Output 1

3
2
3

Initially, the bag is empty.

For the first query 1 3, a ball with the integer 3 written on it enters the bag.

For the second query 1 1, a ball with the integer 1 written on it enters the bag.

For the third query 1 4, a ball with the integer 4 written on it enters the bag.

For the fourth query 3, the bag has balls with the integers 1, 3, 4, so print 3.

For the fifth query 2 1, a ball with the integer 1 written on it is removed from the bag.

For the sixth query 3, the bag has balls with the integers 3, 4, so print 2.

For the seventh query 1 5, a ball with the integer 5 written on it enters the bag.

For the eighth query 3, the bag has balls with the integers 3, 4, 5, so print 3.


Sample Input 2

8
1 2
1 2
3
2 2
1 4
1 4
2 2
3

Sample Output 2

1
1
F - K Swap

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

長さ N の数列 A=(a_1,\ldots,a_N) があります。また、整数 K が与えられます。

あなたは次の操作を 0 回以上何度でも行えます。

  • 1 \leq i \leq N-K を満たす整数 i を選び、a_ia_{i+K} の値を入れ替える。

A を昇順に並べ替えることが出来るかどうかを判定してください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N-1
  • 1 \leq a_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N K
a_1 \ldots a_N

出力

A を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。


入力例 1

5 2
3 4 1 3 4

出力例 1

Yes

次のように操作をすることで A を昇順に並び替えることが出来ます。

  • i=1 とし、a_1a_3 の値を入れ替える。数列は (1,4,3,3,4) となる。
  • i=2 とし、a_2a_4 の値を入れ替える。数列は (1,3,3,4,4) となる。

入力例 2

5 3
3 4 1 3 4

出力例 2

No

入力例 3

7 5
1 2 3 4 5 5 10

出力例 3

Yes

操作を行う必要が無い場合もあります。

Score : 300 points

Problem Statement

We have a sequence of length N: A=(a_1,\ldots,a_N). Additionally, you are given an integer K.

You can perform the following operation zero or more times.

  • Choose an integer i such that 1 \leq i \leq N-K, then swap the values of a_i and a_{i+K}.

Determine whether it is possible to sort A in ascending order.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N-1
  • 1 \leq a_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 \ldots a_N

Output

If it is possible to sort A in ascending order, print Yes; otherwise, print No.


Sample Input 1

5 2
3 4 1 3 4

Sample Output 1

Yes

The following sequence of operations sorts A in ascending order.

  • Choose i=1 to swap the values of a_1 and a_3. A is now (1,4,3,3,4).
  • Choose i=2 to swap the values of a_2 and a_4. A is now (1,3,3,4,4).

Sample Input 2

5 3
3 4 1 3 4

Sample Output 2

No

Sample Input 3

7 5
1 2 3 4 5 5 10

Sample Output 3

Yes

No operations may be needed.

G - Between Two Arrays

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ n の数列 S = (s_1, s_2, \dots, s_n) がすべての i (1 \leq i \leq n - 1) に対して s_i \leq s_{i+1} を満たすとき、かつそのときに限り「数列 S は広義単調増加である」と呼びます。

広義単調増加な長さ N の整数列 A = (a_1, a_2, \dots, a_N), B = (b_1, b_2, \dots, b_N) が与えられます。
このとき、次の条件を満たす広義単調増加な長さ N の整数列 C = (c_1, c_2, \dots, c_N) を考えます。

  • すべての i (1 \leq i \leq N) に対して a_i \leq c_i \leq b_i が成り立つ。

整数列 C としてあり得る数列の個数を 998244353 で割ったあまりを求めてください。

制約

  • 1 \leq N \leq 3000
  • 0 \leq a_i \leq b_i \leq 3000 (1 \leq i \leq N)
  • 整数列 A,B は広義単調増加である。
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N
a_1 a_2 \dots a_N
b_1 b_2 \dots b_N

出力

C としてあり得る数列の個数を 998244353 で割ったあまりを出力せよ。


入力例 1

2
1 1
2 3

出力例 1

5

C としてあり得る数列は次の 5 個です。

  • (1, 1)
  • (1, 2)
  • (1, 3)
  • (2, 2)
  • (2, 3)

数列 (2, 1) は広義単調増加でないため条件を満たさないことに注意してください。


入力例 2

3
2 2 2
2 2 2

出力例 2

1

C としてあり得る数列は次の 1 個です。

  • (2, 2, 2)

入力例 3

10
1 2 3 4 5 6 7 8 9 10
1 4 9 16 25 36 49 64 81 100

出力例 3

978222082

個数を 998244353 で割ったあまりを求めることに注意してください。

Score : 400 points

Problem Statement

A sequence of n numbers, S = (s_1, s_2, \dots, s_n), is said to be non-decreasing if and only if s_i \leq s_{i+1} holds for every i (1 \leq i \leq n - 1).

Given are non-decreasing sequences of N integers each: A = (a_1, a_2, \dots, a_N) and B = (b_1, b_2, \dots, b_N).
Consider a non-decreasing sequence of N integers, C = (c_1, c_2, \dots, c_N), that satisfies the following condition:

  • a_i \leq c_i \leq b_i for every i (1 \leq i \leq N).

Find the number, modulo 998244353, of sequences that can be C.

Constraints

  • 1 \leq N \leq 3000
  • 0 \leq a_i \leq b_i \leq 3000 (1 \leq i \leq N)
  • The sequences A and B are non-decreasing.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \dots a_N
b_1 b_2 \dots b_N

Output

Print the number, modulo 998244353, of sequences that can be C.


Sample Input 1

2
1 1
2 3

Sample Output 1

5

There are five sequences that can be C, as follows.

  • (1, 1)
  • (1, 2)
  • (1, 3)
  • (2, 2)
  • (2, 3)

Note that (2, 1) does not satisfy the condition since it is not non-decreasing.


Sample Input 2

3
2 2 2
2 2 2

Sample Output 2

1

There is one sequence that can be C, as follows.

  • (2, 2, 2)

Sample Input 3

10
1 2 3 4 5 6 7 8 9 10
1 4 9 16 25 36 49 64 81 100

Sample Output 3

978222082

Be sure to find the count modulo 998244353.

H - Art Gallery on Graph

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 475

問題文

頂点に 1 から N の、辺に 1 から M の番号がついた N 頂点 M 辺の単純無向グラフがあります。辺 i は頂点 a_i と頂点 b_i を結んでいます。
1 から K までの番号がついた K 人の警備員が頂点上にいます。警備員 i は頂点 p_i にいて、体力は h_i です。ここで全ての p_i は互いに異なります。

頂点 v が次の条件を満たす時、頂点 v警備されている頂点 と呼びます。

  • 頂点 v と頂点 p_i の距離が h_i 以下であるような警備員 i が少なくとも 1 人存在する。

ここで、頂点 u と頂点 v の距離とは、頂点 u と頂点 v を結ぶパスに含まれる辺の本数の最小値のことをいいます。

グラフに含まれる頂点のうち、警備されている頂点を 小さい方から順に 全て列挙してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min \left(\frac{N(N-1)}{2}, 2 \times 10^5 \right)
  • 1 \leq K \leq N
  • 1 \leq a_i, b_i \leq N
  • 入力で与えられるグラフは単純
  • 1 \leq p_i \leq N
  • p_i は互いに異なる
  • 1 \leq h_i \leq N
  • 入力で与えられる値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N M K
a_1 b_1
a_2 b_2
\vdots
a_M b_M
p_1 h_1
p_2 h_2
\vdots
p_K h_K

出力

答えを以下の形式で出力せよ。ここで、

  • 警備されている頂点の個数を G
  • 警備されている頂点の頂点番号を 昇順に 並べたものを v_1, v_2, \dots, v_G

と定義する。

G
v_1 v_2 \dots v_G

入力例 1

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

出力例 1

4
1 2 3 5

警備されている頂点は 1, 2, 3, 54 頂点です。
これらの頂点が警備されている頂点である理由は以下の通りです。

  • 頂点 1 と頂点 p_1 = 1 の距離は 0 で、これは h_1 = 1 以下です。よって頂点 1 は警備されている頂点です。
  • 頂点 2 と頂点 p_1 = 1 の距離は 1 で、これは h_1 = 1 以下です。よって頂点 2 は警備されている頂点です。
  • 頂点 3 と頂点 p_2 = 5 の距離は 1 で、これは h_2 = 2 以下です。よって頂点 3 は警備されている頂点です。
  • 頂点 5 と頂点 p_1 = 1 の距離は 1 で、これは h_1 = 1 以下です。よって頂点 5 は警備されている頂点です。

入力例 2

3 0 1
2 3

出力例 2

1
2

入力で与えられるグラフに辺がない場合もあります。


入力例 3

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

出力例 3

7
1 2 3 5 6 8 9

Score : 475 points

Problem Statement

There is a simple undirected graph with N vertices and M edges, where vertices are numbered from 1 to N, and edges are numbered from 1 to M. Edge i connects vertex a_i and vertex b_i.
K security guards numbered from 1 to K are on some vertices. Guard i is on vertex p_i and has a stamina of h_i. All p_i are distinct.

A vertex v is said to be guarded when the following condition is satisfied:

  • there is at least one guard i such that the distance between vertex v and vertex p_i is at most h_i.

Here, the distance between vertex u and vertex v is the minimum number of edges in the path connecting vertices u and v.

List all guarded vertices in ascending order.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min \left(\frac{N(N-1)}{2}, 2 \times 10^5 \right)
  • 1 \leq K \leq N
  • 1 \leq a_i, b_i \leq N
  • The given graph is simple.
  • 1 \leq p_i \leq N
  • All p_i are distinct.
  • 1 \leq h_i \leq N
  • All input values are integers.

Input

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

N M K
a_1 b_1
a_2 b_2
\vdots
a_M b_M
p_1 h_1
p_2 h_2
\vdots
p_K h_K

Output

Print the answer in the following format. Here,

  • G is the number of guarded vertices,
  • and v_1, v_2, \dots, v_G are the vertex numbers of the guarded vertices in ascending order.
G
v_1 v_2 \dots v_G

Sample Input 1

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

Sample Output 1

4
1 2 3 5

The guarded vertices are 1, 2, 3, 5.
These vertices are guarded because of the following reasons.

  • The distance between vertex 1 and vertex p_1 = 1 is 0, which is not greater than h_1 = 1. Thus, vertex 1 is guarded.
  • The distance between vertex 2 and vertex p_1 = 1 is 1, which is not greater than h_1 = 1. Thus, vertex 2 is guarded.
  • The distance between vertex 3 and vertex p_2 = 5 is 1, which is not greater than h_2 = 2. Thus, vertex 3 is guarded.
  • The distance between vertex 5 and vertex p_1 = 1 is 1, which is not greater than h_1 = 1. Thus, vertex 5 is guarded.

Sample Input 2

3 0 1
2 3

Sample Output 2

1
2

The given graph may have no edges.


Sample Input 3

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

Sample Output 3

7
1 2 3 5 6 8 9
I - Substrings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

文字列 S が与えられます。高橋君はこの文字列から以下の手順にしたがって新しい文字列 T を作ります。

  • まず、S の文字のうちの一つ以上に印をつける。ただし、印をつけた文字どうしが隣り合ってはならない。
  • 次に、印がついていない文字を全て削除する。
  • 最後に、残った文字列を T とする。ただし、この時に文字を並び替えてはならない。

T としてありうる文字列は何種類ありますか? (10^9 + 7) で割ったあまりを求めてください。

制約

  • S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列

入力

入力は以下の形式で標準入力から与えられる。

S

出力

T としてありうる文字列の種類数を (10^9 + 7) で割ったあまりを出力せよ。


入力例 1

abc

出力例 1

4

T としてありうるものは abcac4 つです。

S1 文字目のみに印をつけたとき Ta

S2 文字目のみに印をつけたとき Tb

S3 文字目のみに印をつけたとき Tc

S1 文字目と 3 文字目のみに印をつけたとき Tac

となります。例えば 1 文字目と 2 文字目の両方に印をつけることはできないことに注意してください。


入力例 2

aa

出力例 2

1

T としてありうるものは a のみです。 印をつけた位置が異なっていても T が同じ文字列となる可能性があることに注意してください。


入力例 3

acba

出力例 3

6

T としてありうるものは abcaaabca6 つです。


入力例 4

chokudai

出力例 4

54

Score : 500 points

Problem Statement

Given is a string S. From this string, Takahashi will make a new string T as follows.

  • First, mark one or more characters in S. Here, no two marked characters should be adjacent.
  • Next, delete all unmarked characters.
  • Finally, let T be the remaining string. Here, it is forbidden to change the order of the characters.

How many strings are there that can be obtained as T? Find the count modulo (10^9 + 7).

Constraints

  • S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of different strings that can be obtained as T, modulo (10^9 + 7).


Sample Input 1

abc

Sample Output 1

4

There are four strings that can be obtained as T: a, b, c, and ac.

Marking the first character of S yields a;

marking the second character of S yields b;

marking the third character of S yields c;

marking the first and third characters of S yields ac.

Note that it is forbidden to, for example, mark both the first and second characters.


Sample Input 2

aa

Sample Output 2

1

There is just one string that can be obtained as T, which is a. Note that marking different positions may result in the same string.


Sample Input 3

acba

Sample Output 3

6

There are six strings that can be obtained as T: a, b, c, aa, ab, and ca.


Sample Input 4

chokudai

Sample Output 4

54