A - Next Alphabet

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

z でない英小文字 C が与えられます。アルファベット順で C の次の文字を出力してください。

制約

  • Cz でない英小文字

入力

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

C

出力

アルファベット順で C の次の文字を出力せよ。


入力例 1

a

出力例 1

b

a の次は b です。


入力例 2

y

出力例 2

z

y の次は z です。

Score : 100 points

Problem Statement

Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.

Constraints

  • C is a lowercase English letter that is not z.

Input

Input is given from Standard Input in the following format:

C

Output

Print the letter that follows C in alphabetical order.


Sample Input 1

a

Sample Output 1

b

a is followed by b.


Sample Input 2

y

Sample Output 2

z

y is followed by z.

B - Achieve the Goal

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君は N 科目のテストを受けます。各テストは K 点満点であり、点数はそれぞれ 0 以上の整数です。

高橋君は N-1 科目のテストを既に受けており、i 番目の科目のテストの点数は A_i 点でした。

高橋君の目標は、N 科目のテストの平均点を M 点以上にすることです。

高橋君が目標を達成するためには、最後のテストで最低何点取る必要があるか出力してください。

達成不可能である場合は、代わりに -1 を出力してください。

制約

  • 2 \leq N \leq 100
  • 1 \leq K \leq 100
  • 1 \leq M \leq K
  • 0 \leq A_i \leq K
  • 入力中のすべての値は整数である。

入力

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

N K M
A_1 A_2 ... A_{N-1}

出力

最後のテストでの必要最低点または -1 を出力せよ。


入力例 1

5 10 7
8 10 3 6

出力例 1

8

最後のテストで 8 点を取ると、(8+10+3+6+8)/5 = 7 より平均点は 7 点となり目標を達成できます。


入力例 2

4 100 60
100 100 100

出力例 2

0

最後のテストで 0 点を取っても目標を達成できます。


入力例 3

4 100 60
0 0 0

出力例 3

-1

もはや挽回は不可能です。

Score : 200 points

Problem Statement

Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive).

He has already taken exams on N-1 subjects and scored A_i points on the i-th subject.

His goal is to achieve the average score of M points or above on the N subjects.

Print the minimum number of points Takahashi needs on the final subject to achieve his goal.

If the goal is unachievable, print -1 instead.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq K \leq 100
  • 1 \leq M \leq K
  • 0 \leq A_i \leq K
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K M
A_1 A_2 ... A_{N-1}

Output

Print the minimum number of points required on the final subject, or -1.


Sample Input 1

5 10 7
8 10 3 6

Sample Output 1

8

If he scores 8 points on the final subject, his average score will be (8+10+3+6+8)/5 = 7 points, which meets the goal.


Sample Input 2

4 100 60
100 100 100

Sample Output 2

0

Scoring 0 points on the final subject still meets the goal.


Sample Input 3

4 100 60
0 0 0

Sample Output 3

-1

He can no longer meet the goal.

C - Welcome to AtCoder

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

高橋君は AtCoder のコンテストに参加しています。

このコンテストでは、 N 問の問題が出題されます。

高橋君はコンテスト中に M 回の提出を行いました。

i 回目の提出は p_i 番目の問題への提出であり、結果は S_i (AC または WA) でした。

高橋君の正答数は、AC1 回以上出した問題の数です。

高橋君のペナルティ数は、高橋君が AC1 回以上出した各問題において、初めて AC を出すまでに出した WA の数の総和です。

高橋君の正答数とペナルティ数を答えてください。

制約

  • N , M , p_i は整数
  • 1 ≤ N ≤ 10^5
  • 0 ≤ M ≤ 10^5
  • 1 \leq p_i \leq N
  • S_iACWA のいずれか

入力

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

N M
p_1 S_1
:
p_M S_M

出力

高橋君の正答数とペナルティ数を出力せよ。


入力例 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

出力例 1

2 2

高橋君が 1 番目の問題に初めて AC を出したのは 2 回目の提出であり、これまでに 1 番目の問題で 1WA を出しています。

高橋君が 2 番目の問題に初めて AC を出したのは 4 回目の提出であり、これまでに 2 番目の問題で 1WA を出しています。

以上より、高橋君の正答数は 2 であり、ペナルティ数も 2 です。


入力例 2

100000 3
7777 AC
7777 AC
7777 AC

出力例 2

1 0

同じ問題で何度 AC を出しても無意味であることに注意してください。


入力例 3

6 0

出力例 3

0 0

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

  • N, M, and p_i are integers.
  • 1 \leq N \leq 10^5
  • 0 \leq M \leq 10^5
  • 1 \leq p_i \leq N
  • S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.


Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.


Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.


Sample Input 3

6 0

Sample Output 3

0 0
D - Maze Master

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

高橋君は、縦 H マス、横 W マスの H \times W マスからなる迷路を持っています。

