310995: CF1918G. Permutation of Given

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Permutation of Giventime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You were given only one number, $n$. It didn't seem interesting to you, so you wondered if it's possible to come up with an array of length $n$ consisting of non-zero integers, such that if each element of the array is replaced by the sum of its neighbors (the elements on the ends are replaced by their only neighbors), you obtain a permutation of the numbers in the original array.

Input

Each test case contains only one number, $n$ ($2 \leq n \leq 10^6$).

Output

If a solution exists, output "YES" (without quotes), followed by an array $a$ ($-10^9 \leq a_i \leq 10^9, a_i \neq 0$) that satisfies the condition of the problem. If there are multiple possible answers, output any of them.

If there is no suitable array, output "NO" (without quotes).

The words "YES" and "NO" can be output in any case, for example, "YES", "Yes", "yEs", and so on.

ExamplesInput
4
Output
YES
1 2 -2 -1
Input
5
Output
NO
Note

In the first test, the array [$1, 2, -2, -1$] is suitable, because if each element is replaced by the sum of its neighbors, the resulting array is [$2, -1, 1, -2$], which is a permutation of the original array.

In the second test, it can be shown that there is no solution.

Output

题目大意:给定一个数字n,要求构造一个长度为n的由非零整数组成的数组,使得每个数组元素被其邻居元素之和替换后(数组的两端分别被其唯一的邻居替换),得到的数组是原数组的一个排列。

输入数据格式:每个测试用例仅包含一个数字n(2 ≤ n ≤ 10^6)。

输出数据格式:如果存在解决方案,输出"YES"(不包含引号),接着输出一个满足题目条件的数组a(-10^9 ≤ a_i ≤ 10^9,a_i ≠ 0)。如果存在多个可能的答案,输出其中任意一个。如果不存在合适的数组,输出"NO"(不包含引号)。"YES"和"NO"可以用任何大小写组合输出。

示例:

输入:4
输出:YES
1 2 -2 -1

输入:5
输出:NO题目大意:给定一个数字n,要求构造一个长度为n的由非零整数组成的数组,使得每个数组元素被其邻居元素之和替换后(数组的两端分别被其唯一的邻居替换),得到的数组是原数组的一个排列。 输入数据格式:每个测试用例仅包含一个数字n(2 ≤ n ≤ 10^6)。 输出数据格式:如果存在解决方案,输出"YES"(不包含引号),接着输出一个满足题目条件的数组a(-10^9 ≤ a_i ≤ 10^9,a_i ≠ 0)。如果存在多个可能的答案,输出其中任意一个。如果不存在合适的数组,输出"NO"(不包含引号)。"YES"和"NO"可以用任何大小写组合输出。 示例: 输入:4 输出:YES 1 2 -2 -1 输入:5 输出:NO

加入题单

上一题 下一题 算法标签: