A - Your First Judge

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

配点 : 100

問題文

文字列 S が与えられるので、この文字列が Hello,World! と完全に一致するなら AC 、そうでないなら WA と出力してください。

「完全に一致する」とは?文字列 AB が完全に一致するとは、文字列 AB の長さが等しく、かつ全ての 1 \le i \le |A| を満たす整数 i について A の先頭から i 文字目と B の先頭から i 文字目とが(英大文字か小文字かも含めて)一致することを指します。

制約

  • 1 \le |S| \le 15
  • S は英大小文字, ,, ! のみからなる

入力

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

S

出力

答えを出力せよ。


入力例 1

Hello,World!

出力例 1

AC

文字列 SHello,World! と完全に一致します。


入力例 2

Hello,world!

出力例 2

WA

先頭から 7 文字目の W が、 Hello,World! では大文字ですが S では小文字です。よって SHello,World! と一致しません。


入力例 3

Hello!World!

出力例 3

WA

Score : 100 points

Problem Statement

Given a string S, print AC if it perfectly matches Hello,World!; otherwise, print WA.

What is a perfect match?Strings A is said to perfectly match B when the length of A is equal to that of B, and the i-th character of A is the same as the i-th character of B for every integer i such that 1 \le i \le |A|.

Constraints

  • 1 \le |S| \le 15
  • S consists of English lowercase letters, English uppercase letters, ,, and !.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer.


Sample Input 1

Hello,World!

Sample Output 1

AC

The string S perfectly matches Hello,World!.


Sample Input 2

Hello,world!

Sample Output 2

WA

The seventh character from the beginning should be an uppercase W in Hello,World!, but S has a lowercase w in that position. Thus, S does not match Hello,World!.


Sample Input 3

Hello!World!

Sample Output 3

WA
B - Lacked Number

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

配点 : 100

問題文

数字のみからなる、長さがちょうど 9 の文字列 S が与えられます。
S には 0 から 9 までのうち、ちょうど 1 つの数字を除いた 9 種類の数字が一度ずつ登場します。

S に登場しない唯一の数字を出力してください。

制約

  • S は数字のみからなる長さ 9 の文字列である。
  • S の文字はすべて相異なる。

入力

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

S

出力

S に登場しない唯一の数字を出力せよ。


入力例 1

023456789

出力例 1

1

文字列 023456789 には 1 のみが登場していません。 よって、1 を出力します。


入力例 2

459230781

出力例 2

6

文字列 459230781 には 6 のみが登場していません。 よって、6 を出力します。

文字列に数字が現れる順番は昇順とは限らないので注意してください。

Score : 100 points

Problem Statement

You are given a string S of length exactly 9 consisting of digits. One but all digits from 0 to 9 appear exactly once in S.

Print the only digit missing in S.

Constraints

  • S is a string of length 9 consisting of digits.
  • All characters in S are distinct.

Input

Input is given from Standard Input in the following format:

S

Output

Print the only digit missing in S.


Sample Input 1

023456789

Sample Output 1

1

The string 023456789 only lacks 1. Thus, 1 should be printed.


Sample Input 2

459230781

Sample Output 2

6

The string 459230781 only lacks 6. Thus, 6 should be printed.

Note that the digits in the string may not appear in increasing order.

C - Minimize Ordering

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

配点 : 200

問題文

文字列 S が与えられます。S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力してください。

なお、相異なる 2 つの文字列 s = s_1 s_2 \ldots s_nt = t_1 t_2 \ldots t_m について、それらが以下の条件のいずれかを満たすとき、辞書順で s \lt t であるとします。

  • ある整数 i\ (1 \leq i \leq \min(n,m)) が存在し、s_i \lt t_i かつすべての整数 j\ (1 \leq j \lt i) について s_j=t_j
  • すべての整数 i\ (1 \leq i \leq \min(n,m)) について s_i = t_i かつ、n \lt m

制約

  • S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列

入力

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

S

出力

S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力せよ。


入力例 1

aba

出力例 1

aab

S= aba を並び替えて得られる文字列は以下の 3 つが考えられます。

  • aba
  • aab
  • baa

この中で辞書順で最小のものは、aab です。


入力例 2

zzzz

出力例 2

zzzz

