A - AtCoder Quiz 3

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

AtCoder で定期的に開催されている、国際的な権威があるコンテストである AtCoder Grand Contest (以下、AGC) は今までに 54 回開催されてきました。

みなさんがちょうど参加している 230 回目の ABC である ABC230 と同様に、 当初は N 回目の AGC のコンテスト名には N3 桁になるようにゼロ埋めした数が割り振られていました。( 1 回目の AGC は AGC001, 2 回目の AGC は AGC002, ...)

ところが、最新の 54 回目の AGC のコンテスト名は AGC055 で、回数より 1 大きい数が割り振られています。これは、AGC042 が社会情勢の影響で中止されて欠番となったため、42 回目以降に開催されたコンテストでは開催された回数より 1 大きい数が割り振られているからです。(入出力例にある説明も参考にしてください。)

さて、ここで問題です。整数 N が与えられるので、N 回目に開催された AGC のコンテスト名を AGCXXX の形式で出力してください。ここで、XXX にはゼロ埋めがなされた 3 桁の数が入ります。

制約

  • 1 \leq N \leq 54
  • N は整数である。

入力

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

N

出力

N 回目に開催された AGC のコンテスト名を所定の形式で出力せよ。


入力例 1

42

出力例 1

AGC043

問題文にある通り、 42 回目以降の AGC には回数より 1 大きい数が割り振られています。
よって 42 回目の AGC のコンテスト名は AGC043 になります。


入力例 2

19

出力例 2

AGC019

41 回目以前の AGC は回数と同じ数が割り振られています。
よって AGC019 が答えとなります。


入力例 3

1

出力例 3

AGC001

問題文にある通り、 1 回目の AGC のコンテスト名は AGC001 です。
数が 3 桁になるようにゼロ埋めを行う必要があるのに注意してください。


入力例 4

50

出力例 4

AGC051

Score : 100 points

Problem Statement

AtCoder Grand Contest (AGC), a regularly held contest with a world authority, has been held 54 times.

Just like the 230-th ABC ― the one you are in now ― is called ABC230, the N-th AGC is initially named with a zero-padded 3-digit number N. (The 1-st AGC is AGC001, the 2-nd AGC is AGC002, ...)

However, the latest 54-th AGC is called AGC055, where the number is one greater than 54. Because AGC042 is canceled and missing due to the social situation, the 42-th and subsequent contests are assigned numbers that are one greater than the numbers of contests held. (See also the explanations at Sample Inputs and Outputs.)

Here is the problem: given an integer N, print the name of the N-th AGC in the format AGCXXX, where XXX is the zero-padded 3-digit number.

Constraints

  • 1 \leq N \leq 54
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the name of the N-th AGC in the specified format.


Sample Input 1

42

Sample Output 1

AGC043

As explained in Problem Statement, the 42-th and subsequent AGCs are assigned numbers that are one greater than the numbers of contests.
Thus, the 42-th AGC is named AGC043.


Sample Input 2

19

Sample Output 2

AGC019

The 41-th and preceding AGCs are assigned numbers that are equal to the numbers of contests.
Thus, the answer is AGC019.


Sample Input 3

1

Sample Output 3

AGC001

As mentioned in Problem Statement, the 1-st AGC is named AGC001.
Be sure to pad the number with zeros into a 3-digit number.


Sample Input 4

50

Sample Output 4

AGC051
B - flip

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

012 種類の文字からなる文字列 s が与えられます。 s に含まれる 01 に、10 に置き換えた文字列を出力してください。

制約

  • s の長さは 1 以上 10 以下
  • s012 種類の文字からなる

入力

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

s

出力

答えを 1 行で出力せよ。


入力例 1

01

出力例 1

10

s1 文字目は 1 なので、1 文字目に出力すべき文字は 0 です。 s2 文字目は 0 なので、2 文字目に出力すべき文字は 1 です。


入力例 2

1011

出力例 2

0100

入力例 3

100100001

出力例 3

011011110

Score : 100 points

Problem Statement

You are given a string s consisting of two kinds of characters, 0 and 1. Print the string obtained by replacing 0 with 1 and 1 with 0 in s.

