A - Zero Sum Game

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

1 から N の番号が付けられた N 人の人がおり、この中で一対一の勝敗のつくゲームを何度か行いました。N 人は最初にそれぞれ持ち点として 0 を持っており、各ゲームでは勝者の持ち点が 1 増え、敗者の持ち点が 1 減ります(持ち点が負になることもあります)。最終的に人 i\ (1\leq i\leq N-1) の持ち点が A_i になったとき、人 N の持ち点を求めてください。なお、ゲームの進行によらず最終的な人 N の持ち点は一意に定まることが示せます。

制約

  • 2\leq N\leq 100
  • -100\leq A_i\leq 100
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_{N-1}

出力

答えを出力せよ。


入力例 1

4
1 -2 -1

出力例 1

2

最終的に人 1,2,3 の持ち点が 1,-2,-1 となるような進行として、例えば次のようなものが考えられます。

  • 最初、人 1,2,3,4 の持ち点はそれぞれ 0,0,0,0 である。
  • 12 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-1,0,0 である。
  • 14 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 0,-1,0,1 である。
  • 12 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-2,0,1 である。
  • 23 が対戦して、人 2 が勝利する。4 人の持ち点はそれぞれ 1,-1,-1,1 である。
  • 24 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 1,-2,-1,2 である。

この場合、人 4 の持ち点は 2 になります。ほかにも別の進行が考えられますが、どのような進行であっても人 4 の持ち点は 2 になります。


入力例 2

3
0 0

出力例 2

0

入力例 3

6
10 20 30 40 50

出力例 3

-150

Score: 100 points

Problem Statement

There are N people labeled 1 to N, who have played several one-on-one games without draws. Initially, each person started with 0 points. In each game, the winner's score increased by 1 and the loser's score decreased by 1 (scores can become negative). Determine the final score of person N if the final score of person i\ (1\leq i\leq N-1) is A_i. It can be shown that the final score of person N is uniquely determined regardless of the sequence of games.

Constraints

  • 2 \leq N \leq 100
  • -100 \leq A_i \leq 100
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_{N-1}

Output

Print the answer.


Sample Input 1

4
1 -2 -1

Sample Output 1

2

Here is one possible sequence of games where the final scores of persons 1, 2, 3 are 1, -2, -1, respectively.

  • Initially, persons 1, 2, 3, 4 have 0, 0, 0, 0 points, respectively.
  • Persons 1 and 2 play, and person 1 wins. The players now have 1, -1, 0, 0 point(s).
  • Persons 1 and 4 play, and person 4 wins. The players now have 0, -1, 0, 1 point(s).
  • Persons 1 and 2 play, and person 1 wins. The players now have 1, -2, 0, 1 point(s).
  • Persons 2 and 3 play, and person 2 wins. The players now have 1, -1, -1, 1 point(s).
  • Persons 2 and 4 play, and person 4 wins. The players now have 1, -2, -1, 2 point(s).

In this case, the final score of person 4 is 2. Other possible sequences of games exist, but the score of person 4 will always be 2 regardless of the progression.


Sample Input 2

3
0 0

Sample Output 2

0

Sample Input 3

6
10 20 30 40 50

Sample Output 3

-150
B - Commencement

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

英小文字からなる文字列 S良い文字列であるとは、すべての 1 以上の整数 i について次の性質が成り立つことであるとします。

  • S にちょうど i 回現れる文字はちょうど 0 種類またはちょうど 2 種類ある

文字列 S が与えられるので、 S が良い文字列か判定してください。

制約

  • S は英小文字からなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

S が良い文字列ならば Yes を、そうでないならば No を出力せよ。


入力例 1

commencement

出力例 1

Yes

文字列 commencement にちょうど i 回現れる文字の種類数は以下のとおりです。

  • i=1: o, t2 種類
  • i=2: c, n2 種類
  • i=3: e, m2 種類
  • i\geq 4: 0 種類

よって、commencement は良い文字列の条件を満たします。


入力例 2

banana

出力例 2

No

