A - Four Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

0 以上 9999 以下の整数 N が与えられます。

N の先頭に必要なだけ 0 をつけ、4 桁の文字列にしたものを出力してください。

制約

  • 0 \leq N \leq 9999
  • N は整数

入力

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

N

出力

答えを出力せよ。


入力例 1

321

出力例 1

0321

3213 桁なので、先頭に 10 をつけると 4 桁になります。


入力例 2

7777

出力例 2

7777

入力例 3

1

出力例 3

0001

Score : 100 points

Problem Statement

You are given an integer N between 0 and 9999 (inclusive).

Print it as a four-digit string after appending to it the necessary number of leading zeros.

Constraints

  • 0 \leq N \leq 9999
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

321

Sample Output 1

0321

321 has three digits, so we need to add one leading zero to it to make it have four digits.


Sample Input 2

7777

Sample Output 2

7777

Sample Input 3

1

Sample Output 3

0001
B - Many A+B Problems

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 個の整数の 2 つ組 (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N) が与えられます。 各 i = 1, 2, \ldots, N について、A_i + B_i を出力してください。

制約

  • 1 \leq N \leq 1000
  • -10^9 \leq A_i, B_i \leq 10^9
  • 入力はすべて整数

入力

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

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には A_i+B_i を出力せよ。


入力例 1

4
3 5
2 -6
-5 0
314159265 123456789

出力例 1

8
-4
-5
437616054
  • 1 行目には、A_1 + B_1 = 3 + 5 = 8 を、
  • 2 行目には、A_2 + B_2 = 2 + (-6) = -4 を、
  • 3 行目には、A_3 + B_3 = (-5) + 0 = -5 を、
  • 4 行目には、A_4 + B_4 = 314159265 + 123456789 = 437616054 を出力します。

Score : 100 points

Problem Statement

You are given N pairs of integers: (A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N). For each i = 1, 2, \ldots, N, print A_i + B_i.

Constraints

  • 1 \leq N \leq 1000
  • -10^9 \leq A_i, B_i \leq 10^9
  • All values in the input 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

Print N lines. For i = 1, 2, \ldots, N, the i-th line should contain A_i+B_i.


Sample Input 1

4
3 5
2 -6
-5 0
314159265 123456789

Sample Output 1

8
-4
-5
437616054
  • The first line should contain A_1 + B_1 = 3 + 5 = 8.
  • The second line should contain A_2 + B_2 = 2 + (-6) = -4.
  • The third line should contain A_3 + B_3 = (-5) + 0 = -5.
  • The fourth line should contain A_4 + B_4 = 314159265 + 123456789 = 437616054.
C - Farthest Point

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

xy 平面上に 1 から N までの番号が付いた N 個の点があります。点 i は座標 (X_i, Y_i) にあり、相異なる 2 点の座標は異なります。

各点について、その点からの距離が最大である点を求めてその点の番号を出力してください。 ただし、距離が最大である点が複数ある場合はその中で最も番号が小さい点の番号を出力してください。

ここで、距離はユークリッド距離、すなわち 2(x_1,y_1)(x_2,y_2) に対し、この 2 点間の距離が \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}} であるものとして定められています。

制約

  • 2 \leq N \leq 100
  • -1000 \leq X_i, Y_i \leq 1000
  • i \neq j ならば (X_i, Y_i) \neq (X_j, Y_j)
  • 入力は全て整数である。

入力

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

N
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

N 行出力せよ。i 行目には点 i からの距離が最大である点の番号を出力せよ。


入力例 1

4
0 0
2 4
5 0
3 4

出力例 1

3
3
1
1

以下の図のように点が並んでいます。ここで P_i は点 i を表します。 1 からの距離が最大である点は点 3,4 で、その中で番号が小さいのは点 3 です。

2 からの距離が最大である点は点 3 です。

3 からの距離が最大である点は点 1,2 で、その中で番号が小さいのは点 1 です。

4 からの距離が最大である点は点 1 です。


入力例 2

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

出力例 2

6
6
6
6
6
4

Score: 200 points

Problem Statement

On the xy-plane, there are N points with ID numbers from 1 to N. Point i is located at coordinates (X_i, Y_i), and no two points have the same coordinates.

From each point, find the farthest point and print its ID number. If multiple points are the farthest, print the smallest of the ID numbers of those points.

Here, we use the Euclidean distance: for two points (x_1,y_1) and (x_2,y_2), the distance between them is \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}}.

Constraints

  • 2 \leq N \leq 100
  • -1000 \leq X_i, Y_i \leq 1000
  • (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
  • All input values are integers.

Input

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

N
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print N lines. The i-th line should contain the ID number of the farthest point from point i.


Sample Input 1

4
0 0
2 4
5 0
3 4

Sample Output 1

3
3
1
1

The following figure shows the arrangement of the points. Here, P_i represents point i. The farthest point from point 1 are points 3 and 4, and point 3 has the smaller ID number.

The farthest point from point 2 is point 3.

The farthest point from point 3 are points 1 and 2, and point 1 has the smaller ID number.

The farthest point from point 4 is point 1.


Sample Input 2

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

Sample Output 2

6
6
6
6
6
4
D - Nice Grid

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

次の図に示す、各マスが黒または白に塗られた縦 15\times15 列のグリッドにおいて、 上から R 行目、左から C 列目のマスが何色かを出力して下さい。

制約

  • 1 \leq R, C \leq 15
  • R, C は整数

入力

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

R C

出力

図のグリッドにおいて上から R 行目、左から C 列目のマスが黒色の場合は black と、白色の場合は white と出力せよ。 ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。


入力例 1

3 5

出力例 1

black

図のグリッドにおいて上から 3 行目、左から 5 列目のマスは黒色です。 よって、black と出力します。


入力例 2

4 5

出力例 2

white

図のグリッドにおいて上から 4 行目、左から 5 列目のマスは白色です。 よって、white と出力します。

Score : 200 points

Problem Statement

Print the color of the cell at the R-th row from the top and C-th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.

Constraints

  • 1 \leq R, C \leq 15
  • R and C are integers.

Input

Input is given from Standard Input in the following format:

R C

Output

In the grid above, if the color of the cell at the R-th row from the top and C-th column from the left is black, then print black; if the cell is white, then print white. Note that the judge is case-sensitive.


Sample Input 1

3 5

Sample Output 1

black

In the grid above, the cell at the 3-rd row from the top and 5-th column from the left is black. Thus, black should be printed.


Sample Input 2

4 5

Sample Output 2

white

In the grid above, the cell at the 4-th row from the top and 5-th column from the left is white. Thus, white should be printed.

E - Minimize Abs 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

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

非負整数 x,y に対する |x^2+y^2-D| の最小値を求めてください。

制約

  • 1\leq D \leq 2\times 10^{12}
  • 入力は全て整数

入力

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

D

出力

答えを出力せよ。


入力例 1

21

出力例 1

1

x=4,y=2 のとき |x^2+y^2-D| = |16+4-21|=1 となります。

|x^2+y^2-D|=0 を満たすような非負整数 x,y は存在しないので、答えは 1 です。


入力例 2

998244353

出力例 2

0

入力例 3

264428617

出力例 3

32

Score : 300 points

Problem Statement

You are given a positive integer D.

Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.

Constraints

  • 1\leq D \leq 2\times 10^{12}
  • All input values are integers.

Input

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

D

Output

Print the answer.


Sample Input 1

21

Sample Output 1

1

For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.

There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.


Sample Input 2

998244353

Sample Output 2

0

Sample Input 3

264428617

Sample Output 3

32