A - o-padding

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

整数 N および、英小文字からなる長さが N 未満 の文字列 S が与えられます。

長さが N になるまで S の先頭に英小文字 o を追加し続けることで得られる文字列を出力してください。

制約

  • 2\leq N \leq 100
  • N は整数
  • S は長さ 1 以上 N 未満の英小文字からなる文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

5
abc

出力例 1

ooabc

N=5S の長さは 3 であるため、S の先頭に o5-3=2 個追加した文字列が答えとなります。


入力例 2

2
o

出力例 2

oo

入力例 3

12
vgxgpuam

出力例 3

oooovgxgpuam

Score : 100 points

Problem Statement

You are given an integer N and a string S consisting of lowercase English letters with length less than N.

Print the string obtained by repeatedly adding the lowercase English letter o to the beginning of S until its length becomes N.

Constraints

  • 2\leq N \leq 100
  • N is an integer.
  • S is a string consisting of lowercase English letters with length between 1 and N - 1, inclusive.

Input

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

N
S

Output

Print the answer.


Sample Input 1

5
abc

Sample Output 1

ooabc

Since N=5 and the length of S is 3, the answer is the string obtained by adding 5-3=2 os to the beginning of S.


Sample Input 2

2
o

Sample Output 2

oo

Sample Input 3

12
vgxgpuam

Sample Output 3

oooovgxgpuam
B - Wrong Answer

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

0 以上 9 以下の整数 A, B が与えられます。

0 以上 9 以下の整数であって A + B と等しくないものをいずれかひとつ出力してください。

制約

  • 0 \leq A \leq 9
  • 0 \leq B \leq 9
  • A + B \leq 9
  • A, B は整数

入力

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

A B

出力

0 以上 9 以下の整数であって A + B と等しくないものをいずれかひとつ出力せよ。


入力例 1

2 5

出力例 1

2

A = 2, B = 5 のとき A + B = 7 です。したがって、0, 1, 2, 3, 4, 5, 6, 8, 9 のいずれかを出力すると正解となります。


入力例 2

0 0

出力例 2

9

入力例 3

7 1

出力例 3

4

Score: 100 points

Problem Statement

You are given two integers A and B, each between 0 and 9, inclusive.

Print any integer between 0 and 9, inclusive, that is not equal to A + B.

Constraints

  • 0 \leq A \leq 9
  • 0 \leq B \leq 9
  • A + B \leq 9
  • A and B are integers.

Input

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

A B

Output

Print any integer between 0 and 9, inclusive, that is not equal to A + B.


Sample Input 1

2 5

Sample Output 1

2

When A = 2, B = 5, we have A + B = 7. Thus, printing any of 0, 1, 2, 3, 4, 5, 6, 8, 9 is correct.


Sample Input 2

0 0

Sample Output 2

9

Sample Input 3

7 1

Sample Output 3

4
C - Enlarged Checker Board

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

A 行、横 B 列のマスからなるタイルを縦 N 行、横 N 列に並べてできた、縦 (A\times N) 行、横 (B\times N) 列のマス目 X があります。
1\leq i,j \leq N について、上から i 行目、左から j 列目のタイルをタイル (i,j) とします。

X の各マスは以下のように塗られています。

  • 各タイルは白いタイルまたは黒いタイルである。
  • 白いタイルのすべてのマスは白で塗られ、黒いタイルのすべてのマスは黒で塗られている。
  • タイル (1,1) は白いタイルである。
  • 辺で隣接する 2 つのタイルは異なる色のタイルである。ただし、タイル (a,b) とタイル (c,d) が辺で隣接するとは、|a-c|+|b-d|=1 ( |x|x の絶対値とする)であることを言う。

マス目 X を出力の形式に従って出力してください。

制約

  • 1 \leq N,A,B \leq 10
  • 入力は全て整数

入力

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

N A B

出力

次の条件をみたす (A\times N) 個の文字列 S_1,\ldots,S_{A\times N} を改行区切りで出力せよ。

  • S_1,\ldots,S_{A\times N} はそれぞれ長さ (B\times N). または # からなる文字列である。
  • i,j (1 \leq i \leq A\times N,1 \leq j \leq B\times N) に対し、マス目 X の上から i 行目かつ左から j 列目のマスが白で塗られているならば S_ij 文字目は .であり、黒く塗られているならば # である。

