You are given 4n4n sticks, the length of the ii-th stick is aiai.
You have to create nn rectangles, each rectangle will consist of exactly 44 sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.
You want to all rectangles to have equal area. The area of the rectangle with sides aa and bb is a⋅ba⋅b.
Your task is to say if it is possible to create exactly nn rectangles of equal area or not.
You have to answer qq independent queries.
Input
The first line of the input contains one integer qq (1≤q≤5001≤q≤500) — the number of queries. Then qq queries follow.
The first line of the query contains one integer nn (1≤n≤1001≤n≤100) — the number of rectangles.
The second line of the query contains 4n4n integers a1,a2,…,a4na1,a2,…,a4n (1≤ai≤1041≤ai≤104), where aiai is the length of the ii-th stick.
Output
For each query print the answer to it. If it is impossible to create exactly nn rectangles of equal area using given sticks, print "NO". Otherwise print "YES".
Example
input
Copy
5 1 1 1 10 10 2 10 5 2 10 1 1 2 5 2 10 5 1 10 5 1 1 1 2 1 1 1 1 1 1 1 1 1 10000 10000 10000 10000
output
Copy
YES YES NO YES YES
题目连接:http://codeforces.com/contest/1203/problem/B
思路:最大和最小的边相乘==第二大乘第二小的边相乘==第三大乘第三小的边...........
#include<bits/stdc++.h>
using namespace std;
int t,n,A[410];
int main()
{
for(scanf("%d",&t);t;t--)
{
scanf("%d",&n);
for(int i=0;i<4*n;i++)
scanf("%d",&A[i]);
sort(A,A+4*n);
bool flag=true;
int judge=A[0]*A[4*n-1];
for(int i=0;i<2*n;i+=2)
{
if(A[2*i]!=A[2*i+1]||A[4*n-i*2-1]!=A[4*n-i*2-2]) flag=false;
if(A[2*i]*A[4*n-i*2-1]!=judge) flag=false;
}
printf("%s\n",flag?"YES":"NO");
}
}