A - Not Found

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字からなる長さ 1 以上 25 以下の文字列 S が与えられます。
S に含まれない英小文字をひとつ出力してください。
但し、そのようなものが複数ある場合はどれを出力しても構いません。

制約

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

入力

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

S

出力

S に含まれない英小文字をひとつ出力せよ。そのようなものが複数ある場合はどれを出力しても構わない。


入力例 1

a

出力例 1

d

S= a です。
a 以外の英小文字、 b, c, ..., z が正解となります。


入力例 2

abcdfhijklmnopqrstuvwxyz

出力例 2

e

S 中に含まれない英小文字は eg です。


入力例 3

qazplwsxokmedcijnrfvuhbgt

出力例 3

y

Score : 100 points

Problem Statement

You are given a string S of length between 1 and 25 consisting of lowercase English letters.
Output one lowercase English letter that does not appear in S.
If there are multiple such letters, you may output any one of them.

Constraints

  • S is a string of length between 1 and 25 (inclusive) consisting of lowercase English letters.

Input

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

S

Output

Output one lowercase English letter that does not appear in S. If there are multiple such letters, you may output any one of them.


Sample Input 1

a

Sample Output 1

d

S= a.
Any lowercase English letter other than a (that is, b, c, …, or z) is a correct answer.


Sample Input 2

abcdfhijklmnopqrstuvwxyz

Sample Output 2

e

The lowercase English letters not included in S are e and g.


Sample Input 3

qazplwsxokmedcijnrfvuhbgt

Sample Output 3

y
B - Cyclic

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

各桁が 1 以上 9 以下の整数である 3 桁の整数 N が与えられます。

N100 の位を a10 の位を b1 の位を c としたとき、b,c,a をこの順に並べた整数と c,a,b をこの順に並べた整数をそれぞれ出力してください。

制約

  • N は各桁が 1 以上 9 以下の整数である 3 桁の整数

入力

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

N

出力

b,c,a をこの順に並べた整数と c,a,b をこの順に並べた整数をこの順で空白区切りで出力せよ。


入力例 1

379

出力例 1

793 937

379100 の位は 310 の位は 71 の位は 9 です。よって、793937 をそれぞれ出力します。


入力例 2

919

出力例 2

199 991

919100 の位は 910 の位は 11 の位は 9 です。よって、199991 をそれぞれ出力します。

Score : 100 points

Problem Statement

You are given a three-digit integer N where each digit is an integer between 1 and 9, inclusive.

Let a, b, c be the hundreds, tens, ones digits of N, respectively. Print an integer formed by arranging b, c, a in this order, and an integer formed by arranging c, a, b in this order.

Constraints

  • N is a three-digit integer where each digit is an integer between 1 and 9, inclusive.

Input

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

N

Output

Print two integers separated by a space in the following order: an integer formed by arranging b, c, a in this order, and an integer formed by arranging c, a, b in this order.


Sample Input 1

379

Sample Output 1

793 937

The hundreds, tens, ones digits of 379 are 3, 7, 9, respectively, so print 793 and 937.


Sample Input 2

919

Sample Output 2

199 991

The hundreds, tens, ones digits of 919 are 9, 1, 9, respectively, so print 199 and 991.

C - 3^A

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

正整数 M が与えられます。 以下の条件を全て満たす正整数 N と非負整数列 A=(A_1,A_2,\ldots,A_N) を一つ求めてください。

  • 1\le N\le 20
  • 0\le A_i\le 10 (1\le i\le N)
  • \displaystyle \sum_{i=1}^N 3^{A_i}=M

ただし、制約下では条件を満たす NA の組が必ず存在することが証明できます。

制約

  • 1\le M\le 10^5

入力

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

M

出力

以下の形式で条件を満たす NA を出力せよ。

N
A_1 A_2 \ldots A_N

なお、条件を満たす NA の組が複数存在する場合は、どれを出力しても正答となる。


入力例 1

6

出力例 1

2
1 1

N=2A=(1,1) とすると \displaystyle \sum_{i=1}^N 3^{A_i}=3+3=6 より全ての条件を満たします。

他に N=4A=(0,0,1,0) なども条件を満たします。


入力例 2

100

出力例 2

4
2 0 2 4

入力例 3

59048

出力例 3

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

