A - Tomorrow

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

AtCoder 国の暦では、1 年は 1 月から M 月までの M ヶ月からなり、どの月も 1 日から D 日までの D 日からなります。

AtCoder 国の暦で ymd 日の翌日は何年何月何日であるか求めてください。

制約

  • 1000 \leq y \leq 9000
  • 1 \leq m \leq M \leq 99
  • 1 \leq d \leq D \leq 99
  • 入力は全て整数である

入力

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

M D
y m d

出力

AtCoder 国の暦で ymd 日の翌日が y'm'd' 日であるとき、y',m',d' をこの順に空白区切りで出力せよ。


入力例 1

12 30
2023 12 30

出力例 1

2024 1 1

AtCoder 国の暦では 1 年は 12 ヶ月であり、どの月も 30 日からなります。 よって、20231230 日の翌日は 202411 日になります。


入力例 2

36 72
6789 23 45

出力例 2

6789 23 46

AtCoder 国の暦では 1 年は 36 ヶ月であり、どの月も 72 日からなります。 よって、67892345 日の翌日は 67892346 日になります。


入力例 3

12 30
2012 6 20

出力例 3

2012 6 21

Score : 100 points

Problem Statement

In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.

What day follows year y, month m, day d in this calendar?

Constraints

  • 1000 \leq y \leq 9000
  • 1 \leq m \leq M \leq 99
  • 1 \leq d \leq D \leq 99
  • All input values are integers.

Input

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

M D
y m d

Output

If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.


Sample Input 1

12 30
2023 12 30

Sample Output 1

2024 1 1

In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days. Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.


Sample Input 2

36 72
6789 23 45

Sample Output 2

6789 23 46

In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days. Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.


Sample Input 3

12 30
2012 6 20

Sample Output 3

2012 6 21
B - Exact Price

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋君の財布の中には 100 円硬貨が 1 枚以上入っており、それ以外には何も入っていません。

高橋君の財布の中の合計金額が X 円である可能性はありますか?

制約

  • 0 \leq X \leq 1000
  • 入力は全て整数

入力

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

X

出力

高橋君の財布の中の合計金額が X 円である可能性がある場合は Yes、そうでない場合は No と出力せよ。


入力例 1

500

出力例 1

Yes

財布に 100 円硬貨が 5 枚入っているとき、合計金額は 500 円になります。故に財布の中の合計金額は X=500 円になりうるため、Yes を出力します。


入力例 2

40

出力例 2

No

入力例 3

0

出力例 3

No

財布の中には 100 円硬貨が 1 枚以上入っていることに注意してください。

Score : 100 points

Problem Statement

Takahashi's purse has one or more 100-yen coins in it and nothing else. (Yen is the Japanese currency.)

Is it possible that the total amount of money in the purse is X yen?

Constraints

  • 0 \leq X \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible that the total amount of money in Takahashi's purse is X yen, print Yes; otherwise, print No.


Sample Input 1

500

Sample Output 1

Yes

If the purse has five 100-yen coins, the total amount of money is 500 yen. Thus, it is possible that the total amount is X=500 yen, so we should print Yes.


Sample Input 2

40

Sample Output 2

No

Sample Input 3

0

Sample Output 3

No

Note that the purse has at least one 100-yen coin.

C - typo

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

文字列 S, T が与えられます。以下の操作を高々 1行うことで、ST と一致させることができるかを判定してください。

  • S の隣り合う 2 文字を選び、入れ替える。

なお、上記の操作を一度も行わないことも可能です。

制約

  • S, T はそれぞれ英小文字のみからなる、長さ 2 以上 100 以下の文字列
  • S の長さと T の長さは等しい

入力

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

S
T

出力

問題文中の操作を高々 1 回行うことで ST と一致させることができるなら Yes を、できないなら No を出力せよ。


入力例 1

abc
acb

出力例 1

Yes

S2 文字目と 3 文字目を入れ替えることで、ST と一致させることができます。


入力例 2

aabb
bbaa

出力例 2

No

どのように操作を行っても、ST と一致させることはできません。


入力例 3

abcde
abcde

出力例 3

Yes

ST は既に一致しています。

Score : 200 points

Problem Statement

You are given two strings S and T. Determine whether it is possible to make S and T equal by doing the following operation at most once:

  • choose two adjacent characters in S and swap them.

Note that it is allowed to choose not to do the operation.

Constraints

  • Each of S and T is a string of length between 2 and 100 (inclusive) consisting of lowercase English letters.
  • S and T have the same length.

Input

Input is given from Standard Input in the following format:

S
T

Output