Constraints

  • The length of s is between 1 and 10, inclusive.
  • s consists of two kinds of characters, 0 and 1.

Input

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

s

Output

Print the answer in a single line.


Sample Input 1

01

Sample Output 1

10

The 1-st character of s is 1, so the 1-st character to print is 0. The 2-nd character of s is 0, so the 2-nd character to print is 1.


Sample Input 2

1011

Sample Output 2

0100

Sample Input 3

100100001

Sample Output 3

011011110
C - How many?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?

制約

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S, T は整数である。

入力

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

S T

出力

条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。


入力例 1

1 0

出力例 1

4

条件を満たす非負整数の組 (a,b,c)(0,0,0), (0,0,1), (0,1,0), (1,0,0)4 つです。


入力例 2

2 5

出力例 2

10

入力例 3

10 10

出力例 3

213

入力例 4

30 100

出力例 4

2471

Score : 200 points

Problem Statement

How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?

Constraints

  • 0 \leq S \leq 100
  • 0 \leq T \leq 10000
  • S and T are integers.

Input

Input is given from Standard Input in the following format:

S T

Output

Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.


Sample Input 1

1 0

Sample Output 1

4

The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.


Sample Input 2

2 5

Sample Output 2

10

Sample Input 3

10 10

Sample Output 3

213

Sample Input 4

30 100

Sample Output 4

2471
D - Triangle (Easier)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1, \dots, N の番号が付けられており、i \, (1 \leq i \leq M) 番目の辺は頂点 U_i と頂点 V_i を結んでいます。

以下の条件を全て満たす整数 a, b, c の組の総数を求めてください。

  • 1 \leq a \lt b \lt c \leq N
  • 頂点 a と頂点 b を結ぶ辺が存在する。
  • 頂点 b と頂点 c を結ぶ辺が存在する。
  • 頂点 c と頂点 a を結ぶ辺が存在する。

制約

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • 入力は全て整数

入力

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

N M
U_1 V_1
\vdots
U_M V_M

出力

答えを出力せよ。


入力例 1

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

出力例 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) が条件を満たします。


入力例 2

3 1
1 2

出力例 2

0

入力例 3

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

出力例 3

4

Score : 200 points

Problem Statement

You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N, and the i-th (1 \leq i \leq M) edge connects Vertex U_i and Vertex V_i.

Find the number of tuples of integers a, b, c that satisfy all of the following conditions:

  • 1 \leq a \lt b \lt c \leq N
  • There is an edge connecting Vertex a and Vertex b.
  • There is an edge connecting Vertex b and Vertex c.
  • There is an edge connecting Vertex c and Vertex a.