Score : 200 points

Problem Statement

You are given a string S. Find the lexicographically smallest string S' obtained by permuting the characters of S.

Here, for different two strings s = s_1 s_2 \ldots s_n and t = t_1 t_2 \ldots t_m, s \lt t holds lexicographically when one of the conditions below is satisfied.

  • There is an integer i\ (1 \leq i \leq \min(n,m)) such that s_i \lt t_i and s_j=t_j for all integers j\ (1 \leq j \lt i).
  • s_i = t_i for all integers i\ (1 \leq i \leq \min(n,m)), and n \lt m.

Constraints

  • S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest string S' obtained by permuting the characters in S.


Sample Input 1

aba

Sample Output 1

aab

Three strings can be obtained by permuting aba:

  • aba
  • aab
  • baa

The lexicographically smallest among them is aab.


Sample Input 2

zzzz

Sample Output 2

zzzz
D - Everyone is Friends

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

配点 : 200

問題文

1,2,\ldots,N の番号がついた N 人の人がいます。

M 回の舞踏会が行われました。 i (1\leq i \leq M) 回目の舞踏会には k_i 人が参加し、参加した人は人 x_{i,1},x_{i,2},\ldots,x_{i,k_i} でした。

どの二人も少なくとも 1 回同じ舞踏会に参加したか判定してください。

制約

  • 2\leq N \leq 100
  • 1\leq M \leq 100
  • 2\leq k_i \leq N
  • 1\leq x_{i,1}<x_{i,2}<\ldots < x_{i,k_i}\leq N
  • 入力は全て整数

入力

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

N M
k_1 x_{1,1} x_{1,2} \ldots x_{1,k_1}
\vdots
k_M x_{M,1} x_{M,2} \ldots x_{M,k_M}

出力

どの二人も少なくとも 1 回同じ舞踏会に参加した場合 Yes を、そうでない場合 No を出力せよ。


入力例 1

3 3
2 1 2
2 2 3
2 1 3

出力例 1

Yes

1 と人 2 は共に 1 回目の舞踏会に参加しています。

2 と人 3 は共に 2 回目の舞踏会に参加しています。

1 と人 3 は共に 3 回目の舞踏会に参加しています。

以上よりどの二人も少なくとも 1 回同じ舞踏会に参加したので、答えは Yes です。


入力例 2

4 2
3 1 2 4
3 2 3 4

出力例 2

No

1 と人 31 回も同じ舞踏会に参加していないので、答えは No です。

Score : 200 points

Problem Statement

There are N people numbered 1,2,\ldots,N.

M parties were held. k_i people attended the i-th (1\leq i \leq M) party, and they were People x_{i,1},x_{i,2},\ldots,x_{i,k_i}.

Determine if every two people attended the same party at least once.

Constraints

  • 2\leq N \leq 100
  • 1\leq M \leq 100
  • 2\leq k_i \leq N
  • 1\leq x_{i,1}<x_{i,2}<\ldots < x_{i,k_i}\leq N
  • All values in the input are integers.

Input

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

N M
k_1 x_{1,1} x_{1,2} \ldots x_{1,k_1}
\vdots
k_M x_{M,1} x_{M,2} \ldots x_{M,k_M}

Output

Print Yes if every two people attended the same party at least once; print No otherwise.


Sample Input 1

3 3
2 1 2
2 2 3
2 1 3

Sample Output 1

Yes

Both Person 1 and Person 2 attended the 1-st party.

Both Person 2 and Person 3 attended the 2-nd party.

Both Person 1 and Person 3 attended the 3-rd party.

Therefore, every two people attended the same party at least once, so the answer is Yes.


Sample Input 2

4 2
3 1 2 4
3 2 3 4

Sample Output 2

No

Person 1 and Person 3 did not attend the same party, so the answer is No.

E - Merge Sequences

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

配点 : 300

問題文

長さ N の狭義単調増加列 A=(A _ 1,A _ 2,\ldots,A _ N) と、長さ M の狭義単調増加列 B=(B _ 1,B _ 2,\ldots,B _ M) が与えられます。 ここで、すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j が成り立っています。