1\le N\le 20 という制約に注意してください。

Score : 200 points

Problem Statement

You are given a positive integer M. Find a positive integer N and a sequence of non-negative integers A = (A_1, A_2, \ldots, A_N) that satisfy all of the following conditions:

  • 1 \le N \le 20
  • 0 \le A_i \le 10 (1 \le i \le N)
  • \displaystyle \sum_{i=1}^N 3^{A_i} = M

It can be proved that under the constraints, there always exists at least one such pair of N and A satisfying the conditions.

Constraints

  • 1 \le M \le 10^5

Input

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

M

Output

Print N and A satisfying the conditions in the following format:

N
A_1 A_2 \ldots A_N

If there are multiple valid pairs of N and A, any of them is acceptable.


Sample Input 1

6

Sample Output 1

2
1 1

For example, with N=2 and A=(1,1), we have \displaystyle \sum_{i=1}^N 3^{A_i} = 3+3=6, satisfying all conditions.

Another example is N=4 and A=(0,0,1,0), which also satisfies the conditions.


Sample Input 2

100

Sample Output 2

4
2 0 2 4

Sample Input 3

59048

Sample Output 3

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

Note the condition 1 \le N \le 20.

D - Cut .0

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

実数 X が小数点以下第 3 位まで与えられます。

実数 X を以下の条件を満たすように出力してください。

  • 小数点以下の部分について、末尾に 0 を付けない
  • 末尾に過剰な小数点を付けない

制約

  • 0 \le X < 100
  • X は小数点以下第 3 位まで与えられる

入力

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

X

出力

答えを出力せよ。


入力例 1

1.012

出力例 1

1.012

1.012 はそのまま出力しても構いません。


入力例 2

12.340

出力例 2

12.34

12.340 を末尾に 0 を付けずに出力すると 12.34 となります。


入力例 3

99.900

出力例 3

99.9

99.900 を末尾に 0 を付けずに出力すると 99.9 となります。


入力例 4

0.000

出力例 4

0

0.000 を末尾に 0 や過剰な小数点を付けずに出力すると 0 となります。

Score : 150 points

Problem Statement

A real number X is given to the third decimal place.

Print the real number X under the following conditions.

  • The decimal part must not have trailing 0s.
  • There must not be an unnecessary trailing decimal point.

Constraints

  • 0 \le X < 100
  • X is given to the third decimal place.

Input

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

X

Output

Output the answer.


Sample Input 1

1.012

Sample Output 1

1.012

1.012 can be printed as it is.


Sample Input 2

12.340

Sample Output 2

12.34

Printing 12.340 without the trailing 0 results in 12.34.


Sample Input 3

99.900

Sample Output 3

99.9

Printing 99.900 without the trailing 0s results in 99.9.


Sample Input 4

0.000

Sample Output 4

0

Printing 0.000 without trailing 0s or an unnecessary decimal point results in 0.

E - Peak

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋くんは数直線上に N 個のプレゼントを置きました。そのうち i 個目のプレゼントは座標 A_i に置かれました。

あなたは数直線上の長さ M の半開区間 [x,x+M) を選び、そこに含まれるプレゼントを全て獲得します。
より詳しくは、以下の手順でプレゼントを獲得します。

  • まず、実数 x をひとつ選択する。
  • その後、プレゼントのうち置かれている座標が x \le A_i < x+M を満たすものを全て獲得する。

最大でいくつのプレゼントを獲得することができますか?

制約

  • 入力は全て整数
  • 1 \le N \le 3 \times 10^5
  • 1 \le M \le 10^9
  • 0 \le A_i \le 10^9

入力

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

N M
A_1 A_2 \dots A_N

出力

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


入力例 1

8 6
2 3 5 7 11 13 17 19

出力例 1

4

例えば、半開区間 [1.5,7.5) を指定します。
このとき、座標 2,3,5,7 にある 4 つのプレゼントを全て獲得することができ、これが獲得可能な最大の個数です。


入力例 2

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

出力例 2

2

同一の座標に複数のプレゼントが置いてあることもあります。


入力例 3

10 998244353
100000007 0 1755647 998244353 495 1000000000 1755648 503 1755649 998244853

出力例 3

7

Score : 300 points

Problem Statement

Takahashi has placed N gifts on a number line. The i-th gift is placed at coordinate A_i.

