A - Equally

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

3 つの整数 A,B,C が与えられます。これら 3 つの整数を 2 つ以上のグループに分けて、それぞれのグループ内の数の和を等しくできるかどうか判定してください。

制約

  • 1 \leq A,B,C \leq 1000
  • 入力はすべて整数

入力

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

A B C

出力

A,B,C を和の等しい 2 つ以上のグループに分けることができるならば Yes を、できないならば No を出力せよ。


入力例 1

3 8 5

出力例 1

Yes

例えば、(3,5),(8)2 つのグループに分けることで、それぞれのグループ内の和をどちらも 8 にすることができます。


入力例 2

2 2 2

出力例 2

Yes

(2),(2),(2)3 つのグループに分けることで、それぞれのグループ内の和をどれも 2 にすることができます。


入力例 3

1 2 4

出力例 3

No

どのように 2 つ以上のグループに分けても、和を等しくすることはできません。

Score : 100 points

Problem Statement

You are given three integers A,B,C. Determine whether it is possible to divide these three integers into two or more groups so that these groups have equal sums.

Constraints

  • 1 \leq A,B,C \leq 1000
  • All input values are integers.

Input

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

A B C

Output

If it is possible to divide A,B,C into two or more groups with equal sums, print Yes; otherwise, print No.


Sample Input 1

3 8 5

Sample Output 1

Yes

For example, by dividing into two groups (3,5) and (8), each group can have the sum 8.


Sample Input 2

2 2 2

Sample Output 2

Yes

By dividing into three groups (2),(2),(2), each group can have the sum 2.


Sample Input 3

1 2 4

Sample Output 3

No

No matter how you divide them into two or more groups, it is not possible to make the sums equal.

B - 321-like Checker

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

以下の条件を満たす正整数 x321-like Number と呼びます。

  • x の各桁を上から見ると狭義単調減少になっている。
  • すなわち、xd 桁の整数だとすると、 1 \le i < d を満たす全ての整数 i について以下の条件を満たす。
    • ( x の上から i 桁目 ) > ( x の上から i+1 桁目 )

なお、 1 桁の正整数は必ず 321-like Number であることに注意してください。

例えば、 321,96410,1 は 321-like Number ですが、 123,2109,86411 は 321-like Number ではありません。

N が入力として与えられるので、 N が 321-like Number なら Yes 、そうでないなら No と出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 99999

入力

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

N

出力

N が 321-like Number なら Yes 、そうでないなら No と出力せよ。


入力例 1

321

出力例 1

Yes

N=321 に対して、以下が成り立ちます。

  • 上から 1 桁目の 3 は上から 2 桁目の 2 より大きい。
  • 上から 2 桁目の 2 は上から 3 桁目の 1 より大きい。

以上より、 321 は 321-like Number です。


入力例 2

123

出力例 2

No

N=123 について、例えば以下が成り立ちます。

  • 上から 1 桁目の 1 は上から 2 桁目の 2 より大きくない。

このことから、 123 は 321-like Number ではありません。


入力例 3

1

出力例 3

Yes

入力例 4

86411

出力例 4

No

Score : 100 points

Problem Statement

A positive integer x is called a 321-like Number when it satisfies the following condition.

  • The digits of x are strictly decreasing from top to bottom.
  • In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d:
    • (the i-th digit from the top of x) > (the (i+1)-th digit from the top of x).

Note that all one-digit positive integers are 321-like Numbers.

For example, 321, 96410, and 1 are 321-like Numbers, but 123, 2109, and 86411 are not.

You are given N as input. Print Yes if N is a 321-like Number, and No otherwise.

Constraints

  • All input values are integers.
  • 1 \le N \le 99999

Input

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

N

Output

Print Yes if N is a 321-like Number, and No otherwise.


Sample Input 1

321

Sample Output 1

Yes

For N=321, the following holds:

  • The first digit from the top, 3, is greater than the second digit from the top, 2.
  • The second digit from the top, 2, is greater than the third digit from the top, 1.

Thus, 321 is a 321-like Number.


Sample Input 2

123

Sample Output 2

No

For N=123, the following holds:

  • The first digit from the top, 1, is not greater than the second digit from the top, 2.

Thus, 123 is not a 321-like Number.


Sample Input 3

1

Sample Output 3

Yes

Sample Input 4

86411

Sample Output 4

No
C - Tournament Result

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 人の人が総当り戦の試合をしました。

NN 列からなる試合の結果の表 A が与えられます。Ai 行目 j 列目の要素を A_{i,j} と表します。
A_{i,j}i=j のとき - であり、それ以外のとき W, L, D のいずれかです。
A_{i,j}W, L, D であることは、人 i が人 j との試合に勝った、負けた、引き分けたことをそれぞれ表します。

与えられた表に矛盾があるかどうかを判定してください。

次のいずれかが成り立つとき、与えられた表には矛盾があるといいます。

  • ある組 (i,j) が存在して、人 i が人 j に勝ったが、人 j が人 i に負けていない
  • ある組 (i,j) が存在して、人 i が人 j に負けたが、人 j が人 i に勝っていない
  • ある組 (i,j) が存在して、人 i が人 j に引き分けたが、人 j が人 i に引き分けていない

