A - AtCoder Quiz 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

AtCoder 王国では、競技プログラミングの実力を測る検定試験が実施されています。

試験は 100 点満点であり、点数が高ければ高いほど、高いランクが認定されます。
ランクは以下のように定められています。

  • 0 点以上 40 点未満のとき、初級
  • 40 点以上 70 点未満のとき、中級
  • 70 点以上 90 点未満のとき、上級
  • 90 点以上のとき、エキスパート

高橋君は、この検定試験を受験し、X 点を取りました。

高橋君が認定されたランクより一つ高いランクとなるためには最低であと何点必要か求めてください。ただし、高橋君がエキスパートと認定された場合、それより高いランクは存在しないため expert と出力してください。

制約

  • 0 \leq X \leq 100
  • X は整数

入力

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

X

出力

答えを出力せよ。


入力例 1

56

出力例 1

14

高橋君は 56 点を取り、中級と認定されました。一つ高いランクである上級となるためには、最低であと 14 点必要です。


入力例 2

32

出力例 2

8

入力例 3

0

出力例 3

40

入力例 4

100

出力例 4

expert

高橋君は満点を取り、エキスパートと認定されました。これより高いランクは存在しないため、expert と出力します。

Score : 100 points

Problem Statement

In the Kingdom of AtCoder, there is a standardized test of competitive programming proficiency.

An examinee will get a score out of 100 and obtain a rank according to the score, as follows:

  • Novice, for a score not less than 0 but less than 40;
  • Intermediate, for a score not less than 40 but less than 70;
  • Advanced, for a score not less than 70 but less than 90;
  • Expert, for a score not less than 90.

Takahashi took this test and got X points.

Find the minimum number of extra points needed to go up one rank higher. If, however, his rank was Expert, print expert, as there is no higher rank than that.

Constraints

  • 0 \leq X \leq 100
  • X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the answer.


Sample Input 1

56

Sample Output 1

14

He got 56 points and was certified as Intermediate. In order to reach the next rank of Advanced, he needs at least 14 more points.


Sample Input 2

32

Sample Output 2

8

Sample Input 3

0

Sample Output 3

40

Sample Input 4

100

Sample Output 4

expert

He got full points and was certified as Expert. There is no rank higher than that, so print expert.

B - 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.

C - Vertical Reading

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

英小文字からなる文字列 S と T が与えられます。

以下の条件を満たす 1 \leq c \leq w < |S| となる整数の組 c と w が存在するか判定してください。ただし、 |S| は文字列 S の長さを表します。ここで、w は |S| 未満である必要があることに注意してください。

  • S を先頭から順に w 文字毎に区切ったとき、長さが c 以上の文字列の c 文字目を順番に連結した文字列が T と一致する

制約

  • S と T は英小文字からなる文字列
  • 1 \leq |T| \leq |S| \leq 100

入力

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

S T

出力

条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w が存在する場合は Yes を、存在しない場合は No を出力せよ。


入力例 1

atcoder toe

出力例 1

Yes

S を 2 文字毎に区切ると以下のようになります。

at
co
de
r

区切った後、 2 文字以上の文字列の 2 文字目を取り出し連結させたときの文字列は、 toe となり T と一致します。よって、 Yes を出力します。


入力例 2

beginner r

出力例 2

No

w=|S| であることはないため、条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w は存在しません。よって、 No を出力します。


入力例 3

verticalreading agh

出力例 3

No

Score : 200 points

Problem Statement

You are given two strings S and T consisting of lowercase English letters.

Determine if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the following condition is satisfied. Here, |S| denotes the length of the string S. Note that w must be less than |S|.

  • If S is split at every w characters from the beginning, the concatenation of the c-th characters of the substrings of length at least c in order equals T.

Constraints

  • S and T are strings consisting of lowercase English letters.
  • 1 \leq |T| \leq |S| \leq 100

Input

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

S T

Output

Print Yes if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the condition is satisfied, and No otherwise.


Sample Input 1

atcoder toe

Sample Output 1

Yes

If S is split at every two characters, it looks like this:

at
co
de
r

Then, the concatenation of the 2nd characters of the substrings of length at least 2 is toe, which equals T. Thus, print Yes.


Sample Input 2

beginner r

Sample Output 2

No