長さ N+M の狭義単調増加列 C=(C _ 1,C _ 2,\ldots,C _ {N+M}) を、次の操作を行った結果得られる列として定めます。

  • CAB を連結した列とする。厳密には、i=1,2,\ldots,N について C _ i=A _ i とし、i=N+1,N+2,\ldots,N+M について C _ i=B _ {i-N} とする。
  • C を昇順にソートする。

A _ 1,A _ 2,\ldots,A _ NB _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるか求めてください。 より厳密には、まず i=1,2,\ldots,N について C _ k=A _ i を満たす k を順に求めたのち、j=1,2,\ldots,M について C _ k=B _ j を満たす k を順に求めてください。

制約

  • 1\leq N,M\leq 10^5
  • 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
  • 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
  • すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j
  • 入力はすべて整数

入力

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

N M
A _ 1 A _ 2 \ldots A _ N
B _ 1 B _ 2 \ldots B _ M

出力

答えを 2 行で出力せよ。
1 行目には A _ 1,A _ 2,\ldots,A _ N がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
2 行目には B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるかを空白区切りで出力せよ。


入力例 1

4 3
3 14 15 92
6 53 58

出力例 1

1 3 4 7
2 5 6

C(3,6,14,15,53,58,92) となります。 A=(3,14,15,92) の要素はそれぞれ 1,3,4,7 番目にあり、B=(6,53,58) の要素はそれぞれ 2,5,6 番目にあります。


入力例 2

4 4
1 2 3 4
100 200 300 400

出力例 2

1 2 3 4
5 6 7 8

入力例 3

8 12
3 4 10 15 17 18 22 30
5 7 11 13 14 16 19 21 23 24 27 28

出力例 3

1 2 5 9 11 12 15 20
3 4 6 7 8 10 13 14 16 17 18 19

Score : 300 points

Problem Statement

You are given strictly increasing sequences of length N and M: A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B _ 1,B _ 2,\ldots,B _ M). Here, A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).

Let C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+M that results from the following procedure.

  • Let C be the concatenation of A and B. Formally, let C _ i=A _ i for i=1,2,\ldots,N, and C _ i=B _ {i-N} for i=N+1,N+2,\ldots,N+M.
  • Sort C in ascending order.

For each of A _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M, find its position in C. More formally, for each i=1,2,\ldots,N, find k such that C _ k=A _ i, and for each j=1,2,\ldots,M, find k such that C _ k=B _ j.

Constraints

  • 1\leq N,M\leq 10^5
  • 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
  • 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
  • A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
  • 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
B _ 1 B _ 2 \ldots B _ M

Output

Print the answer in two lines.
The first line should contain the positions of A _ 1,A _ 2,\ldots,A _ N in C, with spaces in between.
The second line should contain the positions of B _ 1,B _ 2,\ldots,B _ M in C, with spaces in between.


Sample Input 1

4 3
3 14 15 92
6 53 58

Sample Output 1

1 3 4 7
2 5 6

C will be (3,6,14,15,53,58,92). Here, the 1-st, 3-rd, 4-th, 7-th elements are from A=(3,14,15,92), and the 2-nd, 5-th, 6-th elements are from B=(6,53,58).


Sample Input 2

4 4
1 2 3 4
100 200 300 400

Sample Output 2

1 2 3 4
5 6 7 8

Sample Input 3

8 12
3 4 10 15 17 18 22 30
5 7 11 13 14 16 19 21 23 24 27 28

Sample Output 3

1 2 5 9 11 12 15 20
3 4 6 7 8 10 13 14 16 17 18 19
F - LRUD Instructions 2

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

配点 : 300

問題文

二次元平面上に高橋君がいます。高橋君は原点から移動を N 回行いました。

N 回の移動は長さ N の文字列で表され、意味は次の通りです。

  • i 回目の高橋君の移動後の座標は、移動前の座標を (x,y) として、
    • Si 文字目が R であるとき (x+1,y)
    • Si 文字目が L であるとき (x-1,y)
    • Si 文字目が U であるとき (x,y+1)
    • Si 文字目が D であるとき (x,y-1)

N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあるかどうかを判定してください。

制約

  • 1 \leq N \leq 2\times 10^5
  • N は整数
  • SR, L, U, D のみからなる長さ N の文字列

入力

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

N
S

出力

