A - ^{-1}

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

配点 : 100

問題文

(1,2,…,N) を並び替えた数列 P と整数 X が与えられます。 数列 Pi 番目の項の値は P_i です。 P_k = X を満たす k を出力してください。

制約

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • P(1,2,…,N) を並び替えてできる数列
  • 入力はすべて整数

入力

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

N X
P_1 P_2 \ldots P_N

出力

答えを出力せよ。


入力例 1

4 3
2 3 1 4

出力例 1

2

P = (2,3,1,4) なので、P_2 = 3 です。したがって、2 を出力します。


入力例 2

5 2
3 5 1 4 2

出力例 2

5

入力例 3

6 6
1 2 3 4 5 6

出力例 3

6

Score : 100 points

Problem Statement

You are given a sequence P that is a permutation of (1,2,…,N), and an integer X. The i-th term of P has a value of P_i. Print k such that P_k = X.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq X \leq N
  • P is a permutation of (1,2,…,N).
  • All values in the input are integers.

Input

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

N X
P_1 P_2 \ldots P_N

Output

Print the answer.


Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

We have P = (2,3,1,4), so P_2 = 3. Thus, you should print 2.


Sample Input 2

5 2
3 5 1 4 2

Sample Output 2

5

Sample Input 3

6 6
1 2 3 4 5 6

Sample Output 3

6
B - 202<s>3</s>

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

配点 : 100

問題文

英小文字と数字からなる文字列 S が入力されます。
S2023 で終わることが保証されます。
S の最後の文字を 4 に変更し、変更後の文字列を出力してください。

制約

  • S は英小文字と数字からなる長さ 4 以上 100 以下の文字列
  • S2023 で終わる。

入力

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

S

出力

答えを出力せよ。


入力例 1

hello2023

出力例 1

hello2024

hello2023 の最後の文字を 4 に変更すると、 hello2024 となります。


入力例 2

worldtourfinals2023

出力例 2

worldtourfinals2024

入力例 3

2023

出力例 3

2024

S2023 で終わることが保証されていますが、 S2023 そのものである場合もあります。


入力例 4

20232023

出力例 4

20232024

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and digits.
S is guaranteed to end with 2023.
Change the last character of S to 4 and print the modified string.

Constraints

  • S is a string of length between 4 and 100, inclusive, consisting of lowercase English letters and digits.
  • S ends with 2023.

Input

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

S

Output

Print the answer.


Sample Input 1

hello2023

Sample Output 1

hello2024

Changing the last character of hello2023 to 4 yields hello2024.


Sample Input 2

worldtourfinals2023

Sample Output 2

worldtourfinals2024

Sample Input 3

2023

Sample Output 3

2024

S is guaranteed to end with 2023, possibly being 2023 itself.


Sample Input 4

20232023

Sample Output 4

20232024
C - Frequency

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

配点 : 200

問題文

英小文字からなる文字列 S が与えられます。S に最も多く出現する文字を求めてください。そのような文字が複数ある場合は、そのうちアルファベット順で最も早いものを答えてください。

制約

  • 1 \leq |S| \leq 1000|S| は文字列 S の長さ)
  • S の各文字は英小文字である。

入力

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

S

出力

S に最も多く出現する文字のうちアルファベット順で最も早いものを出力せよ。


入力例 1

frequency

出力例 1

e

frequency には e2 回出現し、これは他のどの文字よりも多いため e を出力します。


入力例 2

atcoder

出力例 2

a

atcoder には a, t, c, o, d, e, r1 回ずつ出現するため、このうちアルファベット順で最も早い a を出力します。


入力例 3

pseudopseudohypoparathyroidism

出力例 3

o

Score: 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Find the character that appears most frequently in S. If multiple such characters exist, report the one that comes earliest in alphabetical order.

Constraints

  • 1 \leq |S| \leq 1000 (|S| is the length of the string S.)
  • Each character in S is a lowercase English letter.

Input

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

S

Output

Among the characters that appear most frequently in S, print the one that comes earliest in alphabetical order.


Sample Input 1

frequency

Sample Output 1

e

In frequency, the letter e appears twice, which is more than any other character, so you should print e.


Sample Input 2

atcoder

Sample Output 2

a

In atcoder, each of the letters a, t, c, o, d, e, and r appears once, so you should print the earliest in alphabetical order, which is a.


Sample Input 3

pseudopseudohypoparathyroidism

Sample Output 3

o
D - log2(N)

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

配点 : 200

問題文

正整数 N が与えられるので、 2^k \le N となる最大の整数 k を求めてください。

制約

  • N1 \le N \le 10^{18} を満たす整数である

入力

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

N

出力

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


入力例 1

6

出力例 1

2
  • k=22^2=4 \le 6 を満たします。
  • k \ge 3 である全ての整数 k について 2^k > 6 となります。

以上より、答えは k=2 となります。


入力例 2

1

出力例 2

0

2^0=1 であることに注意してください。


入力例 3

1000000000000000000

出力例 3

59

入力が 32 bit 整数に収まらない場合があります。

Score : 200 points

Problem Statement

Given a positive integer N, find the maximum integer k such that 2^k \le N.

Constraints

  • N is an integer satisfying 1 \le N \le 10^{18}.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

6

Sample Output 1

2
  • k=2 satisfies 2^2=4 \le 6.
  • For every integer k such that k \ge 3, 2^k > 6 holds.

Therefore, the answer is k=2.


Sample Input 2

1

Sample Output 2

0

Note that 2^0=1.


Sample Input 3

1000000000000000000

Sample Output 3

59

The input value may not fit into a 32-bit integer.

E - Peak

実行時間制限: 2 sec / メモリ制限: 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