文字列 banana にちょうど 1 回現れる文字は b1 種類だけであり、良い文字列の条件を満たしません。


入力例 3

ab

出力例 3

Yes

Score: 200 points

Problem Statement

A string S consisting of lowercase English letters is a good string if and only if it satisfies the following property for all integers i not less than 1:

  • There are exactly zero or exactly two different letters that appear exactly i times in S.

Given a string S, determine if it is a good string.

Constraints

  • S is a string of lowercase English letters with a length between 1 and 100, inclusive.

Input

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

S

Output

Print Yes if S is a good string, and No otherwise.


Sample Input 1

commencement

Sample Output 1

Yes

For the string commencement, the number of different letters that appear exactly i times is as follows:

  • i=1: two letters (o and t)
  • i=2: two letters (c and n)
  • i=3: two letters (e and m)
  • i\geq 4: zero letters

Therefore, commencement satisfies the condition of a good string.


Sample Input 2

banana

Sample Output 2

No

For the string banana, there is only one letter that appears exactly one time, which is b, so it does not satisfy the condition of a good string.


Sample Input 3

ab

Sample Output 3

Yes
C - Airport Code

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

英大文字からなる長さ 3 の文字列 T が、英小文字からなる文字列 S空港コード であるとは、 TS から次のいずれかの方法により得られることとします。

  • S の長さ 3 の(連続とは限らない)部分列をとり、それを英大文字に変換したものを T とする
  • S の長さ 2 の(連続とは限らない)部分列をとり、それを英大文字に変換したものの末尾に X を追加したものを T とする

文字列 S, T が与えられるので、 TS の空港コードであるか判定してください。

制約

  • S は英小文字からなる長さ 3 以上 10^5 以下の文字列
  • T は英大文字からなる長さ 3 の文字列

入力

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

S
T

出力

TS の空港コードであるならば Yes を、そうでないならば No を出力せよ。


入力例 1

narita
NRT

出力例 1

Yes

narita の部分列 nrt を英大文字に変換した文字列 NRT は、 narita の空港コードです。


入力例 2

losangeles
LAX

出力例 2

Yes

losangeles の部分列 la を英大文字に変換した文字列 LA の末尾に X を追加したもの LAX は、 losangeles の空港コードです。


入力例 3

snuke
RNG

出力例 3

No

Score: 300 points

Problem Statement

A string T of length 3 consisting of uppercase English letters is an airport code for a string S of lowercase English letters if and only if T can be derived from S by one of the following methods:

  • Take a subsequence of length 3 from S (not necessarily contiguous) and convert it to uppercase letters to form T.
  • Take a subsequence of length 2 from S (not necessarily contiguous), convert it to uppercase letters, and append X to the end to form T.

Given strings S and T, determine if T is an airport code for S.

Constraints

  • S is a string of lowercase English letters with a length between 3 and 10^5, inclusive.
  • T is a string of uppercase English letters with a length of 3.

Input

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

S
T

Output

Print Yes if T is an airport code for S, and No otherwise.


Sample Input 1

narita
NRT

Sample Output 1

Yes

The subsequence nrt of narita, when converted to uppercase, forms the string NRT, which is an airport code for narita.


Sample Input 2

losangeles
LAX

Sample Output 2

Yes

The subsequence la of losangeles, when converted to uppercase and appended with X, forms the string LAX, which is an airport code for losangeles.


Sample Input 3

snuke
RNG

Sample Output 3

No
D - Divide Interval

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 450

問題文

非負整数 l,r\ (l<r) に対して、l 以上 r 未満の整数を順に並べた数列 (l,l+1,\ldots,r-2,r-1)S(l,r) で表します。また、非負整数 i,j を用いて S(2^{i}j,2^{i}(j+1)) と表される数列を良い数列と呼ぶことにします。

