A - Treasure Chest

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

3 種類の文字 . | * からなる、長さ N の文字列 S が与えられます。 S には | がちょうど 2 つ、* がちょうど 1 つ含まれます。

2 つの | で囲まれた部分の中に * が含まれるか判定してください。 含まれている場合 in と、含まれていない場合 out と出力してください。

より厳密には、* より前にある文字のいずれかが | であり、かつ、* より後ろにある文字のいずれかが | であるか判定してください。

制約

  • 3\leq N\leq 100
  • N は整数
  • S. | * からなる長さ N の文字列
  • S| はちょうど 2 個含まれる
  • S* はちょうど 1 個含まれる

入力

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

N
S

出力

2 つの | に囲まれた部分の中に * が含まれている場合 in と、含まれていない場合 out1 行に出力せよ。


入力例 1

10
.|..*...|.

出力例 1

in

2 つの | に囲まれた部分は |..*...| です。 この中に * が含まれているため、in と出力してください。


入力例 2

10
.|..|.*...

出力例 2

out

2 つの | に囲まれた部分は |..| です。 この中に * は含まれていないため、out と出力してください。


入力例 3

3
|*|

出力例 3

in

Score : 100 points

Problem Statement

You are given a string S of length N consisting of three kinds of characters: ., |, and *. S contains exactly two | and exactly one *.

Determine whether the * is between the two |, and if so, print in; otherwise, print out.

More formally, determine whether one of the characters before the * is | and one of the characters after the * is |.

Constraints

  • 3\leq N\leq 100
  • N is an integer.
  • S is a string of length N consisting of ., |, and *.
  • S contains exactly two |.
  • S contains exactly one *.

Input

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

N
S

Output

Print a single line containing in if the * is between the two |, and out otherwise.


Sample Input 1

10
.|..*...|.

Sample Output 1

in

Between the two |, we have |..*...|, which contains *, so you should print in.


Sample Input 2

10
.|..|.*...

Sample Output 2

out

Between the two |, we have |..|, which does not contain *, so you should print out.


Sample Input 3

3
|*|

Sample Output 3

in
B - Trick Taking

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

プレイヤー 1 、プレイヤー 2\ldots 、プレイヤー N番号がつけられた N 人のプレイヤーがカードゲームで対戦します。
各プレイヤーはカードを 1 枚場に出します。

各カードは2 つの属性を持ち、どちらの属性も正整数で表されます。
i = 1, 2, \ldots, N について、プレイヤー i が場に出したカードの色は C_i であり、値は R_i です。 R_1, R_2, \ldots, R_N はすべて異なります。

N 人のプレイヤーの中から 1 人の勝者を下記の方法で決めます。

  • 色が T であるカードが 1 枚以上場に出された場合、色が T であるカードのうち値が最大のものを出したプレイヤーが勝者である。
  • 色が T であるカードが場に 1 枚も出されなかった場合、プレイヤー 1 が出したカードと同じ色のカードのうち値が最大のものを出したプレイヤーが勝者である。(プレイヤー 1 自身も勝者となり得ることに注意してください。)

勝者となるプレイヤーの番号を出力してください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq T \leq 10^9
  • 1 \leq C_i \leq 10^9
  • 1 \leq R_i \leq 10^9
  • i \neq j \implies R_i \neq R_j
  • 入力はすべて整数

入力

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

N T
C_1 C_2 \ldots C_N
R_1 R_2 \ldots R_N

出力

答えを出力せよ。


入力例 1

4 2
1 2 1 2
6 3 4 5

出力例 1

4

色が 2 であるカードが 1 枚以上場に出されています。 よって、色が 2 であるカードのうち値が最大の 5 のカードを出した、プレイヤー 4 が勝者です。


入力例 2

4 2
1 3 1 4
6 3 4 5

出力例 2

1

色が 2 であるカードが 1 枚も場に出されていません。 よって、プレイヤー 1 が出したカードの色と同じ色(すなわち色 1 )のカードのうち値が最大の 6 のカードを出した、プレイヤー 1 が勝者です。