N 回の移動 (始点と終点を含む) で、高橋君が同じ座標にいたことがあれば Yes、なければ No と出力せよ。


入力例 1

5
RLURU

出力例 1

Yes

高橋君のいる座標は (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2) と変化します。


入力例 2

20
URDDLLUUURRRDDDDLLLL

出力例 2

No

Score : 300 points

Problem Statement

Takahashi is on a two-dimensional plane. Starting from the origin, he made N moves.

The N moves are represented by a string of length N as described below:

  • Takahashi's coordinates after the i-th move are:

    • (x+1,y) if the i-th character of S is R;
    • (x-1,y) if the i-th character of S is L;
    • (x,y+1) if the i-th character of S is U; and
    • (x,y-1) if the i-th character of S is D,

    where (x,y) is his coordinates before the move.

Determine if Takahashi visited the same coordinates multiple times in the course of the N moves (including the starting and ending points).

Constraints

  • 1 \leq N \leq 2\times 10^5
  • N is an integer.
  • S is a string of length N consisting of R, L, U, and D.

Input

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

N
S

Output

Print Yes if Takahashi visited the same coordinates multiple times in the course of the N moves; print No otherwise.


Sample Input 1

5
RLURU

Sample Output 1

Yes

Takahashi's coordinates change as follows: (0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2).


Sample Input 2

20
URDDLLUUURRRDDDDLLLL

Sample Output 2

No
G - Unique Username

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

配点 : 400

問題文

高橋君はあるサービスで使うユーザー名を決めるのに困っています。彼を助けるプログラムを書いてください。

以下の条件をすべて満たす文字列 X1 つ求めてください。

  • X は次の手順で得られる文字列である。
    • N 個の文字列 S_1,S_2,\ldots,S_N を好きな順番で並べたものを S_1', S_2', \ldots,S_N' とする。そして、S_1'、( 1 個以上の _ )、S_2'、( 1 個以上の _ )、\ldots、( 1 個以上の _ )、S_N' をこの順番で連結したものを X とする。
  • X の文字数は 3 以上 16 以下である。
  • XM 個の文字列 T_1,T_2,\ldots,T_M のいずれとも一致しない。

ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 と出力してください。

制約

  • 1 \leq N \leq 8
  • 0 \leq M \leq 10^5
  • N,M は整数
  • 1 \leq |S_i| \leq 16
  • N-1+\sum{|S_i|} \leq 16
  • i \neq j ならば S_i \neq S_j
  • S_i は英小文字のみからなる文字列
  • 3 \leq |T_i| \leq 16
  • i \neq j ならば T_i \neq T_j
  • T_i は英小文字と _ のみからなる文字列

入力

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

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

出力

条件をすべて満たす文字列 X1 つ出力せよ。ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 を出力せよ。
答えが複数存在する場合、どれを出力しても良い。


入力例 1

1 1
chokudai
chokudai

出力例 1

-1

条件のうち 1 番目と 2 番目を満たす文字列は X= chokudai しかありませんが、これは T_1 と一致します。
このため、条件をすべて満たす文字列 X が存在せず、-1 が正しい出力となります。


入力例 2

2 2
choku
dai
chokudai
choku_dai

出力例 2

dai_choku

この他に、choku__dai (chokudai の間の _2 つ) 等も条件をすべて満たします。


入力例 3

2 2
chokudai
atcoder
chokudai_atcoder
atcoder_chokudai

出力例 3

-1

chokudai__atcoderatcoder__chokudai (chokudaiatcoder の間の _2 つ)は文字数が 17 なので 2 番目の条件を満たしません。


入力例 4

4 4
ab
cd
ef
gh
hoge
fuga
____
_ab_cd_ef_gh_

出力例 4

ab__ef___cd_gh

1 番目の条件で記述されている操作で得られないような文字列が T_i として与えられる場合があります。

Score : 400 points

Problem Statement

Takahashi is having trouble with deciding a username for a service. Write a code to help him.

Find a string X that satisfies all of the following conditions:

  • X is obtained by the following procedure:
    • Let S_1', S_2', \ldots,S_N' be a permutation of S_1, S_2, \ldots,S_N. Let X be the concatenation of S_1', (1 or more copies of _), S_2', (1 or more copies of _), \ldots, (1 or more copies of _), and S_N', in this order.
  • The length of X is between 3 and 16, inclusive.
  • X does not coincide with any of M strings T_1,T_2,\ldots,T_M.