If it is possible to make S and T equal by doing the operation in Problem Statement at most once, print Yes; otherwise, print No.


Sample Input 1

abc
acb

Sample Output 1

Yes

You can swap the 2-nd and 3-rd characters of S to make S and T equal.


Sample Input 2

aabb
bbaa

Sample Output 2

No

There is no way to do the operation to make S and T equal.


Sample Input 3

abcde
abcde

Sample Output 3

Yes

S and T are already equal.

D - Failing Grade

Time Limit: 2 sec / Memory Limit: 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
E - 1111gal password

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

整数 N が与えられるので、以下の条件を全て満たす整数 X の個数を 998244353 で割った余りを求めてください。

  • N 桁の正整数である。
  • X の各桁を上の位から順に X_1,X_2,\dots,X_N とする。このとき以下の条件を全て満たす。
    • 全ての整数 1 \le i \le N に対して、 1 \le X_i \le 9
    • 全ての整数 1 \le i \le N-1 に対して、 |X_i-X_{i+1}| \le 1

制約

  • N は整数
  • 2 \le N \le 10^6

入力

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

N

出力

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


入力例 1

4

出力例 1

203

4 桁の整数として、例えば 1111,1234,7878,6545 が問題文中の条件を満たします。


入力例 2

2

出力例 2

25

入力例 3

1000000

出力例 3

248860093

998244353 で割った余りを求めることに注意してください。

Score : 300 points

Problem Statement

Given an integer N, find the number of integers X that satisfy all of the following conditions, modulo 998244353.

  • X is an N-digit positive integer.
  • Let X_1,X_2,\dots,X_N be the digits of X from top to bottom. They satisfy all of the following:
    • 1 \le X_i \le 9 for all integers 1 \le i \le N;
    • |X_i-X_{i+1}| \le 1 for all integers 1 \le i \le N-1.

Constraints

  • N is an integer.
  • 2 \le N \le 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

4

Sample Output 1

203

Some of the 4-digit integers satisfying the conditions are 1111,1234,7878,6545.


Sample Input 2

2

Sample Output 2

25

Sample Input 3

1000000

Sample Output 3

248860093

Be sure to find the count modulo 998244353.

F - Filling 3x3 array

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

6 個の整数 h_1, h_2, h_3, w_1, w_2, w_3 が与えられます。
縦横 3 \times 3 のマス目に、以下の条件をすべて満たすように各マスに正の整数を 1 つずつ書きこむことを考えます。

  • i=1,2,3 について、上から i 行目に書きこんだ数の和が h_i になる。
  • j=1,2,3 について、左から j 列目に書きこんだ数の和が w_j になる。

例えば (h_1, h_2, h_3) = (5, 13, 10), (w_1, w_2, w_3) = (6, 13, 9) のとき、以下の 3 通りの書きこみ方はすべて条件を満たしています。(条件を満たす書きこみ方は他にもあります)

image

さて、条件を満たす書きこみ方は全部で何通り存在しますか?

制約

  • 3 \leq h_1, h_2, h_3, w_1, w_2, w_3 \leq 30
  • 入力される値はすべて整数

入力

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

h_1 h_2 h_3 w_1 w_2 w_3

出力

条件を満たす書きこみ方が何通りあるかを出力せよ。


入力例 1

3 4 6 3 3 7

出力例 1

1

条件を満たす数の書きこみ方は次の 1 通りのみです。よって 1 を出力します。

image2


入力例 2

3 4 5 6 7 8

出力例 2

0

条件を満たす書きこみ方が存在しないこともあります。


入力例 3

5 13 10 6 13 9

出力例 3

120

入力例 4

20 25 30 22 29 24

出力例 4

30613

Score : 300 points

Problem Statement

You are given six integers: h_1, h_2, h_3, w_1, w_2, and w_3.
Consider writing a positive integer on each square of a 3 \times 3 grid so that all of the following conditions are satisfied:

  • For i=1,2,3, the sum of numbers written in the i-th row from the top is h_i.
  • For j=1,2,3, the sum of numbers written in the j-th column from the left is w_i.

For example, if (h_1, h_2, h_3) = (5, 13, 10) and (w_1, w_2, w_3) = (6, 13, 9), then all of the following three ways satisfy the conditions. (There are other ways to satisfy the conditions.)

image

How many ways are there to write numbers to satisfy the conditions?

Constraints

  • 3 \leq h_1, h_2, h_3, w_1, w_2, w_3 \leq 30
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

h_1 h_2 h_3 w_1 w_2 w_3

Output

Print the number of ways to write numbers to satisfy the conditions.