w=|S| is not allowed, and no pair of integers 1 \leq c \leq w < |S| satisfies the condition. Thus, print No.


Sample Input 3

verticalreading agh

Sample Output 3

No
D - String Shifting

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

空でない文字列に対し、先頭の文字を末尾に移動する操作を左シフト、末尾の文字を先頭に移動する操作を右シフトと呼びます。

例えば、abcde に対して左シフトを 1 回行うと bcdea となり、右シフトを 2 回行うと deabc となります。

英小文字からなる空でない文字列 S が与えられます。S に対し左シフトと右シフトをそれぞれ好きな回数(0 回でもよい)行って得られる文字列のうち、辞書順で最小のものと最大のものを求めてください。

辞書順とは?

辞書順とは簡単に説明すると「単語が辞書に載っている順番」を意味します。より厳密な説明として、英小文字からなる相異なる文字列 S, T の大小を判定するアルゴリズムを以下に説明します。

以下では「 S の i 文字目の文字」を S_i のように表します。また、 S が T より辞書順で小さい場合は S \lt T 、大きい場合は S \gt T と表します。

  1. S, T のうち長さが大きくない方の文字列の長さを L とします。i=1,2,\dots,L に対して S_i と T_i が一致するか調べます。
  2. S_i \neq T_i である i が存在する場合、そのような i のうち最小のものを j とします。そして、S_j と T_j を比較して、S_j が T_j よりアルファベット順で小さい場合は S \lt T 、そうでない場合は S \gt T と決定して、アルゴリズムを終了します。
  3. S_i \neq T_i である i が存在しない場合、S と T の長さを比較して、S が T より短い場合は S \lt T 、長い場合は S \gt T と決定して、アルゴリズムを終了します。

制約

  • S は英小文字からなる。
  • S の長さは 1 以上 1000 以下である。

入力

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

S

出力

2 行にわたって出力せよ。S に対し左シフトと右シフトをそれぞれ好きな回数(0 回でもよい)行って得られる文字列のうち、辞書順で最小のものと最大のものをそれぞれ S_{\min}, S_{\max} とおいたとき、1 行目には S_{\min} を、2 行目には S_{\max} を出力せよ。


入力例 1

aaba

出力例 1

aaab
baaa

操作によって、aaab , aaba , abaa , baaa の 4 通りの文字列を得ることができます。 これらのうち辞書順で最小、最大のものはそれぞれ aaab , baaa です。


入力例 2

z

出力例 2

z
z

どのように操作を行っても、得られる文字列は z のみです。


入力例 3

abracadabra

出力例 3

aabracadabr
racadabraab

Score : 200 points

Problem Statement

On a non-empty string, a left shift moves the first character to the end of the string, and a right shift moves the last character to the beginning of the string.

For example, a left shift on abcde results in bcdea, and two right shifts on abcde result in deabc.

You are given a non-empty S consisting of lowercase English letters. Among the strings that can be obtained by performing zero or more left shifts and zero or more right shifts on S, find the lexicographically smallest string and the lexicographically largest string.

What is the lexicographical order?

Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings S and T.

Below, let S_i denote the i-th character of S. Also, if S is lexicographically smaller than T, we will denote that fact as S \lt T; if S is lexicographically larger than T, we will denote that fact as S \gt T.

  1. Let L be the smaller of the lengths of S and T. For each i=1,2,\dots,L, we check whether S_i and T_i are the same.
  2. If there is an i such that S_i \neq T_i, let j be the smallest such i. Then, we compare S_j and T_j. If S_j comes earlier than T_j in alphabetical order, we determine that S \lt T and quit; if S_j comes later than T_j, we determine that S \gt T and quit.
  3. If there is no i such that S_i \neq T_i, we compare the lengths of S and T. If S is shorter than T, we determine that S \lt T and quit; if S is longer than T, we determine that S \gt T and quit.

Constraints

  • S consists of lowercase English letters.
  • The length of S is between 1 and 1000 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

Print two lines. The first line should contain S_{\min}, and the second line should contain S_{\max}. Here, S_{\min} and S_{\max} are respectively the lexicographically smallest and largest strings obtained by performing zero or more left shifts and zero or more right shifts on S.


Sample Input 1

aaba

Sample Output 1

aaab
baaa