You will choose a half-open interval [x,x+M) of length M on the number line and acquire all the gifts included in it.
More specifically, you acquire gifts according to the following procedure.

  • First, choose one real number x.
  • Then, acquire all the gifts whose coordinates satisfy x \le A_i < x+M.

What is the maximum number of gifts you can acquire?

Constraints

  • All input values are integers.
  • 1 \le N \le 3 \times 10^5
  • 1 \le M \le 10^9
  • 0 \le A_i \le 10^9

Input

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

N M
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

8 6
2 3 5 7 11 13 17 19

Sample Output 1

4

For example, specify the half-open interval [1.5,7.5).
In this case, you can acquire the four gifts at coordinates 2,3,5,7, the maximum number of gifts that can be acquired.


Sample Input 2

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

Sample Output 2

2

There may be multiple gifts at the same coordinate.


Sample Input 3

10 998244353
100000007 0 1755647 998244353 495 1000000000 1755648 503 1755649 998244853

Sample Output 3

7
F - Ideal Holidays

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

AtCoder 王国の 1 週間は A+B 日からなり、1 日目から A 日目が休日で、A+1 日目から A+B 日目が平日です。

高橋くんは N 個の予定があり、i 番目の予定は今日から D_i 日後です。

高橋くんは今日が 1 週間の何日目かを忘れてしまいました。高橋くんの N 個の予定が全て休日である可能性があるかを判定してください。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq A,B\leq 10^9
  • 1\leq D_1<D_2<\ldots<D_N\leq 10^9

入力

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

N A B
D_1 D_2 \ldots D_N

出力

高橋くんの N 個の予定が全て休日である可能性がある場合は Yes を、そうでない場合は No を一行に出力せよ。


入力例 1

3 2 5
1 2 9

出力例 1

Yes

入力では 1 週間は 7 日からなり、1 日目から 2 日目が休日、3 日目から 7 日目が平日です。

今日が 1 週間の 7 日目だとします。このとき、1 日後は 1 週間の 1 日目、2 日後は 1 週間の 2 日目、9 日後は 1 週間の 2 日目となり、全ての予定が休日となります。そのため、高橋くんの N 個の予定が全て休日である可能性があります。


入力例 2

2 5 10
10 15

出力例 2

No

入力例 3

4 347 347
347 700 705 710

出力例 3

Yes

Score: 350 points

Problem Statement

In the Kingdom of AtCoder, a week consists of A+B days, with the first through A-th days being holidays and the (A+1)-th through (A+B)-th being weekdays.

Takahashi has N plans, and the i-th plan is scheduled D_i days later.

He has forgotten what day of the week it is today. Determine if it is possible for all of his N plans to be scheduled on holidays.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq A,B\leq 10^9
  • 1\leq D_1<D_2<\ldots<D_N\leq 10^9

Input

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

N A B
D_1 D_2 \ldots D_N

Output

Print Yes in a single line if it is possible for all of Takahashi's N plans to be scheduled on holidays, and No otherwise.


Sample Input 1

3 2 5
1 2 9

Sample Output 1

Yes

In this input, a week consists of seven days, with the first through second days being holidays and the third through seventh days being weekdays.

Let us assume today is the seventh day of the week. In this case, one day later would be the first day of the week, two days later would be the second day of the week, and nine days later would also be the second day of the week, making all plans scheduled on holidays. Therefore, it is possible for all of Takahashi's N plans to be scheduled on holidays.


Sample Input 2

2 5 10
10 15

Sample Output 2

No

Sample Input 3

4 347 347
347 700 705 710

Sample Output 3

Yes
G - Permutation Subsequence

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 425

問題文

(1,2,\dots,N) を並び替えて得られる数列 P=(P_1,P_2,\dots,P_N) が与えられます。

長さ K の正整数列 (i_1,i_2,\dots,i_K) であって、以下の条件を共に満たすものを良い添字列と呼びます。

  • 1\leq i_1 < i_2 < \dots < i_K \leq N
  • (P_{i_1},P_{i_2},\dots,P_{i_K}) はある連続する K 個の整数を並び替えることで得られる。
    厳密には、ある整数 a が存在して、\lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace

全ての良い添字列における i_K-i_1 の最小値を求めてください。 なお、本問題の制約下では良い添字列が必ず 1 つ以上存在することが示せます。