非負整数 L,R\ (L\lt R) が与えられます。数列 S(L,R) をできるだけ少ない個数の良い数列に分割するとき、その個数と分割の方法を出力してください。より厳密には、以下を満たす非負整数の組の列 (l_1,r_1),(l_2,r_2),\ldots,(l_M,r_M) が存在するような正整数 M の最小値を求め、そのときの (l_1,r_1),(l_2,r_2),\ldots,(l_M,r_M) を出力してください。

  • L=l_1<r_1=l_2<r_2=\cdots=l_M<r_M=R
  • S(l_1,r_1),S(l_2,r_2),\ldots,S(l_M,r_M) は良い数列

なお、M が最小となるような分割方法は一通りのみ存在することが示せます。

制約

  • 0\leq L\lt R\leq 2^{60}
  • 入力は全て整数

入力

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

L R

出力

以下の形式にしたがって出力せよ。

M
l_1 r_1
\vdots
l_M r_M

(l_1,r_1),\dots,(l_M,r_M)昇順で出力することに注意せよ。


入力例 1

3 19

出力例 1

5
3 4
4 8
8 16
16 18
18 19

S(3,19)=(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) です。これは以下の 5 つの良い数列に分割でき、これが個数が最小となるような分割方法です。

  • S(3,4)=S(2^0\cdot 3,2^0\cdot4)=(3)
  • S(4,8)=S(2^2\cdot 1,2^2\cdot 2)=(4,5,6,7)
  • S(8,16)=S(2^3\cdot 1,2^3\cdot 2)=(8,9,10,11,12,13,14,15)
  • S(16,18)=S(2^1\cdot 8,2^1\cdot 9)=(16,17)
  • S(18,19)=S(2^0\cdot 18,2^0\cdot 19)=(18)

入力例 2

0 1024

出力例 2

1
0 1024

入力例 3

3940649673945088 11549545024454656

出力例 3

8
3940649673945088 3940649673949184
3940649673949184 4503599627370496
4503599627370496 9007199254740992
9007199254740992 11258999068426240
11258999068426240 11540474045136896
11540474045136896 11549270138159104
11549270138159104 11549545016066048
11549545016066048 11549545024454656

Score: 450 points

Problem Statement

For non-negative integers l and r (l < r), let S(l, r) denote the sequence (l, l+1, \ldots, r-2, r-1) formed by arranging integers from l through r-1 in order. Furthermore, a sequence is called a good sequence if and only if it can be represented as S(2^i j, 2^i (j+1)) using non-negative integers i and j.

You are given non-negative integers L and R (L < R). Divide the sequence S(L, R) into the fewest number of good sequences, and print that number of sequences and the division. More formally, find the minimum positive integer M for which there is a sequence of pairs of non-negative integers (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) that satisfies the following, and print such (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M).

  • L = l_1 < r_1 = l_2 < r_2 = \cdots = l_M < r_M = R
  • S(l_1, r_1), S(l_2, r_2), \ldots, S(l_M, r_M) are good sequences.

It can be shown that there is only one division that minimizes M.

Constraints

  • 0 \leq L < R \leq 2^{60}
  • All input values are integers.

Input

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

L R

Output

Print the answer in the following format:

M
l_1 r_1
\vdots
l_M r_M

Note that the pairs (l_1, r_1), \dots, (l_M, r_M) should be printed in ascending order.


Sample Input 1

3 19

Sample Output 1

5
3 4
4 8
8 16
16 18
18 19

S(3,19)=(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) can be divided into the following five good sequences, which is the minimum possible number:

  • S(3,4)=S(2^0\cdot 3,2^0\cdot4)=(3)
  • S(4,8)=S(2^2\cdot 1,2^2\cdot 2)=(4,5,6,7)
  • S(8,16)=S(2^3\cdot 1,2^3\cdot 2)=(8,9,10,11,12,13,14,15)
  • S(16,18)=S(2^1\cdot 8,2^1\cdot 9)=(16,17)
  • S(18,19)=S(2^0\cdot 18,2^0\cdot 19)=(18)

Sample Input 2

0 1024

Sample Output 2

1
0 1024

Sample Input 3

3940649673945088 11549545024454656

Sample Output 3