By performing shifts, we can obtain four strings: aaab, aaba, abaa, baaa. The lexicographically smallest and largest among them are aaab and baaa, respectively.


Sample Input 2

z

Sample Output 2

z
z

Any sequence of operations results in z.


Sample Input 3

abracadabra

Sample Output 3

aabracadabr
racadabraab
E - Extra Character

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

文字列 S,T が与えられます。S は英小文字からなり、T は S に英小文字を 1 つ挿入して作られたことがわかっています。

挿入された文字は T の先頭から何番目の文字であるか求めてください。
複数の候補が考えられる場合はいずれか 1 つを求めてください。

制約

  • 1 \leq |S| \leq 5\times 10^5
  • S は英小文字からなる
  • T は S に英小文字を 1 つ挿入して作られた文字列である

入力

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

S
T

出力

答えを出力せよ。なお、答えが複数考えられる場合はどれを出力しても正解となる。


入力例 1

atcoder
atcorder

出力例 1

5

T の先頭から 5 番目の文字 r が挿入された文字です。


入力例 2

million
milllion

出力例 2

5

T の先頭から 3,4,5 番目の文字のいずれかが挿入された文字です。
よって、3,4,5 のいずれかを出力すると正解となります。


入力例 3

vvwvw
vvvwvw

出力例 3

3

Score : 300 points

Problem Statement

You are given strings S and T. S consists of lowercase English letters, and T is obtained by inserting a lowercase English letter into S.

Find the position of the inserted character in T.
If there are multiple candidates, find any of them.

Constraints

  • 1 \leq |S| \leq 5\times 10^5
  • S consists of lowercase English letters.
  • T is obtained by inserting a lowercase English letter into S.

Input

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

S
T

Output

Print an integer i, representing that the inserted character is the i-th character from the beginning of T. If there are multiple possible answers, printing any of them is accepted.


Sample Input 1

atcoder
atcorder

Sample Output 1

5

The 5-th character from the beginning of T, r, is inserted.


Sample Input 2

million
milllion

Sample Output 2

5

One of the 3-rd, 4-th, and 5-th characters from the beginning of T is inserted. Thus, printing any one of 3, 4, and 5 is accepted.


Sample Input 3

vvwvw
vvvwvw

Sample Output 3

3
F - Blue Spring

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は N 日間の鉄道旅行を計画しています。
高橋君はそれぞれの日について、運賃の通常料金を払うか、1 日周遊パスを 1 枚使用するか選ぶことができます。

ここで、1\leq i\leq N について、i 日目の旅行にかかる運賃の通常料金は F_i 円です。
一方、1 日周遊パスは D 枚セットで P 円で発売されており、何セットでも購入することが可能ですが、D 枚単位でしか購入することができません。
また、購入したパスは 1 枚ずつ好きな日に使うことができ、旅行が終了した時点で余っていても構いません。

N 日間の旅行でかかる金額、すなわち 1 日周遊パスの購入にかかった代金と、1 日周遊パスを利用しなかった日における運賃の通常料金の合計金額の和としてあり得る最小値を求めてください。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq D\leq 2\times 10^5
  • 1\leq P\leq 10^9
  • 1\leq F_i\leq 10^9
  • 入力はすべて整数

入力

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

N D P
F_1 F_2 \ldots F_N

出力

N 日間の旅行でかかる金額としてあり得る最小値を出力せよ。


入力例 1

5 2 10
7 1 6 3 6

出力例 1

20

1 日周遊パスを 1 セットだけ購入し、1 日目と 3 日目に使用すると、合計金額は (10\times 1)+(0+1+0+3+6)=20 となり、このときかかる金額が最小となります。
よって、20 を出力します。


入力例 2

3 1 10
1 2 3

出力例 2

6

3 日間すべてにおいて運賃の通常料金を支払ったときに最小となります。


入力例 3

8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

出力例 3

3000000000

1 日周遊パスを 3 セット購入し、8 日間すべてにおいて 1 日周遊パスを利用したときに最小となります。
答えが 32 bit 整数型に収まらないことがあることに注意してください。

Score : 300 points

Problem Statement

Takahashi is planning an N-day train trip.
For each day, he can pay the regular fare or use a one-day pass.