入力例 1

4 3 2

出力例 1

..##..##
..##..##
..##..##
##..##..
##..##..
##..##..
..##..##
..##..##
..##..##
##..##..
##..##..
##..##..

入力例 2

5 1 5

出力例 2

.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....

入力例 3

4 4 1

出力例 3

.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.
.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.

入力例 4

1 4 4

出力例 4

....
....
....
....

Score : 200 points

Problem Statement

Tiles are aligned in N horizontal rows and N vertical columns. Each tile has a grid with A horizontal rows and B vertical columns. On the whole, the tiles form a grid X with (A\times N) horizontal rows and (B\times N) vertical columns.
For 1\leq i,j \leq N, Tile (i,j) denotes the tile at the i-th row from the top and the j-th column from the left.

Each square of X is painted as follows.

  • Each tile is either a white tile or a black tile.
  • Every square in a white tile is painted white; every square in a black tile is painted black.
  • Tile (1,1) is a white tile.
  • Two tiles sharing a side have different colors. Here, Tile (a,b) and Tile (c,d) are said to be sharing a side if and only if |a-c|+|b-d|=1 (where |x| denotes the absolute value of x).

Print the grid X in the format specified in the Output section.

Constraints

  • 1 \leq N,A,B \leq 10
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print (A\times N) strings S_1,\ldots,S_{A\times N} that satisfy the following condition, with newlines in between.

  • Each of S_1,\ldots,S_{A\times N} is a string of length (B\times N) consisting of . and #.
  • For each i and j (1 \leq i \leq A\times N,1 \leq j \leq B\times N), the j-th character of S_i is . if the square at the i-th row from the top and j-th column from the left in grid X is painted white; the character is # if the square is painted black.

Sample Input 1

4 3 2

Sample Output 1

..##..##
..##..##
..##..##
##..##..
##..##..
##..##..
..##..##
..##..##
..##..##
##..##..
##..##..
##..##..

Sample Input 2

5 1 5

Sample Output 2

.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....
#####.....#####.....#####
.....#####.....#####.....

Sample Input 3

4 4 1

Sample Output 3

.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.
.#.#
.#.#
.#.#
.#.#
#.#.
#.#.
#.#.
#.#.

Sample Input 4

1 4 4

Sample Output 4

....
....
....
....
D - Four Hidden

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

英小文字と ? からなる文字列 T と、英小文字のみからなる文字列 U が与えられます。

T は、英小文字のみからなる文字列 S のちょうど 4 文字を ? で置き換えることで得られた文字列です。

SU を連続部分文字列として含んでいた可能性があるかどうか判定してください。

制約

  • T は長さ 4 以上 10 以下の英小文字と ? からなる文字列
  • T にはちょうど 4 つの ? が含まれる
  • U は長さ 1 以上 |T| 以下の英小文字からなる文字列

入力

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

T
U

出力

SU を部分文字列として含んでいた可能性があるならば Yes を、そうでないならば No を出力せよ。


入力例 1

tak??a?h?
nashi

出力例 1

Yes

例えば、Stakanashi である場合、これは nashi を連続部分文字列として含みます。


入力例 2

??e??e
snuke

出力例 2

No

? がどのような文字であっても、Ssnuke を連続部分文字列として含むことがありません。


入力例 3

????
aoki

出力例 3

Yes

Score : 250 points

Problem Statement

You are given a string T consisting of lowercase English letters and ?, and a string U consisting of lowercase English letters.

The string T is obtained by taking some lowercase-only string S and replacing exactly four of its characters with ?.

Determine whether it is possible that the original string S contained U as a contiguous substring.

Constraints

  • T is a string of length between 4 and 10, inclusive, consisting of lowercase letters and ?.
  • T contains exactly four occurrences of ?.
  • U is a string of length between 1 and |T|, inclusive, consisting of lowercase letters.

Input

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

T
U

Output

Print Yes if it is possible that the original string S contained U as a contiguous substring; otherwise, print No.


