Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
水圧は水深のみに依存し、水深 x [m] の場所では \dfrac{x}{100} [MPa] になるものとします。
水深 D [m] の場所の水圧は何 [MPa] ですか?
制約
- 1 \leq D \leq 10000
- D は整数である。
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。想定解答との絶対誤差または相対誤差が 10^{-3} 以下であれば正解として扱われる。
入力例 1
1000
出力例 1
10
水深 1000 [m] の場所の水圧は 10 [MPa] です。10.0
や 9.999999
などを出力しても正解となります。
入力例 2
50
出力例 2
0.5
入力例 3
3141
出力例 3
31.41
Score : 100 points
Problem Statement
Let us assume that water pressure depends only on depth and is \dfrac{x}{100} megapascal at a depth of x meters.
What is the water pressure in megapascals at a depth of D meters?
Constraints
- 1 \leq D \leq 10000
- D is an integer.
Input
Input is given from Standard Input in the following format:
D
Output
Print the answer. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-3}.
Sample Input 1
1000
Sample Output 1
10
The water pressure at a depth of 1000 meters is 10 megapascal. Outputs such as 10.0
and 9.999999
would also be accepted.
Sample Input 2
50
Sample Output 2
0.5
Sample Input 3
3141
Sample Output 3
31.41
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 人が一列に並んでいます。列の状態は長さ N の文字列 S で与えられ、前から i 番目の人は S の i 文字目が M
のとき男性、F
のとき女性です。
男女が交互に並んでいるかどうか判定してください。
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在しないとき、かつ、そのときに限り、男女が交互に並んでいるといいます。
制約
- 1 \leq N \leq 100
- N は整数である
- S は
M
およびF
のみからなる長さ N の文字列である
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
男女が交互に並んでいるとき Yes
、そうでないとき No
と出力せよ。
入力例 1
6 MFMFMF
出力例 1
Yes
男性同士が隣り合う箇所も女性同士が隣り合う箇所も存在せず、男女が交互に並んでいます。
入力例 2
9 FMFMMFMFM
出力例 2
No
入力例 3
1 F
出力例 3
Yes
Score : 100 points
Problem Statement
There is a row of N people. They are described by a string S of length N. The i-th person from the front is male if the i-th character of S is M
, and female if it is F
.
Determine whether the men and women are alternating.
It is said that the men and women are alternating if and only if there is no position where two men or two women are adjacent.
Constraints
- 1 \leq N \leq 100
- N is an integer.
- S is a string of length N consisting of
M
andF
.
Input
The input is given from Standard Input in the following format:
N S
Output
Print Yes
if the men and women are alternating, and No
otherwise.
Sample Input 1
6 MFMFMF
Sample Output 1
Yes
There is no position where two men or two women are adjacent, so the men and women are alternating.
Sample Input 2
9 FMFMMFMFM
Sample Output 2
No
Sample Input 3
1 F
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
H 行 W 列の行列 A が与えられます。
A の上から i 行目、左から j 列目の要素は A_{i,j} です。
ここで、W 行 H 列の行列 B を、上から i 行目、左から j 列目の要素が A_{j,i} と一致するような行列として定めます。
すなわち、B は A の転置行列です。
B を出力してください。
制約
- 1\leq H,W \leq 10^5
- H \times W \leq 10^5
- 1 \leq A_{i,j} \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
H W A_{1,1} A_{1,2} \ldots A_{1,W} A_{2,1} A_{2,2} \ldots A_{2,W} \vdots A_{H,1} A_{H,2} \ldots A_{H,W}
出力
B を以下の形式で出力せよ。
B_{1,1} B_{1,2} \ldots B_{1,H} B_{2,1} B_{2,2} \ldots B_{2,H} \vdots B_{W,1} B_{W,2} \ldots B_{W,H}
入力例 1
4 3 1 2 3 4 5 6 7 8 9 10 11 12
出力例 1
1 4 7 10 2 5 8 11 3 6 9 12
たとえば A_{2,1}=4 なので、転置行列 B の上から 1 行目、左から 2 列目の要素は 4 になります。
入力例 2
2 2 1000000000 1000000000 1000000000 1000000000
出力例 2
1000000000 1000000000 1000000000 1000000000
Score : 200 points
Problem Statement
You are given an H-by-W matrix A.
The element at the i-th row from the top and j-th column from the left of A is A_{i,j}.
Let B be a W-by-H matrix whose element at the i-th row from the top and j-th column from the left equals A_{j, i}.
That is, B is the transpose of A.
Print B.
Constraints
- 1\leq H,W \leq 10^5
- H \times W \leq 10^5
- 1 \leq A_{i,j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
H W A_{1,1} A_{1,2} \ldots A_{1,W} A_{2,1} A_{2,2} \ldots A_{2,W} \vdots A_{H,1} A_{H,2} \ldots A_{H,W}
Output
Print B in the following format:
B_{1,1} B_{1,2} \ldots B_{1,H} B_{2,1} B_{2,2} \ldots B_{2,H} \vdots B_{W,1} B_{W,2} \ldots B_{W,H}
Sample Input 1
4 3 1 2 3 4 5 6 7 8 9 10 11 12
Sample Output 1
1 4 7 10 2 5 8 11 3 6 9 12
For example, we have A_{2,1}=4, so the element at the 1-st row from the top and 2-nd column from the left of the transpose B is 4.
Sample Input 2
2 2 1000000000 1000000000 1000000000 1000000000
Sample Output 2
1000000000 1000000000 1000000000 1000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
ボウリングのピンは 1 から 10 の番号が付けられており、上から見ると下図のように配置されます。
この図の二つの点線に挟まれた部分を列と呼ぶことにします。
例えば、ピン 1, 5 とピン 3, 9 はそれぞれ同じ列に存在します。
いくつかのピンが倒れた状態のうち、特殊なものはスプリットと呼ばれます。
ピンの配置がスプリットであるとは、以下の条件が全て成り立つことを言います。
- ピン 1 が倒れている。
- ある二つの異なる列であって、次の条件を満たすものが存在する。
- それぞれの列には、立っているピンが 1 本以上存在する。
- それらの列の間に、ピンが全て倒れている列が存在する。
具体例は入出力例を参考にしてください。
さて、あるピンの配置が長さ 10 の文字列 S として与えられます。
i = 1, \dots, 10 について、ピン i が倒れているとき S の i 文字目は 0
であり、ピン i が立っているとき S の i 文字目は 1
です。
S で表されるピンの配置がスプリットかどうか判定してください。
制約
- S は
0
と1
からなる長さ 10 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S で表されるピンの配置がスプリットなら Yes
を、そうでないなら No
を出力せよ。
入力例 1
0101110101
出力例 1
Yes
倒れているピンを灰色で、立っているピンを白色で示すと下図のようになります。
ピン 5 が立っている列とピン 6 が立っている列の間にはピン 3, 9 が置かれている列が存在しますが、ピン 3, 9 はいずれも倒れているので、この配置はスプリットです。
入力例 2
0100101001
出力例 2
Yes
入力例 3
0000100110
出力例 3
No
この配置はスプリットではありません。
入力例 4
1101110101
出力例 4
No
ピン 1 が倒れていないので、スプリットではありません。
Score : 200 points
Problem Statement
Bowling pins are numbered 1 through 10. The following figure is a top view of the arrangement of the pins:
Let us call each part between two dotted lines in the figure a column.
For example, Pins 1 and 5 belong to the same column, and so do Pin 3 and 9.
When some of the pins are knocked down, a special situation called split may occur.
A placement of the pins is a split if both of the following conditions are satisfied:
- Pin 1 is knocked down.
- There are two different columns that satisfy both of the following conditions:
- Each of the columns has one or more standing pins.
- There exists a column between these columns such that all pins in the column are knocked down.
See also Sample Inputs and Outputs for examples.
Now, you are given a placement of the pins as a string S of length 10.
For i = 1, \dots, 10, the i-th character of S is 0
if Pin i is knocked down, and is 1
if it is standing.
Determine if the placement of the pins represented by S is a split.
Constraints
- S is a string of length 10 consisting of
0
and1
.
Input
Input is given from Standard Input in the following format:
S
Output
If the placement of the pins represented by S is a split, print Yes
; otherwise, print No
.
Sample Input 1
0101110101
Sample Output 1
Yes
In the figure below, the knocked-down pins are painted gray, and the standing pins are painted white:
Between the column containing a standing pin 5 and the column containing a standing pin 6 is a column containing Pins 3 and 9. Since Pins 3 and 9 are both knocked down, the placement is a split.
Sample Input 2
0100101001
Sample Output 2
Yes
Sample Input 3
0000100110
Sample Output 3
No
This placement is not a split.
Sample Input 4
1101110101
Sample Output 4
No
This is not a split because Pin 1 is not knocked down.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
あなたはアメーバの観察記録をつけました。
最初 1 匹のアメーバがおり、番号は 1 です。
観察記録は時系列順に N 個あり、i 番目の観察記録は「番号 A_i のアメーバが分裂して消滅し、新たに 2 匹のアメーバが生まれ、それらにそれぞれ 2i,2i+1 と番号をつけた」というものです。
このとき、アメーバ A_i を アメーバ 2i,2i+1 の親と呼びます。
各 k=1,\ldots,2N+1 について、アメーバ k から何代親を遡るとアメーバ 1 になるか求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 観察記録は矛盾していない。すなわち
- 1\leq A_i \leq 2i-1
- A_i は相異なる整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
2N+1 行出力せよ。k 行目にはアメーバ k から何代親を遡るとアメーバ 1 になるかを出力せよ。
入力例 1
2 1 2
出力例 1
0 1 1 2 2
アメーバ 1 からアメーバ 2,3 が生まれ、アメーバ 2 からアメーバ 4,5 が生まれました。
- アメーバ 1 は 0 代遡るとアメーバ 1 になります。
- アメーバ 2 は 1 代遡るとアメーバ 1 になります。
- アメーバ 3 は 1 代遡るとアメーバ 1 になります。
- アメーバ 4 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
- アメーバ 5 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
入力例 2
4 1 3 5 2
出力例 2
0 1 1 2 2 3 3 2 2
Score : 300 points
Problem Statement
You observed amoebae and kept some records.
Initially, there was one amoeba, numbered 1.
You made N records. According to the i-th record, the amoeba numbered A_i disappeared by dividing itself into two new amoebae, which were then numbered 2i and 2i+1.
Here, amoeba A_i is said to be the parent of amoebae 2i and 2i+1.
For each k=1,\ldots,2N+1, how many generations away is amoeba k from amoeba 1?
Constraints
- 1 \leq N \leq 2\times 10^5
- The records are consistent. That is:
- 1\leq A_i \leq 2i-1.
- A_i are distinct integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print 2N+1 lines. The k-th line should contain the generation distance between amoeba 1 and amoeba k.
Sample Input 1
2 1 2
Sample Output 1
0 1 1 2 2
From amoeba 1, amoebae 2 and 3 were born. From amoeba 2, amoebae 4 and 5 were born.
- Amoeba 1 is zero generations away from amoeba 1.
- Amoeba 2 is one generation away from amoeba 1.
- Amoeba 3 is one generation away from amoeba 1.
- Amoeba 4 is one generation away from amoeba 2, and two generations away from amoeba 1.
- Amoeba 5 is one generation away from amoeba 2, and two generations away from amoeba 1.
Sample Input 2
4 1 3 5 2
Sample Output 2
0 1 1 2 2 3 3 2 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の商品があります。i = 1, 2, \ldots, N について、i 番目の商品の値段は A_i 円です。
高橋君は K 枚のクーポンを持っています。
1 枚のクーポンは 1 つの商品に対して使用することができ、1 つの商品に対してはクーポンを何枚でも( 0 枚でもよい)使用することができます。
値段が a 円の商品に対して k 枚のクーポンを使用すると、その商品を \max\lbrace a - kX, 0\rbrace 円で買うことができます。
高橋君がすべての商品を買うために支払う合計金額の最小値を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K, X \leq 10^9
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K X A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
5 4 7 8 3 10 5 13
出力例 1
12
1 番目の商品に対してクーポン 1 枚、3 番目の商品に対してクーポン 1 枚、5 番目の商品に対してクーポン 2 枚を使用すると、
- 1 番目の商品を \max\lbrace A_1-X, 0 \rbrace = 1 円で買うことができ、
- 2 番目の商品を \max\lbrace A_2, 0 \rbrace = 3 円で買うことができ、
- 3 番目の商品を \max\lbrace A_3-X, 0 \rbrace = 3 円で買うことができ、
- 4 番目の商品を \max\lbrace A_4, 0 \rbrace = 5 円で買うことができ、
- 5 番目の商品を \max\lbrace A_5-2X, 0 \rbrace = 0 円で買うことができます。
よって、すべての商品を 1 + 3 + 3 + 5 + 0 = 12 円で買うことができ、これが最小です。
入力例 2
5 100 7 8 3 10 5 13
出力例 2
0
入力例 3
20 815 60 2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202
出力例 3
112
Score : 300 points
Problem Statement
There are N items in a shop. For each i = 1, 2, \ldots, N, the price of the i-th item is A_i yen (the currency of Japan).
Takahashi has K coupons.
Each coupon can be used on one item. You can use any number of coupons, possibly zero, on the same item. Using k coupons on an item with a price of a yen allows you to buy it for \max\lbrace a - kX, 0\rbrace yen.
Print the minimum amount of money Takahashi needs to buy all the items.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K, X \leq 10^9
- 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 X A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
5 4 7 8 3 10 5 13
Sample Output 1
12
By using 1 coupon on the 1-st item, 1 coupon on the 3-rd item, and 2 coupons on the 5-th item, Takahashi can:
- buy the 1-st item for \max\lbrace A_1-X, 0 \rbrace = 1 yen,
- buy the 2-nd item for \max\lbrace A_2, 0 \rbrace = 3 yen,
- buy the 3-rd item for \max\lbrace A_3-X, 0 \rbrace = 3 yen,
- buy the 4-th item for \max\lbrace A_4, 0 \rbrace = 5 yen,
- buy the 5-th item for \max\lbrace A_5-2X, 0 \rbrace = 0 yen,
for a total of 1 + 3 + 3 + 5 + 0 = 12 yen, which is the minimum possible.
Sample Input 2
5 100 7 8 3 10 5 13
Sample Output 2
0
Sample Input 3
20 815 60 2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202
Sample Output 3
112
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
atcoder
の並べ替えである文字列 S が与えられます。
この文字列 S に対して以下の操作を 0 回以上行います。
- S 中の隣接する 2 文字を選び、入れ替える。
S を atcoder
にするために必要な最小の操作回数を求めてください。
制約
- S は
atcoder
の並べ替えである文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
catredo
出力例 1
8
catredo
\rightarrow [ac]tredo
\rightarrow actre[od]
\rightarrow actr[oe]d
\rightarrow actro[de]
\rightarrow act[or]de
\rightarrow acto[dr]e
\rightarrow a[tc]odre
\rightarrow atcod[er]
という流れで操作を行うと、 8 回で S を atcoder
にすることができ、これが達成可能な最小の操作回数です。
入力例 2
atcoder
出力例 2
0
この場合、文字列 S は元から atcoder
です。
入力例 3
redocta
出力例 3
21
Score : 400 points
Problem Statement
You are given a string S that is a permutation of atcoder
.
On this string S, you will perform the following operation 0 or more times:
- Choose two adjacent characters of S and swap them.
Find the minimum number of operations required to make S equal atcoder
.
Constraints
- S is a string that is a permutation of
atcoder
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
catredo
Sample Output 1
8
You can make S equal atcoder
in 8 operations as follows:
catredo
\rightarrow [ac]tredo
\rightarrow actre[od]
\rightarrow actr[oe]d
\rightarrow actro[de]
\rightarrow act[or]de
\rightarrow acto[dr]e
\rightarrow a[tc]odre
\rightarrow atcod[er]
This is the minimum number of operations achievable.
Sample Input 2
atcoder
Sample Output 2
0
In this case, the string S is already atcoder
.
Sample Input 3
redocta
Sample Output 3
21
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の単純連結無向グラフが与えられます。
辺 i は頂点 A_i と頂点 B_i を結ぶ長さ C_i の辺です。
以下の条件を満たすようにいくつかの辺を削除します。削除する辺の数の最大値を求めてください。
- 辺を削除した後のグラフも連結である。
- 全ての頂点対 (s,t) について、頂点 s と頂点 t の間の距離が削除前と削除後で変化しない。
注釈
単純連結無向グラフとは、単純かつ連結で辺に向きの無いグラフのことをいいます。
グラフが単純であるとは、グラフが自己ループや多重辺を含まないことをいいます。
グラフが連結であるとは、グラフ上の任意の 2 頂点 s, t について s から t へ辺をたどって行けることをいいます。
頂点 s と頂点 t の間の距離とは、頂点 s と頂点 t の間の最短路の長さのことをいいます。
制約
- 2 \leq N \leq 300
- N-1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i \lt B_i \leq N
- 1 \leq C_i \leq 10^9
- i \neq j ならば (A_i, B_i) \neq (A_j, B_j) である。
- 与えられるグラフは連結である。
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
出力
答えを出力せよ。
入力例 1
3 3 1 2 2 2 3 3 1 3 6
出力例 1
1
辺を削除する前の全ての頂点対の距離は次の通りです。
- 頂点 1 と頂点 2 の距離は 2
- 頂点 1 と頂点 3 の距離は 5
- 頂点 2 と頂点 3 の距離は 3
辺 3 を削除しても全ての頂点間の距離は変化しません。また、問題文の条件を満たすように 2 本以上の辺を削除することはできないので、答えは 1 本になります。
入力例 2
5 4 1 3 3 2 3 9 3 5 3 4 5 3
出力例 2
0
どの辺も削除することができません。
入力例 3
5 10 1 2 71 1 3 9 1 4 82 1 5 64 2 3 22 2 4 99 2 5 1 3 4 24 3 5 18 4 5 10
出力例 3
5
Score : 500 points
Problem Statement
You are given a simple connected undirected graph with N vertices and M edges.
Edge i connects Vertex A_i and Vertex B_i, and has a length of C_i.
Let us delete some number of edges while satisfying the conditions below. Find the maximum number of edges that can be deleted.
- The graph is still connected after the deletion.
- For every pair of vertices (s, t), the distance between s and t remains the same before and after the deletion.
Notes
A simple connected undirected graph is a graph that is simple and connected and has undirected edges.
A graph is simple when it has no self-loops and no multi-edges.
A graph is connected when, for every pair of two vertices s and t, t is reachable from s by traversing edges.
The distance between Vertex s and Vertex t is the length of a shortest path between s and t.
Constraints
- 2 \leq N \leq 300
- N-1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i \lt B_i \leq N
- 1 \leq C_i \leq 10^9
- (A_i, B_i) \neq (A_j, B_j) if i \neq j.
- The given graph is connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
Output
Print the answer.
Sample Input 1
3 3 1 2 2 2 3 3 1 3 6
Sample Output 1
1
The distance between each pair of vertices before the deletion is as follows.
- The distance between Vertex 1 and Vertex 2 is 2.
- The distance between Vertex 1 and Vertex 3 is 5.
- The distance between Vertex 2 and Vertex 3 is 3.
Deleting Edge 3 does not affect the distance between any pair of vertices. It is impossible to delete two or more edges while satisfying the condition, so the answer is 1.
Sample Input 2
5 4 1 3 3 2 3 9 3 5 3 4 5 3
Sample Output 2
0
No edge can be deleted.
Sample Input 3
5 10 1 2 71 1 3 9 1 4 82 1 5 64 2 3 22 2 4 99 2 5 1 3 4 24 3 5 18 4 5 10
Sample Output 3
5
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 としてありうるものは a
、 b
、 c
、 ac
の 4 つです。
S の 1 文字目のみに印をつけたとき T は a
、
S の 2 文字目のみに印をつけたとき T は b
、
S の 3 文字目のみに印をつけたとき T は c
、
S の 1 文字目と 3 文字目のみに印をつけたとき T は ac
、
となります。例えば 1 文字目と 2 文字目の両方に印をつけることはできないことに注意してください。
入力例 2
aa
出力例 2
1
T としてありうるものは a
のみです。
印をつけた位置が異なっていても T が同じ文字列となる可能性があることに注意してください。
入力例 3
acba
出力例 3
6
T としてありうるものは a
、 b
、 c
、 aa
、 ab
、 ca
の 6 つです。
入力例 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