制約

  • 1\leq K \leq N \leq 2\times 10^5
  • 1\leq P_i\leq N
  • i\neq j ならば P_i\neq P_j
  • 入力は全て整数

入力

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

N K
P_1 P_2 \dots P_N

出力

全ての良い添字列における i_K-i_1 の最小値を出力せよ。


入力例 1

4 2
2 3 1 4

出力例 1

1

良い添字列は (1,2),(1,3),(2,4)3 つです。 例えば (i_1,i_2)=(1,3) は、 1\leq i_1 < i_2 \leq N かつ (P_{i_1},P_{i_2})=(2,1) が連続する 2 つの整数 1,2 の並び替えなので良い添字列です。

これらの良い添字列のうち i_K-i_1 の値が最小となるのは (1,2) で、そのときの値は 2-1=1 です。


入力例 2

4 1
2 3 1 4

出力例 2

0

どの良い添字列においても i_K-i_1=i_1-i_1=0 です。


入力例 3

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

出力例 3

5

Score: 425 points

Problem Statement

You are given a permutation P = (P_1, P_2, \dots, P_N) of (1, 2, \dots, N).

A length-K sequence of indices (i_1, i_2, \dots, i_K) is called a good index sequence if it satisfies both of the following conditions:

  • 1 \leq i_1 < i_2 < \dots < i_K \leq N.
  • The subsequence (P_{i_1}, P_{i_2}, \dots, P_{i_K}) can be obtained by rearranging some consecutive K integers.
    Formally, there exists an integer a such that \lbrace P_{i_1},P_{i_2},\dots,P_{i_K} \rbrace = \lbrace a,a+1,\dots,a+K-1 \rbrace.

Find the minimum value of i_K - i_1 among all good index sequences. It can be shown that at least one good index sequence exists under the constraints of this problem.

Constraints

  • 1 \leq K \leq N \leq 2 \times 10^5
  • 1 \leq P_i \leq N
  • P_i \neq P_j if i \neq j.
  • All input values are integers.

Input

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

N K
P_1 P_2 \dots P_N

Output

Print the minimum value of i_K - i_1 among all good index sequences.


Sample Input 1

4 2
2 3 1 4

Sample Output 1

1

The good index sequences are (1,2),(1,3),(2,4). For example, (i_1, i_2) = (1,3) is a good index sequence because 1 \leq i_1 < i_2 \leq N and (P_{i_1}, P_{i_2}) = (2,1) is a rearrangement of two consecutive integers 1, 2.

Among these good index sequences, the smallest value of i_K - i_1 is for (1,2), which is 2-1=1.


Sample Input 2

4 1
2 3 1 4

Sample Output 2

0

i_K - i_1 = i_1 - i_1 = 0 in all good index sequences.


Sample Input 3

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

Sample Output 3

5
H - Sorting Queries

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

空の列 A があります。クエリが Q 個与えられるので、与えられた順番に処理してください。
クエリは次の 3 種類のいずれかです。

  • 1 x : A の最後尾に x を追加する。
  • 2 : A の最初の要素を出力する。その後、その要素を削除する。このクエリが与えられるとき、A は空でないことが保証される。
  • 3 : A を昇順にソートする。

制約

  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq x \leq 10^9
  • クエリ 2 が与えられるとき、A は空でない。
  • 入力は全て整数である。

入力

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

Q
\mathrm{query} 1
\mathrm{query} 2
\vdots
\mathrm{query} Q

i 番目のクエリ \mathrm{query} i では、まずクエリの種類 c_i1, 2, 3 のいずれか)が与えられる。 c_i = 1 の場合はさらに整数 x が追加で与えられる。

すなわち、各クエリは以下に示す 3 つの形式のいずれかである。

1 x
2
3

出力

c_i = 2 を満たすクエリの回数を q として q 行出力せよ。
j (1 \leq j \leq q) 行目では j 番目のそのようなクエリに対する答えを出力せよ。


入力例 1

8
1 4
1 3
1 2
1 1
3
2
1 0
2

出力例 1

1
2

入力例 1 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。

  • (4)
  • (4, 3)
  • (4, 3, 2)
  • (4, 3, 2, 1)
  • (1, 2, 3, 4)
  • (2, 3, 4)
  • (2, 3, 4, 0)
  • (3, 4, 0)