Sample Input 1

3 4 6 3 3 7

Sample Output 1

1

The following is the only way to satisfy the conditions. Thus, 1 should be printed.

image2


Sample Input 2

3 4 5 6 7 8

Sample Output 2

0

There may not be a way to satisfy the conditions.


Sample Input 3

5 13 10 6 13 9

Sample Output 3

120

Sample Input 4

20 25 30 22 29 24

Sample Output 4

30613
G - ±1 Operation 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の数列 A=(A_1,A_2,\dots,A_N) が与えられます。この A に以下を施すことを「操作」と呼びます。

  • まず、 1 \le i \le N を満たす整数 i を選択する。
  • 次に、以下の 2 つのうちどちらかを選択し、実行する。
    • A_i1 を加算する。
    • A_i から 1 を減算する。

Q 個の質問に答えてください。
i 個目の質問は以下です。

  • 「操作」を 0 回以上何度でも使って A の要素を全て X_i にする時、必要な「操作」の最小回数を求めてください。

制約

  • 入力は全て整数
  • 1 \le N,Q \le 2 \times 10^5
  • 0 \le A_i \le 10^9
  • 0 \le X_i \le 10^9

入力

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

N Q
A_1 A_2 \dots A_N
X_1
X_2
\vdots
X_Q

出力

Q 行にわたって出力せよ。
出力のうち i 行目には、 i 個目の質問に対する答えを整数として出力せよ。


入力例 1

5 3
6 11 2 5 5
5
20
0

出力例 1

10
71
29

A=(6,11,2,5,5) であり、この入力には 3 つの質問が含まれます。

1 つ目の質問について、 A に以下のように 10 回の「操作」を施すことで、 A の要素を全て 5 にすることができます。

  • A_1 から 1 減算する。
  • A_2 から 1 減算することを 6 度繰り返す。
  • A_31 加算することを 3 度繰り返す。

9 回以下の「操作」で A の要素を全て 5 にすることはできません。

2 つ目の質問について、 A71 回の「操作」を施すことで、 A の要素を全て 20 にすることができます。

3 つ目の質問について、 A29 回の「操作」を施すことで、 A の要素を全て 0 にすることができます。


入力例 2

10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0

出力例 2

3316905982
2811735560
5542639502
4275864946
4457360498

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

Score : 400 points

Problem Statement

You are given a sequence of length N: A=(A_1,A_2,\dots,A_N). The following action on this sequence is called an operation.

  • First, choose an integer i such that 1 \le i \le N.
  • Next, choose and do one of the following.
    • Add 1 to A_i.
    • Subtract 1 from A_i.

Answer Q questions.
The i-th question is the following.

  • Consider performing zero or more operations to change every element of A to X_i. Find the minimum number of operations required to do so.

Constraints

  • All values in input are integers.
  • 1 \le N,Q \le 2 \times 10^5
  • 0 \le A_i \le 10^9
  • 0 \le X_i \le 10^9

Input

Input is given from Standard Input in the following format:

N Q
A_1 A_2 \dots A_N
X_1
X_2
\vdots
X_Q

Output

Print Q lines.
The i-th line should contain the answer to the i-th question as an integer.


Sample Input 1

5 3
6 11 2 5 5
5
20
0

Sample Output 1

10
71
29

We have A=(6,11,2,5,5) and three questions in this input.

For the 1-st question, you can change every element of A to 5 in 10 operations as follows.

  • Subtract 1 from A_1.
  • Subtract 1 from A_2 six times.
  • Add 1 to A_3 three times.

It is impossible to change every element of A to 5 in 9 or fewer operations.

For the 2-nd question, you can change every element of A to 20 in 71 operations.

For the 3-rd question, you can change every element of A to 0 in 29 operations.


Sample Input 2

10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0

Sample Output 2

3316905982
2811735560
5542639502
4275864946
4457360498

The output may not fit into 32-bit integers.

H - Integers on Grid

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

H 行、横 W 列のマス目があります。上から i 行目、左から j 列目のマスをマス (i, j) と呼びます。

それぞれのマスには整数が書かれています。 i = 1, 2, \ldots, N について、マス (r_i, c_i) には正整数 a_i が書かれており、それら以外のマスには 0 が書かれています。

はじめ、マス (R, C) にコマが置かれています。 高橋君は、コマを「いま置かれているマスから別のマスに移動させる」ことを好きな回数だけ行うことができます。 ただし、コマを移動する際には下記の 2 つの条件をともに満たさなければなりません。

  • 移動先のマスに書かれている整数は、移動前のマスに書かれている整数より真に大きい。
  • 移動先のマスは移動前のマスと同じ行にある、または、移動先のマスは移動前のマスと同じ列にある。

