Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
長さ N の整数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。
A から偶数だけすべて取り出し、もとの順番を保って出力してください。
制約
- 1\leq N\leq 100
- 1\leq A _ i\leq 100\ (1\leq i\leq N)
- A には 1 つ以上偶数が含まれる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N
出力
A から偶数を取り出した列を、空白区切りで 1 行に出力せよ。
入力例 1
5 1 2 3 5 6
出力例 1
2 6
A=(1,2,3,5,6) です。 このうち偶数なのは A _ 2=2,A _ 5=6 の 2 つなので、2 と 6 をこの順に空白区切りで出力してください。
入力例 2
5 2 2 2 3 3
出力例 2
2 2 2
A の中には同じ要素がある場合もあります。
入力例 3
10 22 3 17 8 30 15 12 14 11 17
出力例 3
22 8 30 12 14
Score : 100 points
Problem Statement
You are given a sequence of N integers: A=(A _ 1,A _ 2,\ldots,A _ N).
Print all even numbers in A without changing the order.
Constraints
- 1\leq N\leq 100
- 1\leq A _ i\leq 100\ (1\leq i\leq N)
- A contains at least one even number.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \ldots A _ N
Output
Print a line containing the sequence of all even numbers in A, with spaces in between.
Sample Input 1
5 1 2 3 5 6
Sample Output 1
2 6
We have A=(1,2,3,5,6). Among them are two even numbers, A _ 2=2 and A _ 5=6, so print 2 and 6 in this order, with a space in between.
Sample Input 2
5 2 2 2 3 3
Sample Output 2
2 2 2
A may contain equal elements.
Sample Input 3
10 22 3 17 8 30 15 12 14 11 17
Sample Output 3
22 8 30 12 14
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は、毎日 S 時 0 分に部屋の電気をつけ、毎日 T 時 0 分に消します。
電気をつけている間に日付が変わることもあります。
X 時 30 分に部屋の電気がついているかどうか判定してください。
制約
- 0 \leq S, T, X \leq 23
- S \neq T
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T X
出力
X 時 30 分に部屋の電気がついているならば Yes と、そうでなければ No と出力せよ。
入力例 1
7 20 12
出力例 1
Yes
部屋の電気がついているのは 7 時 0 分から 20 時 0 分までの間です。12 時 30 分には電気がついているので、Yes と出力します。
入力例 2
20 7 12
出力例 2
No
部屋の電気がついているのは 0 時 0 分から 7 時 0 分までの間と、20 時 0 分から(次の日の)0 時 0 分までの間です。
12 時 30 分には電気がついていないので、No と出力します。
入力例 3
23 0 23
出力例 3
Yes
Score : 100 points
Problem Statement
Takahashi turns on the light of his room at S o'clock (on the 24-hour clock) every day and turns it off at T o'clock every day.
The date may change while the light is on.
Determine whether the light is on at 30 minutes past X o'clock.
Constraints
- 0 \leq S, T, X \leq 23
- S \neq T
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
S T X
Output
If the light is on at 30 minutes past X o'clock, print Yes; otherwise, print No.
Sample Input 1
7 20 12
Sample Output 1
Yes
The light is on between 7 o'clock and 20 o'clock. At 30 minutes past 12 o'clock, it is on, so we print Yes.
Sample Input 2
20 7 12
Sample Output 2
No
The light is on between 0 o'clock and 7 o'clock, and between 20 o'clock and 0 o'clock (on the next day). At 30 minutes past 12 o'clock, it is off, so we print No.
Sample Input 3
23 0 23
Sample Output 3
Yes
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,3 は A に含まれ、4 は A に含まれないので、答えは 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder 遊園地には K 人乗りのアトラクションがあります。 現在、このアトラクションの待機列には N グループが並んでいます。
先頭から i 番目 (1\leq i\leq N) のグループは A _ i 人組です。 すべての i (1\leq i\leq N) について、A _ i\leq K です。
高橋君はこのアトラクションのスタッフとして、並んでいるグループを次の手順に従って誘導します。
はじめ、アトラクションには誰も誘導されておらず、空席は K 個あります。
- 待機列に並んでいるグループがない場合、アトラクションをスタートさせ、誘導を終了する。
- アトラクションの空席の数と待機列の先頭に並んでいるグループの人数を比較し、次のどちらかを行う。
- 待機列の先頭に並んでいるグループの人数よりアトラクションの空席の数のほうが少ない場合、アトラクションをスタートさせる。 スタートしたのち、アトラクションの空席が K 個になる。
- そうでない場合、待機列の先頭に並んでいるグループを全員アトラクションへ誘導する。 先頭のグループが待機列から取り出され、アトラクションの空席がグループの人数ぶんだけ減少する。
- 1 に戻る。
ただし、誘導を開始したあとに追加でグループが並ぶことはないとします。 以上の条件のもとで、この手順が有限回で終了することが示せます。
高橋君が誘導を開始してから誘導を終了するまで、何回アトラクションをスタートさせるか求めてください。
制約
- 1\leq N\leq100
- 1\leq K\leq100
- 1\leq A _ i\leq K\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A _ 1 A _ 2 \ldots A _ N
出力
答えを出力せよ。
入力例 1
7 6 2 5 1 4 1 2 3
出力例 1
4
はじめ、7 つのグループは以下のように並んでいます。