Sample Input 1

tak??a?h?
nashi

Sample Output 1

Yes

For example, if S is takanashi, it contains nashi as a contiguous substring.


Sample Input 2

??e??e
snuke

Sample Output 2

No

No matter what characters replace the ?s in T, S cannot contain snuke as a contiguous substring.


Sample Input 3

????
aoki

Sample Output 3

Yes
E - Robot Takahashi

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

子供と大人があわせて N 人います。i 番目の人の体重は W_i です。
それぞれの人が子供か大人かは、01 からなる長さ N の文字列 S によって表され、
Si 文字目が 0 であるとき i 番目の人が子供であることを、1 であるとき i 番目の人が大人であることをさします。

ロボットである高橋君に対して実数 X を設定すると、 高橋君はそれぞれの人に対して、体重が X 未満なら子供、X 以上なら大人と判定します。
実数 X に対してf(X) を、高橋君に X を設定したときに N 人のうち子供か大人かを正しく判定できる人数で定めます。

X が実数全体を動くとき、f(X) の最大値を求めてください。

制約

  • 1\leq N\leq 2\times 10^5
  • S01 からなる長さ N の文字列
  • 1\leq W_i\leq 10^9
  • N,W_i は整数

入力

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

N
S
W_1 W_2 \ldots W_N

出力

f(X) の最大値を整数で一行に出力せよ。


入力例 1

5
10101
60 45 30 40 80

出力例 1

4

X=50 と設定すると、高橋君は 2,3,4 番目の人を子供、 1,5 番目の人を大人と判定します。
実際には 2,4 番目の人が子供、 1,3,5 番目の人が大人であるので、このとき、1,2,4,5 番目の合計 4 人に対して正しく判定できています。 よって、f(50)=4 です。

5 人全員に対して正しく判定できるような X は存在しないのでこのときが最大です。よって、4 を出力します。


入力例 2

3
000
1 2 3

出力例 2

3

例えば、X=10 とすると最大値 f(10)=3 を達成します。
全員が大人、または全員が子供である可能性もあることに注意してください。


入力例 3

5
10101
60 50 50 50 60

出力例 3

4

例えば、X=55 とすると最大値 f(55)=4 を達成します。
同じ体重の人が複数人存在する可能性もあることに注意してください。

Score : 300 points

Problem Statement

There are N people, each of whom is either a child or an adult. The i-th person has a weight of W_i.
Whether each person is a child or an adult is specified by a string S of length N consisting of 0 and 1.
If the i-th character of S is 0, then the i-th person is a child; if it is 1, then the i-th person is an adult.

When Takahashi the robot is given a real number X, Takahashi judges a person with a weight less than X to be a child and a person with a weight more than or equal to X to be an adult.
For a real value X, let f(X) be the number of people whom Takahashi correctly judges whether they are children or adults.

Find the maximum value of f(X) for all real values of X.

Constraints

  • 1\leq N\leq 2\times 10^5
  • S is a string of length N consisting of 0 and 1.
  • 1\leq W_i\leq 10^9
  • N and W_i are integers.

Input

Input is given from Standard Input in the following format:

N
S
W_1 W_2 \ldots W_N

Output

Print the maximum value of f(X) as an integer in a single line.


Sample Input 1

5
10101
60 45 30 40 80

Sample Output 1

4

When Takahashi is given X=50, it judges the 2-nd, 3-rd, and 4-th people to be children and the 1-st and 5-th to be adults.
In reality, the 2-nd and 4-th are children, and the 1-st, 3-rd, and 5-th are adults, so the 1-st, 2-nd, 4-th, and 5-th people are correctly judged. Thus, f(50)=4.

This is the maximum since there is no X that judges correctly for all 5 people. Thus, 4 should be printed.


Sample Input 2

3
000
1 2 3

Sample Output 2

3

For example, X=10 achieves the maximum value f(10)=3.
Note that the people may be all children or all adults.


Sample Input 3

5
10101
60 50 50 50 60

Sample Output 3

4

For example, X=55 achieves the maximum value f(55)=4.
Note that there may be multiple people with the same weight.

F - Understory

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

