Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 フィートは 12 インチです。
A フィート B インチは、インチ換算で何インチですか?
制約
- 1 \leq A \leq 8
- 0 \leq B \leq 11
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを 1 行に出力せよ。単位 (インチ) は省いて出力すること。
入力例 1
6 7
出力例 1
79
6 フィート 7 インチは、インチ換算で 6 \times 12 + 7 = 79 インチです。
入力例 2
4 11
出力例 2
59
4 フィート 11 インチは、インチ換算で 4 \times 12 + 11 = 59 インチです。
入力例 3
8 0
出力例 3
96
8 フィート 0 インチは、インチ換算で 8 \times 12 + 0 = 96 インチです。
Score : 100 points
Problem Statement
1 foot is 12 inches.
How many inches is A feet B inches?
Constraints
- 1 \leq A \leq 8
- 0 \leq B \leq 11
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Output the answer in one line. Omit the unit (inches).
Sample Input 1
6 7
Sample Output 1
79
6 feet 7 inches is 6 \times 12 + 7 = 79 inches.
Sample Input 2
4 11
Sample Output 2
59
4 feet 11 inches is 4 \times 12 + 11 = 59 inches.
Sample Input 3
8 0
Sample Output 3
96
8 feet 0 inches is 8 \times 12 + 0 = 96 inches.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 社は、オンラインショップでグッズを販売しています。
高橋君はそこで N 種類の商品を購入することにしました。
1 以上 N 以下の整数 i について、i 種類目の商品は 1 個 P_i 円で、高橋君は Q_i 個購入します。
また、高橋君は送料を支払う必要があります。
送料は購入する商品の合計金額が S 円以上なら 0 円、そうでないならば K 円です。
高橋君が支払う金額は購入する商品の合計金額と送料の和です。
高橋君が支払う金額を求めてください。
制約
- 1\leq N\leq 100
- 1\leq S\leq 10000
- 1\leq K\leq 10000
- 1\leq P_i\leq 10000
- 1\leq Q_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S K P_1 Q_1 P_2 Q_2 \vdots P_N Q_N
出力
高橋君がオンラインショッピングで支払う金額を出力せよ。
入力例 1
2 2000 500 1000 1 100 6
出力例 1
2100
高橋君は 1 個 1000 円の商品を 1 個と、 1 個 100 円の商品を 6 つ購入します。
よって、購入する商品の合計金額は 1000\times 1+100\times 6=1600 円となります。
このとき購入する商品の合計金額は 2000 円未満であるため、送料は 500 円となります。
よって、高橋君の支払う金額は 1600+500=2100 円となります。
入力例 2
3 2000 500 1000 1 100 6 5000 1
出力例 2
6600
購入する商品の合計金額は 1000\times 1+100\times 6+5000\times 1=6600 円となります。
このとき購入する商品の合計金額は 2000 円以上であるため、送料は 0 円となります。
よって、高橋君の支払う金額は 6600+0=6600 円となります。
入力例 3
2 2000 500 1000 1 1000 1
出力例 3
2000
1 個あたりの価格が同じ商品が複数存在することもあります。
Score : 100 points
Problem Statement
AtCoder Inc. sells merchandise through its online shop.
Takahashi has decided to purchase N types of products from there.
For each integer i from 1 to N, the i-th type of product has a price of P_i yen each, and he will buy Q_i of this.
Additionally, he must pay a shipping fee.
The shipping fee is 0 yen if the total price of the products purchased is S yen or above, and K yen otherwise.
He will pay the total price of the products purchased plus the shipping fee.
Calculate the amount he will pay.
Constraints
- 1\leq N\leq 100
- 1\leq S\leq 10000
- 1\leq K\leq 10000
- 1\leq P_i\leq 10000
- 1\leq Q_i\leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N S K P_1 Q_1 P_2 Q_2 \vdots P_N Q_N
Output
Print the amount Takahashi will pay for online shopping.
Sample Input 1
2 2000 500 1000 1 100 6
Sample Output 1
2100
Takahashi buys one product for 1000 yen and six products for 100 yen each.
Thus, the total price of the products is 1000\times 1+100\times 6=1600 yen.
Since the total amount for the products is less than 2000 yen, the shipping fee will be 500 yen.
Therefore, the amount Takahashi will pay is 1600+500=2100 yen.
Sample Input 2
3 2000 500 1000 1 100 6 5000 1
Sample Output 2
6600
The total price of the products is 1000\times 1+100\times 6+5000\times 1=6600 yen.
Since the total amount for the products is not less than 2000 yen, the shipping fee will be 0 yen.
Therefore, the amount Takahashi will pay is 6600+0=6600 yen.
Sample Input 3
2 2000 500 1000 1 1000 1
Sample Output 3
2000
There may be multiple products with the same price per item.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英大文字および数字からなる 2 文字の文字列が N 個与えられます。i 個目の文字列は S_i です。
以下の 3 つの条件をすべて満たすか判定してください。
・すべての文字列に対して、1 文字目は H , D , C , S のどれかである。
・すべての文字列に対して、2 文字目は A , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , T , J , Q , K のどれかである。
・すべての文字列は相異なる。つまり、i \neq j ならば S_i \neq S_j である。
制約
- 1 \leq N \leq 52
- S_i は英大文字および数字からなる 2 文字の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
3 つの条件をすべて満たす場合は Yes、そうでない場合は No を出力せよ。
入力例 1
4 H3 DA D3 SK
出力例 1
Yes
このとき 3 つの条件をすべて満たすことが確認できます。
入力例 2
5 H3 DA CK H3 S7
出力例 2
No
S_1 と S_4 がともに H3 となってしまっているため、3 番目の条件に反します。
入力例 3
4 3H AD 3D KS
出力例 3
No
入力例 4
5 00 AA XX YY ZZ
出力例 4
No
Score : 200 points
Problem Statement
You are given N strings, each of length 2, consisting of uppercase English letters and digits. The i-th string is S_i.
Determine whether the following three conditions are all satisfied.
・For every string, the first character is one of H, D, C, and S.
・For every string, the second character is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K.
・All strings are pairwise different. That is, if i \neq j, then S_i \neq S_j.
Constraints
- 1 \leq N \leq 52
- S_i is a string of length 2 consisting of uppercase English letters and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If the three conditions are all satisfied, print Yes; otherwise, print No.
Sample Input 1
4 H3 DA D3 SK
Sample Output 1
Yes
One can verify that the three conditions are all satisfied.
Sample Input 2
5 H3 DA CK H3 S7
Sample Output 2
No
Both S_1 and S_4 are H3, violating the third condition.
Sample Input 3
4 3H AD 3D KS
Sample Output 3
No
Sample Input 4
5 00 AA XX YY ZZ
Sample Output 4
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
1, \dots, N と番号付けられた N 個の都市と、都市間を結ぶ M 本の道路があります。
i \, (1 \leq i \leq M) 番目の道路は都市 A_i と都市 B_i を結んでいます。
以下の指示に従い、N 行にわたって出力してください。
- 都市 i \, (1 \leq i \leq N) と道路で直接結ばれた都市が d_i 個あるとし、それらを昇順に都市 a_{i, 1}, \dots, a_{i, d_i} とおく。
- i \, (1 \leq i \leq N) 行目には、d_i + 1 個の整数 d_i, a_{i, 1}, \dots, a_{i, d_i} を、この順番で空白区切りで出力せよ。
制約
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (i \neq j) ならば (A_i, B_i) \neq (A_j, B_j)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M
出力
問題文の指示に従い、N 行にわたって出力せよ。
入力例 1
6 6 3 6 1 3 5 6 2 5 1 2 1 6
出力例 1
3 2 3 6 2 1 5 2 1 6 0 2 2 6 3 1 3 5
都市 1 と道路で直接結ばれているのは都市 2, 3, 6 です。よって、d_1 = 3, a_{1, 1} = 2, a_{1, 2} = 3, a_{1, 3} = 6 であるので、1 行目には 3, 2, 3, 6 をこの順番で空白区切りで出力します。
a_{i, 1}, \dots, a_{i, d_i} は昇順に並んでいなければならないことに注意してください。例えば、1 行目に 3, 3, 2, 6 をこの順番で出力した場合、不正解となります。
入力例 2
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
出力例 2
4 2 3 4 5 4 1 3 4 5 4 1 2 4 5 4 1 2 3 5 4 1 2 3 4
Score : 200 points
Problem Statement
There are N cities numbered 1, \dots, N, and M roads connecting cities.
The i-th road (1 \leq i \leq M) connects city A_i and city B_i.
Print N lines as follows.
- Let d_i be the number of cities directly connected to city i \, (1 \leq i \leq N), and those cities be city a_{i, 1}, \dots, city a_{i, d_i}, in ascending order.
- The i-th line (1 \leq i \leq N) should contain d_i + 1 integers d_i, a_{i, 1}, \dots, a_{i, d_i} in this order, separated by spaces.
Constraints
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) if (i \neq j).
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M
Output
Print N lines as specified in the Problem Statement.
Sample Input 1
6 6 3 6 1 3 5 6 2 5 1 2 1 6
Sample Output 1
3 2 3 6 2 1 5 2 1 6 0 2 2 6 3 1 3 5
The cities directly connected to city 1 are city 2, city 3, and city 6. Thus, we have d_1 = 3, a_{1, 1} = 2, a_{1, 2} = 3, a_{1, 3} = 6, so you should print 3, 2, 3, 6 in the first line in this order, separated by spaces.
Note that a_{i, 1}, \dots, a_{i, d_i} must be in ascending order. For instance, it is unacceptable to print 3, 3, 2, 6 in the first line in this order.
Sample Input 2
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
Sample Output 2
4 2 3 4 5 4 1 3 4 5 4 1 2 4 5 4 1 2 3 5 4 1 2 3 4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 N と、長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
A の空でない連続部分列であって、同じ値を複数個含むようなものが存在するか判定してください。存在するならばそのようなもののうち最も短いものの長さを求めてください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq A_i\leq 10^6 (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
問題文中の条件を満たす連続部分列が存在しないならば -1 と出力せよ。存在するならば、そのようなもののうち最も短いものの長さを出力せよ。
入力例 1
5 3 9 5 3 1
出力例 1
4
(3,9,5,3) と (3,9,5,3,1) が条件を満たします。短いのは (3,9,5,3) で、その長さは 4 です。
入力例 2
4 2 5 3 1
出力例 2
-1
条件を満たす連続部分列は存在しません。
入力例 3
10 1 1 2 3 5 8 13 21 34 55
出力例 3
2
Score : 300 points
Problem Statement
You are given a positive integer N and an integer sequence A = (A_1,A_2,\dots,A_N) of length N.
Determine whether there exists a non-empty (contiguous) subarray of A that has a repeated value, occurring multiple times in A. If such a subarray exists, find the length of the shortest such subarray.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^6 \ (1 \leq i \leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
If there is no (contiguous) subarray satisfying the condition in the problem statement, print -1. Otherwise, print the length of the shortest such subarray.
Sample Input 1
5 3 9 5 3 1
Sample Output 1
4
(3,9,5,3) and (3,9,5,3,1) satisfy the condition. The shorter one is (3,9,5,3), which has length 4.
Sample Input 2
4 2 5 3 1
Sample Output 2
-1
There is no subarray that satisfies the condition.
Sample Input 3
10 1 1 2 3 5 8 13 21 34 55
Sample Output 3
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
あるイベントには N 人が参加し、i 番目の人の交通費は A_i 円でした。
イベントの主催者である高橋くんは、交通費補助額の上限額 x を設定して、人 i には交通費補助額として \min(x,A_i) 円を支給することとしました。ここで x は非負整数である必要があります。
高橋くんの予算が M 円であり、N 人に渡す交通費補助額の総和を M 円以下にしたいとき、交通費補助額の上限額 x は最大でいくらにできますか?
ただし、交通費補助額の上限額を無限に大きくできる場合は代わりにそのことを報告してください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq M \leq 2\times 10^{14}
- 1\leq A_i \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
A_1 A_2 \ldots A_{N}
出力
予算の条件を満たすときの交通費補助額の上限額 x の最大値を整数として出力せよ。
ただし、交通費補助額の上限額を無限に大きくできる場合は代わりに infinite と出力せよ。
入力例 1
4 8 1 3 2 4
出力例 1
2
交通費補助額の上限額を 2 円にすると、N 人に渡す交通費補助額の総和は \min(2,1) + \min(2,3) + \min(2,2) + \min(2,4) = 7 円となり、予算の 8 円以下となります。
交通費補助額の上限額を 3 円にすると、N 人に渡す交通費補助額の総和は \min(3,1) + \min(3,3) + \min(3,2) + \min(3,4) = 9 円となり、予算の 8 円を超えてしまいます。
よって、交通費補助額の上限額の最大値は 2 円となります。
入力例 2
3 20 5 3 2
出力例 2
infinite
交通費補助額の上限額を無限に大きくできます。
入力例 3
10 23 2 5 6 5 2 1 7 9 7 2
出力例 3
2
Score : 300 points
Problem Statement
There are N people participating in an event, and the transportation cost for the i-th person is A_i yen.
Takahashi, the organizer of the event, decided to set a maximum limit x for the transportation subsidy. The subsidy for person i will be \min(x, A_i) yen. Here, x must be a non-negative integer.
Given that Takahashi's budget is M yen, and he wants the total transportation subsidy for all N people to be at most M yen, what is the maximum possible value of the subsidy limit x?
If the subsidy limit can be made infinitely large, report that instead.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^{14}
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 \ldots A_{N}
Output
Print the maximum value of the subsidy limit x that satisfies the budget condition, as an integer.
If the subsidy limit can be made infinitely large, print infinite instead.
Sample Input 1
4 8 1 3 2 4
Sample Output 1
2
If the subsidy limit is set to 2 yen, the total transportation subsidy for all N people is \min(2,1) + \min(2,3) + \min(2,2) + \min(2,4) = 7 yen, which is within the budget of 8 yen.
If the subsidy limit is set to 3 yen, the total transportation subsidy for all N people is \min(3,1) + \min(3,3) + \min(3,2) + \min(3,4) = 9 yen, which exceeds the budget of 8 yen.
Therefore, the maximum possible value of the subsidy limit is 2 yen.
Sample Input 2
3 20 5 3 2
Sample Output 2
infinite
The subsidy limit can be made infinitely large.
Sample Input 3
10 23 2 5 6 5 2 1 7 9 7 2
Sample Output 3
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N を正整数とします。長さ 2^N の非負整数列 A=(A_1, A_2, \dots, A_{2^N}) の アンバランスさ を次の操作によって得られる非負整数値として定義します。
- はじめ、X=0 とする。
- 次の一連の操作を N 回行う。
- X を \max(X, \max(A) - \min(A)) に更新する。ここで \max(A) および \min(A) は数列 A の最大値と最小値を意味する。
- 先頭から順に 2 つずつ要素を組にして、それらの和を並べることでできる長さが A の半分の数列を、新たな A とする。すなわち、A \gets (A_1 + A_2, A_3 + A_4, \dots, A_{\vert A \vert - 1} + A_{\vert A \vert}) とする。
- 最終的な X をアンバランスさとする。
例えば N=2, A=(6, 8, 3, 5) は以下の手順によりアンバランスさが 6 であるとわかります。
- はじめ、X=0 である。
- 1 回目の一連の操作は次の通りである。
- X を \max(X, \max(A) - \min(A)) = \max(0, 8 - 3) = 5 に更新する。
- A を (6+8, 3+5) = (14, 8) とする。
- 2 回目の一連の操作は次の通りである。
- X を \max(X, \max(A) - \min(A)) = \max(5, 14 - 8) = 6 に更新する。
- A を (14 + 8) = (22) とする。
- 最終的に X=6 となる。
非負整数 K が与えられます。長さ 2^N の非負整数列であって総和が K であるものの中で、アンバランスさが最小値を取る数列を構成してください。
制約
- 1 \leq N \leq 20
- 0 \leq K \leq 10^9
- N, K は整数
入力
入力は以下の形式で標準入力から与えられる。
N K
出力
アンバランスさが最小値を取る数列を B=(B_1,B_2,\dots,B_{2^N}) とする。B のアンバランスさを U とする。この時、以下の形式で答えを出力せよ。
U
B_1 B_2 \dots B_{2^N}
答えが複数ある場合は、どれを出力しても正答とみなされる。
入力例 1
1 11
出力例 1
1 5 6
(5, 6) はアンバランスさが 1 の数列で、これが条件を満たす数列のうちアンバランスさが最小の数列です。
入力例 2
3 56
出力例 2
0 7 7 7 7 7 7 7 7
Score : 400 points
Problem Statement
Let N be a positive integer. Define the imbalance of a sequence A=(A_1, A_2, \dots, A_{2^N}) of non-negative integers of length 2^N as the non-negative integer value obtained by the following operation:
- Initially, set X=0.
- Perform the following series of operations N times:
- Update X to \max(X, \max(A) - \min(A)), where \max(A) and \min(A) denote the maximum and minimum values of sequence A, respectively.
- Form a new sequence of half the length by pairing elements from the beginning two by two and arranging their sums. That is, set A \gets (A_1 + A_2, A_3 + A_4, \dots, A_{\vert A \vert - 1} + A_{\vert A \vert}).
- The final value of X is the imbalance.
For example, when N=2, A=(6, 8, 3, 5), the imbalance is 6 through the following steps:
- Initially, X=0.
- The first series of operations is as follows:
- Update X to \max(X, \max(A) - \min(A)) = \max(0, 8 - 3) = 5.
- Set A to (6+8, 3+5) = (14, 8).
- The second series of operations is as follows:
- Update X to \max(X, \max(A) - \min(A)) = \max(5, 14 - 8) = 6.
- Set A to (14 + 8) = (22).
- Finally, X=6.
You are given a non-negative integer K. Among all sequences of non-negative integers of length 2^N with sum K, construct a sequence that minimizes the imbalance.
Constraints
- 1 \leq N \leq 20
- 0 \leq K \leq 10^9
- N and K are integers.
Input
The input is given from Standard Input in the following format:
N K
Output
Let B=(B_1,B_2,\dots,B_{2^N}) be a sequence with minimum imbalance. Let U be the imbalance of B. Output a solution in the following format:
U
B_1 B_2 \dots B_{2^N}
If there are multiple solutions, any of them will be considered correct.
Sample Input 1
1 11
Sample Output 1
1 5 6
(5, 6) is a sequence with imbalance 1, which is the minimum imbalance among sequences satisfying the condition.
Sample Input 2
3 56
Sample Output 2
0 7 7 7 7 7 7 7 7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
長さ N の正整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。以下の条件を全て満たす正整数組 (i,j,k) の個数を求めてください。
- 1\leq i < j < k\leq N
- A_i = A_k
- A_i \neq A_j
制約
- 3\leq N\leq 3\times 10^5
- 1\leq A_i \leq N
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを整数として出力せよ。
入力例 1
5 1 2 1 3 2
出力例 1
3
条件を全て満たす正整数組 (i,j,k) は以下の 3 個です。
- (i,j,k)=(1,2,3)
- (i,j,k)=(2,3,5)
- (i,j,k)=(2,4,5)
入力例 2
7 1 2 3 4 5 6 7
出力例 2
0
条件を全て満たす正整数組 (i,j,k) が存在しない場合もあります。
入力例 3
13 9 7 11 7 3 8 1 13 11 11 11 6 13
出力例 3
20
Score : 450 points
Problem Statement
You are given a sequence of positive integers of length N: A=(A_1,A_2,\ldots,A_N). Find the number of triples of positive integers (i,j,k) that satisfy all of the following conditions:
- 1\leq i < j < k\leq N,
- A_i = A_k,
- A_i \neq A_j.
Constraints
- 3\leq N\leq 3\times 10^5
- 1\leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer as an integer.
Sample Input 1
5 1 2 1 3 2
Sample Output 1
3
The following three triples of positive integers (i,j,k) satisfy the conditions:
- (i,j,k)=(1,2,3)
- (i,j,k)=(2,3,5)
- (i,j,k)=(2,4,5)
Sample Input 2
7 1 2 3 4 5 6 7
Sample Output 2
0
There may be no triples of positive integers (i,j,k) that satisfy the conditions.
Sample Input 3
13 9 7 11 7 3 8 1 13 11 11 11 6 13
Sample Output 3
20
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
英大文字・英小文字からなる長さ 4 の文字列で、以下の 2 条件をともに満たすものを DDoS 型文字列と呼ぶことにします。
- 1,2,4 文字目が英大文字で、3 文字目が英小文字である
- 1,2 文字目が等しい
例えば DDoS, AAaA は DDoS 型文字列であり、ddos, IPoE は DDoS 型文字列ではありません。
英大文字・英小文字および ? からなる文字列 S が与えられます。
S に含まれる ? を独立に英大文字・英小文字に置き換えてできる文字列は、S に含まれる ? の個数を q として 52^q 通りあります。
このうち DDoS 型文字列を部分列に含まないものの個数を 998244353 で割ったあまりを求めてください。
注記
文字列の部分列とは、文字列から 0 個以上の文字を取り除いた後、残りの文字を元の順序で連結して得られる文字列のことをいいます。
例えば、AC は ABC の部分列であり、RE は ECR の部分列ではありません。
制約
- S は英大文字・英小文字および
?からなる - S の長さは 4 以上 3\times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
DD??S
出力例 1
676
? の少なくとも一方が英小文字のとき、DDoS 型文字列を部分列に含みます。
入力例 2
????????????????????????????????????????
出力例 2
858572093
998244353 で割ったあまりを求めてください。
入力例 3
?D??S
出力例 3
136604
Score : 500 points
Problem Statement
A DDoS-type string is a string of length 4 consisting of uppercase and lowercase English letters satisfying both of the following conditions.
- The first, second, and fourth characters are uppercase English letters, and the third character is a lowercase English letter.
- The first and second characters are equal.
For instance, DDoS and AAaA are DDoS-type strings, while neither ddos nor IPoE is.
You are given a string S consisting of uppercase and lowercase English letters and ?.
Let q be the number of occurrences of ? in S. There are 52^q strings that can be obtained by independently replacing each ? in S with an uppercase or lowercase English letter.
Among these strings, find the number of ones that do not contain a DDoS-type string as a subsequence, modulo 998244353.
Notes
A subsequence of a string is a string obtained by removing zero or more characters from the string and concatenating the remaining characters without changing the order.
For instance, AC is a subsequence of ABC, while RE is not a subsequence of ECR.
Constraints
- S consists of uppercase English letters, lowercase English letters, and
?. - The length of S is between 4 and 3\times 10^5, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
DD??S
Sample Output 1
676
When at least one of the ?s is replaced with a lowercase English letter, the resulting string will contain a DDoS-type string as a subsequence.
Sample Input 2
????????????????????????????????????????
Sample Output 2
858572093
Find the count modulo 998244353.
Sample Input 3
?D??S
Sample Output 3
136604