Here, for 1\leq i\leq N, the regular fare for the i-th day of the trip is F_i yen.
On the other hand, a batch of D one-day passes is sold for P yen. You can buy as many passes as you want, but only in units of D.
Each purchased pass can be used on any day, and it is fine to have some leftovers at the end of the trip.

Find the minimum possible total cost for the N-day trip, that is, the cost of purchasing one-day passes plus the total regular fare for the days not covered by one-day passes.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq D\leq 2\times 10^5
  • 1\leq P\leq 10^9
  • 1\leq F_i\leq 10^9
  • All input values are integers.

Input

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

N D P
F_1 F_2 \ldots F_N

Output

Print the minimum possible total cost for the N-day trip.


Sample Input 1

5 2 10
7 1 6 3 6

Sample Output 1

20

If he buys just one batch of one-day passes and uses them for the first and third days, the total cost will be (10\times 1)+(0+1+0+3+6)=20, which is the minimum cost needed.
Thus, print 20.


Sample Input 2

3 1 10
1 2 3

Sample Output 2

6

The minimum cost is achieved by paying the regular fare for all three days.


Sample Input 3

8 3 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

3000000000

The minimum cost is achieved by buying three batches of one-day passes and using them for all eight days.
Note that the answer may not fit into a 32-bit integer type.

G - Change Usernames

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

あなたの運営する Web サービスには N 人のユーザがいます。

i 番目のユーザの現在のユーザ名は S_i ですが、T_i への変更を希望しています。
ここで、S_1,\ldots,S_N は相異なり、T_1,\ldots,T_N も相異なります。

ユーザ名を変更する順序を適切に定めることで、以下の条件を全て満たすように、全てのユーザのユーザ名を希望通り変更することができるか判定してください。

  • ユーザ名の変更は 1 人ずつ行う
  • どのユーザもユーザ名の変更は一度だけ行う
  • ユーザ名の変更を試みる時点で他のユーザが使っているユーザ名に変更することはできない

制約

  • 1 \leq N \leq 10^5
  • S_i,T_i は英小文字からなる 1 文字以上 8 文字以下の文字列
  • S_i \neq T_i
  • S_i は相異なる
  • T_i は相異なる

入力

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

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

出力

条件を全て満たすように全てのユーザのユーザ名を希望通り変更することができるとき Yes、できないとき No と出力せよ。


入力例 1

2
b m
m d

出力例 1

Yes

1 番目のユーザの現在のユーザ名は b であり、m への変更を希望しています。
2 番目のユーザの現在のユーザ名は m であり、d への変更を希望しています。

まず、2 番目のユーザのユーザ名を m から d に変更し、 その後 1 番目のユーザのユーザ名を b から m に変更することで、条件を満たしながら変更することができます。

最初の時点では 2 番目のユーザのユーザ名が m なので、1 番目のユーザのユーザ名を同じ m に変更することはできません。


入力例 2

3
a b
b c
c a

出力例 2

No

1 番目のユーザの現在のユーザ名は a であり、b への変更を希望しています。
2 番目のユーザの現在のユーザ名は b であり、c への変更を希望しています。
3 番目のユーザの現在のユーザ名は c であり、a への変更を希望しています。

条件を満たしながらユーザ名の変更を行うことはできません。


入力例 3

5
aaa bbb
yyy zzz
ccc ddd
xxx yyy
bbb ccc

出力例 3

Yes

Score : 400 points

Problem Statement

You run a web service with N users.

The i-th user with a current handle S_i wants to change it to T_i.
Here, S_1,\ldots, and S_N are pairwise distinct, and so are T_1,\ldots, and T_N.

Determine if there is an appropriate order to change their handles to fulfill all of their requests subject to the following conditions:

  • you change only one user's handle at a time;
  • you change each user's handle only once;
  • when changing the handle, the new handle should not be used by other users at that point.

Constraints

  • 1 \leq N \leq 10^5
  • S_i and T_i are strings of length between 1 and 8 (inclusive) consisting of lowercase English letters.
  • S_i \neq T_i
  • S_i are pairwise distinct.
  • T_i are pairwise distinct.

Input

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

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

Output

Print Yes if they can change their handles to fulfill all of their requests subject to the conditions; print No otherwise.


Sample Input 1

2
b m
m d

Sample Output 1

Yes