高橋くんは、庭にある木の本数を管理しています。はじめ、庭に木は 1 本もありません。

Q 個のクエリが順に与えられます。クエリは次の 2 種類のいずれかです。各クエリを処理した直後に庭にある木の本数を出力してください。

  • 1 h : 庭に高さ h の木を新たに 1 本追加する。
  • 2 h : いま庭にある木のうち、高さが h 以下の木をすべて削除する。

制約

  • 1 \le Q \le 3 \times 10^5
  • 1 \le h \le 10^9
  • 入力される値は全て整数

入力

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

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

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

1 h
2 h

出力

Q 行出力せよ。

i 行目には i 番目のクエリを処理した直後の庭にある木の本数を出力せよ。


入力例 1

5
1 5
1 7
1 8
2 7
1 3

出力例 1

1
2
3
1
2

以下のように木の本数は変化します。

  • 高さ 5 の木が追加される。庭にある木は高さ 51 本である。
  • 高さ 7 の木が追加される。庭にある木は高さ 5, 72 本である。
  • 高さ 8 の木が追加される。庭にある木は高さ 5, 7, 83 本である。
  • 高さ 7 以下の木が削除される。庭にある木は高さ 81 本である。
  • 高さ 3 の木が追加される。庭にある木は高さ 8, 32 本である。

入力例 2

12
2 256601193
1 85138616
1 202564041
2 276477192
1 55551662
1 170271057
2 754166580
1 854388209
1 772036624
2 651124113
1 301137866
2 290875185

出力例 2

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

Score : 300 points

Problem Statement

Takahashi is managing the number of trees in his garden. Initially, there are no trees in the garden.

Q queries are given in order. Each query is one of the following two types. Immediately after processing each query, output the number of trees currently in the garden.

  • 1 h : Add one new tree of height h to the garden.
  • 2 h : Remove all trees currently in the garden whose height is at most h.

Constraints

  • 1 \le Q \le 3 \times 10^5
  • 1 \le h \le 10^9
  • 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

\text{query}_i, representing the i-th query, is one of the following two types:

1 h
2 h

Output

Output Q lines.

The i-th line should contain the number of trees in the garden immediately after processing the i-th query.


Sample Input 1

5
1 5
1 7
1 8
2 7
1 3

Sample Output 1

1
2
3
1
2

The number of trees changes as follows.

  • A tree of height 5 is added. The garden contains one tree of height 5.
  • A tree of height 7 is added. The garden contains two trees of heights 5, 7.
  • A tree of height 8 is added. The garden contains three trees of heights 5, 7, 8.
  • Trees of height at most 7 are removed. The garden contains one tree of height 8.
  • A tree of height 3 is added. The garden contains two trees of heights 8, 3.

Sample Input 2

12
2 256601193
1 85138616
1 202564041
2 276477192
1 55551662
1 170271057
2 754166580
1 854388209
1 772036624
2 651124113
1 301137866
2 290875185

Sample Output 2

0
1
2
0
1
2
0
1
2
2
3
3
G - Paid Walk

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

N 頂点 M 辺の(単純とは限らない)有向グラフがあり、頂点は頂点 1, 2, \ldots, N と番号付けられています。
i 番目 (1\leq i\leq M) の辺は頂点 U_i から頂点 V_i へ向かう辺で、コストは C_i です。 また、各頂点の出次数は 4 以下です。

次の条件をみたす頂点 v (1\leq v\leq N) をすべて求めてください。

頂点 1 から頂点 v への経路であって、次の条件をともにみたすものが存在する。

  • ちょうど L 回辺を通る。このとき、同じ辺を複数回通っても良いが、通るたびに回数にカウントされる。
  • 通った辺のコストの総和が S 以上 T 以下である。(同じ辺を複数回通った場合、通るたびに総和に加算されるものとする。)
出次数 とは 頂点 u の出次数は、頂点 u から出て行く辺の数を指します。辺の向かう先が同じ頂点であるような辺であっても重ねて数えられます。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq M\leq 2\times 10^5
  • 1\leq L \leq 10
  • 1\leq S\leq T \leq 10^9
  • 1\leq U_i,V_i\leq N
  • 1\leq C_i\leq 10^8
  • 各頂点の出次数は高々 4 である。
  • 入力はすべて整数