Constraints

  • 3 \leq N \leq 100
  • 1 \leq M \leq \frac{N(N - 1)}{2}
  • 1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)
  • (U_i, V_i) \neq (U_j, V_j) \, (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
U_1 V_1
\vdots
U_M V_M

Output

Print the answer.


Sample Input 1

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

Sample Output 1

2

(a, b, c) = (1, 4, 5), (2, 3, 5) satisfy the conditions.


Sample Input 2

3 1
1 2

Sample Output 2

0

Sample Input 3

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

Sample Output 3

4
E - Adjacent Swaps

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 個のボールが左右一列に並んでいます。初め、左から i \, (1 \leq i \leq N) 番目のボールには整数 i が書かれています。

高橋君は Q 回の操作を行いました。 i \, (1 \leq i \leq Q) 回目に行われた操作は次のようなものです。

  • 整数 x_i が書かれているボールをその右隣のボールと入れ替える。ただし、整数 x_i が書かれているボールが元々右端にあった場合、代わりに左隣のボールと入れ替える。

操作後において左から i \, (1 \leq i \leq N) 番目のボールに書かれている整数を a_i とします。 a_1,\ldots,a_N を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq x_i \leq N
  • 入力は全て整数

入力

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

N Q
x_1
\vdots
x_Q

出力

a_1,\ldots,a_N を空白区切りで出力せよ。


入力例 1

5 5
1
2
3
4
5

出力例 1

1 2 3 5 4

操作は以下のように行われます。

  • 1 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 2,1,3,4,5 となる。
  • 2 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
  • 3 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,4,3,5 となる。
  • 4 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
  • 5 と書かれたボールは右端にあるので左隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,5,4 となる。

入力例 2

7 7
7
7
7
7
7
7
7

出力例 2

1 2 3 4 5 7 6

入力例 3

10 6
1
5
2
9
6
6

出力例 3

1 2 3 4 5 7 6 8 10 9

Score : 300 points

Problem Statement

N balls are lined up in a row from left to right. Initially, the i-th (1 \leq i \leq N) ball from the left has an integer i written on it.

Takahashi has performed Q operations. The i-th (1 \leq i \leq Q) operation was as follows.

  • Swap the ball with the integer x_i written on it with the next ball to the right. If the ball with the integer x_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.

Let a_i be the integer written on the i-th (1 \leq i \leq N) ball after the operations. Find a_1,\ldots,a_N.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq x_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
x_1
\vdots
x_Q

Output

Print a_1,\ldots,a_N, with spaces in between.


Sample Input 1

5 5
1
2
3
4
5

Sample Output 1

1 2 3 5 4

The operations are performed as follows.

  • Swap the ball with 1 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,5 written on them, from left to right.
  • Swap the ball with 2 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
  • Swap the ball with 3 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,5 written on them, from left to right.
  • Swap the ball with 4 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
  • Swap the ball with 5 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,4 written on them, from left to right.

Sample Input 2

7 7
7
7
7
7
7
7
7

Sample Output 2

1 2 3 4 5 7 6

Sample Input 3

10 6
1
5
2
9
6
6

Sample Output 3

1 2 3 4 5 7 6 8 10 9
F - Max - Min Query

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

整数の多重集合 S があります。はじめ S は空です。

Q 個のクエリが与えられるので順に処理してください。 クエリは次の 3 種類のいずれかです。

  • 1 x : Sx1 個追加する。

  • 2 x c : S から x\mathrm{min}(c, (S に含まれる x の個数 )) 個削除する。

  • 3 : (S の最大値 )- (S の最小値 ) を出力する。このクエリを処理するとき、 S が空でないことが保証される。

制約

  • 1 \leq Q \leq 2\times 10^5
  • 0 \leq x \leq 10^9
  • 1 \leq c \leq Q
  • 3 のクエリを処理するとき、S は空でない。
  • 入力は全て整数

入力

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

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

i 番目のクエリを表す \mathrm{query}_i は以下の 3 種類のいずれかである。

1 x
2 x c
3 

出力

3 のクエリに対する答えを順に改行区切りで出力せよ。


入力例 1

8
1 3
1 2
3
1 2
1 7
3
2 2 3
3

出力例 1

1
5
4

多重集合 S は以下のように変化します。

  • 1 番目のクエリ : S3 を追加する。S\lbrace3 \rbrace となる。
  • 2 番目のクエリ : S2 を追加する。S\lbrace2, 3\rbrace となる。
  • 3 番目のクエリ : S = \lbrace 2, 3\rbrace の最大値は 3 、最小値は 2 なので、 3-2=1 を出力する。
  • 4 番目のクエリ : S2 を追加する。S\lbrace2,2,3 \rbrace となる。
  • 5 番目のクエリ : S7 を追加する。S\lbrace2, 2,3, 7\rbrace となる。
  • 6 番目のクエリ : S = \lbrace2,2,3, 7\rbrace の最大値は 7 、最小値は 2 なので、 7-2=5 を出力する。
  • 7 番目のクエリ : S に含まれる 2 の個数は 2 個なので、 \mathrm{min(2,3)} = 2 個の 2S から削除する。S\lbrace3, 7\rbrace となる。
  • 8 番目のクエリ : S = \lbrace3, 7\rbrace の最大値は 7 、最小値は 3 なので、 7-3=4 を出力する。

入力例 2

4
1 10000
1 1000
2 100 3
1 10

出力例 2


クエリ 3 が含まれない場合、何も出力してはいけません。

Score : 300 points

Problem Statement

We have a multiset of integers S, which is initially empty.

Given Q queries, process them in order. Each query is of one of the following types.

  • 1 x: Insert an x into S.

  • 2 x c: Remove an x from S m times, where m = \mathrm{min}(c,( the number of x's contained in S)).

  • 3 : Print ( maximum value of S)-( minimum value of S). It is guaranteed that S is not empty when this query is given.

Constraints

  • 1 \leq Q \leq 2\times 10^5
  • 0 \leq x \leq 10^9
  • 1 \leq c \leq Q
  • When a query of type 3 is given, S is not empty.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

\mathrm{query}_i, which denotes the i-th query, is in one of the following formats:

1 x
2 x c
3 

Output

Print the answers for the queries of type 3 in the given order, separated by newlines.


Sample Input 1

8
1 3
1 2
3
1 2
1 7
3
2 2 3
3

Sample Output 1

1
5
4

The multiset S transitions as follows.

  • 1-st query: insert 3 into S. S is now \lbrace 3 \rbrace.
  • 2-nd query: insert 2 into S. S is now \lbrace 2, 3 \rbrace.
  • 3-rd query: the maximum value of S = \lbrace 2, 3\rbrace is 3 and its minimum value is 2, so print 3-2=1.
  • 4-th query: insert 2 into S. S is now \lbrace 2,2,3 \rbrace.
  • 5-th query: insert 7 into S. S is now \lbrace 2, 2,3, 7\rbrace.
  • 6-th query: the maximum value of S = \lbrace 2,2,3, 7\rbrace is 7 and its minimum value is 2, so print 7-2=5.
  • 7-th query: since there are two 2's in S and \mathrm{min(2,3)} = 2, remove 2 from S twice. S is now \lbrace 3, 7\rbrace.
  • 8-th query: the maximum value of S = \lbrace 3, 7\rbrace is 7 and its minimum value is 3, so print 7-3=4.

Sample Input 2

4
1 10000
1 1000
2 100 3
1 10

Sample Output 2


If the given queries do not contain that of type 3, nothing should be printed.

G - At Most 3 (Contestant ver.)

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

整数 W が与えられます。
あなたは以下の条件をすべて満たすようにいくつかのおもりを用意することにしました。

  • おもりの個数は 1 個以上 300 個以下である。
  • おもりの重さは 10^6 以下の正整数である。
  • 1 以上 W 以下のすべての正整数は 良い整数 である。ここで、以下の条件を満たす正整数 n を良い整数と呼ぶ。
    • 用意したおもりのうち \bf{3} 個以下 の異なるおもりを自由に選んで、選んだおもりの重さの和を n にすることができる。  

条件を満たすようなおもりの組を 1 つ出力してください。

制約

  • 1 \leq W \leq 10^6
  • W は整数

入力

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

W

出力

N をおもりの個数、A_ii 番目のおもりの重さとして、以下の形式で出力せよ。答えが複数存在する場合、どれを出力しても正解とみなされる。

N
A_1 A_2 \dots A_N

ただし、N および A_1,A_2,\dots,A_N は以下の条件を満たす必要がある。

  • 1 \leq N \leq 300
  • 1 \leq A_i \leq 10^6

入力例 1

6

出力例 1

3
1 2 3

上の出力は重さ 1 のおもり、重さ 2 のおもり、重さ 3 のおもりの 3 個のおもりを用意しています。
この出力は条件を満たしています。特に 3 番目の条件について、以下のようにおもりを選ぶことで 1 以上 W 以下の整数すべてが良い整数であることが確認できます。

  • 1 番目のおもりのみを選ぶと、重さの和は 1 になる。
  • 2 番目のおもりのみを選ぶと、重さの和は 2 になる。
  • 3 番目のおもりのみを選ぶと、重さの和は 3 になる。
  • 1 番目と 3 番目のおもりを選ぶと、重さの和は 4 になる。
  • 2 番目と 3 番目のおもりを選ぶと、重さの和は 5 になる。
  • 1 番目、2 番目と 3 番目のおもりを選ぶと、重さの和は 6 になる。

入力例 2

12

出力例 2

6
2 5 1 2 5 1

同じ重さのおもりを 2 個以上用意しても良いです。

Score : 400 points

Problem Statement

You are given an integer W.
You are going to prepare some weights so that all of the conditions below are satisfied.

  • The number of weights is between 1 and 300, inclusive.
  • Each weight has a mass of positive integer not exceeding 10^6.
  • Every integer between 1 and W, inclusive, is a good integer. Here, a positive integer n is said to be a good integer if the following condition is satisfied:
    • We can choose at most 3 different weights from the prepared weights with a total mass of n.

Print a combination of weights that satisfies the conditions.

Constraints

  • 1 \leq W \leq 10^6
  • W is an integer.

Input

Input is given from Standard Input in the following format:

W

Output

Print in the following format, where N is the number of weights and A_i is the mass of the i-th weight. If multiple solutions exist, printing any of them is accepted.

N
A_1 A_2 \dots A_N

Here, N and A_1,A_2,\dots,A_N should satisfy the following conditions:

  • 1 \leq N \leq 300
  • 1 \leq A_i \leq 10^6

Sample Input 1

6

Sample Output 1

3
1 2 3

In the output above, 3 weights with masses 1, 2, and 3 are prepared.
This output satisfies the conditions. Especially, regarding the 3-rd condition, we can confirm that every integer between 1 and W, inclusive, is a good integer.

  • If we choose only the 1-st weight, it has a total mass of 1.
  • If we choose only the 2-nd weight, it has a total mass of 2.
  • If we choose only the 3-rd weight, it has a total mass of 3.
  • If we choose the 1-st and the 3-rd weights, they have a total mass of 4.
  • If we choose the 2-nd and the 3-rd weights, they have a total mass of 5.
  • If we choose the 1-st, the 2-nd, and the 3-rd weights, they have a total mass of 6.

Sample Input 2

12

Sample Output 2

6
2 5 1 2 5 1

You may prepare multiple weights with the same mass.

H - Average and Median

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

N 枚のカードがあり、i \, (1 \leq i \leq N) 番目のカードには整数 A_i が書かれています。

高橋君は、これらのカードから好きな枚数選びます。ただし、各 i \, (1 \leq i \leq N - 1) について、i 番目のカードと i + 1 番目のカードの少なくとも一方を選ぶ必要があります。

以下の値を求めてください。

  • 選んだカードに書かれた整数の平均値としてあり得る最大値
  • 選んだカードに書かれた整数の中央値としてあり得る最大値

ただし、n 個の整数の中央値は、それらのうち小さい方から数えて \lceil \frac{n}{2} \rceil 番目であるものとします。ここで、\lceil x \rceilx 以上の最小の整数を表します。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^{9}
  • 入力は全て整数である。

入力

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

N
A_1 \ldots A_N

出力

2 行出力せよ。1 行目には選んだカードに書かれた整数の平均値としてあり得る最大値を、2 行目には選んだカードに書かれた整数の中央値としてあり得る最大値を出力せよ。 平均値の出力については、正しい値との相対誤差または絶対誤差が 10^{-3} 以下であれば正答とみなされる。


入力例 1

6
2 1 2 1 1 10

出力例 1

4
2

2 番目、4 番目、6 番目のカードを選ぶと、書かれた整数の平均は \frac{12}{3} = 4 となり、これが最大です。

1 番目、3 番目、5 番目、6 番目のカードを選ぶと、書かれた整数の中央値は 2 となり、これが最大です。


入力例 2

7
3 1 4 1 5 9 2

出力例 2

5.250000000
4

平均値の出力については誤差が認められるので、例えば 5.2491 と出力しても正答とみなされます。ただし、中央値は正確な値を出力しなければなりません。

Score : 500 points

Problem Statement

We have N cards. The i-th card (1 \leq i \leq N) has an integer A_i written on it.

Takahashi will choose any number of cards from these. However, for each i (1 \leq i \leq N - 1), at least one of the i-th and (i+1)-th cards must be chosen.

Find the following values.

  • The maximum possible average of the integers written on the chosen cards
  • The maximum possible median of the integers written on the chosen cards

Here, the median of the n integers is defined to be the \lceil \frac{n}{2} \rceil-th smallest of them, where \lceil x \rceil is the smallest integer not less than x.

Constraints

  • 2 \leq N \leq 10^5
  • 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
A_1 \ldots A_N

Output

Print two lines. The first and second lines should contain the maximum possible average and maximum possible median of the integers written on the chosen cards, respectively. For the average, your output will be considered correct when its relative or absolute error from the exact answer is at most 10^{-3}.


Sample Input 1

6
2 1 2 1 1 10

Sample Output 1

4
2

Choosing the 2-nd, 4-th, and 6-th cards makes the average of the written integers \frac{12}{3} = 4, which is the maximum possible.

Choosing the 1-st, 3-rd, 5-th, and 6-th cards makes the median of the written integers 2, which is the maximum possible.


Sample Input 2

7
3 1 4 1 5 9 2

Sample Output 2

5.250000000
4

For the average, your output may contain some degree of error: for example, the output 5.2491 is still considered correct. For the median, however, the exact value must be printed.

I - Cumulative Cumulative Cumulative Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

N,Q および A=(A_1,\ldots,A_N) が与えられます。
以下のクエリを Q 個処理してください。クエリは次の 2 種類のいずれかです。

  • 1 x v : A_xv に更新する。
  • 2 x : B_i=\sum_{j=1}^{i}A_jC_i=\sum_{j=1}^{i}B_jD_i=\sum_{j=1}^{i}C_j としたときの D_x\bmod\ 998244353 で出力する。

制約

  • 1 \leq N \leq 2\times10^5
  • 1 \leq Q \leq 2\times10^5
  • 0 \leq A_i \leq 10^9
  • 1 \leq x \leq N
  • 0 \leq v \leq 10^9
  • 入力に含まれる値は全て整数である

入力

入力は以下の形式で標準入力から与えられる。ここで {\rm query}_ii 番目に処理するクエリである。

N Q
A_1 A_2 \ldots A_N
{\rm query}_1
{\rm query}_2
\vdots
{\rm query}_Q

各クエリは以下の 2 種類のいずれかの形式で与えられる。

1 x v
2 x

出力

クエリへの答えを改行区切りで出力せよ。


入力例 1

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

出力例 1

15
9

1 番目のクエリの時点で A=(1,2,3) であるため、B=(1,3,6)C=(1,4,10)D=(1,5,15) となり、D_3=15 です。

3 番目のクエリの時点で A=(1,0,3) であるため、B=(1,1,4)C=(1,2,6)D=(1,3,9) となり、D_3=9 です。


入力例 2

2 1
998244353 998244353
2 1

出力例 2

0

Score : 500 points

Problem Statement

You are given N, Q, and A=(A_1,\ldots,A_N).
Process Q queries, each of which is of one of the following two kinds:

  • 1 x v: update A_x to v.
  • 2 x: let B_i=\sum_{j=1}^{i}A_j, C_i=\sum_{j=1}^{i}B_j, and D_i=\sum_{j=1}^{i}C_j. Print D_x modulo 998244353.

Constraints

  • 1 \leq N \leq 2\times10^5
  • 1 \leq Q \leq 2\times10^5
  • 0 \leq A_i \leq 10^9
  • 1 \leq x \leq N
  • 0 \leq v \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format, where {\rm query}_i denotes the i-th query to be processed:

N Q
A_1 A_2 \ldots A_N
{\rm query}_1
{\rm query}_2
\vdots
{\rm query}_Q

Each query is given in one of the following two formats:

1 x v
2 x

Output

Print the answer to the queries, with newlines in between.


Sample Input 1

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

Sample Output 1

15
9

When the 1-st query is given, A=(1,2,3), so B=(1,3,6), C=(1,4,10), and D=(1,5,15); thus, D_3=15.

When the 3-rd query is given, A=(1,0,3), so B=(1,1,4), C=(1,2,6), and D=(1,3,9); thus, D_3=9.


Sample Input 2

2 1
998244353 998244353
2 1

Sample Output 2

0