高橋君の誘導の様子の一部を以下の図に示します。

- はじめ、先頭に並んでいるグループは 2 人のグループで、空席は 6 個です。よって、高橋君は先頭のグループをアトラクションに誘導し、空席は 4 個になります。
- 次に、先頭に並んでいるグループは 5 人のグループで、空席の個数 4 より多いため、アトラクションをスタートさせます。
- 空席が 6 個になったため、先頭のグループをアトラクションに誘導し、空席は 1 個になります。
- 次に先頭に並んでいるのは 1 人なので、アトラクションに誘導し、空席は 0 個になります。
すべての誘導が終了するまでに、高橋君は 4 回アトラクションをスタートさせることになります。
よって、4 を出力してください。

入力例 2
7 10 1 10 1 10 1 10 1
出力例 2
7
入力例 3
15 100 73 8 55 26 97 48 37 47 35 55 5 17 62 2 60
出力例 3
8
Score: 200 points
Problem Statement
The AtCoder amusement park has an attraction that can accommodate K people. Now, there are N groups lined up in the queue for this attraction.
The i-th group from the front (1\leq i\leq N) consists of A_i people. For all i (1\leq i\leq N), it holds that A_i \leq K.
Takahashi, as a staff member of this attraction, will guide the groups in the queue according to the following procedure.
Initially, no one has been guided to the attraction, and there are K empty seats.
- If there are no groups in the queue, start the attraction and end the guidance.
- Compare the number of empty seats in the attraction with the number of people in the group at the front of the queue, and do one of the following:
- If the number of empty seats is less than the number of people in the group at the front, start the attraction. Then, the number of empty seats becomes K again.
- Otherwise, guide the entire group at the front of the queue to the attraction. The front group is removed from the queue, and the number of empty seats decreases by the number of people in the group.
- Go back to step 1.
Here, no additional groups will line up after the guidance has started. Under these conditions, it can be shown that this procedure will end in a finite number of steps.
Determine how many times the attraction will be started throughout the guidance.
Constraints
- 1\leq N\leq 100
- 1\leq K\leq 100
- 1\leq A_i\leq K\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
7 6 2 5 1 4 1 2 3
Sample Output 1
4
Initially, the seven groups are lined up as follows:

Part of Takahashi's guidance is shown in the following figure:

- Initially, the group at the front has 2 people, and there are 6 empty seats. Thus, he guides the front group to the attraction, leaving 4 empty seats.
- Next, the group at the front has 5 people, which is more than the 4 empty seats, so the attraction is started.
- After the attraction is started, there are 6 empty seats again, so the front group is guided to the attraction, leaving 1 empty seat.
- Next, the group at the front has 1 person, so they are guided to the attraction, leaving 0 empty seats.
In total, he starts the attraction four times before the guidance is completed.
Therefore, print 4.