8
3940649673945088 3940649673949184
3940649673949184 4503599627370496
4503599627370496 9007199254740992
9007199254740992 11258999068426240
11258999068426240 11540474045136896
11540474045136896 11549270138159104
11549270138159104 11549545016066048
11549545016066048 11549545024454656
E - Weighted Tic-Tac-Toe

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 450

問題文

3 \times 3 のマス目があります。上から i 行目、左から j 列目 (1 \leq i,j \leq 3) のマスをマス (i,j) と表します。マス (i,j) には整数 A_{i,j} が書かれています。ここで、 \sum_{i=1}^3 \sum_{j=1}^3 A_{i,j} は奇数であることが保証されます。また、すべてのマスははじめ白で塗られています。

高橋君と青木君が、このマス目を使ってゲームを行います。ゲームでは、高橋君を先手として、二人が交互に以下の操作を行います。

  • 白で塗られているマス (i,j)\,(1\leq i,j \leq 3) を選ぶ(操作が行われる時点で、そのようなマスは必ず存在することが示せる)。操作をしているプレイヤーが得点 A_{i,j} を得る。次に、操作をしているプレイヤーが高橋君ならば、マス (i,j) を赤で、青木君ならば青で塗る。

各操作のあと、次の判定を行います。

  • 赤または青の同じ色で塗られたマスが縦・横・斜めのいずれかの方向に 3 つ連続する箇所があるか判定する。そのような箇所があれば、その時点でゲームを終了し、赤が 3 つ連続しているならば高橋君が、青が 3 つ連続しているならば青木君が勝利する。
  • 白で塗られているマスが存在するか判定する。存在しなければ、その時点でゲームを終了し、その時点までに獲得した累計の得点が高い方のプレイヤーが勝利する。

ゲームは必ず有限回の操作で終了し、高橋君または青木君の一方が勝利することが示せます。両者が勝ちを目指して最適に行動するとき、どちらが勝つか判定してください。

制約

  • |A_{i,j}| \leq 10^9
  • \sum_{i=1}^3 \sum_{j=1}^3 A_{i,j} は奇数
  • 入力はすべて整数

入力

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

A_{1,1} A_{1,2} A_{1,3}
A_{2,1} A_{2,2} A_{2,3}
A_{3,1} A_{3,2} A_{3,3}

出力

高橋君が勝つならば Takahashi を、青木君が勝つならば Aoki を出力せよ。


入力例 1

0 0 0
0 1 0
0 0 0

出力例 1

Takahashi

高橋君が最初の手番で (2,2) を選択すると、その後どのように青木君が行動しても、高橋君が適切に行動することで、青で塗られたマスが 3 つ連続しないようにすることができます。赤で塗られたマスが 3 つ連続した場合は高橋君が勝ちます。赤で塗られたマスが 3 つ連続せずにゲームが終了した場合、その時点で高橋君は 1 点、青木君は 0 点を獲得しているため、どちらにせよ高橋君が勝ちます。


入力例 2

-1 1 0
-4 -2 -5
-4 -1 -5

出力例 2

Aoki

Score: 450 points

Problem Statement

There is a 3 \times 3 grid. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left (1 \leq i, j \leq 3). Cell (i, j) contains an integer A_{i,j}. It is guaranteed that \sum_{i=1}^3 \sum_{j=1}^3 A_{i,j} is odd. Additionally, all cells are initially painted white.

Takahashi and Aoki will play a game using this grid. Takahashi goes first, and they take turns performing the following operation:

  • Choose a cell (i, j) (1\leq i, j \leq 3) that is still painted white (it can be shown that such a cell always exists at the time of the operation). The player performing the operation scores A_{i,j} points. Then, if the player is Takahashi, he paints the cell (i, j) red; if the player is Aoki, he paints it blue.

After each operation, the following checks are made:

  • Check if there are three consecutive cells painted the same color (red or blue) in any row, column, or diagonal. If such a sequence exists, the game ends immediately, and the player whose color forms the sequence wins.
  • Check if there are white cells left. If no white cells remain, the game ends, and the player with the higher total score wins.