入力例 3

2 1000000000
1000000000 1
1 1000000000

出力例 3

1

Score : 200 points

Problem Statement

N players with ID numbers 1, 2, \ldots, N are playing a card game.
Each player plays one card.

Each card has two parameters: color and rank, both of which are represented by positive integers.
For i = 1, 2, \ldots, N, the card played by player i has a color C_i and a rank R_i. All of R_1, R_2, \ldots, R_N are different.

Among the N players, one winner is decided as follows.

  • If one or more cards with the color T are played, the player who has played the card with the greatest rank among those cards is the winner.
  • If no card with the color T is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 1 is the winner. (Note that player 1 may win.)

Print the ID number of the winner.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq T \leq 10^9
  • 1 \leq C_i \leq 10^9
  • 1 \leq R_i \leq 10^9
  • i \neq j \implies R_i \neq R_j
  • All values in the input are integers.

Input

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

N T
C_1 C_2 \ldots C_N
R_1 R_2 \ldots R_N

Output

Print the answer.


Sample Input 1

4 2
1 2 1 2
6 3 4 5

Sample Output 1

4

Cards with the color 2 are played. Thus, the winner is player 4, who has played the card with the greatest rank, 5, among those cards.


Sample Input 2

4 2
1 3 1 4
6 3 4 5

Sample Output 2

1

No card with the color 2 is played. Thus, the winner is player 1, who has played the card with the greatest rank, 6, among the cards with the color of the card played by player 1 (color 1).


Sample Input 3

2 1000000000
1000000000 1
1 1000000000

Sample Output 3

1
C - Dango

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

正の整数 L に対して、 レベル L のダンゴ文字列とは、以下の条件を満たす文字列です。

  • o- からなる長さ L+1 の文字列である。
  • 先頭の文字と末尾の文字のうちちょうど一方が - であり、そのほかの L 文字はすべて o である。

例えば、ooo- はレベル 3 のダンゴ文字列ですが、-ooo-ooo-oo- などはダンゴ文字列ではありません(より正確には、どのような正の整数 L に対してもレベル L のダンゴ文字列ではありません)。

2 種類の文字 o - からなる、長さ N の文字列 S が与えられます。 次の条件を満たすような正整数 X のうち、最大のものを求めてください。

  • S の連続する部分文字列であって、レベル X のダンゴ文字列であるものが存在する。

ただし、そのような整数が存在しない場合、-1 と出力してください。

制約

  • 1\leq N\leq 2\times10^5
  • So - からなる長さ N の文字列

入力

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

N
S

出力

S にレベル X のダンゴ文字列が含まれるような最大の X の値を 1 行で出力せよ。 そのような値が存在しない場合、-1 を出力せよ。


入力例 1

10
o-oooo---o

出力例 1

4

たとえば、S3 文字目から 7 文字目までに対応する部分文字列 oooo- は、レベル 4 のダンゴ文字列です。 S の部分文字列であってレベル 5 以上のダンゴ文字列であるようなものは存在しないため、4 と出力してください。


入力例 2

1
-

出力例 2

-1

S の連続する部分文字列は空文字列と -2 種類だけです。 これらはダンゴ文字列ではないため、-1 と出力してください。


入力例 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

出力例 3

7

Score : 300 points

Problem Statement

For a positive integer L, a level-L dango string is a string that satisfies the following conditions.

  • It is a string of length L+1 consisting of o and -.
  • Exactly one of the first character and the last character is -, and the other L characters are o.

For instance, ooo- is a level-3 dango string, but none of -ooo-, oo, and o-oo- is a dango string (more precisely, none of them is a level-L dango string for any positive integer L).

You are given a string S of length N consisting of the two characters o and -. Find the greatest positive integer X that satisfies the following condition.

  • There is a contiguous substring of S that is a level-X dango string.

If there is no such integer, print -1.

Constraints

  • 1\leq N\leq 2\times10^5
  • S is a string of length N consisting of o and -.

