A - Shout Everyday

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

配点 : 150

問題文

AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。

AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。

制約

  • 0\leq A,B,C\lt 24
  • A,B,C は相異なる
  • 入力は全て整数

入力

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

A B C

出力

高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes を、そうでないならば No を出力せよ。


入力例 1

21 8 14

出力例 1

Yes

高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes を出力します。


入力例 2

0 21 7

出力例 2

No

高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No を出力します。


入力例 3

10 7 17

出力例 3

No

Score : 150 points

Problem Statement

In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.

Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.

Constraints

  • 0\leq A,B,C\lt 24
  • A, B, and C are pairwise different.
  • All input values are integers.

Input

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

A B C

Output

Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.


Sample Input 1

21 8 14

Sample Output 1

Yes

Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes.


Sample Input 2

0 21 7

Sample Output 2

No

Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No.


Sample Input 3

10 7 17

Sample Output 3

No
B - Last Two Digits

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

配点 : 100

問題文

100 以上の整数 N が与えられます。N の下 2 桁を出力してください。

ただし、N の下 2 桁とは十の位と一の位をこの順に並べたものを言います。

制約

  • 100 \le N \le 999
  • N は整数である。

入力

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

N

出力

答えを出力せよ。


入力例 1

254

出力例 1

54

254 の下 2 桁は 54 であるため、54 を出力します。


入力例 2

101

出力例 2

01

101 の下 2 桁は 01 であるため、01 を出力します。

Score : 100 points

Problem Statement

You are given an integer N at least 100. Print the last two digits of N.

Strictly speaking, print the tens and ones digits of N in this order.

Constraints

  • 100 \le N \le 999
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

254

Sample Output 1

54

The last two digits of 254 are 54, which should be printed.


Sample Input 2

101

Sample Output 2

01

The last two digits of 101 are 01, which should be printed.

C - Failing Grade

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

配点 : 200

問題文

N 人の学生が試験を受けました。学生には学生 1, 学生 2, \dots, 学生 N と番号がついていて、学生 ia_i 点を取りました。

P 点未満の点数を取った学生は "不可" となり単位を取得できません。 "不可" となった学生の人数を答えてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq P \leq 100
  • 0 \leq a_i \leq 100 (1 \leq i \leq N)
  • 入力はすべて整数である。

入力

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

N P
a_1 a_2 \dots a_N

出力

"不可" となった学生の人数を出力せよ。


入力例 1

4 50
80 60 40 0

出力例 1

2

学生 180 点、学生 260 点と、 50 点以上の点数を取っているので "不可" とならず単位を取得できています。
一方、学生 340 点、学生 40 点で、 50 点を下回る点数を取っているので "不可" となります。よって答えは 2 人です。


入力例 2

3 90
89 89 89

出力例 2

3

入力例 3

2 22
6 37

出力例 3

1

Score : 200 points

Problem Statement

N students took an exam. The students are labeled as Student 1, Student 2, \dots, Student N, and Student i scored a_i points.

