A. United We Stand

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Given an array a� of length n�, containing integers. And there are two initially empty arrays b� and c�. You need to add each element of array a� to exactly one of the arrays b� or c�, in order to satisfy the following conditions:

  • Both arrays b� and c� are non-empty. More formally, let lb�� be the length of array b�, and lc�� be the length of array c�. Then lb,lc≥1��,��≥1.
  • For any two indices i� and j� (1≤i≤lb,1≤j≤lc1≤�≤��,1≤�≤��), cj�� is not a divisor of bi��.

Output the arrays b� and c� that can be obtained, or output −1−1 if they do not exist.

Input

Each test consists of multiple test cases. The first line contains a single integer t� (1≤t≤5001≤�≤500) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n� (2≤n≤1002≤�≤100) --- the length of array a�.

The second line of each test case contains n� integers a1,a2,...,an�1,�2,...,�� (1≤ai≤1091≤��≤109) --- the elements of array a�.

Output

For each test case, output a single integer −1−1 if a solution does not exist.

Otherwise, in the first line, output two integers lb�� and lc�� --- the lengths of arrays b� and c� respectively.

In the second line, output lb�� integers b1,b2,...,blb�1,�2,...,��� --- the elements of array b�.

In the third line, output lc�� integers c1,c2,...,clc�1,�2,...,��� --- the elements of array c�.

If there are multiple solutions, output any of them. You can output the elements of the arrays in any order.

Example

input

Copy

复制代码

5

3

2 2 2

5

1 2 3 4 5

3

1 3 5

7

1 7 7 2 9 1 4

5

4 8 12 12 4

output

Copy

复制代码
-1
3 2
1 3 5 
2 4 
1 2
1 
3 5 
2 5
1 1 
2 4 7 7 9 
3 2
4 8 4 
12 12 

Note

In the first test case, a solution does not exist.

In the second test case, we can obtain b=[1,3,5]�=[1,3,5] and c=[2,4]�=[2,4]. Then elements 22 and 44 do not divide elements 1,31,3 and 55.

In the fifth test case, we can obtain b=[4,8,4]�=[4,8,4] and c=[12,12]�=[12,12].

解题说明:水题,对数列排序,只要让数列a中的最小值放入数列b,其他值都放入数列c中就可以,前提是数列a不是同一个数。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		sort(a, a + n);
		if (a[0] == a[n - 1])
		{
			cout << -1 << endl;
		}
		else
		{
			int i = 1;
			while (a[i] == a[0])
			{
				i++;
			}
			cout << i << ' ' << n - i << endl;
			for (int j = 0; j < i; j++)
			{
				cout << a[j] << ' ';
			}
			cout << endl;
			for (int j = i; j < n; j++)
			{
				cout << a[j] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}
相关推荐
WW_千谷山4_sch2 分钟前
MYOJ_7788:(洛谷P3387)【模板】缩点(有关强连通分量)
c++·算法·深度优先·动态规划·图论·拓扑学
小O的算法实验室3 分钟前
2026年IEEE TCYB SCI1区TOP,少即是多:一种用于大规模优化的小规模学习粒子群算法,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
0 0 08 分钟前
CCF-CSP 34-2 矩阵重塑(其二)(reshape2)【C++】考点:矩阵转置模拟
开发语言·c++·算法·矩阵
二年级程序员9 分钟前
一篇文章掌握“队列”
c语言·数据结构·算法
ArturiaZ12 分钟前
【day33】
算法
Drifter_yh17 分钟前
「JVM」Java 垃圾回收机制全解析:回收算法、分代流转与 G1 收集器底层拆解
java·jvm·算法
载数而行52018 分钟前
算法系列3之拓扑排序
c语言·数据结构·c++·算法·排序算法
!停22 分钟前
数据结构排序算法—插入排序
数据结构·算法·排序算法
s砚山s22 分钟前
代码随想录刷题——二叉树篇(二十一)
算法
谁不学习揍谁!24 分钟前
基于python大数据机器学习旅游数据分析可视化推荐系统(完整系统+开发文档+部署教程+文档等资料)
大数据·python·算法·机器学习·数据分析·旅游·数据可视化