Input

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

N
S

Output

Print the greatest positive integer X such that S contains a level-X dango string, or -1 if there is no such integer.


Sample Input 1

10
o-oooo---o

Sample Output 1

4

For instance, the substring oooo- corresponding to the 3-rd through 7-th characters of S is a level-4 dango string. No substring of S is a level-5 dango string or above, so you should print 4.


Sample Input 2

1
-

Sample Output 2

-1

Only the empty string and - are the substrings of S. They are not dango strings, so you should print -1.


Sample Input 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

Sample Output 3

7
D - Find by Query

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

ジャッジが 01 のみからなる長さ N の文字列 S = S_1S_2\ldots S_N を持っています。 文字列 S は、S_1 = 0 および S_N = 1 を満たします。

あなたには S の長さ N が与えられますが、S 自体は与えられません。 その代わり、あなたはジャッジに対して以下の質問を 20 回まで行うことができます。

  • 1 \leq i \leq N を満たす整数 i を選び、S_i の値を尋ねる。

1 \leq p \leq N-1 かつ S_p \neq S_{p+1} を満たす整数 p1 個出力してください。
なお、本問題の条件下でそのような整数 p が必ず存在することが示せます。

制約

  • 2 \leq N \leq 2 \times 10^5

入出力

最初に、文字列 S の長さ N を標準入力から受け取ってください。

N

次に、あなたはジャッジに対して問題文中の質問を 20 回まで繰り返すことができます。

質問は、以下の形式で標準出力に出力してください。 ここで、i1 \leq i \leq N を満たす整数でなければなりません。

? i

これに対する応答として、S_i の値が次の形式で標準入力から与えられます。

S_i

ここで、S_i0 または 1 です。

問題文中の条件を満たす整数 p を見つけたら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。

! p

答えが複数ある場合、どれを出力しても正解とみなされます。

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
  • 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
  • 文字列 S はあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。

入出力例

以下は、N = 7, S = 0010011 の場合の入出力例です。

入力 出力 説明
7 N が与えられます。
? 1 S_1 が何かをジャッジに質問します。
0 質問に対する答えとして S_1 = 0 がジャッジから返されます。
? 6 S_6 が何かをジャッジに質問します。
1 質問に対する答えとして S_6 = 1 がジャッジから返されます。
? 5 S_5 が何かをジャッジに質問します。
0 質問に対する答えとして S_5 = 0 がジャッジから返されます。
! 5 問題文中の条件を満たす整数 p として、p = 5 を解答します。

解答した p = 5 について、1 \leq p \leq N-1 かつ S_p \neq S_{p+1} が成り立ちます。 よって、この後ただちにプログラムを終了することで、正解と判定されます。

Score : 400 points

Problem Statement

This is an interactive task, where your program and the judge interact via Standard Input and Output.

The judge has a string of length N consisting of 0 and 1: S = S_1S_2\ldots S_N. Here, S_1 = 0 and S_N = 1.

You are given the length N of S, but not the contents of S. Instead, you can ask the judge at most 20 questions as follows.

  • Choose an integer i such that 1 \leq i \leq N and ask the value of S_i.

Print an integer p such that 1 \leq p \leq N-1 and S_p \neq S_{p+1}.
It can be shown that such p always exists under the settings of this problem.

Constraints

  • 2 \leq N \leq 2 \times 10^5

Input and Output

First, receive the length N of the string S from Standard Input:

N

Then, you get to ask the judge at most 20 questions as described in the problem statement.

Print each question to Standard Output in the following format, where i is an integer satisfying 1 \leq i \leq N:

? i

In response to this, the value of S_i will be given from Standard Input in the following format:

S_i

Here, S_i is 0 or 1.

When you find an integer p satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:

! p

If multiple solutions exist, you may print any of them.

Notes

  • Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
  • If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
  • After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
  • The string S will be fixed at the start of the interaction and will not be changed according to your questions or other factors.

Sample Input and Output

In the following interaction, N = 7 and S = 0010011.