A student who scored less than P points are considered to have failed the exam and cannot earn the credit. Find the number of students who failed the exam.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq P \leq 100
  • 0 \leq a_i \leq 100 (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N P
a_1 a_2 \dots a_N

Output

Print the number of students who failed the exam.


Sample Input 1

4 50
80 60 40 0

Sample Output 1

2

Students 1 and 2, who scored 80 and 60 points, respectively, succeeded in scoring at least 50 points to earn the credit.
On the other hand, Students 3 and 4, who scored 40 and 0 points, respectively, fell below 50 points and failed the exam. Thus, the answer is 2.


Sample Input 2

3 90
89 89 89

Sample Output 2

3

Sample Input 3

2 22
6 37

Sample Output 3

1
D - Grid Walk

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

配点 : 200

問題文

HW 列のグリッドがあります。グリッドの上から i 番目、左から j 番目のマスをマス (i, j) と表記します。

マス (i, j)C_{i, j}. のとき空きマスであり、# のとき空きマスではありません。

高橋君は現在マス (S_i, S_j) におり、i = 1, 2, \ldots, |X| の順に以下のルールに従って行動します。

  • Xi 文字目が L のとき、高橋君が現在いるマスの 1 つ左のマスが存在し、そのマスが空きマスならば 1 つ左のマスに移動する。そうでないならば、現在いるマスに留まる。
  • Xi 文字目が R のとき、高橋君が現在いるマスの 1 つ右のマスが存在し、そのマスが空きマスならば 1 つ右のマスに移動する。そうでないならば、現在いるマスに留まる。
  • Xi 文字目が U のとき、高橋君が現在いるマスの 1 つ上のマスが存在し、そのマスが空きマスならば 1 つ上のマスに移動する。そうでないならば、現在いるマスに留まる。
  • Xi 文字目が D のとき、高橋君が現在いるマスの 1 つ下のマスが存在し、そのマスが空きマスならば 1 つ下のマスに移動する。そうでないならば、現在いるマスに留まる。

一連の行動を終えた後高橋君がどのマスにいるか出力してください。

制約

  • 1 \leq H, W \leq 50
  • 1 \leq S_i \leq H
  • 1 \leq S_j \leq W
  • H, W, S_i, S_j は整数
  • C_{i, j}. または #
  • C_{S_i, S_j} = .
  • XL, R, U, D からなる長さ 1 以上 50 以下の文字列

入力

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

H W
S_i S_j
C_{1, 1}C_{1, 2}\ldotsC_{1, W}
C_{2, 1}C_{2, 2}\ldotsC_{2, W}
\vdots
C_{H, 1}C_{H, 2}\ldotsC_{H, W}
X

出力

高橋君が一連の行動を終えた後にいるマスをマス (x, y) として、xy をこの順に空白区切りで出力せよ。


入力例 1

2 3
2 1
.#.
...
ULDRU

出力例 1

2 2

高橋君ははじめマス (2, 1) にいます。高橋君の一連の行動は以下のようになります。

  • X1 文字目は U であり、マス (2, 1)1 つ上のマスは存在し、そのマスは空きマスであるため 1 つ上のマスであるマス (1, 1) に移動する。
  • X2 文字目は L であり、マス (1, 1)1 つ左のマスは存在しないためマス (1, 1) に留まる。
  • X3 文字目は D であり、マス (1, 1)1 つ下のマスは存在し、そのマスは空きマスであるため 1 つ下のマスであるマス (2, 1) に移動する。
  • X4 文字目は R であり、マス (2, 1)1 つ右のマスは存在し、そのマスは空きマスであるため 1 つ右のマスであるマス (2, 2) に移動する。
  • X5 文字目は U であり、マス (2, 2)1 つ上のマスは存在するが、そのマスは空きマスではないためマス (2, 2) に留まる。

したがって一連の行動を終えた後に高橋君がいるマスはマス (2, 2) です。


入力例 2

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

出力例 2

2 4

入力例 3

6 6
1 1
.#####
######
######
######
######
######
RURLDLULLRULRDL

出力例 3

1 1

Score : 200 points

Problem Statement

There is a grid with 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.

Cell (i, j) is empty if C_{i, j} is ., and not empty if C_{i, j} is #.

Takahashi is currently at cell (S_i, S_j), and he will act according to the following rules for i = 1, 2, \ldots, |X| in order.

  • If the i-th character of X is L, and the cell to the left of his current cell exists and is empty, he moves to the cell to the left. Otherwise, he stays in the current cell.
  • If the i-th character of X is R, and the cell to the right of his current cell exists and is empty, he moves to the cell to the right. Otherwise, he stays in the current cell.
  • If the i-th character of X is U, and the cell above his current cell exists and is empty, he moves to the cell above. Otherwise, he stays in the current cell.
  • If the i-th character of X is D, and the cell below his current cell exists and is empty, he moves to the cell below. Otherwise, he stays in the current cell.

Print the cell where he is after completing the series of actions.

Constraints

  • 1 \leq H, W \leq 50
  • 1 \leq S_i \leq H
  • 1 \leq S_j \leq W
  • H, W, S_i, S_j are integers.
  • C_{i, j} is . or #.
  • C_{S_i, S_j} = .
  • X is a string of length between 1 and 50, inclusive, consisting of L, R, U, D.

Input

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

H W
S_i S_j
C_{1, 1}C_{1, 2}\ldotsC_{1, W}
C_{2, 1}C_{2, 2}\ldotsC_{2, W}
\vdots
C_{H, 1}C_{H, 2}\ldotsC_{H, W}
X

Output

Let (x, y) be the cell where Takahashi is after completing the series of actions. Print x and y, separated by a space.


Sample Input 1

2 3
2 1
.#.
...
ULDRU

Sample Output 1

2 2

Takahashi starts at cell (2, 1). His series of actions are as follows:

  • The 1st character of X is U, and the cell above (2, 1) exists and is an empty cell, so he moves to the cell above, which is (1, 1).
  • The 2nd character of X is L, and the cell to the left of (1, 1) does not exist, so he stays at (1, 1).
  • The 3rd character of X is D, and the cell below (1, 1) exists and is an empty cell, so he moves to the cell below, which is (2, 1).
  • The 4th character of X is R, and the cell to the right of (2, 1) exists and is an empty cell, so he moves to the cell to the right, which is (2, 2).
  • The 5th character of X is U, and the cell above (2, 2) exists but is not an empty cell, so he stays at (2, 2).

Therefore, after completing the series of actions, he is at cell (2, 2).


Sample Input 2

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

Sample Output 2

2 4

Sample Input 3

6 6
1 1
.#####
######
######
######
######
######
RURLDLULLRULRDL

Sample Output 3

1 1
E - Bingo 2

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

配点 : 300

問題文

N 行、横 N 列のマス目があり、上から i 行目、左から j 列目のマスには整数 N\times (i-1)+j が書かれています。

今から T ターンにわたって相異なる整数が宣言されます。i ターン目には A_i が宣言され、A_i が書かれたマスに印をつけます。初めてビンゴを達成するのは何ターン目か求めてください。ただし、T ターンの中でビンゴを達成しない場合は -1 を出力してください。

ここで、ビンゴを達成するとは以下のいずれかのうち少なくとも一つ満たされることを言います。

  • マス目の横の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する
  • マス目の縦の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する
  • マス目の対角線の列であって、列に含まれる N 個のマスすべてに印がついているものが存在する

制約

  • 2\leq N\leq 2\times 10^3
  • 1\leq T\leq \min(N^2,2\times 10^5)
  • 1\leq A_i\leq N^2
  • i\neq j ならば A_i\neq A_j
  • 入力は全て整数

入力

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

N T
A_1 A_2 \ldots A_T

出力

T ターンの中でビンゴを達成するならば初めてビンゴを達成するターンを、そうでないならば -1 を出力せよ。


入力例 1

3 5
5 1 8 9 7

出力例 1

4

マス目の状態は以下のように変化します。初めてビンゴを達成するのは 4 ターン目です。


入力例 2

3 5
4 2 9 7 5

出力例 2

-1

5 ターンの中でビンゴを達成できないので -1 を出力してください。


入力例 3

4 12
13 9 6 5 2 7 16 14 8 3 10 11

出力例 3

9

Score : 300 points

Problem Statement

There is an N \times N grid, where the cell at the i-th row from the top and the j-th column from the left contains the integer N \times (i-1) + j.

Over T turns, integers will be announced. On Turn i, the integer A_i is announced, and the cell containing A_i is marked. Determine the turn on which Bingo is achieved for the first time. If Bingo is not achieved within T turns, print -1.

Here, achieving Bingo means satisfying at least one of the following conditions:

  • There exists a row in which all N cells are marked.
  • There exists a column in which all N cells are marked.
  • There exists a diagonal line (from top-left to bottom-right or from top-right to bottom-left) in which all N cells are marked.

Constraints

  • 2 \leq N \leq 2 \times 10^3
  • 1 \leq T \leq \min(N^2, 2 \times 10^5)
  • 1 \leq A_i \leq N^2
  • A_i \neq A_j if i \neq j.
  • All input values are integers.

Input

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

N T
A_1 A_2 \ldots A_T

Output

If Bingo is achieved within T turns, print the turn number on which Bingo is achieved for the first time; otherwise, print -1.


Sample Input 1

3 5
5 1 8 9 7

Sample Output 1

4

The state of the grid changes as follows. Bingo is achieved for the first time on Turn 4.


Sample Input 2

3 5
4 2 9 7 5

Sample Output 2

-1

Bingo is not achieved within five turns, so print -1.


Sample Input 3

4 12
13 9 6 5 2 7 16 14 8 3 10 11

Sample Output 3

9