A - Day of Takahashi

Time Limit: 2 sec / Memory Limit: 256 MB

配点:100

問題文

AtCoder 王国では, 55 日のような月の数と日の数が同じ日を「高橋」と言う.
201811 日から 2018ab 日までに, 「高橋」は何日あるか.
ただし, AtCoder 王国ではグレゴリオ暦を利用しているものとする.

制約

  • a1 以上 12 以下の整数
  • b1 以上 31 以下の整数
  • 2018ab 日はグレゴリオ暦において正しい日付である.

入力

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

a b

出力

201811 日から 2018ab 日までに「高橋」は何日あるか、出力しなさい。


入力例 1

5 5

出力例 1

5

11 日, 22 日, 33 日, 44 日, 55 日, 合計 5 日が「高橋」です.


入力例 2

2 1

出力例 2

1

11 日のみが「高橋」です.


入力例 3

11 30

出力例 3

11

1/1, 2/2, 3/3, 4/4, 5/5, 6/6, 7/7, 8/8, 9/9, 10/10, 11/11 の, 合計 11 日です.

Score: 100 points

Problem Statement

In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.

In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?

Constraints

  • a is an integer between 1 and 12 (inclusive).
  • b is an integer between 1 and 31 (inclusive).
  • 2018-a-b is a valid date in Gregorian calendar.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.


Sample Input 1

5 5

Sample Output 1

5

There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.


Sample Input 2

2 1

Sample Output 2

1

There is only one day that is Takahashi: 1-1.


Sample Input 3

11 30

Sample Output 3

11

There are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.

B - Maximum Sum

Time Limit: 2 sec / Memory Limit: 256 MB

配点:200

問題文

黒板に, 3 つの正の整数 A, B, C が書かれています. E869120 君は, 以下の操作を K 回行います.

  • 黒板に書かれている整数のうち 1 つを選び, これを 2 倍した値に書き換える.

さて, K 回の操作を終えた後の, 黒板に書かれる整数の合計としてありうる最大の値はいくつでしょうか?

制約

  • A, B, C1 以上 50 以下の整数
  • K1 以上 10 以下の整数

入力

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

A B C
K

出力

E869120 君が K 回の操作を終えた後の, 黒板に書かれる整数の合計としてありうる最大の値を出力しなさい.


入力例 1

5 3 11
1

出力例 1

30

この入力例では, 最初, 黒板に 5, 3, 11 が書かれており, E869120 君は 1 回の操作を行うことができます.
そのとき, 彼は次の 3 つのうちのどれかのことができます.

  1. 52 倍する」という操作を行うとき:最終的に黒板に書かれる整数は 10, 3, 11 です.
  2. 32 倍する」という操作を行うとき:最終的に黒板に書かれる整数は 5, 6, 11 です.
  3. 112 倍する」という操作を行うとき:最終的に黒板に書かれる整数は 5, 3, 22 です.

3 を選ぶと, 最終的に黒板に書かれる整数の合計は 5 + 3 + 22 = 30 となり, これは 1. 〜 3. の中で最大です.


入力例 2

3 3 4
2

出力例 2

22

E869120 君は 2 回の操作を行うことができます. 次のような方法で最終的に黒板に書かれる整数の合計が最大になります.
まず, 「42 倍する」という操作を行うとき:黒板に書かれた整数は 3, 3, 8 になります.
次に, 「82 倍する」という操作を行うとき:黒板に書かれた整数は 3, 3, 16 になります.
このとき, 最終的に黒板に書かれる整数の合計は 3 + 3 + 16 = 22 となります.

Score: 200 points

Problem Statement

There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:

  • Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.

What is the largest possible sum of the integers written on the blackboard after K operations?

Constraints

  • A, B and C are integers between 1 and 50 (inclusive).
  • K is an integer between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C
K

Output

Print the largest possible sum of the integers written on the blackboard after K operations by E869220.


Sample Input 1

5 3 11
1

Sample Output 1

30

In this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.
There are three choices:

  1. Double 5: The integers written on the board after the operation are 10, 3, 11.
  2. Double 3: The integers written on the board after the operation are 5, 6, 11.
  3. Double 11: The integers written on the board after the operation are 5, 3, 22.

If he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.


Sample Input 2

3 3 4
2

Sample Output 2

22

E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:

  • First, double 4. The integers written on the board are now 3, 3, 8.
  • Next, double 8. The integers written on the board are now 3, 3, 16.

Then, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.

C - Grid Repainting 2

Time Limit: 2 sec / Memory Limit: 256 MB

配点:300

問題文

