A - Task Failed Successfully

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

配点 : 100

問題文

高橋君は N 日間のタスク目標を設定しました。

高橋君は i (1 \leq i \leq N) 日目に A_i 個のタスクを完了することを目標としており、実際には B_i 個のタスクを完了しました。

高橋君が目標より多くのタスクを完了した日数を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq A_i, B_i \leq 100
  • 入力される値はすべて整数

入力

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

答えを出力せよ。


入力例 1

4
2 8
5 5
5 4
6 7

出力例 1

2

高橋君は 1 日目と 4 日目に目標より多くのタスクを完了しました。


入力例 2

5
1 1
1 1
1 1
1 1
1 1

出力例 2

0

入力例 3

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

出力例 3

3

Score : 100 points

Problem Statement

Takahashi set task goals for N days.

He aimed to complete A_i tasks on day i (1 \leq i \leq N), and actually completed B_i tasks.

Find the number of days when he completed more tasks than his goal.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq A_i, B_i \leq 100
  • All input values are integers.

Input

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Output the answer.


Sample Input 1

4
2 8
5 5
5 4
6 7

Sample Output 1

2

Takahashi completed more tasks than his goal on the 1st and 4th days.


Sample Input 2

5
1 1
1 1
1 1
1 1
1 1

Sample Output 2

0

Sample Input 3

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

Sample Output 3

3
B - Legendary Players

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

配点 : 100

問題文

AtCoder では、レーティング上位 10 人のハンドルネームには金色の冠が、上位 1 人のハンドルネームには白金色の冠が表示されます。

このコンテストが開始した時点で、アルゴリズム部門での上位 10 人に入っているプレイヤーのハンドルネームとレーティングは以下のようになっています。

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

上記のプレイヤーのハンドルネーム S が与えられるので、その人のレーティングを出力してください。

制約

  • S はアルゴリズム部門でレーティング上位 10 人に入っているプレイヤーのハンドルネームのいずれかと等しい。

入力

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

S

出力

対応するプレイヤーのレーティングを 1 行で出力せよ。


入力例 1

tourist

出力例 1

3858

このコンテストが開始した時点において、 tourist さんのアルゴリズム部門のレーティングは 3858 です。


入力例 2

semiexp

出力例 2

3481

このコンテストが開始した時点において、 semiexp さんのアルゴリズム部門のレーティングは 3481 です。

Score : 100 points

Problem Statement

In AtCoder, the top 10 rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.

At the start of this contest, the usernames and ratings of the top 10 rated players in the algorithm category are as follows:

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

You are given the username S of one of these players. Print that player's rating.

Constraints

  • S is equal to one of the usernames of the top 10 rated players in the algorithm category.

Input

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

S

Output

Print the rating of the corresponding player in one line.


Sample Input 1

tourist

Sample Output 1

3858

At the start of this contest, the rating of tourist in the algorithm category is 3858.


Sample Input 2

semiexp

Sample Output 2

3481

At the start of this contest, the rating of semiexp in the algorithm category is 3481.

C - Langton's Takahashi

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

配点 : 250

問題文

HW 列のグリッドがあり、はじめすべてのマスが白で塗られています。グリッドの上から i 行目、左から j 列目のマスを (i, j) と表記します。

このグリッドはトーラス状であるとみなします。すなわち、各 1 \leq i \leq H に対して (i, W) の右に (i, 1) があり、各 1 \leq j \leq W に対して (H, j) の下に (1, j) があるとします。

高橋君が (1, 1) にいて上を向いています。高橋君が以下の操作を N 回繰り返した後のグリッドの各マスがどの色で塗られているか出力してください。

  • 現在いるマスが白で塗られている場合は、現在いるマスを黒に塗り替え、時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。そうでない場合は、現在いるマスを白に塗り替え、反時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。

制約

  • 1 \leq H, W \leq 100
  • 1 \leq N \leq 1000
  • 入力される数値はすべて整数

入力

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

H W N

出力

H 行出力せよ。i 行目には長さ W の文字列であって、(i, j) が白で塗られている場合は j 文字目が .、黒で塗られている場合は j 文字目が # であるものを出力せよ。


入力例 1

3 4 5

出力例 1

.#..
##..
....

グリッドの各マスは操作によって以下のように変化します。

....   #...   ##..   ##..   ##..   .#..
.... → .... → .... → .#.. → ##.. → ##..
....   ....   ....   ....   ....   ....

入力例 2