Input Output Description
7 N is given.
? 1 Ask the value of S_1.
0 The judge responds with S_1 = 0.
? 6 Ask the value of S_6.
1 The judge responds with S_6 = 1.
? 5 Ask the value of S_5.
0 The judge responds with S_5 = 0.
! 5 Present p = 5 as an integer satisfying the condition.

For the presented p = 5, we have 1 \leq p \leq N-1 and S_p \neq S_{p+1}. Thus, if the program immediately quits here, this case will be judged as correctly solved.

E - Nearest Black Vertex

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

N 個の頂点と M 本の辺からなる、単純(自己ループおよび多重辺を含まない)かつ連結な無向グラフが与えられます。
i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結ぶ無向辺です。

各頂点を白または黒で塗る方法であって、下記の 2 つの条件をともに満たすものが存在するかを判定し、存在する場合はその一例を示してください。

  • 1 個以上の頂点が黒で塗られている。
  • すべての i = 1, 2, \ldots, K について、下記の条件が成り立つ。
    • 頂点 p_i と「黒で塗られた頂点のうち頂点 p_i からの距離が最小であるもの」の距離がちょうど d_i である。

ここで、頂点 u と頂点 v の距離は、uv を結ぶパスの辺の本数としてあり得る最小値として定義されます。

制約

  • 1 \leq N \leq 2000
  • N-1 \leq M \leq \min\lbrace N(N-1)/2, 2000 \rbrace
  • 1 \leq u_i, v_i \leq N
  • 0 \leq K \leq N
  • 1 \leq p_1 \lt p_2 \lt \cdots \lt p_K \leq N
  • 0 \leq d_i \leq N
  • 与えられるグラフは単純かつ連結
  • 入力はすべて整数

入力

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
K
p_1 d_1
p_2 d_2
\vdots
p_K d_K

出力

問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しない場合は、No を出力せよ。
存在する場合は、下記の形式の通り、1 行目に Yes と出力し、2 行目に各頂点を塗る方法を表す文字列 S を出力せよ。 ここで、S は長さ N の文字列であり、i = 1, 2, \ldots, N について Si 文字目は、頂点 i を黒で塗るとき 1 、白で塗るとき 0 である。

Yes
S

答えが複数ある場合、どれを出力しても正解とみなされる。


入力例 1

5 5
1 2
2 3
3 1
3 4
4 5
2
1 0
5 2

出力例 1

Yes
10100

例えば、頂点 1, 3 を黒に、頂点 2, 4, 5 を白に塗るという方法が、問題文中の条件を満たします。
実際、i = 1, 2, 3, 4, 5 について、頂点 i と「黒で塗られた頂点のうち頂点 i からの距離が最小であるもの」の距離を A_i で表すと、 (A_1, A_2, A_3, A_4, A_5) = (0, 1, 0, 1, 2) であり、特に、A_1 = 0, A_5 = 2 が成り立ちます。


入力例 2

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

出力例 2

No

問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しないため、No を出力します。


入力例 3

1 0
0

出力例 3

Yes
1

Score : 500 points

Problem Statement

You are given a simple connected undirected graph with N vertices and M edges (a simple graph contains no self-loop and no multi-edges).
For i = 1, 2, \ldots, M, the i-th edge connects vertex u_i and vertex v_i bidirectionally.

Determine whether there is a way to paint each vertex black or white to satisfy both of the following conditions, and show one such way if it exists.

  • At least one vertex is painted black.
  • For every i = 1, 2, \ldots, K, the following holds:
    • the minimum distance between vertex p_i and a vertex painted black is exactly d_i.

Here, the distance between vertex u and vertex v is the minimum number of edges in a path connecting u and v.

Constraints

  • 1 \leq N \leq 2000
  • N-1 \leq M \leq \min\lbrace N(N-1)/2, 2000 \rbrace
  • 1 \leq u_i, v_i \leq N
  • 0 \leq K \leq N
  • 1 \leq p_1 \lt p_2 \lt \cdots \lt p_K \leq N
  • 0 \leq d_i \leq N
  • The given graph is simple and connected.
  • All values in the input are integers.

