#SP0000235. Chiếc rương hòa hợp của Little Pony (Little Pony and Harmony Chest)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chiếc rương hòa hợp của Little Pony (Little Pony and Harmony Chest)
Little Pony and Harmony Chest
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Princess Twilight finds a harmony chest. Its key is a sequence of positive integers in which every two entries at different positions are coprime:
$$\gcd(b_i,b_j)=1\quad \text{for all }1\le i<j\le n.$$Given positive integers , construct a valid sequence minimizing the sum of absolute deviations
If multiple optimal sequences exist, you may output any of them.
Input
Line 1 contains . Line 2 contains exactly integers .
Output
Print exactly positive integers , in order, forming a pairwise coprime sequence with minimum .
Subtasks
-
Subtask 1 (20 points): ; for all .
-
Subtask 2 (30 points): ; for all .
-
Subtask 3 (50 points): ; for all .
Examples
Input
5
1 1 1 1 1
Output
1 1 1 1 1
Explanation
The input contains five s. Choose . Every pair has , so the sequence is valid. Each deviation , yielding total cost . Since absolute values are nonnegative, no smaller cost is possible; this output is optimal.