入力

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

N M L S T
U_1 V_1 C_1
U_2 V_2 C_2
\vdots
U_M V_M C_M

出力

条件をみたす頂点を 昇順に 空白区切りで出力せよ。
条件をみたす頂点が存在しない場合は空行を出力せよ。


入力例 1

5 8 3 80 100
1 2 20
1 3 70
2 1 30
2 5 10
3 2 10
3 4 30
3 5 20
5 1 70

出力例 1

1 5

与えられるグラフは下図左のようになっています。各辺のコストはその辺の始点のそばに示されています。

このとき、以下のようになります。

  • 頂点 1 から頂点 1 への経路について、頂点 1 \to 頂点 2 \to 頂点 5 \to 頂点 1 (上図中央)を考えると、これはちょうど 3 本の辺を通り、通る辺のコストの総和は 20+10+70=100 であるため、条件をみたしています。
  • 頂点 1 から頂点 2 への経路であって、条件をみたすような経路は存在しません。ちょうど 3 本の辺を通るような経路としては、頂点 1 \to 頂点 2 \to 頂点 1 \to 頂点 2 が存在しますが、この経路において通る辺のコストの総和は 20+30+20=70 であり特に 80 より小さいため、条件をみたしていません。
  • 頂点 1 から頂点 3 への経路であって、条件をみたすような経路は存在しません。ちょうど 3 本の辺を通るような経路としては、頂点 1 \to 頂点 2 \to 頂点 1 \to 頂点 3 が存在しますが、この経路において通る辺のコストの総和は 20+30+70=120 であり特に 100 より大きいため、条件をみたしていません。
  • 頂点 1 から頂点 4 への経路であって、条件をみたすような経路は存在しません。
  • 頂点 1 から頂点 5 への経路について、頂点 1 \to 頂点 3 \to 頂点 2 \to 頂点 5 (上図右)を考えると、これはちょうど 3 本の辺を通り、通る辺のコストの総和は 70+10+10=90 であるため、条件をみたしています。

よって、1, 5 をこの順に出力します。条件をみたす頂点を昇順に出力する必要があることに注意してください。


入力例 2

10 1 1 1 100
2 3 1

出力例 2


条件をみたす頂点が存在しない場合は空行を出力してください。


入力例 3

2 5 3 1 100
1 1 1
2 2 100
1 2 1
1 2 1
1 2 100

出力例 3

1 2

グラフは自己ループや多重辺を含む可能性があります。
なお、このテストケースにおけるグラフの頂点 1,2 からの出次数はそれぞれ 4,1 です。

Score : 400 points

Problem Statement

There is a directed graph (not necessarily simple) with N vertices and M edges, where the vertices are numbered as vertices 1, 2, \ldots, N.
The i-th (1\leq i\leq M) edge goes from vertex U_i to vertex V_i with cost C_i. Additionally, the out-degree of each vertex is at most 4.

Find all vertices v (1\leq v\leq N) that satisfy the following condition:

There exists a path from vertex 1 to vertex v that satisfies both of the following conditions:

  • It traverses exactly L edges. If the same edge is traversed multiple times, each traversal is counted.
  • The sum of the costs of the traversed edges is at least S and at most T. (If the same edge is traversed multiple times, the cost is added to the sum each time.)
What is out-degree? The out-degree of vertex u refers to the number of edges going out from vertex u. Even if multiple edges go to the same vertex, they are counted separately.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq M\leq 2\times 10^5
  • 1\leq L \leq 10
  • 1\leq S\leq T \leq 10^9
  • 1\leq U_i,V_i\leq N
  • 1\leq C_i\leq 10^8
  • The out-degree of each vertex is at most 4.
  • All input values are integers.

Input

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

N M L S T
U_1 V_1 C_1
U_2 V_2 C_2
\vdots
U_M V_M C_M

Output

Print the vertices that satisfy the condition in ascending order, separated by spaces.
If there are no vertices that satisfy the condition, print an empty line.


Sample Input 1

5 8 3 80 100
1 2 20
1 3 70
2 1 30
2 5 10
3 2 10
3 4 30
3 5 20
5 1 70