The 1-st user with a current handle b wants to change it to m.
The 2-nd user with a current handle m wants to change it to d.

First, you change the 2-nd user's handle from m to d; then you change the 1-st user's handle from b to m. This way, you can achieve the objective.

Note that you cannot change the 1-st user's handle to m at first, because it is used by the 2-nd user at that point.


Sample Input 2

3
a b
b c
c a

Sample Output 2

No

The 1-st user with a current handle a wants to change it to b.
The 2-nd user with a current handle b wants to change it to c.
The 3-rd user with a current handle c wants to change it to a.

We cannot change their handles subject to the conditions.


Sample Input 3

5
aaa bbb
yyy zzz
ccc ddd
xxx yyy
bbb ccc

Sample Output 3

Yes
H - Prefix Equality

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

長さ N の整数列 A = (a_1,\ldots,a_N) と B = (b_1,\ldots,b_N) が与えられます。

i=1,...,Q に対し、次の形式のクエリに答えてください。

  • A の先頭 x_i 項 (a_1,\ldots,a_{x_i}) に含まれる値の集合と B の先頭 y_i 項 (b_1,\ldots,b_{y_i}) に含まれる値の集合が等しいならば Yes と、そうでなければ No と出力せよ。

制約

  • 1 \leq N,Q \leq 2 \times 10^5
  • 1 \leq a_i,b_i \leq 10^9
  • 1 \leq x_i,y_i \leq N
  • 入力は全て整数

入力

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

N
a_1 \ldots a_N
b_1 \ldots b_N
Q
x_1 y_1
\vdots
x_Q y_Q

出力

Q 行出力せよ。 i 行目には、i 番目のクエリに対する出力をせよ。


入力例 1

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

出力例 1

Yes
Yes
Yes
No
No
Yes
No

集合は各値が含まれるかどうかのみに注目した概念であることに気を付けてください。
3 番目のクエリにおいて、A の先頭 2 項には 1 と 2 が 1 個ずつ、B の先頭 3 項には 1 が 1 個と 2 が 2 個含まれます。しかし、それぞれに含まれる値の集合はどちらも \{ 1,2 \} となり、一致します。
また、6 番目のクエリにおいては各値が現れる順番が異なりますが、やはり集合としては一致します。

Score : 500 points

Problem Statement

You are given integer sequences A = (a_1,\ldots,a_N) and B = (b_1,\ldots,b_N), each of length N.

For i=1,...,Q, answer the query in the following format.

  • If the set of values contained in the first x_i terms of A, (a_1,\ldots,a_{x_i}), and the set of values contained in the first y_i terms of B, (b_1,\ldots,b_{y_i}), are equal, then print Yes; otherwise, print No.

Constraints

  • 1 \leq N,Q \leq 2 \times 10^5
  • 1 \leq a_i,b_i \leq 10^9
  • 1 \leq x_i,y_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 \ldots a_N
b_1 \ldots b_N
Q
x_1 y_1
\vdots
x_Q y_Q

Output

Print Q lines. The i-th line should contain the response to the i-th query.


Sample Input 1

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

Sample Output 1

Yes
Yes
Yes
No
No
Yes
No

Note that sets are a concept where it matters only whether each value is contained or not.
For the 3-rd query, the first 2 terms of A contain one 1 and one 2, while the first 3 terms of B contain one 1 and two 2's. However, the sets of values contained in the segments are both \{ 1,2 \}, which are equal.
Also, for the 6-th query, the values appear in different orders, but they are still equal as sets.

I - Robot Rotation

Time Limit: 4 sec / Memory Limit: 1024 MiB

配点 : 525 点

問題文

右向きを x 軸正方向、上向きを y 軸正方向とする座標平面の原点にロボットがいます。ロボットは最初、x 軸正方向を向いています。

i=1,\ldots,N の順に以下の操作を行います:

  • ロボットを右回りまたは左回りに 90 度回転させる。その後、ロボットは向いている方向に A_i 進む

回転方向を適切に選ぶことで、N 回の操作後にロボットがいる座標を (X,Y) にすることはできますか?

できるならば、各操作において、右回りと左回りのどちらを選べばよいか求めてください。

制約

  • 1 \leq N \leq 80
  • 1 \leq A_i \leq 10^7
  • -10^9\leq X,Y \leq 10^9
  • 入力は全て整数である

