A - ファンレター

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

あなたはアイドルグループ Bit♡Beat のプロデューサーです。

Bit♡Beat の事務所に N 個のファンレターが届きました。 i 個目のファンレターは A_i 月 B_i 日に届いたものです。

これら N 個のファンレターの日付を早い順(1 月 1 日から始めて、先に訪れる順)に出力してください。

制約

  • 1\le N\le 365
  • A_i 月 B_i 日は平年(うるう年ではない年)において正しい日付である。
  • (A_i , B_i) \neq (A_j , B_j) (i \neq j)
  • 入力される値は全て整数

入力

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

N 行出力せよ。

i 行目 (1\le i\le N) には、届いた日付が i 番目に早いファンレターの日付の月と日を半角スペース区切りで出力せよ。


入力例 1

3
3 15
1 15
3 8

出力例 1

1 15
3 8
3 15

事務所には 3 月 15 日、 1 月 15 日、 3 月 8 日にファンレターが届きました。

これらの日付を早い順に並べると 1 月 15 日、 3 月 8 日、 3 月 15 日となります。したがって、上記のように出力してください。


入力例 2

5
1 1
1 2
1 3
1 4
1 5

出力例 2

1 1
1 2
1 3
1 4
1 5

入力例 3

10
9 21
8 22
10 28
6 22
6 26
7 10
5 3
8 31
9 4
11 21

出力例 3

5 3
6 22
6 26
7 10
8 22
8 31
9 4
9 21
10 28
11 21
B - delete .

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

英小文字および . からなる文字列 S が与えられます。 S から . を全て削除した文字列を求めてください。

制約

  • S は英小文字および . からなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

S から . を全て削除した文字列を出力せよ。


入力例 1

.v.

出力例 1

v

.v. から . を全て削除すると v になります。したがって、 v を出力してください。


入力例 2

chokudai

出力例 2

chokudai

S に . が含まれない場合もあります。


入力例 3

...

出力例 3


S の文字が全て . である場合もあります。

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and .. Find the string obtained by removing all . from S.

Constraints

  • S is a string of length between 1 and 100, inclusive, consisting of lowercase English letters and ..

Input

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

S

Output

Print the string obtained by removing all . from S.


Sample Input 1

.v.

Sample Output 1

v

Removing all . from .v. yields v, so print v.


Sample Input 2

chokudai

Sample Output 2

chokudai

There are cases where S does not contain ..


Sample Input 3

...

Sample Output 3


There are also cases where all characters in S are ..

C - Humidifier 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250 点

問題文

AtCoder社のオフィスは H 行 W 列のマス目で表されます。上から i 行目、左から j 列目のマスを (i, j) と表します。

各マスの状態は文字 S_{i,j} で表され、 S_{i,j} が # のときそのマスは机、. のときそのマスは床です。床のマスは 2 つ以上存在することが保証されます。

あなたは床のマスから異なる 2 マスを選び、加湿器を設置します。

加湿器が設置されたとき、あるマス (i,j) は加湿器があるマス (i',j') からのマンハッタン距離が D 以下であるとき、またその時に限り加湿されます。 なお、マス (i,j) からマス (i',j') までのマンハッタン距離は |i-i'|+|j-j'| で表されます。 ここで、加湿器が置かれた床のマスは必ず加湿されていることに注意してください。

加湿される 床のマス の個数として考えられる最大値を求めてください。

制約

  • 1 \leq H \leq 10
  • 1 \leq W \leq 10
  • 2 \leq H \times W
  • 0 \leq D \leq H+W-2
  • H,W,D は整数
  • S_{i,j} は # または . である (1 \leq i \leq H, 1 \leq j \leq W)
  • 床のマスは 2 つ以上存在する

入力

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

H W D
S_{1,1}S_{1,2}\cdotsS_{1,W}
S_{2,1}S_{2,2}\cdotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\cdotsS_{H,W}

出力

答えを出力せよ。


入力例 1

2 5 1
.###.
.#.##

出力例 1

3

マス (1,1) とマス (1,5) に加湿器を置いた時:

  • マス (1,1) の加湿器によってマス (1,1),(2,1) の 2 マスが加湿されます。
  • マス (1,5) の加湿器によってマス (1,5) の 1 マスが加湿されます。

よって、合計 3 マス加湿されています。また、4 マス以上加湿するような加湿器の置き方は存在しないため、答えは 3 です。


入力例 2

5 5 2
.#.#.
.....
.#.#.
#.#.#
.....

出力例 2

15

マス (2,4) とマス (5,3) に加湿器を置いた時、15 個の床のマスが加湿されます。


入力例 3

4 4 2
....
.##.
.##.
....

出力例 3

10

Score : 250 points

Problem Statement

The AtCoder company office can be represented as a grid of H rows and W columns. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left.

The state of each cell is represented by a character S_{i,j}. If S_{i,j} is #, that cell contains a desk; if S_{i,j} is ., that cell is a floor. It is guaranteed that there are at least two floor cells.

You will choose two distinct floor cells and place a humidifier on each.

