A - Five Integers

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

配点 : 100

問題文

与えられる 5 つの整数 A, B, C, D, E の中に何種類の整数があるかを出力してください。

制約

  • 0 \leq A, B, C, D, E \leq 100
  • 入力はすべて整数

入力

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

A B C D E

出力

答えを出力せよ。


入力例 1

31 9 24 31 24

出力例 1

3

与えられる 5 つの整数 31, 9, 24, 31, 24 の中には、9, 24, 31 という 3 種類の整数があります。 よって、3 を出力します。


入力例 2

0 0 0 0 0

出力例 2

1

Score : 100 points

Problem Statement

Print how many distinct integers there are in given five integers A, B, C, D, and E.

Constraints

  • 0 \leq A, B, C, D, E \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D E

Output

Print the answer.


Sample Input 1

31 9 24 31 24

Sample Output 1

3

In the given five integers 31, 9, 24, 31, and 24, there are three distinct integers 9, 24, and 31. Thus, 3 should be printed.


Sample Input 2

0 0 0 0 0

Sample Output 2

1
B - Round decimals

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

配点 : 100

問題文

小数第三位までで表すことのできる実数 X が、小数第三位まで入力されます。
X を小数第一位で四捨五入した結果として得られる整数を出力してください。

制約

  • 0 \leq X < 100
  • X は小数第三位までで表現可能である。
  • X は小数第三位まで与えられる。

入力

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

X

出力

X を小数第一位で四捨五入して得られる整数を出力せよ。


入力例 1

3.456

出力例 1

3

3.456 の小数第一位は 4 であるので、3.456 を小数第一位で四捨五入した値は 3 となります。


入力例 2

99.500

出力例 2

100

入力例 3

0.000

出力例 3

0

Score : 100 points

Problem Statement

You are given a real number X, which is representable using at most three decimal digits, with three decimal digits.
Round X to the nearest integer and print the result.

Constraints

  • 0 \leq X < 100
  • X is representable using at most three decimal digits.
  • X has three decimal digits in input.

Input

Input is given from Standard Input in the following format:

X

Output

Print the integer resulting from rounding X to the nearest integer.


Sample Input 1

3.456

Sample Output 1

3

The digit in the first decimal place of 3.456 is 4, so we should round it down to 3.


Sample Input 2

99.500

Sample Output 2

100

Sample Input 3

0.000

Sample Output 3

0
C - Discord

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

配点 : 200

問題文

1,2,\ldots,N と番号づけられた N 人が M 回、一列に並んで集合写真を撮りました。i 番目の撮影で左から j 番目に並んだ人の番号は a_{i,j} です。

ある二人組は M 回の撮影で一度も連続して並ばなかった場合、不仲である可能性があります。  

不仲である可能性がある二人組の個数を求めてください。なお、人 x と人 y からなる二人組と人 y と人 x からなる二人組は区別しません。

制約

  • 2 \leq N \leq 50
  • 1 \leq M \leq 50
  • 1 \leq a_{i,j} \leq N
  • a_{i,1},\ldots,a_{i,N} には 1,\ldots,N1 回ずつ現れる
  • 入力はすべて整数

入力

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

N M
a_{1,1} \ldots a_{1,N}
\vdots
a_{M,1} \ldots a_{M,N}

出力

答えを出力せよ。


入力例 1

4 2
1 2 3 4
4 3 1 2

出力例 1

2

1 と人 4 からなる二人組と、人 2 と人 4 からなる二人組がそれぞれ不仲である可能性があります。


入力例 2

3 3
1 2 3
3 1 2
1 2 3

出力例 2

0

入力例 3

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

出力例 3

6

Score : 200 points

Problem Statement

N people numbered 1,2,\ldots,N were in M photos. In each of the photos, they stood in a single line. In the i-th photo, the j-th person from the left is person a_{i,j}.

Two people who did not stand next to each other in any of the photos may be in a bad mood.

How many pairs of people may be in a bad mood? Here, we do not distinguish a pair of person x and person y, and a pair of person y and person x.