i = 1, 2, \ldots, N のそれぞれについて、(R, C) = (r_i, c_i) の場合に高橋君がコマの移動を行うことができる回数の最大値を出力してください。

制約

  • 2 \leq H, W \leq 2 \times 10^5
  • 1 \leq N \leq \min(2 \times 10^5, HW)
  • 1 \leq r_i \leq H
  • 1 \leq c_i \leq W
  • 1 \leq a_i \leq 10^9
  • i \neq j \Rightarrow (r_i, c_i) \neq (r_j, c_j)
  • 入力はすべて整数

入力

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

H W N
r_1 c_1 a_1
r_2 c_2 a_2
\vdots
r_N c_N a_N

出力

N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には (R, C) = (r_i, c_i) の場合に高橋君がコマの移動を行うことができる回数の最大値を出力せよ。


入力例 1

3 3 7
1 1 4
1 2 7
2 1 3
2 3 5
3 1 2
3 2 5
3 3 5

出力例 1

1
0
2
0
3
1
0

マス目に書かれた整数は下記の通りです。

4 7 0
3 0 5
2 5 5
  • (R, C) = (r_1, c_1) = (1, 1) の場合、(1, 1) \rightarrow (1, 2) と移動すると、コマの移動を 1 回行うことができます。
  • (R, C) = (r_2, c_2) = (1, 2) の場合、一度もコマの移動を行うことができません。
  • (R, C) = (r_3, c_3) = (2, 1) の場合、(2, 1) \rightarrow (1, 1) \rightarrow (1, 2) と移動すると、コマの移動を 2 回行うことができます。
  • (R, C) = (r_4, c_4) = (2, 3) の場合、一度もコマの移動を行うことができません。
  • (R, C) = (r_5, c_5) = (3, 1) の場合、(3, 1) \rightarrow (2, 1) \rightarrow (1, 1) \rightarrow (1, 2) と移動すると、コマの移動を 3 回行うことができます。
  • (R, C) = (r_6, c_6) = (3, 2) の場合、(3, 2) \rightarrow (1, 2) と移動すると、コマの移動を 1 回行うことができます。
  • (R, C) = (r_7, c_7) = (3, 3) の場合、一度もコマの移動を行うことができません。

入力例 2

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

出力例 2

2
4
1
5
3
6
6
2
7
0
0
4
1
5
3
0
5
2
4
0

Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left.

Each square contains an integer. For each i = 1, 2, \ldots, N, the square (r_i, c_i) contains a positive integer a_i. The other square contains a 0.

Initially, there is a piece on the square (R, C). Takahashi can move the piece to a square other than the square it occupies now, any number of times. However, when moving the piece, both of the following conditions must be satisfied.

  • The integer written on the square to which the piece is moved is strictly greater than the integer written on the square from which the piece is moved.
  • The squares to and from which the piece is moved are in the same row or the same column.

For each i = 1, 2, \ldots, N, print the maximum number of times Takahashi can move the piece when (R, C) = (r_i, c_i).