Sample Input 2
7 10 1 10 1 10 1 10 1
Sample Output 2
7
Sample Input 3
15 100 73 8 55 26 97 48 37 47 35 55 5 17 62 2 60
Sample Output 3
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。
N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X 個 (X>0) 存在するならば、X を文字列として扱って S_i+
(+X+)を出力する。
制約
- 1 \leq N \leq 2\times 10^5
- S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文中の指示にしたがって、N 行出力せよ。
入力例 1
5 newfile newfile newfolder newfile newfolder
出力例 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
入力例 2
11 a a a a a a a a a a a
出力例 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Score : 300 points
Problem Statement
For two strings A and B, let A+B denote the concatenation of A and B in this order.
You are given N strings S_1,\ldots,S_N. Modify and print them as follows, in the order i=1, \ldots, N:
- if none of S_1,\ldots,S_{i-1} is equal to S_i, print S_i;
- if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i, print S_i+
(+X+), treating X as a string.
Constraints
- 1 \leq N \leq 2\times 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines as specified in the Problem Statement.
Sample Input 1
5 newfile newfile newfolder newfile newfolder
Sample Output 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
Sample Input 2
11 a a a a a a a a a a a
Sample Output 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 本の導火線を一直線に接着したものがあります。左から i 本目の導火線は長さが A_i cm で、 1 秒あたり B_i cm の一定の速さで燃えます。
この導火線の左端と右端から同時に火をつけるとき、 2 つの火がぶつかる場所が着火前の導火線の左端から何 cm の地点か求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq A_i,B_i \leq 1000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
2 つの火がぶつかる場所が着火前の導火線の左端から何 cm の地点か(単位を除いて)出力せよ。
想定解答との絶対誤差または相対誤差が 10^{-5} 以下であれば正解として扱われる。
入力例 1
3 1 1 2 1 3 1
出力例 1
3.000000000000000
着火前の導火線の左端から 3 cm の地点で 2 つの火がぶつかります。
入力例 2
3 1 3 2 2 3 1
出力例 2
3.833333333333333
入力例 3
5 3 9 1 2 4 6 1 5 5 3
出力例 3
8.916666666666668
Score : 300 points
Problem Statement
We have N fuses connected in series. The i-th fuse from the left has a length of A_i centimeters and burns at a constant speed of B_i centimeters per second.
Consider igniting this object from left and right ends simultaneously. Find the distance between the position where the two flames will meet and the left end of the object.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq A_i,B_i \leq 1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print the distance between the position where the two flames will meet and the left end of the object, in centimeters (print just the number).
Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-5}.
Sample Input 1
3 1 1 2 1 3 1
Sample Output 1
3.000000000000000
The two flames will meet at 3 centimeters from the left end of the object.
Sample Input 2
3 1 3 2 2 3 1
Sample Output 2
3.833333333333333
Sample Input 3
5 3 9 1 2 4 6 1 5 5 3
Sample Output 3
8.916666666666668
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
0, 1 からなる長さ N の文字列 S が与えられます。
0, 1 からなる長さ N の文字列 T は以下の条件を満たすとき、またそのときに限り 良い文字列 であると定義します。
- 1 \leq i \leq N - 1 を満たす整数 i であって、T の i 文字目と i + 1 文字目が一致するようなものがちょうど 1 つ存在する。
i = 1,2,\ldots, N について以下の操作を 1 度行うか行わないか選ぶことができます。
- S の i 文字目が
0であるとき S の i 文字目を1に、そうでないとき S の i 文字目を0に置き換える。操作を行った場合、C_i のコストがかかる。
S を良い文字列にするために必要なコストの総和の最小値を求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- S は長さ N の
0,1からなる文字列 - 1 \leq C_i \leq 10^9
- N, C_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N S C_1 C_2 \ldots C_N
出力
答えを出力せよ。
入力例 1
5 00011 3 9 2 6 4
出力例 1
7
i = 1, 5 に対して操作を行い、i = 2, 3, 4 に対して操作を行わないことで S = 10010 となり、S は良い文字列となります。このときかかるコストは 7 であり、コスト 7 未満で S を良い文字列にすることはできないため、7 を出力します。
入力例 2
4 1001 1 2 3 4
出力例 2
0
入力例 3
11 11111100111 512298012 821282085 543342199 868532399 690830957 973970164 928915367 954764623 923012648 540375785 925723427
出力例 3
2286846953
Score: 400 points
Problem Statement
You are given a string S of length N consisting of 0 and 1.
A string T of length N consisting of 0 and 1 is a good string if and only if it satisfies the following condition:
- There is exactly one integer i such that 1 \leq i \leq N - 1 and the i-th and (i + 1)-th characters of T are the same.
For each i = 1,2,\ldots, N, you can choose whether or not to perform the following operation once:
- If the i-th character of S is
0, replace it with1, and vice versa. The cost of this operation, if performed, is C_i.
Find the minimum total cost required to make S a good string.
Constraints
- 2 \leq N \leq 2 \times 10^5
- S is a string of length N consisting of
0and1. - 1 \leq C_i \leq 10^9
- N and C_i are integers.
Input
The input is given from Standard Input in the following format:
N S C_1 C_2 \ldots C_N
Output
Print the answer.
Sample Input 1
5 00011 3 9 2 6 4
Sample Output 1
7
Performing the operation for i = 1, 5 and not performing it for i = 2, 3, 4 makes S = 10010, which is a good string. The cost incurred in this case is 7, and it is impossible to make S a good string for less than 7, so print 7.
Sample Input 2
4 1001 1 2 3 4
Sample Output 2
0
Sample Input 3
11 11111100111 512298012 821282085 543342199 868532399 690830957 973970164 928915367 954764623 923012648 540375785 925723427
Sample Output 3
2286846953
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
ストーリー
長い水槽があり、高さの異なる板が等間隔に配置されています。 高橋くんは、この水槽の端へ水を注いでいったとき、板で区切られたそれぞれの領域に水が到達する時刻が知りたいです。
問題文
長さ N の正整数列 H=(H _ 1,H _ 2,\dotsc,H _ N) が与えられます。
長さ N+1 の非負整数列 A=(A _ 0,A _ 1,\dotsc,A _ N) があります。 はじめ、A _ 0=A _ 1=\dotsb=A _ N=0 です。
A に対して、次の操作を繰り返します。
- A _ 0 の値を 1 増やす。
- i=1,2,\ldots,N に対して、この順に次の操作を行う。
- A _ {i-1}\gt A _ i かつ A _ {i-1}\gt H _ i のとき、A _ {i-1} の値を 1 減らし、A _ i の値を 1 増やす。
i=1,2,\ldots,N のそれぞれに対して、初めて A _ i>0 が成り立つのは何回目の操作の後か求めてください。
制約
- 1\leq N\leq2\times10 ^ 5
- 1\leq H _ i\leq10 ^ 9\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H _ 1 H _ 2 \dotsc H _ N
出力
i=1,2,\ldots,N に対する答えを、空白を区切りとして 1 行に出力せよ。
入力例 1
5 3 1 4 1 5
出力例 1
4 5 13 14 26
はじめ 5 回の操作では以下のようになります。
それぞれの行が一回の操作に対応し、左端が 1 番の操作を、それ以外が 2 番の操作に対応します。

