atcoder#ARC122E. [ARC122E] Increasing LCMs

[ARC122E] Increasing LCMs

Score : 800800 points

Problem Statement

We have a sequence of NN positive integers: A1,A2,,ANA_1,A_2,\cdots,A_N. You are to rearrange these integers into another sequence x1,x2,,xNx_1,x_2,\cdots,x_N, where xx must satisfy the following condition:

  • Let us define yi=LCM(x1,x2,,xi)y_i=\operatorname{LCM}(x_1,x_2,\cdots,x_i), where the function LCM\operatorname{LCM} returns the least common multiple of the given integers. Then, yy is strictly increasing. In other words, $y_1 holds.

Determine whether it is possible to form a sequence xx satisfying the condition, and show one such sequence if it is possible.

Constraints

  • 1N1001 \leq N \leq 100
  • 2A1<A2<AN10182 \leq A_1 < A_2 \cdots < A_N \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

If it is possible to form a sequence xx satisfying the condition, print your answer in the following format:

Yes

x1x_1 x2x_2 \cdots xNx_N

If it is impossible, print No.

3
3 4 6
Yes
3 6 4

For x=(3,6,4)x=(3,6,4), we have:

  • y1=LCM(3)=3y_1=\operatorname{LCM}(3)=3
  • y2=LCM(3,6)=6y_2=\operatorname{LCM}(3,6)=6
  • y3=LCM(3,6,4)=12y_3=\operatorname{LCM}(3,6,4)=12

Here, $y_1 holds.

3
2 3 6
No

No permutation of AA would satisfy the condition.

10
922513 346046618969 3247317977078471 4638516664311857 18332844097865861 81706734998806133 116282391418772039 134115264093375553 156087536381939527 255595307440611247
Yes
922513 346046618969 116282391418772039 81706734998806133 255595307440611247 156087536381939527 134115264093375553 18332844097865861 3247317977078471 4638516664311857