Input

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
K
p_1 d_1
p_2 d_2
\vdots
p_K d_K

Output

If there is no way to paint each vertex black or white to satisfy the conditions, print No.
Otherwise, print Yes in the first line, and a string S representing a coloring of the vertices in the second line, as shown below.
Here, S is a string of length N such that, for each i = 1, 2, \ldots, N, the i-th character of S is 1 if vertex i is painted black and 0 if white.

Yes
S

If multiple solutions exist, you may print any of them.


Sample Input 1

5 5
1 2
2 3
3 1
3 4
4 5
2
1 0
5 2

Sample Output 1

Yes
10100

One way to satisfy the conditions is to paint vertices 1, 3 black and vertices 2, 4, 5 white.
Indeed, for each i = 1, 2, 3, 4, 5, let A_i denote the minimum distance between vertex i and a vertex painted black, and we have (A_1, A_2, A_3, A_4, A_5) = (0, 1, 0, 1, 2), where A_1 = 0, A_5 = 2.


Sample Input 2

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

Sample Output 2

No

There is no way to satisfy the conditions by painting each vertex black or white, so you should print No.


Sample Input 3

1 0
0

Sample Output 3

Yes
1
F - Square Subsequence

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

英小文字のみからなる文字列 S が与えられます。 下記の条件を満たす空でない文字列 T の個数を 998244353 で割ったあまりを出力してください。

T2 つ連結して得られる文字列 TT が、S に(連続とは限らない)部分列として含まれる。

制約

  • S は英小文字のみからなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

ababbaba

出力例 1

8

問題文中の条件を満たす文字列 T は、aaaabababbababbb8 個です。


入力例 2

zzz

出力例 2

1

問題文中の条件を満たす文字列 T は、z のみです。 S = S_1S_2S_3 = zzz から、文字列 zz を部分列として得る方法は、 S_1S_2 = zzS_1S_3 = zzS_2S_3 = zz3 通りありますが、文字列 z は答えに 1 回だけ寄与することに注意してください。


入力例 3

ppppqqppqqqpqpqppqpqqqqpppqppq

出力例 3

580

Score : 500 points

Problem Statement

You are given a string S consisting of lowercase English letters. Print the number of non-empty strings T that satisfy the following condition, modulo 998244353.

The concatenation TT of two copies of T is a subsequence of S (not necessarily contiguous).

Constraints

  • S is a string consisting of lowercase English letters whose length is between 1 and 100, inclusive.

Input

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

S

Output

Print the answer.


Sample Input 1

ababbaba

Sample Output 1

8

The eight strings satisfying the condition are a, aa, ab, aba, b, ba, bab, and bb.


Sample Input 2

zzz

Sample Output 2

1

The only string satisfying the condition is z. Note that this string contributes to the answer just once, although there are three ways to extract the subsequence zz from S = S_1S_2S_3 = zzz: S_1S_2 = zz, S_1S_3 = zz, and S_2S_3 = zz.


Sample Input 3

ppppqqppqqqpqpqppqpqqqqpppqppq

Sample Output 3

580
G - Minimum Permutation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

1 以上 M 以下の整数からなる長さ N の数列 A があります。ここで、1 以上 M 以下のどの整数も A1 回以上登場します。

A の長さ M の(連続とは限らない)部分列であって 1, \ldots, M1 回ずつ登場するもののうち、辞書順最小のものを答えてください。

制約

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq M
  • 1 以上 M 以下のどの整数も A1 回以上登場する。
  • 入力中の値はすべて整数である。

入力

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

N M
A_1 A_2 \ldots A_N

出力

求めるべき部分列を B_1, \ldots, B_M として、以下の形式で出力せよ。

B_1 B_2 \ldots B_M

入力例 1

4 3
2 3 1 3

出力例 1

2 1 3