入力

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

N X Y
A_1 \ldots A_N

出力

N 回の操作後にロボットがいる座標を (X,Y) にできないとき、No と出力せよ。
N 回の操作後にロボットがいる座標を (X,Y) にできるとき、1行目に Yes と出力し、2行目に次の条件を満たす長さ N の文字列 S を出力せよ。
条件: S は L または R のみからなり、S の i 番目の文字が L ならば i 回目の操作においてロボットを左回りに、R ならばロボットを右回りに回転させることで、N 回の操作後にロボットがいる座標を (X,Y) にできる。

答えが複数ある場合はどれを出力しても正解となる。


入力例 1

3 -2 4
3 2 1

出力例 1

Yes
LLR

最初ロボットは (0,0) にいて、x 軸正方向を向いています。次の手順により、N 回の操作後にロボットがいる座標を (X,Y) にできます。

  • 1 回目の操作:ロボットを左に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_1=3 進み、ロボットのいる座標は (0,3) となる。
  • 2 回目の操作:ロボットを左に 90 度回転させ、x 軸負方向を向かせる。ロボットは向いている方向に A_2=2 進み、ロボットのいる座標は (-2,3) となる。
  • 3 回目の操作:ロボットを右に 90 度回転させ、y 軸正方向を向かせる。ロボットは向いている方向に A_3=1 進み、ロボットのいる座標は (-2,4) となる。

図


入力例 2

1 0 0
1

出力例 2

No

入力例 3

4 0 0
1 1 1 1

出力例 3

Yes
LRRR

LLLL や RRRR などでも正解となります。


入力例 4

14 2543269 -1705099
3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9

出力例 4

Yes
LLLLLLLLLRLRRR

Score : 525 points

Problem Statement

A robot is at the origin of a coordinate plane where the positive x-axis points to the right and the positive y-axis points upwards. Initially, the robot is facing the positive x-direction.

You will perform the following operation for i=1,\ldots,N in this order.

  • Rotate the robot 90 degrees clockwise or counterclockwise. Then, the robot moves forward A_i units in the direction it is facing.

Can the direction of rotation be chosen so that the robot will be at the coordinates (X,Y) after the N operations?

If it is possible, determine which direction, clockwise or counterclockwise, should be chosen for each operation.

Constraints

  • 1 \leq N \leq 80
  • 1 \leq A_i \leq 10^7
  • -10^9\leq X,Y \leq 10^9
  • All input values are integers.

Input

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

N X Y
A_1 \ldots A_N

Output

If the robot cannot be at the coordinates (X,Y) after the N operations, print No.
If the robot can be at the coordinates (X,Y) after the N operations, the first line should contain Yes, and the second line should contain a string S of length N that satisfies the following condition.
Condition: S consists of L and R, and the following choices can put the robot at the coordinates (X,Y) after the N operations: in the i-th operation, rotate the robot counterclockwise if the i-th character of S is L, and rotate it clockwise if it is R.

If there are multiple solutions, you may print any of them.


Sample Input 1

3 -2 4
3 2 1

Sample Output 1

Yes
LLR

Initially, the robot is at (0,0) and facing the positive x-direction. The following choices can put the robot at the coordinates (X,Y) after the N operations.

  • First operation: Rotate the robot 90 degrees counterclockwise to face the positive y-direction. The robot moves forward A_1=3 units in the direction it is facing, and moves to (0,3).
  • Second operation: Rotate the robot 90 degrees counterclockwise to face the negative x-direction. The robot moves forward A_2=2 units in the direction it is facing, and moves to (-2,3).
  • Third operation: Rotate the robot 90 degrees clockwise to face the positive y-direction. The robot moves forward A_3=1 unit in the direction it is facing, and moves to (-2,4).

Diagram


Sample Input 2

1 0 0
1

Sample Output 2

No

Sample Input 3

4 0 0
1 1 1 1

Sample Output 3

Yes
LRRR

Outputs such as LLLL and RRRR are also accepted.


Sample Input 4

14 2543269 -1705099
3 14 159 2653 58979 323846 2643383 2795028 841971 69399 37510 58 20 9

Sample Output 4

Yes
LLLLLLLLLRLRRR