After placing the humidifiers, a cell (i,j) is humidified if and only if it is within a Manhattan distance D from at least one of the humidifier cells (i',j'). The Manhattan distance between (i,j) and (i',j') is defined as |i - i'| + |j - j'|. Note that any floor cell on which a humidifier is placed is always humidified.

Find the maximum possible number of humidified floor cells.

Constraints

  • 1 \leq H \leq 10
  • 1 \leq W \leq 10
  • 2 \leq H \times W
  • 0 \leq D \leq H+W-2
  • H,W,D are integers.
  • S_{i,j} is # or .. (1 \leq i \leq H, 1 \leq j \leq W)
  • There are at least two floor cells.

Input

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

H W D
S_{1,1}S_{1,2}\cdotsS_{1,W}
S_{2,1}S_{2,2}\cdotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\cdotsS_{H,W}

Output

Print the answer.


Sample Input 1

2 5 1
.###.
.#.##

Sample Output 1

3

When placing humidifiers on (1,1) and (1,5):

  • From the humidifier on (1,1), two cells (1,1) and (2,1) are humidified.
  • From the humidifier on (1,5), one cell (1,5) is humidified.

In total, three cells are humidified. No configuration can humidify four or more floor cells, so the answer is 3.


Sample Input 2

5 5 2
.#.#.
.....
.#.#.
#.#.#
.....

Sample Output 2

15

When placing humidifiers on (2,4) and (5,3), 15 floor cells are humidified.


Sample Input 3

4 4 2
....
.##.
.##.
....

Sample Output 3

10
D - Chessboard

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

チェス盤のどこにコマが置かれているか答えてください。

縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。

  • 左から 1 列目にあるマスの名前の 1 文字目は a である。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目は b, c, d, e, f, g, h である。
  • 下から 1 行目にあるマスの名前の 2 文字目は 1 である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は 2, 3, 4, 5, 6, 7, 8 である。

例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。

グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。

制約

  • S_i は . および * のみからなる長さ 8 の文字列である
  • S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在する。

入力

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

出力

答えを出力せよ。


入力例 1

........
........
........
........
........
........
........
*.......

出力例 1

a1

問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。


入力例 2

........
........
........
........
........
.*......
........
........

出力例 2

b3

Score : 200 points

Problem Statement

Locate a piece on a chessboard.

We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.

  • The first character of the name of a square in the 1-st column from the left is a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left is b, c, d, e, f, g, h, respectively.
  • The second character of the name of a square in the 1-st row from the bottom is 1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is 2, 3, 4, 5, 6, 7, 8, respectively.

For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.

You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise. The character * occurs exactly once among S_1,\ldots,S_8. Find the name of the square that has a piece on it.

Constraints

  • S_i is a string of length 8 consisting of . and*.
  • The character * occurs exactly once among S_1,\ldots,S_8.

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the answer.


Sample Input 1

........
........
........
........
........
........
........
*.......

Sample Output 1

a1

As explained in the problem statement, the bottom-left square is named a1.


Sample Input 2

........
........
........
........
........
.*......
........
........

Sample Output 2

b3
E - Distance Indicators

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

長さ N の整数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。

整数の 2 つ組 (i,j)\ (1\le i\lt j\le N) のうち、j-i=A _ i+A _ j を満たすものがいくつあるか求めてください。

制約

  • 1\le N\le2\times10 ^ 5
  • 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

答えを出力せよ。


入力例 1

9
3 1 4 1 5 9 2 6 5

出力例 1

3

例えば、(i,j)=(4,7) とすると、j-i=7-4=3 かつ A _ i+A _ j=1+2=3 が成り立つので、j-i=A _ i+A _ j です。

一方で、(i,j)=(3,8) とすると、j-i=8-3=5 かつ A _ i+A _ j=4+6=10 となるので、j-i\ne A _ i+A _ j です。

(i,j)=(1,9),(2,4),(4,7) の 3 組だけが条件を満たすので、3 を出力してください。


入力例 2

3
123456 123456 123456

出力例 2

0

条件を満たす組が存在しない場合もあります。


入力例 3

30
8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5

出力例 3

17

Score : 300 points

Problem Statement

You are given an integer sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.

Find how many pairs of integers (i,j)\ (1\le i\lt j\le N) satisfy j-i=A _ i+A _ j.

Constraints

  • 1\le N\le2\times10 ^ 5
  • 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

Output the answer.


Sample Input 1

9
3 1 4 1 5 9 2 6 5

Sample Output 1

3

For example, when (i,j)=(4,7), we have j-i=7-4=3 and A _ i+A _ j=1+2=3, so j-i=A _ i+A _ j.

In contrast, when (i,j)=(3,8), we have j-i=8-3=5 and A _ i+A _ j=4+6=10, so j-i\ne A _ i+A _ j.

Only the three pairs (i,j)=(1,9),(2,4),(4,7) satisfy the condition, so output 3.


Sample Input 2

3
123456 123456 123456

Sample Output 2

0

There may be no pairs that satisfy the condition.


Sample Input 3

30
8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5

Sample Output 3

17