この図から、A _ 1\gt0 が初めて成り立つのは 4 回目の操作の後、A _ 2\gt0 が初めて成り立つのは 5 回目の操作の後です。
同様にして、A _ 3,A _ 4,A _ 5 に対する答えは 13,14,26 です。
よって、4 5 13 14 26 を出力してください。
入力例 2
6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
1000000001 2000000001 3000000001 4000000001 5000000001 6000000001
出力すべき値が 32\operatorname{bit} 整数に収まらない場合があることに注意してください。
入力例 3
15 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632
出力例 3
749 918 1921 2250 4861 5390 5822 6428 6836 7796 7934 8294 10109 10223 11373
Score : 500 points
Story
There is a long water tank with boards of different heights placed at equal intervals. Takahashi wants to know the time at which water reaches each section separated by the boards when water is poured from one end of the tank.
Problem Statement
You are given a sequence of positive integers of length N: H=(H _ 1,H _ 2,\dotsc,H _ N).
There is a sequence of non-negative integers of length N+1: A=(A _ 0,A _ 1,\dotsc,A _ N). Initially, A _ 0=A _ 1=\dotsb=A _ N=0.
Perform the following operations repeatedly on A:
- Increase the value of A _ 0 by 1.
- For i=1,2,\ldots,N in this order, perform the following operation:
- If A _ {i-1}\gt A _ i and A _ {i-1}\gt H _ i, decrease the value of A _ {i-1} by 1 and increase the value of A _ i by 1.
For each i=1,2,\ldots,N, find the number of operations before A _ i>0 holds for the first time.
Constraints
- 1\leq N\leq2\times10 ^ 5
- 1\leq H _ i\leq10 ^ 9\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H _ 1 H _ 2 \dotsc H _ N
Output
Print the answers for i=1,2,\ldots,N in a single line, separated by spaces.
Sample Input 1
5 3 1 4 1 5
Sample Output 1
4 5 13 14 26
The first five operations go as follows.
Here, each row corresponds to one operation, with the leftmost column representing step 1 and the others representing step 2.