2 2 1000

出力例 2

..
..

入力例 3

10 10 10

出力例 3

##........
##........
..........
..........
..........
..........
..........
..........
..........
#........#

Score: 250 points

Problem Statement

There is a grid with H rows and W columns; initially, all cells are painted white. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.

This grid is considered to be toroidal. That is, (i, 1) is to the right of (i, W) for each 1 \leq i \leq H, and (1, j) is below (H, j) for each 1 \leq j \leq W.

Takahashi is at (1, 1) and facing upwards. Print the color of each cell in the grid after Takahashi repeats the following operation N times.

  • If the current cell is painted white, repaint it black, rotate 90^\circ clockwise, and move forward one cell in the direction he is facing. Otherwise, repaint the current cell white, rotate 90^\circ counterclockwise, and move forward one cell in the direction he is facing.

Constraints

  • 1 \leq H, W \leq 100
  • 1 \leq N \leq 1000
  • All input values are integers.

Input

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

H W N

Output

Print H lines. The i-th line should contain a string of length W where the j-th character is . if the cell (i, j) is painted white, and # if it is painted black.


Sample Input 1

3 4 5

Sample Output 1

.#..
##..
....

The cells of the grid change as follows due to the operations:

....   #...   ##..   ##..   ##..   .#..
.... → .... → .... → .#.. → ##.. → ##..
....   ....   ....   ....   ....   ....

Sample Input 2

2 2 1000

Sample Output 2

..
..

Sample Input 3

10 10 10

Sample Output 3

##........
##........
..........
..........
..........
..........
..........
..........
..........
#........#
D - Unauthorized

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

配点 : 200

問題文

ある日、高橋くんはあるウェブサイトに対して N 回の操作を行いました。

i 回目 (1\leq i\leq N) の操作は文字列 S _ i で表され、次の 4 つのうちいずれかです。

  • S _ i= login である。高橋くんはログイン操作を行い、高橋くんがウェブサイトにログインした状態になる。
  • S _ i= logout である。高橋くんはログアウト操作を行い、高橋くんがウェブサイトにログインしていない状態になる。
  • S _ i= public である。高橋くんはウェブサイトの公開ページにアクセスする。
  • S _ i= private である。高橋くんはウェブサイトの非公開ページにアクセスする。

高橋くんがログインしていない状態で非公開ページにアクセスした時、またその時に限り、ウェブサイトは認証エラーを返します。

ログインした状態でさらにログイン操作をしたり、ログインしていない状態でさらにログアウト操作をしてもエラーにはなりません。 また、認証エラーが返されたあとも、高橋くんは操作を続けることができます。

はじめ、高橋くんはログインしていない状態です。

N 回の操作のうち、高橋くんが認証エラーを受け取った回数を出力してください。