If there is no X that satisfies all of the conditions, print -1 instead.

Constraints

  • 1 \leq N \leq 8
  • 0 \leq M \leq 10^5
  • N and M are integers.
  • 1 \leq |S_i| \leq 16
  • N-1+\sum{|S_i|} \leq 16
  • S_i \neq S_j if i \neq j.
  • S_i is a string consisting of lowercase English letters.
  • 3 \leq |T_i| \leq 16
  • T_i \neq T_j if i \neq j.
  • T_i is a string consisting of lowercase English letters and _.

Input

Input is given from Standard Input in the following format:

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

Output

Print a string X that satisfies all of the conditions. If there is no X that satisfies all of the conditions, print -1 instead.
If there are multiple solutions, print any of them.


Sample Input 1

1 1
chokudai
chokudai

Sample Output 1

-1

The only string that satisfies the first and second conditions is X= chokudai, but it coincides with T_1.
Thus, there is no X that satisfies all of the conditions, so -1 should be printed.


Sample Input 2

2 2
choku
dai
chokudai
choku_dai

Sample Output 2

dai_choku

Strings like choku__dai (which has two _'s between choku and dai) also satisfy all of the conditions.


Sample Input 3

2 2
chokudai
atcoder
chokudai_atcoder
atcoder_chokudai

Sample Output 3

-1

chokudai__atcoder and atcoder__chokudai (which have two _'s between chokudai and atcoder) have a length of 17, which violates the second condition.


Sample Input 4

4 4
ab
cd
ef
gh
hoge
fuga
____
_ab_cd_ef_gh_

Sample Output 4

ab__ef___cd_gh

The given T_i may contain a string that cannot be obtained by the procedure described in the first condition.

H - Subtree K-th Max

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

配点 : 500

問題文

N 頂点の根付き木があります。頂点には 1 から N の番号がついており、根は頂点 1 です。
i 番目の辺は頂点 A_iB_i を結んでいます。
頂点 i には整数 X_i が書かれています。

Q 個のクエリが与えられます。i 番目のクエリでは整数の組 (V_i,K_i) が与えられるので、次の問題に答えてください。

  • 問題:頂点 V_i の部分木に含まれる頂点に書かれた整数のうち、大きい方から K_i 番目の値を求めよ

制約

  • 2 \leq N \leq 10^5
  • 0\leq X_i\leq 10^9
  • 1\leq A_i,B_i\leq N
  • 1\leq Q \leq 10^5
  • 1\leq V_i\leq N
  • 1\leq K_i\leq 20
  • 与えられるグラフは木である
  • 頂点 V_i の部分木は頂点を K_i 個以上持つ
  • 入力に含まれる値は全て整数である

入力

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

N Q
X_1 \ldots X_N
A_1 B_1
\vdots
A_{N-1} B_{N-1}
V_1 K_1
\vdots
V_Q K_Q

出力

Q 行出力せよ。i 行目には i 番目のクエリに対する答えを出力せよ。


入力例 1

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

出力例 1

4
5

この入力において与えられる木は下図のようなものです。

図

1 番目のクエリでは、頂点 1 の部分木に含まれる頂点 1,2,3,4,5 に書かれた数のうち大きい方から 2 番目である 4 を出力します。
2 番目のクエリでは、頂点 2 の部分木に含まれる頂点 2,3,5 に書かれた数のうち大きい方から 1 番目である 5 を出力します。


入力例 2

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

出力例 2

9
10

入力例 3

4 4
1 10 100 1000
1 2
2 3
3 4
1 4
2 3
3 2
4 1

出力例 3

1
10
100
1000

Score : 500 points

Problem Statement

We have a rooted tree with N vertices. The vertices are numbered 1 through N, and the root is Vertex 1.
The i-th edge connects Vertices A_i and B_i.
Vertex i has an integer X_i written on it.

You are given Q queries. For the i-th query, given a pair of integers (V_i,K_i), answer the following question.

  • Question: among the integers written on the vertices in the subtree rooted at Vertex V_i, find the K_i-th largest value.

Constraints

  • 2 \leq N \leq 10^5
  • 0\leq X_i\leq 10^9
  • 1\leq A_i,B_i\leq N
  • 1\leq Q \leq 10^5
  • 1\leq V_i\leq N
  • 1\leq K_i\leq 20
  • The given graph is a tree.
  • The subtree rooted at Vertex V_i has K_i or more vertices.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
X_1 \ldots X_N
A_1 B_1
\vdots
A_{N-1} B_{N-1}
V_1 K_1
\vdots
V_Q K_Q

Output

Print Q lines. The i-th line should contain the response to the i-th query.


Sample Input 1

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

Sample Output 1

4
5

The tree given in this input is shown below.

figure

For the 1-st query, the vertices in the subtree rooted at Vertex 1 are Vertices 1, 2, 3, 4, and 5, so print the 2-nd largest value of the numbers written on these vertices, 4.
For the 2-nd query, the vertices in the subtree rooted at Vertex 2 are Vertices 2, 3, and 5, so print the 1-st largest value of the numbers written on these vertices, 5.


Sample Input 2

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

Sample Output 2

9
10

Sample Input 3

4 4
1 10 100 1000
1 2
2 3
3 4
1 4
2 3
3 2
4 1

Sample Output 3

1
10
100
1000
I - Integer Division

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

配点 : 500

問題文

10 進表記で N 桁の正整数 X が与えられます。X の各桁は 0 ではありません。
\lbrace 1,2, \ldots, N-1 \rbrace の部分集合 S に対し、f(S) を以下のように定義します。

X10 進表記したものを長さ N の文字列とみなし、i \in S のとき、またそのときに限り文字列の i 文字目と i + 1 文字目に区切りを入れることで |S| + 1 個の文字列に分解する。
このようにして得られた |S|+1 個の文字列を 10 進表記された整数とみなし、f(S) をこれら |S|+1 個の整数の積で定める。

S としてあり得るものは空集合を含めて 2^{N-1} 通りありますが、これら全てに対する f(S) の総和を 998244353 で割った余りを求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • X10 進表記で N 桁で、各桁は 0 でない
  • 入力はすべて整数

入力

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

N
X

出力

答えを出力せよ。


入力例 1

3
234

出力例 1

418

S = \emptyset とすると、f(S) = 234 です。
S = \lbrace 1 \rbrace とすると、f(S) = 2 \times 34 = 68 です。
S = \lbrace 2 \rbrace とすると、f(S) = 23 \times 4 = 92 です。
S = \lbrace 1, 2 \rbrace とすると、f(S) = 2 \times 3 \times 4 = 24 です。
234 + 68 + 92 + 24 = 418 であるため、418 を出力します。


入力例 2

4
5915

出力例 2

17800

入力例 3

9
998244353

出力例 3

258280134

Score : 500 points

Problem Statement

You are given a positive integer X with N digits in decimal representation. None of the digits of X is 0.
For a subset S of \lbrace 1,2, \ldots, N-1 \rbrace , let f(S) be defined as follows.

See the decimal representation of X as a string of length N, and decompose it into |S| + 1 strings by splitting it between the i-th and (i + 1)-th characters if and only if i \in S.
Then, see these |S| + 1 strings as integers in decimal representation, and let f(S) be the product of these |S| + 1 integers.

There are 2^{N-1} subsets of \lbrace 1,2, \ldots, N-1 \rbrace , including the empty set, which can be S. Find the sum of f(S) over all these S, modulo 998244353.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • X has N digits in decimal representation, none of which is 0.
  • All values in the input are integers.

Input

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

N
X

Output

Print the answer.


Sample Input 1

3
234

Sample Output 1

418

For S = \emptyset, we have f(S) = 234.
For S = \lbrace 1 \rbrace, we have f(S) = 2 \times 34 = 68.
For S = \lbrace 2 \rbrace, we have f(S) = 23 \times 4 = 92.
For S = \lbrace 1, 2 \rbrace, we have f(S) = 2 \times 3 \times 4 = 24.
Thus, you should print 234 + 68 + 92 + 24 = 418.


Sample Input 2

4
5915

Sample Output 2

17800

Sample Input 3

9
998244353

Sample Output 3

258280134