Codeforces Round #826 (Div. 3) B. Funny Permutation

该博客讨论了一种特殊类型的整数排列,称为'有趣排列',它满足两个条件:每个元素至少有一个相邻元素与之相差1,且没有任何固定点(即没有位置上的数字等于其索引)。文章通过举例和代码解释了如何找到长度为n的有趣排列,特别是在n为偶数和奇数时的不同解决方案。当n为偶数时,有趣排列总是存在的,而对于某些特定的奇数n(如3),则不存在满足条件的排列。
摘要由CSDN通过智能技术生成

A sequence of nn numbers is called permutation if it contains all numbers from 11 to nn exactly once. For example, the sequences [3,1,4,2][3,1,4,2], [11] and [2,1][2,1] are permutations, but [1,2,1][1,2,1], [0,1][0,1] and [1,3,4][1,3,4] are not.

For a given number nn you need to make a permutation pp such that two requirements are satisfied at the same time:

  • For each element pipi, at least one of its neighbors has a value that differs from the value of pipi by one. That is, for each element pipi (1≤i≤n1≤i≤n), at least one of its neighboring elements (standing to the left or right of pipi) must be pi+1pi+1, or pi−1pi−1.
  • the permutation must have no fixed points. That is, for every ii (1≤i≤n1≤i≤n), pi≠ipi≠i must be satisfied.

Let's call the permutation that satisfies these requirements funny.

For example, let n=4n=4. Then [4,3,1,24,3,1,2] is a funny permutation, since:

  • to the right of p1=4p1=4 is p2=p1−1=4−1=3p2=p1−1=4−1=3;
  • to the left of p2=3p2=3 is p1=p2+1=3+1=4p1=p2+1=3+1=4;
  • to the right of p3=1p3=1 is p4=p3+1=1+1=2p4=p3+1=1+1=2;
  • to the left of p4=2p4=2 is p3=p4−1=2−1=1p3=p4−1=2−1=1.
  • for all ii is pi≠ipi≠i.

For a given positive integer nn, output any funny permutation of length nn, or output -1 if funny permutation of length nn does not exist.

Input

The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The description of the test cases follows.

Each test case consists of f single line containing one integer nn (2≤n≤2⋅1052≤n≤2⋅105).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print on a separate line:

  • any funny permutation pp of length nn;
  • or the number -1 if the permutation you are looking for does not exist.

Example

input

Copy

 

5

4

3

7

5

2

output

Copy

3 4 2 1
-1
6 7 4 5 3 2 1
5 4 1 2 3
2 1

Note

The first test case is explained in the problem statement.

In the second test case, it is not possible to make the required permutation: permutations [1,2,3][1,2,3], [1,3,2][1,3,2], [2,1,3][2,1,3], [3,2,1][3,2,1] have fixed points, and in [2,3,1][2,3,1] and [3,1,2][3,1,2] the first condition is met not for all positions.

#include<stdio.h>

//  1 2 3 4 
//  4 3 2 1 
// 1 2 3 
 //3 2 1 
int main()
{
	int n;
	scanf("%d", &n);
	while (n) {
		int a;
		scanf("%d", &a);
		if (a % 2 == 0)
		{
			for (int i = a; i > 0; i--)
				printf("%d ", i);
			printf("\n");
			n--;
		}
		else if (a == 3)
		{printf("-1\n");
		n--;
	}
		else {
			for (int i = a; i > (a+1)/ 2; i--)
				printf("%d ", i);
			for(int i=1;i<=(a+1)/2;i++)
				printf("%d ", i);
			printf("\n");
			n--;
				//1 2 3 4 5 
				//5 4 1 2 3 
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值