HW 列のマス目で表されるキャンバスがあります. 上から i 番目, 左から j 番目のマスを (i, j) と表します.
最初, すべてのマス目は白色です. square1001 君は, 黒い絵の具を使って絵を描きたいと思いました. 具体的には, square1001 君の目標は, s_{i, j}= # のときマス (i, j) を黒色, s_{i, j}= . のときマス (i, j) を白色にすることです.
しかし, 彼は絵を描くことが得意ではないので, 何回か (0 回でもよい)「上下左右に隣接する 2 つのマスを選び, 両方黒く塗る」ことしかできません. ただし, すでに黒く塗られているマスを選ぶこともでき, この場合マスの色は黒のまま変わりません.
square1001 君が目標を達成することができるか判定してください.

制約

  • H1 以上 50 以下の整数
  • W1 以上 50 以下の整数
  • すべての (i, j) \ (1 \leq i \leq H, 1 \leq j \leq W) に対して, s_{i, j}# または .

入力

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

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

出力

square1001 君が目標を達成することができるならば Yes、達成できないならば No と出力しなさい.


入力例 1

3 3
.#.
###
.#.

出力例 1

Yes

目標を達成する手順の一例として, 下の図の方法が挙げられます. この図では, 「次に黒く塗るマス」を「☆」で表しています.


入力例 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

出力例 2

No

square1001 君は目標を達成することができません.


入力例 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

出力例 3

Yes

Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.

Constraints

  • H is an integer between 1 and 50 (inclusive).
  • W is an integer between 1 and 50 (inclusive).
  • For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.


Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.


Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.


Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes
D - Five, Five Everywhere

Time Limit: 2 sec / Memory Limit: 256 MB

配点:400

問題文

以下の条件を満たす, 長さ N の数列 a_1, a_2, ..., a_N1 つ出力してください.

  • a_i \ (1 \leq i \leq N)55 \ 555 以下の素数である.
  • a_1, a_2, ..., a_N の値はすべて異なる.
  • a_1, a_2, ..., a_N からどの異なる 5 個の整数を選んでも, この合計は合成数になる.

条件を満たす数列が複数個存在するとき、条件を満たすもののうちどのような数列を出力しても正解となります.

備考

2 以上の整数 N が, 1N 以外のどの正の整数でも割り切れなければ N は「素数」であり, そうでない場合 N は「合成数」である.

制約

  • N5 以上 55 以下の整数

入力

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

N

出力

1 行に, N 個の数 a_1, a_2, a_3, ..., a_N を空白区切りで出力しなさい.


入力例 1

5

出力例 1

3 5 7 11 31

まず, 3, 5, 7, 11, 31 は全て異なり, 全て素数です.
これらから 5 個の整数を選ぶ方法は, 「全てを選ぶ」の 1 通りのみです. a_1+a_2+a_3+a_4+a_5=57 であり, この値は合成数なので問題文の条件を満たします.
他にも, 2 3 5 7 13 11 13 17 19 31 7 11 5 31 3 などを出力しても正解となります.


入力例 2

6

出力例 2

2 3 5 7 11 13
  • 2, 3, 5, 7, 11, 13 は全て異なる素数です.
  • 2+3+5+7+11=28 であり, 合成数です.
  • 2+3+5+7+13=30 であり, 合成数です.
  • 2+3+5+11+13=34 であり, 合成数です.
  • 2+3+7+11+13=36 であり, 合成数です.
  • 2+5+7+11+13=38 であり, 合成数です.
  • 3+5+7+11+13=39 であり, 合成数です.

よって, 2 3 5 7 11 13 は条件を満たす数列です.


入力例 3

8

出力例 3

2 5 7 13 19 37 67 79

Score: 400 points

Problem Statement

Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:

  • a_i (1 \leq i \leq N) is a prime number at most 55 555.
  • The values of a_1, a_2, ..., a_N are all different.
  • In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.

If there are multiple such sequences, printing any of them is accepted.

Notes

An integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N, and called a composite number otherwise.

Constraints

  • N is an integer between 5 and 55 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.


Sample Input 1

5

Sample Output 1

3 5 7 11 31

Let us see if this output actually satisfies the conditions.
First, 3, 5, 7, 11 and 31 are all different, and all of them are prime numbers.
The only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57, which is a composite number.
There are also other possible outputs, such as 2 3 5 7 13, 11 13 17 19 31 and 7 11 5 31 3.


Sample Input 2

6

Sample Output 2

2 3 5 7 11 13
  • 2, 3, 5, 7, 11, 13 are all different prime numbers.
  • 2+3+5+7+11=28 is a composite number.
  • 2+3+5+7+13=30 is a composite number.
  • 2+3+5+11+13=34 is a composite number.
  • 2+3+7+11+13=36 is a composite number.
  • 2+5+7+11+13=38 is a composite number.
  • 3+5+7+11+13=39 is a composite number.

Thus, the sequence 2 3 5 7 11 13 satisfies the conditions.


Sample Input 3

8

Sample Output 3

2 5 7 13 19 37 67 79