上から i 行目、左から j 列目のマス (i,j) は、 S_{ij}# のとき壁であり、. のとき道です。

道のマスからは、上下左右に隣接する道のマスに移動することができます。

迷路の外に移動すること、壁のマスへ移動すること、斜めに移動することはできません。

高橋君は、道のマスからスタートとゴールを自由に決め、迷路を青木君に渡します。

青木君は、移動回数が最小になるようにしてスタートからゴールまで移動します。

高橋君がスタートとゴールの位置を適切に定めたとき、青木君の移動回数は最大で何回になるでしょうか?

制約

  • 1 \leq H,W \leq 20
  • S_{ij}.#
  • S.2 つ以上含む
  • 任意の道のマスから任意の道のマスまで 0 回以上の移動で到達できる

入力

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

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

出力

青木君の移動回数の最大値を出力せよ。


入力例 1

3 3
...
...
...

出力例 1

4

高橋君が左上のマスをスタート、右下のマスをゴールにした場合、青木君の移動回数は 4 回になります。


入力例 2

3 5
...#.
.#.#.
.#...

出力例 2

10

高橋君が左下のマスをスタート、右上のマスをゴールにした場合、青木君の移動回数は 10 回になります。

Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

  • 1 \leq H,W \leq 20
  • S_{ij} is . or #.
  • S contains at least two occurrences of ..
  • Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.


Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.


Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.

E - Max-Min Sums

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

有限個の整数からなる集合 X に対し f(X)=\max X - \min X と定義します。

N 個の整数 A_1,...,A_N が与えられます。

このうち K 個を選び、それらからなる集合を S とします。同じ値であっても添字が異なる要素を区別すると、そのような選び方は {}_N C_K 通りありますが、その全てについての f(S) の合計を求めてください。

答えは非常に大きくなる可能性があるので、\bmod 10^9+7 で出力してください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq N
  • |A_i| \leq 10^9

入力

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

N K
A_1 ... A_N

出力

答えを \bmod 10^9+7 で出力せよ。


入力例 1

4 2
1 1 3 4

出力例 1

11

S の選び方は \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\},\{3,4\}6 通りあり (ふたつの 1 は区別します)、f(S) はそれぞれ 0,2,3,2,3,1 となるので、合計は 11 です。


入力例 2

6 3
10 10 10 -10 -10 -10

出力例 2

360

S の選び方は 20 通りあり、そのうち 18 通りで f(S)=202 通りで f(S)=0 となります。


入力例 3

3 1
1 1 1

出力例 3

0

入力例 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

出力例 4

999998537

合計は \bmod 10^9+7 で出力してください。

Score : 500 points

Problem Statement

For a finite set of integers X, let f(X)=\max X - \min X.

Given are N integers A_1,...,A_N.

We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways.

Since the answer can be enormous, print it \bmod (10^9+7).

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq N
  • |A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 ... A_N

Output

Print the answer \bmod (10^9+7).


Sample Input 1

4 2
1 1 3 4

Sample Output 1

11

There are six ways to choose S: \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1s). The value of f(S) for these choices are 0,2,3,2,3,1, respectively, for the total of 11.


Sample Input 2

6 3
10 10 10 -10 -10 -10

Sample Output 2

360

There are 20 ways to choose S. In 18 of them, f(S)=20, and in 2 of them, f(S)=0.


Sample Input 3

3 1
1 1 1

Sample Output 3

0

Sample Input 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

Sample Output 4

999998537

Print the sum \bmod (10^9+7).

F - Enclose All

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

平面上の N 個の点 (x_i, y_i) が与えられます。

これら全てを内部または周上に含む円の半径の最小値を求めてください。

制約

  • 2 ≤ N ≤ 50
  • 0 ≤ x_i ≤ 1000
  • 0 ≤ y_i ≤ 1000
  • 与えられる N 点は全て異なる
  • 入力で与えられる値は全て整数

入力

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

N
x_1 y_1
:
x_N y_N

出力

N 個全ての点を内部または周上に含む円の半径の最小値を出力せよ。

なお、想定解答との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。


入力例 1

2
0 0
1 0

出力例 1

0.500000000000000000

2 つの点は中心 (0.5,0) 、半径 0.5 の円に含まれます。


入力例 2

3
0 0
0 1
1 0

出力例 2

0.707106781186497524

入力例 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

出力例 3

6.726812023536805158

想定解答との絶対誤差または相対誤差が 10^{−6} 以下であれば正解として扱われます。

Score : 600 points

Problem Statement

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

  • 2 \leq N \leq 50
  • 0 \leq x_i \leq 1000
  • 0 \leq y_i \leq 1000
  • The given N points are all different.
  • The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum radius of a circle such that all the N points are inside or on it.

Your output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.


Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

Both points are contained in the circle centered at (0.5,0) with a radius of 0.5.


Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Sample Output 3

6.726812023536805158

If the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.