Sample Output 1

1 5

The given graph is as shown in the left figure below. The cost of each edge is shown near the starting vertex of that edge.

Here, the following holds:

  • For the path from vertex 1 to vertex 1, consider vertex 1 \to vertex 2 \to vertex 5 \to vertex 1 (center of the figure above). This traverses exactly three edges, and the sum of the costs of the traversed edges is 20+10+70=100, so it satisfies the condition.
  • There is no path from vertex 1 to vertex 2 that satisfies the condition. One path that traverses exactly three edges is vertex 1 \to vertex 2 \to vertex 1 \to vertex 2, but the sum of the costs of the edges traversed in this path is 20+30+20=70, which is less than 80, so it does not satisfy the condition.
  • There is no path from vertex 1 to vertex 3 that satisfies the condition. One path that traverses exactly three edges is vertex 1 \to vertex 2 \to vertex 1 \to vertex 3, but the sum of the costs of the edges traversed in this path is 20+30+70=120, which is greater than 100, so it does not satisfy the condition.
  • There is no path from vertex 1 to vertex 4 that satisfies the condition.
  • For the path from vertex 1 to vertex 5, consider vertex 1 \to vertex 3 \to vertex 2 \to vertex 5 (right of the figure above). This traverses exactly three edges, and the sum of the costs of the traversed edges is 70+10+10=90, so it satisfies the condition.

Therefore, print 1, 5 in this order. Note that you need to print those vertices that satisfy the condition in ascending order.


Sample Input 2

10 1 1 1 100
2 3 1

Sample Output 2


If there are no vertices that satisfy the condition, print an empty line.


Sample Input 3

2 5 3 1 100
1 1 1
2 2 100
1 2 1
1 2 1
1 2 100

Sample Output 3

1 2

The graph may contain self-loops and multiple edges.
In this test case, the out-degrees from vertices 1 and 2 are 4 and 1, respectively.

H - Arithmetic Number

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

以下の条件を満たす正の整数 n を、 等差数 と呼びます。

  • (n を先頭に余計な 0 を付けずに 10 進法で表記した際、) n の上から i 桁目を d_i とする。このとき、 nk 桁の整数であったとすると、 (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) が成立する。
    • この条件は、「 数列 (d_1,d_2,\dots,d_k) が等差数列である」と言い換えることができる。
    • 但し、 n1 桁の整数である時、 n は等差数であるものとする。

たとえば、 234,369,86420,17,95,8,11,777 は等差数ですが、 751,919,2022,246810,2356 は等差数ではありません。

等差数のうち、 X 以上で最小のものを求めてください。

制約

  • X1 以上 10^{17} 以下の整数である

入力

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

X

出力

答えを整数として出力せよ。


入力例 1

152

出力例 1

159

152 以上で最小の等差数は 159 です。


入力例 2

88

出力例 2

88

X 自身が等差数である場合もあります。


入力例 3

8989898989

出力例 3

9876543210

Score : 500 points

Problem Statement

Let us call a positive integer n that satisfies the following condition an arithmetic number.

  • Let d_i be the i-th digit of n from the top (when n is written in base 10 without unnecessary leading zeros.) Then, (d_2-d_1)=(d_3-d_2)=\dots=(d_k-d_{k-1}) holds, where k is the number of digits in n.
    • This condition can be rephrased into the sequence (d_1,d_2,\dots,d_k) being arithmetic.
    • If n is a 1-digit integer, it is assumed to be an arithmetic number.

For example, 234,369,86420,17,95,8,11,777 are arithmetic numbers, while 751,919,2022,246810,2356 are not.

Find the smallest arithmetic number not less than X.

Constraints

  • X is an integer between 1 and 10^{17} (inclusive).

Input

Input is given from Standard Input in the following format:

X

Output

Print the answer as an integer.


Sample Input 1

152

Sample Output 1

159

The smallest arithmetic number not less than 152 is 159.


Sample Input 2

88

Sample Output 2

88

X itself may be an arithmetic number.


Sample Input 3

8989898989

Sample Output 3

9876543210
I - Merge Slimes 2