Constraints

  • 2 \leq N \leq 50
  • 1 \leq M \leq 50
  • 1 \leq a_{i,j} \leq N
  • a_{i,1},\ldots,a_{i,N} contain each of 1,\ldots,N exactly once.
  • All values in the input are integers.

Input

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

N M
a_{1,1} \ldots a_{1,N}
\vdots
a_{M,1} \ldots a_{M,N}

Output

Print the answer.


Sample Input 1

4 2
1 2 3 4
4 3 1 2

Sample Output 1

2

The pair of person 1 and person 4, and the pair of person 2 and person 4, may be in a bad mood.


Sample Input 2

3 3
1 2 3
3 1 2
1 2 3

Sample Output 2

0

Sample Input 3

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

Sample Output 3

6
D - log2(N)

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

配点 : 200

問題文

正整数 N が与えられるので、 2^k \le N となる最大の整数 k を求めてください。

制約

  • N1 \le N \le 10^{18} を満たす整数である

入力

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

N

出力

答えを整数として出力せよ。


入力例 1

6

出力例 1

2
  • k=22^2=4 \le 6 を満たします。
  • k \ge 3 である全ての整数 k について 2^k > 6 となります。

以上より、答えは k=2 となります。


入力例 2

1

出力例 2

0

2^0=1 であることに注意してください。


入力例 3

1000000000000000000

出力例 3

59

入力が 32 bit 整数に収まらない場合があります。

Score : 200 points

Problem Statement

Given a positive integer N, find the maximum integer k such that 2^k \le N.

Constraints

  • N is an integer satisfying 1 \le N \le 10^{18}.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

6

Sample Output 1

2
  • k=2 satisfies 2^2=4 \le 6.
  • For every integer k such that k \ge 3, 2^k > 6 holds.

Therefore, the answer is k=2.


Sample Input 2

1

Sample Output 2

0

Note that 2^0=1.


Sample Input 3

1000000000000000000

Sample Output 3

59

The input value may not fit into a 32-bit integer.

E - Choose Elements

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

配点 : 300

問題文

長さ N の整数からなる数列 A=(A_1,\ldots,A_N),B=(B_1,\ldots,B_N) が与えられます。

以下の条件を全て満たす長さ N の数列 X=(X_1,\ldots,X_N) が存在するかを判定してください。

  • すべての i(1\leq i\leq N) について、X_i = A_i または X_i = B_i

  • すべての i(1\leq i\leq N-1) について、|X_i - X_{i+1}| \leq K

制約

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq K \leq 10^9
  • 1 \leq A_i,B_i \leq 10^9
  • 入力は全て整数である

入力

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

N K
A_1 \ldots A_N
B_1 \ldots B_N

出力

条件を全て満たす X が存在するならば Yes と、存在しないならば No と出力せよ。


入力例 1

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

出力例 1

Yes

X=(9,6,3,7,5) が全ての条件を満たします。


入力例 2

4 90
1 1 1 100
1 2 3 100

出力例 2

No

条件を満たす X は存在しません。


入力例 3

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000

出力例 3

Yes

Score : 300 points

Problem Statement

You are given two sequences, each of length N, consisting of integers: A=(A_1, \ldots, A_N) and B=(B_1, \ldots, B_N).

Determine whether there is a sequence of length N, X=(X_1, \ldots, X_N), satisfying all of the conditions below.

  • X_i = A_i or X_i = B_i, for every i(1\leq i\leq N).

  • |X_i - X_{i+1}| \leq K, for every i(1\leq i\leq N-1).

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 0 \leq K \leq 10^9
  • 1 \leq A_i,B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N
B_1 \ldots B_N

Output

If there is an X that satisfies all of the conditions, print Yes; otherwise, print No.


Sample Input 1

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

Sample Output 1

Yes

X=(9,6,3,7,5) satisfies all conditions.


Sample Input 2

4 90
1 1 1 100
1 2 3 100

Sample Output 2

No

No X satisfies all conditions.


Sample Input 3

4 1000000000
1 1 1000000000 1000000000
1 1000000000 1 1000000000

Sample Output 3

Yes