From this diagram, A _ 1\gt0 holds for the first time after the 4th operation, and A _ 2\gt0 holds for the first time after the 5th operation.
Similarly, the answers for A _ 3, A _ 4, A _ 5 are 13, 14, 26, respectively.
Therefore, you should print 4 5 13 14 26.
Sample Input 2
6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
1000000001 2000000001 3000000001 4000000001 5000000001 6000000001
Note that the values to be output may not fit within a 32-bit integer.
Sample Input 3
15 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632
Sample Output 3
749 918 1921 2250 4861 5390 5822 6428 6836 7796 7934 8294 10109 10223 11373
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
M 個の数字 C_i が与えられます。
1 以上 N 以下の整数のうち、先頭に余分な 0 をつけずに 10 進法で表した時に C_1,\ldots,C_M を全て含むようなもの全ての和を、 998244353 で割った余りを求めてください。
制約
- 1 \leq N < 10^{10^4}
- 1 \leq M \leq 10
- 0 \leq C_1 < \ldots < C_M \leq 9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M C_1 \ldots C_M
出力
答えを出力せよ。
入力例 1
104 2 0 1
出力例 1
520
1 以上 104 以下の整数のうち、10 進法で表した時に 0, 1 を共に含むようなものは、10,100,101,102,103,104 の 6 個あります。
これらの和は 520 です。
入力例 2
999 4 1 2 3 4
出力例 2
0
1 以上 999 以下の整数で、1, 2, 3, 4 を全て含むようなものは存在しません。
入力例 3
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 5 0 2 4 6 8
出力例 3
397365274
998244353 で割った余りを求めてください。
Score : 500 points
Problem Statement
Given are M digits C_i.
Find the sum, modulo 998244353, of all integers between 1 and N (inclusive) that contain all of C_1, \ldots, C_M when written in base 10 without unnecessary leading zeros.
Constraints
- 1 \leq N < 10^{10^4}
- 1 \leq M \leq 10
- 0 \leq C_1 < \ldots < C_M \leq 9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M C_1 \ldots C_M
Output
Print the answer.
Sample Input 1
104 2 0 1
Sample Output 1
520
Between 1 and 104, there are six integers that contain both 0 and 1 when written in base 10: 10,100,101,102,103,104.
The sum of them is 520.
Sample Input 2
999 4 1 2 3 4
Sample Output 2
0
Between 1 and 999, no integer contains all of 1, 2, 3, 4.
Sample Input 3
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 5 0 2 4 6 8
Sample Output 3
397365274
Be sure to find the sum modulo 998244353.