A の長さ 3 の部分列であって 1, 2, 31 回ずつ登場するものは (2, 3, 1)(2, 1, 3) であり、このうち辞書順で小さいのは (2, 1, 3) です。


入力例 2

4 4
2 3 1 4

出力例 2

2 3 1 4

入力例 3

20 10
6 3 8 5 8 10 9 3 6 1 8 3 3 7 4 7 2 7 8 5

出力例 3

3 5 8 10 9 6 1 4 2 7

Score : 600 points

Problem Statement

We have a sequence A of length N consisting of integers between 1 and M. Here, every integer from 1 to M appears at least once in A.

Among the length-M subsequences of A where each of 1, \ldots, M appears once, find the lexicographically smallest one.

Constraints

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq M
  • Every integer between 1 and M, inclusive, appears at least once in A.
  • All values in the input are integers.

Input

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

N M
A_1 A_2 \ldots A_N

Output

Let B_1, \ldots, B_M be the sought subsequence, and print it in the following format:

B_1 B_2 \ldots B_M

Sample Input 1

4 3
2 3 1 3

Sample Output 1

2 1 3

The length-3 subsequences of A where each of 1, 2, 3 appears once are (2, 3, 1) and (2, 1, 3). The lexicographically smaller among them is (2, 1, 3).


Sample Input 2

4 4
2 3 1 4

Sample Output 2

2 3 1 4

Sample Input 3

20 10
6 3 8 5 8 10 9 3 6 1 8 3 3 7 4 7 2 7 8 5

Sample Output 3

3 5 8 10 9 6 1 4 2 7
Ex - Dice Sum Infinity

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

高橋くんは、偏りがない 6 面サイコロ 1 個と、10^9 未満の正の整数 R1 個持っています。 サイコロを 1 度振ると 1,2,3,4,5,6 のいずれかの整数の目が出ます。 どの整数の目が出るかは同様に確からしく、サイコロを複数回振ったとき、何回目に出た目の値も互いに独立です。

高橋くんは、次の操作を行います。 はじめ、C=0 です。

  1. サイコロを振り、C の値を 1 増やす。
  2. これまでに出た目の合計を X とし、X-R10^9 の倍数になったら、操作をやめる。
  3. 1. に戻る。

操作が終了したときの C の期待値を {}\bmod 998244353 で求めてください。

注意

この問題の制約のもとで、C の期待値は既約分数 p/q として表せ、かつ xq \equiv p\pmod{998244353} を満たす整数 x\ (0\leq x\lt998244353) がただひとつ存在することが示せます。 このような x を出力してください。

制約

  • 0\lt R\lt10^9
  • R は整数

入力

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

R

出力

答えを 1 行で出力せよ。


入力例 1

1

出力例 1

291034221

操作が終了したときの C の期待値はおよそ 833333333.619047619 で、{}\bmod 998244353 では 291034221 です。


入力例 2

720357616

出力例 2

153778832

Score : 600 points

Problem Statement

Takahashi has an unbiased six-sided die and a positive integer R less than 10^9. Each time the die is cast, it shows one of the numbers 1,2,3,4,5,6 with equal probability, independently of the outcomes of the other trials.

Takahashi will perform the following procedure. Initially, C=0.

  1. Cast the die and increment C by 1.
  2. Let X be the sum of the numbers shown so far. If X-R is a multiple of 10^9, quit the procedure.
  3. Go back to step 1.

Find the expected value of C at the end of the procedure, modulo 998244353.

Notes

Under the constraints of this problem, it can be shown that the expected value of C is represented as an irreducible fraction p/q, and there is a unique integer x\ (0\leq x\lt998244353) such that xq \equiv p\pmod{998244353}. Print this x.

Constraints

  • 0\lt R\lt10^9
  • R is an integer.

Input

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

R

Output

Print a single line containing the answer.


Sample Input 1

1

Sample Output 1

291034221

The expected value of C at the end of the procedure is approximately 833333333.619047619, and 291034221 when represented modulo 998244353.


Sample Input 2

720357616

Sample Output 2

153778832