制約

  • 2 \leq N \leq 1000
  • A_{i,i}- である
  • i\neq j のとき、A_{i,j}W, L, D のいずれかである

入力

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

N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}

出力

与えられた表に矛盾がないとき correct、矛盾があるとき incorrect と出力せよ。


入力例 1

4
-WWW
L-DD
LD-W
LDW-

出力例 1

incorrect

3 が人 4 に勝ったにもかかわらず、人 4 も人 3 に勝ったことになっており、矛盾しています。


入力例 2

2
-D
D-

出力例 2

correct

矛盾はありません。

Score : 200 points

Problem Statement

N players played a round-robin tournament.

You are given an N-by-N table A containing the results of the matches. Let A_{i,j} denote the element at the i-th row and j-th column of A.
A_{i,j} is - if i=j, and W, L, or D otherwise.
A_{i,j} is W if Player i beat Player j, L if Player i lost to Player j, and D if Player i drew with Player j.

Determine whether the given table is contradictory.

The table is said to be contradictory when some of the following holds:

  • There is a pair (i,j) such that Player i beat Player j, but Player j did not lose to Player i;
  • There is a pair (i,j) such that Player i lost to Player j, but Player j did not beat Player i;
  • There is a pair (i,j) such that Player i drew with Player j, but Player j did not draw with Player i.

Constraints

  • 2 \leq N \leq 1000
  • A_{i,i} is -.
  • A_{i,j} is W, L, or D, for i\neq j.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}\ldots A_{1,N}
A_{2,1}A_{2,2}\ldots A_{2,N}
\vdots
A_{N,1}A_{N,2}\ldots A_{N,N}

Output

If the given table is not contradictory, print correct; if it is contradictory, print incorrect.


Sample Input 1

4
-WWW
L-DD
LD-W
LDW-

Sample Output 1

incorrect

Player 3 beat Player 4, while Player 4 also beat Player 3, which is contradictory.


Sample Input 2

2
-D
D-

Sample Output 2

correct

There is no contradiction.

D - Full House 3

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

7 枚のカードがあります。i 番目 (i=1,\ldots,7) のカードには整数 A_i が書かれています。
これらのカードから 5 枚を選び、フルハウスとできるか判定してください。

ただし、 5 枚組のカードは以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。

  • 異なる整数 x,y について、 x が書かれたカード 3 枚と y が書かれたカード 2 枚からなる。

制約

  • A_i1 以上 13 以下の整数

入力

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

A_1 A_2 A_3 A_4 A_5 A_6 A_7

出力

5 枚カードを選んでフルハウスとできるなら Yes 、そうでないなら No と出力せよ。


入力例 1

1 4 1 4 2 1 3

出力例 1

Yes

例えば、 (1,1,1,4,4) とカードを選択することでフルハウスとできます。


入力例 2

11 12 13 10 13 12 11

出力例 2

No

7 枚のカードからどのように 5 枚を選んでもフルハウスとはできません。


入力例 3

7 7 7 7 7 7 7

出力例 3

No

同じカード 5 枚組はフルハウスではないことに注意してください。


入力例 4

13 13 1 1 7 4 13

出力例 4

Yes

Score : 250 points

Problem Statement

We have seven cards. The i-th card (i=1,\ldots,7) has an integer A_i written on it.
Determine whether it is possible to choose five of them so that the chosen cards form a full house.

A set of five cards is called a full house if and only if the following conditions are satisfied:

  • For different integers x and y, there are three cards with x and two cards with y.

Constraints

  • A_i is an integer between 1 and 13, inclusive.

Input

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

A_1 A_2 A_3 A_4 A_5 A_6 A_7

Output

If a full house can be formed by choosing five cards, print Yes; otherwise, print No.


Sample Input 1

1 4 1 4 2 1 3

Sample Output 1

Yes

For example, by choosing the cards (1,1,1,4,4), we can form a full house.


Sample Input 2

11 12 13 10 13 12 11

Sample Output 2

No

No five cards chosen from the seven cards form a full house.


Sample Input 3

7 7 7 7 7 7 7

Sample Output 3

No

Note that five identical cards do not form a full house.


Sample Input 4

13 13 1 1 7 4 13

Sample Output 4

Yes
E - Even Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

非負整数 n が次の条件を満たすとき、n良い整数 と呼びます。

  • n10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。

例えば 068 および 2024 は良い整数です。

整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。

制約

  • 1 \leq N \leq 10^{12}
  • N は整数

入力

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

N

出力

小さい方から N 番目の良い整数を出力せよ。


入力例 1

8

出力例 1

24

良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。


入力例 2

133

出力例 2

2024

入力例 3

31415926535

出力例 3

2006628868244228

Score: 300 points

Problem Statement

A non-negative integer n is called a good integer when it satisfies the following condition:

  • All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).

For example, 0, 68, and 2024 are good integers.

You are given an integer N. Find the N-th smallest good integer.

Constraints

  • 1 \leq N \leq 10^{12}
  • N is an integer.

Input

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

N

Output

Print the N-th smallest good integer.


Sample Input 1

8

Sample Output 1

24

The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.


Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228