It can be shown that the game will always end after a finite number of moves, and either Takahashi or Aoki will win. Determine which player wins if both play optimally for victory.

Constraints

  • |A_{i,j}| \leq 10^9
  • \sum_{i=1}^3 \sum_{j=1}^3 A_{i,j} is odd.
  • All input values are integers.

Input

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

A_{1,1} A_{1,2} A_{1,3}
A_{2,1} A_{2,2} A_{2,3}
A_{3,1} A_{3,2} A_{3,3}

Output

If Takahashi wins, print Takahashi; if Aoki wins, print Aoki.


Sample Input 1

0 0 0
0 1 0
0 0 0

Sample Output 1

Takahashi

If Takahashi chooses cell (2,2) in his first move, no matter how Aoki plays afterward, Takahashi can always act to prevent three consecutive blue cells. If three consecutive red cells are formed, Takahashi wins. If the game ends without three consecutive red cells, at that point, Takahashi has scored 1 point and Aoki 0 points, so Takahashi wins either way.


Sample Input 2

-1 1 0
-4 -2 -5
-4 -1 -5

Sample Output 2

Aoki
F - Subsequence LCM

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 525

問題文

長さ N の正整数列 A=(A_1,A_2,\dots,A_N) と正整数 M が与えられます。A の空でない連続とは限らない部分列であって、列に含まれる要素の最小公倍数が M になるようなものの個数を 998244353 で割った余りを求めてください。ただし、2 つの部分列が列として同じでも、取り出す位置が異なるならば区別するものとします。また、列の要素の個数が 1 のときはその要素自身を最小公倍数とします。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq M\leq 10^{16}
  • 1\leq A_i\leq 10^{16}
  • 入力は全て整数

入力

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

N M
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4 6
2 3 4 6

出力例 1

5

A の部分列であって,列に含まれる要素の最小公倍数が 6 となるものは (2,3),(2,3,6),(2,6),(3,6),(6)5 つです。


入力例 2

5 349
1 1 1 1 349

出力例 2

16

部分列が列として同じでも、取り出す位置が異なるならば区別することに注意してください。


入力例 3

16 720720
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

出力例 3

2688

Score: 525 points

Problem Statement

You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer M. Find the number, modulo 998244353, of non-empty and not necessarily contiguous subsequences of A such that the least common multiple (LCM) of the elements in the subsequence is M. Two subsequences are distinguished if they are taken from different positions in the sequence, even if they coincide as sequences. Also, the LCM of a sequence with a single element is that element itself.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 10^{16}
  • 1 \leq A_i \leq 10^{16}
  • All input values are integers.

Input

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

N M
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

4 6
2 3 4 6

Sample Output 1

5

The subsequences of A whose elements have an LCM of 6 are (2,3),(2,3,6),(2,6),(3,6),(6); there are five of them.


Sample Input 2

5 349
1 1 1 1 349

Sample Output 2

16

Note that even if some subsequences coincide as sequences, they are distinguished if they are taken from different positions.


Sample Input 3

16 720720
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Sample Output 3

2688
G - Palindrome Construction

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 625

問題文

長さ M の正整数列 T=(T_1,T_2,\dots,T_M)回文であるとは、各 i=1,2,\dots,M について T_i=T_{M-i+1} が成り立つこととします。

長さ N の非負整数列 A = (A_1,A_2,\dots,A_N) が与えられます。次の条件を満たす長さ N の正整数列 S=(S_1,S_2,\dots,S_N) が存在するか判定し、存在するならば条件を満たすもののうち辞書順最小のものを求めてください。

  • i=1,2,\dots,N に対して、次の両方が成り立つ
    • (S_{i-A_i},S_{i-A_i+1},\dots,S_{i+A_i}) は回文である
    • 2 \leq i-A_i かつ i+A_i \leq N-1 ならば、列 (S_{i-A_i-1},S_{i-A_i},\dots,S_{i+A_i+1}) は回文でない

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq \min\{i-1,N-i\}
  • 入力はすべて整数

