A - Closed interval

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

配点 : 100

問題文

整数 L,R が与えられます。

L 以上 R 以下の整数がいくつあるか求めてください。

制約

  • 1\le L\le R\le 100
  • 入力される値は全て整数

入力

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

L R

出力

答えを出力せよ。


入力例 1

3 5

出力例 1

3

3 以上 5 以下の整数は 3,4,53 つです。したがって、3 を出力してください。


入力例 2

1 7

出力例 2

7

入力例 3

14 79

出力例 3

66

Score : 100 points

Problem Statement

You are given integers L and R.

Find how many integers are between L and R, inclusive.

Constraints

  • 1\le L\le R\le 100
  • All input values are integers.

Input

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

L R

Output

Output the answer.


Sample Input 1

3 5

Sample Output 1

3

The integers between 3 and 5, inclusive, are 3,4,5, which is three integers. Thus, output 3.


Sample Input 2

1 7

Sample Output 2

7

Sample Input 3

14 79

Sample Output 3

66
B - Chompers

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

配点 : 100

問題文

英小文字からなる文字列 S と正の整数 N が与えられます。S の長さは 2N+1 以上です。

S の先頭と末尾から N 文字ずつ取り除いて得られる文字列を求めてください。

制約

  • S は英小文字からなる文字列
  • N は整数
  • 2N+1 \leq |S| \leq 30
  • 1 \leq N \leq 10

入力

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

S
N

出力

答えを出力せよ。


入力例 1

chemotherapy
3

出力例 1

mother

chemotherapy の先頭 3 文字 (che) と末尾 3 文字 (apy) を取り除くと、mother が得られます。


入力例 2

thermometer
4

出力例 2

mom

入力例 3

burger
1

出力例 3

urge

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and a positive integer N. The length of S is at least 2N+1.

Find the string obtained by removing N characters from the beginning and N characters from the end of S.

Constraints

  • S is a string consisting of lowercase English letters.
  • N is an integer.
  • 2N+1 \leq |S| \leq 30
  • 1 \leq N \leq 10

Input

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

S
N

Output

Output the answer.


Sample Input 1

chemotherapy
3

Sample Output 1

mother

Removing the first three characters (che) and the last three characters (apy) from chemotherapy gives mother.


Sample Input 2

thermometer
4

Sample Output 2

mom

Sample Input 3

burger
1

Sample Output 3

urge
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 - Permute to Minimize

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

配点 : 200

問題文

正整数 X が与えられます。

X を(先頭に 0 を含まない形で)十進表記した際に現れる数字を、先頭に 0 が来ないように 並び替えることで得られる正整数のうち、値が最小のものを求めてください。

制約

  • 1\leq X < 10^5
  • X は整数

入力

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

X

出力

答えを出力せよ。


入力例 1

903

出力例 1

309

X を十進表記した際に現れる数字を先頭に 0 が来ないように並び替えることで得られる正整数は、903, 930, 309, 3904 通りであり、このうち値が最小のものは 309 です。


入力例 2

432

出力例 2

234

入力例 3

100

出力例 3

100

Score : 200 points

Problem Statement

You are given a positive integer X.

Find the minimum value among all positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X (without leading zeros) such that there is no leading zero.

Constraints

  • 1\leq X < 10^5
  • X is an integer.

Input

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

X

Output

Output the answer.


Sample Input 1

903

Sample Output 1

309

There are four positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X such that there is no leading zero: 903, 930, 309, 390; the minimum value among them is 309.


Sample Input 2

432

Sample Output 2

234

Sample Input 3

100

Sample Output 3

100
E - Except and Min

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

配点 : 300

問題文

1 から N の番号がついた N 個のボールが袋に入っています。ボール i には整数 A_i が書かれています。
Q 個のクエリを処理してください。
クエリでは長さ K の数列 B_1, B_2, \dots, B_{K} が与えられるので以下の一連の操作を行ってください。ここで、B_i は全て 1 以上 N 以下で、かつ相異なります。

  • まず、ボール B_1, ボール B_2, \dots, ボール B_K を全て袋から取り出す。
  • そして、現在の袋に入っているボールに書かれた整数の最小値を出力する。(この時、袋は空でないことが制約から保証されている。)
  • その後、取り出した K 個のボールを全て袋に戻す。

制約

  • 6 \leq N \leq 3 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq K \leq 5
  • 1 \leq B_1 \lt B_2 \lt \dots \lt B_K \leq N
  • 全てのクエリに対する K の総和は 4 \times 10^5 以下
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。ここで \mathrm{query}_ii 番目のクエリを意味する。

N Q
A_1 A_2 \dots A_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

クエリは以下の形式で与えられる。

K
B_1 B_2 \dots B_K

出力

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


入力例 1

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

出力例 1

2
1
3
5
2
1

例えば 1 番目のクエリでは、ボール 4 とボール 5 を袋から取り出します。この時、袋には以下の 4 個のボールが残っています:

  • 3 が書き込まれたボール 1
  • 2 が書き込まれたボール 2
  • 5 が書き込まれたボール 3
  • 2 が書き込まれたボール 6

よってこの時の袋に入っているボールに書かれた整数の最小値は 2 です。

Score : 300 points

Problem Statement

A bag contains N balls numbered 1 to N. Ball i has the integer A_i written on it.
Process Q queries.
For each query, a sequence B_1, B_2, \dots, B_{K} of length K is given, and you should perform the following sequence of operations. Here, all B_i are between 1 and N inclusive and are distinct.

  • First, remove balls B_1, B_2, \dots, B_K from the bag.
  • Then, output the minimum value among the integers written on the balls currently in the bag. (It is guaranteed by the constraints that the bag is not empty at this point.)
  • Afterwards, return all K removed balls to the bag.

Constraints

  • 6 \leq N \leq 3 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq K \leq 5
  • 1 \leq B_1 \lt B_2 \lt \dots \lt B_K \leq N
  • The sum of K over all queries is at most 4 \times 10^5.
  • All input values are integers.

Input

The input is given from Standard Input in the following format, where \mathrm{query}_i denotes the i-th query.

N Q
A_1 A_2 \dots A_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query is given in the following format.

K
B_1 B_2 \dots B_K

Output

Output Q lines. The i-th line should contain the answer to the i-th query.


Sample Input 1

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

Sample Output 1

2
1
3
5
2
1

For example, in the first query, balls 4 and 5 are removed from the bag. At this point, the following four balls remain in the bag:

  • Ball 1 with 3 written on it
  • Ball 2 with 2 written on it
  • Ball 3 with 5 written on it
  • Ball 6 with 2 written on it

Thus, the minimum value among the integers written on the balls in the bag is 2.