Constraints

  • 2 \leq H, W \leq 2 \times 10^5
  • 1 \leq N \leq \min(2 \times 10^5, HW)
  • 1 \leq r_i \leq H
  • 1 \leq c_i \leq W
  • 1 \leq a_i \leq 10^9
  • i \neq j \Rightarrow (r_i, c_i) \neq (r_j, c_j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W N
r_1 c_1 a_1
r_2 c_2 a_2
\vdots
r_N c_N a_N

Output

Print N lines. For each i = 1, 2, \ldots, N, the i-th line should contain the maximum number of times Takahashi can move the piece when (R, C) = (r_i, c_i).


Sample Input 1

3 3 7
1 1 4
1 2 7
2 1 3
2 3 5
3 1 2
3 2 5
3 3 5

Sample Output 1

1
0
2
0
3
1
0

The grid contains the following integers.

4 7 0
3 0 5
2 5 5
  • When (R, C) = (r_1, c_1) = (1, 1), you can move the piece once by moving it as (1, 1) \rightarrow (1, 2).
  • When (R, C) = (r_2, c_2) = (1, 2), you cannot move the piece at all.
  • When (R, C) = (r_3, c_3) = (2, 1), you can move the piece twice by moving it as (2, 1) \rightarrow (1, 1) \rightarrow (1, 2).
  • When (R, C) = (r_4, c_4) = (2, 3), you cannot move the piece at all.
  • When (R, C) = (r_5, c_5) = (3, 1), you can move the piece three times by moving it as (3, 1) \rightarrow (2, 1) \rightarrow (1, 1) \rightarrow (1, 2).
  • When (R, C) = (r_6, c_6) = (3, 2), you can move the piece once by moving it as (3, 2) \rightarrow (1, 2).
  • When (R, C) = (r_7, c_7) = (3, 3), you cannot move the piece at all.

Sample Input 2

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

Sample Output 2

2
4
1
5
3
6
6
2
7
0
0
4
1
5
3
0
5
2
4
0
I - Gather Coins

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

H 行、横 W 列のグリッドがあります。 このグリッドの上から i 行目、左から j 列目にあるマスのことを (i,j) と表記します。

このグリッド上には N 枚のコインが落ちており、i 個目のコインはマス (R_i,C_i) を通ることで拾うことができます。

あなたの目標は、マス (1,1) から始めて下か右に 1 マス移動することを繰り返し、できるだけ多くのコインを拾いながらマス (H,W) まで行くことです。

あなたが拾うことのできるコインの枚数の最大値、およびそれを達成するための移動経路を 1 つ求めてください。

制約

  • 2\leq H,W \leq 2\times 10^5
  • 1\leq N \leq \min(HW-2, 2\times 10^5)
  • 1\leq R_i \leq H
  • 1\leq C_i \leq W
  • (R_i,C_i)\neq (1,1)
  • (R_i,C_i)\neq (H,W)
  • (R_i,C_i) は互いに相異なる
  • 入力は全て整数

入力

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

H W N
R_1 C_1
R_2 C_2
\vdots
R_N C_N

出力

2 行出力せよ。 1 行目には、あなたが拾うことのできるコインの枚数の最大値を出力せよ。 2 行目には、それを達成するための移動経路の 1 つを長さ H+W-2 の文字列として出力せよ。 ここで、出力する文字列の i 文字目は、i 回目の移動において下に移動するならば D、右に移動するならば R である。

拾うコインの枚数が最大となるような移動経路が複数存在する場合は、そのどれを出力しても良い。


入力例 1

3 4 4
3 3
2 1
2 3
1 4

出力例 1

3
DRRDR

上図のように (1,1)\rightarrow (2,1)\rightarrow (2,2)\rightarrow (2,3)\rightarrow (3,3)\rightarrow (3,4) と移動することで、(2,1),(2,3),(3,3) にある 3 枚のコインを拾うことができます。


入力例 2

2 2 2
2 1
1 2

出力例 2

1
DR

RD という移動経路も正解となります。


入力例 3

10 15 8
2 7
2 9
7 9
10 3
7 11
8 12
9 6
8 1

出力例 3

5
DRRRRRRRRDDDDDRRDRDDRRR

Score : 500 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.

There are N coins on this grid, and the i-th coin can be picked up by passing through the cell (R_i,C_i).

Your goal is to start from cell (1,1), repeatedly move either down or right by one cell, and reach cell (H,W) while picking up as many coins as possible.

Find the maximum number of coins you can pick up and one of the paths that achieves this maximum.

Constraints

  • 2\leq H,W \leq 2\times 10^5
  • 1\leq N \leq \min(HW-2, 2\times 10^5)
  • 1\leq R_i \leq H
  • 1\leq C_i \leq W
  • (R_i,C_i)\neq (1,1)
  • (R_i,C_i)\neq (H,W)
  • (R_i,C_i) are pairwise distinct.
  • All input values are integers.

Input

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

H W N
R_1 C_1
R_2 C_2
\vdots
R_N C_N

Output

Print two lines. The first line should contain the maximum number of coins you can pick up. The second line should contain one of the paths that achieves this maximum as a string of length H+W-2. The i-th character of this string should be D if the i-th move is downward, and R if it is rightward.

If there are multiple paths that maximize the number of coins picked up, you may print any of them.


Sample Input 1

3 4 4
3 3
2 1
2 3
1 4

Sample Output 1

3
DRRDR

As shown in the figure above, by moving (1,1)\rightarrow (2,1)\rightarrow (2,2)\rightarrow (2,3)\rightarrow (3,3)\rightarrow (3,4), you can pick up three coins at (2,1),(2,3),(3,3).


Sample Input 2

2 2 2
2 1
1 2

Sample Output 2

1
DR

The path RD is also acceptable.


Sample Input 3

10 15 8
2 7
2 9
7 9
10 3
7 11
8 12
9 6
8 1

Sample Output 3

5
DRRRRRRRRDDDDDRRDRDDRRR