制約

  • 1\leq N\leq100
  • N は整数
  • S _ ilogin, logout, public, private のいずれか (1\leq i\leq N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

高橋くんが認証エラーを受け取った回数を出力せよ。


入力例 1

6
login
private
public
logout
private
public

出力例 1

1

高橋くんが行うそれぞれの操作の結果は以下のようになります。

  • 高橋くんがウェブサイトにログインした状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしているので、エラーは返されない。
  • 高橋くんは公開ページにアクセスする。
  • 高橋くんがウェブサイトにログインしていない状態になる。
  • 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしていないので、認証エラーが返される。
  • 高橋くんは公開ページにアクセスする。

高橋くんが認証エラーを受け取るのは 5 回目の操作のみなので、1 を出力してください。


入力例 2

4
private
private
private
logout

出力例 2

3

連続で非公開ページにアクセスしようとした場合、操作のたびに認証エラーを受け取ります。

ログインしていない状態からさらにログアウト操作をした場合には認証エラーは返されないことに注意してください。


入力例 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

出力例 3

3

Score : 200 points

Problem Statement

One day, Takahashi performed N operations on a certain web site.

The i‑th operation (1 \le i \le N) is represented by a string S_i, which is one of the following:

  • S _ i= login: He performs a login operation and becomes logged in to the site.
  • S _ i= logout: He performs a logout operation and becomes not logged in to the site.
  • S _ i= public: He accesses a public page of the site.
  • S _ i= private: He accesses a private page of the site.

The site returns an authentication error if and only if he accesses a private page while he is not logged in.

Logging in again while already logged in, or logging out again while already logged out, does not cause an error. Even after an authentication error is returned, he continues performing the remaining operations.

Initially, he is not logged in.

Print the number of operations among the N operations at which he receives an authentication error.

Constraints

  • 1 \le N \le 100
  • N is an integer.
  • Each S_i is one of login, logout, public, private. (1 \le i \le N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print the number of times Takahashi receives an authentication error.


Sample Input 1

6
login
private
public
logout
private
public

Sample Output 1

1

The result of each operation is as follows:

  • Takahashi becomes logged in.
  • He accesses a private page. He is logged in, so no error is returned.
  • He accesses a public page.
  • He becomes logged out.
  • He accesses a private page. He is not logged in, so an authentication error is returned.
  • He accesses a public page.

An authentication error occurs only at the 5th operation, so print 1.


Sample Input 2

4
private
private
private
logout

Sample Output 2

3

If he tries to access private pages consecutively while not logged in, he receives an authentication error for each such operation.

Note that logging out again while already logged out does not cause an authentication error.


Sample Input 3

20
private
login
private
logout
public
logout
logout
logout
logout
private
login
login
private
login
private
login
public
private
logout
private

Sample Output 3

3
E - Sensors

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

配点 : 300

問題文

HW 列のマス目の上に 0 個以上のセンサが配置されています。上から i 行目、左から j 列目のマス目を (i, j) と表記します。
センサが配置されているマス目の情報は長さ W の文字列 S_1, S_2, \ldots, S_H によって与えられ、S_ij 文字目が # のとき、またそのときに限り (i, j) にセンサが配置されています。
このセンサは上下左右斜めに隣接しているマス目に存在する他のセンサと連動し、一つのセンサとして動作します。 ただし、マス目 (x, y)(x', y') が上下左右斜めに隣接しているとは、\max(|x-x'|,|y-y'|) = 1 であることを指します。
また、センサ A とセンサ B が連動し、センサ A とセンサ C が連動しているとき、センサ B とセンサ C も連動することに注意してください。

連動するセンサを一つのセンサと見なしたとき、このマス目の上にあるセンサの個数を求めてください。

制約

  • 1 \leq H, W \leq 1000
  • H, W は整数
  • S_i は各文字が # または . である長さ W の文字列

入力

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

H W
S_1
S_2
\vdots
S_H

出力

答えを出力せよ。


入力例 1

5 6
.##...
...#..
....##
#.#...
..#...

出力例 1

3

連動しているセンサを一つのセンサと見なしたとき、

  • (1,2),(1,3),(2,4),(3,5),(3,6) にあるセンサが連動したもの
  • (4,1) にあるセンサ
  • (4,3),(5,3) にあるセンサが連動したもの

3 つのセンサが存在します。


入力例 2

3 3
#.#
.#.
#.#

出力例 2

1

入力例 3

4 2
..
..
..
..

出力例 3

0

入力例 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

出力例 4

7

Score : 300 points

Problem Statement

There are zero or more sensors placed on a grid of H rows and W columns. Let (i, j) denote the square in the i-th row from the top and the j-th column from the left.
Whether each square contains a sensor is given by the strings S_1, S_2, \ldots, S_H, each of length W. (i, j) contains a sensor if and only if the j-th character of S_i is #.
These sensors interact with other sensors in the squares horizontally, vertically, or diagonally adjacent to them and operate as one sensor. Here, a cell (x, y) and a cell (x', y') are said to be horizontally, vertically, or diagonally adjacent if and only if \max(|x-x'|,|y-y'|) = 1.
Note that if sensor A interacts with sensor B and sensor A interacts with sensor C, then sensor B and sensor C also interact.

Considering the interacting sensors as one sensor, find the number of sensors on this grid.

Constraints

  • 1 \leq H, W \leq 1000
  • H and W are integers.
  • S_i is a string of length W where each character is # or ..

Input

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

H W
S_1
S_2
\vdots
S_H

Output

Print the answer.


Sample Input 1

5 6
.##...
...#..
....##
#.#...
..#...

Sample Output 1

3

When considering the interacting sensors as one sensor, the following three sensors exist:

  • The interacting sensors at (1,2),(1,3),(2,4),(3,5),(3,6)
  • The sensor at (4,1)
  • The interacting sensors at (4,3),(5,3)

Sample Input 2

3 3
#.#
.#.
#.#

Sample Output 2

1

Sample Input 3

4 2
..
..
..
..

Sample Output 3

0

Sample Input 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

Sample Output 4

7