実行時間制限: 3 sec / メモリ制限: 1024 MiB

配点 : 525

問題文

長さ N の非負整数列 A があり、最初はすべての要素が 0 です。 Q 個のクエリが与えられるので順に処理してください。
q 番目のクエリでは 1 \leq l_q \leq r_q \leq N を満たす整数 l_q,r_q と正整数 a_q が与えられるので、以下を順に行ってください。

  • A_{l_q}, A_{{l_q}+1}, \dots, A_{r_q}a_q を足す。
  • その後、M=r_q-l_q+1, \; B=(B_1,B_2,\dots,B_M)=(A_{l_q}, A_{l_q+1}, \dots, A_{r_q}) として、以下の問題の答えを求める。

M 個のスライム 1,2,\dots,M があって、m 個目のスライムの重さは B_m です。
2 個のスライムを選び、合成させるという操作を M-1 回繰り返します。
重さが x,y のスライムを合成させると重さ x+y のスライムが出現し、元の 2 個のスライムは消えます。このとき x \times y のコストがかかります。
M-1 回の操作のコストの総和としてあり得る値の最小値を 998244353 で割った余りを求めてください。

各クエリでの A に対する変更内容はその後にも引き継がれることに注意してください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq l_q \leq r_q \leq N
  • 1 \leq a_q \leq 10^9
  • 入力はすべて整数

入力

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

N Q
l_1 r_1 a_1
l_2 r_2 a_2
\vdots
l_Q r_Q a_Q

出力

答えを合計 Q 行で出力せよ。 q 行目には、q 番目のクエリの答えを出力せよ。


入力例 1

5 4
1 3 22
3 4 13
5 5 455
1 5 1000000000

出力例 1

1452
455
0
21421644

1 番目のクエリの後、A=(22,22,22,0,0) となり、B=(22,22,22) です。1 回目に 1 つ目のスライムと 3 つ目のスライムを合成すると、そのコストは 22 \times 22=484 です。次に残った 2 つのスライムを合成するとそのコストは 22 \times 44=968 です。このときコストの合計は 484+968=1452 です。また、コストの合計をこれよりも小さくすることはできません。
2 番目のクエリの後、A=(22,22,35,13,0) となり、B=(35,13) です。求める答えは 35 \times 13 = 455 です。

Score : 525 points

Problem Statement

There is a sequence A of N non-negative integers, all initially 0. Process Q queries given in order.
For the q-th query, you are given integers l_q, r_q satisfying 1 \leq l_q \leq r_q \leq N and a positive integer a_q. Perform the following in order:

  • Add a_q to each of A_{l_q}, A_{{l_q}+1}, \dots, A_{r_q}.
  • Then, letting M=r_q-l_q+1 and B=(B_1,B_2,\dots,B_M)=(A_{l_q}, A_{l_q+1}, \dots, A_{r_q}), find the answer to the following problem:

There are M slimes 1,2,\dots,M, where the m-th slime has weight B_m.
Repeat the operation of choosing two slimes and merging them M-1 times.
When slimes of weights x and y are merged, a slime of weight x+y appears and the original two slimes disappear. This incurs a cost of x \times y.
Find, modulo 998244353, the minimum possible total cost of the M-1 operations.

Note that the changes made on A in each query carry over to subsequent queries.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq l_q \leq r_q \leq N
  • 1 \leq a_q \leq 10^9
  • All input values are integers.

Input

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

N Q
l_1 r_1 a_1
l_2 r_2 a_2
\vdots
l_Q r_Q a_Q

Output

Output the answers over Q lines in total. The q-th line should contain the answer to the q-th query.


Sample Input 1

5 4
1 3 22
3 4 13
5 5 455
1 5 1000000000

Sample Output 1

1452
455
0
21421644

After the first query, A=(22,22,22,0,0) and B=(22,22,22). Merging the first and third slimes first incurs a cost of 22 \times 22=484. Then merging the remaining two slimes incurs a cost of 22 \times 44=968. The total cost is 484+968=1452. Moreover, the total cost cannot be made smaller than this.
After the second query, A=(22,22,35,13,0) and B=(35,13). The answer is 35 \times 13 = 455.