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.
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.
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".
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
YES YES NO YES YES
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> typedef long long ll; using namespace std; const int INT=1e6+5; #define lson rt<<1, l, m #define rson rt<<1|1, m+1, r #define read(x) scanf("%d",&x) #define lread(x) scanf("%lld",&x); #define pt(x) printf("%d\n",(x)) #define cn cin>> #define ct cout<< #define en <<endl #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++) #define mem(s,t) memset(s,t,sizeof(s)) #define re return 0; #define TLE std::ios::sync_with_stdio(false); ll a[100000+5],b[10000+5]; priority_queue<ll>q1,q2; int main() { TLE; int t,n,m,mx,flag; cn t; while(t--) { map<int,int>mp; mx=-INT; cn n; mem(b,0); rep(1,4*n) { cn a[i]; b[ a[i] ]++; } m=0;flag = 0; sort(a+1,a+4*n+1); mx=a[1]*a[4*n]; if(n==1 && b[a[1]]==4) ct "YES" en; else { rep(1,4*n-1) { if(a[i]!=a[i+1] || a[i]*a[4*n-i+1]!=mx) { flag = 1; break; } i++; } if(flag) ct "NO" en; else ct "YES" en; } } re ; }