入力

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

N
A_1 A_2 \dots A_N

出力

条件を満たす S が存在しなければ、 No を出力せよ。

条件を満たす S が存在するならば、そのうち辞書順最小のものを S' として、以下の形式で出力せよ。

Yes
S'_1 S'_2 \dots S'_N

入力例 1

7
0 0 2 0 2 0 0

出力例 1

Yes
1 1 2 1 1 1 2

S = (1,1,2,1,1,1,2) が条件を満たすことを確認します。

  • i=1: (A_1)=(1) は回文です
  • i=2: (A_2)=(1) は回文であり、 (A_1,A_2,A_3)=(1,1,2) は回文ではありません
  • i=3: (A_1,A_2,\dots,A_5)=(1,1,2,1,1) は回文です
  • i=4: (A_4)=(1) は回文であり、 (A_3,A_4,A_5)=(2,1,1) は回文ではありません
  • i=5: (A_3,A_4,\dots,A_7)=(2,1,1,1,2) は回文です
  • i=6: (A_6)=(1) は回文であり、 (A_5,A_6,A_7)=(1,1,2) は回文ではありません
  • i=7: (A_7)=(2) は回文です

他にも S=(2,2,1,2,2,2,1) などが条件を満たしますが、そのうち辞書順最小のものである (1,1,2,1,1,1,2) を出力します。


入力例 2

7
0 1 2 3 2 1 0

出力例 2

Yes
1 1 1 1 1 1 1

入力例 3

7
0 1 2 0 2 1 0

出力例 3

No

Score: 625 points

Problem Statement

A sequence of positive integers T=(T_1,T_2,\dots,T_M) of length M is a palindrome if and only if T_i=T_{M-i+1} for each i=1,2,\dots,M.

You are given a sequence of non-negative integers A = (A_1,A_2,\dots,A_N) of length N. Determine if there is a sequence of positive integers S=(S_1,S_2,\dots,S_N) of length N that satisfies the following condition, and if it exists, find the lexicographically smallest such sequence.

  • For each i=1,2,\dots,N, both of the following hold:
    • The sequence (S_{i-A_i},S_{i-A_i+1},\dots,S_{i+A_i}) is a palindrome.
    • If 2 \leq i-A_i and i+A_i \leq N-1, the sequence (S_{i-A_i-1},S_{i-A_i},\dots,S_{i+A_i+1}) is not a palindrome.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq \min\{i-1,N-i\}
  • All input values are integers.

Input

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

N
A_1 A_2 \dots A_N

Output

If there is no sequence S that satisfies the condition, print No.

If there is a sequence S that satisfies the condition, let S' be the lexicographically smallest such sequence and print it in the following format:

Yes
S'_1 S'_2 \dots S'_N

Sample Input 1

7
0 0 2 0 2 0 0

Sample Output 1

Yes
1 1 2 1 1 1 2

S = (1,1,2,1,1,1,2) satisfies the condition:

  • i=1: (A_1)=(1) is a palindrome.
  • i=2: (A_2)=(1) is a palindrome, but (A_1,A_2,A_3)=(1,1,2) is not.
  • i=3: (A_1,A_2,\dots,A_5)=(1,1,2,1,1) is a palindrome.
  • i=4: (A_4)=(1) is a palindrome, but (A_3,A_4,A_5)=(2,1,1) is not.
  • i=5: (A_3,A_4,\dots,A_7)=(2,1,1,1,2) is a palindrome.
  • i=6: (A_6)=(1) is a palindrome, but (A_5,A_6,A_7)=(1,1,2) is not.
  • i=7: (A_7)=(2) is a palindrome.

There are other sequences like S=(2,2,1,2,2,2,1) that satisfy the condition, but print the lexicographically smallest one, which is (1,1,2,1,1,1,2).


Sample Input 2

7
0 1 2 3 2 1 0

Sample Output 2

Yes
1 1 1 1 1 1 1

Sample Input 3

7
0 1 2 0 2 1 0

Sample Output 3

No