入力例 2

9
1 5
1 5
1 3
2
3
2
1 6
3
2

出力例 2

5
3
5

入力例 2 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。

  • (5)
  • (5, 5)
  • (5, 5, 3)
  • (5, 3)
  • (3, 5)
  • (5)
  • (5, 6)
  • (5, 6)
  • (6)

Score : 500 points

Problem Statement

We have an empty sequence A. You will be given Q queries, which should be processed in the order they are given. Each query is of one of the three kinds below:

  • 1 x : Append x to the end of A.
  • 2 : Print the element at the beginning of A. Then, delete that element. It is guaranteed that A will not empty when this query is given.
  • 3 : Sort A in ascending order.

Constraints

  • 1 \leq Q \leq 2 \times 10^5
  • 0 \leq x \leq 10^9
  • A will not be empty when a query 2 is given.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
\mathrm{query} 1
\mathrm{query} 2
\vdots
\mathrm{query} Q

The i-th query, \mathrm{query} i, begins with the kind of query c_i (1, 2, or 3). If c_i = 1, the line additionally has an integer x.

In other words, each query is in one of the three formats below.

1 x
2
3

Output

Print q lines, where q is the number of queries with c_i = 2.
The j-th line (1 \leq j \leq q) should contain the response for the j-th such query.


Sample Input 1

8
1 4
1 3
1 2
1 1
3
2
1 0
2

Sample Output 1

1
2

The i-th line below shows the contents of A after the i-th query is processed in Sample Input 1.

  • (4)
  • (4, 3)
  • (4, 3, 2)
  • (4, 3, 2, 1)
  • (1, 2, 3, 4)
  • (2, 3, 4)
  • (2, 3, 4, 0)
  • (3, 4, 0)

Sample Input 2

9
1 5
1 5
1 3
2
3
2
1 6
3
2

Sample Output 2

5
3
5

The i-th line below shows the contents of A after the i-th query is processed in Sample Input 2.

  • (5)
  • (5, 5)
  • (5, 5, 3)
  • (5, 3)
  • (3, 5)
  • (5)
  • (5, 6)
  • (5, 6)
  • (6)
I - Strongly Connected 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 525

問題文

辺と頂点に番号がついた N 頂点 N-1+M 辺の有向グラフがあります。
1 \leq i \leq M に対し辺 i は頂点 X_i から頂点 Y_i への有向辺であり、1 \leq i \leq N-1 に対し辺 M+i は頂点 i+1 から頂点 i への有向辺です。

1,2,\dots,M のうちいくつか( 0 個でもよい) の辺を選ぶ方法は 2^M 通りありますが、そのうち選んだ辺を削除したあとのグラフが強連結となるものは何通りありますか。998244353 で割った余りを求めてください。

制約

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq X_i < Y_i \leq N
  • 入力は全て整数

入力

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

N M
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

出力

答えを出力せよ。


入力例 1

4 3
1 4
1 3
2 4

出力例 1

5

選ぶ辺の番号の集合が \{\}, \{1\},\{2\},\{3\},\{2,3\}5 通りのいずれかであるとき、グラフは強連結となります。


入力例 2

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

出力例 2

1297

与えられるグラフは多重辺を持つことがあります。

Score : 525 points

Problem Statement

There is a directed graph with N vertices and N-1+M edges, with edges and vertices numbered.
For 1 \leq i \leq M, edge i is a directed edge from vertex X_i to vertex Y_i, and for 1 \leq i \leq N-1, edge M+i is a directed edge from vertex i+1 to vertex i.

There are 2^M ways to choose some (possibly zero) edges from among edges 1, 2, \dots, M. Among these ways, how many result in the graph being strongly connected after deleting the chosen edges? Find the count modulo 998244353.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq X_i < Y_i \leq N
  • All input values are integers.

Input

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

N M
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M

Output

Output the answer.


Sample Input 1

4 3
1 4
1 3
2 4

Sample Output 1

5

The graph is strongly connected when the set of chosen edge indices is one of \{\}, \{1\}, \{2\}, \{3\}, \{2,3\}, giving five ways.


Sample Input 2

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

Sample Output 2

1297

The given graph may have multi-edges.